[140752] wizards: create html/jsp/css/js files outside the webcontent dir
diff --git a/bundles/org.eclipse.jst.jsp.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.jst.jsp.ui/META-INF/MANIFEST.MF
index 79be696..b3acf28 100644
--- a/bundles/org.eclipse.jst.jsp.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.jst.jsp.ui/META-INF/MANIFEST.MF
@@ -58,5 +58,7 @@
  org.eclipse.ui.ide,
  org.eclipse.wst.javascript.ui,
  org.eclipse.ui.views,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.wst.common.modulecore,
  com.ibm.icu
 Eclipse-LazyStart: true
diff --git a/bundles/org.eclipse.jst.jsp.ui/plugin.xml b/bundles/org.eclipse.jst.jsp.ui/plugin.xml
index 83bb063..4672b6e 100644
--- a/bundles/org.eclipse.jst.jsp.ui/plugin.xml
+++ b/bundles/org.eclipse.jst.jsp.ui/plugin.xml
@@ -420,24 +420,11 @@
         wizardId="org.eclipse.jst.jsp.ui.internal.wizard.NewJSPWizard">
 			<enablement>
 				<or>
-					 
-		           <adapt type="org.eclipse.core.resources.IProject">
-		           	  <or>
-			              <test
-			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
-			                    value="wst.web"/>
-			              <test
-			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
-			                    value="jst.web"/>
-			          </or>
-		           </adapt>
-
-					<instanceof
-						value="org.eclipse.core.resources.IFolder" />
-
-					<instanceof
-						value="org.eclipse.core.resources.IFile" /> 				
-
+					<adapt type="org.eclipse.core.resources.IResource">
+						<test
+							property="org.eclipse.wst.common.project.facet.core.projectFacet"
+							value="jst.web"/>
+					</adapt>
 				</or>
 			</enablement>
 		</commonWizard>
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java
index d1c4d2d..338b245 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java
@@ -61,6 +61,8 @@
 	public static String _UI_WIZARD_NEW_HEADING;
 	public static String _UI_WIZARD_NEW_DESCRIPTION;
 	public static String _ERROR_FILENAME_MUST_END_JSP;
+	public static String _WARNING_FILE_MUST_BE_INSIDE_JAVA_PROJECT;
+	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT;
 	public static String ResourceGroup_nameExists;
 	public static String NewJSPTemplatesWizardPage_0;
 	public static String NewJSPTemplatesWizardPage_1;
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties
index 0ba3223..85cfe32 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties
@@ -36,7 +36,9 @@
 _UI_WIZARD_NEW_TITLE = New JavaServer Page
 _UI_WIZARD_NEW_HEADING = JavaServer Page
 _UI_WIZARD_NEW_DESCRIPTION = Create a new JavaServer Page.
-_ERROR_FILENAME_MUST_END_JSP = The file name must end in one of the following extensions {0}.
+_ERROR_FILENAME_MUST_END_JSP = The file name must end in one of the following extensions {0}. 
+_WARNING_FILE_MUST_BE_INSIDE_JAVA_PROJECT = JavaServer Pages created in projects that do not support Java might not work as expected. 
+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = Files created outside of the Web Content folder will not be included in your deployed Web application. 
 ResourceGroup_nameExists = The same name already exists.
 NewJSPTemplatesWizardPage_0=Select JSP Template
 NewJSPTemplatesWizardPage_1=Select a template as initial content in the JSP page.
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java
new file mode 100644
index 0000000..068aae5
--- /dev/null
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.jsp.ui.internal.wizard;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
+import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
+import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
+import org.eclipse.jst.jsp.ui.internal.JSPUIMessages;
+import org.eclipse.jst.jsp.ui.internal.Logger;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+class NewJSPFileWizardPage extends WizardNewFileCreationPage {
+
+	private IContentType fContentType;
+	private List fValidExtensions = null;
+
+	public NewJSPFileWizardPage(String pageName, IStructuredSelection selection) {
+		super(pageName, selection);
+	}
+
+	/**
+	 * This method is overriden to set the selected folder to web contents
+	 * folder if the current selection is outside the web contents folder.
+	 */
+	protected void initialPopulateContainerNameField() {
+		super.initialPopulateContainerNameField();
+
+		IPath fullPath = getContainerFullPath();
+		IProject project = getProjectFromPath(fullPath);
+		IPath webContentPath = getWebContentPath(project);
+
+		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
+			setContainerFullPath(webContentPath);
+		}
+	}
+
+	/**
+	 * This method is overriden to set additional validation specific to jsp
+	 * files.
+	 */
+	protected boolean validatePage() {
+		setMessage(null);
+		setErrorMessage(null);
+
+		if (!super.validatePage()) {
+			return false;
+		}
+
+		String fileName = getFileName();
+		IPath fullPath = getContainerFullPath();
+		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
+			// check that filename does not contain invalid extension
+			if (!extensionValidForContentType(fileName)) {
+				setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString()));
+				return false;
+			}
+			// no file extension specified so check adding default
+			// extension doesn't equal a file that already exists
+			if (fileName.lastIndexOf('.') == -1) {
+				String newFileName = addDefaultExtension(fileName);
+				IPath resourcePath = fullPath.append(newFileName);
+
+				IWorkspace workspace = ResourcesPlugin.getWorkspace();
+				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
+				if (!result.isOK()) {
+					// path invalid
+					setErrorMessage(result.getMessage());
+					return false;
+				}
+
+				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
+					setErrorMessage(JSPUIMessages.ResourceGroup_nameExists);
+					return false;
+				}
+			}
+
+			// get the IProject for the selection path
+			IProject project = getProjectFromPath(fullPath);
+			if (project != null) {
+				if (!isJavaProject(project)) {
+					setMessage(JSPUIMessages._WARNING_FILE_MUST_BE_INSIDE_JAVA_PROJECT, WARNING);
+				}
+				// if inside web project, check if inside webContent folder
+				if (isDynamicWebProject(project)) {
+					// check that the path is inside the webContent folder
+					IPath webContentPath = getWebContentPath(project);
+					if (!webContentPath.isPrefixOf(fullPath)) {
+						setMessage(JSPUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING);
+					}
+				}
+			}
+		}
+
+		return true;
+	}
+
+	/**
+	 * Adds default extension to the filename
+	 * 
+	 * @param filename
+	 * @return
+	 */
+	String addDefaultExtension(String filename) {
+		StringBuffer newFileName = new StringBuffer(filename);
+
+		Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences();
+		String ext = preference.getString(JSPCorePreferenceNames.DEFAULT_EXTENSION);
+
+		newFileName.append("."); //$NON-NLS-1$
+		newFileName.append(ext);
+
+		return newFileName.toString();
+	}
+
+	/**
+	 * Get content type associated with this new file wizard
+	 * 
+	 * @return IContentType
+	 */
+	private IContentType getContentType() {
+		if (fContentType == null)
+			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP);
+		return fContentType;
+	}
+
+	/**
+	 * Get list of valid extensions for JSP Content type
+	 * 
+	 * @return
+	 */
+	private List getValidExtensions() {
+		if (fValidExtensions == null) {
+			IContentType type = getContentType();
+			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
+		}
+		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
+	 */
+	private 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;
+	}
+
+	/**
+	 * Returns the project that contains the specified path
+	 * 
+	 * @param path
+	 *            the path which project is needed
+	 * @return IProject object. If path is <code>null</code> the return
+	 *         value is also <code>null</code>.
+	 */
+	private IProject getProjectFromPath(IPath path) {
+		IWorkspace workspace = ResourcesPlugin.getWorkspace();
+		IProject project = null;
+
+		if (path != null) {
+			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
+				project = workspace.getRoot().getProject(path.toString());
+			}
+			else {
+				project = workspace.getRoot().getFile(path).getProject();
+			}
+		}
+
+		return project;
+	}
+
+	/**
+	 * Checks if the specified project is a web project.
+	 * 
+	 * @param project
+	 *            project to be checked
+	 * @return true if the project is web project, otherwise false
+	 */
+	private boolean isDynamicWebProject(IProject project) {
+		IFacetedProject faceted = null;
+		try {
+			faceted = ProjectFacetsManager.create(project);
+		}
+		catch (CoreException e) {
+			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
+		}
+
+		if (faceted != null && faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE))) {
+			return true;
+		}
+
+		return false;
+	}
+
+	/**
+	 * Checks if the specified project is a type of java project.
+	 * 
+	 * @param project
+	 *            project to be checked (cannot be null)
+	 * @return true if the project is a type of java project, otherwise false
+	 */
+	private boolean isJavaProject(IProject project) {
+		boolean isJava = false;
+		try {
+			isJava = project.hasNature(JavaCore.NATURE_ID);
+		}
+		catch (CoreException e) {
+			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
+		}
+
+		return isJava;
+	}
+
+	/**
+	 * Returns the web contents folder of the specified project
+	 * 
+	 * @param project
+	 *            the project which web contents path is needed
+	 * @return IPath of the web contents folder
+	 */
+	private IPath getWebContentPath(IProject project) {
+		IPath path = null;
+
+		if (project != null && isDynamicWebProject(project)) {
+			IVirtualComponent component = ComponentCore.createComponent(project);
+			path = component.getRootFolder().getWorkspaceRelativePath();
+		}
+
+		return path;
+	}
+}
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 f670de6..d152057 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
@@ -13,153 +13,35 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
-import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
-import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
 import org.eclipse.jst.jsp.ui.internal.JSPUIMessages;
 import org.eclipse.jst.jsp.ui.internal.Logger;
 import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper;
 import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages;
-import org.eclipse.osgi.util.NLS;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
 
 public class NewJSPWizard extends Wizard implements INewWizard {
-	private WizardNewFileCreationPage fNewFilePage;
+	private NewJSPFileWizardPage fNewFilePage;
 	private NewJSPTemplatesWizardPage fNewFileTemplatesPage;
 	private IStructuredSelection fSelection;
-	private IContentType fContentType;
-	private List fValidExtensions = null;
-
-	/**
-	 * Adds default extension to the filename
-	 * 
-	 * @param filename
-	 * @return
-	 */
-	String addDefaultExtension(String filename) {
-		StringBuffer newFileName = new StringBuffer(filename);
-
-		Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences();
-		String ext = preference.getString(JSPCorePreferenceNames.DEFAULT_EXTENSION);
-
-		newFileName.append("."); //$NON-NLS-1$
-		newFileName.append(ext);
-
-		return newFileName.toString();
-	}
-
-	/**
-	 * Get content type associated with this new file wizard
-	 * 
-	 * @return IContentType
-	 */
-	IContentType getContentType() {
-		if (fContentType == null)
-			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP);
-		return fContentType;
-	}
-
-	/**
-	 * Get list of valid extensions for JSP Content type
-	 * 
-	 * @return
-	 */
-	List getValidExtensions() {
-		if (fValidExtensions == null) {
-			IContentType type = getContentType();
-			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
-		}
-		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() {
-				String fileName = getFileName();
-				IPath fullPath = getContainerFullPath();
-				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
-					// check that filename does not contain invalid extension
-					if (!extensionValidForContentType(fileName)) {
-						setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString()));
-						return false;
-					}
-					// no file extension specified so check adding default
-					// extension doesn't equal a file that already exists
-					if (fileName.lastIndexOf('.') == -1) {
-						String newFileName = addDefaultExtension(fileName);
-						IPath resourcePath = fullPath.append(newFileName);
-
-						IWorkspace workspace = ResourcesPlugin.getWorkspace();
-						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
-						if (!result.isOK()) {
-							// path invalid
-							setErrorMessage(result.getMessage());
-							return false;
-						}
-
-						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
-							setErrorMessage(JSPUIMessages.ResourceGroup_nameExists);
-							return false;
-						}
-					}
-				}
-				setErrorMessage(null);
-				return super.validatePage();
-			}
-		};
+		fNewFilePage = new NewJSPFileWizardPage("JSPWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))); //$NON-NLS-1$ 
 		fNewFilePage.setTitle(JSPUIMessages._UI_WIZARD_NEW_HEADING);
 		fNewFilePage.setDescription(JSPUIMessages._UI_WIZARD_NEW_DESCRIPTION);
-
 		addPage(fNewFilePage);
 
 		fNewFileTemplatesPage = new NewJSPTemplatesWizardPage();
@@ -199,7 +81,7 @@
 		// no file extension specified so add default extension
 		String fileName = fNewFilePage.getFileName();
 		if (fileName.lastIndexOf('.') == -1) {
-			String newFileName = addDefaultExtension(fileName);
+			String newFileName = fNewFilePage.addDefaultExtension(fileName);
 			fNewFilePage.setFileName(newFileName);
 		}
 
diff --git a/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF
index a2eb6aa..c8fb87d 100644
--- a/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF
@@ -43,5 +43,7 @@
  org.eclipse.core.resources,
  org.eclipse.core.runtime,
  org.eclipse.ui.ide,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.wst.common.modulecore,
  com.ibm.icu
 Eclipse-LazyStart: true
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java
index 94cec38..ab4fb2a 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java
@@ -69,6 +69,7 @@
 	public static String _UI_WIZARD_NEW_HEADING;
 	public static String _UI_WIZARD_NEW_DESCRIPTION;
 	public static String _ERROR_FILENAME_MUST_END_CSS;
+	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT;
 	public static String Title_InvalidValue;
 	public static String Message_InvalidValue;
 	public static String FormatMenu_label;
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties
index 64a1c80..f192d05 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties
@@ -56,6 +56,7 @@
 _UI_WIZARD_NEW_HEADING = Cascading Style Sheet
 _UI_WIZARD_NEW_DESCRIPTION = Create a new CSS file.
 _ERROR_FILENAME_MUST_END_CSS = The file name must end in one of the following extensions {0}.
+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = Files created outside of the Web Content folder will not be included in your deployed Web application. 
 #
 Title_InvalidValue=Invalid Value
 Message_InvalidValue=Invalid property value.
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java
new file mode 100644
index 0000000..6c73061
--- /dev/null
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *     
+ *******************************************************************************/
+package org.eclipse.wst.css.ui.internal.wizard;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.css.core.internal.CSSCorePlugin;
+import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames;
+import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS;
+import org.eclipse.wst.css.ui.internal.CSSUIMessages;
+import org.eclipse.wst.css.ui.internal.Logger;
+
+class NewCSSFileWizardPage extends WizardNewFileCreationPage {
+
+	private IContentType fContentType;
+	private List fValidExtensions = null;
+	
+	public NewCSSFileWizardPage(String pageName, IStructuredSelection selection) {
+        super(pageName, selection);
+    }
+	
+	/**
+	 * This method is overriden to set the selected folder to web contents 
+	 * folder if the current selection is outside the web contents folder. 
+	 */
+	protected void initialPopulateContainerNameField() {
+		super.initialPopulateContainerNameField();
+		
+		IPath fullPath = getContainerFullPath();
+		IProject project = getProjectFromPath(fullPath);
+		IPath webContentPath = getWebContentPath(project);
+		
+		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
+			setContainerFullPath(webContentPath);
+		}
+	}
+	
+	/**
+	 * This method is overriden to set additional validation specific to 
+	 * css files. 
+	 */
+	protected boolean validatePage() {
+		setMessage(null);
+		setErrorMessage(null);
+		
+		if (!super.validatePage()) {
+			return false;
+		}
+		
+		String fileName = getFileName();
+		IPath fullPath = getContainerFullPath();
+		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
+			// check that filename does not contain invalid extension
+			if (!extensionValidForContentType(fileName)) {
+				setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString()));
+				return false;
+			}
+			// no file extension specified so check adding default
+			// extension doesn't equal a file that already exists
+			if (fileName.lastIndexOf('.') == -1) {
+				String newFileName = addDefaultExtension(fileName);
+				IPath resourcePath = fullPath.append(newFileName);
+
+				IWorkspace workspace = ResourcesPlugin.getWorkspace();
+				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
+				if (!result.isOK()) {
+					// path invalid
+					setErrorMessage(result.getMessage());
+					return false;
+				}
+
+				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
+					setErrorMessage(CSSUIMessages.ResourceGroup_nameExists);
+					return false;
+				}
+			}
+			
+			// get the IProject for the selection path
+			IProject project = getProjectFromPath(fullPath);
+			// if inside web project, check if inside webContent folder
+			if (project != null && isWebProject(project)) {
+				// check that the path is inside the webContent folder
+				IPath webContentPath = getWebContentPath(project);
+				if (!webContentPath.isPrefixOf(fullPath)) {
+					setMessage(CSSUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING);
+				}
+			}
+		}
+
+		return true;
+	}
+	
+	/**
+	 * Get content type associated with this new file wizard
+	 * 
+	 * @return IContentType
+	 */
+	private IContentType getContentType() {
+		if (fContentType == null)
+			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForCSS.ContentTypeID_CSS);
+		return fContentType;
+	}
+
+	/**
+	 * Get list of valid extensions for CSS Content type
+	 * 
+	 * @return
+	 */
+	private List getValidExtensions() {
+		if (fValidExtensions == null) {
+			IContentType type = getContentType();
+			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
+		}
+		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
+	 */
+	private 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;
+	}
+
+	/**
+	 * Adds default extension to the filename
+	 * 
+	 * @param filename
+	 * @return
+	 */
+	String addDefaultExtension(String filename) {
+		StringBuffer newFileName = new StringBuffer(filename);
+
+		Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
+		String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION);
+
+		newFileName.append("."); //$NON-NLS-1$
+		newFileName.append(ext);
+
+		return newFileName.toString();
+	}
+	
+	/**
+	 * Returns the project that contains the specified path
+	 * 
+	 * @param path the path which project is needed
+	 * @return IProject object. If path is <code>null</code> the return value 
+	 * 		   is also <code>null</code>. 
+	 */
+	private IProject getProjectFromPath(IPath path) {
+		IWorkspace workspace = ResourcesPlugin.getWorkspace();
+		IProject project = null;
+		
+		if (path != null) {
+			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
+				project = workspace.getRoot().getProject(path.toString());
+			} else {
+				project = workspace.getRoot().getFile(path).getProject();
+			}
+		}
+		
+		return project;
+	}
+	
+	/**
+	 * Checks if the specified project is a web project. 
+	 * 
+	 * @param project project to be checked
+	 * @return true if the project is web project, otherwise false
+	 */
+	private boolean isWebProject(IProject project) {
+		IFacetedProject faceted = null;
+		try {
+			faceted = ProjectFacetsManager.create(project);
+		} catch (CoreException e) {
+			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
+		}
+		
+		if (faceted != null && 
+			(faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.WST_WEB_MODULE)) || 
+			 faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE)))) {
+			return true;
+		}
+		
+		return false;
+	}
+	
+	/**
+	 * Returns the web contents folder of the specified project
+	 * 
+	 * @param project the project which web contents path is needed
+	 * @return IPath of the web contents folder
+	 */
+	private IPath getWebContentPath(IProject project) {
+		IPath path = null;
+		
+		if (project != null && isWebProject(project)) {			
+			IVirtualComponent component = ComponentCore.createComponent(project);
+			path = component.getRootFolder().getWorkspaceRelativePath();
+		}
+		
+		return path;
+	}
+
+}
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 e811db6..31a6044 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
@@ -14,34 +14,20 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.osgi.util.NLS;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.wst.css.core.internal.CSSCorePlugin;
-import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames;
-import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS;
 import org.eclipse.wst.css.ui.internal.CSSUIMessages;
 import org.eclipse.wst.css.ui.internal.Logger;
 import org.eclipse.wst.css.ui.internal.editor.CSSEditorPluginImages;
@@ -49,118 +35,14 @@
 import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
 
 public class NewCSSWizard extends Wizard implements INewWizard {
-	private WizardNewFileCreationPage fNewFilePage;
+	private NewCSSFileWizardPage fNewFilePage;
 	private NewCSSTemplatesWizardPage fNewFileTemplatesPage;
 	private IStructuredSelection fSelection;
-	private IContentType fContentType;
-	private List fValidExtensions = null;
-
-	/**
-	 * Adds default extension to the filename
-	 * 
-	 * @param filename
-	 * @return
-	 */
-	String addDefaultExtension(String filename) {
-		StringBuffer newFileName = new StringBuffer(filename);
-
-		Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
-		String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION);
-
-		newFileName.append("."); //$NON-NLS-1$
-		newFileName.append(ext);
-
-		return newFileName.toString();
-	}
-
-	/**
-	 * Get content type associated with this new file wizard
-	 * 
-	 * @return IContentType
-	 */
-	IContentType getContentType() {
-		if (fContentType == null)
-			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForCSS.ContentTypeID_CSS);
-		return fContentType;
-	}
-
-	/**
-	 * Get list of valid extensions for CSS Content type
-	 * 
-	 * @return
-	 */
-	List getValidExtensions() {
-		if (fValidExtensions == null) {
-			IContentType type = getContentType();
-			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
-		}
-		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() {
-				String fileName = getFileName();
-				IPath fullPath = getContainerFullPath();
-				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
-					// check that filename does not contain invalid extension
-					if (!extensionValidForContentType(fileName)) {
-						setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString()));
-						return false;
-					}
-					// no file extension specified so check adding default
-					// extension doesn't equal a file that already exists
-					if (fileName.lastIndexOf('.') == -1) {
-						String newFileName = addDefaultExtension(fileName);
-						IPath resourcePath = fullPath.append(newFileName);
-
-						IWorkspace workspace = ResourcesPlugin.getWorkspace();
-						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
-						if (!result.isOK()) {
-							// path invalid
-							setErrorMessage(result.getMessage());
-							return false;
-						}
-
-						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
-							setErrorMessage(CSSUIMessages.ResourceGroup_nameExists);
-							return false;
-						}
-					}
-				}
-				setErrorMessage(null);
-				return super.validatePage();
-			}
-		};
+		fNewFilePage = new NewCSSFileWizardPage("CSSWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))); //$NON-NLS-1$
 		fNewFilePage.setTitle(CSSUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$
 		fNewFilePage.setDescription(CSSUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$
-
 		addPage(fNewFilePage);
 
 		fNewFileTemplatesPage = new NewCSSTemplatesWizardPage();
@@ -199,7 +81,7 @@
 		// no file extension specified so add default extension
 		String fileName = fNewFilePage.getFileName();
 		if (fileName.lastIndexOf('.') == -1) {
-			String newFileName = addDefaultExtension(fileName);
+			String newFileName = fNewFilePage.addDefaultExtension(fileName);
 			fNewFilePage.setFileName(newFileName);
 		}
 
diff --git a/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF
index b91802b..686c3c0 100644
--- a/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF
@@ -46,5 +46,7 @@
  org.eclipse.wst.common.uriresolver,
  org.eclipse.wst.validation,
  org.eclipse.wst.javascript.ui,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.wst.common.modulecore,
  com.ibm.icu
 Eclipse-LazyStart: true
diff --git a/bundles/org.eclipse.wst.html.ui/plugin.xml b/bundles/org.eclipse.wst.html.ui/plugin.xml
index e694ecb..32cb25a 100644
--- a/bundles/org.eclipse.wst.html.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.html.ui/plugin.xml
@@ -318,20 +318,16 @@
         wizardId="org.eclipse.wst.html.ui.internal.wizard.NewHTMLWizard">
 			<enablement>
 				<or>
-					<adapt type="org.eclipse.core.resources.IProject">
-		           	  <or>
-			              <test
-			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
-			                    value="wst.web"/>
-			              <test
-			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
-			                    value="jst.web"/>
-			          </or>
-		           </adapt>
-					<instanceof
-						value="org.eclipse.core.resources.IFolder" />
-					<instanceof
-						value="org.eclipse.core.resources.IFile" /> 
+					<adapt type="org.eclipse.core.resources.IResource">
+						<or>
+							<test
+								property="org.eclipse.wst.common.project.facet.core.projectFacet"
+								value="wst.web"/>
+							<test
+								property="org.eclipse.wst.common.project.facet.core.projectFacet"
+								value="jst.web"/>
+						</or>
+					</adapt>
 				</or>
 			</enablement>
 		</commonWizard>
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java
index 4d6b8ff..5b5b537 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java
@@ -49,6 +49,7 @@
 	public static String _UI_WIZARD_NEW_HEADING;
 	public static String _UI_WIZARD_NEW_DESCRIPTION;
 	public static String _ERROR_FILENAME_MUST_END_HTML;
+	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT;
 	public static String ResourceGroup_nameExists;
 	public static String NewHTMLTemplatesWizardPage_0;
 	public static String NewHTMLTemplatesWizardPage_1;
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties
index a8c46b8..c7be050 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties
@@ -19,6 +19,7 @@
 _UI_WIZARD_NEW_HEADING = HTML Page
 _UI_WIZARD_NEW_DESCRIPTION = Create a new HTML Page.
 _ERROR_FILENAME_MUST_END_HTML = The file name must end in one of the following extensions {0}.
+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = Files created outside of the Web Content folder will not be included in your deployed Web application. 
 ResourceGroup_nameExists = The same name already exists.
 NewHTMLTemplatesWizardPage_0=Select HTML Template
 NewHTMLTemplatesWizardPage_1=Select a template as initial content in the HTML page.
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java
new file mode 100644
index 0000000..e541788
--- /dev/null
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *     
+ *******************************************************************************/
+package org.eclipse.wst.html.ui.internal.wizard;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
+import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
+import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
+import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
+import org.eclipse.wst.html.ui.internal.Logger;
+
+class NewHTMLFileWizardPage extends WizardNewFileCreationPage {
+
+	private IContentType fContentType;
+	private List fValidExtensions = null;
+	
+	public NewHTMLFileWizardPage(String pageName, IStructuredSelection selection) {
+        super(pageName, selection);
+    }
+	
+	/**
+	 * This method is overriden to set the selected folder to web contents 
+	 * folder if the current selection is outside the web contents folder. 
+	 */
+	protected void initialPopulateContainerNameField() {
+		super.initialPopulateContainerNameField();
+		
+		IPath fullPath = getContainerFullPath();
+		IProject project = getProjectFromPath(fullPath);
+		IPath webContentPath = getWebContentPath(project);
+		
+		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
+			setContainerFullPath(webContentPath);
+		}
+	}
+	
+	/**
+	 * This method is overriden to set additional validation specific to 
+	 * html files. 
+	 */
+	protected boolean validatePage() {
+		setMessage(null);
+		setErrorMessage(null);
+		
+		if (!super.validatePage()) {
+			return false;
+		}
+		
+		String fileName = getFileName();
+		IPath fullPath = getContainerFullPath();
+		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
+			// check that filename does not contain invalid extension
+			if (!extensionValidForContentType(fileName)) {
+				setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString()));
+				return false;
+			}
+			// no file extension specified so check adding default
+			// extension doesn't equal a file that already exists
+			if (fileName.lastIndexOf('.') == -1) {
+				String newFileName = addDefaultExtension(fileName);
+				IPath resourcePath = fullPath.append(newFileName);
+
+				IWorkspace workspace = ResourcesPlugin.getWorkspace();
+				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
+				if (!result.isOK()) {
+					// path invalid
+					setErrorMessage(result.getMessage());
+					return false;
+				}
+
+				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
+					setErrorMessage(HTMLUIMessages.ResourceGroup_nameExists);
+					return false;
+				}
+			}
+			
+			// get the IProject for the selection path
+			IProject project = getProjectFromPath(fullPath);
+			// if inside web project, check if inside webContent folder
+			if (project != null && isWebProject(project)) {
+				// check that the path is inside the webContent folder
+				IPath webContentPath = getWebContentPath(project);
+				if (!webContentPath.isPrefixOf(fullPath)) {
+					setMessage(HTMLUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING);
+				}
+			}
+		}
+
+		return true;
+	}
+	
+	/**
+	 * Get content type associated with this new file wizard
+	 * 
+	 * @return IContentType
+	 */
+	private IContentType getContentType() {
+		if (fContentType == null)
+			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML);
+		return fContentType;
+	}
+
+	/**
+	 * Get list of valid extensions for HTML Content type
+	 * 
+	 * @return
+	 */
+	private List getValidExtensions() {
+		if (fValidExtensions == null) {
+			IContentType type = getContentType();
+			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
+		}
+		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
+	 */
+	private 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;
+	}
+
+	/**
+	 * Adds default extension to the filename
+	 * 
+	 * @param filename
+	 * @return
+	 */
+	String addDefaultExtension(String filename) {
+		StringBuffer newFileName = new StringBuffer(filename);
+
+		Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
+		String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION);
+
+		newFileName.append("."); //$NON-NLS-1$
+		newFileName.append(ext);
+
+		return newFileName.toString();
+	}
+	
+	/**
+	 * Returns the project that contains the specified path
+	 * 
+	 * @param path the path which project is needed
+	 * @return IProject object. If path is <code>null</code> the return value 
+	 * 		   is also <code>null</code>. 
+	 */
+	private IProject getProjectFromPath(IPath path) {
+		IWorkspace workspace = ResourcesPlugin.getWorkspace();
+		IProject project = null;
+		
+		if (path != null) {
+			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
+				project = workspace.getRoot().getProject(path.toString());
+			} else {
+				project = workspace.getRoot().getFile(path).getProject();
+			}
+		}
+		
+		return project;
+	}
+	
+	/**
+	 * Checks if the specified project is a web project. 
+	 * 
+	 * @param project project to be checked
+	 * @return true if the project is web project, otherwise false
+	 */
+	private boolean isWebProject(IProject project) {
+		IFacetedProject faceted = null;
+		try {
+			faceted = ProjectFacetsManager.create(project);
+		} catch (CoreException e) {
+			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
+		}
+		
+		if (faceted != null && 
+			(faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.WST_WEB_MODULE)) || 
+			 faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE)))) {
+			return true;
+		}
+		
+		return false;
+	}
+	
+	/**
+	 * Returns the web contents folder of the specified project
+	 * 
+	 * @param project the project which web contents path is needed
+	 * @return IPath of the web contents folder
+	 */
+	private IPath getWebContentPath(IProject project) {
+		IPath path = null;
+		
+		if (project != null && isWebProject(project)) {			
+			IVirtualComponent component = ComponentCore.createComponent(project);
+			path = component.getRootFolder().getWorkspaceRelativePath();
+		}
+		
+		return path;
+	}
+}
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 e012751..7c5741e 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
@@ -13,34 +13,20 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.osgi.util.NLS;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
-import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
-import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
 import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
 import org.eclipse.wst.html.ui.internal.Logger;
 import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper;
@@ -48,119 +34,15 @@
 import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
 
 public class NewHTMLWizard extends Wizard implements INewWizard {
-	private WizardNewFileCreationPage fNewFilePage;
+	
+	private NewHTMLFileWizardPage fNewFilePage;
 	private NewHTMLTemplatesWizardPage fNewFileTemplatesPage;
 	private IStructuredSelection fSelection;
-	private IContentType fContentType;
-	private List fValidExtensions = null;
-
-	/**
-	 * Adds default extension to the filename
-	 * 
-	 * @param filename
-	 * @return
-	 */
-	String addDefaultExtension(String filename) {
-		StringBuffer newFileName = new StringBuffer(filename);
-
-		Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
-		String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION);
-
-		newFileName.append("."); //$NON-NLS-1$
-		newFileName.append(ext);
-
-		return newFileName.toString();
-	}
-
-	/**
-	 * Get content type associated with this new file wizard
-	 * 
-	 * @return IContentType
-	 */
-	IContentType getContentType() {
-		if (fContentType == null)
-			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML);
-		return fContentType;
-	}
-
-	/**
-	 * Get list of valid extensions for HTML Content type
-	 * 
-	 * @return
-	 */
-	List getValidExtensions() {
-		if (fValidExtensions == null) {
-			IContentType type = getContentType();
-			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
-		}
-		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() {
-				String fileName = getFileName();
-				IPath fullPath = getContainerFullPath();
-				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
-					// check that filename does not contain invalid extension
-					if (!extensionValidForContentType(fileName)) {
-						setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString()));
-						return false;
-					}
-					// no file extension specified so check adding default
-					// extension doesn't equal a file that already exists
-					if (fileName.lastIndexOf('.') == -1) {
-						String newFileName = addDefaultExtension(fileName);
-						IPath resourcePath = fullPath.append(newFileName);
-
-						IWorkspace workspace = ResourcesPlugin.getWorkspace();
-						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
-						if (!result.isOK()) {
-							// path invalid
-							setErrorMessage(result.getMessage());
-							return false;
-						}
-
-						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
-							setErrorMessage(HTMLUIMessages.ResourceGroup_nameExists);
-							return false;
-						}
-					}
-				}
-
-				setErrorMessage(null);
-				return super.validatePage();
-			}
-		};
+		fNewFilePage = new NewHTMLFileWizardPage("HTMLWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))); //$NON-NLS-1$
 		fNewFilePage.setTitle(HTMLUIMessages._UI_WIZARD_NEW_HEADING);
 		fNewFilePage.setDescription(HTMLUIMessages._UI_WIZARD_NEW_DESCRIPTION);
-
 		addPage(fNewFilePage);
 
 		fNewFileTemplatesPage = new NewHTMLTemplatesWizardPage();
@@ -199,7 +81,7 @@
 		// no file extension specified so add default extension
 		String fileName = fNewFilePage.getFileName();
 		if (fileName.lastIndexOf('.') == -1) {
-			String newFileName = addDefaultExtension(fileName);
+			String newFileName = fNewFilePage.addDefaultExtension(fileName);
 			fNewFilePage.setFileName(newFileName);
 		}