001
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
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(
047 FileVersion sourceFileVersion, FileVersion destinationFileVersion)
048 throws Exception {
049
050 ImageProcessor imageProcessor = getImageProcessor();
051
052 if (imageProcessor != null) {
053 imageProcessor.generateImages(
054 sourceFileVersion, destinationFileVersion);
055 }
056 }
057
058 public static Set<String> getImageMimeTypes() {
059 ImageProcessor imageProcessor = getImageProcessor();
060
061 if (imageProcessor == null) {
062 return null;
063 }
064
065 return imageProcessor.getImageMimeTypes();
066 }
067
068 public static ImageProcessor getImageProcessor() {
069 return (ImageProcessor)DLProcessorRegistryUtil.getDLProcessor(
070 DLProcessorConstants.IMAGE_PROCESSOR);
071 }
072
073 public static InputStream getPreviewAsStream(FileVersion fileVersion)
074 throws Exception {
075
076 ImageProcessor imageProcessor = getImageProcessor();
077
078 if (imageProcessor == null) {
079 return null;
080 }
081
082 return imageProcessor.getPreviewAsStream(fileVersion);
083 }
084
085 public static long getPreviewFileSize(FileVersion fileVersion)
086 throws Exception {
087
088 ImageProcessor imageProcessor = getImageProcessor();
089
090 if (imageProcessor == null) {
091 return 0;
092 }
093
094 return imageProcessor.getPreviewFileSize(fileVersion);
095 }
096
097 public static String getPreviewType(FileVersion fileVersion) {
098 ImageProcessor imageProcessor = getImageProcessor();
099
100 if (imageProcessor == null) {
101 return null;
102 }
103
104 return imageProcessor.getPreviewType(fileVersion);
105 }
106
107 public static InputStream getThumbnailAsStream(
108 FileVersion fileVersion, int index)
109 throws Exception {
110
111 ImageProcessor imageProcessor = getImageProcessor();
112
113 if (imageProcessor == null) {
114 return null;
115 }
116
117 return imageProcessor.getThumbnailAsStream(fileVersion, index);
118 }
119
120 public static long getThumbnailFileSize(FileVersion fileVersion, int index)
121 throws Exception {
122
123 ImageProcessor imageProcessor = getImageProcessor();
124
125 if (imageProcessor == null) {
126 return 0;
127 }
128
129 return imageProcessor.getThumbnailFileSize(fileVersion, index);
130 }
131
132 public static String getThumbnailType(FileVersion fileVersion) {
133 ImageProcessor imageProcessor = getImageProcessor();
134
135 if (imageProcessor == null) {
136 return null;
137 }
138
139 return imageProcessor.getThumbnailType(fileVersion);
140 }
141
142 public static boolean hasImages(FileVersion fileVersion) {
143 ImageProcessor imageProcessor = getImageProcessor();
144
145 if (imageProcessor == null) {
146 return false;
147 }
148
149 return imageProcessor.hasImages(fileVersion);
150 }
151
152 public static boolean isImageSupported(FileVersion fileVersion) {
153 ImageProcessor imageProcessor = getImageProcessor();
154
155 if (imageProcessor == null) {
156 return false;
157 }
158
159 return imageProcessor.isImageSupported(fileVersion);
160 }
161
162 public static boolean isImageSupported(String mimeType) {
163 ImageProcessor imageProcessor = getImageProcessor();
164
165 if (imageProcessor == null) {
166 return false;
167 }
168
169 return imageProcessor.isImageSupported(mimeType);
170 }
171
172 public static boolean isSupported(String mimeType) {
173 ImageProcessor imageProcessor = getImageProcessor();
174
175 if (imageProcessor == null) {
176 return false;
177 }
178
179 return imageProcessor.isSupported(mimeType);
180 }
181
182 public static void storeThumbnail(
183 long companyId, long groupId, long fileEntryId, long fileVersionId,
184 long custom1ImageId, long custom2ImageId, InputStream is,
185 String type)
186 throws Exception {
187
188 ImageProcessor imageProcessor = getImageProcessor();
189
190 if (imageProcessor != null) {
191 imageProcessor.storeThumbnail(
192 companyId, groupId, fileEntryId, fileVersionId, custom1ImageId,
193 custom2ImageId, is, type);
194 }
195 }
196
197 public static void trigger(
198 FileVersion sourceFileVersion, FileVersion destinationFileVersion) {
199
200 ImageProcessor imageProcessor = getImageProcessor();
201
202 if (imageProcessor != null) {
203 imageProcessor.trigger(sourceFileVersion, destinationFileVersion);
204 }
205 }
206
207
210 public void setImageProcessor(ImageProcessor imageProcessor) {
211 }
212
213 }