[92957] CSS formatting doesn't work in HTML
diff --git a/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/format/CSSSourceFormatter.java b/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/format/CSSSourceFormatter.java
deleted file mode 100644
index 37fe679..0000000
--- a/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/format/CSSSourceFormatter.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.css.core.internal.format;
-
-
-
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-
-
-/**
- * @deprecated
- */
-public interface CSSSourceFormatter extends INodeAdapter {
-
-	/**
-	 * 
-	 */
-	StringBuffer cleanup(ICSSNode node);
-
-	/**
-	 * 
-	 * @return java.lang.StringBuffer
-	 * @param node
-	 *            org.eclipse.wst.css.core.model.interfaces.ICSSNode
-	 * @param region
-	 *            org.eclipse.jface.text.IRegion
-	 */
-	StringBuffer cleanup(ICSSNode node, IRegion region);
-
-	/**
-	 * 
-	 */
-	StringBuffer format(ICSSNode node);
-
-	/**
-	 * 
-	 */
-	StringBuffer format(ICSSNode node, IRegion region);
-}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/CSSTextNodeCleanupHandler.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/CSSTextNodeCleanupHandler.java
index ff8006c..05675c6 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/CSSTextNodeCleanupHandler.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/CSSTextNodeCleanupHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 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,7 +12,8 @@
 
 
 
-import org.eclipse.wst.css.core.internal.format.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatterFactory;
 import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
@@ -57,10 +58,12 @@
 		if (document == null)
 			return null;
 		INodeNotifier notifier = (INodeNotifier) document;
-		INodeAdapter adapter = notifier.getAdapterFor(CSSSourceFormatter.class);
-		if (adapter == null)
+		CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
+		// try another way to get formatter
+		if (formatter == null)
+			formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
+		if (formatter == null)
 			return null;
-		CSSSourceFormatter formatter = (CSSSourceFormatter) adapter;
 		StringBuffer buffer = formatter.cleanup(document);
 		if (buffer == null)
 			return null;
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java
index 32d20db..11af74b 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/cleanup/ElementNodeCleanupHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 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
@@ -20,7 +20,8 @@
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.text.edits.InsertEdit;
 import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.wst.css.core.internal.format.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatterFactory;
 import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleDeclarationAdapter;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
@@ -328,10 +329,12 @@
 		if (document == null)
 			return null;
 		INodeNotifier notifier = (INodeNotifier) document;
-		INodeAdapter adapter = notifier.getAdapterFor(CSSSourceFormatter.class);
-		if (adapter == null)
+		CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
+		// try another way to get formatter
+		if (formatter == null)
+			formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
+		if (formatter == null)
 			return null;
-		CSSSourceFormatter formatter = (CSSSourceFormatter) adapter;
 		StringBuffer buffer = formatter.cleanup(document);
 		if (buffer == null)
 			return null;
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/EmbeddedCSSFormatter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/EmbeddedCSSFormatter.java
index 294906c..74ec679 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/EmbeddedCSSFormatter.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/EmbeddedCSSFormatter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 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,7 +12,8 @@
 
 
 
-import org.eclipse.wst.css.core.internal.format.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatterFactory;
 import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
@@ -26,7 +27,8 @@
 
 public class EmbeddedCSSFormatter extends HTMLFormatter {
 
-	//private IAdapterFactory factory = new CSSSourceFormatterFactory(CSSSourceFormatter.class, true);
+	// private IAdapterFactory factory = new
+	// CSSSourceFormatterFactory(CSSSourceFormatter.class, true);
 	/**
 	 */
 	protected EmbeddedCSSFormatter() {
@@ -61,10 +63,12 @@
 		if (document == null)
 			return null;
 		INodeNotifier notifier = (INodeNotifier) document;
-		INodeAdapter adapter = notifier.getAdapterFor(CSSSourceFormatter.class);
-		if (adapter == null)
+		CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
+		// try another way to get formatter
+		if (formatter == null)
+			formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
+		if (formatter == null)
 			return null;
-		CSSSourceFormatter formatter = (CSSSourceFormatter) adapter;
 		StringBuffer buffer = formatter.format(document);
 		if (buffer == null)
 			return null;
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLElementFormatter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLElementFormatter.java
index 9264c34..88d249b 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLElementFormatter.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLElementFormatter.java
@@ -12,7 +12,8 @@
 
 import java.util.Iterator;
 
-import org.eclipse.wst.css.core.internal.format.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter;
+import org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatterFactory;
 import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleDeclarationAdapter;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
 import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
@@ -108,7 +109,7 @@
 		// String newEndTag = endStructuredDocumentRegion.getText();
 		// if (newEndTag != null && newEndTag.length() > 0) {
 		// setWidth(contraints, newEndTag);
-		//		}
+		// }
 	}
 
 	/**
@@ -339,10 +340,12 @@
 		if (document == null)
 			return null;
 		INodeNotifier notifier = (INodeNotifier) document;
-		INodeAdapter adapter = notifier.getAdapterFor(CSSSourceFormatter.class);
-		if (adapter == null)
+		CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
+		// try another way to get formatter
+		if (formatter == null)
+			formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
+		if (formatter == null)
 			return null;
-		CSSSourceFormatter formatter = (CSSSourceFormatter) adapter;
 		StringBuffer buffer = formatter.format(document);
 		if (buffer == null)
 			return null;
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java
index 72e9916..37890b5 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/HTMLFormatter.java
@@ -110,7 +110,8 @@
 			if (next == null && element.getEndStructuredDocumentRegion() == null)
 				return false;
 
-			// insert line break under non-HTML elements including JSP elements
+			// insert line break under non-HTML elements including JSP
+			// elements
 			if (element.getPrefix() != null)
 				return true;
 
@@ -175,7 +176,8 @@
 			if (prev == null && element.getStartStructuredDocumentRegion() == null)
 				return false;
 
-			// insert line break under non-HTML elements including JSP elements
+			// insert line break under non-HTML elements including JSP
+			// elements
 			if (element.getPrefix() != null)
 				return true;
 
@@ -386,6 +388,10 @@
 			return;
 		if (node.getNodeType() == Node.TEXT_NODE)
 			return;
+		// don't insert break if node is on the last line
+		int documentLength = node.getStructuredDocument().getLength();
+		if (documentLength < 1 || (node.getEndOffset() >= (documentLength - 1)))
+			return;
 		Node parent = node.getParentNode();
 		if (parent == null)
 			return;
@@ -482,9 +488,11 @@
 		int startOffset = flatNode.getStartOffset();
 		if (structuredDocument.containsReadOnly(startOffset + offset, length))
 			return;
-		// We use 'structuredDocument' as the requester object just so this and the other
-		// format-related 'repalceText' (in replaceSource) can use the same requester.
-		// Otherwise, if requester is not identical, 
+		// We use 'structuredDocument' as the requester object just so this
+		// and the other
+		// format-related 'repalceText' (in replaceSource) can use the same
+		// requester.
+		// Otherwise, if requester is not identical,
 		// the undo group gets "broken" into multiple pieces based
 		// on the requesters being different. Technically, any unique, common
 		// requester object would work.
@@ -503,12 +511,14 @@
 			source = new String();
 		if (structuredDocument.containsReadOnly(offset, length))
 			return;
-		// We use 'structuredDocument' as the requester object just so this and the other
-		// format-related 'repalceText' (in replaceSource) can use the same requester.
-		// Otherwise, if requester is not identical, 
+		// We use 'structuredDocument' as the requester object just so this
+		// and the other
+		// format-related 'repalceText' (in replaceSource) can use the same
+		// requester.
+		// Otherwise, if requester is not identical,
 		// the undo group gets "broken" into multiple pieces based
 		// on the requesters being different. Technically, any unique, common
-		// requester object would work. 
+		// requester object would work.
 		structuredDocument.replaceText(structuredDocument, offset, length, source);
 	}
 
@@ -587,19 +597,19 @@
 	/**
 	 */
 	protected boolean splitLines() {
-		return true;//getFormatPreferences().getSplitLines();
+		return true;// getFormatPreferences().getSplitLines();
 	}
 
 	protected IStructuredFormatPreferences fFormatPreferences = null;
 	protected HTMLFormatContraints fFormatContraints = null;
 	protected IProgressMonitor fProgressMonitor = null;
 
-	//public void format(XMLNode node, FormatContraints formatContraints) {
-	//	if (formatContraints.getFormatWithSiblingIndent())
-	//		formatContraints.setCurrentIndent(getSiblingIndent(node));
+	// public void format(XMLNode node, FormatContraints formatContraints) {
+	// if (formatContraints.getFormatWithSiblingIndent())
+	// formatContraints.setCurrentIndent(getSiblingIndent(node));
 	//
-	//	formatNode(node, formatContraints);
-	//}
+	// formatNode(node, formatContraints);
+	// }
 
 	public void setFormatPreferences(IStructuredFormatPreferences formatPreferences) {
 		fFormatPreferences = formatPreferences;
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/SpaceConverter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/SpaceConverter.java
index a7b6f66..38f9203 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/SpaceConverter.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/format/SpaceConverter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 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
@@ -216,6 +216,8 @@
 			}
 			if (oldSpaces != null) {
 				spaces = mergeBlankLines(spaces, oldSpaces);
+				if (oldSpaces.equals(spaces))
+					return;
 			}
 		}