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.servlet.filters.dynamiccss;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.regex.PatternFactory;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.util.PropsValues;
022    import com.liferay.rtl.css.RTLCSSConverter;
023    
024    import java.util.regex.Matcher;
025    import java.util.regex.Pattern;
026    
027    /**
028     * @author Eduardo Garcia
029     * @author David Truong
030     */
031    public class RTLCSSUtil {
032    
033            public static String getRtlCss(String fileName, String css)
034                    throws Exception {
035    
036                    String rtlCss = css;
037    
038                    try {
039                            if (_rtlCSSConverter == null) {
040                                    _rtlCSSConverter = new RTLCSSConverter();
041                            }
042    
043                            rtlCss = _rtlCSSConverter.process(rtlCss);
044                    }
045                    catch (Exception e) {
046                            _log.error(
047                                    "Unable to generate RTL version for " + fileName +
048                                            StringPool.COMMA_AND_SPACE + e.getMessage());
049                    }
050    
051                    return rtlCss;
052            }
053    
054            public static boolean isExcludedPath(String filePath) {
055                    for (Pattern pattern : _patterns) {
056                            Matcher matcher = pattern.matcher(filePath);
057    
058                            if (matcher.matches()) {
059                                    return true;
060                            }
061                    }
062    
063                    return false;
064            }
065    
066            private static final Log _log = LogFactoryUtil.getLog(RTLCSSUtil.class);
067    
068            private static final Pattern[] _patterns = PatternFactory.compile(
069                    PropsValues.RTL_CSS_EXCLUDED_PATHS_REGEXP);
070            private static RTLCSSConverter _rtlCSSConverter;
071    
072    }