From 8d813e255bdbf4eb93f3c6fb0cfc141c347c2771 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Tue, 6 Mar 2007 22:03:43 +0000 Subject: [PATCH] M dist/mcp-test/src/test/java/cardemo/CarDemoTest.java - remove Robot from this class. Moved into MCP M dom/classes/org/mozilla/dom/DocumentImpl.java M dom/jni/org_mozilla_dom_DocumentImpl.cpp - implement getDocumentURI(). M dom/classes/org/mozilla/dom/util/DOMTreeDumper.java - added findElementWithName(). R webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java A dom/classes/org/mozilla/dom/util/DOMTreeModel.java R webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeNotifier.java A dom/classes/org/mozilla/dom/util/DOMTreeNotifier.java M webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java M webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java M webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMViewerFrame.java - Move these over from test browser package M webclient/classes_spec/org/mozilla/mcp/MCP.java - added useful new public methods findElement clickElement blockingClickElement - absorbed functionality of Robot. R webclient/classes_spec/org/mozilla/webclient/impl/DOMTreeDumper.java R webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeDumper.java - For some reason, there were several copies of this file. M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java - Use newly implemented getDocumentURI() for logging. --- .../src/test/java/cardemo/CarDemoTest.java | 18 +- .../classes/org/mozilla/dom/DocumentImpl.java | 5 +- .../org/mozilla/dom/util/DOMTreeDumper.java | 54 +++- .../org/mozilla/dom/util}/DOMTreeModel.java | 4 +- .../mozilla/dom/util}/DOMTreeNotifier.java | 4 +- java/dom/jni/org_mozilla_dom_DocumentImpl.cpp | 39 +++ .../classes_spec/org/mozilla/mcp/MCP.java | 113 +++++++-- .../mozilla/webclient/impl/DOMTreeDumper.java | 231 ------------------ .../impl/wrapper_native/CurrentPageImpl.java | 6 +- .../webclient/test/DOMAccessPanel.java | 1 + .../mozilla/webclient/test/DOMTreeDumper.java | 215 ---------------- .../mozilla/webclient/test/DOMTreeModel.java | 116 --------- .../webclient/test/DOMTreeNotifier.java | 43 ---- .../webclient/test/DOMViewerFrame.java | 3 +- .../webclient/test/DOMAccessPanel.java | 3 +- .../mozilla/webclient/test/DOMTreeDumper.java | 231 ------------------ .../webclient/test/DOMViewerFrame.java | 3 +- 17 files changed, 208 insertions(+), 881 deletions(-) rename java/{webclient/test/manual/src/classes/org/mozilla/webclient/test => dom/classes/org/mozilla/dom/util}/DOMTreeModel.java (97%) mode change 100644 => 100755 rename java/{webclient/test/manual/src/classes/org/mozilla/webclient/test => dom/classes/org/mozilla/dom/util}/DOMTreeNotifier.java (95%) mode change 100644 => 100755 delete mode 100644 java/webclient/classes_spec/org/mozilla/webclient/impl/DOMTreeDumper.java delete mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java delete mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java delete mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java delete mode 100644 java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeDumper.java diff --git a/java/dist/mcp-test/src/test/java/cardemo/CarDemoTest.java b/java/dist/mcp-test/src/test/java/cardemo/CarDemoTest.java index 0d073dd2e7ac..baf0080613d6 100755 --- a/java/dist/mcp-test/src/test/java/cardemo/CarDemoTest.java +++ b/java/dist/mcp-test/src/test/java/cardemo/CarDemoTest.java @@ -7,8 +7,6 @@ package cardemo; -import java.awt.Robot; -import java.awt.event.InputEvent; import org.mozilla.mcp.MCP; import org.mozilla.webclient.WebclientTestCase; import org.w3c.dom.Element; @@ -41,19 +39,9 @@ public class CarDemoTest extends WebclientTestCase { public void testCardemo() throws Exception { mcp.getRealizedVisibleBrowserWindow(); mcp.blockingLoad("http://webdev1.sun.com/jsf-ajax-cardemo/faces/chooseLocale.jsp"); - Element germanButton = mcp.getElementInCurrentPageById("j_id_id73:Germany"); - assertNotNull(germanButton); - String clientX = germanButton.getAttribute("clientX"); - String clientY = germanButton.getAttribute("clientY"); - assertNotNull(clientX); - assertNotNull(clientY); - int x = Integer.valueOf(clientX).intValue(); - int y = Integer.valueOf(clientY).intValue(); - Robot robot = new Robot(); - - robot.mouseMove(x, y); - robot.mousePress(InputEvent.BUTTON1_MASK); - robot.mouseRelease(InputEvent.BUTTON1_MASK); + mcp.blockingClickElement("j_id_id73:Germany"); + mcp.blockingClickElement("j_id_id18:j_id_id43"); + Thread.currentThread().sleep(30000); } diff --git a/java/dom/classes/org/mozilla/dom/DocumentImpl.java b/java/dom/classes/org/mozilla/dom/DocumentImpl.java index 2ca5c99af4ed..45e2a8dd78b4 100644 --- a/java/dom/classes/org/mozilla/dom/DocumentImpl.java +++ b/java/dom/classes/org/mozilla/dom/DocumentImpl.java @@ -62,6 +62,7 @@ public class DocumentImpl extends NodeImpl implements Document, DocumentEvent { public native Event createEvent(String type); public native NodeList getElementsByTagNameNS(String namespaceURI, String localName); public native Element getElementById(String elementId); + public native String getDocumentURI(); public Node importNode(Node importedNode, boolean deep) throws DOMException { throw new UnsupportedOperationException(); @@ -77,10 +78,6 @@ public class DocumentImpl extends NodeImpl implements Document, DocumentEvent { throw new UnsupportedOperationException(); } - public String getDocumentURI() { - throw new UnsupportedOperationException(); - } - public DOMConfiguration getDomConfig() { throw new UnsupportedOperationException(); } diff --git a/java/dom/classes/org/mozilla/dom/util/DOMTreeDumper.java b/java/dom/classes/org/mozilla/dom/util/DOMTreeDumper.java index 806a6d6cd05c..b6e0d123963a 100644 --- a/java/dom/classes/org/mozilla/dom/util/DOMTreeDumper.java +++ b/java/dom/classes/org/mozilla/dom/util/DOMTreeDumper.java @@ -20,12 +20,12 @@ package org.mozilla.dom.util; import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.FileOutputStream; import java.io.IOException; import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -222,6 +222,58 @@ public class DOMTreeDumper { dumpDocument(doc); dbg("finished dumping..."); } + + public String dump(Document doc) { + ByteArrayOutputStream baos = null; + baos = new ByteArrayOutputStream(1024); + ps = new PrintStream(baos); + + dbg("dumping to String"); + dumpDocument(doc); + dbg("finished dumping..."); + return baos.toString(); + } + + + private Element findElementWithName(Element start, String name) { + Element result = null; + Node child = null; + String elementName = start.getAttribute("name"); + if (null != elementName && elementName.equals(name)) { + return start; + } + else { + NodeList children = start.getChildNodes(); + int length = 0; + boolean hasChildren = ((children != null) && + ((length = children.getLength()) > 0)); + if (!hasChildren) { + return result; + } + for (int i=0; i < length; i++) { + child = children.item(i); + result = null; + if (child instanceof Element) { + result = findElementWithName((Element) child, name); + } + if (null != result) { + break; + } + } + } + + return result; + } + + public Element findFirstElementWithName(Document doc, String name) { + Element result = null; + result = doc.getDocumentElement(); + if (null != result) { + result.normalize(); + result = findElementWithName(result, name); + } + return result; + } private void dbg(String str) { if (debug) { diff --git a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeModel.java b/java/dom/classes/org/mozilla/dom/util/DOMTreeModel.java old mode 100644 new mode 100755 similarity index 97% rename from java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeModel.java rename to java/dom/classes/org/mozilla/dom/util/DOMTreeModel.java index ece09f8bf515..69a61a9efd15 --- a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeModel.java +++ b/java/dom/classes/org/mozilla/dom/util/DOMTreeModel.java @@ -19,7 +19,7 @@ * Louis-Philippe Gagnon */ -package org.mozilla.webclient.test; +package org.mozilla.dom.util; import javax.swing.tree.TreePath; import javax.swing.tree.TreeModel; @@ -30,7 +30,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.Vector; -class DOMTreeModel implements TreeModel, DOMTreeNotifier { +public class DOMTreeModel implements TreeModel, DOMTreeNotifier { private Node rootNode; private Vector treeModelListeners = new Vector(); diff --git a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeNotifier.java b/java/dom/classes/org/mozilla/dom/util/DOMTreeNotifier.java old mode 100644 new mode 100755 similarity index 95% rename from java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeNotifier.java rename to java/dom/classes/org/mozilla/dom/util/DOMTreeNotifier.java index 20f3095b4f54..881f348d839b --- a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeNotifier.java +++ b/java/dom/classes/org/mozilla/dom/util/DOMTreeNotifier.java @@ -16,11 +16,11 @@ * Contributor(s): Igor Kushnirskiy */ -package org.mozilla.webclient.test; +package org.mozilla.dom.util; import javax.swing.event.TreeModelEvent; -interface DOMTreeNotifier { +public interface DOMTreeNotifier { /* * Invoked after a node (or a set of siblings) has changed in some way. */ diff --git a/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp b/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp index ef6e4f20f680..643b0a4067c1 100644 --- a/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp +++ b/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp @@ -20,7 +20,9 @@ */ #include "prlog.h" +#include "nsCOMPtr.h" #include "nsIDOMDocument.h" +#include "nsIDOM3Document.h" #include "nsIDOMAttr.h" #include "nsIDOMComment.h" #include "nsIDOMElement.h" @@ -757,3 +759,40 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getElementById return JavaDOMGlobals::CreateNodeSubtype(env, (nsIDOMNode*)element); } + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getDocumentURI + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_DocumentImpl_getDocumentURI + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + jstring result = nsnull; + nsresult rv = NS_OK; + + nsCOMPtr dom3 = do_QueryInterface(doc, &rv); + if (NS_FAILED(rv) || !dom3) { + JavaDOMGlobals::ThrowException(env, + "Document.getDocumentURI: failed", rv); + return result; + } + nsString ret; + rv = dom3->GetDocumentURI(ret); + if (NS_FAILED(rv)) { + JavaDOMGlobals::ThrowException(env, + "Document.getDocumentURI: failed", rv); + return result; + } + result = env->NewString((jchar*) ret.get(), ret.Length()); + if (!result) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDocumentURI: NewString failed\n")); + } + + return result; + + +} diff --git a/java/webclient/classes_spec/org/mozilla/mcp/MCP.java b/java/webclient/classes_spec/org/mozilla/mcp/MCP.java index 52e607aa8000..4a26f0fe12d1 100755 --- a/java/webclient/classes_spec/org/mozilla/mcp/MCP.java +++ b/java/webclient/classes_spec/org/mozilla/mcp/MCP.java @@ -9,12 +9,16 @@ package org.mozilla.mcp; +import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Frame; +import java.awt.Robot; +import java.awt.event.InputEvent; import java.io.FileNotFoundException; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import org.mozilla.dom.util.DOMTreeDumper; import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.BrowserControlCanvas; import org.mozilla.webclient.BrowserControlFactory; @@ -50,13 +54,14 @@ public class MCP { private Navigation2 navigation = null; private EventRegistration2 eventRegistration = null; private PageInfoListener pageInfoListener = null; - private CurrentPage2 currentPage = null; private Frame frame = null; private int x = 0; private int y = 0; private int width = 1280; private int height = 960; private boolean initialized = false; + private Robot robot; + private DOMTreeDumper treeDumper = null; public void setAppData(String absolutePathToNativeBrowserBinDir) throws FileNotFoundException, @@ -65,7 +70,14 @@ public class MCP { initialized = true; } - void setBounds(int x, int y, int width, int height) { + private DOMTreeDumper getDOMTreeDumper() { + if (null == treeDumper) { + treeDumper = new DOMTreeDumper("MCP", false); + } + return treeDumper; + } + + public void setBounds(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; @@ -108,20 +120,20 @@ public class MCP { } private CurrentPage2 getCurrentPage() { - if (null == currentPage) { - try { - currentPage = (CurrentPage2) - getBrowserControl().queryInterface(BrowserControl.CURRENT_PAGE_NAME); - } - catch (Throwable th) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.throwing(this.getClass().getName(), "getCurrentPage", - th); - LOGGER.severe("Unable to obtain CurrentPage2 reference from BrowserControl"); - } - } - + CurrentPage2 currentPage = null; + + try { + currentPage = (CurrentPage2) + getBrowserControl().queryInterface(BrowserControl.CURRENT_PAGE_NAME); } + catch (Throwable th) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getCurrentPage", + th); + LOGGER.severe("Unable to obtain CurrentPage2 reference from BrowserControl"); + } + } + return currentPage; } @@ -184,14 +196,68 @@ public class MCP { return frame; } - public Element getElementInCurrentPageById(String id) { + public Element findElement(String id) { Element result = null; Document dom = getCurrentPage().getDOM(); - result = dom.getElementById(id); + try { + result = dom.getElementById(id); + } + catch (Exception e) { + + } + if (null == result) { + result = getDOMTreeDumper().findFirstElementWithName(dom, id); + } return result; } + public void clickElement(String id) { + Element element = findElement(id); + String clientX = null, clientY = null; + if (null != element) { + clientX = element.getAttribute("clientX"); + clientY = element.getAttribute("clientY"); + int x,y; + if (null != clientX && null != clientY) { + try { + x = Integer.valueOf(clientX).intValue(); + y = Integer.valueOf(clientY).intValue(); + Robot robot = getRobot(); + robot.mouseMove(x, y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + } catch (NumberFormatException ex) { + LOGGER.throwing(this.getClass().getName(), "clickElementGivenId", + ex); + ex.printStackTrace(); + throw new IllegalStateException(ex); + } + } + } + if (null == element || null == clientX || null == clientY) { + throw new IllegalStateException("Unable to click element " + id); + } + } + + public void blockingClickElement(String idOrName) { + synchronized (this) { + try { + clickElement(idOrName); + this.wait(); + } + catch (IllegalStateException ise) { + LOGGER.throwing(this.getClass().getName(), "blockingClickElementGivenId", + ise); + } + catch (InterruptedException ie) { + LOGGER.throwing(this.getClass().getName(), "blockingClickElementGivenId", + ie); + } + } + } + public void blockingLoad(String url) { Navigation2 nav = getNavigation(); synchronized (this) { @@ -206,6 +272,19 @@ public class MCP { } } + private Robot getRobot() { + if (null == robot) { + try { + robot = new Robot(); + } catch (AWTException ex) { + LOGGER.throwing(this.getClass().getName(), "getRobot", + ex); + ex.printStackTrace(); + } + } + return robot; + } + private class PageInfoListenerImpl implements PageInfoListener { private MCP owner = null; PageInfoListenerImpl(MCP owner) { diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/DOMTreeDumper.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/DOMTreeDumper.java deleted file mode 100644 index 6fc8607c996b..000000000000 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/DOMTreeDumper.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. - * - * The Initial Developer of the Original Code is Sun Microsystems, - * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, - * Inc. All Rights Reserved. - * - * Contributor(s): Denis Sharypov - * - */ - -package org.mozilla.webclient.impl; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class DOMTreeDumper { - - private String prefix = "DOMTreeDumper"; - private boolean debug; - private PrintStream ps; - private boolean inA; - private final String[] endTagForbiddenNames = {"AREA", - "BASE", - "BASEFONT", - "BR", - "COL", - "FRAME", - "HR", - "IMG", - "INPUT", - "ISINDEX", - "LINK", - "META", - "PARAM"}; - - public DOMTreeDumper() { - this(true); - } - - public DOMTreeDumper(boolean debug) { - this.debug = debug; - } - - private void dumpDocument(Document doc) { - if (doc == null) return; - Element element = doc.getDocumentElement(); - if (element == null) return; - element.normalize(); -// DocumentType dt = doc.getDoctype(); -// dumpNode(dt); - - dumpNode(element); - ps.println(); - ps.flush(); - - element = null; - doc = null; - } - - private void dumpNode(Node node) { - dumpNode(node, false); - } - - private void dumpNode(Node 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(">"); - dumpChildren(node); - if (name.equals("A")) inA = false; - if (!endTagForbidden(name)) { - ps.print(""); - } - break; - case Node.ATTRIBUTE_NODE: - ps.print(" " + name.toUpperCase() + "=\"" + value + "\""); - 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)); - } - break; - case Node.COMMENT_NODE: - ps.print("\n"); - 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"); - break; - } - } - - private void dumpAttributes(Node node) { - NamedNodeMap map = node.getAttributes(); - if (map == null) return; - int length = map.getLength(); - for (int i=0; i < length; i++) { - Node item = map.item(i); - dumpNode(item, true); - } - } - - private void dumpChildren(Node node) { - NodeList children = node.getChildNodes(); - int length = 0; - boolean hasChildren = ((children != null) && ((length = children.getLength()) > 0)); - if (!hasChildren) { - return; - } - for (int i=0; i < length; i++) { - dumpNode(children.item(i), false); - } - 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; - } - - public void dumpToFile(String fileName, Document doc) { - try { - FileOutputStream fos = new FileOutputStream(fileName); - ps = new PrintStream(new BufferedOutputStream(fos, 1024)); - } catch (IOException ex) { - ex.printStackTrace(); - return; - } - dbg("dumping to " + fileName); - dumpDocument(doc); - dbg("finished dumping..."); - } - - public String dump(Document doc) { - ByteArrayOutputStream baos = null; - baos = new ByteArrayOutputStream(1024); - ps = new PrintStream(baos); - - dbg("dumping to String"); - dumpDocument(doc); - dbg("finished dumping..."); - return baos.toString(); - } - - - - - - private void dbg(String str) { - if (debug) { - System.out.println(prefix + ": " + str); - } - } -} diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java index 21356696c3c9..7073b1f4ae4d 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java @@ -34,7 +34,6 @@ import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.CurrentPage2; import org.mozilla.webclient.Selection; import org.mozilla.webclient.impl.WrapperFactory; -import org.mozilla.webclient.impl.DOMTreeDumper; import java.util.Properties; import java.util.logging.Level; @@ -46,6 +45,7 @@ import org.w3c.dom.Node; import org.mozilla.webclient.UnimplementedException; import org.mozilla.dom.DOMAccessor; +import org.mozilla.dom.util.DOMTreeDumper; import org.mozilla.util.Log; public class CurrentPageImpl extends ImplObjectNative implements CurrentPage2, @@ -297,6 +297,10 @@ public Document getDOM() { // PENDING(edburns): run this on the event thread. Document result = nativeGetDOM(getNativeBrowserControl()); + if (LOGGER.isLoggable((Level.INFO))) { + LOGGER.info("CurrentPageImpl.getDOM(): getting DOM with URI: " + + result.getDocumentURI()); + } return result; } diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java index f512bf4c99d8..874028a61b39 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java @@ -21,6 +21,7 @@ package org.mozilla.webclient.test; import java.awt.*; import java.awt.event.*; +import org.mozilla.dom.util.DOMTreeNotifier; import org.w3c.dom.*; import org.mozilla.dom.*; import javax.swing.*; diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java deleted file mode 100644 index 119bcef2de46..000000000000 --- a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. - * - * The Initial Developer of the Original Code is Sun Microsystems, - * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, - * Inc. All Rights Reserved. - * - * Contributor(s): Denis Sharypov - * - */ - -package org.mozilla.webclient.test; - -import java.io.BufferedOutputStream; -import java.io.PrintStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class DOMTreeDumper { - - private String prefix = "DOMTreeDumper"; - private boolean debug; - private PrintStream ps; - private boolean inA; - private final String[] endTagForbiddenNames = {"AREA", - "BASE", - "BASEFONT", - "BR", - "COL", - "FRAME", - "HR", - "IMG", - "INPUT", - "ISINDEX", - "LINK", - "META", - "PARAM"}; - - DOMTreeDumper() { - this(true); - } - - DOMTreeDumper(boolean debug) { - this.debug = debug; - } - - private void dumpDocument(Document doc) { - if (doc == null) return; - Element element = doc.getDocumentElement(); - if (element == null) return; - element.normalize(); -// DocumentType dt = doc.getDoctype(); -// dumpNode(dt); - - dumpNode(element); - ps.println(); - ps.flush(); - - element = null; - doc = null; - } - - private void dumpNode(Node node) { - dumpNode(node, false); - } - - private void dumpNode(Node 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(">"); - dumpChildren(node); - if (name.equals("A")) inA = false; - if (!endTagForbidden(name)) { - ps.print(""); - } - break; - case Node.ATTRIBUTE_NODE: - ps.print(" " + name.toUpperCase() + "=\"" + value + "\""); - 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)); - } - break; - case Node.COMMENT_NODE: - ps.print("\n"); - 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"); - break; - } - } - - private void dumpAttributes(Node node) { - NamedNodeMap map = node.getAttributes(); - if (map == null) return; - int length = map.getLength(); - for (int i=0; i < length; i++) { - Node item = map.item(i); - dumpNode(item, true); - } - } - - private void dumpChildren(Node node) { - NodeList children = node.getChildNodes(); - int length = 0; - boolean hasChildren = ((children != null) && ((length = children.getLength()) > 0)); - if (!hasChildren) { - return; - } - for (int i=0; i < length; i++) { - dumpNode(children.item(i), false); - } - 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; - } - - public void dumpToFile(String fileName, Document doc) { - try { - FileOutputStream fos = new FileOutputStream(fileName); - ps = new PrintStream(new BufferedOutputStream(fos, 1024)); - } catch (IOException ex) { - ex.printStackTrace(); - return; - } - dbg("dumping to " + fileName); - dumpDocument(doc); - dbg("finished dumping..."); - } - - private void dbg(String str) { - if (debug) { - System.out.println(prefix + ": " + str); - } - } -} diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java deleted file mode 100644 index ece09f8bf515..000000000000 --- a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. - * - * The Initial Developer of the Original Code is Sun Microsystems, - * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, - * Inc. All Rights Reserved. - * - * Contributor(s): Igor Kushnirskiy - * Ed Burns - * Jason Mawdsley - * Louis-Philippe Gagnon - */ - -package org.mozilla.webclient.test; - -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeModel; -import javax.swing.event.TreeModelEvent; -import javax.swing.event.TreeModelListener; - -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import java.util.Vector; - -class DOMTreeModel implements TreeModel, DOMTreeNotifier { - private Node rootNode; - private Vector treeModelListeners = new Vector(); - - public DOMTreeModel(Node node) { - rootNode = node; - } - public void addTreeModelListener(TreeModelListener l) { - // use addElement instead of add for jdk1.1.x compatibility. - treeModelListeners.addElement(l); - } - public void removeTreeModelListener(TreeModelListener l) { - treeModelListeners.removeElement(l); - } - public Object getChild(Object parent, int index) { - return ((Node)parent).getChildNodes().item(index); - } - public int getChildCount(Object parent) { - return ((Node)parent).getChildNodes().getLength(); - } - public int getIndexOfChild(Object parent, Object child) { - NodeList childNodes = ((Node)parent).getChildNodes(); - int res = -1; - int length = childNodes.getLength(); - for (int i = 0; i < length; i++) { - if (childNodes.item(i) == child) { - res = i; - break; - } - } - return res; - - } - public Object getRoot() { - return rootNode; - } - public boolean isLeaf(Object node) { - return getChildCount(node) == 0; - } - - public void valueForPathChanged(TreePath path, Object newValue) { - return; - } - - - /* - * Invoked after a node (or a set of siblings) has changed in some way. - */ - public void treeNodesChanged(TreeModelEvent e) { - for (int i = 0; i < treeModelListeners.size() ; i++) { - ((TreeModelListener)treeModelListeners.elementAt(i)). - treeNodesChanged(e); - } - } - - /* - * Invoked after nodes have been inserted into the tree. - */ - public void treeNodesInserted(TreeModelEvent e) { - for (int i = 0; i < treeModelListeners.size(); i++) { - ((TreeModelListener)treeModelListeners.elementAt(i)). - treeNodesInserted(e); - } - } - - /* - * Invoked after nodes have been removed from the tree. - */ - public void treeNodesRemoved(TreeModelEvent e) { - for (int i = 0; i < treeModelListeners.size(); i++) { - ((TreeModelListener)treeModelListeners.elementAt(i)). - treeNodesRemoved(e); - } - } - /* - * Invoked after the tree has drastically changed structure from a given node down. - */ - public void treeStructureChanged(TreeModelEvent e) { - for (int i = 0; i < treeModelListeners.size(); i++) { - ((TreeModelListener)treeModelListeners.elementAt(i)). - treeStructureChanged(e); - } - } -} diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java deleted file mode 100644 index 20f3095b4f54..000000000000 --- a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. - * - * The Initial Developer of the Original Code is Sun Microsystems, - * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, - * Inc. All Rights Reserved. - * - * Contributor(s): Igor Kushnirskiy - */ - -package org.mozilla.webclient.test; - -import javax.swing.event.TreeModelEvent; - -interface DOMTreeNotifier { - /* - * Invoked after a node (or a set of siblings) has changed in some way. - */ - public void treeNodesChanged(TreeModelEvent e); - - /* - * Invoked after nodes have been inserted into the tree. - */ - public void treeNodesInserted(TreeModelEvent e); - - /* - * Invoked after nodes have been removed from the tree. - */ - public void treeNodesRemoved(TreeModelEvent e); - /* - * Invoked after the tree has drastically changed structure from a given node down. - */ - public void treeStructureChanged(TreeModelEvent e); -}; - diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java index ee218639d917..b9f9bc977112 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java @@ -27,6 +27,7 @@ package org.mozilla.webclient.test; +import org.mozilla.dom.util.DOMTreeModel; import org.mozilla.util.Assert; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -57,7 +58,7 @@ import java.util.Stack; * A dom viewer Frame * - * @version $Id: DOMViewerFrame.java,v 1.7 2001/04/03 01:37:28 edburns%acm.org Exp $ + * @version $Id: DOMViewerFrame.java,v 1.8 2007/03/06 22:03:43 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory diff --git a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMAccessPanel.java b/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMAccessPanel.java index c1257698204a..573b1448f2cd 100644 --- a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMAccessPanel.java +++ b/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMAccessPanel.java @@ -21,8 +21,9 @@ package org.mozilla.webclient.test; import java.awt.*; import java.awt.event.*; +import org.mozilla.dom.util.DOMTreeNotifier; +import org.mozilla.dom.util.DOMTreeDumper; import org.w3c.dom.*; -import org.mozilla.dom.*; import javax.swing.*; import javax.swing.tree.*; //idk import javax.swing.border.*; diff --git a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeDumper.java b/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeDumper.java deleted file mode 100644 index a848c616848b..000000000000 --- a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMTreeDumper.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. - * - * The Initial Developer of the Original Code is Sun Microsystems, - * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, - * Inc. All Rights Reserved. - * - * Contributor(s): Denis Sharypov - * - */ - -package org.mozilla.webclient.test; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class DOMTreeDumper { - - private String prefix = "DOMTreeDumper"; - private boolean debug; - private PrintStream ps; - private boolean inA; - private final String[] endTagForbiddenNames = {"AREA", - "BASE", - "BASEFONT", - "BR", - "COL", - "FRAME", - "HR", - "IMG", - "INPUT", - "ISINDEX", - "LINK", - "META", - "PARAM"}; - - DOMTreeDumper() { - this(true); - } - - DOMTreeDumper(boolean debug) { - this.debug = debug; - } - - private void dumpDocument(Document doc) { - if (doc == null) return; - Element element = doc.getDocumentElement(); - if (element == null) return; - element.normalize(); -// DocumentType dt = doc.getDoctype(); -// dumpNode(dt); - - dumpNode(element); - ps.println(); - ps.flush(); - - element = null; - doc = null; - } - - private void dumpNode(Node node) { - dumpNode(node, false); - } - - private void dumpNode(Node 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(">"); - dumpChildren(node); - if (name.equals("A")) inA = false; - if (!endTagForbidden(name)) { - ps.print(""); - } - break; - case Node.ATTRIBUTE_NODE: - ps.print(" " + name.toUpperCase() + "=\"" + value + "\""); - 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)); - } - break; - case Node.COMMENT_NODE: - ps.print("\n"); - 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"); - break; - } - } - - private void dumpAttributes(Node node) { - NamedNodeMap map = node.getAttributes(); - if (map == null) return; - int length = map.getLength(); - for (int i=0; i < length; i++) { - Node item = map.item(i); - dumpNode(item, true); - } - } - - private void dumpChildren(Node node) { - NodeList children = node.getChildNodes(); - int length = 0; - boolean hasChildren = ((children != null) && ((length = children.getLength()) > 0)); - if (!hasChildren) { - return; - } - for (int i=0; i < length; i++) { - dumpNode(children.item(i), false); - } - 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; - } - - public void dumpToFile(String fileName, Document doc) { - try { - FileOutputStream fos = new FileOutputStream(fileName); - ps = new PrintStream(new BufferedOutputStream(fos, 1024)); - } catch (IOException ex) { - ex.printStackTrace(); - return; - } - dbg("dumping to " + fileName); - dumpDocument(doc); - dbg("finished dumping..."); - } - - public String dump(Document doc) { - ByteArrayOutputStream baos = null; - baos = new ByteArrayOutputStream(1024); - ps = new PrintStream(baos); - - dbg("dumping to String"); - dumpDocument(doc); - dbg("finished dumping..."); - return baos.toString(); - } - - - - - - private void dbg(String str) { - if (debug) { - System.out.println(prefix + ": " + str); - } - } -} diff --git a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMViewerFrame.java b/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMViewerFrame.java index fa0c5772aa34..6c4ae5c4d68f 100644 --- a/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMViewerFrame.java +++ b/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/DOMViewerFrame.java @@ -27,6 +27,7 @@ package org.mozilla.webclient.test; +import org.mozilla.dom.util.DOMTreeModel; import org.mozilla.util.Assert; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -57,7 +58,7 @@ import java.util.Stack; * A dom viewer Frame * - * @version $Id: DOMViewerFrame.java,v 1.1 2005/04/17 20:19:46 edburns%acm.org Exp $ + * @version $Id: DOMViewerFrame.java,v 1.2 2007/03/06 22:03:43 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory