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