[304620] [validation]Markup Validator should be run along with the XML Validator
diff --git a/bundles/org.eclipse.jst.jsp.ui/plugin.xml b/bundles/org.eclipse.jst.jsp.ui/plugin.xml
index 6012f7c..bb02d00 100644
--- a/bundles/org.eclipse.jst.jsp.ui/plugin.xml
+++ b/bundles/org.eclipse.jst.jsp.ui/plugin.xml
@@ -154,22 +154,7 @@
</contentTypeIdentifier>
</validator>
</extension>
- <!--======================================================================================-->
- <!-- custom XML source (as you type) validation -->
- <!--======================================================================================-->
- <extension point="org.eclipse.wst.sse.ui.sourcevalidation">
- <validator
- scope="total"
- class="org.eclipse.wst.xml.ui.internal.validation.MarkupValidator"
- id="org.eclipse.jst.jsp.ui.internal.validation.markupvalidator">
- <contentTypeIdentifier
- id="org.eclipse.jst.jsp.core.jspsource">
- <partitionType id="org.eclipse.jst.jsp.JSP_DIRECTIVE"/>
- <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/>
- <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/>
- </contentTypeIdentifier>
- </validator>
- </extension>
+
<!--======================================================================================-->
<!-- HTML (as you type) validation -->
<!--======================================================================================-->
diff --git a/bundles/org.eclipse.wst.html.ui/plugin.xml b/bundles/org.eclipse.wst.html.ui/plugin.xml
index 2f06c98..3f0d41b 100644
--- a/bundles/org.eclipse.wst.html.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.html.ui/plugin.xml
@@ -353,19 +353,6 @@
</contentTypeIdentifier>
</validator>
</extension>
- <extension point="org.eclipse.wst.sse.ui.sourcevalidation">
- <validator
- scope="total"
- class="org.eclipse.wst.xml.ui.internal.validation.MarkupValidator"
- id="org.eclipse.wst.html.ui.internal.validation.markupvalidator">
- <contentTypeIdentifier
- id="org.eclipse.wst.html.core.htmlsource">
- <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/>
- <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/>
- </contentTypeIdentifier>
- </validator>
- </extension>
-
<!-- New HTML wizard -->
<extension point="org.eclipse.ui.newWizards">
diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/AnnotationMsg.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/AnnotationMsg.java
new file mode 100644
index 0000000..5ba65d9
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/AnnotationMsg.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.xml.core.internal.validation;
+
+public class AnnotationMsg {
+ public static String PROBMLEM_ID = "ProblemId"; //$NON-NLS-1$
+ public static String LENGTH = "Length"; //$NON-NLS-1$
+ public static String ATTRVALUETEXT = "AttributeValueText"; //$NON-NLS-1$
+ public static String ATTRVALUENO = "AttributeValueNo"; //$NON-NLS-1$
+ public static String ATTRNO = "AttrNo"; //$NON-NLS-1$
+ private int problemId;
+ private Object attributeValueText;
+ private int length;
+
+ public AnnotationMsg(int problemId, Object attributeValueText, int length) {
+ super();
+ this.problemId = problemId;
+ this.attributeValueText = attributeValueText;
+ this.length = length;
+ }
+ public int getProblemId() {
+ return problemId;
+ }
+
+ public Object getAttributeValueText() {
+ return attributeValueText;
+ }
+
+ public int getLength(){
+ return length;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/MarkupValidator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/MarkupValidator.java
new file mode 100644
index 0000000..a6d19bf
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/MarkupValidator.java
@@ -0,0 +1,929 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ *******************************************************************************/
+package org.eclipse.wst.xml.core.internal.validation;
+
+import java.util.Locale;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+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.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+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.LocalizedMessage;
+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.IValidator;
+import org.eclipse.wst.xml.core.internal.Logger;
+import org.eclipse.wst.xml.core.internal.XMLCoreMessages;
+import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
+import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.w3c.dom.Node;
+
+/**
+ * Basic XML syntax checking step.
+ */
+public class MarkupValidator extends AbstractValidator implements IValidator {
+ public static final int ELEMENT_ERROR_LIMIT = 25;
+ public static final int PARTIAL = 1;
+ public static final int TOTAL = 0;
+ private String DQUOTE = "\""; //$NON-NLS-1$
+ private String SQUOTE = "'"; //$NON-NLS-1$
+
+
+ private IDocument fDocument;
+
+ private IContentType fRootContentType = null;
+
+ private IReporter fReporter = null;
+
+ private static final String ANNOTATIONMSG = AnnotationMsg.class.getName();
+
+ public void getAnnotationMsg(IReporter reporter, int problemId, LocalizedMessage message, Object attributeValueText, int len){
+ AnnotationMsg annotation = new AnnotationMsg(problemId, attributeValueText,len);
+ message.setAttribute(ANNOTATIONMSG, annotation);
+ reporter.addMessage(this, message);
+ }
+
+
+ private void addAttributeError(String messageText, String attributeValueText, int start, int length, int problemId, IStructuredDocumentRegion sdRegion, IReporter reporter, int messageSeverity) {
+
+ if (sdRegion.isDeleted()) {
+ return;
+ }
+
+ int lineNo = getLineNumber(start);
+ LocalizedMessage message = new LocalizedMessage(messageSeverity, messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(lineNo);
+
+
+ getAnnotationMsg(reporter, problemId, message, attributeValueText,length);
+
+ }
+
+ private void checkAttributesInEndTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ ITextRegionList textRegions = structuredDocumentRegion.getRegions();
+ int errorCount = 0;
+ int start = structuredDocumentRegion.getEndOffset();
+ int end = structuredDocumentRegion.getEndOffset();
+ for (int i = 0; (i < textRegions.size()) && (errorCount < ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) {
+ ITextRegion textRegion = textRegions.get(i);
+ if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) {
+ if (start > structuredDocumentRegion.getStartOffset(textRegion)) {
+ start = structuredDocumentRegion.getStartOffset(textRegion);
+ }
+ end = structuredDocumentRegion.getEndOffset(textRegion);
+ errorCount++;
+ }
+ }
+ // create one error for all attributes in the end tag
+ if (errorCount > 0) {
+ // Position p = new Position(start, end - start);
+ String messageText = XMLCoreMessages.End_tag_has_attributes;
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES), messageText);
+ message.setOffset(start);
+ message.setLength(end - start);
+ message.setLineNo(getLineNumber(start));
+
+ getAnnotationMsg(reporter, ProblemIDsXML.AttrsInEndTag, message, null,end-start);
+
+ }
+ }
+
+
+ private void checkClosingBracket(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ ITextRegionList regions = structuredDocumentRegion.getRegions();
+ ITextRegion r = null;
+ boolean closed = false;
+ for (int i = 0; (i < regions.size()) && !structuredDocumentRegion.isDeleted(); i++) {
+ r = regions.get(i);
+ if ((r.getType() == DOMRegionContext.XML_TAG_CLOSE) || (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) {
+ closed = true;
+ }
+ }
+ if (!closed) {
+
+ String messageText = XMLCoreMessages.ReconcileStepForMarkup_6;
+
+ int start = structuredDocumentRegion.getStartOffset();
+ int length = structuredDocumentRegion.getText().trim().length();
+ int lineNo = getLineNumber(start);
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET) , messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(lineNo);
+ getAnnotationMsg(reporter, ProblemIDsXML.MissingClosingBracket, message, null,length);
+
+
+ }
+ }
+
+ private void checkEmptyTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ // navigate to name
+ ITextRegionList regions = structuredDocumentRegion.getRegions();
+ if (regions.size() == 2) {
+ // missing name region
+ if ((regions.get(0).getType() == DOMRegionContext.XML_TAG_OPEN) && (regions.get(1).getType() == DOMRegionContext.XML_TAG_CLOSE)) {
+ String messageText = XMLCoreMessages.ReconcileStepForMarkup_3;
+ int start = structuredDocumentRegion.getStartOffset();
+ int length = structuredDocumentRegion.getLength();
+ int lineNo = getLineNumber(start);
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_TAG_NAME) , messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(lineNo);
+
+ getAnnotationMsg(reporter, ProblemIDsXML.EmptyTag, message, null,length);
+ }
+ }
+ }
+
+ private int getLineNumber(int start) {
+ int lineNo = -1;
+ try {
+ lineNo = getDocument().getLineOfOffset(start) + 1;
+ }
+ catch (BadLocationException e) {
+ Logger.logException(e);
+ }
+ return lineNo;
+ }
+
+ private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ // check for attributes without a value
+ // track the attribute/equals/value sequence using a state of 0, 1 ,2
+ // representing the name, =, and value, respectively
+ int attrState = 0;
+ ITextRegionList textRegions = structuredDocumentRegion.getRegions();
+ // ReconcileAnnotationKey key = createKey(structuredDocumentRegion,
+ // getScope());
+
+ int errorCount = 0;
+ for (int i = 0; (i < textRegions.size()) && (errorCount < ELEMENT_ERROR_LIMIT); i++) {
+ ITextRegion textRegion = textRegions.get(i);
+ if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) {
+ // dangling name and '='
+ if ((attrState == 2) && (i >= 2)) {
+ // create annotation
+ ITextRegion nameRegion = textRegions.get(i - 2);
+ if (!(nameRegion instanceof ITextRegionContainer)) {
+ Object[] args = {structuredDocumentRegion.getText(nameRegion)};
+ String messageText = NLS.bind(XMLCoreMessages.Attribute__is_missing_a_value, args);
+
+ int start = structuredDocumentRegion.getStartOffset(nameRegion);
+ int end = structuredDocumentRegion.getEndOffset();
+ int lineNo = getLineNumber(start);
+ int textLength = structuredDocumentRegion.getText(nameRegion).trim().length();
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE) , messageText);
+ message.setOffset(start);
+ message.setLength(textLength);
+ message.setLineNo(lineNo);
+
+ // quick fix info
+ ITextRegion equalsRegion = textRegions.get(i - 2 + 1);
+ int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end;
+ Object[] additionalFixInfo = {structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset)};
+
+ getAnnotationMsg(reporter, ProblemIDsXML.MissingAttrValue, message, additionalFixInfo,textLength);
+ errorCount++;
+ }
+ }
+ // name but no '=' (XML only)
+ else if ((attrState == 1) && (i >= 1)) {
+ // create annotation
+ ITextRegion previousRegion = textRegions.get(i - 1);
+ if (!(previousRegion instanceof ITextRegionContainer)) {
+ Object[] args = {structuredDocumentRegion.getText(previousRegion)};
+ String messageText = NLS.bind(XMLCoreMessages.Attribute__has_no_value, args);
+ int start = structuredDocumentRegion.getStartOffset(previousRegion);
+ int textLength = structuredDocumentRegion.getText(previousRegion).trim().length();
+ int lineNo = getLineNumber(start);
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
+ message.setOffset(start);
+ message.setLength(textLength);
+ message.setLineNo(lineNo);
+
+ getAnnotationMsg(reporter, ProblemIDsXML.NoAttrValue, message, structuredDocumentRegion.getText(previousRegion),textLength);
+
+
+ errorCount++;
+ }
+ }
+ attrState = 1;
+ }
+ else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
+ attrState = 2;
+ }
+ else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
+ attrState = 0;
+ }
+ }
+
+ }
+
+ private void checkForSpaceBeforeName(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ String sdRegionText = structuredDocumentRegion.getFullText();
+ if (sdRegionText.startsWith(" ")) { //$NON-NLS-1$
+ IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious();
+ if (prev != null) {
+ // this is possibly the case of "< tag"
+ if ((prev.getRegions().size() == 1) && isStartTag(prev)) {
+ // add the error for preceding space in tag name
+ String messageText = XMLCoreMessages.ReconcileStepForMarkup_2;
+ int start = structuredDocumentRegion.getStartOffset();
+ // find length of whitespace
+ int length = sdRegionText.trim().equals("") ? sdRegionText.length() : sdRegionText.indexOf(sdRegionText.trim()); //$NON-NLS-1$
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME) , messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(getLineNumber(start));
+ getAnnotationMsg(reporter, ProblemIDsXML.SpacesBeforeTagName, message, null,length);
+ }
+ }
+ }
+ }
+
+ private void checkNoNamespaceInPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ // navigate to name
+ ITextRegionList regions = structuredDocumentRegion.getRegions();
+ ITextRegion r = null;
+ int errorCount = 0;
+ for (int i = 0; (i < regions.size()) && (errorCount < ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) {
+ r = regions.get(i);
+ if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
+ String piText = structuredDocumentRegion.getText(r);
+ int index = piText.indexOf(":"); //$NON-NLS-1$
+ if (index != -1) {
+ String messageText = XMLCoreMessages.ReconcileStepForMarkup_4;
+ int start = structuredDocumentRegion.getStartOffset(r) + index;
+ int length = piText.trim().length() - index;
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET) , messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(getLineNumber(start));
+
+
+ getAnnotationMsg(reporter, ProblemIDsXML.NamespaceInPI, message, null,length);
+
+ errorCount++;
+ }
+ }
+ }
+ }
+
+ private void checkQuotesForAttributeValues(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+ ITextRegionList regions = structuredDocumentRegion.getRegions();
+ ITextRegion r = null;
+ String attrValueText = ""; //$NON-NLS-1$
+ int errorCount = 0;
+ for (int i = 0; (i < regions.size()) && (errorCount < ELEMENT_ERROR_LIMIT); i++) {
+ r = regions.get(i);
+ if (r.getType() != DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
+ continue;
+ }
+
+ attrValueText = structuredDocumentRegion.getText(r);
+ // attribute value includes quotes in the string
+ // split up attribute value on quotes
+ /*
+ * WORKAROUND till
+ * http://dev.icu-project.org/cgi-bin/icu-bugs/incoming?findid=5207
+ * is fixed. (Also see BUG143628)
+ */
+
+ java.util.StringTokenizer st = new java.util.StringTokenizer(attrValueText, "\"'", true); //$NON-NLS-1$
+ int size = st.countTokens();
+ // get the pieces of the attribute value
+ String one = "", two = ""; //$NON-NLS-1$ //$NON-NLS-2$
+ if (size > 0) {
+ one = st.nextToken();
+ }
+ if (size > 1) {
+ two = st.nextToken();
+ }
+ if (size > 2) {
+ // should be handled by parsing...
+ // as in we can't have an attribute value like: <element
+ // attr="a"b"c"/>
+ // and <element attr='a"b"c' /> is legal
+ continue;
+ }
+
+
+ if (size == 1) {
+ if (one.equals(DQUOTE) || one.equals(SQUOTE)) {
+ // missing closing quote
+ String message = XMLCoreMessages.ReconcileStepForMarkup_0;
+ addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, reporter, getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE));
+ errorCount++;
+ }
+ else {
+ // missing both
+ String message = XMLCoreMessages.ReconcileStepForMarkup_1;
+ addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.AttrValueNotQuoted, structuredDocumentRegion, reporter, getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE));
+ errorCount++;
+ }
+ }
+ else if (size == 2) {
+ if ((one.equals(SQUOTE) && !two.equals(SQUOTE)) || (one.equals(DQUOTE) && !two.equals(DQUOTE))) {
+ // missing closing quote
+ String message = XMLCoreMessages.ReconcileStepForMarkup_0;
+ addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, reporter, getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE));
+ errorCount++;
+ }
+ }
+ }
+ // end of region for loop
+ }
+
+ private void checkStartEndTagPairs(IStructuredDocumentRegion sdRegion, IReporter reporter) {
+
+ if (sdRegion.isDeleted()) {
+ return;
+ }
+
+ // check start/end tag pairs
+ IDOMNode xmlNode = getXMLNode(sdRegion);
+
+ if (xmlNode == null) {
+ return;
+ }
+
+ boolean selfClosed = false;
+ String tagName = null;
+
+ /**
+ * For tags that aren't meant to be EMPTY, make sure it's empty or has an end tag
+ */
+ if (xmlNode.isContainer()) {
+ IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
+ if (endRegion == null) {
+ IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
+ if (startRegion != null && !startRegion.isDeleted() && DOMRegionContext.XML_TAG_OPEN.equals(startRegion.getFirstRegion().getType())) {
+ // analyze the tag (check self closing)
+ ITextRegionList regions = startRegion.getRegions();
+ ITextRegion r = null;
+ int start = sdRegion.getStart();
+ int length = sdRegion.getTextLength();
+ for (int i = 0; i < regions.size(); i++) {
+ r = regions.get(i);
+ if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
+ tagName = sdRegion.getText(r);
+ start = sdRegion.getStartOffset(r);
+ length = r.getTextLength();
+ }
+ else if (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
+ selfClosed = true;
+ }
+ }
+
+
+ if (!selfClosed && (tagName != null)) {
+ Object[] args = {tagName};
+ String messageText = NLS.bind(XMLCoreMessages.Missing_end_tag_, args);
+
+ int lineNumber = getLineNumber(start);
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_END_TAG) , messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(lineNumber);
+ Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
+
+ getAnnotationMsg(reporter, ProblemIDsXML.MissingEndTag, message, additionalFixInfo,length);
+ }
+ }
+ }
+ else {
+ IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
+ if (startRegion == null || startRegion.isDeleted()) {
+ // analyze the tag (check self closing)
+ ITextRegionList regions = endRegion.getRegions();
+ ITextRegion r = null;
+ int start = sdRegion.getStart();
+ int length = sdRegion.getTextLength();
+ for (int i = 0; i < regions.size(); i++) {
+ r = regions.get(i);
+ if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
+ tagName = sdRegion.getText(r);
+ start = sdRegion.getStartOffset(r);
+ length = r.getTextLength();
+ }
+ }
+
+ if (tagName != null) {
+ Object[] args = {tagName};
+ String messageText = NLS.bind(XMLCoreMessages.Missing_start_tag_, args);
+
+ int lineNumber = getLineNumber(start);
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_START_TAG), messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(lineNumber);
+ Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
+
+ getAnnotationMsg(reporter, ProblemIDsXML.MissingStartTag, message, additionalFixInfo,length);
+
+ }
+ }
+ }
+
+ }
+ /*
+ * Check for an end tag that has no start tag
+ */
+ else {
+ IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
+ if (startRegion == null) {
+ IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
+ if (!endRegion.isDeleted()) {
+ // get name
+ ITextRegionList regions = endRegion.getRegions();
+ ITextRegion r = null;
+ for (int i = 0; i < regions.size(); i++) {
+ r = regions.get(i);
+ if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
+ tagName = sdRegion.getText(r);
+ }
+ }
+
+ if (!selfClosed && (tagName != null)) {
+ String messageText = XMLCoreMessages.Indicate_no_grammar_specified_severities_error;
+
+ int start = sdRegion.getStart();
+ int lineNumber = getLineNumber(start);
+
+ // SEVERITY_STRUCTURE == IMessage.HIGH_SEVERITY
+ IMessage message = new LocalizedMessage(IMessage.HIGH_SEVERITY, messageText);
+ message.setOffset(start);
+ message.setLength(sdRegion.getTextLength());
+ message.setLineNo(lineNumber);
+
+ reporter.addMessage(this, message);
+ }
+ }
+ }
+ }
+ }
+
+ private Object[] getStartEndFixInfo(IDOMNode xmlNode, String tagName, ITextRegion r) {
+ // quick fix info
+ String tagClose = "/>"; //$NON-NLS-1$
+ int tagCloseOffset = xmlNode.getFirstStructuredDocumentRegion().getEndOffset();
+ if ((r != null) && (r.getType() == DOMRegionContext.XML_TAG_CLOSE)) {
+ tagClose = "/"; //$NON-NLS-1$
+ tagCloseOffset--;
+ }
+ IDOMNode firstChild = (IDOMNode) xmlNode.getFirstChild();
+ while ((firstChild != null) && (firstChild.getNodeType() == Node.TEXT_NODE)) {
+ firstChild = (IDOMNode) firstChild.getNextSibling();
+ }
+ int endOffset = xmlNode.getEndOffset();
+ int firstChildStartOffset = firstChild == null ? endOffset : firstChild.getStartOffset();
+ Object[] additionalFixInfo = {tagName, tagClose, new Integer(tagCloseOffset), new Integer(xmlNode.getFirstStructuredDocumentRegion().getEndOffset()), // startTagEndOffset
+ new Integer(firstChildStartOffset), // firstChildStartOffset
+ new Integer(endOffset)}; // endOffset
+ return additionalFixInfo;
+ }
+
+ private void checkStartingSpaceForPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion.isDeleted()) {
+ return;
+ }
+
+ IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious();
+ if ((prev != null) && prev.getStartOffset() == 0) {
+ if (prev.getType() == DOMRegionContext.XML_CONTENT) {
+ String messageText = XMLCoreMessages.ReconcileStepForMarkup_5;
+ int start = prev.getStartOffset();
+ int length = prev.getLength();
+
+ LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.WHITESPACE_AT_START) , messageText);
+ message.setOffset(start);
+ message.setLength(length);
+ message.setLineNo(getLineNumber(start));
+
+
+ getAnnotationMsg(reporter, ProblemIDsXML.SpacesBeforePI, message, null,length);
+
+ // Position p = new Position(start, length);
+ //
+ // ReconcileAnnotationKey key =
+ // createKey(structuredDocumentRegion, getScope());
+ // TemporaryAnnotation annotation = new TemporaryAnnotation(p,
+ // SEVERITY_SYNTAX_ERROR, message, key,
+ // ProblemIDsXML.SpacesBeforePI);
+ // results.add(annotation);
+ }
+ }
+ }
+
+ public int getScope() {
+ return PARTIAL;
+ }
+
+ private IDOMNode getXMLNode(IStructuredDocumentRegion sdRegion) {
+
+ if (sdRegion == null) {
+ return null;
+ }
+
+ IStructuredModel xModel = null;
+ IDOMNode xmlNode = null;
+ // get/release models should always be in a try/finally block
+ try {
+ xModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
+ // xModel is sometime null, when closing editor, for example
+ if (xModel != null) {
+ xmlNode = (IDOMNode) xModel.getIndexedRegion(sdRegion.getStart());
+ }
+ }
+ finally {
+ if (xModel != null) {
+ xModel.releaseFromRead();
+ }
+ }
+ return xmlNode;
+ }
+
+ /**
+ * Determines whether the IStructuredDocumentRegion is a XML "end tag"
+ * since they're not allowed to have attribute ITextRegions
+ *
+ * @param structuredDocumentRegion
+ */
+ private boolean isEndTag(IStructuredDocumentRegion structuredDocumentRegion) {
+ if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) {
+ return false;
+ }
+ return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN;
+ }
+
+ /**
+ * Determines if the IStructuredDocumentRegion is an XML Processing
+ * Instruction
+ *
+ * @param structuredDocumentRegion
+ *
+ */
+ private boolean isPI(IStructuredDocumentRegion structuredDocumentRegion) {
+ if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) {
+ return false;
+ }
+ return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_PI_OPEN;
+ }
+
+ /**
+ * Determines whether the IStructuredDocumentRegion is a XML "start tag"
+ * since they need to be checked for proper XML attribute region sequences
+ *
+ * @param structuredDocumentRegion
+ *
+ */
+ private boolean isStartTag(IStructuredDocumentRegion structuredDocumentRegion) {
+ if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) {
+ return false;
+ }
+ return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_TAG_OPEN;
+ }
+
+ // Because we check the "proper" closing separately from attribute
+ // sequencing, we need to know what's
+ // an appropriate close.
+ private boolean isTagCloseTextRegion(ITextRegion textRegion) {
+ return (textRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) || (textRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE);
+ }
+
+ /**
+ * Determines if the IStructuredDocumentRegion is XML Content
+ *
+ * @param structuredDocumentRegion
+ *
+ */
+ private boolean isXMLContent(IStructuredDocumentRegion structuredDocumentRegion) {
+ if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) {
+ return false;
+ }
+ return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_CONTENT;
+ }
+
+ private IDocument getDocument() {
+ return fDocument;
+ }
+
+ public void connect(IDocument document) {
+ fDocument = document;
+ }
+
+ public void disconnect(IDocument document) {
+ fDocument = null;
+ }
+
+ public void validate(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+
+ if (structuredDocumentRegion == null) {
+ return;
+ }
+
+ if (isStartTag(structuredDocumentRegion)) {
+ // check for attributes without a value
+ checkForAttributeValue(structuredDocumentRegion, reporter);
+ // check if started tag is ended
+ checkStartEndTagPairs(structuredDocumentRegion, reporter);
+ // check empty tag <>
+ checkEmptyTag(structuredDocumentRegion, reporter);
+ // check that each attribute has quotes
+ checkQuotesForAttributeValues(structuredDocumentRegion, reporter);
+ // check that the closing '>' is there
+ checkClosingBracket(structuredDocumentRegion, reporter);
+ }
+ else if (isEndTag(structuredDocumentRegion)) {
+ // check if ending tag was started
+ checkStartEndTagPairs(structuredDocumentRegion, reporter);
+ // check for attributes in an end tag
+ checkAttributesInEndTag(structuredDocumentRegion, reporter);
+ // check that the closing '>' is there
+ checkClosingBracket(structuredDocumentRegion, reporter);
+ }
+ else if (isPI(structuredDocumentRegion)) {
+ // check validity of processing instruction
+ checkStartingSpaceForPI(structuredDocumentRegion, reporter);
+ checkNoNamespaceInPI(structuredDocumentRegion, reporter);
+ }
+ else if (isXMLContent(structuredDocumentRegion)) {
+ checkForSpaceBeforeName(structuredDocumentRegion, reporter);
+ }
+ else if (isXMLDoctypeDeclaration(structuredDocumentRegion)) {
+ checkDocumentTypeReferences(structuredDocumentRegion, reporter);
+ }
+ }
+
+ /**
+ * @param structuredDocumentRegion
+ * @param reporter
+ */
+ private void checkDocumentTypeReferences(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
+ }
+
+ /**
+ * @param structuredDocumentRegion
+ * @return
+ */
+ private boolean isXMLDoctypeDeclaration(IStructuredDocumentRegion structuredDocumentRegion) {
+ if ((structuredDocumentRegion == null) || structuredDocumentRegion.isDeleted()) {
+ return false;
+ }
+ return structuredDocumentRegion.getFirstRegion().getType() == DOMRegionContext.XML_DECLARATION_OPEN && structuredDocumentRegion.getType().equals(DOMRegionContext.XML_DOCTYPE_DECLARATION);
+ }
+
+ public void cleanup(IReporter reporter) {
+ fDocument = null;
+ }
+
+ public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
+ String[] uris = helper.getURIs();
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ if (uris.length > 0) {
+ IFile currentFile = null;
+
+ for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
+ // might be called with just project path?
+ IPath path = new Path(uris[i]);
+ if (path.segmentCount() > 1) {
+ currentFile = wsRoot.getFile(path);
+ if (shouldValidate(currentFile, true)) {
+ validateV1File(currentFile, reporter);
+ }
+ }
+ else if (uris.length == 1) {
+ validateV1Project(helper, reporter);
+ }
+ }
+ }
+ else
+ validateV1Project(helper, reporter);
+ }
+
+ private boolean shouldValidate(IResourceProxy proxy) {
+ if(proxy.getType() == IResource.FILE) {
+ String name = proxy.getName();
+ if(name.toLowerCase(Locale.US).endsWith(".xml")) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ return shouldValidate(proxy.requestResource(), false);
+ }
+
+ private boolean shouldValidate(IResource file, boolean checkExtension) {
+ if (file == null || !file.exists() || file.getType() != IResource.FILE)
+ return false;
+ if (checkExtension) {
+ String extension = file.getFileExtension();
+ if (extension != null && "xml".endsWith(extension.toLowerCase(Locale.US))) //$NON-NLS-1$
+ return true;
+ }
+
+ IContentDescription contentDescription = null;
+ try {
+ contentDescription = ((IFile) file).getContentDescription();
+ if (contentDescription != null) {
+ IContentType contentType = contentDescription.getContentType();
+ return contentDescription != null && contentType.isKindOf(getXMLContentType());
+ }
+ }
+ catch (CoreException e) {
+ Logger.logException(e);
+ }
+ return false;
+ }
+
+ /**
+ * @param helper
+ * @param reporter
+ */
+ private void validateV1Project(IValidationContext helper, final IReporter reporter) {
+ // if uris[] length 0 -> validate() gets called for each project
+ if (helper instanceof IWorkbenchContext) {
+ IProject project = ((IWorkbenchContext) helper).getProject();
+ IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ if (shouldValidate(proxy)) {
+ validateV1File((IFile) proxy.requestResource(), reporter);
+ }
+ return true;
+ }
+ };
+ try {
+ // collect all jsp files for the project
+ project.accept(visitor, IResource.DEPTH_INFINITE);
+ }
+ catch (CoreException e) {
+ Logger.logException(e);
+ }
+ }
+ }
+
+
+ /**
+ * @param currentFile
+ * @param reporter
+ */
+ private void validateV1File(IFile currentFile, IReporter reporter) {
+ Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, currentFile.getFullPath().toString().substring(1));
+ reporter.displaySubtask(MarkupValidator.this, message);
+
+ IStructuredModel model = null;
+ try {
+ model = StructuredModelManager.getModelManager().getModelForRead(currentFile);
+ IStructuredDocument document = null;
+ if (model != null) {
+ document = model.getStructuredDocument();
+ connect(document);
+ IStructuredDocumentRegion validationRegion = document.getFirstStructuredDocumentRegion();
+ while (validationRegion != null) {
+ validate(validationRegion, reporter);
+ validationRegion = validationRegion.getNext();
+ }
+ disconnect(document);
+ }
+ }
+ catch (Exception e) {
+ Logger.logException(e);
+ }
+ finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ private IContentType getXMLContentType() {
+ if (fRootContentType == null) {
+ fRootContentType = Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); //$NON-NLS-1$
+ }
+ return fRootContentType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.validation.AbstractValidator#validate(org.eclipse.core.resources.IResource, int, org.eclipse.wst.validation.ValidationState, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ if (resource.getType() != IResource.FILE)
+ return null;
+ ValidationResult result = new ValidationResult();
+ fReporter = result.getReporter(monitor);
+
+ validateV1File((IFile) resource, fReporter);
+
+ return result;
+ }
+
+ public IReporter validate(IResource resource, int kind, ValidationState state) {
+ validate(resource,kind,state,new NullProgressMonitor());
+ return fReporter;
+ }
+ private Preferences getPluginPreference(){
+ return XMLCorePlugin.getDefault().getPluginPreferences();
+ }
+
+ public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) {
+ if (getDocument() == null) {
+ return;
+ }
+ if (!(getDocument() instanceof IStructuredDocument)) {
+ return;
+ }
+
+ // remove old messages
+ reporter.removeAllMessages(this);
+
+ IStructuredDocumentRegion[] regions = ((IStructuredDocument) fDocument).getStructuredDocumentRegions(dirtyRegion.getOffset(), dirtyRegion.getLength());
+ for (int i = 0; i < regions.length; i++) {
+ validate(regions[i], reporter);
+ }
+ }
+
+
+}
diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/ProblemIDsXML.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/ProblemIDsXML.java
new file mode 100644
index 0000000..cf34e74
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/ProblemIDsXML.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 20010 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.xml.core.internal.validation;
+
+public interface ProblemIDsXML {
+ int AttrsInEndTag = 3;
+ int AttrValueNotQuoted = 13;
+ int EmptyTag = 1;
+ int InvalidAttrValue = 11;
+ int MissingAttrValue = 4;
+ int MissingClosingBracket = 14;
+ int MissingEndTag = 2;
+ int MissingRequiredAttr = 12;
+ int MissingStartTag = 15;
+ int NamespaceInPI = 8;
+ int NoAttrValue = 5;
+ int SpacesBeforePI = 7;
+ int SpacesBeforeTagName = 6;
+ int Unclassified = 0;
+ int UnknownAttr = 10;
+ int UnknownElement = 9;
+}
diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java
index ad69888..e088fca 100644
--- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java
+++ b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/XMLValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2009 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 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
@@ -40,6 +40,7 @@
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLInputSource;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -49,7 +50,12 @@
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.internal.ValOperation;
+import org.eclipse.wst.validation.internal.operations.LocalizedMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.xml.core.internal.Logger;
+import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
+import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
import org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream;
import org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext;
import org.xml.sax.Attributes;
@@ -82,7 +88,11 @@
protected static final String NO_GRAMMAR_FOUND = "NO_GRAMMAR_FOUND"; //$NON-NLS-1$
private static final String FILE_NOT_FOUND_KEY = "FILE_NOT_FOUND"; //$NON-NLS-1$
-
+
+ private MarkupValidator val = new MarkupValidator();
+
+ private final String ANNOTATIONMSG = AnnotationMsg.class.getName();
+
/**
* Constructor.
*/
@@ -97,10 +107,10 @@
// Here we add some error keys that we need to adjust the location information for.
// The location information will be adjusted to place the message on the line of the starting
// element instead of on the line of the closing element.
- adjustLocationErrorKeySet.add("MSG_CONTENT_INVALID");
- adjustLocationErrorKeySet.add("MSG_CONTENT_INCOMPLETE");
- adjustLocationErrorKeySet.add("cvc-complex-type.2.4.b");
- adjustLocationErrorKeySet.add("cvc-complex-type.2.3");
+ adjustLocationErrorKeySet.add("MSG_CONTENT_INVALID"); //$NON-NLS-1$
+ adjustLocationErrorKeySet.add("MSG_CONTENT_INCOMPLETE"); //$NON-NLS-1$
+ adjustLocationErrorKeySet.add("cvc-complex-type.2.4.b"); //$NON-NLS-1$
+ adjustLocationErrorKeySet.add("cvc-complex-type.2.3"); //$NON-NLS-1$
}
/**
@@ -214,7 +224,7 @@
StringBuffer fileString = new StringBuffer();
try
{
- InputStreamReader inputReader = new InputStreamReader(inputStream, "UTF-8");
+ InputStreamReader inputReader = new InputStreamReader(inputStream, "UTF-8"); //$NON-NLS-1$
BufferedReader reader = new BufferedReader(inputReader);
char[] chars = new char[1024];
int numberRead = reader.read(chars);
@@ -296,7 +306,7 @@
*/
public XMLValidationReport validate(String uri, InputStream inputStream, XMLValidationConfiguration configuration, ValidationResult result, NestedValidatorContext context)
{
- String grammarFile = "";
+ String grammarFile = ""; //$NON-NLS-1$
Reader reader1 = null; // Used for the preparse.
Reader reader2 = null; // Used for validation parse.
@@ -380,11 +390,53 @@
Logger.logException(e.getLocalizedMessage(), e);
}
}
+
+ if ( XMLCorePlugin.getDefault().getPluginPreferences().getBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION)){
+ IReporter reporter = executeMarkupValidator(uri);
+ if (reporter != null){
+ List msgList = reporter.getMessages();
+ for (int i = 0;i < msgList.size();i++){
+ LocalizedMessage msg = (LocalizedMessage)msgList.get(i);
+ if (msg.getSeverity() == 2)
+ valinfo.addError(msg.getLocalizedMessage(), msg.getLineNumber(), msg.getOffset(),valinfo.getFileURI(),"null",getMsgArguments(msg) ); //$NON-NLS-1$
+ else if (msg.getSeverity() == 1)
+ valinfo.addWarning(msg.getLocalizedMessage(), msg.getLineNumber(), msg.getOffset(),valinfo.getFileURI(),"null", getMsgArguments(msg)); //$NON-NLS-1$
+ }
+ }
+ }
return valinfo;
}
+ private Object[] getMsgArguments(LocalizedMessage msg){
+ Object obj = msg.getAttribute(ANNOTATIONMSG);
+ return new Object[]{obj};
+ }
+
+
+ private IReporter executeMarkupValidator(String uri){
+ Path path = new Path(uri);
+ String fileProtocol = "file://"; //$NON-NLS-1$
+ int index = uri.indexOf(fileProtocol);
+
+ IFile resource = null;
+ if (index == 0){
+ String transformedUri = uri.substring(fileProtocol.length());
+ Path transformedPath = new Path(transformedUri);
+ resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(transformedPath);
+ }
+ else {
+ resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+
+ }
+ IReporter reporter = null;
+ if (resource != null){
+ reporter = val.validate(resource, 0, new ValOperation().getState()) ;
+ }
+ return reporter;
+ }
+
/**
* Add a validation message to the specified list.
*
diff --git a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java
index c8897eb..4183f42 100644
--- a/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java
+++ b/bundles/org.eclipse.wst.xml.core/src-validation/org/eclipse/wst/xml/core/internal/validation/core/AbstractNestedValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 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
@@ -34,6 +34,7 @@
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
+import org.eclipse.wst.xml.core.internal.validation.AnnotationMsg;
/**
* An abstract validator that assists validators in running and contributing
@@ -110,9 +111,9 @@
{
// The helper may not have a file stored in it but may have an InputStream if being
// called from a source other than the validation framework such as an editor.
- if (context.loadModel(GET_INPUTSTREAM) instanceof InputStream) //$NON-NLS-1$
+ if (context.loadModel(GET_INPUTSTREAM) instanceof InputStream)
{
- validate(file, (InputStream)context.loadModel(GET_INPUTSTREAM), null, reporter, nestedcontext); //do we need the fileName? what is int ruleGroup? //$NON-NLS-1$
+ validate(file, (InputStream)context.loadModel(GET_INPUTSTREAM), null, reporter, nestedcontext); //do we need the fileName? what is int ruleGroup?
}
else
{
@@ -416,7 +417,28 @@
message.setLineNo(validationMessage.getLineNumber());
addInfoToMessage(validationMessage, message);
-
+ Object[] objlist = validationMessage.getMessageArguments();
+ if (objlist != null && objlist.length ==1 ){
+ Object obj = objlist[0];
+ if (obj instanceof AnnotationMsg){
+ message.setAttribute(AnnotationMsg.PROBMLEM_ID, new Integer(((AnnotationMsg)obj).getProblemId()));
+ message.setAttribute(AnnotationMsg.LENGTH, new Integer(((AnnotationMsg)obj).getLength()));
+ Object obj1 = ((AnnotationMsg)obj).getAttributeValueText();
+ if (obj1 instanceof String){
+ message.setAttribute(AnnotationMsg.ATTRVALUETEXT, obj1);
+ }
+ else if ( obj1 instanceof Object[]){
+ Object[] objArray = (Object[])obj1;
+ message.setAttribute(AnnotationMsg.ATTRVALUENO, new Integer(objArray.length));
+ for (int j=0; j <objArray.length;j++){
+ Object obj2 = objArray[j];
+ String attrName = AnnotationMsg.ATTRNO + j;
+ message.setAttribute(attrName, obj2);
+ }
+
+ }
+ }
+ }
List nestederrors = validationMessage.getNestedMessages();
if (nestederrors != null && !nestederrors.isEmpty())
{
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java
index 3692afb..831c0a2 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2005, 2010 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
@@ -38,6 +38,19 @@
public static String Catalog_resolution_malformed_url;
public static String Catalog_resolution_io_exception;
public static String CMDocument_load_exception;
+ public static String End_tag_has_attributes;
+ public static String Attribute__is_missing_a_value;
+ public static String Attribute__has_no_value;
+ public static String Missing_end_tag_;
+ public static String Missing_start_tag_;
+ public static String ReconcileStepForMarkup_0;
+ public static String ReconcileStepForMarkup_1;
+ public static String ReconcileStepForMarkup_2;
+ public static String ReconcileStepForMarkup_3;
+ public static String ReconcileStepForMarkup_4;
+ public static String ReconcileStepForMarkup_5;
+ public static String ReconcileStepForMarkup_6;
+ public static String Indicate_no_grammar_specified_severities_error;
static {
// load message values from bundle file
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties
index c1b213a..d9f1fb7 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2001, 2009 IBM Corporation and others.
+# Copyright (c) 2001, 2010 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
@@ -32,3 +32,16 @@
Catalog_resolution_malformed_url=Malformed URL exception trying to resolve
Catalog_resolution_io_exception=I/O exception trying to resolve
CMDocument_load_exception=An error occurred while loading document {0} with publicId {1}
+End_tag_has_attributes=End tag has attributes
+Attribute__is_missing_a_value=Attribute \"{0}\" is missing a value
+Attribute__has_no_value=Attribute \"{0}\" has no value
+Missing_start_tag_=Missing start tag \"{0}\"
+Missing_end_tag_=Missing end tag \"{0}\"
+ReconcileStepForMarkup_0=Missing closing quote
+ReconcileStepForMarkup_1=Missing quotes for attribute value
+ReconcileStepForMarkup_2=A tagname cannot start with a space
+ReconcileStepForMarkup_3=Empty tags are not allowed
+ReconcileStepForMarkup_4=Namespaces are not allowed in a Processing Instruction target
+ReconcileStepForMarkup_5=Spaces are not allowed before a Processing Instruction
+ReconcileStepForMarkup_6=Tag missing closing bracket '>'
+Indicate_no_grammar_specified_severities_error=ErrorCMDocument_load_exception=An error occurred while loading document {0} with publicId {1}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
index 50fb82b..cde1575 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -63,5 +63,18 @@
node.putInt(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR, 1);
node.putBoolean(XMLCorePreferenceNames.USE_XINCLUDE, false);
node.putBoolean(XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS, true);
+
+ node.putBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION, false);
+ node.putInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE, 2);
+ node.putInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES, 2);
+ node.putInt(XMLCorePreferenceNames.MISSING_START_TAG, 2);
+ node.putInt(XMLCorePreferenceNames.MISSING_END_TAG, 2);
+ node.putInt(XMLCorePreferenceNames.MISSING_TAG_NAME, 2);
+ node.putInt(XMLCorePreferenceNames.MISSING_QUOTES, 2);
+ node.putInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, 2);
+ node.putInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE, 2);
+ node.putInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET, 2);
+ node.putInt(XMLCorePreferenceNames.WHITESPACE_AT_START, 2);
+ node.putInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME, 2);
}
}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
index e03ae53..562652d 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2010 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
@@ -12,6 +12,7 @@
package org.eclipse.wst.xml.core.internal.preferences;
+
/**
* Common preference keys used by XML core
*
@@ -247,4 +248,34 @@
* Value is of type <code>boolean</code>
*/
public static final String FORMAT_COMMENT_JOIN_LINES = "formatCommentJoinLines"; //$NON-NLS-1$
+
+
+ /**
+ * Indicates whether or not MarkUpValidator should run as part of XMl Validation.
+ * <p>
+ * Value is of type <code>boolean</code>.<br />
+ * Possible values: {TRUE, FALSE}
+ * </p>
+ */
+ public static final String MARKUP_VALIDATION = "markupValidation"; //$NON-NLS-1$
+
+ /**
+ * Indicates whether or not a message should be produced when validating a
+ * file that specifies following condition.
+ * <p>
+ * Value is of type <code>integer</code>.<br />
+ * Possible values: {0, 1, 2} (none, warning, error)
+ * </p>
+ */
+ public static final String ATTRIBUTE_HAS_NO_VALUE = "attributeHasNoValue"; //$NON-NLS-1$
+ public static final String END_TAG_WITH_ATTRIBUTES = "endTagWithAttributes"; //$NON-NLS-1$
+ public static final String WHITESPACE_BEFORE_TAGNAME = "whitespaceBeforeTagName"; //$NON-NLS-1$
+ public static final String MISSING_CLOSING_BRACKET = "missingClosingBracket"; //$NON-NLS-1$
+ public static final String MISSING_CLOSING_QUOTE = "missingClosingQuote"; //$NON-NLS-1$
+ public static final String MISSING_END_TAG = "missingEndTag"; //$NON-NLS-1$
+ public static final String MISSING_START_TAG = "missingStartTag"; //$NON-NLS-1$
+ public static final String MISSING_QUOTES = "missingQuotes"; //$NON-NLS-1$
+ public static final String NAMESPACE_IN_PI_TARGET = "namespaceInPITarget"; //$NON-NLS-1$
+ public static final String MISSING_TAG_NAME = "missingTagName"; //$NON-NLS-1$
+ public static final String WHITESPACE_AT_START = "whitespaceAtStart"; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.wst.xml.ui/plugin.xml b/bundles/org.eclipse.wst.xml.ui/plugin.xml
index 8d842ca..3730eda 100644
--- a/bundles/org.eclipse.wst.xml.ui/plugin.xml
+++ b/bundles/org.eclipse.wst.xml.ui/plugin.xml
@@ -488,22 +488,7 @@
</validator>
</extension>
- <extension point="org.eclipse.wst.sse.ui.sourcevalidation">
- <validator
- scope="total"
- class="org.eclipse.wst.xml.ui.internal.validation.MarkupValidator"
- id="org.eclipse.wst.xml.ui.internal.validation.markupvalidator">
- <contentTypeIdentifier id="org.eclipse.core.runtime.xml">
- <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/>
- <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier id="org.eclipse.wst.xml.core.xmlsource">
- <partitionType id="org.eclipse.wst.xml.XML_DEFAULT"/>
- <partitionType id="org.eclipse.wst.sse.ST_DEFAULT"/>
- </contentTypeIdentifier>
- </validator>
- </extension>
-
+
<extension point="org.eclipse.ui.editors.annotationTypes">
<type name="org.eclipse.wst.xml.ui.matching.tag"/>
</extension>
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
index 16f6cb3..2f03c15 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -318,6 +318,22 @@
public static String Honour_all_schema_locations;
public static String Open;
public static String _UI_BUTTON_SORT;
+ public static String MarkupValidation_files_label;
+ public static String MarkupValidation_files;
+ public static String Severity_error;
+ public static String Severity_warning;
+ public static String Severity_ignore;
+ public static String Empty_element_tag;
+ public static String End_tag_with_attributes;
+ public static String Invalid_whitespace_before_tagname;
+ public static String Missing_closing_bracket;
+ public static String Missing_closing_quote;
+ public static String Missing_end_tag;
+ public static String Missing_start_tag;
+ public static String Missing_quotes;
+ public static String Namespace_in_pi_target;
+ public static String Tag_name_missing;
+ public static String Whitespace_at_start;
static {
// load message values from bundle file
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
index 9c48935..7c1f7c3 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2001, 2009 IBM Corporation and others.
+# Copyright (c) 2001, 2010 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
@@ -347,3 +347,24 @@
gotoMatchingTag_end=End tag of element <{0}>
Open=Open ''{0}''
_UI_BUTTON_SORT=Sort
+Validating_files=Validating files
+Indicate_no_grammar_specified=Indicate when no &grammar is specified:
+Indicate_no_grammar_specified_severities_error=Error
+Indicate_no_grammar_specified_severities_warning=Warning
+Indicate_no_grammar_specified_severities_ignore=Ignore
+MarkupValidation_files_label=Errors/Warnings
+MarkupValidation_files=&Enable markup validation
+Severity_error=Error
+Severity_warning=Warning
+Severity_ignore=Ignore
+Empty_element_tag=Invalid e&mpty element tag:
+End_tag_with_attributes=Invalid end &tag with attributes:
+Invalid_whitespace_before_tagname=Invalid &white space before tag name:
+Missing_closing_bracket=Missing &closing bracket:
+Missing_closing_quote=Missing closing "e:
+Missing_end_tag=Missing e&nd tag:
+Missing_start_tag=Missing &start tag:
+Missing_quotes=Missing q&uotes:
+Namespace_in_pi_target=In&valid name space in PI:
+Tag_name_missing=Missing tag n&ame:
+Whitespace_at_start=Inva&lid white space at start:
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java
index 18fae10..8bebba4 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/ProblemIDsXML.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2008 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 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
@@ -12,21 +12,5 @@
*******************************************************************************/
package org.eclipse.wst.xml.ui.internal.correction;
-public interface ProblemIDsXML {
- int AttrsInEndTag = 3;
- int AttrValueNotQuoted = 13;
- int EmptyTag = 1;
- int InvalidAttrValue = 11;
- int MissingAttrValue = 4;
- int MissingClosingBracket = 14;
- int MissingEndTag = 2;
- int MissingRequiredAttr = 12;
- int MissingStartTag = 15;
- int NamespaceInPI = 8;
- int NoAttrValue = 5;
- int SpacesBeforePI = 7;
- int SpacesBeforeTagName = 6;
- int Unclassified = 0;
- int UnknownAttr = 10;
- int UnknownElement = 9;
+public interface ProblemIDsXML extends org.eclipse.wst.xml.core.internal.validation.ProblemIDsXML {
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java
index 28eaea1..600824f 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/correction/QuickFixProcessorXML.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 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
@@ -21,6 +21,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.sse.ui.internal.correction.IQuickFixProcessor;
import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
+import org.eclipse.wst.xml.core.internal.validation.ProblemIDsXML;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLValidatorPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLValidatorPreferencePage.java
index 6749375..29a2312 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLValidatorPreferencePage.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLValidatorPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2009 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 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
@@ -15,7 +15,11 @@
import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.dialogs.ControlEnableState;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -24,6 +28,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage;
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
@@ -34,18 +39,46 @@
public class XMLValidatorPreferencePage extends AbstractPreferencePage {
private Combo fIndicateNoGrammar;
-
+
private Button fHonourAllSchemaLocations;
private Button fUseXinclude;
+
+ private Button fExtendedMarkupValidation;
+
+ private Combo fEmptyElementTag;
+
+ private Combo fEndTagWithAttributes;
+
+ private Combo fInvalidWhitespaceBeforeTagname;
+
+ private Combo fMissingClosingBracket;
+
+ private Combo fMissingClosingQuote;
+
+ private Combo fMissingEndTag;
+
+ private Combo fMissingStartTag;
+
+ private Combo fMissingQuotes;
+
+ private Combo fInvalidNamespaceInPI;
+
+ private Combo fMissingTagName;
+
+ private Combo fInvalidWhitespaceAtStart;
+
+ private Group fMarkupValidationGroup;
+ private ControlEnableState fMarkupState;
private static final String[] SEVERITIES = {XMLUIMessages.Indicate_no_grammar_specified_severities_error, XMLUIMessages.Indicate_no_grammar_specified_severities_warning, XMLUIMessages.Indicate_no_grammar_specified_severities_ignore};
+ private static final String[] MARKUP_SEVERITIES = {XMLUIMessages.Severity_error, XMLUIMessages.Severity_warning, XMLUIMessages.Severity_ignore};
protected Control createContents(Composite parent) {
Composite composite = (Composite)super.createContents(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_VALIDATOR_HELPID);
createContentsForValidatingGroup(composite);
-
+ createContentsForMarkupValidationGroup(composite);
setSize(composite);
loadPreferences();
@@ -70,6 +103,65 @@
((GridData)fHonourAllSchemaLocations.getLayoutData()).horizontalSpan = 2;
}
}
+ private void handleMarkupSeveritySelection(){
+ if (fExtendedMarkupValidation.getSelection()) {
+ fMarkupState.restore();
+ }
+ else {
+ fMarkupState = ControlEnableState.disable(fMarkupValidationGroup);
+ }
+ }
+
+ protected void createContentsForMarkupValidationGroup(Composite parent) {
+
+ if (fExtendedMarkupValidation == null) {
+ fExtendedMarkupValidation = createCheckBox(parent, XMLUIMessages.MarkupValidation_files);
+ ((GridData)fExtendedMarkupValidation.getLayoutData()).horizontalSpan = 2;
+ fExtendedMarkupValidation.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleMarkupSeveritySelection();
+ }
+ });
+ }
+ fMarkupValidationGroup = createGroup(parent, 3);
+ ((GridLayout)fMarkupValidationGroup.getLayout()).makeColumnsEqualWidth = false;
+ fMarkupValidationGroup.setText(XMLUIMessages.MarkupValidation_files_label);
+
+ if (fMissingStartTag == null) {
+ fMissingStartTag = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_start_tag, MARKUP_SEVERITIES);
+ }
+ if (fMissingEndTag == null) {
+ fMissingEndTag = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_end_tag, MARKUP_SEVERITIES);
+ }
+ if (fMissingTagName == null) {
+ fMissingTagName = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Tag_name_missing, MARKUP_SEVERITIES);
+ }
+ if (fMissingQuotes == null) {
+ fMissingQuotes = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_quotes, MARKUP_SEVERITIES);
+ }
+ if (fMissingClosingBracket == null) {
+ fMissingClosingBracket = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_closing_bracket, MARKUP_SEVERITIES);
+ }
+ if (fMissingClosingQuote == null) {
+ fMissingClosingQuote = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Missing_closing_quote, MARKUP_SEVERITIES);
+ }
+ if (fEmptyElementTag == null) {
+ fEmptyElementTag = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Empty_element_tag, MARKUP_SEVERITIES);
+ }
+ if (fEndTagWithAttributes == null) {
+ fEndTagWithAttributes = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.End_tag_with_attributes, MARKUP_SEVERITIES);
+ }
+ if (fInvalidWhitespaceBeforeTagname == null) {
+ fInvalidWhitespaceBeforeTagname = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Invalid_whitespace_before_tagname, MARKUP_SEVERITIES);
+ }
+ if (fInvalidNamespaceInPI == null) {
+ fInvalidNamespaceInPI = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Namespace_in_pi_target, MARKUP_SEVERITIES);
+ }
+ if (fInvalidWhitespaceAtStart == null) {
+ fInvalidWhitespaceAtStart = createMarkupCombo(fMarkupValidationGroup, XMLUIMessages.Whitespace_at_start, MARKUP_SEVERITIES);
+ }
+
+ }
/**
* @param parent
@@ -86,8 +178,26 @@
return combo;
}
+ private Combo createMarkupCombo(Composite parent, String text, String[] items) {
+ Label label = new Label(parent, SWT.LEFT);
+ GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
+ label.setFont(JFaceResources.getDialogFont());
+ label.setText(text);
+ label.setLayoutData(gd);
+
+ Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
+ combo.setItems(items);
+
+ //GridData
+ // GridData data = new GridData(SWT.FILL, SWT.CENTER, false, true);
+ combo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ return combo;
+ }
+
protected void initializeValues() {
initializeValuesForValidatingGroup();
+ initializeValuesForMarkupValidationGroup();
}
protected void initializeValuesForValidatingGroup() {
@@ -108,6 +218,95 @@
fHonourAllSchemaLocations.setSelection(honourAllSelected);
}
}
+
+ protected void initializeValuesForMarkupValidationGroup() {
+ Preferences modelPreferences = getModelPreferences();
+ boolean useExtendedMarkupValidation = modelPreferences.getBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION);
+
+
+ if (fExtendedMarkupValidation != null) {
+ fExtendedMarkupValidation.setSelection(useExtendedMarkupValidation);
+ }
+ int emptyElementTag = modelPreferences.getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE);
+
+ if (fEmptyElementTag != null) {
+ fEmptyElementTag.select(2 - emptyElementTag);
+ fEmptyElementTag.setText(MARKUP_SEVERITIES[2 - emptyElementTag]);
+ }
+
+ int endTagWithAttributes = modelPreferences.getInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES);
+
+ if (fEndTagWithAttributes != null) {
+ fEndTagWithAttributes.select(2 - endTagWithAttributes);
+ fEndTagWithAttributes.setText(MARKUP_SEVERITIES[2 - endTagWithAttributes]);
+ }
+
+ int invalidWhitespaceBeforeTagname = modelPreferences.getInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME);
+
+ if (fInvalidWhitespaceBeforeTagname != null) {
+ fInvalidWhitespaceBeforeTagname.select(2 - invalidWhitespaceBeforeTagname);
+ fInvalidWhitespaceBeforeTagname.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceBeforeTagname]);
+ }
+
+ int missingClosingBracket = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET);
+
+ if (fMissingClosingBracket != null) {
+ fMissingClosingBracket.select(2 - missingClosingBracket);
+ fMissingClosingBracket.setText(MARKUP_SEVERITIES[2 - missingClosingBracket]);
+ }
+
+ int missingClosingQuote = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE);
+
+ if (fMissingClosingQuote != null) {
+ fMissingClosingQuote.select(2 - missingClosingQuote);
+ fMissingClosingQuote.setText(MARKUP_SEVERITIES[2 - missingClosingQuote]);
+ }
+
+ int missingEndTag = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_END_TAG);
+
+ if (fMissingEndTag != null) {
+ fMissingEndTag.select(2 - missingEndTag);
+ fMissingEndTag.setText(MARKUP_SEVERITIES[2 - missingEndTag]);
+ }
+
+ int missingStartTag = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_START_TAG);
+
+ if (fMissingStartTag != null) {
+ fMissingStartTag.select(2 - missingStartTag);
+ fMissingStartTag.setText(MARKUP_SEVERITIES[2 - missingStartTag]);
+ }
+
+ int missingQuotes = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_QUOTES);
+
+ if (fMissingQuotes != null) {
+ fMissingQuotes.select(2 - missingQuotes);
+ fMissingQuotes.setText(MARKUP_SEVERITIES[2 - missingQuotes]);
+ }
+
+ int invalidNamespaceInPI = modelPreferences.getInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET);
+
+ if (fInvalidNamespaceInPI != null) {
+ fInvalidNamespaceInPI.select(2 - invalidNamespaceInPI);
+ fInvalidNamespaceInPI.setText(MARKUP_SEVERITIES[2 - invalidNamespaceInPI]);
+ }
+
+ int tagNameMissing = modelPreferences.getInt(XMLCorePreferenceNames.MISSING_TAG_NAME);
+
+ if (fMissingTagName != null) {
+ fMissingTagName.select(2 - tagNameMissing);
+ fMissingTagName.setText(MARKUP_SEVERITIES[2 - tagNameMissing]);
+ }
+
+ int invalidWhitespaceAtStart = modelPreferences.getInt(XMLCorePreferenceNames.WHITESPACE_AT_START);
+
+ if (fInvalidWhitespaceAtStart != null) {
+ fInvalidWhitespaceAtStart.select(2 - invalidWhitespaceAtStart);
+ fInvalidWhitespaceAtStart.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceAtStart]);
+ }
+
+ if (!useExtendedMarkupValidation)
+ fMarkupState = ControlEnableState.disable(fMarkupValidationGroup);
+ }
protected void performDefaultsForValidatingGroup() {
Preferences modelPreferences = getModelPreferences();
@@ -127,6 +326,92 @@
fHonourAllSchemaLocations.setSelection(honourAllButtonSelected);
}
}
+
+ protected void performDefaultsForMarkupValidationGroup() {
+ Preferences modelPreferences = getModelPreferences();
+ boolean useExtendedMarkupValidation = modelPreferences.getDefaultBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION);
+
+
+ if (fExtendedMarkupValidation != null) {
+ fExtendedMarkupValidation.setSelection(useExtendedMarkupValidation);
+ }
+ int emptyElementTag = modelPreferences.getDefaultInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE);
+
+ if (fEmptyElementTag != null) {
+ fEmptyElementTag.setSelection(new Point(emptyElementTag,2 - emptyElementTag));
+ fEmptyElementTag.setText(MARKUP_SEVERITIES[2 - emptyElementTag]);
+ }
+
+ int endTagWithAttributes = modelPreferences.getDefaultInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES);
+
+ if (fEndTagWithAttributes != null) {
+ fEndTagWithAttributes.setSelection(new Point(endTagWithAttributes,2 - endTagWithAttributes));
+ fEndTagWithAttributes.setText(MARKUP_SEVERITIES[2 - endTagWithAttributes]);
+ }
+
+ int invalidWhitespaceBeforeTagname = modelPreferences.getDefaultInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME);
+
+ if (fInvalidWhitespaceBeforeTagname != null) {
+ fInvalidWhitespaceBeforeTagname.setSelection(new Point(invalidWhitespaceBeforeTagname,2 - invalidWhitespaceBeforeTagname));
+ fInvalidWhitespaceBeforeTagname.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceBeforeTagname]);
+ }
+
+ int missingClosingBracket = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET);
+
+ if (fMissingClosingBracket != null) {
+ fMissingClosingBracket.setSelection(new Point(missingClosingBracket,2 - missingClosingBracket));
+ fMissingClosingBracket.setText(MARKUP_SEVERITIES[2 - missingClosingBracket]);
+ }
+
+ int missingClosingQuote = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE);
+
+ if (fMissingClosingQuote != null) {
+ fMissingClosingQuote.setSelection(new Point(missingClosingQuote,2 - missingClosingQuote));
+ fMissingClosingQuote.setText(MARKUP_SEVERITIES[2 - missingClosingQuote]);
+ }
+
+ int missingEndTag = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_END_TAG);
+
+ if (fMissingEndTag != null) {
+ fMissingEndTag.setSelection(new Point(missingEndTag,2 - missingEndTag));
+ fMissingEndTag.setText(MARKUP_SEVERITIES[2 - missingEndTag]);
+ }
+
+ int missingStartTag = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_START_TAG);
+
+ if (fMissingStartTag != null) {
+ fMissingStartTag.setSelection(new Point(missingStartTag,2 - missingStartTag));
+ fMissingStartTag.setText(MARKUP_SEVERITIES[2 - missingStartTag]);
+ }
+
+ int missingQuotes = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_QUOTES);
+
+ if (fMissingQuotes != null) {
+ fMissingQuotes.setSelection(new Point(missingQuotes,2 - missingQuotes));
+ fMissingQuotes.setText(MARKUP_SEVERITIES[2 - missingQuotes]);
+ }
+
+ int invalidNamespaceInPI = modelPreferences.getDefaultInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET);
+
+ if (fInvalidNamespaceInPI != null) {
+ fInvalidNamespaceInPI.setSelection(new Point(invalidNamespaceInPI,2 - invalidNamespaceInPI));
+ fInvalidNamespaceInPI.setText(MARKUP_SEVERITIES[2 - invalidNamespaceInPI]);
+ }
+
+ int tagNameMissing = modelPreferences.getDefaultInt(XMLCorePreferenceNames.MISSING_TAG_NAME);
+
+ if (fMissingTagName != null) {
+ fMissingTagName.setSelection(new Point(tagNameMissing,2 - tagNameMissing));
+ fMissingTagName.setText(MARKUP_SEVERITIES[2 - tagNameMissing]);
+ }
+
+ int invalidWhitespaceAtStart = modelPreferences.getDefaultInt(XMLCorePreferenceNames.WHITESPACE_AT_START);
+
+ if (fInvalidWhitespaceAtStart != null) {
+ fInvalidWhitespaceAtStart.setSelection(new Point(invalidWhitespaceAtStart,2 - invalidWhitespaceAtStart));
+ fInvalidWhitespaceAtStart.setText(MARKUP_SEVERITIES[2 - invalidWhitespaceAtStart]);
+ }
+ }
protected void storeValuesForValidatingGroup()
{
@@ -144,13 +429,70 @@
modelPreferences.setValue(XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS, honourAllButtonSelected);
}
}
+ protected void storeValuesForMarkupValidationGroup()
+ {
+ Preferences modelPreferences = getModelPreferences();
+ if (fExtendedMarkupValidation != null) {
+ boolean extendedMarkupValidation = fExtendedMarkupValidation.getSelection();
+ modelPreferences.setValue(XMLCorePreferenceNames.MARKUP_VALIDATION, extendedMarkupValidation);
+ }
+ if (fEmptyElementTag != null) {
+ int emptyElementTag = 2 - fEmptyElementTag.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE, emptyElementTag);
+ }
+ if (fEndTagWithAttributes != null) {
+ int endTagWithAttributes = 2 - fEndTagWithAttributes.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES, endTagWithAttributes);
+ }
+ if (fInvalidWhitespaceBeforeTagname != null) {
+ int invalidWhitespaceBeforeTagname = 2 - fInvalidWhitespaceBeforeTagname.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME, invalidWhitespaceBeforeTagname);
+ }
+ if (fMissingClosingBracket != null) {
+ int missingClosingBracket = 2 - fMissingClosingBracket.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, missingClosingBracket);
+ }
+ if (fMissingClosingQuote != null) {
+ int missingClosingQuote = 2 - fMissingClosingQuote.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, missingClosingQuote);
+ }
+ if (fMissingEndTag != null) {
+ int missingEndTag = 2 - fMissingEndTag.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.MISSING_END_TAG, missingEndTag);
+ modelPreferences.getInt(XMLCorePreferenceNames.MISSING_END_TAG);
+ }
+ if (fMissingStartTag != null) {
+ int missingStartTag = 2 - fMissingStartTag.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.MISSING_START_TAG, missingStartTag);
+ }
+ if (fMissingQuotes != null) {
+ int missingQuotes = 2 - fMissingQuotes.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.MISSING_QUOTES, missingQuotes);
+ }
+ if (fInvalidNamespaceInPI != null) {
+ int invalidNamespaceInPI = 2 - fInvalidNamespaceInPI.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET, invalidNamespaceInPI);
+ }
+ if (fMissingTagName != null) {
+ int missingTagName = 2 - fMissingTagName.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.MISSING_TAG_NAME, missingTagName);
+ }
+ if (fInvalidWhitespaceAtStart != null) {
+ int invalidWhitespaceAtStart = 2 - fInvalidWhitespaceAtStart.getSelectionIndex();
+ modelPreferences.setValue(XMLCorePreferenceNames.WHITESPACE_AT_START, invalidWhitespaceAtStart);
+ }
+
+
+ }
protected void storeValues() {
storeValuesForValidatingGroup();
+ storeValuesForMarkupValidationGroup();
}
protected void performDefaults() {
performDefaultsForValidatingGroup();
+ performDefaultsForMarkupValidationGroup();
super.performDefaults();
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java
index 087019d..9a2c070 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/DelegatingSourceValidator.java
@@ -22,10 +22,13 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo;
+import org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter;
import org.eclipse.wst.validation.internal.core.IMessageAccess;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -40,6 +43,7 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
+import org.eclipse.wst.xml.core.internal.validation.AnnotationMsg;
import org.eclipse.wst.xml.ui.internal.Logger;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -66,6 +70,9 @@
protected static final String TEXT_ENTITY_REFERENCE = "TEXT_ENTITY_REFERENCE"; //$NON-NLS-1$
protected static final String VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE = "VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE"; //$NON-NLS-1$
protected static final String END_TAG = "END_TAG"; //$NON-NLS-1$
+ private static final String QUICKASSISTPROCESSOR = IQuickAssistProcessor.class.getName();
+
+
/**
* This constant specifies the attribute name that specifies the side of
@@ -270,20 +277,48 @@
try {
if (message.getAttribute(COLUMN_NUMBER_ATTRIBUTE) != null) {
int column = ((Integer) message.getAttribute(COLUMN_NUMBER_ATTRIBUTE)).intValue();
- String selectionStrategy = (String) message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE);
- String nameOrValue = (String) message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE);
-
- // convert the line and Column numbers to an offset:
- int start = document.getStructuredDocument().getLineOffset(message.getLineNumber() - 1) + column - 1;
-
- // calculate the "better" start and end offset:
- int[] result = computeStartAndEndLocation(start, selectionStrategy, getErrorSide(message), nameOrValue, document);
- if (result != null) {
- message.setOffset(result[0]);
- message.setLength(result[1] - result[0]);
- reporter.addMessage(this, message);
+ if (message.getAttribute(AnnotationMsg.PROBMLEM_ID) != null && reporter instanceof IncrementalReporter){
+ Integer problemId = (Integer)message.getAttribute(AnnotationMsg.PROBMLEM_ID);
+ MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
+ processor.setProblemId(problemId.intValue());
+ message.setOffset(column);
+ Integer length = (Integer) message.getAttribute(AnnotationMsg.LENGTH);
+ message.setLength( length.intValue());
+ Object attrValue = message.getAttribute(AnnotationMsg.ATTRVALUETEXT);
+ if (attrValue != null)
+ processor.setAdditionalFixInfo(attrValue);
+ else{
+ Object attrValueNo = message.getAttribute(AnnotationMsg.ATTRVALUENO);
+ if (attrValueNo != null){
+ int len = ((Integer)attrValueNo).intValue();
+ Object[] objArray = new Object[len];
+ for ( int j=0; j<len; j++){
+ objArray[j] = message.getAttribute(AnnotationMsg.ATTRNO + j);
+ }
+ processor.setAdditionalFixInfo(objArray);
+ }
+
+ }
+ message.setAttribute(QUICKASSISTPROCESSOR, processor);
+ AnnotationInfo info = new AnnotationInfo(message);
+ ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
}
- }
+ else {
+ String selectionStrategy = (String) message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE);
+ String nameOrValue = (String) message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE);
+
+ // convert the line and Column numbers to an offset:
+ int start = document.getStructuredDocument().getLineOffset(message.getLineNumber() - 1) + column - 1;
+ int[] result = computeStartAndEndLocation(start, selectionStrategy, getErrorSide(message), nameOrValue, document);
+ if (result != null) {
+ message.setOffset(result[0]);
+ message.setLength(result[1] - result[0]);
+
+ reporter.addMessage(this, message);
+ }
+ }
+ }
+
}
catch (BadLocationException e) { // this exception should not
// occur - it is thrown if
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java
index c8c876c..c5bb299 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupQuickAssistProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 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
@@ -18,8 +18,8 @@
import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xml.core.internal.validation.ProblemIDsXML;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.correction.ProblemIDsXML;
import org.eclipse.wst.xml.ui.internal.correction.RemoveUnknownElementQuickFixProposal;
import org.eclipse.wst.xml.ui.internal.correction.RenameInFileQuickAssistProposal;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java
index 17e2ba1..d228699 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/validation/MarkupValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2008 IBM Corporation and others.
+ * Copyright (c) 2001, 2010 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
@@ -58,13 +58,19 @@
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.eclipse.wst.xml.core.internal.validation.ProblemIDsXML;
import org.eclipse.wst.xml.ui.internal.Logger;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
-import org.eclipse.wst.xml.ui.internal.correction.ProblemIDsXML;
import org.w3c.dom.Node;
/**
* Basic XML syntax checking step.
+ * @deprecated No longer used as the source validator for XML documents. Instead {@link DelegatingSourceValidatorForXML}
+ * is the source validator, and the markup validation is done as a step in {@link XMLValidator} by {@link org.eclipse.wst.xml.core.internal.validation.MarkupValidator}.
+ *
+ * @see org.eclipse.wst.xml.core.internal.validation.MarkupValidator
+ * @see DelegatingSourceValidatorForXML
+ * @see XMLValidator
*/
public class MarkupValidator extends AbstractValidator implements IValidator, ISourceValidator {
private String DQUOTE = "\""; //$NON-NLS-1$