[204145] Introduces the UrlPattern utility class.
diff --git a/plugins/org.eclipse.jst.j2ee.web/META-INF/MANIFEST.MF b/plugins/org.eclipse.jst.j2ee.web/META-INF/MANIFEST.MF index ebfbbf0..0d1c222 100644 --- a/plugins/org.eclipse.jst.j2ee.web/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.jst.j2ee.web/META-INF/MANIFEST.MF
@@ -17,7 +17,8 @@ org.eclipse.jst.j2ee.internal.web.validation;x-internal:=true, org.eclipse.jst.j2ee.web.componentcore.util, org.eclipse.jst.j2ee.web.datamodel.properties, - org.eclipse.jst.j2ee.web.project.facet + org.eclipse.jst.j2ee.web.project.facet, + org.eclipse.jst.j2ee.web.validation Require-Bundle: org.eclipse.jst.j2ee;bundle-version="[1.1.0,1.2.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.wst.server.core;bundle-version="[1.0.102,1.1.0)",
diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java index 111f8fe..7df2d48 100644 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java +++ b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java
@@ -28,6 +28,7 @@ import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; import org.eclipse.jst.j2ee.model.IModelProvider; import org.eclipse.jst.j2ee.model.ModelProviderManager; +import org.eclipse.jst.j2ee.web.validation.UrlPattern; import org.eclipse.osgi.util.NLS; import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; @@ -482,49 +483,12 @@ int size = prop.size(); for (int i = 0; i < size; i++) { String urlMappingValue = ((String[]) prop.get(i))[0]; - if (!isURLPatternValid(urlMappingValue)) + if (!UrlPattern.isValid(urlMappingValue)) return urlMappingValue; } return ""; } - private boolean isURLPatternValid(String urlPattern) { - // URL Pattern must not be empty string - if (urlPattern.length() == 0) - return false; - - // URL Pattern must not contain Carriage Return characters - if (urlPattern.indexOf('\r') != -1) - return false; - - // URL Pattern must not contain New Line characters - if (urlPattern.indexOf('\n') != -1) - return false; - - // Path Mappings must not contain "*." character sequences - if (urlPattern.startsWith("/")) { - if (urlPattern.indexOf("*.") == -1) { - return true; - } else { - return false; - } - } - - // Extension Mappings must not contain '/' characters - if (urlPattern.startsWith("*.")) { - if (urlPattern.indexOf('/') == -1) { - return true; - } else { - return false; - } - } - - // The URL Pattern is neither a Path Mapping, nor Extension Mapping - // Therefore, it is invalid - return false; - } - - /** * This method is intended for internal use only. It provides a simple algorithm for detecting * if there are duplicate entries in a list. It will accept a null paramter. It will not return
diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/web/validation/UrlPattern.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/web/validation/UrlPattern.java new file mode 100644 index 0000000..e8f789c --- /dev/null +++ b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/web/validation/UrlPattern.java
@@ -0,0 +1,60 @@ +package org.eclipse.jst.j2ee.web.validation; + +/** + * Utility method for URL patterns. + * + * <p> + * Could be used by components dealing with URL patterns like: Servlet and + * Filter wizards, web.xml validators, etc. + * </p> + * + * @author kraev + */ +public class UrlPattern { + + /** + * Validates an URL pattern. + * + * @param urlPattern + * the string representation of the URL pattern to validate + * + * @return <code>true</code> if the given pattern is a valid one, + * <code>false</code> - otherwise. + */ + public static boolean isValid(String urlPattern) { + // URL Pattern must not be empty string + if (urlPattern.length() == 0) + return false; + + // URL Pattern must not contain Carriage Return characters + if (urlPattern.indexOf('\r') != -1) + return false; + + // URL Pattern must not contain New Line characters + if (urlPattern.indexOf('\n') != -1) + return false; + + // Path Mappings must not contain "*." character sequences + if (urlPattern.startsWith("/")) { + if (urlPattern.indexOf("*.") == -1) { + return true; + } else { + return false; + } + } + + // Extension Mappings must not contain '/' characters + if (urlPattern.startsWith("*.")) { + if (urlPattern.indexOf('/') == -1) { + return true; + } else { + return false; + } + } + + // The URL Pattern is neither a Path Mapping, nor Extension Mapping + // Therefore, it is invalid + return false; + } + +}