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