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