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 AudioProcessorUtil {
028    
029            public static void generateAudio(FileVersion fileVersion) throws Exception {
030                    AudioProcessor audioProcessor = getAudioProcessor();
031    
032                    if (audioProcessor != null) {
033                            audioProcessor.generateAudio(fileVersion);
034                    }
035            }
036    
037            public static Set<String> getAudioMimeTypes() {
038                    AudioProcessor audioProcessor = getAudioProcessor();
039    
040                    if (audioProcessor == null) {
041                            return null;
042                    }
043    
044                    return audioProcessor.getAudioMimeTypes();
045            }
046    
047            public static AudioProcessor getAudioProcessor() {
048                    return (AudioProcessor)DLProcessorRegistryUtil.getDLProcessor(
049                            DLProcessorConstants.AUDIO_PROCESSOR);
050            }
051    
052            public static InputStream getPreviewAsStream(
053                            FileVersion fileVersion, String type)
054                    throws Exception {
055    
056                    AudioProcessor audioProcessor = getAudioProcessor();
057    
058                    if (audioProcessor == null) {
059                            return null;
060                    }
061    
062                    return audioProcessor.getPreviewAsStream(fileVersion, type);
063            }
064    
065            public static long getPreviewFileSize(FileVersion fileVersion, String type)
066                    throws Exception {
067    
068                    AudioProcessor audioProcessor = getAudioProcessor();
069    
070                    if (audioProcessor == null) {
071                            return 0;
072                    }
073    
074                    return audioProcessor.getPreviewFileSize(fileVersion, type);
075            }
076    
077            public static boolean hasAudio(FileVersion fileVersion) {
078                    AudioProcessor audioProcessor = getAudioProcessor();
079    
080                    if (audioProcessor == null) {
081                            return false;
082                    }
083    
084                    return audioProcessor.hasAudio(fileVersion);
085            }
086    
087            public static boolean isAudioSupported(FileVersion fileVersion) {
088                    AudioProcessor audioProcessor = getAudioProcessor();
089    
090                    if (audioProcessor == null) {
091                            return false;
092                    }
093    
094                    return audioProcessor.isAudioSupported(fileVersion);
095            }
096    
097            public static boolean isAudioSupported(String mimeType) {
098                    AudioProcessor audioProcessor = getAudioProcessor();
099    
100                    if (audioProcessor == null) {
101                            return false;
102                    }
103    
104                    return audioProcessor.isAudioSupported(mimeType);
105            }
106    
107            public static boolean isSupported(String mimeType) {
108                    AudioProcessor audioProcessor = getAudioProcessor();
109    
110                    if (audioProcessor == null) {
111                            return false;
112                    }
113    
114                    return audioProcessor.isSupported(mimeType);
115            }
116    
117            public static void trigger(FileVersion fileVersion) {
118                    AudioProcessor audioProcessor = getAudioProcessor();
119    
120                    if (audioProcessor == null) {
121                            return;
122                    }
123    
124                    audioProcessor.trigger(fileVersion);
125            }
126    
127            /**
128             * @deprecated
129             */
130            public void setAudioProcessor(AudioProcessor audioProcessor) {
131            }
132    
133    }