001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.repository.model.FileEntry;
020    import com.liferay.portal.kernel.repository.model.FileVersion;
021    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
022    
023    /**
024     * Document library processor responsible for the generation of raw metadata
025     * associated with all of the the files stored in the document library.
026     *
027     * <p>
028     * This processor automatically and assynchronously extracts the metadata from
029     * all of the files stored in the document library. The metadata extraction is
030     * done with the help of {@link
031     * com.liferay.portal.metadata.TikaRawMetadataProcessor}
032     * </p>
033     *
034     * @author Alexander Chow
035     * @author Mika Koivisto
036     * @author Miguel Pastor
037     */
038    public class RawMetadataProcessorUtil {
039    
040            public static void cleanUp(FileEntry fileEntry) {
041                    getRawMetadataProcessor().cleanUp(fileEntry);
042            }
043    
044            public static void cleanUp(FileVersion fileVersion) {
045                    getRawMetadataProcessor().cleanUp(fileVersion);
046            }
047    
048            /**
049             * Generates the raw metadata associated with the file entry.
050             *
051             * @param  fileVersion the file version from which the raw metatada is to be
052             *         generated
053             * @throws PortalException if an error occurred in the metadata extraction
054             * @throws SystemException if a system exception occurred
055             */
056            public static void generateMetadata(FileVersion fileVersion)
057                    throws PortalException, SystemException {
058    
059                    getRawMetadataProcessor().generateMetadata(fileVersion);
060            }
061    
062            public static RawMetadataProcessor getRawMetadataProcessor() {
063                    PortalRuntimePermission.checkGetBeanProperty(
064                            RawMetadataProcessorUtil.class);
065    
066                    return _rawMetadataProcessor;
067            }
068    
069            public static boolean isSupported(FileVersion fileVersion) {
070                    return getRawMetadataProcessor().isSupported(fileVersion);
071            }
072    
073            public static boolean isSupported(String mimeType) {
074                    return getRawMetadataProcessor().isSupported(mimeType);
075            }
076    
077            /**
078             * Saves the raw metadata present in the file version.
079             *
080             * <p>
081             * The raw metadata present in the file version is extracted and persisted
082             * using {@link com.liferay.portal.metadata.TikaRawMetadataProcessor}.
083             * </p>
084             *
085             * @param  fileVersion the file version from which the raw metatada is to be
086             *         extracted and persisted
087             * @throws PortalException if an error occurred in the metadata extraction
088             * @throws SystemException if a system exception occurred
089             */
090            public static void saveMetadata(FileVersion fileVersion)
091                    throws PortalException, SystemException {
092    
093                    getRawMetadataProcessor().saveMetadata(fileVersion);
094            }
095    
096            /**
097             * Launches extraction of raw metadata from the file version.
098             *
099             * <p>
100             * The raw metadata extraction is done asynchronously.
101             * </p>
102             *
103             * @param fileVersion the latest file version from which the raw metadata is
104             *        to be generated
105             */
106            public static void trigger(FileVersion fileVersion) {
107                    getRawMetadataProcessor().trigger(fileVersion);
108            }
109    
110            public void setRawMetadataProcessor(
111                    RawMetadataProcessor rawMetadataProcessor) {
112    
113                    PortalRuntimePermission.checkSetBeanProperty(getClass());
114    
115                    _rawMetadataProcessor = rawMetadataProcessor;
116            }
117    
118            private static RawMetadataProcessor _rawMetadataProcessor;
119    
120    }