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.util;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portlet.documentlibrary.FileExtensionException;
019    import com.liferay.portlet.documentlibrary.FileNameException;
020    import com.liferay.portlet.documentlibrary.FileSizeException;
021    import com.liferay.portlet.documentlibrary.FolderNameException;
022    import com.liferay.portlet.documentlibrary.InvalidFileVersionException;
023    import com.liferay.portlet.documentlibrary.SourceFileNameException;
024    
025    import java.io.File;
026    import java.io.InputStream;
027    
028    /**
029     * @author Adolfo P??rez
030     */
031    public class DLValidatorUtil {
032    
033            public static DLValidator getDLValidator() {
034                    PortalRuntimePermission.checkGetBeanProperty(DLValidatorUtil.class);
035    
036                    return _dlValidator;
037            }
038    
039            public static boolean isValidName(String name) {
040                    return getDLValidator().isValidName(name);
041            }
042    
043            public static final void validateDirectoryName(String directoryName)
044                    throws FolderNameException {
045    
046                    getDLValidator().validateDirectoryName(directoryName);
047            }
048    
049            public static void validateFileExtension(String fileName)
050                    throws FileExtensionException {
051    
052                    getDLValidator().validateFileExtension(fileName);
053            }
054    
055            public static void validateFileName(String fileName)
056                    throws FileNameException {
057    
058                    getDLValidator().validateFileName(fileName);
059            }
060    
061            public static void validateFileSize(String fileName, byte[] bytes)
062                    throws FileSizeException {
063    
064                    getDLValidator().validateFileSize(fileName, bytes);
065            }
066    
067            public static void validateFileSize(String fileName, File file)
068                    throws FileSizeException {
069    
070                    getDLValidator().validateFileSize(fileName, file);
071            }
072    
073            public static void validateFileSize(String fileName, InputStream is)
074                    throws FileSizeException {
075    
076                    getDLValidator().validateFileSize(fileName, is);
077            }
078    
079            public static void validateFileSize(String fileName, long size)
080                    throws FileSizeException {
081    
082                    getDLValidator().validateFileSize(fileName, size);
083            }
084    
085            public static void validateSourceFileExtension(
086                            String fileExtension, String sourceFileName)
087                    throws SourceFileNameException {
088    
089                    getDLValidator().validateSourceFileExtension(
090                            fileExtension, sourceFileName);
091            }
092    
093            public static void validateVersionLabel(String versionLabel)
094                    throws InvalidFileVersionException {
095    
096                    getDLValidator().validateVersionLabel(versionLabel);
097            }
098    
099            public void setDLValidator(DLValidator dlValidator) {
100                    PortalRuntimePermission.checkSetBeanProperty(getClass());
101    
102                    _dlValidator = dlValidator;
103            }
104    
105            private static DLValidator _dlValidator;
106    
107    }