[129716] New SSE Wizards should allow extensions of subtypes
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java
index acc680d..f670de6 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java
@@ -96,15 +96,40 @@
 		return fValidExtensions;
 	}
 
+	/**
+	 * Verifies if fileName is valid name for content type. Takes base content
+	 * type into consideration.
+	 * 
+	 * @param fileName
+	 * @return true if extension is valid for this content type
+	 */
+	boolean extensionValidForContentType(String fileName) {
+		boolean valid = false;
+
+		IContentType type = getContentType();
+		// there is currently an extension
+		if (fileName.lastIndexOf('.') != -1) {
+			// check what content types are associated with current extension
+			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
+			int i = 0;
+			while (i < types.length && !valid) {
+				valid = types[i].isKindOf(type);
+				++i;
+			}
+		}
+		else
+			valid = true; // no extension so valid
+		return valid;
+	}
+
 	public void addPages() {
 		fNewFilePage = new WizardNewFileCreationPage("JSPWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
 			protected boolean validatePage() {
-				IContentType type = getContentType();
 				String fileName = getFileName();
 				IPath fullPath = getContainerFullPath();
 				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
 					// check that filename does not contain invalid extension
-					if ((fileName.lastIndexOf('.') != -1) && (!type.isAssociatedWith(fileName))) {
+					if (!extensionValidForContentType(fileName)) {
 						setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString()));
 						return false;
 					}
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java
index 09b38cc..e811db6 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java
@@ -96,16 +96,41 @@
 		}
 		return fValidExtensions;
 	}
+	
+	/**
+	 * Verifies if fileName is valid name for content type. Takes base content
+	 * type into consideration.
+	 * 
+	 * @param fileName
+	 * @return true if extension is valid for this content type
+	 */
+	boolean extensionValidForContentType(String fileName) {
+		boolean valid = false;
+
+		IContentType type = getContentType();
+		// there is currently an extension
+		if (fileName.lastIndexOf('.') != -1) {
+			// check what content types are associated with current extension
+			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
+			int i = 0;
+			while (i < types.length && !valid) {
+				valid = types[i].isKindOf(type);
+				++i;
+			}
+		}
+		else
+			valid = true; // no extension so valid
+		return valid;
+	}
 
 	public void addPages() {
 		fNewFilePage = new WizardNewFileCreationPage("CSSWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
 			protected boolean validatePage() {
-				IContentType type = getContentType();
 				String fileName = getFileName();
 				IPath fullPath = getContainerFullPath();
 				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
 					// check that filename does not contain invalid extension
-					if ((fileName.lastIndexOf('.') != -1) && (!type.isAssociatedWith(fileName))) {
+					if (!extensionValidForContentType(fileName)) {
 						setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString()));
 						return false;
 					}
diff --git a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java
index 01b4a9c..de09787 100644
--- a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java
+++ b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java
@@ -97,16 +97,40 @@
 		return fValidExtensions;
 	}
 
+	/**
+	 * Verifies if fileName is valid name for content type. Takes base content
+	 * type into consideration.
+	 * 
+	 * @param fileName
+	 * @return true if extension is valid for this content type
+	 */
+	boolean extensionValidForContentType(String fileName) {
+		boolean valid = false;
 
+		IContentType type = getContentType();
+		// there is currently an extension
+		if (fileName.lastIndexOf('.') != -1) {
+			// check what content types are associated with current extension
+			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
+			int i = 0;
+			while (i < types.length && !valid) {
+				valid = types[i].isKindOf(type);
+				++i;
+			}
+		}
+		else
+			valid = true; // no extension so valid
+		return valid;
+	}
+	
 	public void addPages() {
 		fNewFilePage = new WizardNewFileCreationPage("DTDWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
 			protected boolean validatePage() {
-				IContentType type = getContentType();
 				String fileName = getFileName();
 				IPath fullPath = getContainerFullPath();
 				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
 					// check that filename does not contain invalid extension
-					if ((fileName.lastIndexOf('.') != -1) && (!type.isAssociatedWith(fileName))) {
+					if (!extensionValidForContentType(fileName)) {
 						setErrorMessage(NLS.bind(DTDUIMessages._ERROR_FILENAME_MUST_END_DTD, getValidExtensions().toString()));
 						return false;
 					}
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java
index 020d377..e012751 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java
@@ -95,16 +95,41 @@
 		}
 		return fValidExtensions;
 	}
+	
+	/**
+	 * Verifies if fileName is valid name for content type. Takes base content
+	 * type into consideration.
+	 * 
+	 * @param fileName
+	 * @return true if extension is valid for this content type
+	 */
+	boolean extensionValidForContentType(String fileName) {
+		boolean valid = false;
+
+		IContentType type = getContentType();
+		// there is currently an extension
+		if (fileName.lastIndexOf('.') != -1) {
+			// check what content types are associated with current extension
+			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
+			int i = 0;
+			while (i < types.length && !valid) {
+				valid = types[i].isKindOf(type);
+				++i;
+			}
+		}
+		else
+			valid = true; // no extension so valid
+		return valid;
+	}
 
 	public void addPages() {
 		fNewFilePage = new WizardNewFileCreationPage("HTMLWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
 			protected boolean validatePage() {
-				IContentType type = getContentType();
 				String fileName = getFileName();
 				IPath fullPath = getContainerFullPath();
 				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
 					// check that filename does not contain invalid extension
-					if ((fileName.lastIndexOf('.') != -1) && (!type.isAssociatedWith(fileName))) {
+					if (!extensionValidForContentType(fileName)) {
 						setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString()));
 						return false;
 					}
diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java
index c2163a1..e8de054 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java
@@ -26,6 +26,7 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -272,9 +273,8 @@
 
     protected boolean validatePage() {
 		String fullFileName = getFileName();
-		String fileExtension = (new Path(fullFileName)).getFileExtension();
-		if (fileExtension != null && (!getValidExtensions().contains(fileExtension))) {
-			setErrorMessage(XMLWizardsMessages._ERROR_BAD_FILENAME_EXTENSION);
+		if (!extensionValidForContentType(fullFileName)) {
+			setErrorMessage(NLS.bind(XMLWizardsMessages._ERROR_BAD_FILENAME_EXTENSION, getValidExtensions().toString()));
 			return false;
 		}
 		// no fileExtension, let's check for this file with default file extension
@@ -321,6 +321,32 @@
 		}
 		return fValidExtensions;
 	}
+	
+	/**
+	 * Verifies if fileName is valid name for content type. Takes base content
+	 * type into consideration.
+	 * 
+	 * @param fileName
+	 * @return true if extension is valid for this content type
+	 */
+	boolean extensionValidForContentType(String fileName) {
+		boolean valid = false;
+
+		IContentType type = Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML);
+		// there is currently an extension
+		if (fileName.lastIndexOf('.') != -1) {
+			// check what content types are associated with current extension
+			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
+			int i = 0;
+			while (i < types.length && !valid) {
+				valid = types[i].isKindOf(type);
+				++i;
+			}
+		}
+		else
+			valid = true; // no extension so valid
+		return valid;
+	}
   }
 }