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