001
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
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 }