001/* 002 * (C) Copyright 2002-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 */ 018package org.nuxeo.ecm.platform.picture.convert; 019 020import java.io.Serializable; 021import java.util.ArrayList; 022import java.util.List; 023import java.util.Map; 024 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 027import org.nuxeo.ecm.core.convert.api.ConversionException; 028import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder; 029import org.nuxeo.ecm.core.convert.extension.Converter; 030import org.nuxeo.ecm.core.convert.extension.ConverterDescriptor; 031import org.nuxeo.ecm.platform.picture.api.ImagingConvertConstants; 032import org.nuxeo.ecm.platform.picture.api.ImagingService; 033import org.nuxeo.runtime.api.Framework; 034 035/** 036 * @author <a href="mailto:ldoguin@nuxeo.com">Laurent Doguint</a> 037 */ 038public class RotationPictureConverter implements Converter { 039 040 @Override 041 public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { 042 ImagingService service = Framework.getService(ImagingService.class); 043 List<Blob> results = new ArrayList<Blob>(); 044 List<Blob> sources = blobHolder.getBlobs(); 045 int angle = (Integer) parameters.get(ImagingConvertConstants.OPTION_ROTATE_ANGLE); 046 for (Blob source : sources) { 047 if (source != null) { 048 Blob result = service.rotate(source, angle); 049 if (result != null) { 050 results.add(result); 051 } 052 } 053 } 054 return new SimpleCachableBlobHolder(results); 055 } 056 057 @Override 058 public void init(ConverterDescriptor descriptor) { 059 } 060 061}