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