001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 */ 020package org.nuxeo.ecm.platform.picture.convert; 021 022import java.io.Serializable; 023import java.util.ArrayList; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.ecm.core.api.Blob; 028import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 029import org.nuxeo.ecm.core.convert.api.ConversionException; 030import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder; 031import org.nuxeo.ecm.core.convert.extension.Converter; 032import org.nuxeo.ecm.core.convert.extension.ConverterDescriptor; 033import org.nuxeo.ecm.platform.picture.api.ImagingConvertConstants; 034import org.nuxeo.ecm.platform.picture.api.ImagingService; 035import org.nuxeo.runtime.api.Framework; 036 037/** 038 * @author <a href="mailto:[email protected]">Laurent Doguint</a> 039 */ 040public class RotationPictureConverter implements Converter { 041 042 @Override 043 public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { 044 ImagingService service = Framework.getService(ImagingService.class); 045 List<Blob> results = new ArrayList<Blob>(); 046 List<Blob> sources = blobHolder.getBlobs(); 047 int angle = (Integer) parameters.get(ImagingConvertConstants.OPTION_ROTATE_ANGLE); 048 for (Blob source : sources) { 049 if (source != null) { 050 Blob result = service.rotate(source, angle); 051 if (result != null) { 052 results.add(result); 053 } 054 } 055 } 056 return new SimpleCachableBlobHolder(results); 057 } 058 059 @Override 060 public void init(ConverterDescriptor descriptor) { 061 } 062 063}