summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2013-05-14 15:19:07 (EDT)
committer Florian Thienel2013-05-14 15:19:07 (EDT)
commitca2f868c6a9d29699d5aba000a42cfcca1a75681 (patch)
tree1ad07b209a98190074f6d8ced8b3bf70e7506425
parentf726a9d02dc8a1422402e8a681153456d5139c75 (diff)
downloadorg.eclipse.mylyn.docs.vex-ca2f868c6a9d29699d5aba000a42cfcca1a75681.zip
org.eclipse.mylyn.docs.vex-ca2f868c6a9d29699d5aba000a42cfcca1a75681.tar.gz
org.eclipse.mylyn.docs.vex-ca2f868c6a9d29699d5aba000a42cfcca1a75681.tar.bz2
do not create Text nodes for superflous whitespace
https://bugs.eclipse.org/bugs/show_bug.cgi?id=407803
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DummyValidator.java15
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentReaderTest.java49
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/SpaceNormalizerTest.java5
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/LayoutTestSuite.java5
-rw-r--r--org.eclipse.vex.core.tests/testResources/documentWithoutDTD.xml13
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java71
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentReader.java16
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java6
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/IValidator.java45
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java14
10 files changed, 205 insertions, 34 deletions
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DummyValidator.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DummyValidator.java
index eac1ccb..4528b29 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DummyValidator.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DummyValidator.java
@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.vex.core.internal.io.DocumentContentModel;
import org.eclipse.vex.core.provisional.dom.AttributeDefinition;
import org.eclipse.vex.core.provisional.dom.IAttribute;
import org.eclipse.vex.core.provisional.dom.IElement;
@@ -25,6 +26,20 @@ import org.eclipse.vex.core.provisional.dom.IValidator;
*/
public class DummyValidator implements IValidator {
+ private final DocumentContentModel documentContentModel;
+
+ public DummyValidator() {
+ this(new DocumentContentModel());
+ }
+
+ public DummyValidator(final DocumentContentModel documentContentModel) {
+ this.documentContentModel = documentContentModel;
+ }
+
+ public DocumentContentModel getDocumentContentModel() {
+ return documentContentModel;
+ }
+
public AttributeDefinition getAttributeDefinition(final IAttribute attribute) {
return null;
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentReaderTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentReaderTest.java
index 691f781..8d181dd 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentReaderTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentReaderTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Florian Thienel - initial API and implementation
+ * Carsten Hiesserich - do not add text nodes containing only whitespace when reading the document (bug 407803)
*******************************************************************************/
package org.eclipse.vex.core.internal.io;
@@ -21,10 +22,15 @@ import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
+import org.eclipse.vex.core.IFilter;
+import org.eclipse.vex.core.internal.dom.DummyValidator;
+import org.eclipse.vex.core.provisional.dom.BaseNodeVisitorWithResult;
+import org.eclipse.vex.core.provisional.dom.IAxis;
import org.eclipse.vex.core.provisional.dom.IComment;
import org.eclipse.vex.core.provisional.dom.IDocument;
import org.eclipse.vex.core.provisional.dom.IElement;
import org.eclipse.vex.core.provisional.dom.INode;
+import org.eclipse.vex.core.provisional.dom.IText;
import org.eclipse.vex.core.tests.TestResources;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager;
@@ -65,7 +71,7 @@ public class DocumentReaderTest {
public void useDocumentContentModelAsEntityResolver() throws Exception {
final DocumentReader reader = new DocumentReader();
final boolean[] called = new boolean[1];
- reader.setDocumentContentModel(new DocumentContentModel() {
+ reader.setValidator(new DummyValidator(new DocumentContentModel() {
@Override
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
if (TestResources.TEST_DTD.equals(publicId)) {
@@ -73,7 +79,7 @@ public class DocumentReaderTest {
}
return super.resolveEntity(publicId, systemId);
}
- });
+ }));
reader.read(TestResources.get("documentWithDtdPublic.xml"));
assertTrue(called[0]);
}
@@ -83,7 +89,7 @@ public class DocumentReaderTest {
final DocumentReader reader = new DocumentReader();
final boolean[] documentContentModelCalled = new boolean[1];
final boolean[] entityResolverCalled = new boolean[1];
- reader.setDocumentContentModel(new DocumentContentModel() {
+ reader.setValidator(new DummyValidator(new DocumentContentModel() {
@Override
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
if (TestResources.TEST_DTD.equals(publicId)) {
@@ -91,7 +97,7 @@ public class DocumentReaderTest {
}
return super.resolveEntity(publicId, systemId);
}
- });
+ }));
reader.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
if (TestResources.TEST_DTD.equals(publicId)) {
@@ -111,7 +117,7 @@ public class DocumentReaderTest {
final int[] callPosition = new int[1];
final int[] documentContentModelPosition = new int[1];
final int[] entityResolverPosition = new int[1];
- reader.setDocumentContentModel(new DocumentContentModel() {
+ reader.setValidator(new DummyValidator(new DocumentContentModel() {
@Override
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
if (TestResources.TEST_DTD.equals(publicId)) {
@@ -119,7 +125,7 @@ public class DocumentReaderTest {
}
return super.resolveEntity(publicId, systemId);
}
- });
+ }));
reader.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
if (TestResources.TEST_DTD.equals(publicId)) {
@@ -162,4 +168,35 @@ public class DocumentReaderTest {
rootChildren.next();
assertFalse(rootChildren.hasNext());
}
+
+ @Test
+ public void shouldNotAddWhitespaceTextNodesInDocumentWithoutDTD() throws Exception {
+ final DocumentReader reader = new DocumentReader();
+ final IDocument document = reader.read(TestResources.get("documentWithoutDTD.xml"));
+ final IElement rootElement = document.getRootElement();
+
+ final IFilter<INode> recursiveWhitespaceTextNodeFilter = new IFilter<INode>() {
+ public boolean matches(final INode node) {
+ return node.accept(new BaseNodeVisitorWithResult<Boolean>(false) {
+ @Override
+ public Boolean visit(final IElement element) {
+ return containsEmptyTextNodes(element);
+ }
+
+ @Override
+ public Boolean visit(final IText text) {
+ return text.getText().trim().length() == 0;
+ }
+ });
+ }
+
+ private boolean containsEmptyTextNodes(final IElement element) {
+ return !element.children().matching(this).isEmpty();
+ }
+ };
+
+ final IAxis<? extends INode> nodesWithEmptyTextNodes = rootElement.children().matching(recursiveWhitespaceTextNodeFilter);
+
+ assertEquals("whitespace text nodes", 0, nodesWithEmptyTextNodes.count());
+ }
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/SpaceNormalizerTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/SpaceNormalizerTest.java
index e48f0aa..505a0ab 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/SpaceNormalizerTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/SpaceNormalizerTest.java
@@ -45,6 +45,7 @@ import org.eclipse.vex.core.internal.css.CssWhitespacePolicy;
import org.eclipse.vex.core.internal.css.MockDisplayDevice;
import org.eclipse.vex.core.internal.css.StyleSheet;
import org.eclipse.vex.core.internal.css.StyleSheetReader;
+import org.eclipse.vex.core.internal.dom.DummyValidator;
import org.eclipse.vex.core.provisional.dom.IDocument;
import org.eclipse.vex.core.provisional.dom.IElement;
import org.eclipse.vex.core.provisional.dom.INode;
@@ -298,12 +299,12 @@ public class SpaceNormalizerTest {
final XMLReader xmlReader = factory.newSAXParser().getXMLReader();
final StyleSheet mySS = ss;
final CssWhitespacePolicy policy = new CssWhitespacePolicy(mySS);
- final DocumentBuilder builder = new DocumentBuilder(null, new DocumentContentModel() {
+ final DocumentBuilder builder = new DocumentBuilder(null, new DummyValidator(new DocumentContentModel() {
@Override
public IWhitespacePolicy getWhitespacePolicy() {
return policy;
}
- });
+ }));
final InputSource is = new InputSource(new ByteArrayInputStream(s.getBytes()));
xmlReader.setContentHandler(builder);
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/LayoutTestSuite.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/LayoutTestSuite.java
index 040ab84..6b056e3 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/LayoutTestSuite.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/LayoutTestSuite.java
@@ -28,6 +28,7 @@ import junit.framework.TestSuite;
import org.eclipse.vex.core.internal.css.CssWhitespacePolicy;
import org.eclipse.vex.core.internal.css.StyleSheet;
import org.eclipse.vex.core.internal.css.StyleSheetReader;
+import org.eclipse.vex.core.internal.dom.DummyValidator;
import org.eclipse.vex.core.internal.io.DocumentContentModel;
import org.eclipse.vex.core.internal.io.DocumentReader;
import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
@@ -103,12 +104,12 @@ public class LayoutTestSuite extends TestCase {
final CssWhitespacePolicy policy = new CssWhitespacePolicy(ss);
final DocumentReader docReader = new DocumentReader();
- docReader.setDocumentContentModel(new DocumentContentModel() {
+ docReader.setValidator(new DummyValidator(new DocumentContentModel() {
@Override
public IWhitespacePolicy getWhitespacePolicy() {
return policy;
}
- });
+ }));
final IDocument doc = docReader.read(this.doc);
context.setDocument(doc);
diff --git a/org.eclipse.vex.core.tests/testResources/documentWithoutDTD.xml b/org.eclipse.vex.core.tests/testResources/documentWithoutDTD.xml
new file mode 100644
index 0000000..213dc0b
--- /dev/null
+++ b/org.eclipse.vex.core.tests/testResources/documentWithoutDTD.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<chapter xmlns="http://www.eclipse.org/vex/test/structure">
+ <title>Title1</title>
+ <chapter>
+ <title>Title2</title>
+ </chapter>
+ <!-- comment 1 -->
+ <!-- comment 2 -->
+ <chapter>
+ <title>Title3</title>
+ <!--comment 3-->
+ </chapter>
+</chapter>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java
index cc962f7..de7b274 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java
@@ -8,10 +8,12 @@
* Contributors:
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
+ * Carsten Hiesserich - do not add text nodes containing only whitespace when reading the document (bug 407803)
*******************************************************************************/
package org.eclipse.vex.core.internal.io;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -22,10 +24,16 @@ import org.eclipse.vex.core.internal.dom.Document;
import org.eclipse.vex.core.internal.dom.Element;
import org.eclipse.vex.core.internal.dom.GapContent;
import org.eclipse.vex.core.internal.dom.Node;
+import org.eclipse.vex.core.provisional.dom.BaseNodeVisitorWithResult;
import org.eclipse.vex.core.provisional.dom.ContentRange;
import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
+import org.eclipse.vex.core.provisional.dom.IComment;
import org.eclipse.vex.core.provisional.dom.IContent;
import org.eclipse.vex.core.provisional.dom.IDocument;
+import org.eclipse.vex.core.provisional.dom.IElement;
+import org.eclipse.vex.core.provisional.dom.INode;
+import org.eclipse.vex.core.provisional.dom.IText;
+import org.eclipse.vex.core.provisional.dom.IValidator;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
@@ -46,7 +54,7 @@ import org.xml.sax.ext.LexicalHandler;
*/
public class DocumentBuilder implements ContentHandler, LexicalHandler {
- private final DocumentContentModel documentContentModel;
+ private final IValidator validator;
private IWhitespacePolicy policy;
@@ -80,9 +88,9 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
private IDocument document;
private Locator locator;
- public DocumentBuilder(final String baseUri, final DocumentContentModel documentContentModel) {
+ public DocumentBuilder(final String baseUri, final IValidator validator) {
this.baseUri = baseUri;
- this.documentContentModel = documentContentModel;
+ this.validator = validator;
}
/**
@@ -209,6 +217,7 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
}
}
+ final DocumentContentModel documentContentModel = validator.getDocumentContentModel();
if (stack.isEmpty() && documentContentModel != null) {
documentContentModel.initialize(baseUri, dtdPublicID, dtdSystemID, rootElement);
policy = documentContentModel.getWhitespacePolicy();
@@ -255,7 +264,7 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
trimLeading = true;
appendPendingCharsFiltered(ch, start, length);
- appendChars(true);
+ appendCharsNoValidation(true); // Trailing whitespace of a comment must not be removed (could end with '-- ')
content.insertTagMarker(content.length());
comment.associate(content, new ContentRange(startOffset, content.length() - 1));
@@ -271,7 +280,7 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
trimLeading = true;
appendPendingCharsFiltered(ch, start, length);
- appendChars(true);
+ appendCharsNoValidation(true); // Trailing whitespace of a comment must not be removed (could end with '-- ')
content.insertTagMarker(content.length());
comment.associate(content, new ContentRange(startOffset, content.length() - 1));
@@ -291,7 +300,7 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
trimLeading = true;
appendPendingCharsFiltered(ch, start, length);
- appendChars(true);
+ appendCharsNoValidation(true); // Trailing whitespace of a comment must not be removed (could end with '-- ')
content.insertTagMarker(content.length());
comment.associate(content, new ContentRange(startOffset, content.length() - 1));
@@ -340,6 +349,24 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
sb = cleanUpTextContent(trimTrailing);
+ if (!stack.isEmpty()) {
+ final Element parent = stack.getLast().element;
+ if (canInsertText(parent, 0) || sb.toString().trim().length() > 0) {
+ // Whitespace only is ignored if element does not allow text
+ content.insertText(content.length(), sb.toString());
+ }
+ }
+
+ pendingChars.setLength(0);
+ trimLeading = false;
+ }
+
+ // Append any pending characters without validation
+ private void appendCharsNoValidation(final boolean trimTrailing) {
+ StringBuilder sb;
+
+ sb = cleanUpTextContent(trimTrailing);
+
content.insertText(content.length(), sb.toString());
pendingChars.setLength(0);
@@ -359,7 +386,7 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
boolean ws = false; // true if we're in a run of whitespace
for (int i = 0; i < pendingChars.length(); i++) {
final char c = pendingChars.charAt(i);
- if (Character.isWhitespace(c)) {
+ if (isXmlWhitespace(c)) {
ws = true;
} else {
if (ws) {
@@ -385,6 +412,11 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
return sb;
}
+ private static boolean isXmlWhitespace(final char c) {
+ // whitespace according to the W3C recommendation (http://www.w3.org/TR/REC-xml/#NT-S)
+ return c == 0x20 || c == 0x9 || c == 0xD || c == 0xA;
+ }
+
private boolean isBlock(final Node node) {
return policy != null && policy.isBlock(node);
}
@@ -393,6 +425,31 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
return policy != null && policy.isPre(node);
}
+ private boolean canInsertText(final INode insertionNode, final int offset) {
+
+ final List<QualifiedName> textNode = Arrays.asList(IValidator.PCDATA);
+
+ if (insertionNode == null) {
+ return false;
+ }
+ return insertionNode.accept(new BaseNodeVisitorWithResult<Boolean>(false) {
+ @Override
+ public Boolean visit(final IElement element) {
+ return validator.isValidSequence(element.getQualifiedName(), textNode, null, null, true);
+ }
+
+ @Override
+ public Boolean visit(final IComment comment) {
+ return true;
+ }
+
+ @Override
+ public Boolean visit(final IText text) {
+ return true;
+ }
+ });
+ }
+
/**
* Convert lines that end in CR and CRLFs to plain newlines.
*
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentReader.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentReader.java
index 3ae35ea..ba6e021 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentReader.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentReader.java
@@ -23,6 +23,7 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.vex.core.provisional.dom.IDocument;
+import org.eclipse.vex.core.provisional.dom.IValidator;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -37,7 +38,7 @@ public class DocumentReader {
private boolean debugging;
- private DocumentContentModel documentContentModel = new DocumentContentModel(); // use the default implementation as default
+ private IValidator validator = IValidator.NULL;
private EntityResolver entityResolver;
@@ -50,7 +51,7 @@ public class DocumentReader {
result = null;
}
if (result == null) {
- return documentContentModel.resolveEntity(publicId, systemId);
+ return validator.getDocumentContentModel().resolveEntity(publicId, systemId);
}
return result;
}
@@ -103,7 +104,7 @@ public class DocumentReader {
factory.setNamespaceAware(true);
final XMLReader xmlReader = factory.newSAXParser().getXMLReader();
- final DocumentBuilder builder = new DocumentBuilder(is.getSystemId(), getDocumentContentModel());
+ final DocumentBuilder builder = new DocumentBuilder(is.getSystemId(), validator);
ContentHandler contentHandler = builder;
LexicalHandler lexicalHandler = builder;
@@ -155,12 +156,11 @@ public class DocumentReader {
this.entityResolver = entityResolver;
}
- public DocumentContentModel getDocumentContentModel() {
- return documentContentModel;
+ public void setValidator(final IValidator validator) {
+ this.validator = validator;
}
- public void setDocumentContentModel(final DocumentContentModel documentContentModel) {
- this.documentContentModel = documentContentModel;
+ public IValidator getValidator() {
+ return validator;
}
-
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java
index 48acd91..3c0b78c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java
@@ -26,10 +26,10 @@ import java.util.Set;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.internal.io.DocumentContentModel;
import org.eclipse.vex.core.provisional.dom.AttributeDefinition;
+import org.eclipse.vex.core.provisional.dom.AttributeDefinition.Type;
import org.eclipse.vex.core.provisional.dom.IAttribute;
import org.eclipse.vex.core.provisional.dom.IElement;
import org.eclipse.vex.core.provisional.dom.IValidator;
-import org.eclipse.vex.core.provisional.dom.AttributeDefinition.Type;
import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement;
import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
@@ -83,6 +83,10 @@ public class WTPVEXValidator implements IValidator {
this.documentContentModel = documentContentModel;
}
+ public DocumentContentModel getDocumentContentModel() {
+ return documentContentModel;
+ }
+
private CMDocument getSchema(final String namespaceURI) {
if (isDTDDefined()) {
return getDTD();
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/IValidator.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/IValidator.java
index 468e8d8..e99b11e 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/IValidator.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/IValidator.java
@@ -12,10 +12,12 @@
*******************************************************************************/
package org.eclipse.vex.core.provisional.dom;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.vex.core.internal.io.DocumentContentModel;
/**
* Represents an object that can validate the structure of a document.
@@ -23,10 +25,53 @@ import org.eclipse.core.runtime.QualifiedName;
public interface IValidator {
/**
+ * NULL object
+ */
+ IValidator NULL = new IValidator() {
+
+ private final DocumentContentModel documentContentModel = new DocumentContentModel();
+
+ public DocumentContentModel getDocumentContentModel() {
+ return documentContentModel;
+ }
+
+ public AttributeDefinition getAttributeDefinition(final IAttribute attribute) {
+ return null;
+ }
+
+ public List<AttributeDefinition> getAttributeDefinitions(final IElement element) {
+ return Collections.emptyList();
+ }
+
+ public Set<QualifiedName> getValidRootElements() {
+ return Collections.emptySet();
+ }
+
+ public Set<QualifiedName> getValidItems(final IElement element) {
+ return Collections.emptySet();
+ }
+
+ public boolean isValidSequence(final QualifiedName element, final List<QualifiedName> nodes, final boolean partial) {
+ return false;
+ }
+
+ public boolean isValidSequence(final QualifiedName element, final List<QualifiedName> sequence1, final List<QualifiedName> sequence2, final List<QualifiedName> sequence3, final boolean partial) {
+ return false;
+ }
+
+ public Set<String> getRequiredNamespaces() {
+ return Collections.emptySet();
+ }
+
+ };
+
+ /**
* QualifiedName indicating that character data is allowed at the given point in the document.
*/
final QualifiedName PCDATA = new QualifiedName(null, "#PCDATA");
+ DocumentContentModel getDocumentContentModel();
+
/**
* Returns the AttributeDefinition for a particular attribute.
*
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
index 183c17b..7df9590 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
@@ -336,9 +336,10 @@ public class VexEditor extends EditorPart {
}
final VexDocumentContentModel documentContentModel = new VexDocumentContentModel(getSite().getShell());
+ final IValidator validator = new WTPVEXValidator(documentContentModel);
final DocumentReader reader = new DocumentReader();
reader.setDebugging(debugging);
- reader.setDocumentContentModel(documentContentModel);
+ reader.setValidator(validator);
document = reader.read(inputSource);
if (debugging) {
@@ -356,13 +357,10 @@ public class VexEditor extends EditorPart {
doctype = documentContentModel.getDocumentType();
style = documentContentModel.getStyle();
- final IValidator validator = new WTPVEXValidator(documentContentModel);
- if (validator != null) {
- document.setValidator(validator);
- if (debugging) {
- final long end = System.currentTimeMillis();
- System.out.println("Got validator in " + (end - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ document.setValidator(validator);
+ if (debugging) {
+ final long end = System.currentTimeMillis();
+ System.out.println("Got validator in " + (end - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
}
showVexWidget();