001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.util;
016    
017    import com.liferay.portal.kernel.repository.model.FileEntry;
018    import com.liferay.portal.kernel.repository.model.FileVersion;
019    import com.liferay.portlet.documentlibrary.model.DLProcessorConstants;
020    
021    import java.io.InputStream;
022    
023    import java.util.Set;
024    
025    /**
026     * @author Sergio Gonz??lez
027     */
028    public class ImageProcessorUtil {
029    
030            public static void cleanUp(FileEntry fileEntry) {
031                    ImageProcessor imageProcessor = getImageProcessor();
032    
033                    if (imageProcessor != null) {
034                            imageProcessor.cleanUp(fileEntry);
035                    }
036            }
037    
038            public static void cleanUp(FileVersion fileVersion) {
039                    ImageProcessor imageProcessor = getImageProcessor();
040    
041                    if (imageProcessor != null) {
042                            imageProcessor.cleanUp(fileVersion);
043                    }
044            }
045    
046            public static void generateImages(FileVersion fileVersion) {
047                    ImageProcessor imageProcessor = getImageProcessor();
048    
049                    if (imageProcessor != null) {
050                            imageProcessor.generateImages(fileVersion);
051                    }
052            }
053    
054            public static Set<String> getImageMimeTypes() {
055                    ImageProcessor imageProcessor = getImageProcessor();
056    
057                    if (imageProcessor == null) {
058                            return null;
059                    }
060    
061                    return imageProcessor.getImageMimeTypes();
062            }
063    
064            public static ImageProcessor getImageProcessor() {
065                    return (ImageProcessor)DLProcessorRegistryUtil.getDLProcessor(
066                            DLProcessorConstants.IMAGE_PROCESSOR);
067            }
068    
069            public static InputStream getPreviewAsStream(FileVersion fileVersion)
070                    throws Exception {
071    
072                    ImageProcessor imageProcessor = getImageProcessor();
073    
074                    if (imageProcessor == null) {
075                            return null;
076                    }
077    
078                    return imageProcessor.getPreviewAsStream(fileVersion);
079            }
080    
081            public static long getPreviewFileSize(FileVersion fileVersion)
082                    throws Exception {
083    
084                    ImageProcessor imageProcessor = getImageProcessor();
085    
086                    if (imageProcessor == null) {
087                            return 0;
088                    }
089    
090                    return imageProcessor.getPreviewFileSize(fileVersion);
091            }
092    
093            public static String getPreviewType(FileVersion fileVersion) {
094                    ImageProcessor imageProcessor = getImageProcessor();
095    
096                    if (imageProcessor == null) {
097                            return null;
098                    }
099    
100                    return imageProcessor.getPreviewType(fileVersion);
101            }
102    
103            public static InputStream getThumbnailAsStream(
104                            FileVersion fileVersion, int index)
105                    throws Exception {
106    
107                    ImageProcessor imageProcessor = getImageProcessor();
108    
109                    if (imageProcessor == null) {
110                            return null;
111                    }
112    
113                    return imageProcessor.getThumbnailAsStream(fileVersion, index);
114            }
115    
116            public static long getThumbnailFileSize(FileVersion fileVersion, int index)
117                    throws Exception {
118    
119                    ImageProcessor imageProcessor = getImageProcessor();
120    
121                    if (imageProcessor == null) {
122                            return 0;
123                    }
124    
125                    return imageProcessor.getThumbnailFileSize(fileVersion, index);
126            }
127    
128            public static String getThumbnailType(FileVersion fileVersion) {
129                    ImageProcessor imageProcessor = getImageProcessor();
130    
131                    if (imageProcessor == null) {
132                            return null;
133                    }
134    
135                    return imageProcessor.getThumbnailType(fileVersion);
136            }
137    
138            public static boolean hasImages(FileVersion fileVersion) {
139                    ImageProcessor imageProcessor = getImageProcessor();
140    
141                    if (imageProcessor == null) {
142                            return false;
143                    }
144    
145                    return imageProcessor.hasImages(fileVersion);
146            }
147    
148            public static boolean isImageSupported(FileVersion fileVersion) {
149                    ImageProcessor imageProcessor = getImageProcessor();
150    
151                    if (imageProcessor == null) {
152                            return false;
153                    }
154    
155                    return imageProcessor.isImageSupported(fileVersion);
156            }
157    
158            public static boolean isImageSupported(String mimeType) {
159                    ImageProcessor imageProcessor = getImageProcessor();
160    
161                    if (imageProcessor == null) {
162                            return false;
163                    }
164    
165                    return imageProcessor.isImageSupported(mimeType);
166            }
167    
168            public static boolean isSupported(String mimeType) {
169                    ImageProcessor imageProcessor = getImageProcessor();
170    
171                    if (imageProcessor == null) {
172                            return false;
173                    }
174    
175                    return imageProcessor.isSupported(mimeType);
176            }
177    
178            public static void storeThumbnail(
179                            long companyId, long groupId, long fileEntryId, long fileVersionId,
180                            long custom1ImageId, long custom2ImageId, InputStream is,
181                            String type)
182                    throws Exception {
183    
184                    ImageProcessor imageProcessor = getImageProcessor();
185    
186                    if (imageProcessor != null) {
187                            imageProcessor.storeThumbnail(
188                                    companyId, groupId, fileEntryId, fileVersionId, custom1ImageId,
189                                    custom2ImageId, is, type);
190                    }
191            }
192    
193            public static void trigger(FileVersion fileVersion) {
194                    ImageProcessor imageProcessor = getImageProcessor();
195    
196                    if (imageProcessor != null) {
197                            imageProcessor.trigger(fileVersion);
198                    }
199            }
200    
201            /**
202             * @deprecated
203             */
204            public void setImageProcessor(ImageProcessor imageProcessor) {
205            }
206    
207    }