[375605] 'New File (HTML/JSP)' wizard uses wrong default location
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java
index 89ee497..e47ed45 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -250,4 +250,45 @@
 
 		return basePath.uptoSegment(1);
 	}
+
+	/**
+	 * Gets the root container for the path in the project
+	 * @param project
+	 * @param path
+	 * @return
+	 */
+	public static IPath getRootContainerForPath(IProject project, IPath path) {
+		if (project == null)
+			return null;
+		IPath root = null;
+		try {
+			root = FacetModuleCoreSupportDelegate.getRootContainerForPath(project, path);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return null;
+		}
+		return root;
+	}
+
+	/**
+	 * Gets the default root container for the project
+	 * @param project
+	 * @return
+	 */
+	public static IPath getDefaultRootContainer(IProject project) {
+		if (project == null)
+			return null;
+		IPath root = null;
+		try {
+			root = FacetModuleCoreSupportDelegate.getDefaultRoot(project);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return null;
+		}
+		return root;
+	}
 }
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java
index 7c2087c..316b503 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse License v1.0
  * which accompanies this distribution, and is available at
@@ -224,4 +224,29 @@
 		}
 		return paths;
 	}
+
+	static IPath getDefaultRoot(IProject project) {
+		if (ModuleCoreNature.isFlexibleProject(project)) {
+			IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+			if (componentFolder != null && componentFolder.exists()) {
+				return componentFolder.getWorkspaceRelativePath();
+			}
+		}
+		return null;
+	}
+
+	static IPath getRootContainerForPath(IProject project, IPath path) {
+		if (ModuleCoreNature.isFlexibleProject(project)) {
+			IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+			if (componentFolder != null && componentFolder.exists()) {
+				IContainer[] workspaceFolders = componentFolder.getUnderlyingFolders();
+				for (int i = 0; i < workspaceFolders.length; i++) {
+					if (workspaceFolders[i].getFullPath().isPrefixOf(path)) {
+						return workspaceFolders[i].getFullPath();
+					}
+				}
+			}
+		}
+		return null;
+	}
 }
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
index f660996..814752b 100644
--- 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 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
@@ -82,12 +82,14 @@
 
 		IPath fullPath = getContainerFullPath();
 		IProject project = getProjectFromPath(fullPath);
-		IPath[] webContentPaths = FacetModuleCoreSupport.getAcceptableRootPaths(project);
-		for (int i = 0; webContentPaths != null && i < webContentPaths.length; i++) {
-			if (!webContentPaths[i].isPrefixOf(fullPath)) {
-				setContainerFullPath(webContentPaths[i]);
-				break;
-			}
+		IPath root = FacetModuleCoreSupport.getRootContainerForPath(project, fullPath);
+		if (root != null) {
+			return;
+		}
+		root = FacetModuleCoreSupport.getDefaultRootContainer(project);
+		if (root != null) {
+			setContainerFullPath(root);
+			return;
 		}
 	}
 
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 a47c807..caa3ea9 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
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2004, 2009 IBM Corporation and others.
+# Copyright (c) 2004, 2012 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
@@ -66,7 +66,7 @@
 _UI_WIZARD_NEW_HEADING = CSS
 _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. 
+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = Files created outside of a 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/FacetModuleCoreSupport.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupport.java
index 636c693..db540b8 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupport.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupport.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -63,5 +63,63 @@
 		return true;
 	}
 
+	/**
+	 * @param project
+	 * @return the IPaths to acceptable "roots" in a project
+	 */
+	public static IPath[] getAcceptableRootPaths(IProject project) {
+		if (project == null)
+			return null;
+		IPath[] paths = null;
+		try {
+			paths = FacetModuleCoreSupportDelegate.getAcceptableRootPaths(project);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return new IPath[]{project.getFullPath()};
+		}
+		return paths;
+	}
 
+	/**
+	 * Gets the root container for the path in the project
+	 * @param project
+	 * @param path
+	 * @return
+	 */
+	public static IPath getRootContainerForPath(IProject project, IPath path) {
+		if (project == null)
+			return null;
+		IPath root = null;
+		try {
+			root = FacetModuleCoreSupportDelegate.getRootContainerForPath(project, path);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return null;
+		}
+		return root;
+	}
+
+	/**
+	 * Gets the default root container for the project
+	 * @param project
+	 * @return
+	 */
+	public static IPath getDefaultRootContainer(IProject project) {
+		if (project == null)
+			return null;
+		IPath root = null;
+		try {
+			root = FacetModuleCoreSupportDelegate.getDefaultRoot(project);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return null;
+		}
+		return root;
+	}
 }
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java
index 1af190f..12ff6f2 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse License v1.0
  * which accompanies this distribution, and is available at
@@ -10,12 +10,15 @@
  *******************************************************************************/
 package org.eclipse.wst.css.ui.internal.wizard;
 
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.wst.common.componentcore.ComponentCore;
 import org.eclipse.wst.common.componentcore.ModuleCoreNature;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
 import org.eclipse.wst.common.project.facet.core.IFacetedProject;
 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -81,4 +84,49 @@
 		}
 		return is;
 	}
+
+	static IPath[] getAcceptableRootPaths(IProject project) {
+		if (!ModuleCoreNature.isFlexibleProject(project)) {
+			return new IPath[]{project.getFullPath()};
+		}
+
+		IPath[] paths = null;
+		IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+		if (componentFolder != null && componentFolder.exists()) {
+			IContainer[] workspaceFolders = componentFolder.getUnderlyingFolders();
+			paths = new IPath[workspaceFolders.length];
+			for (int i = 0; i < workspaceFolders.length; i++) {
+				paths[i] = workspaceFolders[i].getFullPath();
+			}
+		}
+		else {
+			paths = new IPath[]{project.getFullPath()};
+		}
+		return paths;
+	}
+
+	static IPath getDefaultRoot(IProject project) {
+		if (ModuleCoreNature.isFlexibleProject(project)) {
+			IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+			if (componentFolder != null && componentFolder.exists()) {
+				return componentFolder.getWorkspaceRelativePath();
+			}
+		}
+		return null;
+	}
+
+	static IPath getRootContainerForPath(IProject project, IPath path) {
+		if (ModuleCoreNature.isFlexibleProject(project)) {
+			IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+			if (componentFolder != null && componentFolder.exists()) {
+				IContainer[] workspaceFolders = componentFolder.getUnderlyingFolders();
+				for (int i = 0; i < workspaceFolders.length; i++) {
+					if (workspaceFolders[i].getFullPath().isPrefixOf(path)) {
+						return workspaceFolders[i].getFullPath();
+					}
+				}
+			}
+		}
+		return null;
+	}
 }
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
index 5596c3d..ebe9d95 100644
--- 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 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
@@ -77,10 +77,14 @@
 		
 		IPath fullPath = getContainerFullPath();
 		IProject project = getProjectFromPath(fullPath);
-		IPath webContentPath = getWebContentPath(project);
-		
-		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
-			setContainerFullPath(webContentPath);
+		IPath root = FacetModuleCoreSupport.getRootContainerForPath(project, fullPath);
+		if (root != null) {
+			return;
+		}
+		root = FacetModuleCoreSupport.getDefaultRootContainer(project);
+		if (root != null) {
+			setContainerFullPath(root);
+			return;
 		}
 	}
 	
@@ -129,8 +133,12 @@
 			// 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)) {
+				IPath[] webContentPaths = FacetModuleCoreSupport.getAcceptableRootPaths(project);
+				boolean isPrefix = false;
+				for (int i = 0; !isPrefix && i < webContentPaths.length; i++) {
+					isPrefix |= webContentPaths[i].isPrefixOf(fullPath);
+				}
+				if (!isPrefix) {
 					setMessage(CSSUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING);
 				}
 			}
@@ -238,15 +246,5 @@
 	private boolean isWebProject(IProject project) {
 		return FacetModuleCoreSupport.isWebProject(project);
 	}
-	
-	/**
-	 * 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) {
-		return FacetModuleCoreSupport.getWebContentRootPath(project);
-	}
 
 }
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java
index b02801a..352cdfc 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -80,5 +80,44 @@
 		return true;
 	}
 
+	/**
+	 * Gets the root container for the path in the project
+	 * @param project
+	 * @param path
+	 * @return
+	 */
+	public static IPath getRootContainerForPath(IProject project, IPath path) {
+		if (project == null)
+			return null;
+		IPath root = null;
+		try {
+			root = FacetModuleCoreSupportDelegate.getRootContainerForPath(project, path);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return null;
+		}
+		return root;
+	}
 
+	/**
+	 * Gets the default root container for the project
+	 * @param project
+	 * @return
+	 */
+	public static IPath getDefaultRootContainer(IProject project) {
+		if (project == null)
+			return null;
+		IPath root = null;
+		try {
+			root = FacetModuleCoreSupportDelegate.getDefaultRoot(project);
+		}
+		catch (NoClassDefFoundError e) {
+			if (_dump_NCDFE)
+				e.printStackTrace();
+			return null;
+		}
+		return root;
+	}
 }
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java
index 2698791..d0fcd0e 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse License v1.0
  * which accompanies this distribution, and is available at
@@ -104,4 +104,29 @@
 		}
 		return paths;
 	}
+
+	static IPath getDefaultRoot(IProject project) {
+		if (ModuleCoreNature.isFlexibleProject(project)) {
+			IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+			if (componentFolder != null && componentFolder.exists()) {
+				return componentFolder.getWorkspaceRelativePath();
+			}
+		}
+		return null;
+	}
+
+	static IPath getRootContainerForPath(IProject project, IPath path) {
+		if (ModuleCoreNature.isFlexibleProject(project)) {
+			IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
+			if (componentFolder != null && componentFolder.exists()) {
+				IContainer[] workspaceFolders = componentFolder.getUnderlyingFolders();
+				for (int i = 0; i < workspaceFolders.length; i++) {
+					if (workspaceFolders[i].getFullPath().isPrefixOf(path)) {
+						return workspaceFolders[i].getFullPath();
+					}
+				}
+			}
+		}
+		return null;
+	}
 }
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
index 44e414e..39c87ec 100644
--- 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 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
@@ -78,12 +78,14 @@
 
 		IPath fullPath = getContainerFullPath();
 		IProject project = getProjectFromPath(fullPath);
-		IPath[] webContentPaths = FacetModuleCoreSupport.getAcceptableRootPaths(project);
-		for (int i = 0; webContentPaths != null && i < webContentPaths.length; i++) {
-			if (!webContentPaths[i].isPrefixOf(fullPath)) {
-				setContainerFullPath(webContentPaths[i]);
-				break;
-			}
+		IPath root = FacetModuleCoreSupport.getRootContainerForPath(project, fullPath);
+		if (root != null) {
+			return;
+		}
+		root = FacetModuleCoreSupport.getDefaultRootContainer(project);
+		if (root != null) {
+			setContainerFullPath(root);
+			return;
 		}
 	}