001    /**
002     * Copyright (c) 2000-2013 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.antivirus;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    
020    import java.io.File;
021    import java.io.InputStream;
022    
023    /**
024     * @author Michael C. Han
025     * @author Raymond Aug??
026     */
027    public class AntivirusScannerUtil {
028    
029            public static AntivirusScanner getAntivirusScanner() {
030                    PortalRuntimePermission.checkGetBeanProperty(
031                            AntivirusScannerUtil.class);
032    
033                    return _antivirusScanner;
034            }
035    
036            public static boolean isActive() {
037                    AntivirusScanner antivirusScanner = getAntivirusScanner();
038    
039                    if (antivirusScanner == null) {
040                            return false;
041                    }
042    
043                    return antivirusScanner.isActive();
044            }
045    
046            public static void scan(byte[] bytes)
047                    throws AntivirusScannerException, SystemException {
048    
049                    if (isActive()) {
050                            getAntivirusScanner().scan(bytes);
051                    }
052            }
053    
054            public static void scan(File file)
055                    throws AntivirusScannerException, SystemException {
056    
057                    if (isActive()) {
058                            getAntivirusScanner().scan(file);
059                    }
060            }
061    
062            public static void scan(InputStream inputStream)
063                    throws AntivirusScannerException, SystemException {
064    
065                    if (isActive()) {
066                            getAntivirusScanner().scan(inputStream);
067                    }
068            }
069    
070            public void setAntivirusScanner(AntivirusScanner antiVirusScanner) {
071                    PortalRuntimePermission.checkSetBeanProperty(getClass());
072    
073                    _antivirusScanner = antiVirusScanner;
074            }
075    
076            private static AntivirusScanner _antivirusScanner;
077    
078    }