001    /**
002     * Copyright (c) 2000-2013 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.portal.util;
016    
017    import com.liferay.portal.kernel.util.StringUtil;
018    
019    /**
020     * @author Eduardo Lundgren
021     */
022    public class AggregateUtil {
023    
024            public static String updateRelativeURLs(String content, String baseURL) {
025                    content = StringUtil.replace(
026                            content, _CSS_PATH_TYPES, _CSS_PATH_PLACEHOLDERS);
027    
028                    content = StringUtil.replace(
029                            content,
030                            new String[] {
031                                    "[$RELATIVE_1$]", "[$RELATIVE_2$]", "[$RELATIVE_3$]"
032                            },
033                            new String[] {
034                                    "url('" + baseURL, "url(\"" + baseURL, "url(" + baseURL
035                            });
036    
037                    content = StringUtil.replace(
038                            content, _CSS_PATH_PLACEHOLDERS, _CSS_PATH_TYPES);
039    
040                    return content;
041            }
042    
043            private AggregateUtil() {
044            }
045    
046            private static final String[] _CSS_PATH_PLACEHOLDERS = new String[] {
047                    "[$EMPTY_1$]", "[$EMPTY_2$]", "[$EMPTY_3$]", "[$TOKEN_1$]",
048                    "[$TOKEN_2$]", "[$TOKEN_3$]", "[$ABSOLUTE_1$]", "[$ABSOLUTE_2$]",
049                    "[$ABSOLUTE_3$]", "[$ABSOLUTE_4$]", "[$ABSOLUTE_5$]", "[$ABSOLUTE_6$]",
050                    "[$ABSOLUTE_7$]", "[$ABSOLUTE_8$]", "[$ABSOLUTE_9$]", "[$ABSOLUTE_10$]",
051                    "[$ABSOLUTE_11$]", "[$ABSOLUTE_12$]", "[$RELATIVE_1$]",
052                    "[$RELATIVE_2$]", "[$RELATIVE_3$]"
053            };
054    
055            private static final String[] _CSS_PATH_TYPES = new String[] {
056                    "url('')", "url(\"\")", "url()", "url('@",
057                    "url(\"@", "url(@", "url('http://", "url(\"http://", "url(http://",
058                    "url('https://", "url(\"https://", "url(https://", "url('/", "url(\"/",
059                    "url(/", "url('data:", "url(\"data:", "url(data:", "url('", "url(\"",
060                    "url("
061            };
062    
063    }