Author: akazakov
Date: 2007-08-22 08:42:07 -0400 (Wed, 22 Aug 2007)
New Revision: 3271
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLExtendedElementFormatter.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLFormatProcessor.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ExtendedStructuredTextViewerConfigurationHTML.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-801
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ExtendedStructuredTextViewerConfigurationHTML.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ExtendedStructuredTextViewerConfigurationHTML.java 2007-08-22
12:17:17 UTC (rev 3270)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ExtendedStructuredTextViewerConfigurationHTML.java 2007-08-22
12:42:07 UTC (rev 3271)
@@ -18,6 +18,8 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jst.jsp.core.text.IJSPPartitions;
@@ -25,12 +27,12 @@
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.wst.html.core.text.IHTMLPartitions;
import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
-import org.osgi.framework.Bundle;
-
-import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.eclipse.wst.sse.ui.internal.format.StructuredFormattingStrategy;
import org.jboss.tools.common.text.xml.contentassist.ContentAssistProcessorBuilder;
import org.jboss.tools.common.text.xml.contentassist.ContentAssistProcessorDefinition;
import org.jboss.tools.jst.jsp.contentassist.RedHatHtmlContentAssistProcessor;
+import org.jboss.tools.jst.jsp.format.HTMLFormatProcessor;
+import org.osgi.framework.Bundle;
public class ExtendedStructuredTextViewerConfigurationHTML extends
StructuredTextViewerConfigurationHTML {
@@ -130,4 +132,14 @@
}
return result;
}
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML#getContentFormatter(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+ MultiPassContentFormatter formatter = new
MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer),
IHTMLPartitions.HTML_DEFAULT);
+ formatter.setMasterStrategy(new StructuredFormattingStrategy(new
HTMLFormatProcessor()));
+ return formatter;
+ }
}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLExtendedElementFormatter.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLExtendedElementFormatter.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLExtendedElementFormatter.java 2007-08-22
12:42:07 UTC (rev 3271)
@@ -0,0 +1,90 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.format;
+
+import java.util.ArrayList;
+
+import org.eclipse.wst.html.core.internal.format.HTMLElementFormatter;
+import org.eclipse.wst.html.core.internal.provisional.HTMLFormatContraints;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Formatter for html elements
+ * Extends HTMLElementFormatter but doesn't format EL
+ * @author Alexey Kazakov
+ */
+public class HTMLExtendedElementFormatter extends HTMLElementFormatter {
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.html.core.internal.format.HTMLElementFormatter#formatNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode,
org.eclipse.wst.html.core.internal.provisional.HTMLFormatContraints)
+ */
+ protected void formatNode(IDOMNode node, HTMLFormatContraints contraints) {
+ if (node == null) {
+ return;
+ }
+ IDOMElement element = (IDOMElement) node;
+ String oldStyleValue = null;
+ Attr style = element.getAttributeNode("style");//$NON-NLS-1$
+ if (style != null) {
+ oldStyleValue = style.getValue();
+ }
+ super.formatNode(node, contraints);
+ if(oldStyleValue!=null && oldStyleValue.indexOf("#{")>-1) {
+ style.setValue(oldStyleValue);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.html.core.internal.format.HTMLFormatter#formatChildNodes(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode,
org.eclipse.wst.html.core.internal.provisional.HTMLFormatContraints)
+ */
+ protected void formatChildNodes(IDOMNode node, HTMLFormatContraints contraints) {
+ if (node == null || !node.hasChildNodes()) {
+ return;
+ }
+ ArrayList<Attr> styles = new ArrayList<Attr>();
+ ArrayList<String> oldValues = new ArrayList<String>();
+ collectAllStyleAttributesOfNodeChildren(node, styles, oldValues);
+ super.formatChildNodes(node, contraints);
+ for(int i=0; i<styles.size(); i++) {
+ Attr style = styles.get(i);
+ String oldValue = oldValues.get(i);
+ style.setNodeValue(oldValue);
+ }
+ }
+
+ private void collectAllStyleAttributesOfNodeChildren(Node node, ArrayList<Attr>
styles, ArrayList<String> oldValues) {
+ if (!node.hasChildNodes()) {
+ return;
+ }
+ NodeList children = node.getChildNodes();
+ for(int i=0; i<children.getLength(); i++) {
+ Node child = children.item(i);
+ if(child instanceof Element) {
+ Attr style = ((Element)child).getAttributeNode("style");
+ if(style!=null) {
+ String value = style.getValue();
+ if(value.indexOf("#{")>-1) {
+ styles.add(style);
+ oldValues.add(value);
+ }
+ }
+ }
+ collectAllStyleAttributesOfNodeChildren(child, styles, oldValues);
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLFormatProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLFormatProcessor.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/format/HTMLFormatProcessor.java 2007-08-22
12:42:07 UTC (rev 3271)
@@ -0,0 +1,36 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.format;
+
+import org.eclipse.wst.html.core.internal.format.HTMLElementFormatter;
+import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl;
+import org.eclipse.wst.sse.core.internal.format.IStructuredFormatter;
+import org.w3c.dom.Node;
+
+/**
+ * This Processor formats HTML.
+ * @author Alexey Kazakov
+ */
+public class HTMLFormatProcessor extends HTMLFormatProcessorImpl {
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl#getFormatter(org.w3c.dom.Node)
+ */
+ protected IStructuredFormatter getFormatter(Node node) {
+ IStructuredFormatter formatter = super.getFormatter(node);
+ if(formatter instanceof HTMLElementFormatter) {
+ formatter = new HTMLExtendedElementFormatter();
+ formatter.setFormatPreferences(getFormatPreferences());
+ }
+ return formatter;
+ }
+}
\ No newline at end of file