[204145] URL mapping validation added to the Servlet wizard.
diff --git a/plugins/org.eclipse.jst.j2ee.web/property_files/web.properties b/plugins/org.eclipse.jst.j2ee.web/property_files/web.properties
index 582c649..265d39a 100644
--- a/plugins/org.eclipse.jst.j2ee.web/property_files/web.properties
+++ b/plugins/org.eclipse.jst.j2ee.web/property_files/web.properties
@@ -17,6 +17,7 @@
ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY=The servlet mapping url pattern cannot be empty.
ERR_SERVLET_MAPPING_URL_PATTERN_EXIST=The servlet mapping url pattern "{0}" already exists.
+ERR_SERVLET_MAPPING_URL_PATTERN_INVALID="{0}" is unresolvable URL mapping. URL mappings should start with "/" or "*.".
KEY_3=The filter mapping url pattern cannot be empty.
KEY_4=The filter mapping url pattern "{0}" already exists.
KEY_5=The filter mapping servlet cannot be empty.
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 48896af..f5a93a8 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
@@ -27,6 +27,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.osgi.util.NLS;
import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
@@ -406,6 +407,12 @@
String msg = WebMessages.ERR_DUPLICATED_URL_MAPPING;
return WTPCommonPlugin.createErrorStatus(msg);
}
+ String isValidValue = validateValue(prop);
+ if (isValidValue != null && isValidValue.length() > 0) {
+ NLS.bind(WebMessages.ERR_SERVLET_MAPPING_URL_PATTERN_INVALID, isValidValue);
+ String resourceString = WebMessages.getResourceString(WebMessages.ERR_SERVLET_MAPPING_URL_PATTERN_INVALID, new String[]{isValidValue});
+ return WTPCommonPlugin.createWarningStatus(resourceString);
+ }
} else {
String msg = WebMessages.ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY;
return WTPCommonPlugin.createErrorStatus(msg);
@@ -413,6 +420,38 @@
// Return OK
return WTPCommonPlugin.OK_STATUS;
}
+
+ /**
+ * This method is intended for internal use only. It provides a simple algorithm for detecting
+ * if there are invalid pattern's value in a list. It will accept a null parameter.
+ *
+ * @see NewServletClassDataModelProvider#validateURLMappingList(List)
+ *
+ * @param input
+ * @return String first invalid pattern's value?
+ */
+ private String validateValue(List prop) {
+ if (prop == null) {
+ return "";
+ }
+ String urlPatternValue = "";
+ int size = prop.size();
+ for (int i = 0; i < size; i++) {
+ String urlMappingValue = ((String[]) prop.get(i))[0];
+ // correct pattern beginning with a /
+ boolean isSlashCorrect = urlMappingValue.startsWith("/");
+ // correct pattern beginning with a *.
+ boolean isAsteriskCorrect = urlMappingValue.startsWith("*.") && urlMappingValue.length() > 2;
+
+ if (!isSlashCorrect && !isAsteriskCorrect) {
+ // no correct pattern
+ urlPatternValue = urlMappingValue;
+ break;
+ }
+ }
+ return urlPatternValue;
+ }
+
/**
* This method is intended for internal use only. It provides a simple algorithm for detecting
diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java
index 815aa69..c0f408d 100644
--- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java
+++ b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java
@@ -41,6 +41,7 @@
public static String ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY;
public static String ERR_SERVLET_MAPPING_URL_PATTERN_EXIST;
+ public static String ERR_SERVLET_MAPPING_URL_PATTERN_INVALID;
public static String KEY_3;
public static String KEY_4;
public static String KEY_5;