test the correct setting of publicID and systemID on Document, based on
the startDTD event of LexicalHandler, implemented in DocumentBuilder

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentReaderTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentReaderTest.java
new file mode 100644
index 0000000..f7708f9
--- /dev/null
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentReaderTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************

+ * Copyright (c) 2011 Florian Thienel 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:

+ * 		Florian Thienel - initial API and implementation

+ *******************************************************************************/

+package org.eclipse.vex.core.internal.dom;

+

+import static org.junit.Assert.*;

+import static org.junit.Assert.assertEquals;

+import static org.junit.Assert.assertNotNull;

+import static org.junit.Assert.assertNull;

+

+import java.net.URL;

+

+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;

+import org.junit.Test;

+

+/**

+ * @author Florian Thienel

+ */

+public class DocumentReaderTest {

+	

+	@Test

+	public void readDocumentWithDtdPublic() throws Exception {

+		final DocumentReader reader = new DocumentReader();

+		reader.setWhitespacePolicyFactory(IWhitespacePolicyFactory.NULL);

+		final Document document = reader.read(TestResources.get("documentWithDtdPublic.xml"));

+		assertEquals("-//Eclipse Foundation//DTD Vex Test//EN", document.getPublicID());

+		assertEquals("test1.dtd", document.getSystemID());

+	}

+

+	@Test

+	public void testname() throws Exception {

+		final DocumentReader reader = new DocumentReader();

+		reader.setWhitespacePolicyFactory(IWhitespacePolicyFactory.NULL);

+		final URL documentUrl = TestResources.get("documentWithDtdSystem.xml");

+		final Document document = reader.read(documentUrl);

+		assertNull(document.getPublicID());

+		assertEquals("test1.dtd", document.getSystemID());

+	}

+	

+	@Test

+	public void resolveDtdWithSystemId() throws Exception {

+		final URL documentUrl = TestResources.get("documentWithDtdSystem.xml");

+		final ContentModelManager modelManager = ContentModelManager.getInstance();

+		final URL dtdUrl = new URL(documentUrl, "test1.dtd");

+		final CMDocument dtd = modelManager.createCMDocument(dtdUrl.toString(), null);

+		assertNotNull(dtd.getElements().getNamedItem("section"));

+	}

+}

diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java
index 0df4c9c..de69eba 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java
@@ -21,6 +21,7 @@
 import org.eclipse.vex.core.internal.css.RuleTest;
 import org.eclipse.vex.core.internal.dom.BlockElementBoxTest;
 import org.eclipse.vex.core.internal.dom.DTDValidatorTest;
+import org.eclipse.vex.core.internal.dom.DocumentReaderTest;
 import org.eclipse.vex.core.internal.dom.DocumentWriterTest;
 import org.eclipse.vex.core.internal.dom.GapContentTest;
 import org.eclipse.vex.core.internal.dom.NamespaceStackTest;
@@ -45,6 +46,7 @@
 		super("Vex Core Tests");
 		addTest(new JUnit4TestAdapter(NamespaceStackTest.class));
 		addTest(new JUnit4TestAdapter(NamespaceTest.class));
+		addTest(new JUnit4TestAdapter(DocumentReaderTest.class));
 		addTest(new JUnit4TestAdapter(SchemaValidatorTest.class));
 		addTestSuite(CssTest.class);
 		addTestSuite(PropertyTest.class);
diff --git a/org.eclipse.vex.core.tests/testResources/documentWithDtdPublic.xml b/org.eclipse.vex.core.tests/testResources/documentWithDtdPublic.xml
new file mode 100644
index 0000000..70c9dd4
--- /dev/null
+++ b/org.eclipse.vex.core.tests/testResources/documentWithDtdPublic.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>

+<!DOCTYPE section PUBLIC "-//Eclipse Foundation//DTD Vex Test//EN" "test1.dtd">

+<section>

+	<title>Testdocument with DTD (Public Identifier)</title>

+	<para>This is a Testdocument using a DTD which is referenced by a public identifier.</para>

+</section>
\ No newline at end of file
diff --git a/org.eclipse.vex.core.tests/testResources/documentWithDtdSystem.xml b/org.eclipse.vex.core.tests/testResources/documentWithDtdSystem.xml
new file mode 100644
index 0000000..7637e16
--- /dev/null
+++ b/org.eclipse.vex.core.tests/testResources/documentWithDtdSystem.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>

+<!DOCTYPE section SYSTEM "test1.dtd">

+<section>

+	<title>Testdocument with DTD (System Identifier)</title>

+	<para>This is a Testdocument using a DTD which is referenced by a system identifier.</para>

+</section>
\ No newline at end of file
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java
index 14ab02c..d1e645e 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java
@@ -41,7 +41,7 @@
 	// Holds pending characters until we see another element boundary.
 	// This is (a) so we can collapse spaces in multiple adjacent character
 	// blocks, and (b) so we can trim trailing whitespace, if necessary.
-	private final StringBuffer pendingChars = new StringBuffer();
+	private final StringBuilder pendingChars = new StringBuilder();
 
 	// If true, trim the leading whitespace from the next received block of
 	// text.
@@ -118,7 +118,6 @@
 	}
 
 	public void endPrefixMapping(final String prefix) {
-		System.out.println("end prefix: '" + prefix + "'"); // TODO trace
 	}
 
 	public void ignorableWhitespace(final char[] ch, final int start, final int length) {
@@ -138,7 +137,6 @@
 	}
 
 	public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes attrs) throws SAXException {
-		System.out.println("element: '" + qName + "' namespaceUri: '" + namespaceURI + "' local: '" + localName + "'"); // TODO trace
 		final QualifiedName elementName;
 		if ("".equals(namespaceURI))
 			elementName = new QualifiedName(null, qName);
@@ -166,7 +164,6 @@
 
 		final int n = attrs.getLength();
 		for (int i = 0; i < n; i++) {
-			System.out.println("attr: " + attrs.getQName(i)); // TODO trace
 			final QualifiedName attributeName;
 			if ("".equals(attrs.getLocalName(i)))
 				attributeName = new QualifiedName(null, attrs.getQName(i));
@@ -192,7 +189,6 @@
 	}
 
 	public void startPrefixMapping(final String prefix, final String uri) {
-		System.out.println("prefix: '" + prefix + "' uri: '" + uri + "'"); // TODO trace
 		checkPrefix(prefix);
 		if (isDefaultPrefix(prefix))
 			namespaceStack.pushDefault(uri);
@@ -238,7 +234,7 @@
 	// Append any pending characters to the content
 	private void appendChars(final boolean trimTrailing) {
 
-		StringBuffer sb;
+		StringBuilder sb;
 
 		sb = cleanUpTextContent(trimTrailing);
 
@@ -248,8 +244,8 @@
 		trimLeading = false;
 	}
 
-	private StringBuffer cleanUpTextContent(final boolean trimTrailing) {
-		StringBuffer sb;
+	private StringBuilder cleanUpTextContent(final boolean trimTrailing) {
+		StringBuilder sb;
 		final StackEntry entry = stack.isEmpty() ? null : stack.getLast();
 
 		if (entry != null && entry.pre)
@@ -257,7 +253,7 @@
 		else {
 
 			// collapse the space in the pending characters
-			sb = new StringBuffer(pendingChars.length());
+			sb = new StringBuilder(pendingChars.length());
 			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);
@@ -298,7 +294,7 @@
 	 * @param sb
 	 *            StringBuffer to be normalized.
 	 */
-	private void normalizeNewlines(final StringBuffer sb) {
+	private void normalizeNewlines(final StringBuilder sb) {
 
 		// State machine states
 		final int START = 0;
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentReader.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentReader.java
index a54bdea..271a844 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentReader.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentReader.java
@@ -34,6 +34,12 @@
  */
 public class DocumentReader {
 
+	private boolean debugging;
+
+	private EntityResolver entityResolver;
+	
+	private IWhitespacePolicyFactory whitespacePolicyFactory;
+
 	/**
 	 * Returns the debugging flag.
 	 */
@@ -62,7 +68,6 @@
 	 *            URL from which to load the document.
 	 */
 	public Document read(final URL url) throws IOException, ParserConfigurationException, SAXException {
-
 		return read(new InputSource(url.toString()));
 	}
 
@@ -74,7 +79,6 @@
 	 *            String containing the document to be read.
 	 */
 	public Document read(final String s) throws IOException, ParserConfigurationException, SAXException {
-
 		final Reader reader = new CharArrayReader(s.toCharArray());
 		return this.read(new InputSource(reader));
 	}
@@ -86,15 +90,14 @@
 	 *            SAX InputSource from which to load the document.
 	 */
 	public Document read(final InputSource is) throws IOException, ParserConfigurationException, SAXException {
-
 		final SAXParserFactory factory = SAXParserFactory.newInstance();
-		factory.setValidating(false); // TODO: experimental--SWT implementation
+		factory.setValidating(false);
 		factory.setNamespaceAware(true);
+
 		final XMLReader xmlReader = factory.newSAXParser().getXMLReader();
 		// xmlReader.setFeature("http://xml.org/sax/features/validation",
 		// false);
-		final org.eclipse.vex.core.internal.dom.DocumentBuilder builder = new org.eclipse.vex.core.internal.dom.DocumentBuilder(
-				getWhitespacePolicyFactory());
+		final org.eclipse.vex.core.internal.dom.DocumentBuilder builder = new org.eclipse.vex.core.internal.dom.DocumentBuilder(getWhitespacePolicyFactory());
 
 		ContentHandler contentHandler = builder;
 		LexicalHandler lexicalHandler = builder;
@@ -159,10 +162,4 @@
 		this.whitespacePolicyFactory = whitespacePolicyFactory;
 	}
 
-	// ======================================================= PRIVATE
-
-	private boolean debugging;
-	private EntityResolver entityResolver;
-	private IWhitespacePolicyFactory whitespacePolicyFactory;
-
 }