[161330] XML Formatter Misformats CDATA
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java
index 5f52e58..d49d827 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java
@@ -17,7 +17,6 @@
 import org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences;
 import org.eclipse.wst.sse.core.internal.format.IStructuredFormatter;
 import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.document.CDATASectionImpl;
 import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
 import org.w3c.dom.Node;
 
@@ -70,10 +69,11 @@
 				break;
 			}
 			case Node.TEXT_NODE : {
-				if (node instanceof CDATASectionImpl)
-					formatter = new NodeFormatter();
-				else
-					formatter = new TextNodeFormatter();
+				formatter = new TextNodeFormatter();
+				break;
+			}
+			case Node.CDATA_SECTION_NODE : {
+				formatter = new NoMoveFormatter();
 				break;
 			}
 			case Node.COMMENT_NODE : {
@@ -89,7 +89,7 @@
 				break;
 			}
 			case Node.ENTITY_REFERENCE_NODE : {
-				formatter = new EntityReferenceFormatter();
+				formatter = new NoMoveFormatter();
 				break;
 			}
 			default : {
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/EntityReferenceFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java
similarity index 94%
rename from bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/EntityReferenceFormatter.java
rename to bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java
index 8b14ab5..7b68ece 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/EntityReferenceFormatter.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java
@@ -17,7 +17,7 @@
  * Formats entities which really need no formatting. They are just like text
  * nodes.
  */
-public class EntityReferenceFormatter extends NodeFormatter {
+class NoMoveFormatter extends NodeFormatter {
 	protected void formatIndentationBeforeNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
 		// node nothing
 	}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java
index e9c5d72..7964580 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java
@@ -159,7 +159,7 @@
 			IDOMNode previousSibling = (IDOMNode) node.getPreviousSibling();
 			IStructuredDocument doc = node.getModel().getStructuredDocument();
 			String lineDelimiter = getLineDelimiter(node, doc);
-			
+
 			String lineIndent = formatContraints.getCurrentIndent();
 
 			if (node.getParentNode() != null) {
@@ -394,11 +394,12 @@
 				formatter = new ElementNodeFormatter();
 				break;
 			}
-			case Node.TEXT_NODE: {
-				if (node instanceof CDATASectionImpl)
-					formatter = new NodeFormatter();
-				else
-					formatter = new TextNodeFormatter();
+			case Node.TEXT_NODE : {
+				formatter = new TextNodeFormatter();
+				break;
+			}
+			case Node.CDATA_SECTION_NODE : {
+				formatter = new NoMoveFormatter();
 				break;
 			}
 			case Node.COMMENT_NODE : {
@@ -414,7 +415,7 @@
 				break;
 			}
 			case Node.ENTITY_REFERENCE_NODE : {
-				formatter = new EntityReferenceFormatter();
+				formatter = new NoMoveFormatter();
 				break;
 			}
 			default : {
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java
index a4b382b..bb180ce 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java
@@ -141,11 +141,11 @@
 				// handle first line specially to check for allowWhitespace
 				if (vectorSize > 0) {
 					// determines whether or not to allow whitespace if there
-					// is an entity before it
+					// is an entity or cdata before it
 					boolean allowWhitespace = true;
 					if (!Character.isWhitespace(nodeText.charAt(0))) {
 						Node previousSibling = node.getPreviousSibling();
-						if (previousSibling != null && previousSibling.getNodeType() == Node.ENTITY_REFERENCE_NODE)
+						if (previousSibling != null && (previousSibling.getNodeType() == Node.ENTITY_REFERENCE_NODE || previousSibling.getNodeType() == Node.CDATA_SECTION_NODE))
 							allowWhitespace = false;
 					}
 					String theString = (String) vector.get(0);
@@ -207,7 +207,7 @@
 								reflowedText = StringUtils.appendIfNotEndWith(reflowedText, nodeIndentation);
 							}
 						}
-						else if (nextSibling.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
+						else if (nextSibling.getNodeType() == Node.ENTITY_REFERENCE_NODE || nextSibling.getNodeType() == Node.CDATA_SECTION_NODE) {
 							int textLength = nodeText.length();
 							if (textLength > 0 && Character.isWhitespace(nodeText.charAt(textLength - 1))) {
 								reflowedText = StringUtils.appendIfNotEndWith(reflowedText, lineDelimiter);