Example usage for com.liferay.portal.util PropsValues DL_STORE_ANTIVIRUS_ENABLED

List of usage examples for com.liferay.portal.util PropsValues DL_STORE_ANTIVIRUS_ENABLED

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues DL_STORE_ANTIVIRUS_ENABLED.

Prototype

boolean DL_STORE_ANTIVIRUS_ENABLED

To view the source code for com.liferay.portal.util PropsValues DL_STORE_ANTIVIRUS_ENABLED.

Click Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension,
        byte[] bytes) throws PortalException, SystemException {

    validate(fileName, validateFileExtension, bytes);

    if (!PropsValues.DL_STORE_ANTIVIRUS_ENABLED) {
        AntivirusScannerUtil.scan(bytes);
    }// ww  w  . j av a  2s  .  co m

    store.addFile(companyId, repositoryId, fileName, bytes);
}

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension,
        File file) throws PortalException, SystemException {

    validate(fileName, validateFileExtension, file);

    if (PropsValues.DL_STORE_ANTIVIRUS_ENABLED) {
        AntivirusScannerUtil.scan(file);
    }/*from   w ww .  ja va2  s.  c  om*/

    store.addFile(companyId, repositoryId, fileName, file);
}

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension,
        InputStream is) throws PortalException, SystemException {

    if (is instanceof ByteArrayFileInputStream) {
        ByteArrayFileInputStream byteArrayFileInputStream = (ByteArrayFileInputStream) is;

        File file = byteArrayFileInputStream.getFile();

        addFile(companyId, repositoryId, fileName, validateFileExtension, file);

        return;/*  ww  w .  j av a2 s .  co  m*/
    }

    validate(fileName, validateFileExtension, is);

    if (!PropsValues.DL_STORE_ANTIVIRUS_ENABLED || !AntivirusScannerUtil.isActive()) {

        store.addFile(companyId, repositoryId, fileName, is);
    } else {
        File tempFile = null;

        try {
            if (is.markSupported()) {
                is.mark(is.available() + 1);

                AntivirusScannerUtil.scan(is);

                is.reset();

                store.addFile(companyId, repositoryId, fileName, is);
            } else {
                tempFile = FileUtil.createTempFile();

                FileUtil.write(tempFile, is);

                AntivirusScannerUtil.scan(tempFile);

                store.addFile(companyId, repositoryId, fileName, tempFile);
            }
        } catch (IOException ioe) {
            throw new SystemException("Unable to scan file " + fileName, ioe);
        } finally {
            if (tempFile != null) {
                tempFile.delete();
            }
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public void updateFile(long companyId, long repositoryId, String fileName, String fileExtension,
        boolean validateFileExtension, String versionLabel, String sourceFileName, File file)
        throws PortalException, SystemException {

    validate(fileName, fileExtension, sourceFileName, validateFileExtension, file);

    if (!PropsValues.DL_STORE_ANTIVIRUS_ENABLED) {
        AntivirusScannerUtil.scan(file);
    }//from w w w  .  j  a  va 2 s .c om

    store.updateFile(companyId, repositoryId, fileName, versionLabel, file);
}

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public void updateFile(long companyId, long repositoryId, String fileName, String fileExtension,
        boolean validateFileExtension, String versionLabel, String sourceFileName, InputStream is)
        throws PortalException, SystemException {

    if (is instanceof ByteArrayFileInputStream) {
        ByteArrayFileInputStream byteArrayFileInputStream = (ByteArrayFileInputStream) is;

        File file = byteArrayFileInputStream.getFile();

        updateFile(companyId, repositoryId, fileName, fileExtension, validateFileExtension, versionLabel,
                sourceFileName, file);//from   w  w w.j  a  v  a2  s .co m

        return;
    }

    validate(fileName, fileExtension, sourceFileName, validateFileExtension, is);

    if (!PropsValues.DL_STORE_ANTIVIRUS_ENABLED || !AntivirusScannerUtil.isActive()) {

        store.updateFile(companyId, repositoryId, fileName, versionLabel, is);
    } else {
        File tempFile = null;

        try {
            if (is.markSupported()) {
                is.mark(is.available() + 1);

                AntivirusScannerUtil.scan(is);

                is.reset();

                store.updateFile(companyId, repositoryId, fileName, versionLabel, is);
            } else {
                tempFile = FileUtil.createTempFile();

                FileUtil.write(tempFile, is);

                AntivirusScannerUtil.scan(tempFile);

                store.updateFile(companyId, repositoryId, fileName, versionLabel, tempFile);
            }
        } catch (IOException ioe) {
            throw new SystemException("Unable to scan file " + fileName, ioe);
        } finally {
            if (tempFile != null) {
                tempFile.delete();
            }
        }
    }
}