remove dependency from DocumentContentModel to IWhitespacePolicy

https://bugs.eclipse.org/bugs/show_bug.cgi?id=409893
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
index 414a7c7..7a55ca6 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
@@ -20,7 +20,6 @@
 

 import org.eclipse.core.runtime.QualifiedName;

 import org.eclipse.vex.core.internal.dom.Element;

-import org.eclipse.vex.core.internal.io.DocumentContentModel;

 import org.eclipse.vex.core.tests.TestResources;

 import org.eclipse.vex.core.tests.VEXCoreTestPlugin;

 import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;

@@ -63,11 +62,6 @@
 	}

 

 	@Test

-	public void createWhitespacePolicy() throws Exception {

-		assertNotNull(model.getWhitespacePolicy());

-	}

-

-	@Test

 	public void isEntityResolver() throws Exception {

 		assertTrue(model instanceof EntityResolver);

 	}

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 505a0ab..8a5c7ca 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
@@ -294,19 +294,16 @@
 		assertFalse("more strings expected", children.hasNext());
 	}
 
-	private IDocument createDocument(final String s, final StyleSheet ss) throws ParserConfigurationException, SAXException, IOException {
+	private IDocument createDocument(final String documentContent, final StyleSheet styleSheet) throws ParserConfigurationException, SAXException, IOException {
 		final SAXParserFactory factory = SAXParserFactory.newInstance();
 		final XMLReader xmlReader = factory.newSAXParser().getXMLReader();
-		final StyleSheet mySS = ss;
-		final CssWhitespacePolicy policy = new CssWhitespacePolicy(mySS);
-		final DocumentBuilder builder = new DocumentBuilder(null, new DummyValidator(new DocumentContentModel() {
-			@Override
-			public IWhitespacePolicy getWhitespacePolicy() {
-				return policy;
+		final DocumentBuilder builder = new DocumentBuilder(null, new DummyValidator(), new IStyleSheetProvider() {
+			public StyleSheet getStyleSheet(final DocumentContentModel documentContentModel) {
+				return styleSheet;
 			}
-		}));
+		}, CssWhitespacePolicy.FACTORY);
 
-		final InputSource is = new InputSource(new ByteArrayInputStream(s.getBytes()));
+		final InputSource is = new InputSource(new ByteArrayInputStream(documentContent.getBytes()));
 		xmlReader.setContentHandler(builder);
 		xmlReader.parse(is);
 		return builder.getDocument();
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 708628e..98bceed 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
@@ -32,7 +32,7 @@
 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;
+import org.eclipse.vex.core.internal.io.IStyleSheetProvider;
 import org.eclipse.vex.core.provisional.dom.BaseNodeVisitorWithResult;
 import org.eclipse.vex.core.provisional.dom.ContentRange;
 import org.eclipse.vex.core.provisional.dom.IDocument;
@@ -65,7 +65,7 @@
 public class LayoutTestSuite extends TestCase {
 
 	public String id;
-	public String doc;
+	public String documentContent;
 	public int layoutWidth = 100;
 	public boolean performActions = false;
 	public BoxSpec result;
@@ -107,34 +107,33 @@
 
 	public void testLayout() throws Exception {
 		final URL url = LayoutTestSuite.class.getResource(css);
-		final StyleSheetReader reader = new StyleSheetReader();
-		final StyleSheet ss = reader.read(url);
+		final StyleSheet styleSheet = new StyleSheetReader().read(url);
 
 		final FakeGraphics g = new FakeGraphics();
 
 		final LayoutContext context = new LayoutContext();
 		context.setBoxFactory(new MockBoxFactory());
 		context.setGraphics(g);
-		context.setStyleSheet(ss);
-		final CssWhitespacePolicy policy = new CssWhitespacePolicy(ss);
+		context.setStyleSheet(styleSheet);
 
-		final DocumentReader docReader = new DocumentReader();
-		docReader.setValidator(new DummyValidator(new DocumentContentModel() {
-			@Override
-			public IWhitespacePolicy getWhitespacePolicy() {
-				return policy;
+		final DocumentReader reader = new DocumentReader();
+		reader.setValidator(new DummyValidator());
+		reader.setStyleSheetProvider(new IStyleSheetProvider() {
+			public StyleSheet getStyleSheet(final DocumentContentModel documentContentModel) {
+				return styleSheet;
 			}
-		}));
-		final IDocument doc = docReader.read(this.doc);
-		context.setDocument(doc);
+		});
+		reader.setWhitespacePolicyFactory(CssWhitespacePolicy.FACTORY);
+		final IDocument document = reader.read(documentContent);
+		context.setDocument(document);
 
-		final RootBox rootBox = new RootBox(context, doc, layoutWidth);
+		final RootBox rootBox = new RootBox(context, document, layoutWidth);
 		rootBox.layout(context, 0, Integer.MAX_VALUE);
 
 		assertBox(result, rootBox, "");
 
 		if (performActions) {
-			performActions(result, rootBox, doc);
+			performActions(result, rootBox, document);
 			assertLayoutStates(result, rootBox);
 			rootBox.layout(context, 0, Integer.MAX_VALUE);
 			assertBox(result, rootBox, "", true);
@@ -259,7 +258,7 @@
 			final String s = new String(ch, start, length).trim();
 			if (s.length() > 0) {
 				if (inDoc) {
-					testCase.doc = testCase.doc + new String(ch, start, length);
+					testCase.documentContent = testCase.documentContent + new String(ch, start, length);
 				} else {
 					throw new IllegalStateException();
 				}
@@ -302,7 +301,7 @@
 				testCases.add(testCase);
 			} else if (qName.equals("doc")) {
 				inDoc = true;
-				testCase.doc = "";
+				testCase.documentContent = "";
 			} else if (qName.equals("result")) {
 			} else if (qName.equals("box")) {
 				final BoxSpec parent = boxSpec;
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/CssWhitespacePolicy.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/CssWhitespacePolicy.java
index 00fa855..ee8abb6 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/CssWhitespacePolicy.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/CssWhitespacePolicy.java
@@ -10,8 +10,11 @@
  *******************************************************************************/
 package org.eclipse.vex.core.internal.css;
 
+import org.eclipse.vex.core.internal.io.DocumentContentModel;
 import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
+import org.eclipse.vex.core.internal.io.IWhitespacePolicyFactory;
 import org.eclipse.vex.core.provisional.dom.INode;
+import org.eclipse.vex.core.provisional.dom.IValidator;
 
 /**
  * Implementation of IWhitespacePolicy using a CSS stylesheet.
@@ -20,6 +23,12 @@
  */
 public class CssWhitespacePolicy implements IWhitespacePolicy {
 
+	public static final IWhitespacePolicyFactory FACTORY = new IWhitespacePolicyFactory() {
+		public IWhitespacePolicy createPolicy(final IValidator validator, final DocumentContentModel documentContentModel, final StyleSheet styleSheet) {
+			return new CssWhitespacePolicy(styleSheet);
+		}
+	};
+
 	private final StyleSheet styleSheet;
 
 	/**
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 cd7ed24..78d1b4a 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
@@ -20,6 +20,7 @@
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.QualifiedName;
 import org.eclipse.vex.core.XML;
+import org.eclipse.vex.core.internal.css.StyleSheet;
 import org.eclipse.vex.core.internal.dom.Comment;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
@@ -57,7 +58,10 @@
 
 	private final IValidator validator;
 
-	private IWhitespacePolicy policy;
+	private final IStyleSheetProvider styleSheetProvider;
+
+	private final IWhitespacePolicyFactory whitespacePolicyFactory;
+	private IWhitespacePolicy whitespacePolicy = IWhitespacePolicy.NULL;
 
 	// Holds pending characters until we see another element boundary.
 	// This is (a) so we can collapse spaces in multiple adjacent character
@@ -89,9 +93,11 @@
 	private IDocument document;
 	private Locator locator;
 
-	public DocumentBuilder(final String baseUri, final IValidator validator) {
+	public DocumentBuilder(final String baseUri, final IValidator validator, final IStyleSheetProvider styleSheetProvider, final IWhitespacePolicyFactory whitespacePolicyFactory) {
 		this.baseUri = baseUri;
 		this.validator = validator;
+		this.styleSheetProvider = styleSheetProvider;
+		this.whitespacePolicyFactory = whitespacePolicyFactory;
 	}
 
 	/**
@@ -101,6 +107,10 @@
 		return document;
 	}
 
+	public IWhitespacePolicy getWhitespacePolicy() {
+		return whitespacePolicy;
+	}
+
 	// ============================================= ContentHandler methods
 
 	public void characters(final char[] ch, final int start, final int length) throws SAXException {
@@ -221,7 +231,8 @@
 		final DocumentContentModel documentContentModel = validator.getDocumentContentModel();
 		if (stack.isEmpty() && documentContentModel != null) {
 			documentContentModel.initialize(baseUri, dtdPublicID, dtdSystemID, rootElement);
-			policy = documentContentModel.getWhitespacePolicy();
+			final StyleSheet styleSheet = styleSheetProvider.getStyleSheet(documentContentModel);
+			whitespacePolicy = whitespacePolicyFactory.createPolicy(validator, documentContentModel, styleSheet);
 		}
 
 		appendChars(isBlock(element));
@@ -391,11 +402,11 @@
 	}
 
 	private boolean isBlock(final Node node) {
-		return policy != null && policy.isBlock(node);
+		return whitespacePolicy != null && whitespacePolicy.isBlock(node);
 	}
 
 	private boolean isPre(final Node node) {
-		return policy != null && policy.isPre(node);
+		return whitespacePolicy != null && whitespacePolicy.isPre(node);
 	}
 
 	private boolean canInsertText(final INode insertionNode, final int offset) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentContentModel.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentContentModel.java
index edf07a0..27a70a1 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentContentModel.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentContentModel.java
@@ -84,10 +84,6 @@
 		return modelManager.createCMDocument(resolvedDtdUrl.toString(), null);

 	}

 

-	public IWhitespacePolicy getWhitespacePolicy() {

-		return IWhitespacePolicy.NULL;

-	}

-

 	public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {

 		final String resolved = URI_RESOLVER.resolve(baseUri, publicId, systemId);

 		System.out.println("Resolved " + publicId + " " + systemId + " -> " + resolved);

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 ba6e021..4c8279e 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
@@ -40,6 +40,12 @@
 
 	private IValidator validator = IValidator.NULL;
 
+	private IStyleSheetProvider styleSheetProvider = IStyleSheetProvider.NULL;
+
+	private IWhitespacePolicyFactory whitespacePolicyFactory = IWhitespacePolicyFactory.NULL;
+
+	private IWhitespacePolicy whitespacePolicy = IWhitespacePolicy.NULL;
+
 	private EntityResolver entityResolver;
 
 	private final EntityResolver combinedEntityResolver = new EntityResolver() {
@@ -65,13 +71,6 @@
 	}
 
 	/**
-	 * Returns the entity resolver for this reader.
-	 */
-	public EntityResolver getEntityResolver() {
-		return entityResolver;
-	}
-
-	/**
 	 * Reads a document given a URL.
 	 * 
 	 * @param url
@@ -104,7 +103,7 @@
 		factory.setNamespaceAware(true);
 
 		final XMLReader xmlReader = factory.newSAXParser().getXMLReader();
-		final DocumentBuilder builder = new DocumentBuilder(is.getSystemId(), validator);
+		final DocumentBuilder builder = new DocumentBuilder(is.getSystemId(), validator, styleSheetProvider, whitespacePolicyFactory);
 
 		ContentHandler contentHandler = builder;
 		LexicalHandler lexicalHandler = builder;
@@ -133,6 +132,9 @@
 		if (result != null) {
 			result.setDocumentURI(is.getSystemId());
 		}
+
+		whitespacePolicy = builder.getWhitespacePolicy();
+
 		return result;
 	}
 
@@ -156,6 +158,13 @@
 		this.entityResolver = entityResolver;
 	}
 
+	/**
+	 * Returns the entity resolver for this reader.
+	 */
+	public EntityResolver getEntityResolver() {
+		return entityResolver;
+	}
+
 	public void setValidator(final IValidator validator) {
 		this.validator = validator;
 	}
@@ -163,4 +172,16 @@
 	public IValidator getValidator() {
 		return validator;
 	}
+
+	public void setStyleSheetProvider(final IStyleSheetProvider styleSheetProvider) {
+		this.styleSheetProvider = styleSheetProvider;
+	}
+
+	public void setWhitespacePolicyFactory(final IWhitespacePolicyFactory whitespacePolicyFactory) {
+		this.whitespacePolicyFactory = whitespacePolicyFactory;
+	}
+
+	public IWhitespacePolicy getWhitespacePolicy() {
+		return whitespacePolicy;
+	}
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IStyleSheetProvider.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IStyleSheetProvider.java
new file mode 100644
index 0000000..2f8ac93
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IStyleSheetProvider.java
@@ -0,0 +1,28 @@
+/*******************************************************************************

+ * Copyright (c) 2013 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.io;

+

+import org.eclipse.vex.core.internal.css.StyleSheet;

+

+/**

+ * @author Florian Thienel

+ */

+public interface IStyleSheetProvider {

+

+	static final IStyleSheetProvider NULL = new IStyleSheetProvider() {

+		public StyleSheet getStyleSheet(final DocumentContentModel documentContentModel) {

+			return StyleSheet.NULL;

+		}

+	};

+

+	StyleSheet getStyleSheet(DocumentContentModel documentContentModel);

+

+}

diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IWhitespacePolicyFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IWhitespacePolicyFactory.java
index 6eca185..dd8834b 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IWhitespacePolicyFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/IWhitespacePolicyFactory.java
@@ -11,6 +11,9 @@
  *******************************************************************************/
 package org.eclipse.vex.core.internal.io;
 
+import org.eclipse.vex.core.internal.css.StyleSheet;
+import org.eclipse.vex.core.provisional.dom.IValidator;
+
 /**
  * Factory for returning a WhitespacePolicy object given a document type public ID. This is required by DocumentBuilder,
  * since we don't know what WhitespacePolicy we need before we begin parsing the document.
@@ -21,7 +24,7 @@
 	 * A factory that always returns the NULL whitespace policy.
 	 */
 	IWhitespacePolicyFactory NULL = new IWhitespacePolicyFactory() {
-		public IWhitespacePolicy getPolicy(final String publicId) {
+		public IWhitespacePolicy createPolicy(final IValidator validator, final DocumentContentModel documentContentModel, final StyleSheet style) {
 			return IWhitespacePolicy.NULL;
 		}
 	};
@@ -32,5 +35,5 @@
 	 * @param publicId
 	 *            Public ID of the document type associated with the document.
 	 */
-	IWhitespacePolicy getPolicy(String publicId);
+	IWhitespacePolicy createPolicy(IValidator validator, DocumentContentModel documentContentModel, StyleSheet styleSheet);
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/IVexWidget.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/IVexWidget.java
index 0bd5099..16a9eb1 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/IVexWidget.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/IVexWidget.java
@@ -16,6 +16,7 @@
 import org.eclipse.core.runtime.QualifiedName;
 import org.eclipse.vex.core.internal.core.ElementName;
 import org.eclipse.vex.core.internal.css.StyleSheet;
+import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
 import org.eclipse.vex.core.internal.layout.Box;
 import org.eclipse.vex.core.internal.layout.BoxFactory;
 import org.eclipse.vex.core.internal.undo.CannotRedoException;
@@ -503,6 +504,10 @@
 	 */
 	public void setStyleSheet(URL ssUrl) throws IOException;
 
+	public void setWhitespacePolicy(IWhitespacePolicy whitespacePolicy);
+
+	public IWhitespacePolicy getWhitespacePolicy();
+
 	/**
 	 * Split the element at the current caret offset. This is the normal behaviour when the user presses Enter.
 	 */
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
index 5e4be04..599276b 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
@@ -40,6 +40,7 @@
 import org.eclipse.vex.core.internal.css.Styles;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Node;
+import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
 import org.eclipse.vex.core.internal.layout.BlockBox;
 import org.eclipse.vex.core.internal.layout.Box;
 import org.eclipse.vex.core.internal.layout.BoxFactory;
@@ -106,6 +107,8 @@
 
 	private IDocument document;
 	private StyleSheet styleSheet;
+	private IWhitespacePolicy whitespacePolicy = IWhitespacePolicy.NULL;
+
 	private BoxFactory boxFactory = new CssBoxFactory();
 
 	private RootBox rootBox;
@@ -1355,6 +1358,18 @@
 		this.setStyleSheet(ss);
 	}
 
+	public void setWhitespacePolicy(final IWhitespacePolicy whitespacePolicy) {
+		if (whitespacePolicy == null) {
+			this.whitespacePolicy = IWhitespacePolicy.NULL;
+		} else {
+			this.whitespacePolicy = whitespacePolicy;
+		}
+	}
+
+	public IWhitespacePolicy getWhitespacePolicy() {
+		return whitespacePolicy;
+	}
+
 	public void split() throws DocumentValidationException, ReadOnlyException {
 		if (readOnly) {
 			throw new ReadOnlyException("Cannot split, because the editor is read-only.");
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java
index 14db75c..1580a72 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java
@@ -15,6 +15,9 @@
 import org.eclipse.core.runtime.IStatus;

 import org.eclipse.core.runtime.preferences.InstanceScope;

 import org.eclipse.jface.preference.IPreferenceStore;

+import org.eclipse.vex.core.internal.css.StyleSheet;

+import org.eclipse.vex.core.internal.io.DocumentContentModel;

+import org.eclipse.vex.core.internal.io.IStyleSheetProvider;

 import org.eclipse.vex.ui.internal.config.ConfigurationRegistry;

 import org.eclipse.vex.ui.internal.config.Style;

 import org.eclipse.vex.ui.internal.editor.Messages;

@@ -24,7 +27,7 @@
 /**

  * @author Florian Thienel

  */

-public class VexPreferences {

+public class VexPreferences implements IStyleSheetProvider {

 

 	public static final String INDENTATION_CHAR_CHOICE = "indetationCharChoice";

 

@@ -83,4 +86,12 @@
 	public int getLineWidth() {

 		return preferenceStore.getInt(LINE_WIDTH);

 	}

+

+	public StyleSheet getStyleSheet(final DocumentContentModel documentContentModel) {

+		final Style style = getPreferredStyle(documentContentModel.getMainDocumentTypeIdentifier());

+		if (style == null) {

+			return StyleSheet.NULL;

+		}

+		return style.getStyleSheet();

+	}

 }

diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
index b969107..d38a6e8 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2011 Florian Thienel and others.

+ * Copyright (c) 2011, 2013 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

@@ -11,9 +11,7 @@
 package org.eclipse.vex.ui.internal.editor;

 

 import org.eclipse.swt.widgets.Shell;

-import org.eclipse.vex.core.internal.css.CssWhitespacePolicy;

 import org.eclipse.vex.core.internal.io.DocumentContentModel;

-import org.eclipse.vex.core.internal.io.IWhitespacePolicy;

 import org.eclipse.vex.core.provisional.dom.IElement;

 import org.eclipse.vex.ui.internal.VexPlugin;

 import org.eclipse.vex.ui.internal.config.DocumentType;

@@ -75,14 +73,6 @@
 		return dialog.getDoctype();

 	}

 

-	@Override

-	public IWhitespacePolicy getWhitespacePolicy() {

-		if (style == null) {

-			return super.getWhitespacePolicy();

-		}

-		return new CssWhitespacePolicy(style.getStyleSheet());

-	}

-

 	public DocumentType getDocumentType() {

 		return documentType;

 	}

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 7df9590..8e86963 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
@@ -202,7 +202,7 @@
 
 	private DocumentWriter createDocumentWriter() {
 		final DocumentWriter result = new DocumentWriter();
-		result.setWhitespacePolicy(new CssWhitespacePolicy(style.getStyleSheet()));
+		result.setWhitespacePolicy(vexWidget.getWhitespacePolicy());
 		result.setIndent(preferences.getIndentationPattern());
 		result.setWrapColumn(preferences.getLineWidth());
 		return result;
@@ -340,6 +340,8 @@
 			final DocumentReader reader = new DocumentReader();
 			reader.setDebugging(debugging);
 			reader.setValidator(validator);
+			reader.setStyleSheetProvider(VexPlugin.getDefault().getPreferences());
+			reader.setWhitespacePolicyFactory(CssWhitespacePolicy.FACTORY);
 			document = reader.read(inputSource);
 
 			if (debugging) {
@@ -368,6 +370,7 @@
 			document.addDocumentListener(documentListener);
 
 			vexWidget.setDebugging(debugging);
+			vexWidget.setWhitespacePolicy(reader.getWhitespacePolicy());
 			vexWidget.setDocument(document, style.getStyleSheet());
 			vexWidget.setReadOnly(readOnly);
 
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DefaultOutlineProvider.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DefaultOutlineProvider.java
index 6dacff8..4e143dd 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DefaultOutlineProvider.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DefaultOutlineProvider.java
@@ -18,8 +18,6 @@
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.vex.core.internal.css.CssWhitespacePolicy;
-import org.eclipse.vex.core.internal.css.StyleSheet;
 import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
 import org.eclipse.vex.core.provisional.dom.IDocument;
 import org.eclipse.vex.core.provisional.dom.IElement;
@@ -31,8 +29,7 @@
 public class DefaultOutlineProvider implements IOutlineProvider {
 
 	public void init(final VexEditor editor) {
-		final StyleSheet ss = editor.getVexWidget().getStyleSheet();
-		whitespacePolicy = new CssWhitespacePolicy(ss);
+		whitespacePolicy = editor.getVexWidget().getWhitespacePolicy();
 		contentProvider = new ContentProvider();
 		labelProvider = new LabelProvider() {
 			@Override
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/swt/VexWidget.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/swt/VexWidget.java
index 68447a7..eca8a3c 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/swt/VexWidget.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/swt/VexWidget.java
@@ -59,10 +59,11 @@
 import org.eclipse.vex.core.internal.core.Graphics;
 import org.eclipse.vex.core.internal.core.Rectangle;
 import org.eclipse.vex.core.internal.css.StyleSheet;
+import org.eclipse.vex.core.internal.io.IWhitespacePolicy;
 import org.eclipse.vex.core.internal.layout.Box;
 import org.eclipse.vex.core.internal.layout.BoxFactory;
-import org.eclipse.vex.core.internal.widget.IHostComponent;
 import org.eclipse.vex.core.internal.widget.IBoxFilter;
+import org.eclipse.vex.core.internal.widget.IHostComponent;
 import org.eclipse.vex.core.internal.widget.IVexWidget;
 import org.eclipse.vex.core.internal.widget.ReadOnlyException;
 import org.eclipse.vex.core.internal.widget.VexWidgetImpl;
@@ -433,6 +434,14 @@
 		impl.setStyleSheet(ssUrl);
 	}
 
+	public void setWhitespacePolicy(final IWhitespacePolicy whitespacePolicy) {
+		impl.setWhitespacePolicy(whitespacePolicy);
+	}
+
+	public IWhitespacePolicy getWhitespacePolicy() {
+		return impl.getWhitespacePolicy();
+	}
+
 	public void split() throws DocumentValidationException {
 		impl.split();
 	}