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.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    }