Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 189708 Details for
Bug 338111
Separate the HTML validator into the org.eclipse.wst.html.core bundle so it can be used in headless tools
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
possible patch
wtp_headless_html_validator.patch (text/plain), 108.03 KB, created by
Troy Bishop
on 2011-02-24 11:09:14 EST
(
hide
)
Description:
possible patch
Filename:
MIME Type:
Creator:
Troy Bishop
Created:
2011-02-24 11:09:14 EST
Size:
108.03 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.html.core >Index: .classpath >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/.classpath,v >retrieving revision 1.7 >diff -u -r1.7 .classpath >--- .classpath 1 Apr 2007 21:20:38 -0000 1.7 >+++ .classpath 24 Feb 2011 13:49:52 -0000 >@@ -1,6 +1,7 @@ > <?xml version="1.0" encoding="UTF-8"?> > <classpath> > <classpathentry kind="src" path="src"/> >+ <classpathentry kind="src" path="src-html-validation"/> > <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> > <accessrules> > <accessrule kind="accessible" pattern="org/w3c/dom/css/**/*"/> >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/plugin.properties,v >retrieving revision 1.8 >diff -u -r1.8 plugin.properties >--- plugin.properties 29 Apr 2010 00:47:25 -0000 1.8 >+++ plugin.properties 24 Feb 2011 13:49:52 -0000 >@@ -14,3 +14,4 @@ > HTML_Content_Type_Extension_Element.name=HTML > _taskMarker.name=HTML Task > _validationMarker.name=HTML Problem >+HTML_Syntax_Validator.name=HTML Syntax Validator >\ No newline at end of file >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/plugin.xml,v >retrieving revision 1.21 >diff -u -r1.21 plugin.xml >--- plugin.xml 24 Nov 2008 22:59:28 -0000 1.21 >+++ plugin.xml 24 Feb 2011 13:49:52 -0000 >@@ -210,4 +210,28 @@ > class="org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceInitializer" /> > </extension> > >+ <!--======================================================================================--> >+ <!-- Workbench validation --> >+ <!--======================================================================================--> >+ <extension id="HTMLValidator" name="%HTML_Syntax_Validator.name" point="org.eclipse.wst.validation.validatorV2"> >+ <validator >+ build="true" >+ class="org.eclipse.wst.html.internal.validation.HTMLValidator" >+ manual="true" >+ sourceid="org.eclipse.wst.html.ui.internal.validation.htmlsyntaxvalidator" >+ version="1" >+ markerId="org.eclipse.wst.html.core.validationMarker"> >+ <include> >+ <rules> >+ <contentType id="org.eclipse.wst.html.core.htmlsource"></contentType> >+ <fileext caseSensitive="false" ext="html"/> >+ <fileext caseSensitive="false" ext="xhtml"/> >+ <fileext caseSensitive="false" ext="htm"/> >+ <fileext caseSensitive="false" ext="htpl"/> >+ <fileext caseSensitive="false" ext="wml"/> >+ </rules> >+ </include> >+ <group id="org.eclipse.wst.sse.core.structuredModelGroup"/> >+ </validator> >+ </extension> > </plugin> >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/META-INF/MANIFEST.MF,v >retrieving revision 1.31.2.4 >diff -u -r1.31.2.4 MANIFEST.MF >--- META-INF/MANIFEST.MF 4 Nov 2010 01:40:29 -0000 1.31.2.4 >+++ META-INF/MANIFEST.MF 24 Feb 2011 13:49:52 -0000 >@@ -2,7 +2,7 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: %pluginName > Bundle-SymbolicName: org.eclipse.wst.html.core; singleton:=true >-Bundle-Version: 1.1.404.qualifier >+Bundle-Version: 1.1.405.qualifier > Bundle-Activator: org.eclipse.wst.html.core.internal.HTMLCorePlugin > Bundle-Vendor: %providerName > Bundle-Localization: plugin >@@ -26,7 +26,8 @@ > org.eclipse.wst.html.core.internal.provisional.text;x-internal:=true, > org.eclipse.wst.html.core.internal.text;x-internal:=true, > org.eclipse.wst.html.core.internal.validate;x-internal:=true, >- org.eclipse.wst.html.core.text >+ org.eclipse.wst.html.core.text, >+ org.eclipse.wst.html.internal.validation;x-friends:="org.eclipse.wst.html.ui" > Import-Package: com.ibm.icu.util; version="3.8" > Require-Bundle: org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)", > org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", >@@ -35,6 +36,7 @@ > org.eclipse.wst.xml.core;bundle-version="[1.1.500,1.2.0)", > org.eclipse.wst.css.core;bundle-version="[1.1.400,1.2.0)", > org.eclipse.core.filebuffers;bundle-version="[3.5.0,4.0.0)", >- org.eclipse.wst.common.modulecore;bundle-version="[1.2.0,2.0.0)";resolution:=optional >+ org.eclipse.wst.common.modulecore;bundle-version="[1.2.0,2.0.0)";resolution:=optional, >+ org.eclipse.wst.validation;bundle-version="1.2.201" > Bundle-ActivationPolicy: lazy;exclude:="org.eclipse.wst.html.core.internal.contenttype,org.eclipse.wst.html.core.internal.provisional.contenttype" > Bundle-RequiredExecutionEnvironment: J2SE-1.4 >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,150 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.wst.html.core.internal.validate.MessageFactory; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >+import org.eclipse.wst.sse.core.internal.validate.ErrorInfo; >+import org.eclipse.wst.sse.core.internal.validate.ValidationMessage; >+import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; >+import org.eclipse.wst.validation.internal.provisional.core.IMessage; >+import org.eclipse.wst.validation.internal.provisional.core.IReporter; >+import org.eclipse.wst.validation.internal.provisional.core.IValidator; >+ >+public class HTMLValidationReporter implements ValidationReporter { >+ >+ private IValidator owner = null; >+ private IReporter reporter = null; >+ private IFile file = null; >+ private IStructuredModel model = null; >+ private HTMLValidationResult result = null; >+ private MessageFactory fFactory = null; >+ >+ /** >+ */ >+ public HTMLValidationReporter(IValidator owner, IReporter reporter, IFile file, IStructuredModel model) { >+ super(); >+ this.owner = owner; >+ this.reporter = reporter; >+ this.file = file; >+ this.model = model; >+ fFactory = new MessageFactory(file != null ? file.getProject() : null); >+ } >+ >+ /** >+ */ >+ public void clear() { >+ if (this.file == null) >+ return; >+ >+ this.result = null; >+ >+ if (this.reporter != null) { >+ this.reporter.removeAllMessages(this.owner, this.file); >+ } >+ else { >+ // remove by myself? >+ String id = HTMLValidator.class.getName(); >+ try { >+ // TaskListHelper API changed >+ // TaskListHelper.getTaskList().removeAllTasks(id, this.file, >+ // null); >+ TaskListHelper.getTaskList().removeAllTasks(this.file, id, null); >+ } >+ catch (CoreException ex) { >+ } >+ } >+ } >+ >+ >+ /** >+ */ >+ public HTMLValidationResult getResult() { >+ if (this.result == null) >+ this.result = new HTMLValidationResult(); >+ return this.result; >+ } >+ >+ /** >+ */ >+ public void report(ValidationMessage message) { >+ if (message == null || message.getSeverity() == ValidationMessage.IGNORE) >+ return; >+ IMessage mes = translateMessage(message); >+ >+ if (this.reporter != null) { >+ this.reporter.addMessage(this.owner, mes); >+ } >+ else { >+ if (this.file == null) >+ return; >+ >+ // add by myself? >+ String id = HTMLValidator.class.getName(); >+ String location = Integer.toString(mes.getLineNumber()); >+ String name = ""; //$NON-NLS-1$ >+ IPath filePath = this.file.getFullPath(); >+ if (filePath != null) { >+ name = filePath.toString(); >+ } >+ try { >+ TaskListHelper.getTaskList().addTask(id, this.file, location, mes.getId(), mes.getText(), mes.getSeverity(), name, mes.getGroupName(), mes.getOffset(), mes.getLength()); >+ } >+ catch (CoreException ex) { >+ } >+ } >+ } >+ >+ /** >+ * Translate ValidationMessage to IMessage and generate result log >+ */ >+ private IMessage translateMessage(ValidationMessage message) { >+ int severity = IMessage.LOW_SEVERITY; >+ HTMLValidationResult result = getResult(); >+ switch (message.getSeverity()) { >+ case ValidationMessage.ERROR : >+ severity = IMessage.HIGH_SEVERITY; >+ result.addError(); >+ break; >+ case ValidationMessage.WARNING : >+ severity = IMessage.NORMAL_SEVERITY; >+ result.addWarning(); >+ break; >+ case ValidationMessage.INFORMATION : >+ result.addInformation(); >+ break; >+ default : >+// result.addInformation(); >+ break; >+ } >+ >+ IMessage mes = new LocalizedMessage(severity, message.getMessage(), this.file); >+ mes.setOffset(message.getOffset()); >+ mes.setLength(message.getLength()); >+ if (this.model != null) { >+ IStructuredDocument flatModel = this.model.getStructuredDocument(); >+ if (flatModel != null) { >+ int line = flatModel.getLineOfOffset(message.getOffset()); >+ mes.setLineNo(line + 1); >+ } >+ } >+ >+ return mes; >+ } >+ >+ public void report(ErrorInfo info) { >+ report(fFactory.createMessage(info)); >+ } >+} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+public class HTMLValidationResult { >+ private int errors = 0; >+ private int warnings = 0; >+ private int informations = 0; >+ >+ /** >+ */ >+ public HTMLValidationResult() { >+ } >+ >+ /** >+ */ >+ public void addError() { >+ this.errors++; >+ } >+ >+ /** >+ */ >+ public void addInformation() { >+ this.informations++; >+ } >+ >+ /** >+ */ >+ public void addWarning() { >+ this.warnings++; >+ } >+ >+ /** >+ */ >+ public int getErrors() { >+ return this.errors; >+ } >+ >+ /** >+ */ >+ public int getInformations() { >+ return this.informations; >+ } >+ >+ /** >+ */ >+ public int getWarnings() { >+ return this.warnings; >+ } >+ >+ /** >+ */ >+ public boolean isValid() { >+ return (this.errors == 0 && this.warnings == 0 && this.informations == 0); >+ } >+} >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,380 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+import java.io.IOException; >+import java.io.UnsupportedEncodingException; >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExecutableExtension; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.content.IContentDescription; >+import org.eclipse.core.runtime.content.IContentType; >+import org.eclipse.core.runtime.content.IContentTypeManager; >+import org.eclipse.core.runtime.jobs.ISchedulingRule; >+import org.eclipse.wst.html.core.internal.Logger; >+import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeConstants; >+import org.eclipse.wst.html.core.internal.validate.HTMLValidationAdapterFactory; >+import org.eclipse.wst.sse.core.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.provisional.IModelManager; >+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; >+import org.eclipse.wst.sse.core.utils.StringUtils; >+import org.eclipse.wst.validation.AbstractValidator; >+import org.eclipse.wst.validation.ValidationResult; >+import org.eclipse.wst.validation.ValidationState; >+import org.eclipse.wst.validation.internal.core.Message; >+import org.eclipse.wst.validation.internal.core.ValidationException; >+import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; >+import org.eclipse.wst.validation.internal.provisional.core.IMessage; >+import org.eclipse.wst.validation.internal.provisional.core.IReporter; >+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; >+import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; >+import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >+ >+public class HTMLValidator extends AbstractValidator implements IValidatorJob, IExecutableExtension { >+ private static final String ORG_ECLIPSE_WST_HTML_CORE_HTMLSOURCE = "org.eclipse.wst.html.core.htmlsource"; //$NON-NLS-1$ >+ >+ static boolean shouldValidate(IFile file) { >+ IResource resource = file; >+ do { >+ if (resource.isDerived() || resource.isTeamPrivateMember() || !resource.isAccessible() >+ || (resource.getName().charAt(0) == '.' && resource.getType() == IResource.FOLDER)) { >+ return false; >+ } >+ resource = resource.getParent(); >+ } >+ while ((resource.getType() & IResource.PROJECT) == 0); >+ return true; >+ } >+ >+ private IContentTypeManager fContentTypeManager; >+ private IContentType[] fOtherSupportedContentTypes = null; >+ private String[] fAdditionalContentTypesIDs = null; >+ private IContentType fHTMLContentType; >+ >+ public HTMLValidator() { >+ super(); >+ fContentTypeManager = Platform.getContentTypeManager(); >+ fHTMLContentType = fContentTypeManager.getContentType(ORG_ECLIPSE_WST_HTML_CORE_HTMLSOURCE); >+ } >+ >+ /** >+ */ >+ public void cleanup(IReporter reporter) { >+ // nothing to do >+ } >+ >+ /** >+ * Gets list of content types this validator is interested in >+ * >+ * @return All HTML-related content types >+ */ >+ private IContentType[] getOtherSupportedContentTypes() { >+ if (fOtherSupportedContentTypes == null) { >+ List contentTypes = new ArrayList(3); >+ if (fAdditionalContentTypesIDs != null) { >+ for (int i = 0; i < fAdditionalContentTypesIDs.length; i++) { >+ IContentType type = Platform.getContentTypeManager().getContentType(fAdditionalContentTypesIDs[i]); >+ if (type != null) { >+ contentTypes.add(type); >+ } >+ } >+ } >+ fOtherSupportedContentTypes = (IContentType[]) contentTypes.toArray(new IContentType[contentTypes.size()]); >+ } >+ return fOtherSupportedContentTypes; >+ } >+ >+ /** >+ */ >+ protected IDOMModel getModel(IProject project, IFile file) { >+ if (project == null || file == null) >+ return null; >+ if (!file.exists()) >+ return null; >+ if (!canHandle(file)) >+ return null; >+ >+ IStructuredModel model = null; >+ IModelManager manager = StructuredModelManager.getModelManager(); >+ try { >+ file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); >+ } >+ catch (CoreException e) { >+ Logger.logException(e); >+ } >+ try { >+ try { >+ model = manager.getModelForRead(file); >+ } >+ catch (UnsupportedEncodingException ex) { >+ // retry ignoring META charset for invalid META charset >+ // specification >+ // recreate input stream, because it is already partially read >+ model = manager.getModelForRead(file, new String(), null); >+ } >+ } >+ catch (UnsupportedEncodingException ex) { >+ } >+ catch (IOException ex) { >+ } >+ catch (CoreException e) { >+ Logger.logException(e); >+ } >+ >+ if (model == null) >+ return null; >+ if (!(model instanceof IDOMModel)) { >+ releaseModel(model); >+ return null; >+ } >+ return (IDOMModel) model; >+ } >+ >+ /** >+ */ >+ protected HTMLValidationReporter getReporter(IReporter reporter, IFile file, IDOMModel model) { >+ return new HTMLValidationReporter(this, reporter, file, model); >+ } >+ >+ /** >+ * Check file extension to validate >+ */ >+ private boolean canHandle(IFile file) { >+ boolean result = false; >+ if (file != null) { >+ try { >+ IContentDescription contentDescription = file.getContentDescription(); >+ if (contentDescription != null) { >+ IContentType fileContentType = contentDescription.getContentType(); >+ if (fileContentType.isKindOf(fHTMLContentType)) { >+ result = true; >+ } >+ else { >+ IContentType[] otherTypes = getOtherSupportedContentTypes(); >+ for (int i = 0; i < otherTypes.length; i++) { >+ result = result || fileContentType.isKindOf(otherTypes[i]); >+ } >+ } >+ } >+ else if (fHTMLContentType != null) { >+ result = fHTMLContentType.isAssociatedWith(file.getName()); >+ } >+ } >+ catch (CoreException e) { >+ // should be rare, but will ignore to avoid logging "encoding >+ // exceptions" and the like here. >+ // Logger.logException(e); >+ } >+ } >+ return result; >+ } >+ >+ /** >+ */ >+ private boolean hasHTMLFeature(IDOMDocument document) { >+ DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class); >+ if (adapter == null) >+ return false; >+ return adapter.hasFeature(HTMLDocumentTypeConstants.HTML); >+ } >+ >+ /** >+ */ >+ protected void releaseModel(IStructuredModel model) { >+ if (model != null) >+ model.releaseFromRead(); >+ } >+ >+ /** >+ */ >+ public void validate(IValidationContext helper, IReporter reporter) { >+ if (helper == null) >+ return; >+ if ((reporter != null) && (reporter.isCancelled() == true)) { >+ throw new OperationCanceledException(); >+ } >+ String[] deltaArray = helper.getURIs(); >+ if (deltaArray != null && deltaArray.length > 0) { >+ validateDelta(helper, reporter); >+ } >+ else { >+ validateFull(helper, reporter); >+ } >+ } >+ >+ /** >+ */ >+ private HTMLValidationResult validate(IReporter reporter, IFile file, IDOMModel model) { >+ if (file == null || model == null) >+ return null; // error >+ IDOMDocument document = model.getDocument(); >+ if (document == null) >+ return null; // error >+ if (!hasHTMLFeature(document)) >+ return null; // ignore >+ >+ INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance(); >+ ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document); >+ if (adapter == null) >+ return null; // error >+ >+ HTMLValidationReporter rep = getReporter(reporter, file, model); >+ rep.clear(); >+ adapter.setReporter(rep); >+ adapter.validate(document); >+ return rep.getResult(); >+ } >+ >+ /** >+ */ >+ private void validateContainer(IValidationContext helper, IReporter reporter, IContainer container) { >+ try { >+ IResource[] resourceArray = container.members(false); >+ for (int i = 0; i < resourceArray.length; i++) { >+ IResource resource = resourceArray[i]; >+ if (resource == null || reporter.isCancelled()) >+ continue; >+ if (resource instanceof IFile) { >+ Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, resource.getFullPath().toString() >+ .substring(1)); >+ reporter.displaySubtask(this, message); >+ validateFile(helper, reporter, (IFile) resource); >+ } >+ else if (resource instanceof IContainer) { >+ validateContainer(helper, reporter, (IContainer) resource); >+ } >+ } >+ } >+ catch (CoreException ex) { >+ } >+ } >+ >+ /** >+ */ >+ private void validateDelta(IValidationContext helper, IReporter reporter) { >+ String[] deltaArray = helper.getURIs(); >+ for (int i = 0; i < deltaArray.length; i++) { >+ String delta = deltaArray[i]; >+ if (delta == null) >+ continue; >+ >+ if (reporter != null) { >+ Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, delta.substring(1)); >+ reporter.displaySubtask(this, message); >+ } >+ >+ IResource resource = getResource(delta); >+ if (resource == null || !(resource instanceof IFile)) >+ continue; >+ validateFile(helper, reporter, (IFile) resource); >+ } >+ } >+ >+ /** >+ */ >+ private void validateFile(IValidationContext helper, IReporter reporter, IFile file) { >+ if ((reporter != null) && (reporter.isCancelled() == true)) { >+ throw new OperationCanceledException(); >+ } >+ if (!shouldValidate(file)) { >+ return; >+ } >+ IDOMModel model = getModel(file.getProject(), file); >+ if (model == null) >+ return; >+ >+ try { >+ validate(reporter, file, model); >+ } >+ finally { >+ releaseModel(model); >+ } >+ } >+ >+ /** >+ */ >+ private void validateFull(IValidationContext helper, IReporter reporter) { >+ IProject project = null; >+ String[] fileDelta = helper.getURIs(); >+ if (helper instanceof IWorkbenchContext) { >+ IWorkbenchContext wbHelper = (IWorkbenchContext) helper; >+ project = wbHelper.getProject(); >+ } >+ else if (fileDelta.length > 0) { >+ // won't work for project validation (b/c nothing in file delta) >+ project = getResource(fileDelta[0]).getProject(); >+ } >+ if (project == null) >+ return; >+ validateContainer(helper, reporter, project); >+ } >+ >+ /* >+ * added to get rid or dependency on IWorkbenchHelper >+ */ >+ public IResource getResource(String delta) { >+ return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(delta)); >+ } >+ >+ public ISchedulingRule getSchedulingRule(IValidationContext helper) { >+ return null; >+ } >+ >+ public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException { >+ // Exception catching was removed, see >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123600 >+ IStatus status = Status.OK_STATUS; >+ validate(helper, reporter); >+ return status; >+ } >+ >+ /** >+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, >+ * java.lang.String, java.lang.Object) >+ */ >+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) >+ throws CoreException { >+ fAdditionalContentTypesIDs = new String[0]; >+ if (data != null) { >+ if (data instanceof String && data.toString().length() > 0) { >+ fAdditionalContentTypesIDs = StringUtils.unpack(data.toString()); >+ } >+ } >+ } >+ >+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { >+ if (resource.getType() != IResource.FILE) >+ return null; >+ ValidationResult result = new ValidationResult(); >+ IReporter reporter = result.getReporter(monitor); >+ validateFile(null, reporter, (IFile) resource); >+ return result; >+ } >+} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,65 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+import java.util.Locale; >+ >+import org.eclipse.core.resources.IResource; >+import org.eclipse.wst.validation.internal.core.Message; >+ >+/** >+ * copied from org.eclipse.wst.validation.internal.operations.LocalizedMessage >+ * >+ * This class is provided for validators which run only in Eclipse and whose messages, because they >+ * come from another tool, are already localized. LocalizedMessage cannot be used by any validator >+ * which needs to run in both WebSphere and Eclipse. >+ */ >+public class LocalizedMessage extends Message { >+ private String _message = null; >+ >+ public LocalizedMessage(int severity, String messageText) { >+ this(severity, messageText, null); >+ } >+ >+ public LocalizedMessage(int severity, String messageText, IResource targetObject) { >+ this(severity, messageText, (Object) targetObject); >+ } >+ >+ public LocalizedMessage(int severity, String messageText, Object targetObject) { >+ super(null, severity, null); >+ setLocalizedMessage(messageText); >+ setTargetObject(targetObject); >+ } >+ >+ public void setLocalizedMessage(String message) { >+ _message = message; >+ } >+ >+ public String getLocalizedMessage() { >+ return _message; >+ } >+ >+ public String getText() { >+ return getLocalizedMessage(); >+ } >+ >+ public String getText(ClassLoader cl) { >+ return getLocalizedMessage(); >+ } >+ >+ public String getText(Locale l) { >+ return getLocalizedMessage(); >+ } >+ >+ public String getText(Locale l, ClassLoader cl) { >+ return getLocalizedMessage(); >+ } >+} >Index: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+ >+/** >+ * >+ * Class to help this Problem's list. >+ * >+ */ >+class TaskListHelper { >+ private static TaskListHelper _taskListHelper = null; >+ >+ public static TaskListHelper getTaskList() { >+ if (_taskListHelper == null) { >+ _taskListHelper = new TaskListHelper(); >+ } >+ return _taskListHelper; >+ } >+ >+ /** >+ * This method adds a message to a resource in the task list. >+ */ >+ public void addTask(String pluginId, IResource resource, String location, String messageId, String message, int markerType, String targetObjectName, String groupName, int offset, int length) throws CoreException { >+ TaskListUtility.addTask(pluginId, resource, location, messageId, message, markerType, targetObjectName, groupName, offset, length); >+ } >+ >+ /** >+ * This method removes all messages from a resource in the task list. >+ */ >+ public void removeAllTasks(IResource resource, String owner, String objectName) throws CoreException { >+ TaskListUtility.removeAllTasks(resource, owner, objectName); >+ } >+} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,436 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.wst.html.core.internal.HTMLCorePlugin; >+import org.eclipse.wst.validation.internal.provisional.core.IMessage; >+ >+/** >+ * This class must be called only by the validation framework. >+ * >+ * This singleton interacts with the eclipse workbench's Task list. >+ * TaskListUtility adds and removes tasks from the list. >+ * >+ * This class must not be called outside of an IWorkspaceRunnable or >+ * IRunnableWithProgress. Many resource deltas can be generated by the methods >+ * in this class. >+ * >+ * This came from TaskListUtility >+ */ >+public class TaskListUtility { >+ // private static final String PLUGIN_ID = ValidationPlugin.PLUGIN_ID; >+ private static final String PLUGIN_ID = HTMLCorePlugin.ID; >+ private static final String VALIDATION_MARKER = PLUGIN_ID + ".problemmarker"; //$NON-NLS-1$ // The extension which is used to add validation markers to the task list >+ private static final String VALIDATION_MARKER_OWNER = "owner"; //$NON-NLS-1$ // The IValidator who owns the IMarker on the task list >+ private static final String VALIDATION_MARKER_SEVERITY = "validationSeverity"; //$NON-NLS-1$ // one of the IMessage values >+ private static final String VALIDATION_MARKER_TARGETOBJECT = "targetObject"; //$NON-NLS-1$ // When more than one target object resolves to the same IResource, this field identifies which targetObject owns a particular message. >+ private static final String VALIDATION_MARKER_GROUP = "groupName"; //$NON-NLS-1$ // For incremental validation, this field associates a message with a group, so that a subset of messages may be removed from a file. >+ private static final String VALIDATION_MARKER_MESSAGEID = "messageId"; //$NON-NLS-1$ // Persist the message id of the message, not just the translated text. >+ private static final int DEPTH_INFINITE = IResource.DEPTH_INFINITE; >+ private static final int DEPTH_ZERO = IResource.DEPTH_ZERO; >+ private final static IMarker[] NO_MARKERS = new IMarker[0]; >+ >+ /** >+ * This method adds a message to a resource in the task list. >+ */ >+ public static IMarker addTask(String pluginId, IResource resource, String location, String messageId, String message, int markerType, String targetObjectName, String groupName, int offset, int length) throws CoreException { >+ if ((message == null) || (resource == null)) { >+ return null; >+ } >+ >+ int severity = getSeverity(markerType); >+ >+ // Allow duplicate entries in the task list. >+ // Prior to a full validation, the validation framework will remove >+ // all messages owned >+ // by a validator before it is executed. >+ // Prior to an incremental validation, the validation framework will >+ // remove all messages, >+ // on each of the changed resources, owned by a validator before it is >+ // invoked. >+ // >+ // It is up to the validator to make sure that it is not adding the >+ // same message >+ // in more than one place, and also to clear out any old messages >+ // which are not cleared >+ // by the validation framework. >+ IMarker item = resource.createMarker(VALIDATION_MARKER); // add a >+ // validation >+ // marker >+ >+ // For performance reasons, replace the multiple setAttribute >+ // calls above with a single setAttributes call. >+ boolean offsetSet = ((offset != IMessage.OFFSET_UNSET) && (length != IMessage.OFFSET_UNSET)); >+ int size = (offsetSet) ? 10 : 8; // add CHAR_START, CHAR_END only >+ // if the offset is set. If the >+ // offset is set, it takes >+ // precendence over the line >+ // number. (eclipse's rule, not >+ // mine.) >+ String[] attribNames = new String[size]; >+ Object[] attribValues = new Object[size]; >+ >+ // Very first thing, add the owner. That way, if the code dies >+ // before things are persisted, hopefully this marker will be >+ // persisted. >+ // Hopefully, eclipse WILL persist this field, as requested. >+ attribNames[0] = VALIDATION_MARKER_OWNER; >+ attribValues[0] = pluginId; >+ attribNames[1] = VALIDATION_MARKER_SEVERITY; // this validation >+ // severity is stored, >+ // in addition to the >+ // marker severity, to >+ // enable more than >+ // one severity of >+ // message to be >+ // displayed. e.g. >+ // ERROR | WARNING >+ // (using binary OR). >+ // The IMarker >+ // constants are >+ // regular decimal >+ // constants. >+ attribValues[1] = new Integer(markerType); >+ attribNames[2] = VALIDATION_MARKER_TARGETOBJECT; // to distinguish >+ // between >+ // messages which >+ // are registered >+ // on an >+ // IResource, but >+ // against >+ // different >+ // target objects >+ attribValues[2] = ((targetObjectName == null) ? "" : targetObjectName); //$NON-NLS-1$ >+ attribNames[3] = VALIDATION_MARKER_GROUP; >+ attribValues[3] = ((groupName == null) ? "" : groupName); //$NON-NLS-1$ >+ attribNames[4] = IMarker.MESSAGE; >+ attribValues[4] = message; >+ attribNames[5] = VALIDATION_MARKER_MESSAGEID; >+ attribValues[5] = messageId; >+ >+ attribNames[6] = IMarker.SEVERITY; // IMarker.SEVERITY_ERROR, >+ // IMarker.SEVERITY_WARNING, >+ // IMarker.SEVERITY_INFO >+ attribValues[6] = new Integer(severity); >+ try { >+ // If the location is a line number, store it as a line number >+ Integer lineNumber = Integer.valueOf(location); >+ attribNames[7] = IMarker.LINE_NUMBER; >+ attribValues[7] = lineNumber; >+ } >+ catch (NumberFormatException exc) { >+ // Otherwise, store it as a text location >+ attribNames[7] = IMarker.LOCATION; >+ attribValues[7] = location; >+ } >+ >+ if (offsetSet) { >+ attribNames[8] = IMarker.CHAR_START; >+ attribValues[8] = new Integer(offset); >+ attribNames[9] = IMarker.CHAR_END; >+ attribValues[9] = new Integer(offset + length); >+ } >+ >+ item.setAttributes(attribNames, attribValues); >+ >+ return item; >+ } >+ >+ /** >+ * Given one of the SeverityEnum severities, return the IMarker severity >+ * int that is its equivalent. >+ */ >+ private static int getSeverity(int severityEnumValue) { >+ switch (severityEnumValue) { >+ case (IMessage.HIGH_SEVERITY) : { >+ return IMarker.SEVERITY_ERROR; >+ } >+ >+ case (IMessage.LOW_SEVERITY) : { >+ return IMarker.SEVERITY_INFO; >+ } >+ >+ case (IMessage.NORMAL_SEVERITY) : { >+ return IMarker.SEVERITY_WARNING; >+ } >+ >+ case (IMessage.ALL_MESSAGES) : >+ case (IMessage.ERROR_AND_WARNING) : >+ default : { >+ // assume it's a warning. >+ return IMarker.SEVERITY_WARNING; >+ } >+ } >+ } >+ >+ private static int getDepth(IResource resource) { >+ if (resource instanceof IProject) { >+ return DEPTH_INFINITE; // DEPTH_INFINITE means get this project's >+ // markers, and the markers belonging to >+ // the project's children. >+ } >+ else if (resource instanceof IWorkspaceRoot) { >+ // Needed for the ValidationMigrator when it checks for orphan >+ // tasks. >+ return DEPTH_INFINITE; // DEPTH_INFINITE means get all of the >+ // markers in the workspace >+ } >+ >+ return DEPTH_ZERO; // DEPTH_ZERO means just this resource, not its >+ // children >+ } >+ >+ private static IMarker[] getValidationTasks(IResource resource, int severity, int depth) { >+ IMarker[] tempMarkers = null; >+ int validCount = 0; >+ try { >+ IMarker[] allMarkers = null; >+ try { >+ allMarkers = resource.findMarkers(VALIDATION_MARKER, false, depth); // false >+ // means >+ // only >+ // consider >+ // PROBLEM_MARKER, >+ // not >+ // variants >+ // of >+ // PROBLEM_MARKER. >+ // Since >+ // addTask >+ // only >+ // adds >+ // PROBLEM_MARKER, >+ // we >+ // don't >+ // need >+ // to >+ // consider >+ // its >+ // subtypes. >+ } >+ catch (CoreException exc) { >+ // Logger logger = >+ // ValidationPlugin.getPlugin().getMsgLogger(); >+ // if (logger.isLoggingLevel(Level.SEVERE)) { >+ // LogEntry entry = ValidationPlugin.getLogEntry(); >+ // entry.setSourceID("TaskListUtility.getValidationTasks(IResource, >+ // int)"); //$NON-NLS-1$ >+ // entry.setTargetException(exc); >+ // logger.write(Level.SEVERE, entry); >+ // } >+ return NO_MARKERS; >+ } >+ >+ // Now filter in the markers, based on severity type. >+ if (allMarkers.length != 0) { >+ tempMarkers = new IMarker[allMarkers.length]; >+ for (int i = 0; i < allMarkers.length; i++) { >+ IMarker marker = allMarkers[i]; >+ Integer filterSeverity = (Integer) marker.getAttribute(VALIDATION_MARKER_SEVERITY); >+ if (filterSeverity == null) { >+ // odd...marker wasn't created correctly. How could >+ // this happen? >+ // Default to the current severity and add it to the >+ // list. >+ try { >+ marker.setAttribute(IMarker.SEVERITY, getSeverity(severity)); >+ } >+ catch (CoreException exc) { >+ // Logger logger = >+ // ValidationPlugin.getPlugin().getMsgLogger(); >+ // if (logger.isLoggingLevel(Level.SEVERE)) { >+ // LogEntry entry = >+ // ValidationPlugin.getLogEntry(); >+ // entry.setSourceID("TaskListUtility.getValidationTasks(int, >+ // IResource, int)"); //$NON-NLS-1$ >+ // entry.setTargetException(exc); >+ // logger.write(Level.SEVERE, entry); >+ // } >+ continue; >+ } >+ catch (Exception exc) { >+ // Logger logger = >+ // ValidationPlugin.getPlugin().getMsgLogger(); >+ // if (logger.isLoggingLevel(Level.SEVERE)) { >+ // LogEntry entry = >+ // ValidationPlugin.getLogEntry(); >+ // entry.setSourceID("TaskListUtility.getValidationTasks(int, >+ // IResource, int)"); //$NON-NLS-1$ >+ // entry.setTargetException(exc); >+ // logger.write(Level.SEVERE, entry); >+ // } >+ continue; >+ } >+ } >+ else if ((severity & filterSeverity.intValue()) == 0) { >+ continue; >+ } >+ tempMarkers[validCount++] = marker; >+ } >+ } >+ } >+ catch (CoreException exc) { >+ // Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); >+ // if (logger.isLoggingLevel(Level.SEVERE)) { >+ // LogEntry entry = ValidationPlugin.getLogEntry(); >+ // entry.setSourceID("TaskListUtility.getValidationTasks(int, >+ // IResource, int)"); //$NON-NLS-1$ >+ // entry.setTargetException(exc); >+ // logger.write(Level.SEVERE, entry); >+ // } >+ } >+ >+ if (validCount == 0) { >+ return NO_MARKERS; >+ } >+ >+ IMarker[] validMarkers = new IMarker[validCount]; >+ System.arraycopy(tempMarkers, 0, validMarkers, 0, validCount); >+ return validMarkers; >+ } >+ >+ private static IMarker[] getValidationTasks(IResource resource, String[] messageOwners, int depth) { >+ IMarker[] markers = getValidationTasks(resource, IMessage.ALL_MESSAGES, depth); >+ if (markers.length == 0) { >+ return NO_MARKERS; >+ } >+ >+ IMarker[] temp = new IMarker[markers.length]; >+ int validCount = 0; >+ for (int i = 0; i < markers.length; i++) { >+ IMarker marker = markers[i]; >+ >+ try { >+ Object owner = marker.getAttribute(VALIDATION_MARKER_OWNER); >+ if ((owner == null) || !(owner instanceof String)) { >+ // The ValidationMigrator will remove any "unowned" >+ // validation markers. >+ continue; >+ } >+ >+ for (int j = 0; j < messageOwners.length; j++) { >+ String messageOwner = messageOwners[j]; >+ if (((String) owner).equals(messageOwner)) { >+ temp[validCount++] = marker; >+ break; >+ } >+ } >+ } >+ catch (CoreException exc) { >+ // Logger logger = >+ // ValidationPlugin.getPlugin().getMsgLogger(); >+ // if (logger.isLoggingLevel(Level.SEVERE)) { >+ // LogEntry entry = ValidationPlugin.getLogEntry(); >+ // entry.setSourceID("TaskListUtility.getValidationTasks(project, >+ // String[])"); //$NON-NLS-1$ >+ // entry.setTargetException(exc); >+ // logger.write(Level.SEVERE, entry); >+ // } >+ return NO_MARKERS; >+ } >+ } >+ >+ IMarker[] result = new IMarker[validCount]; >+ System.arraycopy(temp, 0, result, 0, validCount); >+ return result; >+ } >+ >+ /** >+ * This method retrieves all validation tasks from the resource. If depth >+ * is INFINITE, child tasks are returned as well. Only the tasks which are >+ * owned by the specified messageOwner, and apply to the named IMessage's >+ * target object (objectName) will be returned. >+ */ >+ private static IMarker[] getValidationTasks(IResource resource, String[] messageOwner, String objectName, String groupName, int depth) throws CoreException { >+ if ((messageOwner == null) || (resource == null)) { >+ return NO_MARKERS; >+ } >+ >+ int validCount = 0; >+ IMarker[] validList = null; >+ IMarker[] markers = getValidationTasks(resource, messageOwner, depth); >+ if (markers != null) { >+ validList = new IMarker[markers.length]; >+ for (int i = 0; i < markers.length; i++) { >+ IMarker marker = markers[i]; >+ >+ // If more than one target object resolves to the same >+ // resource, removing one target's >+ // messages should not remove the other target object's >+ // messages. >+ if (objectName != null) { >+ Object targetObject = marker.getAttribute(VALIDATION_MARKER_TARGETOBJECT); >+ if ((targetObject == null) || !(targetObject instanceof String) || !(((String) targetObject).equals(objectName))) { >+ continue; >+ } >+ } >+ >+ if (groupName != null) { >+ Object group = marker.getAttribute(VALIDATION_MARKER_GROUP); >+ if ((group == null) || !(group instanceof String) || !(((String) group).equals(groupName))) { >+ continue; >+ } >+ } >+ >+ validList[validCount++] = marker; >+ } >+ } >+ >+ if (validCount == 0) { >+ return NO_MARKERS; >+ } >+ >+ IMarker[] result = new IMarker[validCount]; >+ System.arraycopy(validList, 0, result, 0, validCount); >+ return result; >+ } >+ >+ /** >+ * This method removes all messages from a resource in the task list. >+ */ >+ public static void removeAllTasks(IResource resource, String owner, String objectName) throws CoreException { >+ removeAllTasks(resource, new String[]{owner}, objectName); >+ } >+ >+ public static void removeAllTasks(IResource resource, String[] owners, String objectName) throws CoreException { >+ removeAllTasks(resource, owners, objectName, getDepth(resource)); >+ } >+ >+ protected static void removeAllTasks(IResource resource, String[] owners, String objectName, int depth) throws CoreException { >+ removeTaskSubset(resource, owners, objectName, null, depth); // null >+ // means >+ // no >+ // group >+ // name >+ } >+ >+ /** >+ * This method removes a subset of tasks from the project, including child >+ * tasks. Every task which belongs to the group, identified by groupName, >+ * will be removed. >+ */ >+ protected static void removeTaskSubset(IResource resource, String[] owners, String objectName, String groupName, int depth) throws CoreException { >+ if ((owners == null) || (resource == null)) { >+ return; >+ } >+ >+ IMarker[] allTasks = getValidationTasks(resource, owners, objectName, groupName, depth); >+ if (allTasks.length > 0) { >+ ResourcesPlugin.getWorkspace().deleteMarkers(allTasks); >+ } >+ } >+} >Index: src/org/eclipse/wst/html/core/internal/HTMLCorePlugin.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCorePlugin.java,v >retrieving revision 1.9 >diff -u -r1.9 HTMLCorePlugin.java >--- src/org/eclipse/wst/html/core/internal/HTMLCorePlugin.java 10 Apr 2007 18:31:52 -0000 1.9 >+++ src/org/eclipse/wst/html/core/internal/HTMLCorePlugin.java 24 Feb 2011 13:49:52 -0000 >@@ -20,6 +20,9 @@ > * The main plugin class to be used in the desktop. > */ > public class HTMLCorePlugin extends Plugin { >+ >+ public final static String ID = "org.eclipse.wst.html.core"; //$NON-NLS-1$ >+ > // The shared instance. > private static HTMLCorePlugin plugin; > >#P org.eclipse.wst.html.ui >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.40.2.5 >diff -u -r1.40.2.5 MANIFEST.MF >--- META-INF/MANIFEST.MF 4 Nov 2010 01:39:59 -0000 1.40.2.5 >+++ META-INF/MANIFEST.MF 24 Feb 2011 13:49:53 -0000 >@@ -2,7 +2,7 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: %pluginName > Bundle-SymbolicName: org.eclipse.wst.html.ui; singleton:=true >-Bundle-Version: 1.0.504.qualifier >+Bundle-Version: 1.0.505.qualifier > Bundle-Activator: org.eclipse.wst.html.ui.internal.HTMLUIPlugin > Bundle-Vendor: %providerName > Bundle-Localization: plugin >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/plugin.properties,v >retrieving revision 1.32 >diff -u -r1.32 plugin.properties >--- plugin.properties 29 Apr 2010 00:47:28 -0000 1.32 >+++ plugin.properties 24 Feb 2011 13:49:53 -0000 >@@ -28,7 +28,6 @@ > HTML_Tag_context_type_Extension_Element.name=HTML Tag > HTML_Attribute_context_type_Extension_Element.name=HTML Attribute > HTML_Attribute_value_context_type_Extension_Element.name=HTML Attribute value >-HTML_Syntax_Validator.name=HTML Syntax Validator > ############################################################################### > #org.eclipse.ui.newWizards extension point > _UI_WIZARD_NAME = HTML File >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/plugin.xml,v >retrieving revision 1.94.2.1 >diff -u -r1.94.2.1 plugin.xml >--- plugin.xml 15 Dec 2010 20:56:27 -0000 1.94.2.1 >+++ plugin.xml 24 Feb 2011 13:49:53 -0000 >@@ -310,38 +310,13 @@ > </extension> > > <!--======================================================================================--> >- <!-- Workbench validation --> >- <!--======================================================================================--> >- <extension id="HTMLValidator" name="%HTML_Syntax_Validator.name" point="org.eclipse.wst.validation.validatorV2"> >- <validator >- build="true" >- class="org.eclipse.wst.html.internal.validation.HTMLValidator" >- manual="true" >- sourceid="org.eclipse.wst.html.ui.internal.validation.htmlsyntaxvalidator" >- version="1" >- markerId="org.eclipse.wst.html.core.validationMarker"> >- <include> >- <rules> >- <contentType id="org.eclipse.wst.html.core.htmlsource"></contentType> >- <fileext caseSensitive="false" ext="html"/> >- <fileext caseSensitive="false" ext="xhtml"/> >- <fileext caseSensitive="false" ext="htm"/> >- <fileext caseSensitive="false" ext="htpl"/> >- <fileext caseSensitive="false" ext="wml"/> >- </rules> >- </include> >- <group id="org.eclipse.wst.sse.core.structuredModelGroup"/> >- </validator> >- </extension> >- >- <!--======================================================================================--> > <!-- As you type validation --> > <!--======================================================================================--> > > <extension point="org.eclipse.wst.sse.ui.sourcevalidation"> > <validator > scope="total" >- class="org.eclipse.wst.html.internal.validation.HTMLValidator" >+ class="org.eclipse.wst.html.internal.validation.HTMLSourceValidator" > id="org.eclipse.wst.html.ui.internal.validation.htmlsyntaxvalidator"> > <contentTypeIdentifier > id="org.eclipse.wst.html.core.htmlsource"> >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLSourceValidator.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLSourceValidator.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLSourceValidator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-html-validation/org/eclipse/wst/html/internal/validation/HTMLSourceValidator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,210 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.html.internal.validation; >+ >+import org.eclipse.core.filebuffers.ITextFileBuffer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeConstants; >+import org.eclipse.wst.html.core.internal.validate.HTMLValidationAdapterFactory; >+import org.eclipse.wst.sse.core.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.FileBufferModelManager; >+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; >+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >+import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; >+import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator; >+import org.eclipse.wst.validation.internal.core.Message; >+import org.eclipse.wst.validation.internal.provisional.core.IMessage; >+import org.eclipse.wst.validation.internal.provisional.core.IReporter; >+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; >+import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >+import org.w3c.dom.Text; >+ >+public class HTMLSourceValidator extends HTMLValidator implements ISourceValidator { >+ >+ private IDocument fDocument; >+ >+ public HTMLSourceValidator() { >+ >+ super(); >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator >+ */ >+ public void connect(IDocument document) { >+ fDocument = document; >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator >+ */ >+ public void disconnect(IDocument document) { >+ fDocument = null; >+ } >+ >+ /** >+ * This validate call is for the ISourceValidator partial document validation approach >+ * >+ * @param dirtyRegion >+ * @param helper >+ * @param reporter >+ * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator >+ */ >+ public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) { >+ >+ if (helper == null || fDocument == null) >+ return; >+ >+ if ((reporter != null) && (reporter.isCancelled() == true)) { >+ throw new OperationCanceledException(); >+ } >+ >+ IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); >+ if (model == null) >+ return; // error >+ >+ try { >+ >+ IDOMDocument document = null; >+ if (model instanceof IDOMModel) { >+ document = ((IDOMModel) model).getDocument(); >+ } >+ >+ if (document == null || !hasHTMLFeature(document)) { >+ // handled in finally clause >+ // model.releaseFromRead(); >+ return; // ignore >+ } >+ >+ IPath filePath = null; >+ IFile file = null; >+ >+ ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument); >+ if (fb != null) { >+ filePath = fb.getLocation(); >+ >+ if (filePath.segmentCount() > 1) { >+ file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); >+ if (!file.isAccessible()) { >+ file = null; >+ } >+ } >+ } >+ else { >+ filePath = new Path(model.getId()); >+ } >+ >+ // this will be the wrong region if it's Text (instead of Element) >+ // we don't know how to validate Text >+ IndexedRegion ir = getCoveringNode(dirtyRegion); // model.getIndexedRegion(dirtyRegion.getOffset()); >+ if (ir instanceof Text) { >+ while (ir != null && ir instanceof Text) { >+ // it's assumed that this gets the IndexedRegion to >+ // the right of the end offset >+ ir = model.getIndexedRegion(ir.getEndOffset()); >+ } >+ } >+ >+ if (ir instanceof INodeNotifier) { >+ INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance(); >+ ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir); >+ if (adapter == null) >+ return; // error >+ >+ if (reporter != null) { >+ HTMLValidationReporter rep = null; >+ rep = getReporter(reporter, file, (IDOMModel) model); >+ rep.clear(); >+ adapter.setReporter(rep); >+ >+ Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, filePath.toString().substring(1)); >+ reporter.displaySubtask(this, mess); >+ } >+ adapter.validate(ir); >+ } >+ } >+ finally { >+ releaseModel(model); >+ } >+ } >+ >+ private IndexedRegion getCoveringNode(IRegion dirtyRegion) { >+ >+ IndexedRegion largestRegion = null; >+ if (fDocument instanceof IStructuredDocument) { >+ IStructuredDocumentRegion[] regions = ((IStructuredDocument) fDocument).getStructuredDocumentRegions( >+ dirtyRegion.getOffset(), dirtyRegion.getLength()); >+ largestRegion = getLargest(regions); >+ } >+ return largestRegion; >+ } >+ >+ /** >+ */ >+ private boolean hasHTMLFeature(IDOMDocument document) { >+ DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class); >+ if (adapter == null) >+ return false; >+ return adapter.hasFeature(HTMLDocumentTypeConstants.HTML); >+ } >+ >+ protected IndexedRegion getLargest(IStructuredDocumentRegion[] sdRegions) { >+ >+ if (sdRegions == null || sdRegions.length == 0) >+ return null; >+ >+ IndexedRegion currentLargest = getCorrespondingNode(sdRegions[0]); >+ for (int i = 0; i < sdRegions.length; i++) { >+ if (!sdRegions[i].isDeleted()) { >+ IndexedRegion corresponding = getCorrespondingNode(sdRegions[i]); >+ >+ if (currentLargest instanceof Text) >+ currentLargest = corresponding; >+ >+ if (corresponding != null) { >+ if (!(corresponding instanceof Text)) { >+ if (corresponding.getStartOffset() <= currentLargest.getStartOffset() >+ && corresponding.getEndOffset() >= currentLargest.getEndOffset()) >+ currentLargest = corresponding; >+ } >+ } >+ >+ } >+ } >+ return currentLargest; >+ } >+ >+ protected IndexedRegion getCorrespondingNode(IStructuredDocumentRegion sdRegion) { >+ IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); >+ IndexedRegion indexedRegion = null; >+ try { >+ if (sModel != null) >+ indexedRegion = sModel.getIndexedRegion(sdRegion.getStart()); >+ } >+ finally { >+ if (sModel != null) >+ sModel.releaseFromRead(); >+ } >+ return indexedRegion; >+ } >+} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java >--- src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationReporter.java 25 Mar 2008 18:12:24 -0000 1.7 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,150 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2001, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.html.internal.validation; >- >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.wst.html.core.internal.validate.MessageFactory; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >-import org.eclipse.wst.sse.core.internal.validate.ErrorInfo; >-import org.eclipse.wst.sse.core.internal.validate.ValidationMessage; >-import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; >-import org.eclipse.wst.validation.internal.provisional.core.IMessage; >-import org.eclipse.wst.validation.internal.provisional.core.IReporter; >-import org.eclipse.wst.validation.internal.provisional.core.IValidator; >- >-public class HTMLValidationReporter implements ValidationReporter { >- >- private IValidator owner = null; >- private IReporter reporter = null; >- private IFile file = null; >- private IStructuredModel model = null; >- private HTMLValidationResult result = null; >- private MessageFactory fFactory = null; >- >- /** >- */ >- public HTMLValidationReporter(IValidator owner, IReporter reporter, IFile file, IStructuredModel model) { >- super(); >- this.owner = owner; >- this.reporter = reporter; >- this.file = file; >- this.model = model; >- fFactory = new MessageFactory(file != null ? file.getProject() : null); >- } >- >- /** >- */ >- public void clear() { >- if (this.file == null) >- return; >- >- this.result = null; >- >- if (this.reporter != null) { >- this.reporter.removeAllMessages(this.owner, this.file); >- } >- else { >- // remove by myself? >- String id = HTMLValidator.class.getName(); >- try { >- // TaskListHelper API changed >- // TaskListHelper.getTaskList().removeAllTasks(id, this.file, >- // null); >- TaskListHelper.getTaskList().removeAllTasks(this.file, id, null); >- } >- catch (CoreException ex) { >- } >- } >- } >- >- >- /** >- */ >- public HTMLValidationResult getResult() { >- if (this.result == null) >- this.result = new HTMLValidationResult(); >- return this.result; >- } >- >- /** >- */ >- public void report(ValidationMessage message) { >- if (message == null || message.getSeverity() == ValidationMessage.IGNORE) >- return; >- IMessage mes = translateMessage(message); >- >- if (this.reporter != null) { >- this.reporter.addMessage(this.owner, mes); >- } >- else { >- if (this.file == null) >- return; >- >- // add by myself? >- String id = HTMLValidator.class.getName(); >- String location = Integer.toString(mes.getLineNumber()); >- String name = ""; //$NON-NLS-1$ >- IPath filePath = this.file.getFullPath(); >- if (filePath != null) { >- name = filePath.toString(); >- } >- try { >- TaskListHelper.getTaskList().addTask(id, this.file, location, mes.getId(), mes.getText(), mes.getSeverity(), name, mes.getGroupName(), mes.getOffset(), mes.getLength()); >- } >- catch (CoreException ex) { >- } >- } >- } >- >- /** >- * Translate ValidationMessage to IMessage and generate result log >- */ >- private IMessage translateMessage(ValidationMessage message) { >- int severity = IMessage.LOW_SEVERITY; >- HTMLValidationResult result = getResult(); >- switch (message.getSeverity()) { >- case ValidationMessage.ERROR : >- severity = IMessage.HIGH_SEVERITY; >- result.addError(); >- break; >- case ValidationMessage.WARNING : >- severity = IMessage.NORMAL_SEVERITY; >- result.addWarning(); >- break; >- case ValidationMessage.INFORMATION : >- result.addInformation(); >- break; >- default : >-// result.addInformation(); >- break; >- } >- >- IMessage mes = new LocalizedMessage(severity, message.getMessage(), this.file); >- mes.setOffset(message.getOffset()); >- mes.setLength(message.getLength()); >- if (this.model != null) { >- IStructuredDocument flatModel = this.model.getStructuredDocument(); >- if (flatModel != null) { >- int line = flatModel.getLineOfOffset(message.getOffset()); >- mes.setLineNo(line + 1); >- } >- } >- >- return mes; >- } >- >- public void report(ErrorInfo info) { >- report(fFactory.createMessage(info)); >- } >-} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java >--- src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidationResult.java 10 Apr 2007 18:30:16 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,64 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2001, 2005 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.html.internal.validation; >- >-public class HTMLValidationResult { >- private int errors = 0; >- private int warnings = 0; >- private int informations = 0; >- >- /** >- */ >- public HTMLValidationResult() { >- } >- >- /** >- */ >- public void addError() { >- this.errors++; >- } >- >- /** >- */ >- public void addInformation() { >- this.informations++; >- } >- >- /** >- */ >- public void addWarning() { >- this.warnings++; >- } >- >- /** >- */ >- public int getErrors() { >- return this.errors; >- } >- >- /** >- */ >- public int getInformations() { >- return this.informations; >- } >- >- /** >- */ >- public int getWarnings() { >- return this.warnings; >- } >- >- /** >- */ >- public boolean isValid() { >- return (this.errors == 0 && this.warnings == 0 && this.informations == 0); >- } >-} >Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java >--- src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java 17 Feb 2009 01:44:39 -0000 1.26 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,560 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2001, 2007 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.html.internal.validation; >- >-import java.io.IOException; >-import java.io.UnsupportedEncodingException; >-import java.util.ArrayList; >-import java.util.List; >- >-import org.eclipse.core.filebuffers.ITextFileBuffer; >-import org.eclipse.core.resources.IContainer; >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IConfigurationElement; >-import org.eclipse.core.runtime.IExecutableExtension; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.NullProgressMonitor; >-import org.eclipse.core.runtime.OperationCanceledException; >-import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.Platform; >-import org.eclipse.core.runtime.Status; >-import org.eclipse.core.runtime.content.IContentDescription; >-import org.eclipse.core.runtime.content.IContentType; >-import org.eclipse.core.runtime.content.IContentTypeManager; >-import org.eclipse.core.runtime.jobs.ISchedulingRule; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.IRegion; >-import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeConstants; >-import org.eclipse.wst.html.core.internal.validate.HTMLValidationAdapterFactory; >-import org.eclipse.wst.html.ui.internal.Logger; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.FileBufferModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; >-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >-import org.eclipse.wst.sse.core.internal.util.URIResolver; >-import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; >-import org.eclipse.wst.sse.core.utils.StringUtils; >-import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator; >-import org.eclipse.wst.validation.AbstractValidator; >-import org.eclipse.wst.validation.ValidationResult; >-import org.eclipse.wst.validation.ValidationState; >-import org.eclipse.wst.validation.internal.core.Message; >-import org.eclipse.wst.validation.internal.core.ValidationException; >-import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; >-import org.eclipse.wst.validation.internal.operations.WorkbenchReporter; >-import org.eclipse.wst.validation.internal.provisional.core.IMessage; >-import org.eclipse.wst.validation.internal.provisional.core.IReporter; >-import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; >-import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; >-import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; >-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; >-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >-import org.w3c.dom.Text; >- >-public class HTMLValidator extends AbstractValidator implements IValidatorJob, ISourceValidator, IExecutableExtension { >- private static final String ORG_ECLIPSE_WST_HTML_CORE_HTMLSOURCE = "org.eclipse.wst.html.core.htmlsource"; //$NON-NLS-1$ >- >- static boolean shouldValidate(IFile file) { >- IResource resource = file; >- do { >- if (resource.isDerived() || resource.isTeamPrivateMember() || !resource.isAccessible() || (resource.getName().charAt(0) == '.' && resource.getType() == IResource.FOLDER)) { >- return false; >- } >- resource = resource.getParent(); >- } >- while ((resource.getType() & IResource.PROJECT) == 0); >- return true; >- } >- >- private IDocument fDocument; >- private IContentTypeManager fContentTypeManager; >- private IContentType[] fOtherSupportedContentTypes = null; >- private String[] fAdditionalContentTypesIDs = null; >- private IContentType fHTMLContentType; >- >- public HTMLValidator() { >- super(); >- fContentTypeManager = Platform.getContentTypeManager(); >- fHTMLContentType = fContentTypeManager.getContentType(ORG_ECLIPSE_WST_HTML_CORE_HTMLSOURCE); >- } >- >- /** >- */ >- public void cleanup(IReporter reporter) { >- // nothing to do >- } >- >- /** >- * Gets list of content types this validator is interested in >- * >- * @return All HTML-related content types >- */ >- private IContentType[] getOtherSupportedContentTypes() { >- if (fOtherSupportedContentTypes == null) { >- List contentTypes = new ArrayList(3); >- if (fAdditionalContentTypesIDs != null) { >- for (int i = 0; i < fAdditionalContentTypesIDs.length; i++) { >- IContentType type = Platform.getContentTypeManager().getContentType(fAdditionalContentTypesIDs[i]); >- if (type != null) { >- contentTypes.add(type); >- } >- } >- } >- fOtherSupportedContentTypes = (IContentType[]) contentTypes.toArray(new IContentType[contentTypes.size()]); >- } >- return fOtherSupportedContentTypes; >- } >- >- >- /** >- */ >- protected IDOMModel getModel(IProject project, IFile file) { >- if (project == null || file == null) >- return null; >- if (!file.exists()) >- return null; >- if (!canHandle(file)) >- return null; >- >- IStructuredModel model = null; >- IModelManager manager = StructuredModelManager.getModelManager(); >- try { >- file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); >- } >- catch (CoreException e) { >- Logger.logException(e); >- } >- try { >- try { >- model = manager.getModelForRead(file); >- } >- catch (UnsupportedEncodingException ex) { >- // retry ignoring META charset for invalid META charset >- // specification >- // recreate input stream, because it is already partially read >- model = manager.getModelForRead(file, new String(), null); >- } >- } >- catch (UnsupportedEncodingException ex) { >- } >- catch (IOException ex) { >- } >- catch (CoreException e) { >- Logger.logException(e); >- } >- >- if (model == null) >- return null; >- if (!(model instanceof IDOMModel)) { >- releaseModel(model); >- return null; >- } >- return (IDOMModel) model; >- } >- >- /** >- */ >- protected HTMLValidationReporter getReporter(IReporter reporter, IFile file, IDOMModel model) { >- return new HTMLValidationReporter(this, reporter, file, model); >- } >- >- /** >- * Check file extension to validate >- */ >- private boolean canHandle(IFile file) { >- boolean result = false; >- if (file != null) { >- try { >- IContentDescription contentDescription = file.getContentDescription(); >- if (contentDescription != null) { >- IContentType fileContentType = contentDescription.getContentType(); >- if (fileContentType.isKindOf(fHTMLContentType)) { >- result = true; >- } >- else { >- IContentType[] otherTypes = getOtherSupportedContentTypes(); >- for (int i = 0; i < otherTypes.length; i++) { >- result = result || fileContentType.isKindOf(otherTypes[i]); >- } >- } >- } >- else if (fHTMLContentType != null) { >- result = fHTMLContentType.isAssociatedWith(file.getName()); >- } >- } >- catch (CoreException e) { >- // should be rare, but will ignore to avoid logging "encoding >- // exceptions" and the like here. >- // Logger.logException(e); >- } >- } >- return result; >- } >- >- /** >- */ >- private boolean hasHTMLFeature(IDOMDocument document) { >- DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class); >- if (adapter == null) >- return false; >- return adapter.hasFeature(HTMLDocumentTypeConstants.HTML); >- } >- >- /** >- */ >- protected void releaseModel(IStructuredModel model) { >- if (model != null) >- model.releaseFromRead(); >- } >- >- /** >- */ >- public void validate(IValidationContext helper, IReporter reporter) { >- if (helper == null) >- return; >- if ((reporter != null) && (reporter.isCancelled() == true)) { >- throw new OperationCanceledException(); >- } >- String[] deltaArray = helper.getURIs(); >- if (deltaArray != null && deltaArray.length > 0) { >- validateDelta(helper, reporter); >- } >- else { >- validateFull(helper, reporter); >- } >- } >- >- /** >- * This validate call is for the ISourceValidator partial document >- * validation approach >- * >- * @param dirtyRegion >- * @param helper >- * @param reporter >- * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator >- */ >- public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) { >- >- if (helper == null || fDocument == null) >- return; >- >- if ((reporter != null) && (reporter.isCancelled() == true)) { >- throw new OperationCanceledException(); >- } >- >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); >- if (model == null) >- return; // error >- >- try { >- >- IDOMDocument document = null; >- if (model instanceof IDOMModel) { >- document = ((IDOMModel) model).getDocument(); >- } >- >- if (document == null || !hasHTMLFeature(document)) { >- // handled in finally clause >- // model.releaseFromRead(); >- return; //ignore >- } >- >- IPath filePath = null; >- IFile file = null; >- >- ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument); >- if (fb != null) { >- filePath = fb.getLocation(); >- >- if (filePath.segmentCount() > 1) { >- file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); >- if (!file.isAccessible()) { >- file = null; >- } >- } >- } >- else { >- filePath = new Path(model.getId()); >- } >- >- // this will be the wrong region if it's Text (instead of Element) >- // we don't know how to validate Text >- IndexedRegion ir = getCoveringNode(dirtyRegion); // model.getIndexedRegion(dirtyRegion.getOffset()); >- if (ir instanceof Text) { >- while (ir != null && ir instanceof Text) { >- // it's assumed that this gets the IndexedRegion to >- // the right of the end offset >- ir = model.getIndexedRegion(ir.getEndOffset()); >- } >- } >- >- if (ir instanceof INodeNotifier) { >- >- INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance(); >- ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir); >- if (adapter == null) >- return; // error >- >- if (reporter != null) { >- HTMLValidationReporter rep = null; >- rep = getReporter(reporter, file, (IDOMModel) model); >- rep.clear(); >- adapter.setReporter(rep); >- >- Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, filePath.toString().substring(1)); >- reporter.displaySubtask(this, mess); >- } >- adapter.validate(ir); >- } >- } >- finally { >- if (model != null) >- model.releaseFromRead(); >- } >- } >- >- private IndexedRegion getCoveringNode(IRegion dirtyRegion) { >- >- IndexedRegion largestRegion = null; >- if(fDocument instanceof IStructuredDocument) { >- IStructuredDocumentRegion[] regions = ((IStructuredDocument) fDocument).getStructuredDocumentRegions(dirtyRegion.getOffset(), dirtyRegion.getLength()); >- largestRegion = getLargest(regions); >- } >- return largestRegion; >- } >- protected IndexedRegion getLargest(IStructuredDocumentRegion[] sdRegions) { >- >- if(sdRegions == null || sdRegions.length == 0) >- return null; >- >- IndexedRegion currentLargest = getCorrespondingNode(sdRegions[0]); >- for (int i = 0; i < sdRegions.length; i++) { >- if(!sdRegions[i].isDeleted()) { >- IndexedRegion corresponding = getCorrespondingNode(sdRegions[i]); >- >- if(currentLargest instanceof Text) >- currentLargest = corresponding; >- >- if(corresponding != null) { >- if(!(corresponding instanceof Text)) { >- if (corresponding.getStartOffset() <= currentLargest.getStartOffset() >- && corresponding.getEndOffset() >= currentLargest.getEndOffset() ) >- currentLargest = corresponding; >- } >- } >- >- } >- } >- return currentLargest; >- } >- protected IndexedRegion getCorrespondingNode(IStructuredDocumentRegion sdRegion) { >- IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); >- IndexedRegion indexedRegion = null; >- try { >- if (sModel != null) >- indexedRegion = sModel.getIndexedRegion(sdRegion.getStart()); >- } finally { >- if (sModel != null) >- sModel.releaseFromRead(); >- } >- return indexedRegion; >- } >- >- /** >- * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator >- */ >- public void connect(IDocument document) { >- fDocument = document; >- } >- >- /** >- * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator >- */ >- public void disconnect(IDocument document) { >- fDocument = null; >- } >- >- /** >- */ >- protected HTMLValidationResult validate(IDOMModel model, IFile file) { >- IProject prj = null; >- if (file != null) { >- prj = file.getProject(); >- } >- if ((prj == null) && (model != null)) { >- URIResolver res = model.getResolver(); >- if (res != null) { >- prj = res.getProject(); >- } >- } >- final WorkbenchReporter reporter = new WorkbenchReporter(prj, new NullProgressMonitor()); >- return validate(reporter, file, model); >- } >- >- /** >- */ >- private HTMLValidationResult validate(IReporter reporter, IFile file, IDOMModel model) { >- if (file == null || model == null) >- return null; // error >- IDOMDocument document = model.getDocument(); >- if (document == null) >- return null; // error >- if (!hasHTMLFeature(document)) >- return null; // ignore >- >- INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance(); >- ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document); >- if (adapter == null) >- return null; // error >- >- HTMLValidationReporter rep = getReporter(reporter, file, model); >- rep.clear(); >- adapter.setReporter(rep); >- adapter.validate(document); >- return rep.getResult(); >- } >- >- /** >- */ >- private void validateContainer(IValidationContext helper, IReporter reporter, IContainer container) { >- try { >- IResource[] resourceArray = container.members(false); >- for (int i = 0; i < resourceArray.length; i++) { >- IResource resource = resourceArray[i]; >- if (resource == null || reporter.isCancelled()) >- continue; >- if (resource instanceof IFile) { >- Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, resource.getFullPath().toString().substring(1)); >- reporter.displaySubtask(this, message); >- validateFile(helper, reporter, (IFile) resource); >- } >- else if (resource instanceof IContainer) { >- validateContainer(helper, reporter, (IContainer) resource); >- } >- } >- } >- catch (CoreException ex) { >- } >- } >- >- /** >- */ >- private void validateDelta(IValidationContext helper, IReporter reporter) { >- String[] deltaArray = helper.getURIs(); >- for (int i = 0; i < deltaArray.length; i++) { >- String delta = deltaArray[i]; >- if (delta == null) >- continue; >- >- if (reporter != null) { >- Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, delta.substring(1)); >- reporter.displaySubtask(this, message); >- } >- >- IResource resource = getResource(delta); >- if (resource == null || !(resource instanceof IFile)) >- continue; >- validateFile(helper, reporter, (IFile) resource); >- } >- } >- >- /** >- */ >- private void validateFile(IValidationContext helper, IReporter reporter, IFile file) { >- if ((reporter != null) && (reporter.isCancelled() == true)) { >- throw new OperationCanceledException(); >- } >- if (!shouldValidate(file)) { >- return; >- } >- IDOMModel model = getModel(file.getProject(), file); >- if (model == null) >- return; >- >- try { >- validate(reporter, file, model); >- } >- finally { >- releaseModel(model); >- } >- } >- >- /** >- */ >- private void validateFull(IValidationContext helper, IReporter reporter) { >- IProject project = null; >- String[] fileDelta = helper.getURIs(); >- if (helper instanceof IWorkbenchContext) { >- IWorkbenchContext wbHelper = (IWorkbenchContext) helper; >- project = wbHelper.getProject(); >- } >- else if(fileDelta.length > 0){ >- // won't work for project validation (b/c nothing in file delta) >- project = getResource(fileDelta[0]).getProject(); >- } >- if (project == null) >- return; >- validateContainer(helper, reporter, project); >- } >- >- /* >- * added to get rid or dependency on IWorkbenchHelper >- * >- */ >- public IResource getResource(String delta) { >- return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(delta)); >- } >- >- public ISchedulingRule getSchedulingRule(IValidationContext helper) { >- return null; >- } >- >- public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException { >- // Exception catching was removed, see >- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123600 >- IStatus status = Status.OK_STATUS; >- validate(helper, reporter); >- return status; >- } >- >- /** >- * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, >- * java.lang.String, java.lang.Object) >- */ >- public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { >- fAdditionalContentTypesIDs = new String[0]; >- if (data != null) { >- if (data instanceof String && data.toString().length() > 0) { >- fAdditionalContentTypesIDs = StringUtils.unpack(data.toString()); >- } >- } >- } >- >- public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { >- if (resource.getType() != IResource.FILE) >- return null; >- ValidationResult result = new ValidationResult(); >- IReporter reporter = result.getReporter(monitor); >- validateFile(null, reporter, (IFile) resource); >- return result; >- } >-} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java >--- src-html-validation/org/eclipse/wst/html/internal/validation/LocalizedMessage.java 10 Apr 2007 18:30:16 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,65 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2001, 2005 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.html.internal.validation; >- >-import java.util.Locale; >- >-import org.eclipse.core.resources.IResource; >-import org.eclipse.wst.validation.internal.core.Message; >- >-/** >- * copied from org.eclipse.wst.validation.internal.operations.LocalizedMessage >- * >- * This class is provided for validators which run only in Eclipse and whose messages, because they >- * come from another tool, are already localized. LocalizedMessage cannot be used by any validator >- * which needs to run in both WebSphere and Eclipse. >- */ >-public class LocalizedMessage extends Message { >- private String _message = null; >- >- public LocalizedMessage(int severity, String messageText) { >- this(severity, messageText, null); >- } >- >- public LocalizedMessage(int severity, String messageText, IResource targetObject) { >- this(severity, messageText, (Object) targetObject); >- } >- >- public LocalizedMessage(int severity, String messageText, Object targetObject) { >- super(null, severity, null); >- setLocalizedMessage(messageText); >- setTargetObject(targetObject); >- } >- >- public void setLocalizedMessage(String message) { >- _message = message; >- } >- >- public String getLocalizedMessage() { >- return _message; >- } >- >- public String getText() { >- return getLocalizedMessage(); >- } >- >- public String getText(ClassLoader cl) { >- return getLocalizedMessage(); >- } >- >- public String getText(Locale l) { >- return getLocalizedMessage(); >- } >- >- public String getText(Locale l, ClassLoader cl) { >- return getLocalizedMessage(); >- } >-} >Index: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java >--- src-html-validation/org/eclipse/wst/html/internal/validation/TaskListHelper.java 3 Oct 2005 00:53:44 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,44 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2001, 2005 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.html.internal.validation; >- >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.runtime.CoreException; >- >-/** >- * >- * Class to help this Problem's list. >- * >- */ >-class TaskListHelper { >- private static TaskListHelper _taskListHelper = null; >- >- public static TaskListHelper getTaskList() { >- if (_taskListHelper == null) { >- _taskListHelper = new TaskListHelper(); >- } >- return _taskListHelper; >- } >- >- /** >- * This method adds a message to a resource in the task list. >- */ >- public void addTask(String pluginId, IResource resource, String location, String messageId, String message, int markerType, String targetObjectName, String groupName, int offset, int length) throws CoreException { >- TaskListUtility.addTask(pluginId, resource, location, messageId, message, markerType, targetObjectName, groupName, offset, length); >- } >- >- /** >- * This method removes all messages from a resource in the task list. >- */ >- public void removeAllTasks(IResource resource, String owner, String objectName) throws CoreException { >- TaskListUtility.removeAllTasks(resource, owner, objectName); >- } >-} >\ No newline at end of file >Index: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java >=================================================================== >RCS file: src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java >diff -N src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java >--- src-html-validation/org/eclipse/wst/html/internal/validation/TaskListUtility.java 10 Apr 2007 18:30:16 -0000 1.5 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,436 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2001, 2007 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.html.internal.validation; >- >-import org.eclipse.core.resources.IMarker; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.IWorkspaceRoot; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.wst.html.ui.internal.HTMLUIPlugin; >-import org.eclipse.wst.validation.internal.provisional.core.IMessage; >- >-/** >- * This class must be called only by the validation framework. >- * >- * This singleton interacts with the eclipse workbench's Task list. >- * TaskListUtility adds and removes tasks from the list. >- * >- * This class must not be called outside of an IWorkspaceRunnable or >- * IRunnableWithProgress. Many resource deltas can be generated by the methods >- * in this class. >- * >- * This came from TaskListUtility >- */ >-public class TaskListUtility { >- // private static final String PLUGIN_ID = ValidationPlugin.PLUGIN_ID; >- private static final String PLUGIN_ID = HTMLUIPlugin.ID; >- private static final String VALIDATION_MARKER = PLUGIN_ID + ".problemmarker"; //$NON-NLS-1$ // The extension which is used to add validation markers to the task list >- private static final String VALIDATION_MARKER_OWNER = "owner"; //$NON-NLS-1$ // The IValidator who owns the IMarker on the task list >- private static final String VALIDATION_MARKER_SEVERITY = "validationSeverity"; //$NON-NLS-1$ // one of the IMessage values >- private static final String VALIDATION_MARKER_TARGETOBJECT = "targetObject"; //$NON-NLS-1$ // When more than one target object resolves to the same IResource, this field identifies which targetObject owns a particular message. >- private static final String VALIDATION_MARKER_GROUP = "groupName"; //$NON-NLS-1$ // For incremental validation, this field associates a message with a group, so that a subset of messages may be removed from a file. >- private static final String VALIDATION_MARKER_MESSAGEID = "messageId"; //$NON-NLS-1$ // Persist the message id of the message, not just the translated text. >- private static final int DEPTH_INFINITE = IResource.DEPTH_INFINITE; >- private static final int DEPTH_ZERO = IResource.DEPTH_ZERO; >- private final static IMarker[] NO_MARKERS = new IMarker[0]; >- >- /** >- * This method adds a message to a resource in the task list. >- */ >- public static IMarker addTask(String pluginId, IResource resource, String location, String messageId, String message, int markerType, String targetObjectName, String groupName, int offset, int length) throws CoreException { >- if ((message == null) || (resource == null)) { >- return null; >- } >- >- int severity = getSeverity(markerType); >- >- // Allow duplicate entries in the task list. >- // Prior to a full validation, the validation framework will remove >- // all messages owned >- // by a validator before it is executed. >- // Prior to an incremental validation, the validation framework will >- // remove all messages, >- // on each of the changed resources, owned by a validator before it is >- // invoked. >- // >- // It is up to the validator to make sure that it is not adding the >- // same message >- // in more than one place, and also to clear out any old messages >- // which are not cleared >- // by the validation framework. >- IMarker item = resource.createMarker(VALIDATION_MARKER); // add a >- // validation >- // marker >- >- // For performance reasons, replace the multiple setAttribute >- // calls above with a single setAttributes call. >- boolean offsetSet = ((offset != IMessage.OFFSET_UNSET) && (length != IMessage.OFFSET_UNSET)); >- int size = (offsetSet) ? 10 : 8; // add CHAR_START, CHAR_END only >- // if the offset is set. If the >- // offset is set, it takes >- // precendence over the line >- // number. (eclipse's rule, not >- // mine.) >- String[] attribNames = new String[size]; >- Object[] attribValues = new Object[size]; >- >- // Very first thing, add the owner. That way, if the code dies >- // before things are persisted, hopefully this marker will be >- // persisted. >- // Hopefully, eclipse WILL persist this field, as requested. >- attribNames[0] = VALIDATION_MARKER_OWNER; >- attribValues[0] = pluginId; >- attribNames[1] = VALIDATION_MARKER_SEVERITY; // this validation >- // severity is stored, >- // in addition to the >- // marker severity, to >- // enable more than >- // one severity of >- // message to be >- // displayed. e.g. >- // ERROR | WARNING >- // (using binary OR). >- // The IMarker >- // constants are >- // regular decimal >- // constants. >- attribValues[1] = new Integer(markerType); >- attribNames[2] = VALIDATION_MARKER_TARGETOBJECT; // to distinguish >- // between >- // messages which >- // are registered >- // on an >- // IResource, but >- // against >- // different >- // target objects >- attribValues[2] = ((targetObjectName == null) ? "" : targetObjectName); //$NON-NLS-1$ >- attribNames[3] = VALIDATION_MARKER_GROUP; >- attribValues[3] = ((groupName == null) ? "" : groupName); //$NON-NLS-1$ >- attribNames[4] = IMarker.MESSAGE; >- attribValues[4] = message; >- attribNames[5] = VALIDATION_MARKER_MESSAGEID; >- attribValues[5] = messageId; >- >- attribNames[6] = IMarker.SEVERITY; // IMarker.SEVERITY_ERROR, >- // IMarker.SEVERITY_WARNING, >- // IMarker.SEVERITY_INFO >- attribValues[6] = new Integer(severity); >- try { >- // If the location is a line number, store it as a line number >- Integer lineNumber = Integer.valueOf(location); >- attribNames[7] = IMarker.LINE_NUMBER; >- attribValues[7] = lineNumber; >- } >- catch (NumberFormatException exc) { >- // Otherwise, store it as a text location >- attribNames[7] = IMarker.LOCATION; >- attribValues[7] = location; >- } >- >- if (offsetSet) { >- attribNames[8] = IMarker.CHAR_START; >- attribValues[8] = new Integer(offset); >- attribNames[9] = IMarker.CHAR_END; >- attribValues[9] = new Integer(offset + length); >- } >- >- item.setAttributes(attribNames, attribValues); >- >- return item; >- } >- >- /** >- * Given one of the SeverityEnum severities, return the IMarker severity >- * int that is its equivalent. >- */ >- private static int getSeverity(int severityEnumValue) { >- switch (severityEnumValue) { >- case (IMessage.HIGH_SEVERITY) : { >- return IMarker.SEVERITY_ERROR; >- } >- >- case (IMessage.LOW_SEVERITY) : { >- return IMarker.SEVERITY_INFO; >- } >- >- case (IMessage.NORMAL_SEVERITY) : { >- return IMarker.SEVERITY_WARNING; >- } >- >- case (IMessage.ALL_MESSAGES) : >- case (IMessage.ERROR_AND_WARNING) : >- default : { >- // assume it's a warning. >- return IMarker.SEVERITY_WARNING; >- } >- } >- } >- >- private static int getDepth(IResource resource) { >- if (resource instanceof IProject) { >- return DEPTH_INFINITE; // DEPTH_INFINITE means get this project's >- // markers, and the markers belonging to >- // the project's children. >- } >- else if (resource instanceof IWorkspaceRoot) { >- // Needed for the ValidationMigrator when it checks for orphan >- // tasks. >- return DEPTH_INFINITE; // DEPTH_INFINITE means get all of the >- // markers in the workspace >- } >- >- return DEPTH_ZERO; // DEPTH_ZERO means just this resource, not its >- // children >- } >- >- private static IMarker[] getValidationTasks(IResource resource, int severity, int depth) { >- IMarker[] tempMarkers = null; >- int validCount = 0; >- try { >- IMarker[] allMarkers = null; >- try { >- allMarkers = resource.findMarkers(VALIDATION_MARKER, false, depth); // false >- // means >- // only >- // consider >- // PROBLEM_MARKER, >- // not >- // variants >- // of >- // PROBLEM_MARKER. >- // Since >- // addTask >- // only >- // adds >- // PROBLEM_MARKER, >- // we >- // don't >- // need >- // to >- // consider >- // its >- // subtypes. >- } >- catch (CoreException exc) { >- // Logger logger = >- // ValidationPlugin.getPlugin().getMsgLogger(); >- // if (logger.isLoggingLevel(Level.SEVERE)) { >- // LogEntry entry = ValidationPlugin.getLogEntry(); >- // entry.setSourceID("TaskListUtility.getValidationTasks(IResource, >- // int)"); //$NON-NLS-1$ >- // entry.setTargetException(exc); >- // logger.write(Level.SEVERE, entry); >- // } >- return NO_MARKERS; >- } >- >- // Now filter in the markers, based on severity type. >- if (allMarkers.length != 0) { >- tempMarkers = new IMarker[allMarkers.length]; >- for (int i = 0; i < allMarkers.length; i++) { >- IMarker marker = allMarkers[i]; >- Integer filterSeverity = (Integer) marker.getAttribute(VALIDATION_MARKER_SEVERITY); >- if (filterSeverity == null) { >- // odd...marker wasn't created correctly. How could >- // this happen? >- // Default to the current severity and add it to the >- // list. >- try { >- marker.setAttribute(IMarker.SEVERITY, getSeverity(severity)); >- } >- catch (CoreException exc) { >- // Logger logger = >- // ValidationPlugin.getPlugin().getMsgLogger(); >- // if (logger.isLoggingLevel(Level.SEVERE)) { >- // LogEntry entry = >- // ValidationPlugin.getLogEntry(); >- // entry.setSourceID("TaskListUtility.getValidationTasks(int, >- // IResource, int)"); //$NON-NLS-1$ >- // entry.setTargetException(exc); >- // logger.write(Level.SEVERE, entry); >- // } >- continue; >- } >- catch (Exception exc) { >- // Logger logger = >- // ValidationPlugin.getPlugin().getMsgLogger(); >- // if (logger.isLoggingLevel(Level.SEVERE)) { >- // LogEntry entry = >- // ValidationPlugin.getLogEntry(); >- // entry.setSourceID("TaskListUtility.getValidationTasks(int, >- // IResource, int)"); //$NON-NLS-1$ >- // entry.setTargetException(exc); >- // logger.write(Level.SEVERE, entry); >- // } >- continue; >- } >- } >- else if ((severity & filterSeverity.intValue()) == 0) { >- continue; >- } >- tempMarkers[validCount++] = marker; >- } >- } >- } >- catch (CoreException exc) { >- // Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); >- // if (logger.isLoggingLevel(Level.SEVERE)) { >- // LogEntry entry = ValidationPlugin.getLogEntry(); >- // entry.setSourceID("TaskListUtility.getValidationTasks(int, >- // IResource, int)"); //$NON-NLS-1$ >- // entry.setTargetException(exc); >- // logger.write(Level.SEVERE, entry); >- // } >- } >- >- if (validCount == 0) { >- return NO_MARKERS; >- } >- >- IMarker[] validMarkers = new IMarker[validCount]; >- System.arraycopy(tempMarkers, 0, validMarkers, 0, validCount); >- return validMarkers; >- } >- >- private static IMarker[] getValidationTasks(IResource resource, String[] messageOwners, int depth) { >- IMarker[] markers = getValidationTasks(resource, IMessage.ALL_MESSAGES, depth); >- if (markers.length == 0) { >- return NO_MARKERS; >- } >- >- IMarker[] temp = new IMarker[markers.length]; >- int validCount = 0; >- for (int i = 0; i < markers.length; i++) { >- IMarker marker = markers[i]; >- >- try { >- Object owner = marker.getAttribute(VALIDATION_MARKER_OWNER); >- if ((owner == null) || !(owner instanceof String)) { >- // The ValidationMigrator will remove any "unowned" >- // validation markers. >- continue; >- } >- >- for (int j = 0; j < messageOwners.length; j++) { >- String messageOwner = messageOwners[j]; >- if (((String) owner).equals(messageOwner)) { >- temp[validCount++] = marker; >- break; >- } >- } >- } >- catch (CoreException exc) { >- // Logger logger = >- // ValidationPlugin.getPlugin().getMsgLogger(); >- // if (logger.isLoggingLevel(Level.SEVERE)) { >- // LogEntry entry = ValidationPlugin.getLogEntry(); >- // entry.setSourceID("TaskListUtility.getValidationTasks(project, >- // String[])"); //$NON-NLS-1$ >- // entry.setTargetException(exc); >- // logger.write(Level.SEVERE, entry); >- // } >- return NO_MARKERS; >- } >- } >- >- IMarker[] result = new IMarker[validCount]; >- System.arraycopy(temp, 0, result, 0, validCount); >- return result; >- } >- >- /** >- * This method retrieves all validation tasks from the resource. If depth >- * is INFINITE, child tasks are returned as well. Only the tasks which are >- * owned by the specified messageOwner, and apply to the named IMessage's >- * target object (objectName) will be returned. >- */ >- private static IMarker[] getValidationTasks(IResource resource, String[] messageOwner, String objectName, String groupName, int depth) throws CoreException { >- if ((messageOwner == null) || (resource == null)) { >- return NO_MARKERS; >- } >- >- int validCount = 0; >- IMarker[] validList = null; >- IMarker[] markers = getValidationTasks(resource, messageOwner, depth); >- if (markers != null) { >- validList = new IMarker[markers.length]; >- for (int i = 0; i < markers.length; i++) { >- IMarker marker = markers[i]; >- >- // If more than one target object resolves to the same >- // resource, removing one target's >- // messages should not remove the other target object's >- // messages. >- if (objectName != null) { >- Object targetObject = marker.getAttribute(VALIDATION_MARKER_TARGETOBJECT); >- if ((targetObject == null) || !(targetObject instanceof String) || !(((String) targetObject).equals(objectName))) { >- continue; >- } >- } >- >- if (groupName != null) { >- Object group = marker.getAttribute(VALIDATION_MARKER_GROUP); >- if ((group == null) || !(group instanceof String) || !(((String) group).equals(groupName))) { >- continue; >- } >- } >- >- validList[validCount++] = marker; >- } >- } >- >- if (validCount == 0) { >- return NO_MARKERS; >- } >- >- IMarker[] result = new IMarker[validCount]; >- System.arraycopy(validList, 0, result, 0, validCount); >- return result; >- } >- >- /** >- * This method removes all messages from a resource in the task list. >- */ >- public static void removeAllTasks(IResource resource, String owner, String objectName) throws CoreException { >- removeAllTasks(resource, new String[]{owner}, objectName); >- } >- >- public static void removeAllTasks(IResource resource, String[] owners, String objectName) throws CoreException { >- removeAllTasks(resource, owners, objectName, getDepth(resource)); >- } >- >- protected static void removeAllTasks(IResource resource, String[] owners, String objectName, int depth) throws CoreException { >- removeTaskSubset(resource, owners, objectName, null, depth); // null >- // means >- // no >- // group >- // name >- } >- >- /** >- * This method removes a subset of tasks from the project, including child >- * tasks. Every task which belongs to the group, identified by groupName, >- * will be removed. >- */ >- protected static void removeTaskSubset(IResource resource, String[] owners, String objectName, String groupName, int depth) throws CoreException { >- if ((owners == null) || (resource == null)) { >- return; >- } >- >- IMarker[] allTasks = getValidationTasks(resource, owners, objectName, groupName, depth); >- if (allTasks.length > 0) { >- ResourcesPlugin.getWorkspace().deleteMarkers(allTasks); >- } >- } >-}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
nsand.dev
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 338111
: 189708