Author: ezheleznyakov
Date: 2007-09-27 09:41:53 -0400 (Thu, 27 Sep 2007)
New Revision: 3862
Added:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/util/
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/util/DOMTreeDumper.java
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/META-INF/MANIFEST.MF
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeAttributeOperand.java
Log:
Add dump source feature, and little fix with html tag <img/>.
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2007-09-27
13:09:20 UTC (rev 3861)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2007-09-27
13:41:53 UTC (rev 3862)
@@ -122,10 +122,10 @@
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
-import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.selbar.SelectionBar;
+import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
@@ -1056,10 +1056,9 @@
if (VpeDebug.visualContextMenuDumpSource) {
manager.add(new Action("Dump Source") { //$NON-NLS-1$
- public void run() {
- throw new RuntimeException("Not Implemented");
-// DOMTreeDumper dumper = new DOMTreeDumper();
-// dumper.dumpToStream(System.out, visualEditor.getDomDocument());
+ public void run() {
+ DOMTreeDumper dumper = new DOMTreeDumper();
+ dumper.dumpToStream(System.out, visualEditor.getDomDocument());
}
});
}
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeAttributeOperand.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeAttributeOperand.java 2007-09-27
13:09:20 UTC (rev 3861)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/expression/VpeAttributeOperand.java 2007-09-27
13:41:53 UTC (rev 3862)
@@ -17,11 +17,9 @@
public class VpeAttributeOperand extends VpeOperand {
private String name;
- private boolean caseSensitive;
VpeAttributeOperand(String name, boolean caseSensitive) {
this.name = name;
- this.caseSensitive = caseSensitive;
}
int getPriority() {
@@ -33,8 +31,8 @@
try {
value = ((Element)sourceNode).getAttribute(name);
- if (!caseSensitive) {
- value = (value == null ? "" : value.toLowerCase());
+ if (value == null) {
+ value = "";
}
} catch (Exception e) {
// throw new VpeExpressionError(x.getMessage());
@@ -46,4 +44,4 @@
public String getAttributeName() {
return name;
}
-}
+}
\ No newline at end of file
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/META-INF/MANIFEST.MF
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/META-INF/MANIFEST.MF 2007-09-27
13:09:20 UTC (rev 3861)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/META-INF/MANIFEST.MF 2007-09-27
13:41:53 UTC (rev 3862)
@@ -12,6 +12,7 @@
Eclipse-LazyStart: true
Export-Package:
org.jboss.tools.vpe.xulrunner;uses:="org.eclipse.jface.resource,org.eclipse.ui.plugin,org.osgi.framework",
org.jboss.tools.vpe.xulrunner.browser;uses:="org.mozilla.interfaces,org.eclipse.swt.widgets,org.mozilla.xpcom",
+ org.jboss.tools.vpe.xulrunner.browser.util,
org.jboss.tools.vpe.xulrunner.editor
Bundle-ClassPath: .
Bundle-Vendor: Red Hat, Inc.
Added:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/util/DOMTreeDumper.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/util/DOMTreeDumper.java
(rev 0)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/util/DOMTreeDumper.java 2007-09-27
13:41:53 UTC (rev 3862)
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.xulrunner.browser.util;
+
+import java.io.PrintStream;
+
+import org.mozilla.interfaces.nsIDOMAttr;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNamedNodeMap;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class DOMTreeDumper {
+ private PrintStream ps;
+ private boolean inA;
+ private final String[] endTagForbiddenNames = {"AREA",
+ "BASE",
+ "BASEFONT",
+ "BR",
+ "COL",
+ "FRAME",
+ "HR",
+ "IMG",
+ "INPUT",
+ "ISINDEX",
+ "LINK",
+ "META",
+ "PARAM"};
+
+ public void dumpToStream(PrintStream ps, nsIDOMDocument doc) {
+ this.ps = ps;
+ dumpDocument(doc);
+ }
+
+ private void dumpDocument(nsIDOMDocument doc) {
+ if (doc == null) {
+ return;
+ }
+ nsIDOMElement element = doc.getDocumentElement();
+ if (element == null) return;
+
+ dumpNode((nsIDOMNode)element.queryInterface(nsIDOMNode.NS_IDOMNODE_IID));
+ ps.println();
+ ps.flush();
+
+ element = null;
+ doc = null;
+ }
+
+ private void dumpNode(nsIDOMNode node) {
+ dumpNode(node, false);
+ }
+
+ private void dumpNode(nsIDOMNode node, boolean isMapNode) {
+ if (node == null) {
+ return;
+ }
+
+ int type = node.getNodeType();
+ String name = node.getNodeName();
+ String value = node.getNodeValue();
+
+ switch (type) {
+ case Node.ELEMENT_NODE:
+ if (name.equals("A")) {
+ inA = true;
+ }
+ if (!(inA || name.equals("BR"))) {
+ ps.println();
+ }
+ ps.print("<" + name);
+ dumpAttributes(node);
+ ps.print(">(" + node.hashCode() + ")");
+ dumpChildren(node);
+ if (name.equals("A")) {
+ inA = false;
+ }
+ if (!endTagForbidden(name)) {
+ ps.print("</" + name + ">");
+ }
+ break;
+
+ case Node.ATTRIBUTE_NODE:
+ nsIDOMAttr attr = (nsIDOMAttr) node.queryInterface(nsIDOMAttr.NS_IDOMATTR_IID);
+ if (attr.getSpecified()) {
+ ps.print(" " + attr.getName().toUpperCase() + "=\"" +
attr.getValue() + "\"");
+ } else {
+ ps.print(" " + attr.getName().toUpperCase());
+ }
+ break;
+
+ case Node.TEXT_NODE:
+ if (!node.getParentNode().getNodeName().equals("PRE")) {
+ value = value.trim();
+ }
+ if (!value.equals("")) {
+ if (!inA) {
+ ps.println();
+ }
+ ps.print(canonicalize(value));
+ }
+ ps.print("(" + node.hashCode() + ")");
+ break;
+ case Node.COMMENT_NODE:
+ ps.print("\n<!--" + value + "-->");
+ break;
+ case Node.CDATA_SECTION_NODE:
+ case Node.ENTITY_REFERENCE_NODE:
+ case Node.ENTITY_NODE:
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ case Node.DOCUMENT_NODE:
+ case Node.DOCUMENT_TYPE_NODE:
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ case Node.NOTATION_NODE:
+ ps.println("\n<!-- NOT HANDLED: " + name +
+ " value=" + value + " -->");
+ break;
+ }
+ }
+
+ private void dumpAttributes(nsIDOMNode node) {
+ nsIDOMNamedNodeMap map = node.getAttributes();
+ if (map == null) {
+ return;
+ }
+ long length = map.getLength();
+ for (int i=0; i < length; i++) {
+ dumpNode(map.item(i), true);
+ }
+ }
+
+ private void dumpChildren(nsIDOMNode node) {
+ nsIDOMNodeList children = node.getChildNodes();
+ if (children == null) {
+ return;
+ }
+ long length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ dumpNode(children.item(i));
+ }
+ if (!inA) {
+ ps.println();
+ }
+ }
+
+ private String canonicalize(String str) {
+ StringBuffer in = new StringBuffer(str);
+ int length = in.length();
+ StringBuffer out = new StringBuffer(length);
+ char c;
+ for (int i = 0; i < length; i++) {
+ switch (c = in.charAt(i)) {
+ case '&' :
+ out.append("&");
+ break;
+ case '<':
+ out.append("<");
+ break;
+ case '>':
+ out.append(">");
+ break;
+ case '\u00A0':
+ out.append(" ");
+ break;
+ default:
+ out.append(c);
+ }
+ }
+ return out.toString();
+ }
+
+ private boolean endTagForbidden(String name) {
+ for (int i = 0; i < endTagForbiddenNames.length; i++) {
+ if (name.equals(endTagForbiddenNames[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file