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.model;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.kernel.util.UnicodeFormatter;
021    
022    /**
023     * <p>
024     * This contains several utility methods for the purpose of determining folder
025     * IDs and data repository IDs as used by back-end data systems like search and
026     * Document Library stores. These repository IDs should not be confused with the
027     * repository ID used by {@link
028     * com.liferay.portal.service.impl.RepositoryServiceImpl}.
029     * </p>
030     *
031     * @author Samuel Kong
032     * @author Alexander Chow
033     */
034    public class DLFolderConstants {
035    
036            public static final long DEFAULT_PARENT_FOLDER_ID = 0;
037    
038            public static final String NAME_GENERAL_RESTRICTIONS = "blank";
039    
040            public static final String NAME_LABEL = "folder-name";
041    
042            public static final int RESTRICTION_TYPE_FILE_ENTRY_TYPES_AND_WORKFLOW = 1;
043    
044            public static final int RESTRICTION_TYPE_INHERIT = 0;
045    
046            public static final int RESTRICTION_TYPE_WORKFLOW = 2;
047    
048            public static String getClassName() {
049                    return DLFolder.class.getName();
050            }
051    
052            /**
053             * Determine the data repository ID from the repository ID and folder ID.
054             * The folder ID may be zero, implying that it is the root folder for the
055             * given repository.
056             */
057            public static long getDataRepositoryId(long repositoryId, long folderId) {
058                    if (folderId != DEFAULT_PARENT_FOLDER_ID) {
059                            return folderId;
060                    }
061                    else {
062                            return repositoryId;
063                    }
064            }
065    
066            /**
067             * Determine the folder ID when no knowledge of it currently exists.
068             */
069            public static long getFolderId(long groupId, long dataRepositoryId) {
070                    if (groupId != dataRepositoryId) {
071                            return dataRepositoryId;
072                    }
073                    else {
074                            return DEFAULT_PARENT_FOLDER_ID;
075                    }
076            }
077    
078            public static String getNameInvalidCharacters(String[] charBlacklist) {
079                    return StringUtil.merge(charBlacklist, StringPool.SPACE);
080            }
081    
082            public static String getNameInvalidEndCharacters(
083                    String[] charLastBlacklist) {
084    
085                    StringBundler sb = new StringBundler(charLastBlacklist.length * 2);
086    
087                    sb.append(StringPool.BLANK);
088    
089                    for (int i = 0; i < charLastBlacklist.length; i++) {
090                            if (charLastBlacklist[i].startsWith("\\u")) {
091                                    sb.append(UnicodeFormatter.parseString(charLastBlacklist[i]));
092                            }
093                            else {
094                                    sb.append(charLastBlacklist[i]);
095                            }
096    
097                            if ((i + 1) < charLastBlacklist.length) {
098                                    sb.append(StringPool.SPACE);
099                            }
100                    }
101    
102                    return sb.toString();
103            }
104    
105            public static String getNameReservedWords(String[] nameBlacklist) {
106                    return StringPool.NULL + StringPool.COMMA_AND_SPACE +
107                            StringUtil.merge(nameBlacklist, StringPool.COMMA_AND_SPACE);
108            }
109    
110    }