001
014
015 package com.liferay.portlet.documentlibrary.util;
016
017 import com.liferay.portal.kernel.repository.model.FileVersion;
018 import com.liferay.portlet.documentlibrary.model.DLProcessorConstants;
019
020 import java.io.InputStream;
021
022 import java.util.Properties;
023
024
027 public class PDFProcessorUtil {
028
029 public static void generateImages(FileVersion fileVersion)
030 throws Exception {
031
032 PDFProcessor pdfProcessor = getPDFProcessor();
033
034 if (pdfProcessor != null) {
035 pdfProcessor.generateImages(fileVersion);
036 }
037 }
038
039 public static String getGlobalSearchPath() throws Exception {
040 PDFProcessor pdfProcessor = getPDFProcessor();
041
042 if (pdfProcessor == null) {
043 return null;
044 }
045
046 return pdfProcessor.getGlobalSearchPath();
047 }
048
049 public static PDFProcessor getPDFProcessor() {
050 return (PDFProcessor)DLProcessorRegistryUtil.getDLProcessor(
051 DLProcessorConstants.PDF_PROCESSOR);
052 }
053
054 public static InputStream getPreviewAsStream(
055 FileVersion fileVersion, int index)
056 throws Exception {
057
058 PDFProcessor pdfProcessor = getPDFProcessor();
059
060 if (pdfProcessor == null) {
061 return null;
062 }
063
064 return pdfProcessor.getPreviewAsStream(fileVersion, index);
065 }
066
067 public static int getPreviewFileCount(FileVersion fileVersion) {
068 PDFProcessor pdfProcessor = getPDFProcessor();
069
070 if (pdfProcessor == null) {
071 return 0;
072 }
073
074 return pdfProcessor.getPreviewFileCount(fileVersion);
075 }
076
077 public static long getPreviewFileSize(FileVersion fileVersion, int index)
078 throws Exception {
079
080 PDFProcessor pdfProcessor = getPDFProcessor();
081
082 if (pdfProcessor == null) {
083 return 0;
084 }
085
086 return pdfProcessor.getPreviewFileSize(fileVersion, index);
087 }
088
089 public static Properties getResourceLimitsProperties() throws Exception {
090 PDFProcessor pdfProcessor = getPDFProcessor();
091
092 if (pdfProcessor == null) {
093 return null;
094 }
095
096 return pdfProcessor.getResourceLimitsProperties();
097 }
098
099 public static InputStream getThumbnailAsStream(
100 FileVersion fileVersion, int index)
101 throws Exception {
102
103 PDFProcessor pdfProcessor = getPDFProcessor();
104
105 if (pdfProcessor == null) {
106 return null;
107 }
108
109 return pdfProcessor.getThumbnailAsStream(fileVersion, index);
110 }
111
112 public static long getThumbnailFileSize(FileVersion fileVersion, int index)
113 throws Exception {
114
115 PDFProcessor pdfProcessor = getPDFProcessor();
116
117 if (pdfProcessor == null) {
118 return 0;
119 }
120
121 return pdfProcessor.getThumbnailFileSize(fileVersion, index);
122 }
123
124 public static boolean hasImages(FileVersion fileVersion) {
125 PDFProcessor pdfProcessor = getPDFProcessor();
126
127 if (pdfProcessor == null) {
128 return false;
129 }
130
131 return pdfProcessor.hasImages(fileVersion);
132 }
133
134 public static boolean isDocumentSupported(FileVersion fileVersion) {
135 PDFProcessor pdfProcessor = getPDFProcessor();
136
137 if (pdfProcessor == null) {
138 return false;
139 }
140
141 return pdfProcessor.isDocumentSupported(fileVersion);
142 }
143
144 public static boolean isDocumentSupported(String mimeType) {
145 PDFProcessor pdfProcessor = getPDFProcessor();
146
147 if (pdfProcessor == null) {
148 return false;
149 }
150
151 return pdfProcessor.isDocumentSupported(mimeType);
152 }
153
154 public static boolean isImageMagickEnabled() throws Exception {
155 PDFProcessor pdfProcessor = getPDFProcessor();
156
157 if (pdfProcessor == null) {
158 return false;
159 }
160
161 return pdfProcessor.isImageMagickEnabled();
162 }
163
164 public static boolean isSupported(String mimeType) {
165 PDFProcessor pdfProcessor = getPDFProcessor();
166
167 if (pdfProcessor == null) {
168 return false;
169 }
170
171 return pdfProcessor.isSupported(mimeType);
172 }
173
174 public static void reset() throws Exception {
175 PDFProcessor pdfProcessor = getPDFProcessor();
176
177 if (pdfProcessor != null) {
178 getPDFProcessor().reset();
179 }
180 }
181
182 public static void trigger(FileVersion fileVersion) {
183 PDFProcessor pdfProcessor = getPDFProcessor();
184
185 if (pdfProcessor != null) {
186 getPDFProcessor().trigger(fileVersion);
187 }
188 }
189
190
193 public void setPDFProcessor(PDFProcessor pdfProcessor) {
194 }
195
196 }