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.webdav;
016    
017    import com.liferay.portal.kernel.util.HttpUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.util.PropsValues;
021    
022    /**
023     * @author Iv??n Zaera
024     */
025    public class DLWebDAVUtil {
026    
027            public static String escapeRawTitle(String title) {
028                    return StringUtil.replace(
029                            title, StringPool.SLASH, PropsValues.DL_WEBDAV_SUBSTITUTION_CHAR);
030            }
031    
032            public static String escapeURLTitle(String title) {
033                    return HttpUtil.encodeURL(escapeRawTitle(title), true);
034            }
035    
036            public static String getRepresentableTitle(String title, int i) {
037                    return StringUtil.replace(
038                            title, PropsValues.DL_WEBDAV_SUBSTITUTION_CHAR,
039                            StringPool.UNDERLINE + String.valueOf(i) + StringPool.UNDERLINE);
040            }
041    
042            public static boolean isRepresentableTitle(String title) {
043                    return !title.contains(PropsValues.DL_WEBDAV_SUBSTITUTION_CHAR);
044            }
045    
046            public static String unescapeRawTitle(String escapedTitle) {
047                    return StringUtil.replace(
048                            escapedTitle, PropsValues.DL_WEBDAV_SUBSTITUTION_CHAR,
049                            StringPool.SLASH);
050            }
051    
052    }