001    /**
002     * Copyright (c) 2000-2012 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.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    
022    /**
023     * Document library processor responsible for the generation of raw metadata
024     * associated with all of the the files stored in the document library.
025     *
026     * <p>
027     * This processor automatically and assynchronously extracts the metadata from
028     * all of the files stored in the document library. The metadata extraction is
029     * done with the help of {@link
030     * com.liferay.portal.metadata.TikaRawMetadataProcessor}
031     * </p>
032     *
033     * @author Alexander Chow
034     * @author Mika Koivisto
035     * @author Miguel Pastor
036     */
037    public class RawMetadataProcessorUtil {
038    
039            public static void cleanUp(FileEntry fileEntry) {
040                    getRawMetadataProcessor().cleanUp(fileEntry);
041            }
042    
043            public static void cleanUp(FileVersion fileVersion) {
044                    getRawMetadataProcessor().cleanUp(fileVersion);
045            }
046    
047            /**
048             * Generates the raw metadata associated with the file entry.
049             *
050             * @param  fileVersion the file version from which the raw metatada is to be
051             *         generated
052             * @throws PortalException if an error occurred in the metadata extraction
053             * @throws SystemException if a system exception occurred
054             */
055            public static void generateMetadata(FileVersion fileVersion)
056                    throws PortalException, SystemException {
057    
058                    getRawMetadataProcessor().generateMetadata(fileVersion);
059            }
060    
061            public static RawMetadataProcessor getRawMetadataProcessor() {
062                    return _rawMetadataProcessor;
063            }
064    
065            public static boolean isSupported(FileVersion fileVersion) {
066                    return getRawMetadataProcessor().isSupported(fileVersion);
067            }
068    
069            public static boolean isSupported(String mimeType) {
070                    return getRawMetadataProcessor().isSupported(mimeType);
071            }
072    
073            /**
074             * Saves the raw metadata present in the file version.
075             *
076             * <p>
077             * The raw metadata present in the file version is extracted and persisted
078             * using {@link com.liferay.portal.metadata.TikaRawMetadataProcessor}.
079             * </p>
080             *
081             * @param  fileVersion the file version from which the raw metatada is to be
082             *         extracted and persisted
083             * @throws PortalException if an error occurred in the metadata extraction
084             * @throws SystemException if a system exception occurred
085             */
086            public static void saveMetadata(FileVersion fileVersion)
087                    throws PortalException, SystemException {
088    
089                    getRawMetadataProcessor().saveMetadata(fileVersion);
090            }
091    
092            /**
093             * Launches extraction of raw metadata from the file version.
094             *
095             * <p>
096             * The raw metadata extraction is done asynchronously.
097             * </p>
098             *
099             * @param fileVersion the latest file version from which the raw metadata is
100             *        to be generated
101             */
102            public static void trigger(FileVersion fileVersion) {
103                    getRawMetadataProcessor().trigger(fileVersion);
104            }
105    
106            public void setRawMetadataProcessor(
107                    RawMetadataProcessor rawMetadataProcessor) {
108    
109                    _rawMetadataProcessor = rawMetadataProcessor;
110            }
111    
112            private static RawMetadataProcessor _rawMetadataProcessor;
113    
114    }