View | Details | Raw Unified | Return to bug 140752 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java (-122 / +5 lines)
Lines 13-46 Link Here
13
import java.io.ByteArrayInputStream;
13
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayOutputStream;
14
import java.io.ByteArrayOutputStream;
15
import java.io.OutputStreamWriter;
15
import java.io.OutputStreamWriter;
16
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.List;
19
16
20
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IWorkspace;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.Preferences;
28
import org.eclipse.core.runtime.content.IContentType;
29
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.ImageDescriptor;
30
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.wizard.Wizard;
22
import org.eclipse.jface.wizard.Wizard;
33
import org.eclipse.osgi.util.NLS;
34
import org.eclipse.ui.INewWizard;
23
import org.eclipse.ui.INewWizard;
35
import org.eclipse.ui.IWorkbench;
24
import org.eclipse.ui.IWorkbench;
36
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.IWorkbenchPage;
37
import org.eclipse.ui.PartInitException;
26
import org.eclipse.ui.PartInitException;
38
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
40
import org.eclipse.ui.ide.IDE;
28
import org.eclipse.ui.ide.IDE;
41
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
29
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
42
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
43
import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
44
import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
30
import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
45
import org.eclipse.wst.html.ui.internal.Logger;
31
import org.eclipse.wst.html.ui.internal.Logger;
46
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper;
32
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper;
Lines 48-166 Link Here
48
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
34
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
49
35
50
public class NewHTMLWizard extends Wizard implements INewWizard {
36
public class NewHTMLWizard extends Wizard implements INewWizard {
51
	private WizardNewFileCreationPage fNewFilePage;
37
	
38
	private NewHTMLFileWizardPage fNewFilePage;
52
	private NewHTMLTemplatesWizardPage fNewFileTemplatesPage;
39
	private NewHTMLTemplatesWizardPage fNewFileTemplatesPage;
53
	private IStructuredSelection fSelection;
40
	private IStructuredSelection fSelection;
54
	private IContentType fContentType;
55
	private List fValidExtensions = null;
56
57
	/**
58
	 * Adds default extension to the filename
59
	 * 
60
	 * @param filename
61
	 * @return
62
	 */
63
	String addDefaultExtension(String filename) {
64
		StringBuffer newFileName = new StringBuffer(filename);
65
66
		Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
67
		String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION);
68
69
		newFileName.append("."); //$NON-NLS-1$
70
		newFileName.append(ext);
71
72
		return newFileName.toString();
73
	}
74
75
	/**
76
	 * Get content type associated with this new file wizard
77
	 * 
78
	 * @return IContentType
79
	 */
80
	IContentType getContentType() {
81
		if (fContentType == null)
82
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML);
83
		return fContentType;
84
	}
85
86
	/**
87
	 * Get list of valid extensions for HTML Content type
88
	 * 
89
	 * @return
90
	 */
91
	List getValidExtensions() {
92
		if (fValidExtensions == null) {
93
			IContentType type = getContentType();
94
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
95
		}
96
		return fValidExtensions;
97
	}
98
	
99
	/**
100
	 * Verifies if fileName is valid name for content type. Takes base content
101
	 * type into consideration.
102
	 * 
103
	 * @param fileName
104
	 * @return true if extension is valid for this content type
105
	 */
106
	boolean extensionValidForContentType(String fileName) {
107
		boolean valid = false;
108
109
		IContentType type = getContentType();
110
		// there is currently an extension
111
		if (fileName.lastIndexOf('.') != -1) {
112
			// check what content types are associated with current extension
113
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
114
			int i = 0;
115
			while (i < types.length && !valid) {
116
				valid = types[i].isKindOf(type);
117
				++i;
118
			}
119
		}
120
		else
121
			valid = true; // no extension so valid
122
		return valid;
123
	}
124
41
125
	public void addPages() {
42
	public void addPages() {
126
		fNewFilePage = new WizardNewFileCreationPage("HTMLWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
43
		fNewFilePage = new NewHTMLFileWizardPage("NewHTMLTemplatesWizardPage", 
127
			protected boolean validatePage() {
44
				new StructuredSelection(IDE.computeSelectedResources(fSelection)));
128
				String fileName = getFileName();
129
				IPath fullPath = getContainerFullPath();
130
				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
131
					// check that filename does not contain invalid extension
132
					if (!extensionValidForContentType(fileName)) {
133
						setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString()));
134
						return false;
135
					}
136
					// no file extension specified so check adding default
137
					// extension doesn't equal a file that already exists
138
					if (fileName.lastIndexOf('.') == -1) {
139
						String newFileName = addDefaultExtension(fileName);
140
						IPath resourcePath = fullPath.append(newFileName);
141
142
						IWorkspace workspace = ResourcesPlugin.getWorkspace();
143
						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
144
						if (!result.isOK()) {
145
							// path invalid
146
							setErrorMessage(result.getMessage());
147
							return false;
148
						}
149
150
						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
151
							setErrorMessage(HTMLUIMessages.ResourceGroup_nameExists);
152
							return false;
153
						}
154
					}
155
				}
156
157
				setErrorMessage(null);
158
				return super.validatePage();
159
			}
160
		};
161
		fNewFilePage.setTitle(HTMLUIMessages._UI_WIZARD_NEW_HEADING);
45
		fNewFilePage.setTitle(HTMLUIMessages._UI_WIZARD_NEW_HEADING);
162
		fNewFilePage.setDescription(HTMLUIMessages._UI_WIZARD_NEW_DESCRIPTION);
46
		fNewFilePage.setDescription(HTMLUIMessages._UI_WIZARD_NEW_DESCRIPTION);
163
164
		addPage(fNewFilePage);
47
		addPage(fNewFilePage);
165
48
166
		fNewFileTemplatesPage = new NewHTMLTemplatesWizardPage();
49
		fNewFileTemplatesPage = new NewHTMLTemplatesWizardPage();
Lines 199-205 Link Here
199
		// no file extension specified so add default extension
82
		// no file extension specified so add default extension
200
		String fileName = fNewFilePage.getFileName();
83
		String fileName = fNewFilePage.getFileName();
201
		if (fileName.lastIndexOf('.') == -1) {
84
		if (fileName.lastIndexOf('.') == -1) {
202
			String newFileName = addDefaultExtension(fileName);
85
			String newFileName = fNewFilePage.addDefaultExtension(fileName);
203
			fNewFilePage.setFileName(newFileName);
86
			fNewFilePage.setFileName(newFileName);
204
		}
87
		}
205
88
(-)plugin.xml (-13 / +29 lines)
Lines 318-336 Link Here
318
			<enablement>
318
			<enablement>
319
				<or>
319
				<or>
320
					<adapt type="org.eclipse.core.resources.IProject">
320
					<adapt type="org.eclipse.core.resources.IProject">
321
		           	  <or>
321
						<or>
322
			              <test
322
							<test
323
			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
323
								property="org.eclipse.wst.common.project.facet.core.projectFacet"
324
			                    value="wst.web"/>
324
								value="wst.web"/>
325
			              <test
325
							<test
326
			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
326
								property="org.eclipse.wst.common.project.facet.core.projectFacet"
327
			                    value="jst.web"/>
327
								value="jst.web"/>
328
			          </or>
328
						</or>
329
		           </adapt>
329
					</adapt>
330
					<instanceof
330
					<adapt type="org.eclipse.core.resources.IFolder">
331
						value="org.eclipse.core.resources.IFolder" />
331
						<or>
332
					<instanceof
332
							<test 
333
						value="org.eclipse.core.resources.IFile" /> 
333
								property="org.eclipse.wst.common.ui.webContent"
334
								args="wst.web"/>
335
							<test 
336
								property="org.eclipse.wst.common.ui.webContent"
337
								args="jst.web"/>
338
						</or>
339
					</adapt>
340
					<adapt type="org.eclipse.core.resources.IFile">
341
						<or>
342
							<test 
343
								property="org.eclipse.wst.common.ui.webContent"
344
								args="wst.web"/>
345
							<test 
346
								property="org.eclipse.wst.common.ui.webContent"
347
								args="jst.web"/>
348
						</or>
349
					</adapt>
334
				</or>
350
				</or>
335
			</enablement>
351
			</enablement>
336
		</commonWizard>
352
		</commonWizard>
(-)src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties (+2 lines)
Lines 19-24 Link Here
19
_UI_WIZARD_NEW_HEADING = HTML Page
19
_UI_WIZARD_NEW_HEADING = HTML Page
20
_UI_WIZARD_NEW_DESCRIPTION = Create a new HTML Page.
20
_UI_WIZARD_NEW_DESCRIPTION = Create a new HTML Page.
21
_ERROR_FILENAME_MUST_END_HTML = The file name must end in one of the following extensions {0}.
21
_ERROR_FILENAME_MUST_END_HTML = The file name must end in one of the following extensions {0}.
22
_ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT = The folder must be inside Static or Dynamic Web Project.
23
_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS = The folder must be inside the Web Contents folder. 
22
ResourceGroup_nameExists = The same name already exists.
24
ResourceGroup_nameExists = The same name already exists.
23
NewHTMLTemplatesWizardPage_0=Select HTML Template
25
NewHTMLTemplatesWizardPage_0=Select HTML Template
24
NewHTMLTemplatesWizardPage_1=Select a template as initial content in the HTML page.
26
NewHTMLTemplatesWizardPage_1=Select a template as initial content in the HTML page.
(-)src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java (+2 lines)
Lines 49-54 Link Here
49
	public static String _UI_WIZARD_NEW_HEADING;
49
	public static String _UI_WIZARD_NEW_HEADING;
50
	public static String _UI_WIZARD_NEW_DESCRIPTION;
50
	public static String _UI_WIZARD_NEW_DESCRIPTION;
51
	public static String _ERROR_FILENAME_MUST_END_HTML;
51
	public static String _ERROR_FILENAME_MUST_END_HTML;
52
	public static String _ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT;
53
	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS;
52
	public static String ResourceGroup_nameExists;
54
	public static String ResourceGroup_nameExists;
53
	public static String NewHTMLTemplatesWizardPage_0;
55
	public static String NewHTMLTemplatesWizardPage_0;
54
	public static String NewHTMLTemplatesWizardPage_1;
56
	public static String NewHTMLTemplatesWizardPage_1;
(-)META-INF/MANIFEST.MF (-1 / +5 lines)
Lines 45-49 Link Here
45
 org.eclipse.core.runtime,
45
 org.eclipse.core.runtime,
46
 org.eclipse.wst.common.uriresolver,
46
 org.eclipse.wst.common.uriresolver,
47
 org.eclipse.wst.validation,
47
 org.eclipse.wst.validation,
48
 org.eclipse.wst.javascript.ui
48
 org.eclipse.wst.javascript.ui,
49
 org.eclipse.wst.common.project.facet.core,
50
 org.eclipse.wst.common.modulecore,
51
 org.eclipse.emf.ecore,
52
 org.eclipse.wst.common.ui
49
Eclipse-LazyStart: true
53
Eclipse-LazyStart: true
(-)src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java (+249 lines)
Added Link Here
1
package org.eclipse.wst.html.ui.internal.wizard;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.Iterator;
6
import java.util.List;
7
8
import org.eclipse.core.resources.IProject;
9
import org.eclipse.core.resources.IResource;
10
import org.eclipse.core.resources.IWorkspace;
11
import org.eclipse.core.resources.ResourcesPlugin;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
22
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
23
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
24
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
25
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
26
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
27
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
28
import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
29
import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
30
31
public class NewHTMLFileWizardPage extends WizardNewFileCreationPage {
32
33
	private IContentType fContentType;
34
	private List fValidExtensions = null;
35
	
36
	public NewHTMLFileWizardPage(String pageName, IStructuredSelection selection) {
37
        super(pageName, selection);
38
    }
39
	
40
	/**
41
	 * This method is overriden to set the selected folder to web contents 
42
	 * folder if the current selection is outside the web contents folder. 
43
	 */
44
	protected void initialPopulateContainerNameField() {
45
		super.initialPopulateContainerNameField();
46
		
47
		IPath fullPath = getContainerFullPath();
48
		IProject project = getProjectFromPath(fullPath);
49
		IPath webContentPath = getWebContentPath(project);
50
		
51
		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
52
			setContainerFullPath(webContentPath);
53
		}
54
	}
55
	
56
	/**
57
	 * This method is overriden to set additional validation specific to 
58
	 * html files. 
59
	 */
60
	protected boolean validatePage() {
61
		setMessage(null);
62
		setErrorMessage(null);
63
		
64
		if (!super.validatePage()) {
65
			return false;
66
		}
67
		
68
		String fileName = getFileName();
69
		IPath fullPath = getContainerFullPath();
70
		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
71
			// check that filename does not contain invalid extension
72
			if (!extensionValidForContentType(fileName)) {
73
				setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString()));
74
				return false;
75
			}
76
			// no file extension specified so check adding default
77
			// extension doesn't equal a file that already exists
78
			if (fileName.lastIndexOf('.') == -1) {
79
				String newFileName = addDefaultExtension(fileName);
80
				IPath resourcePath = fullPath.append(newFileName);
81
82
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
83
				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
84
				if (!result.isOK()) {
85
					// path invalid
86
					setErrorMessage(result.getMessage());
87
					return false;
88
				}
89
90
				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
91
					setErrorMessage(HTMLUIMessages.ResourceGroup_nameExists);
92
					return false;
93
				}
94
			}
95
			
96
			// get the IProject for the selection path
97
			IProject project = getProjectFromPath(fullPath);
98
			
99
			// check if the project has has web facet
100
			if (!isWebProject(project)) {
101
				setErrorMessage(HTMLUIMessages._ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT);
102
				return false;
103
			}
104
			
105
			// check that the path is inside the webContent folder
106
			IPath webContentPath = getWebContentPath(project);
107
			if (!webContentPath.isPrefixOf(fullPath)) {
108
				setMessage(HTMLUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS, WARNING);
109
			}
110
		}
111
112
		return true;
113
	}
114
	
115
	/**
116
	 * Get content type associated with this new file wizard
117
	 * 
118
	 * @return IContentType
119
	 */
120
	protected IContentType getContentType() {
121
		if (fContentType == null)
122
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML);
123
		return fContentType;
124
	}
125
126
	/**
127
	 * Get list of valid extensions for HTML Content type
128
	 * 
129
	 * @return
130
	 */
131
	protected List getValidExtensions() {
132
		if (fValidExtensions == null) {
133
			IContentType type = getContentType();
134
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
135
		}
136
		return fValidExtensions;
137
	}
138
	
139
	/**
140
	 * Verifies if fileName is valid name for content type. Takes base content
141
	 * type into consideration.
142
	 * 
143
	 * @param fileName
144
	 * @return true if extension is valid for this content type
145
	 */
146
	protected boolean extensionValidForContentType(String fileName) {
147
		boolean valid = false;
148
149
		IContentType type = getContentType();
150
		// there is currently an extension
151
		if (fileName.lastIndexOf('.') != -1) {
152
			// check what content types are associated with current extension
153
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
154
			int i = 0;
155
			while (i < types.length && !valid) {
156
				valid = types[i].isKindOf(type);
157
				++i;
158
			}
159
		}
160
		else
161
			valid = true; // no extension so valid
162
		return valid;
163
	}
164
165
	/**
166
	 * Adds default extension to the filename
167
	 * 
168
	 * @param filename
169
	 * @return
170
	 */
171
	protected String addDefaultExtension(String filename) {
172
		StringBuffer newFileName = new StringBuffer(filename);
173
174
		Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
175
		String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION);
176
177
		newFileName.append("."); //$NON-NLS-1$
178
		newFileName.append(ext);
179
180
		return newFileName.toString();
181
	}
182
	
183
	/**
184
	 * Returns the project that contains the specified path
185
	 * 
186
	 * @param path the path which project is needed
187
	 * @return IProject object. If path is <code>null</code> the return value 
188
	 * 		   is also <code>null</code>. 
189
	 */
190
	protected IProject getProjectFromPath(IPath path) {
191
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
192
		IProject project = null;
193
		
194
		if (path != null) {
195
			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
196
				project = workspace.getRoot().getProject(path.toString());
197
			} else {
198
				project = workspace.getRoot().getFile(path).getProject();
199
			}
200
		}
201
		
202
		return project;
203
	}
204
	
205
	/**
206
	 * Checks if the specified project is a web project. 
207
	 * 
208
	 * @param project project to be checked
209
	 * @return true if the project is web project, otherwise false
210
	 * @throws CoreException thrown when creating IFacetedProject from IProject
211
	 */
212
	protected boolean isWebProject(IProject project) {
213
		IFacetedProject faceted;
214
		try {
215
			faceted = ProjectFacetsManager.create(project);
216
		} catch (CoreException e) {
217
			throw new RuntimeException(e);
218
		}
219
		
220
		if (faceted != null && 
221
			(faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("wst.web")) || 
222
			 faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web")))) {
223
			return true;
224
		}
225
		
226
		return false;
227
	}
228
	
229
	/**
230
	 * Returns the web contents folder of the specified project
231
	 * 
232
	 * @param project the project which web contents path is needed
233
	 * @return IPath of the web contents folder
234
	 */
235
	protected IPath getWebContentPath(IProject project) {
236
		if (project != null && isWebProject(project)) {
237
			List resources = StructureEdit.getStructureEditForRead(project).getComponent().getResources();
238
			Iterator iter = resources.iterator();
239
			while (iter.hasNext()) {
240
				ComponentResource res = (ComponentResource) iter.next();
241
				if (res.getRuntimePath().isRoot()) {
242
					return new Path(project.getFullPath().toString() + res.getSourcePath().toString());
243
				}
244
			}
245
		}
246
		
247
		return null;
248
	}
249
}
(-)src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties (+2 lines)
Lines 37-42 Link Here
37
_UI_WIZARD_NEW_HEADING = JavaServer Page
37
_UI_WIZARD_NEW_HEADING = JavaServer Page
38
_UI_WIZARD_NEW_DESCRIPTION = Create a new JavaServer Page.
38
_UI_WIZARD_NEW_DESCRIPTION = Create a new JavaServer Page.
39
_ERROR_FILENAME_MUST_END_JSP = The file name must end in one of the following extensions {0}.
39
_ERROR_FILENAME_MUST_END_JSP = The file name must end in one of the following extensions {0}.
40
_ERROR_FOLDER_MUST_BE_INSIDE_DYNAMIC_WEB_PROJECT = The folder must be inside Dynamic Web Project. 
41
_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS = The folder must be inside the Web Contents folder. 
40
ResourceGroup_nameExists = The same name already exists.
42
ResourceGroup_nameExists = The same name already exists.
41
NewJSPTemplatesWizardPage_0=Select JSP Template
43
NewJSPTemplatesWizardPage_0=Select JSP Template
42
NewJSPTemplatesWizardPage_1=Select a template as initial content in the JSP page.
44
NewJSPTemplatesWizardPage_1=Select a template as initial content in the JSP page.
(-)src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java (+2 lines)
Lines 61-66 Link Here
61
	public static String _UI_WIZARD_NEW_HEADING;
61
	public static String _UI_WIZARD_NEW_HEADING;
62
	public static String _UI_WIZARD_NEW_DESCRIPTION;
62
	public static String _UI_WIZARD_NEW_DESCRIPTION;
63
	public static String _ERROR_FILENAME_MUST_END_JSP;
63
	public static String _ERROR_FILENAME_MUST_END_JSP;
64
	public static String _ERROR_FOLDER_MUST_BE_INSIDE_DYNAMIC_WEB_PROJECT;
65
	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS;
64
	public static String ResourceGroup_nameExists;
66
	public static String ResourceGroup_nameExists;
65
	public static String NewJSPTemplatesWizardPage_0;
67
	public static String NewJSPTemplatesWizardPage_0;
66
	public static String NewJSPTemplatesWizardPage_1;
68
	public static String NewJSPTemplatesWizardPage_1;
(-)META-INF/MANIFEST.MF (-1 / +5 lines)
Lines 57-61 Link Here
57
 org.eclipse.wst.common.uriresolver,
57
 org.eclipse.wst.common.uriresolver,
58
 org.eclipse.ui.ide,
58
 org.eclipse.ui.ide,
59
 org.eclipse.wst.javascript.ui,
59
 org.eclipse.wst.javascript.ui,
60
 org.eclipse.ui.views
60
 org.eclipse.ui.views,
61
 org.eclipse.wst.common.project.facet.core,
62
 org.eclipse.wst.common.modulecore,
63
 org.eclipse.emf.ecore,
64
 org.eclipse.wst.common.ui
61
Eclipse-LazyStart: true
65
Eclipse-LazyStart: true
(-)src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java (-121 / +4 lines)
Lines 13-165 Link Here
13
import java.io.ByteArrayInputStream;
13
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayOutputStream;
14
import java.io.ByteArrayOutputStream;
15
import java.io.OutputStreamWriter;
15
import java.io.OutputStreamWriter;
16
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.List;
19
16
20
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IWorkspace;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.Preferences;
28
import org.eclipse.core.runtime.content.IContentType;
29
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.ImageDescriptor;
30
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.wizard.Wizard;
22
import org.eclipse.jface.wizard.Wizard;
33
import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
23
import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
34
import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
35
import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
36
import org.eclipse.jst.jsp.ui.internal.JSPUIMessages;
24
import org.eclipse.jst.jsp.ui.internal.JSPUIMessages;
37
import org.eclipse.jst.jsp.ui.internal.Logger;
25
import org.eclipse.jst.jsp.ui.internal.Logger;
38
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper;
26
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper;
39
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages;
27
import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages;
40
import org.eclipse.osgi.util.NLS;
41
import org.eclipse.ui.INewWizard;
28
import org.eclipse.ui.INewWizard;
42
import org.eclipse.ui.IWorkbench;
29
import org.eclipse.ui.IWorkbench;
43
import org.eclipse.ui.IWorkbenchPage;
30
import org.eclipse.ui.IWorkbenchPage;
44
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.PartInitException;
45
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
47
import org.eclipse.ui.ide.IDE;
33
import org.eclipse.ui.ide.IDE;
48
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
34
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
49
35
50
public class NewJSPWizard extends Wizard implements INewWizard {
36
public class NewJSPWizard extends Wizard implements INewWizard {
51
	private WizardNewFileCreationPage fNewFilePage;
37
	private NewJSPFileWizardPage fNewFilePage;
52
	private NewJSPTemplatesWizardPage fNewFileTemplatesPage;
38
	private NewJSPTemplatesWizardPage fNewFileTemplatesPage;
53
	private IStructuredSelection fSelection;
39
	private IStructuredSelection fSelection;
54
	private IContentType fContentType;
55
	private List fValidExtensions = null;
56
57
	/**
58
	 * Adds default extension to the filename
59
	 * 
60
	 * @param filename
61
	 * @return
62
	 */
63
	String addDefaultExtension(String filename) {
64
		StringBuffer newFileName = new StringBuffer(filename);
65
66
		Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences();
67
		String ext = preference.getString(JSPCorePreferenceNames.DEFAULT_EXTENSION);
68
69
		newFileName.append("."); //$NON-NLS-1$
70
		newFileName.append(ext);
71
72
		return newFileName.toString();
73
	}
74
75
	/**
76
	 * Get content type associated with this new file wizard
77
	 * 
78
	 * @return IContentType
79
	 */
80
	IContentType getContentType() {
81
		if (fContentType == null)
82
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP);
83
		return fContentType;
84
	}
85
86
	/**
87
	 * Get list of valid extensions for JSP Content type
88
	 * 
89
	 * @return
90
	 */
91
	List getValidExtensions() {
92
		if (fValidExtensions == null) {
93
			IContentType type = getContentType();
94
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
95
		}
96
		return fValidExtensions;
97
	}
98
99
	/**
100
	 * Verifies if fileName is valid name for content type. Takes base content
101
	 * type into consideration.
102
	 * 
103
	 * @param fileName
104
	 * @return true if extension is valid for this content type
105
	 */
106
	boolean extensionValidForContentType(String fileName) {
107
		boolean valid = false;
108
109
		IContentType type = getContentType();
110
		// there is currently an extension
111
		if (fileName.lastIndexOf('.') != -1) {
112
			// check what content types are associated with current extension
113
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
114
			int i = 0;
115
			while (i < types.length && !valid) {
116
				valid = types[i].isKindOf(type);
117
				++i;
118
			}
119
		}
120
		else
121
			valid = true; // no extension so valid
122
		return valid;
123
	}
124
40
125
	public void addPages() {
41
	public void addPages() {
126
		fNewFilePage = new WizardNewFileCreationPage("JSPWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
42
		fNewFilePage = new NewJSPFileWizardPage("NewJSPTemplatesWizardPage", 
127
			protected boolean validatePage() {
43
				new StructuredSelection(IDE.computeSelectedResources(fSelection)));
128
				String fileName = getFileName();
129
				IPath fullPath = getContainerFullPath();
130
				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
131
					// check that filename does not contain invalid extension
132
					if (!extensionValidForContentType(fileName)) {
133
						setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString()));
134
						return false;
135
					}
136
					// no file extension specified so check adding default
137
					// extension doesn't equal a file that already exists
138
					if (fileName.lastIndexOf('.') == -1) {
139
						String newFileName = addDefaultExtension(fileName);
140
						IPath resourcePath = fullPath.append(newFileName);
141
142
						IWorkspace workspace = ResourcesPlugin.getWorkspace();
143
						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
144
						if (!result.isOK()) {
145
							// path invalid
146
							setErrorMessage(result.getMessage());
147
							return false;
148
						}
149
150
						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
151
							setErrorMessage(JSPUIMessages.ResourceGroup_nameExists);
152
							return false;
153
						}
154
					}
155
				}
156
				setErrorMessage(null);
157
				return super.validatePage();
158
			}
159
		};
160
		fNewFilePage.setTitle(JSPUIMessages._UI_WIZARD_NEW_HEADING);
44
		fNewFilePage.setTitle(JSPUIMessages._UI_WIZARD_NEW_HEADING);
161
		fNewFilePage.setDescription(JSPUIMessages._UI_WIZARD_NEW_DESCRIPTION);
45
		fNewFilePage.setDescription(JSPUIMessages._UI_WIZARD_NEW_DESCRIPTION);
162
163
		addPage(fNewFilePage);
46
		addPage(fNewFilePage);
164
47
165
		fNewFileTemplatesPage = new NewJSPTemplatesWizardPage();
48
		fNewFileTemplatesPage = new NewJSPTemplatesWizardPage();
Lines 199-205 Link Here
199
		// no file extension specified so add default extension
82
		// no file extension specified so add default extension
200
		String fileName = fNewFilePage.getFileName();
83
		String fileName = fNewFilePage.getFileName();
201
		if (fileName.lastIndexOf('.') == -1) {
84
		if (fileName.lastIndexOf('.') == -1) {
202
			String newFileName = addDefaultExtension(fileName);
85
			String newFileName = fNewFilePage.addDefaultExtension(fileName);
203
			fNewFilePage.setFileName(newFileName);
86
			fNewFilePage.setFileName(newFileName);
204
		}
87
		}
205
88
(-)plugin.xml (-18 / +15 lines)
Lines 419-442 Link Here
419
			wizardId="org.eclipse.jst.jsp.ui.internal.wizard.NewJSPWizard">
419
			wizardId="org.eclipse.jst.jsp.ui.internal.wizard.NewJSPWizard">
420
			<enablement>
420
			<enablement>
421
				<or>
421
				<or>
422
					 
422
					<adapt type="org.eclipse.core.resources.IProject">
423
		           <adapt type="org.eclipse.core.resources.IProject">
423
						<test
424
		           	  <or>
424
							property="org.eclipse.wst.common.project.facet.core.projectFacet"
425
			              <test
425
							value="jst.web"/>
426
			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
426
					</adapt>
427
			                    value="wst.web"/>
427
					<adapt type="org.eclipse.core.resources.IFolder">
428
			              <test
428
						<test 
429
			                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
429
							property="org.eclipse.wst.common.ui.webContent"
430
			                    value="jst.web"/>
430
							args="jst.web"/>
431
			          </or>
431
					</adapt>
432
		           </adapt>
432
					<adapt type="org.eclipse.core.resources.IFile">
433
433
						<test 
434
					<instanceof
434
							property="org.eclipse.wst.common.ui.webContent"
435
						value="org.eclipse.core.resources.IFolder" />
435
							args="jst.web"/>
436
436
					</adapt>
437
					<instanceof
438
						value="org.eclipse.core.resources.IFile" /> 				
439
440
				</or>
437
				</or>
441
			</enablement>
438
			</enablement>
442
		</commonWizard>
439
		</commonWizard>
(-)src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java (+248 lines)
Added Link Here
1
package org.eclipse.jst.jsp.ui.internal.wizard;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.Iterator;
6
import java.util.List;
7
8
import org.eclipse.core.resources.IProject;
9
import org.eclipse.core.resources.IResource;
10
import org.eclipse.core.resources.IWorkspace;
11
import org.eclipse.core.resources.ResourcesPlugin;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
21
import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
22
import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
23
import org.eclipse.jst.jsp.ui.internal.JSPUIMessages;
24
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
26
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
27
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
28
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
29
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
30
31
public class NewJSPFileWizardPage extends WizardNewFileCreationPage {
32
	
33
	private IContentType fContentType;
34
	private List fValidExtensions = null;
35
36
	public NewJSPFileWizardPage(String pageName, IStructuredSelection selection) {
37
        super(pageName, selection);
38
    }
39
	
40
	/**
41
	 * This method is overriden to set the selected folder to web contents 
42
	 * folder if the current selection is outside the web contents folder. 
43
	 */
44
	protected void initialPopulateContainerNameField() {
45
		super.initialPopulateContainerNameField();
46
		
47
		IPath fullPath = getContainerFullPath();
48
		IProject project = getProjectFromPath(fullPath);
49
		IPath webContentPath = getWebContentPath(project);
50
		
51
		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
52
			setContainerFullPath(webContentPath);
53
		}
54
	}
55
	
56
	/**
57
	 * This method is overriden to set additional validation specific to 
58
	 * jsp files. 
59
	 */
60
	protected boolean validatePage() {
61
		setMessage(null);
62
		setErrorMessage(null);
63
		
64
		if (!super.validatePage()) {
65
			return false;
66
		}
67
		
68
		String fileName = getFileName();
69
		IPath fullPath = getContainerFullPath();
70
		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
71
			// check that filename does not contain invalid extension
72
			if (!extensionValidForContentType(fileName)) {
73
				setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString()));
74
				return false;
75
			}
76
			// no file extension specified so check adding default
77
			// extension doesn't equal a file that already exists
78
			if (fileName.lastIndexOf('.') == -1) {
79
				String newFileName = addDefaultExtension(fileName);
80
				IPath resourcePath = fullPath.append(newFileName);
81
82
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
83
				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
84
				if (!result.isOK()) {
85
					// path invalid
86
					setErrorMessage(result.getMessage());
87
					return false;
88
				}
89
90
				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
91
					setErrorMessage(JSPUIMessages.ResourceGroup_nameExists);
92
					return false;
93
				}
94
			}
95
			
96
			// get the IProject for the selection path
97
			IProject project = getProjectFromPath(fullPath);
98
			
99
			// check if the project has has web facet
100
			if (!isDynamicWebProject(project)) {
101
				setErrorMessage(JSPUIMessages._ERROR_FOLDER_MUST_BE_INSIDE_DYNAMIC_WEB_PROJECT);
102
				return false;
103
			}
104
			
105
			// check that the path is inside the webContent folder
106
			IPath webContentPath = getWebContentPath(project);
107
			if (!webContentPath.isPrefixOf(fullPath)) {
108
				setMessage(JSPUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS, WARNING);
109
			}
110
		}
111
112
		return true;
113
	}
114
115
	/**
116
	 * Adds default extension to the filename
117
	 * 
118
	 * @param filename
119
	 * @return
120
	 */
121
	protected String addDefaultExtension(String filename) {
122
		StringBuffer newFileName = new StringBuffer(filename);
123
124
		Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences();
125
		String ext = preference.getString(JSPCorePreferenceNames.DEFAULT_EXTENSION);
126
127
		newFileName.append("."); //$NON-NLS-1$
128
		newFileName.append(ext);
129
130
		return newFileName.toString();
131
	}
132
133
	/**
134
	 * Get content type associated with this new file wizard
135
	 * 
136
	 * @return IContentType
137
	 */
138
	protected IContentType getContentType() {
139
		if (fContentType == null)
140
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP);
141
		return fContentType;
142
	}
143
144
	/**
145
	 * Get list of valid extensions for JSP Content type
146
	 * 
147
	 * @return
148
	 */
149
	protected List getValidExtensions() {
150
		if (fValidExtensions == null) {
151
			IContentType type = getContentType();
152
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
153
		}
154
		return fValidExtensions;
155
	}
156
157
	/**
158
	 * Verifies if fileName is valid name for content type. Takes base content
159
	 * type into consideration.
160
	 * 
161
	 * @param fileName
162
	 * @return true if extension is valid for this content type
163
	 */
164
	protected boolean extensionValidForContentType(String fileName) {
165
		boolean valid = false;
166
167
		IContentType type = getContentType();
168
		// there is currently an extension
169
		if (fileName.lastIndexOf('.') != -1) {
170
			// check what content types are associated with current extension
171
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
172
			int i = 0;
173
			while (i < types.length && !valid) {
174
				valid = types[i].isKindOf(type);
175
				++i;
176
			}
177
		}
178
		else
179
			valid = true; // no extension so valid
180
		return valid;
181
	}
182
	
183
	/**
184
	 * Returns the project that contains the specified path
185
	 * 
186
	 * @param path the path which project is needed
187
	 * @return IProject object. If path is <code>null</code> the return value 
188
	 * 		   is also <code>null</code>. 
189
	 */
190
	protected IProject getProjectFromPath(IPath path) {
191
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
192
		IProject project = null;
193
		
194
		if (path != null) {
195
			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
196
				project = workspace.getRoot().getProject(path.toString());
197
			} else {
198
				project = workspace.getRoot().getFile(path).getProject();
199
			}
200
		}
201
		
202
		return project;
203
	}
204
	
205
	/**
206
	 * Checks if the specified project is a web project. 
207
	 * 
208
	 * @param project project to be checked
209
	 * @return true if the project is web project, otherwise false
210
	 * @throws CoreException thrown when creating IFacetedProject from IProject
211
	 */
212
	protected boolean isDynamicWebProject(IProject project) {
213
		IFacetedProject faceted;
214
		try {
215
			faceted = ProjectFacetsManager.create(project);
216
		} catch (CoreException e) {
217
			throw new RuntimeException(e);
218
		}
219
		
220
		if (faceted != null && 
221
			faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web"))) {
222
			return true;
223
		}
224
		
225
		return false;
226
	}
227
	
228
	/**
229
	 * Returns the web contents folder of the specified project
230
	 * 
231
	 * @param project the project which web contents path is needed
232
	 * @return IPath of the web contents folder
233
	 */
234
	protected IPath getWebContentPath(IProject project) {
235
		if (project != null && isDynamicWebProject(project)) {
236
			List resources = StructureEdit.getStructureEditForRead(project).getComponent().getResources();
237
			Iterator iter = resources.iterator();
238
			while (iter.hasNext()) {
239
				ComponentResource res = (ComponentResource) iter.next();
240
				if (res.getRuntimePath().isRoot()) {
241
					return new Path(project.getFullPath().toString() + res.getSourcePath().toString());
242
				}
243
			}
244
		}
245
		
246
		return null;
247
	}
248
}
(-)src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java (+2 lines)
Lines 69-74 Link Here
69
	public static String _UI_WIZARD_NEW_HEADING;
69
	public static String _UI_WIZARD_NEW_HEADING;
70
	public static String _UI_WIZARD_NEW_DESCRIPTION;
70
	public static String _UI_WIZARD_NEW_DESCRIPTION;
71
	public static String _ERROR_FILENAME_MUST_END_CSS;
71
	public static String _ERROR_FILENAME_MUST_END_CSS;
72
	public static String _ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT;
73
	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS;
72
	public static String Title_InvalidValue;
74
	public static String Title_InvalidValue;
73
	public static String Message_InvalidValue;
75
	public static String Message_InvalidValue;
74
	public static String FormatMenu_label;
76
	public static String FormatMenu_label;
(-)src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties (+2 lines)
Lines 56-61 Link Here
56
_UI_WIZARD_NEW_HEADING = Cascading Style Sheet
56
_UI_WIZARD_NEW_HEADING = Cascading Style Sheet
57
_UI_WIZARD_NEW_DESCRIPTION = Create a new CSS file.
57
_UI_WIZARD_NEW_DESCRIPTION = Create a new CSS file.
58
_ERROR_FILENAME_MUST_END_CSS = The file name must end in one of the following extensions {0}.
58
_ERROR_FILENAME_MUST_END_CSS = The file name must end in one of the following extensions {0}.
59
_ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT = The folder must be inside Static or Dynamic Web Project.
60
_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS = The folder must be inside the Web Contents folder. 
59
#
61
#
60
Title_InvalidValue=Invalid Value
62
Title_InvalidValue=Invalid Value
61
Message_InvalidValue=Invalid property value.
63
Message_InvalidValue=Invalid property value.
(-)plugin.xml (+44 lines)
Lines 126-131 Link Here
126
			<selection class="org.eclipse.core.resources.IResource" />
126
			<selection class="org.eclipse.core.resources.IResource" />
127
		</wizard>
127
		</wizard>
128
	</extension>
128
	</extension>
129
	
130
	<!-- Add new CSS wizard to J2EE Project Navigator -->
131
	<extension
132
		id="org.eclipse.wst.css.commonWizard.newCSS"
133
		point="org.eclipse.ui.navigator.navigatorContent">
134
		<commonWizard
135
			type="new"
136
			wizardId="org.eclipse.wst.css.ui.internal.wizard.NewCSSWizard">
137
			<enablement>
138
				<or>
139
					<adapt type="org.eclipse.core.resources.IProject">
140
						<or>
141
							<test
142
								property="org.eclipse.wst.common.project.facet.core.projectFacet"
143
								value="wst.web"/>
144
							<test
145
								property="org.eclipse.wst.common.project.facet.core.projectFacet"
146
								value="jst.web"/>
147
						</or>
148
					</adapt>
149
					<adapt type="org.eclipse.core.resources.IFolder">
150
						<or>
151
							<test 
152
								property="org.eclipse.wst.common.ui.webContent"
153
								args="wst.web"/>
154
							<test 
155
								property="org.eclipse.wst.common.ui.webContent"
156
								args="jst.web"/>
157
						</or>
158
					</adapt>
159
					<adapt type="org.eclipse.core.resources.IFile">
160
						<or>
161
							<test 
162
								property="org.eclipse.wst.common.ui.webContent"
163
								args="wst.web"/>
164
							<test 
165
								property="org.eclipse.wst.common.ui.webContent"
166
								args="jst.web"/>
167
						</or>
168
					</adapt>
169
				</or>
170
			</enablement>
171
		</commonWizard>
172
	</extension>
129
173
130
	<extension point="org.eclipse.ui.popupMenus">
174
	<extension point="org.eclipse.ui.popupMenus">
131
		<viewerContribution
175
		<viewerContribution
(-)META-INF/MANIFEST.MF (-1 / +5 lines)
Lines 42-46 Link Here
42
 org.eclipse.wst.xml.core,
42
 org.eclipse.wst.xml.core,
43
 org.eclipse.core.resources,
43
 org.eclipse.core.resources,
44
 org.eclipse.core.runtime,
44
 org.eclipse.core.runtime,
45
 org.eclipse.ui.ide
45
 org.eclipse.ui.ide,
46
 org.eclipse.wst.common.project.facet.core,
47
 org.eclipse.wst.common.modulecore,
48
 org.eclipse.emf.ecore,
49
 org.eclipse.wst.common.ui
46
Eclipse-LazyStart: true
50
Eclipse-LazyStart: true
(-)src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java (-121 / +4 lines)
Lines 14-47 Link Here
14
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayInputStream;
15
import java.io.ByteArrayOutputStream;
15
import java.io.ByteArrayOutputStream;
16
import java.io.OutputStreamWriter;
16
import java.io.OutputStreamWriter;
17
import java.util.ArrayList;
18
import java.util.Arrays;
19
import java.util.List;
20
17
21
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.IWorkspace;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Platform;
28
import org.eclipse.core.runtime.Preferences;
19
import org.eclipse.core.runtime.Preferences;
29
import org.eclipse.core.runtime.content.IContentType;
30
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
31
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.jface.viewers.StructuredSelection;
33
import org.eclipse.jface.wizard.Wizard;
23
import org.eclipse.jface.wizard.Wizard;
34
import org.eclipse.osgi.util.NLS;
35
import org.eclipse.ui.INewWizard;
24
import org.eclipse.ui.INewWizard;
36
import org.eclipse.ui.IWorkbench;
25
import org.eclipse.ui.IWorkbench;
37
import org.eclipse.ui.IWorkbenchPage;
26
import org.eclipse.ui.IWorkbenchPage;
38
import org.eclipse.ui.PartInitException;
27
import org.eclipse.ui.PartInitException;
39
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
40
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
41
import org.eclipse.ui.ide.IDE;
29
import org.eclipse.ui.ide.IDE;
42
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
30
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
43
import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames;
44
import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS;
45
import org.eclipse.wst.css.ui.internal.CSSUIMessages;
31
import org.eclipse.wst.css.ui.internal.CSSUIMessages;
46
import org.eclipse.wst.css.ui.internal.Logger;
32
import org.eclipse.wst.css.ui.internal.Logger;
47
import org.eclipse.wst.css.ui.internal.editor.CSSEditorPluginImages;
33
import org.eclipse.wst.css.ui.internal.editor.CSSEditorPluginImages;
Lines 49-166 Link Here
49
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
35
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
50
36
51
public class NewCSSWizard extends Wizard implements INewWizard {
37
public class NewCSSWizard extends Wizard implements INewWizard {
52
	private WizardNewFileCreationPage fNewFilePage;
38
	private NewCSSFileWizardPage fNewFilePage;
53
	private NewCSSTemplatesWizardPage fNewFileTemplatesPage;
39
	private NewCSSTemplatesWizardPage fNewFileTemplatesPage;
54
	private IStructuredSelection fSelection;
40
	private IStructuredSelection fSelection;
55
	private IContentType fContentType;
56
	private List fValidExtensions = null;
57
58
	/**
59
	 * Adds default extension to the filename
60
	 * 
61
	 * @param filename
62
	 * @return
63
	 */
64
	String addDefaultExtension(String filename) {
65
		StringBuffer newFileName = new StringBuffer(filename);
66
67
		Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
68
		String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION);
69
70
		newFileName.append("."); //$NON-NLS-1$
71
		newFileName.append(ext);
72
73
		return newFileName.toString();
74
	}
75
76
	/**
77
	 * Get content type associated with this new file wizard
78
	 * 
79
	 * @return IContentType
80
	 */
81
	IContentType getContentType() {
82
		if (fContentType == null)
83
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForCSS.ContentTypeID_CSS);
84
		return fContentType;
85
	}
86
87
	/**
88
	 * Get list of valid extensions for CSS Content type
89
	 * 
90
	 * @return
91
	 */
92
	List getValidExtensions() {
93
		if (fValidExtensions == null) {
94
			IContentType type = getContentType();
95
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
96
		}
97
		return fValidExtensions;
98
	}
99
	
100
	/**
101
	 * Verifies if fileName is valid name for content type. Takes base content
102
	 * type into consideration.
103
	 * 
104
	 * @param fileName
105
	 * @return true if extension is valid for this content type
106
	 */
107
	boolean extensionValidForContentType(String fileName) {
108
		boolean valid = false;
109
110
		IContentType type = getContentType();
111
		// there is currently an extension
112
		if (fileName.lastIndexOf('.') != -1) {
113
			// check what content types are associated with current extension
114
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
115
			int i = 0;
116
			while (i < types.length && !valid) {
117
				valid = types[i].isKindOf(type);
118
				++i;
119
			}
120
		}
121
		else
122
			valid = true; // no extension so valid
123
		return valid;
124
	}
125
41
126
	public void addPages() {
42
	public void addPages() {
127
		fNewFilePage = new WizardNewFileCreationPage("CSSWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
43
		fNewFilePage = new NewCSSFileWizardPage("NewCSSTemplatesWizardPage", 
128
			protected boolean validatePage() {
44
				new StructuredSelection(IDE.computeSelectedResources(fSelection)));
129
				String fileName = getFileName();
130
				IPath fullPath = getContainerFullPath();
131
				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
132
					// check that filename does not contain invalid extension
133
					if (!extensionValidForContentType(fileName)) {
134
						setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString()));
135
						return false;
136
					}
137
					// no file extension specified so check adding default
138
					// extension doesn't equal a file that already exists
139
					if (fileName.lastIndexOf('.') == -1) {
140
						String newFileName = addDefaultExtension(fileName);
141
						IPath resourcePath = fullPath.append(newFileName);
142
143
						IWorkspace workspace = ResourcesPlugin.getWorkspace();
144
						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
145
						if (!result.isOK()) {
146
							// path invalid
147
							setErrorMessage(result.getMessage());
148
							return false;
149
						}
150
151
						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
152
							setErrorMessage(CSSUIMessages.ResourceGroup_nameExists);
153
							return false;
154
						}
155
					}
156
				}
157
				setErrorMessage(null);
158
				return super.validatePage();
159
			}
160
		};
161
		fNewFilePage.setTitle(CSSUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$
45
		fNewFilePage.setTitle(CSSUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$
162
		fNewFilePage.setDescription(CSSUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$
46
		fNewFilePage.setDescription(CSSUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$
163
164
		addPage(fNewFilePage);
47
		addPage(fNewFilePage);
165
48
166
		fNewFileTemplatesPage = new NewCSSTemplatesWizardPage();
49
		fNewFileTemplatesPage = new NewCSSTemplatesWizardPage();
Lines 199-205 Link Here
199
		// no file extension specified so add default extension
82
		// no file extension specified so add default extension
200
		String fileName = fNewFilePage.getFileName();
83
		String fileName = fNewFilePage.getFileName();
201
		if (fileName.lastIndexOf('.') == -1) {
84
		if (fileName.lastIndexOf('.') == -1) {
202
			String newFileName = addDefaultExtension(fileName);
85
			String newFileName = fNewFilePage.addDefaultExtension(fileName);
203
			fNewFilePage.setFileName(newFileName);
86
			fNewFilePage.setFileName(newFileName);
204
		}
87
		}
205
88
(-)src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java (+250 lines)
Added Link Here
1
package org.eclipse.wst.css.ui.internal.wizard;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.Iterator;
6
import java.util.List;
7
8
import org.eclipse.core.resources.IProject;
9
import org.eclipse.core.resources.IResource;
10
import org.eclipse.core.resources.IWorkspace;
11
import org.eclipse.core.resources.ResourcesPlugin;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
22
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
23
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
24
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
25
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
26
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
27
import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames;
28
import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS;
29
import org.eclipse.wst.css.ui.internal.CSSUIMessages;
30
31
public class NewCSSFileWizardPage extends WizardNewFileCreationPage {
32
33
	private IContentType fContentType;
34
	private List fValidExtensions = null;
35
	
36
	public NewCSSFileWizardPage(String pageName, IStructuredSelection selection) {
37
        super(pageName, selection);
38
    }
39
	
40
	/**
41
	 * This method is overriden to set the selected folder to web contents 
42
	 * folder if the current selection is outside the web contents folder. 
43
	 */
44
	protected void initialPopulateContainerNameField() {
45
		super.initialPopulateContainerNameField();
46
		
47
		IPath fullPath = getContainerFullPath();
48
		IProject project = getProjectFromPath(fullPath);
49
		IPath webContentPath = getWebContentPath(project);
50
		
51
		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
52
			setContainerFullPath(webContentPath);
53
		}
54
	}
55
	
56
	/**
57
	 * This method is overriden to set additional validation specific to 
58
	 * css files. 
59
	 */
60
	protected boolean validatePage() {
61
		setMessage(null);
62
		setErrorMessage(null);
63
		
64
		if (!super.validatePage()) {
65
			return false;
66
		}
67
		
68
		String fileName = getFileName();
69
		IPath fullPath = getContainerFullPath();
70
		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
71
			// check that filename does not contain invalid extension
72
			if (!extensionValidForContentType(fileName)) {
73
				setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString()));
74
				return false;
75
			}
76
			// no file extension specified so check adding default
77
			// extension doesn't equal a file that already exists
78
			if (fileName.lastIndexOf('.') == -1) {
79
				String newFileName = addDefaultExtension(fileName);
80
				IPath resourcePath = fullPath.append(newFileName);
81
82
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
83
				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
84
				if (!result.isOK()) {
85
					// path invalid
86
					setErrorMessage(result.getMessage());
87
					return false;
88
				}
89
90
				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
91
					setErrorMessage(CSSUIMessages.ResourceGroup_nameExists);
92
					return false;
93
				}
94
			}
95
			
96
			// get the IProject for the selection path
97
			IProject project = getProjectFromPath(fullPath);
98
			
99
			// check if the project has has web facet
100
			if (!isWebProject(project)) {
101
				setErrorMessage(CSSUIMessages._ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT);
102
				return false;
103
			}
104
			
105
			// check that the path is inside the webContent folder
106
			IPath webContentPath = getWebContentPath(project);
107
			if (!webContentPath.isPrefixOf(fullPath)) {
108
				setMessage(CSSUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS, WARNING);
109
			}
110
		}
111
112
		return true;
113
	}
114
	
115
	/**
116
	 * Get content type associated with this new file wizard
117
	 * 
118
	 * @return IContentType
119
	 */
120
	protected IContentType getContentType() {
121
		if (fContentType == null)
122
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForCSS.ContentTypeID_CSS);
123
		return fContentType;
124
	}
125
126
	/**
127
	 * Get list of valid extensions for CSS Content type
128
	 * 
129
	 * @return
130
	 */
131
	protected List getValidExtensions() {
132
		if (fValidExtensions == null) {
133
			IContentType type = getContentType();
134
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
135
		}
136
		return fValidExtensions;
137
	}
138
	
139
	/**
140
	 * Verifies if fileName is valid name for content type. Takes base content
141
	 * type into consideration.
142
	 * 
143
	 * @param fileName
144
	 * @return true if extension is valid for this content type
145
	 */
146
	protected boolean extensionValidForContentType(String fileName) {
147
		boolean valid = false;
148
149
		IContentType type = getContentType();
150
		// there is currently an extension
151
		if (fileName.lastIndexOf('.') != -1) {
152
			// check what content types are associated with current extension
153
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
154
			int i = 0;
155
			while (i < types.length && !valid) {
156
				valid = types[i].isKindOf(type);
157
				++i;
158
			}
159
		}
160
		else
161
			valid = true; // no extension so valid
162
		return valid;
163
	}
164
165
	/**
166
	 * Adds default extension to the filename
167
	 * 
168
	 * @param filename
169
	 * @return
170
	 */
171
	protected String addDefaultExtension(String filename) {
172
		StringBuffer newFileName = new StringBuffer(filename);
173
174
		Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
175
		String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION);
176
177
		newFileName.append("."); //$NON-NLS-1$
178
		newFileName.append(ext);
179
180
		return newFileName.toString();
181
	}
182
	
183
	/**
184
	 * Returns the project that contains the specified path
185
	 * 
186
	 * @param path the path which project is needed
187
	 * @return IProject object. If path is <code>null</code> the return value 
188
	 * 		   is also <code>null</code>. 
189
	 */
190
	protected IProject getProjectFromPath(IPath path) {
191
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
192
		IProject project = null;
193
		
194
		if (path != null) {
195
			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
196
				project = workspace.getRoot().getProject(path.toString());
197
			} else {
198
				project = workspace.getRoot().getFile(path).getProject();
199
			}
200
		}
201
		
202
		return project;
203
	}
204
	
205
	/**
206
	 * Checks if the specified project is a web project. 
207
	 * 
208
	 * @param project project to be checked
209
	 * @return true if the project is web project, otherwise false
210
	 * @throws CoreException thrown when creating IFacetedProject from IProject
211
	 */
212
	protected boolean isWebProject(IProject project) {
213
		IFacetedProject faceted;
214
		try {
215
			faceted = ProjectFacetsManager.create(project);
216
		} catch (CoreException e) {
217
			throw new RuntimeException(e);
218
		}
219
		
220
		if (faceted != null && 
221
			(faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("wst.web")) || 
222
			 faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web")))) {
223
			return true;
224
		}
225
		
226
		return false;
227
	}
228
	
229
	/**
230
	 * Returns the web contents folder of the specified project
231
	 * 
232
	 * @param project the project which web contents path is needed
233
	 * @return IPath of the web contents folder
234
	 */
235
	protected IPath getWebContentPath(IProject project) {
236
		if (project != null && isWebProject(project)) {
237
			List resources = StructureEdit.getStructureEditForRead(project).getComponent().getResources();
238
			Iterator iter = resources.iterator();
239
			while (iter.hasNext()) {
240
				ComponentResource res = (ComponentResource) iter.next();
241
				if (res.getRuntimePath().isRoot()) {
242
					return new Path(project.getFullPath().toString() + res.getSourcePath().toString());
243
				}
244
			}
245
		}
246
		
247
		return null;
248
	}
249
250
}
(-)src/org/eclipse/wst/javascript/ui/internal/editor/JavaScriptUIMessages.java (+2 lines)
Lines 41-46 Link Here
41
	public static String _UI_WIZARD_NEW_HEADING;
41
	public static String _UI_WIZARD_NEW_HEADING;
42
	public static String _UI_WIZARD_NEW_DESCRIPTION;
42
	public static String _UI_WIZARD_NEW_DESCRIPTION;
43
	public static String _ERROR_FILENAME_MUST_END_JS;
43
	public static String _ERROR_FILENAME_MUST_END_JS;
44
	public static String _ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT;
45
	public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS;
44
	public static String ResourceGroup_nameExists;
46
	public static String ResourceGroup_nameExists;
45
	public static String Editor_Cut_label; // Resource bundle
47
	public static String Editor_Cut_label; // Resource bundle
46
	public static String Editor_Cut_tooltip; // Resource bundle
48
	public static String Editor_Cut_tooltip; // Resource bundle
(-)src/org/eclipse/wst/javascript/ui/internal/editor/JSUIPluginResources.properties (+2 lines)
Lines 30-35 Link Here
30
_UI_WIZARD_NEW_HEADING = JavaScript
30
_UI_WIZARD_NEW_HEADING = JavaScript
31
_UI_WIZARD_NEW_DESCRIPTION = Create a new JavaScript file.
31
_UI_WIZARD_NEW_DESCRIPTION = Create a new JavaScript file.
32
_ERROR_FILENAME_MUST_END_JS = The file name must end in one of the following extensions {0}.
32
_ERROR_FILENAME_MUST_END_JS = The file name must end in one of the following extensions {0}.
33
_ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT = The folder must be inside Static or Dynamic Web Project.
34
_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS = The folder must be inside the Web Contents folder. 
33
ResourceGroup_nameExists = The same name already exists.
35
ResourceGroup_nameExists = The same name already exists.
34
# these are copied from sse ui
36
# these are copied from sse ui
35
Editor_Cut_label=Cu&t@Ctrl+X
37
Editor_Cut_label=Cu&t@Ctrl+X
(-)META-INF/MANIFEST.MF (-1 / +5 lines)
Lines 34-38 Link Here
34
 org.eclipse.core.runtime,
34
 org.eclipse.core.runtime,
35
 org.eclipse.ui.ide,
35
 org.eclipse.ui.ide,
36
 org.eclipse.wst.xml.core,
36
 org.eclipse.wst.xml.core,
37
 com.ibm.icu
37
 com.ibm.icu,
38
 org.eclipse.wst.common.project.facet.core,
39
 org.eclipse.wst.common.modulecore,
40
 org.eclipse.emf.ecore,
41
 org.eclipse.wst.common.ui
38
Eclipse-LazyStart: true
42
Eclipse-LazyStart: true
(-)src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSWizard.java (-124 / +4 lines)
Lines 1-150 Link Here
1
package org.eclipse.wst.javascript.ui.internal.wizard;
1
package org.eclipse.wst.javascript.ui.internal.wizard;
2
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
7
import org.eclipse.core.resources.IFile;
3
import org.eclipse.core.resources.IFile;
8
import org.eclipse.core.resources.IResource;
9
import org.eclipse.core.resources.IWorkspace;
10
import org.eclipse.core.resources.ResourcesPlugin;
11
import org.eclipse.core.runtime.IPath;
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.core.runtime.Preferences;
15
import org.eclipse.core.runtime.content.IContentType;
16
import org.eclipse.jface.resource.ImageDescriptor;
4
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.jface.viewers.IStructuredSelection;
5
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.StructuredSelection;
6
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.wizard.Wizard;
7
import org.eclipse.jface.wizard.Wizard;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.ui.INewWizard;
8
import org.eclipse.ui.INewWizard;
22
import org.eclipse.ui.IWorkbench;
9
import org.eclipse.ui.IWorkbench;
23
import org.eclipse.ui.IWorkbenchPage;
10
import org.eclipse.ui.IWorkbenchPage;
24
import org.eclipse.ui.PartInitException;
11
import org.eclipse.ui.PartInitException;
25
import org.eclipse.ui.PlatformUI;
12
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
27
import org.eclipse.ui.ide.IDE;
13
import org.eclipse.ui.ide.IDE;
28
import org.eclipse.wst.javascript.core.internal.JavaScriptCorePlugin;
29
import org.eclipse.wst.javascript.core.internal.contenttype.ContentTypeIdForJavaScript;
30
import org.eclipse.wst.javascript.core.internal.preferences.JavaScriptCorePreferenceNames;
31
import org.eclipse.wst.javascript.ui.internal.editor.JSEditorPlugin;
14
import org.eclipse.wst.javascript.ui.internal.editor.JSEditorPlugin;
32
import org.eclipse.wst.javascript.ui.internal.editor.JavaScriptUIMessages;
15
import org.eclipse.wst.javascript.ui.internal.editor.JavaScriptUIMessages;
33
import org.eclipse.wst.javascript.ui.internal.editor.Logger;
16
import org.eclipse.wst.javascript.ui.internal.editor.Logger;
34
17
35
public class NewJSWizard extends Wizard implements INewWizard {
18
public class NewJSWizard extends Wizard implements INewWizard {
36
	static String PAGE_IMAGE = "/icons/full/wizban/newjscriptfile_wiz.gif"; //$NON-NLS-1$
19
	static String PAGE_IMAGE = "/icons/full/wizban/newjscriptfile_wiz.gif"; //$NON-NLS-1$
37
	private WizardNewFileCreationPage fNewFilePage;
20
	private NewJSFileWizardPage fNewFilePage;
38
	private IStructuredSelection fSelection;
21
	private IStructuredSelection fSelection;
39
	private IContentType fContentType;
40
	private List fValidExtensions = null;
41
42
	/**
43
	 * Adds default extension to the filename
44
	 * 
45
	 * @param filename
46
	 * @return
47
	 */
48
	String addDefaultExtension(String filename) {
49
		StringBuffer newFileName = new StringBuffer(filename);
50
51
		Preferences preference = JavaScriptCorePlugin.getDefault().getPluginPreferences();
52
		String ext = preference.getString(JavaScriptCorePreferenceNames.DEFAULT_EXTENSION);
53
54
		newFileName.append("."); //$NON-NLS-1$
55
		newFileName.append(ext);
56
57
		return newFileName.toString();
58
	}
59
60
	/**
61
	 * Get content type associated with this new file wizard
62
	 * 
63
	 * @return IContentType
64
	 */
65
	IContentType getContentType() {
66
		if (fContentType == null)
67
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJavaScript.ContentTypeID_JAVASCRIPT);
68
		return fContentType;
69
	}
70
71
	/**
72
	 * Get list of valid extensions for JavaScript Content type
73
	 * 
74
	 * @return
75
	 */
76
	List getValidExtensions() {
77
		if (fValidExtensions == null) {
78
			IContentType type = getContentType();
79
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
80
		}
81
		return fValidExtensions;
82
	}
83
	
84
	/**
85
	 * Verifies if fileName is valid name for content type. Takes base content
86
	 * type into consideration.
87
	 * 
88
	 * @param fileName
89
	 * @return true if extension is valid for this content type
90
	 */
91
	boolean extensionValidForContentType(String fileName) {
92
		boolean valid = false;
93
94
		IContentType type = getContentType();
95
		// there is currently an extension
96
		if (fileName.lastIndexOf('.') != -1) {
97
			// check what content types are associated with current extension
98
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
99
			int i = 0;
100
			while (i < types.length && !valid) {
101
				valid = types[i].isKindOf(type);
102
				++i;
103
			}
104
		}
105
		else
106
			valid = true; // no extension so valid
107
		return valid;
108
	}
109
22
110
	public void addPages() {
23
	public void addPages() {
111
		fNewFilePage = new WizardNewFileCreationPage("JSWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$
24
		fNewFilePage = new NewJSFileWizardPage("NewJSTemplatesWizardPage", 
112
			protected boolean validatePage() {
25
				new StructuredSelection(IDE.computeSelectedResources(fSelection)));
113
				String fileName = getFileName();
114
				IPath fullPath = getContainerFullPath();
115
				if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
116
					// check that filename does not contain invalid extension
117
					if (!extensionValidForContentType(fileName)) {
118
						setErrorMessage(NLS.bind(JavaScriptUIMessages._ERROR_FILENAME_MUST_END_JS, getValidExtensions().toString()));
119
						return false;
120
					}
121
					// no file extension specified so check adding default
122
					// extension doesn't equal a file that already exists
123
					if (fileName.lastIndexOf('.') == -1) {
124
						String newFileName = addDefaultExtension(fileName);
125
						IPath resourcePath = fullPath.append(newFileName);
126
127
						IWorkspace workspace = ResourcesPlugin.getWorkspace();
128
						IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
129
						if (!result.isOK()) {
130
							// path invalid
131
							setErrorMessage(result.getMessage());
132
							return false;
133
						}
134
135
						if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
136
							setErrorMessage(JavaScriptUIMessages.ResourceGroup_nameExists);
137
							return false;
138
						}
139
					}
140
				}
141
				setErrorMessage(null);
142
				return super.validatePage();
143
			}
144
		};
145
		fNewFilePage.setTitle(JavaScriptUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$
26
		fNewFilePage.setTitle(JavaScriptUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$
146
		fNewFilePage.setDescription(JavaScriptUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$
27
		fNewFilePage.setDescription(JavaScriptUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$
147
148
		addPage(fNewFilePage);
28
		addPage(fNewFilePage);
149
	}
29
	}
150
30
Lines 183-189 Link Here
183
		// no file extension specified so add default extension
63
		// no file extension specified so add default extension
184
		String fileName = fNewFilePage.getFileName();
64
		String fileName = fNewFilePage.getFileName();
185
		if (fileName.lastIndexOf('.') == -1) {
65
		if (fileName.lastIndexOf('.') == -1) {
186
			String newFileName = addDefaultExtension(fileName);
66
			String newFileName = fNewFilePage.addDefaultExtension(fileName);
187
			fNewFilePage.setFileName(newFileName);
67
			fNewFilePage.setFileName(newFileName);
188
		}
68
		}
189
69
(-)plugin.xml (+45 lines)
Lines 110-115 Link Here
110
			<selection class="org.eclipse.core.resources.IResource" />
110
			<selection class="org.eclipse.core.resources.IResource" />
111
		</wizard>
111
		</wizard>
112
	</extension>
112
	</extension>
113
	
114
	<!-- Add new JavaScript wizard to J2EE Project Navigator -->
115
	<extension
116
		id="org.eclipse.wst.javascript.commonWizard.newJS"
117
		point="org.eclipse.ui.navigator.navigatorContent">
118
		<commonWizard
119
			type="new"
120
			wizardId="org.eclipse.wst.javascript.ui.internal.wizard.NewJSWizard">
121
			<enablement>
122
				<or>
123
					<adapt type="org.eclipse.core.resources.IProject">
124
						<or>
125
							<test
126
								property="org.eclipse.wst.common.project.facet.core.projectFacet"
127
								value="wst.web"/>
128
							<test
129
								property="org.eclipse.wst.common.project.facet.core.projectFacet"
130
								value="jst.web"/>
131
						</or>
132
					</adapt>
133
					<adapt type="org.eclipse.core.resources.IFolder">
134
						<or>
135
							<test 
136
								property="org.eclipse.wst.common.ui.webContent"
137
								args="wst.web"/>
138
							<test 
139
								property="org.eclipse.wst.common.ui.webContent"
140
								args="jst.web"/>
141
						</or>
142
					</adapt>
143
					<adapt type="org.eclipse.core.resources.IFile">
144
						<or>
145
							<test 
146
								property="org.eclipse.wst.common.ui.webContent"
147
								args="wst.web"/>
148
							<test 
149
								property="org.eclipse.wst.common.ui.webContent"
150
								args="jst.web"/>
151
						</or>
152
					</adapt>
153
				</or>
154
			</enablement>
155
		</commonWizard>
156
	</extension>
157
	
113
	<extension point="org.eclipse.ui.preferencePages">
158
	<extension point="org.eclipse.ui.preferencePages">
114
		<!-- JAVASCRIPT PREFERENCE PAGES -->
159
		<!-- JAVASCRIPT PREFERENCE PAGES -->
115
		<page
160
		<page
(-)src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSFileWizardPage.java (+249 lines)
Added Link Here
1
package org.eclipse.wst.javascript.ui.internal.wizard;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.Iterator;
6
import java.util.List;
7
8
import org.eclipse.core.resources.IProject;
9
import org.eclipse.core.resources.IResource;
10
import org.eclipse.core.resources.IWorkspace;
11
import org.eclipse.core.resources.ResourcesPlugin;
12
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
22
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
23
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
24
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
25
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
26
import org.eclipse.wst.javascript.core.internal.JavaScriptCorePlugin;
27
import org.eclipse.wst.javascript.core.internal.contenttype.ContentTypeIdForJavaScript;
28
import org.eclipse.wst.javascript.core.internal.preferences.JavaScriptCorePreferenceNames;
29
import org.eclipse.wst.javascript.ui.internal.editor.JavaScriptUIMessages;
30
31
public class NewJSFileWizardPage extends WizardNewFileCreationPage {
32
	
33
	private IContentType fContentType;
34
	private List fValidExtensions = null;
35
	
36
	public NewJSFileWizardPage(String pageName, IStructuredSelection selection) {
37
        super(pageName, selection);
38
    }
39
	
40
	/**
41
	 * This method is overriden to set the selected folder to web contents 
42
	 * folder if the current selection is outside the web contents folder. 
43
	 */
44
	protected void initialPopulateContainerNameField() {
45
		super.initialPopulateContainerNameField();
46
		
47
		IPath fullPath = getContainerFullPath();
48
		IProject project = getProjectFromPath(fullPath);
49
		IPath webContentPath = getWebContentPath(project);
50
		
51
		if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) {
52
			setContainerFullPath(webContentPath);
53
		}
54
	}
55
	
56
	/**
57
	 * This method is overriden to set additional validation specific to 
58
	 * javascript files. 
59
	 */
60
	protected boolean validatePage() {
61
		setMessage(null);
62
		setErrorMessage(null);
63
		
64
		if (!super.validatePage()) {
65
			return false;
66
		}
67
		
68
		String fileName = getFileName();
69
		IPath fullPath = getContainerFullPath();
70
		if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) {
71
			// check that filename does not contain invalid extension
72
			if (!extensionValidForContentType(fileName)) {
73
				setErrorMessage(NLS.bind(JavaScriptUIMessages._ERROR_FILENAME_MUST_END_JS, getValidExtensions().toString()));
74
				return false;
75
			}
76
			// no file extension specified so check adding default
77
			// extension doesn't equal a file that already exists
78
			if (fileName.lastIndexOf('.') == -1) {
79
				String newFileName = addDefaultExtension(fileName);
80
				IPath resourcePath = fullPath.append(newFileName);
81
82
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
83
				IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER);
84
				if (!result.isOK()) {
85
					// path invalid
86
					setErrorMessage(result.getMessage());
87
					return false;
88
				}
89
90
				if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) {
91
					setErrorMessage(JavaScriptUIMessages.ResourceGroup_nameExists);
92
					return false;
93
				}
94
			}
95
			
96
			// get the IProject for the selection path
97
			IProject project = getProjectFromPath(fullPath);
98
			
99
			// check if the project has has web facet
100
			if (!isWebProject(project)) {
101
				setErrorMessage(JavaScriptUIMessages._ERROR_FOLDER_MUST_BE_INSIDE_WEB_PROJECT);
102
				return false;
103
			}
104
			
105
			// check that the path is inside the webContent folder
106
			IPath webContentPath = getWebContentPath(project);
107
			if (!webContentPath.isPrefixOf(fullPath)) {
108
				setMessage(JavaScriptUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENTS, WARNING);
109
			}
110
		}
111
112
		return true;
113
	}
114
	
115
	/**
116
	 * Get content type associated with this new file wizard
117
	 * 
118
	 * @return IContentType
119
	 */
120
	protected IContentType getContentType() {
121
		if (fContentType == null)
122
			fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJavaScript.ContentTypeID_JAVASCRIPT);
123
		return fContentType;
124
	}
125
126
	/**
127
	 * Get list of valid extensions for JavaScript Content type
128
	 * 
129
	 * @return
130
	 */
131
	protected List getValidExtensions() {
132
		if (fValidExtensions == null) {
133
			IContentType type = getContentType();
134
			fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
135
		}
136
		return fValidExtensions;
137
	}
138
	
139
	/**
140
	 * Verifies if fileName is valid name for content type. Takes base content
141
	 * type into consideration.
142
	 * 
143
	 * @param fileName
144
	 * @return true if extension is valid for this content type
145
	 */
146
	protected boolean extensionValidForContentType(String fileName) {
147
		boolean valid = false;
148
149
		IContentType type = getContentType();
150
		// there is currently an extension
151
		if (fileName.lastIndexOf('.') != -1) {
152
			// check what content types are associated with current extension
153
			IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName);
154
			int i = 0;
155
			while (i < types.length && !valid) {
156
				valid = types[i].isKindOf(type);
157
				++i;
158
			}
159
		}
160
		else
161
			valid = true; // no extension so valid
162
		return valid;
163
	}
164
165
	/**
166
	 * Adds default extension to the filename
167
	 * 
168
	 * @param filename
169
	 * @return
170
	 */
171
	protected String addDefaultExtension(String filename) {
172
		StringBuffer newFileName = new StringBuffer(filename);
173
174
		Preferences preference = JavaScriptCorePlugin.getDefault().getPluginPreferences();
175
		String ext = preference.getString(JavaScriptCorePreferenceNames.DEFAULT_EXTENSION);
176
177
		newFileName.append("."); //$NON-NLS-1$
178
		newFileName.append(ext);
179
180
		return newFileName.toString();
181
	}
182
	
183
	/**
184
	 * Returns the project that contains the specified path
185
	 * 
186
	 * @param path the path which project is needed
187
	 * @return IProject object. If path is <code>null</code> the return value 
188
	 * 		   is also <code>null</code>. 
189
	 */
190
	protected IProject getProjectFromPath(IPath path) {
191
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
192
		IProject project = null;
193
		
194
		if (path != null) {
195
			if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) {
196
				project = workspace.getRoot().getProject(path.toString());
197
			} else {
198
				project = workspace.getRoot().getFile(path).getProject();
199
			}
200
		}
201
		
202
		return project;
203
	}
204
	
205
	/**
206
	 * Checks if the specified project is a web project. 
207
	 * 
208
	 * @param project project to be checked
209
	 * @return true if the project is web project, otherwise false
210
	 * @throws CoreException thrown when creating IFacetedProject from IProject
211
	 */
212
	protected boolean isWebProject(IProject project) {
213
		IFacetedProject faceted;
214
		try {
215
			faceted = ProjectFacetsManager.create(project);
216
		} catch (CoreException e) {
217
			throw new RuntimeException(e);
218
		}
219
		
220
		if (faceted != null && 
221
			(faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("wst.web")) || 
222
			 faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web")))) {
223
			return true;
224
		}
225
		
226
		return false;
227
	}
228
	
229
	/**
230
	 * Returns the web contents folder of the specified project
231
	 * 
232
	 * @param project the project which web contents path is needed
233
	 * @return IPath of the web contents folder
234
	 */
235
	protected IPath getWebContentPath(IProject project) {
236
		if (project != null && isWebProject(project)) {
237
			List resources = StructureEdit.getStructureEditForRead(project).getComponent().getResources();
238
			Iterator iter = resources.iterator();
239
			while (iter.hasNext()) {
240
				ComponentResource res = (ComponentResource) iter.next();
241
				if (res.getRuntimePath().isRoot()) {
242
					return new Path(project.getFullPath().toString() + res.getSourcePath().toString());
243
				}
244
			}
245
		}
246
		
247
		return null;
248
	}
249
}
(-)META-INF/MANIFEST.MF (-1 / +5 lines)
Lines 21-25 Link Here
21
 org.eclipse.search,
21
 org.eclipse.search,
22
 org.eclipse.wst.common.core,
22
 org.eclipse.wst.common.core,
23
 org.eclipse.jface.text,
23
 org.eclipse.jface.text,
24
 org.eclipse.ui.workbench.texteditor
24
 org.eclipse.ui.workbench.texteditor,
25
 org.eclipse.wst.common.project.facet.core,
26
 org.eclipse.wst.common.modulecore,
27
 org.eclipse.emf.ecore,
28
 org.eclipse.core.expressions
25
Eclipse-LazyStart: true
29
Eclipse-LazyStart: true
(-)plugin.xml (+10 lines)
Lines 28-31 Link Here
28
      </objectContribution>               
28
      </objectContribution>               
29
    </extension> 
29
    </extension> 
30
   -->
30
   -->
31
  
32
  <extension
33
        point="org.eclipse.core.expressions.propertyTesters">
34
     <propertyTester
35
           class="org.eclipse.wst.common.ui.internal.propertytester.ResourcePropertyTester"
36
           id="org.eclipse.wst.common.ui.ResourcePropertyTester"
37
           namespace="org.eclipse.wst.common.ui"
38
           properties="webContent"
39
           type="org.eclipse.core.resources.IResource"/>
40
  </extension>
31
</plugin>
41
</plugin>
(-)src/org/eclipse/wst/common/ui/internal/propertytester/ResourcePropertyTester.java (+99 lines)
Added Link Here
1
package org.eclipse.wst.common.ui.internal.propertytester;
2
3
import java.util.Iterator;
4
import java.util.List;
5
6
import org.eclipse.core.expressions.PropertyTester;
7
import org.eclipse.core.resources.IProject;
8
import org.eclipse.core.resources.IResource;
9
import org.eclipse.core.runtime.CoreException;
10
import org.eclipse.core.runtime.IPath;
11
import org.eclipse.core.runtime.Path;
12
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
13
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
14
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
15
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
16
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
17
18
/**
19
 * A property tester for various web-specific properties of resources.
20
 */
21
public class ResourcePropertyTester extends PropertyTester {
22
	
23
	/**
24
	 * A property indicating if the resource is inside the web content folder 
25
	 * of a web project. 
26
	 */
27
	protected static final String WEB_CONTENT = "webContent"; //$NON-NLS-1$
28
29
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
30
		
31
		if (!(receiver instanceof IResource))
32
			return false;
33
		IResource res = (IResource) receiver;
34
		
35
		if (property.equals(WEB_CONTENT)) {
36
			if (args.length == 0)
37
				return false;
38
			
39
			// get the resource's project
40
			IProject project = res.getProject();
41
			
42
			// constructs the IProjectFacet. it should be "web" facet: "wst.web" or "jst.web"
43
			IProjectFacet facet = ProjectFacetsManager.getProjectFacet(args[0].toString());
44
			
45
			// check if the project has the facet
46
			if (hasFacet(project, facet)) {
47
				
48
				// get the project's web content folder path
49
				IPath webContentPath = getWebContentPath(project);
50
				
51
				// check if the resource is inside the web content folder path
52
				if (webContentPath != null && webContentPath.isPrefixOf(res.getFullPath())) {
53
					return true;
54
				}
55
			}
56
		}
57
		
58
		// TODO Auto-generated method stub
59
		return false;
60
	}
61
	
62
	/**
63
	 * Get project's webContent folder path
64
	 */
65
	private IPath getWebContentPath(IProject project) {
66
		if (project != null) {
67
			List resources = StructureEdit.getStructureEditForRead(project).getComponent().getResources();
68
			Iterator iter = resources.iterator();
69
			while (iter.hasNext()) {
70
				ComponentResource res = (ComponentResource) iter.next();
71
				if (res.getRuntimePath().isRoot()) {
72
					return new Path(project.getFullPath().toString() + res.getSourcePath().toString());
73
				}
74
			}
75
		}
76
		
77
		return null;
78
	}
79
	
80
	/**
81
	 * Check if a project has the specified facet
82
	 */
83
	private boolean hasFacet(IProject project, IProjectFacet facet) {
84
		IFacetedProject faceted;
85
		try {
86
			faceted = ProjectFacetsManager.create(project);
87
		} catch (CoreException e) {
88
			throw new RuntimeException(e);
89
		}
90
		
91
		if (faceted != null && 
92
			faceted.hasProjectFacet(facet)) {
93
			return true;
94
		}
95
		
96
		return false;
97
	}
98
99
}

Return to bug 140752