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.tools.sourceformatter;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    
019    import java.util.regex.Matcher;
020    import java.util.regex.Pattern;
021    
022    /**
023     * @author Carlos Sierra Andr??s
024     */
025    public class ImportPackageFactoryUtil {
026    
027            public static ImportPackage create(String line) {
028                    if (Validator.isNull(line)) {
029                            return null;
030                    }
031    
032                    Matcher javaMatcher = _javaImportPattern.matcher(line);
033    
034                    if (javaMatcher.find()) {
035                            return new ImportPackage(javaMatcher.group(1), line);
036                    }
037    
038                    Matcher jspMatcher = _jspImportPattern.matcher(line);
039    
040                    if (jspMatcher.find()) {
041                            return new ImportPackage(jspMatcher.group(1), line);
042                    }
043    
044                    return null;
045            }
046    
047            private static final Pattern _javaImportPattern = Pattern.compile(
048                    "import ([^\\s;]+)");
049            private static final Pattern _jspImportPattern = Pattern.compile(
050                    "import=\"([^\\s\"]+)\"");
051    
052    }