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