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.portal.tools;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.model.ModelHintsConstants;
020    
021    import java.io.File;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Raymond Aug??
026     * @author Eduardo Lundgren
027     * @author Shuyang Zhou
028     */
029    public class CSSBuilderUtil {
030    
031            public static File getCacheFile(String fileName) {
032                    return getCacheFile(fileName, StringPool.BLANK);
033            }
034    
035            public static File getCacheFile(String fileName, String suffix) {
036                    return new File(getCacheFileName(fileName, suffix));
037            }
038    
039            public static String getCacheFileName(String fileName, String suffix) {
040                    String cacheFileName = StringUtil.replace(
041                            fileName, StringPool.BACK_SLASH, StringPool.SLASH);
042    
043                    int x = cacheFileName.lastIndexOf(StringPool.SLASH);
044                    int y = cacheFileName.lastIndexOf(StringPool.PERIOD);
045    
046                    return cacheFileName.substring(0, x + 1) + ".sass-cache/" +
047                            cacheFileName.substring(x + 1, y) + suffix +
048                            cacheFileName.substring(y);
049            }
050    
051            public static String getRtlCustomFileName(String fileName) {
052                    int pos = fileName.lastIndexOf(StringPool.PERIOD);
053    
054                    return fileName.substring(0, pos) + "_rtl" + fileName.substring(pos);
055            }
056    
057            public static String parseStaticTokens(String content) {
058                    return StringUtil.replace(
059                            content,
060                            new String[] {
061                                    "@model_hints_constants_text_display_height@",
062                                    "@model_hints_constants_text_display_width@",
063                                    "@model_hints_constants_textarea_display_height@",
064                                    "@model_hints_constants_textarea_display_width@"
065                            },
066                            new String[] {
067                                    ModelHintsConstants.TEXT_DISPLAY_HEIGHT,
068                                    ModelHintsConstants.TEXT_DISPLAY_WIDTH,
069                                    ModelHintsConstants.TEXTAREA_DISPLAY_HEIGHT,
070                                    ModelHintsConstants.TEXTAREA_DISPLAY_WIDTH
071                            });
072            }
073    
074    }