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.FileVersion;
018    import com.liferay.portlet.documentlibrary.model.DLProcessorConstants;
019    
020    import java.io.InputStream;
021    
022    /**
023     * @author Sergio Gonz??lez
024     */
025    public class PDFProcessorUtil {
026    
027            public static void generateImages(
028                            FileVersion sourceFileVersion, FileVersion destinationFileVersion)
029                    throws Exception {
030    
031                    PDFProcessor pdfProcessor = getPDFProcessor();
032    
033                    if (pdfProcessor != null) {
034                            pdfProcessor.generateImages(
035                                    sourceFileVersion, destinationFileVersion);
036                    }
037            }
038    
039            public static PDFProcessor getPDFProcessor() {
040                    return (PDFProcessor)DLProcessorRegistryUtil.getDLProcessor(
041                            DLProcessorConstants.PDF_PROCESSOR);
042            }
043    
044            public static InputStream getPreviewAsStream(
045                            FileVersion fileVersion, int index)
046                    throws Exception {
047    
048                    PDFProcessor pdfProcessor = getPDFProcessor();
049    
050                    if (pdfProcessor == null) {
051                            return null;
052                    }
053    
054                    return pdfProcessor.getPreviewAsStream(fileVersion, index);
055            }
056    
057            public static int getPreviewFileCount(FileVersion fileVersion) {
058                    PDFProcessor pdfProcessor = getPDFProcessor();
059    
060                    if (pdfProcessor == null) {
061                            return 0;
062                    }
063    
064                    return pdfProcessor.getPreviewFileCount(fileVersion);
065            }
066    
067            public static long getPreviewFileSize(FileVersion fileVersion, int index)
068                    throws Exception {
069    
070                    PDFProcessor pdfProcessor = getPDFProcessor();
071    
072                    if (pdfProcessor == null) {
073                            return 0;
074                    }
075    
076                    return pdfProcessor.getPreviewFileSize(fileVersion, index);
077            }
078    
079            public static InputStream getThumbnailAsStream(
080                            FileVersion fileVersion, int index)
081                    throws Exception {
082    
083                    PDFProcessor pdfProcessor = getPDFProcessor();
084    
085                    if (pdfProcessor == null) {
086                            return null;
087                    }
088    
089                    return pdfProcessor.getThumbnailAsStream(fileVersion, index);
090            }
091    
092            public static long getThumbnailFileSize(FileVersion fileVersion, int index)
093                    throws Exception {
094    
095                    PDFProcessor pdfProcessor = getPDFProcessor();
096    
097                    if (pdfProcessor == null) {
098                            return 0;
099                    }
100    
101                    return pdfProcessor.getThumbnailFileSize(fileVersion, index);
102            }
103    
104            public static boolean hasImages(FileVersion fileVersion) {
105                    PDFProcessor pdfProcessor = getPDFProcessor();
106    
107                    if (pdfProcessor == null) {
108                            return false;
109                    }
110    
111                    return pdfProcessor.hasImages(fileVersion);
112            }
113    
114            public static boolean isDocumentSupported(FileVersion fileVersion) {
115                    PDFProcessor pdfProcessor = getPDFProcessor();
116    
117                    if (pdfProcessor == null) {
118                            return false;
119                    }
120    
121                    return pdfProcessor.isDocumentSupported(fileVersion);
122            }
123    
124            public static boolean isDocumentSupported(String mimeType) {
125                    PDFProcessor pdfProcessor = getPDFProcessor();
126    
127                    if (pdfProcessor == null) {
128                            return false;
129                    }
130    
131                    return pdfProcessor.isDocumentSupported(mimeType);
132            }
133    
134            public static boolean isSupported(String mimeType) {
135                    PDFProcessor pdfProcessor = getPDFProcessor();
136    
137                    if (pdfProcessor == null) {
138                            return false;
139                    }
140    
141                    return pdfProcessor.isSupported(mimeType);
142            }
143    
144            public static void trigger(
145                    FileVersion sourceFileVersion, FileVersion destinationFileVersion) {
146    
147                    PDFProcessor pdfProcessor = getPDFProcessor();
148    
149                    if (pdfProcessor != null) {
150                            pdfProcessor.trigger(sourceFileVersion, destinationFileVersion);
151                    }
152            }
153    
154            /**
155             * @deprecated As of 6.2.0
156             */
157            public void setPDFProcessor(PDFProcessor pdfProcessor) {
158            }
159    
160    }