bug 40330
a=edburns r=drapeau This checkin creates a dependency on the mozilla java dom module. Please see mozilla\java\dom\README to build the java dom. Note that you can just run make in mozilla\java and everything should be built correctly. A webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java A webclient/classes_spec/org/mozilla/webclient/test/DOMCellRenderer.java A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java A webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java M Makefile.win M README M webclient/classes_spec/Makefile.unix M webclient/classes_spec/Makefile.win M webclient/classes_spec/org/mozilla/webclient/CurrentPage.java M webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java M webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java M webclient/src_moz/CurrentPageImpl.cpp M webclient/src_moz/DocumentLoaderObserverImpl.cpp M webclient/src_moz/Makefile.win M webclient/src_moz/WindowControlImpl.cpp M webclient/src_moz/jni_util.h git-svn-id: svn://10.0.0.236/trunk@71490 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -7,7 +7,7 @@ JAVAC = ${JDK_LOCATION}/bin/javac
|
||||
JAVAH = ${JDK_LOCATION}/bin/javah
|
||||
OUTPUT_DIR = ../../../dist/classes
|
||||
# If you're using JDK 1.2
|
||||
CLASSES = ${OUTPUT_DIR}:${JDK_LOCATION}/lib/tools.jar:${JDK_LOCATION}/lib/rt.jar
|
||||
CLASSES = ${OUTPUT_DIR}:${JDK_LOCATION}/lib/tools.jar:${JDK_LOCATION}/lib/rt.jar:${CLASSPATH}
|
||||
JAVA_FILES = ./org/mozilla/webclient/*.java ./org/mozilla/webclient/wrapper_native/*.java ./org/mozilla/webclient/wrapper_native/motif/*.java ./org/mozilla/webclient/test/*.java
|
||||
JAVAH_OUTPUT_DIR = ../src_moz
|
||||
CP = cp
|
||||
|
||||
@@ -62,9 +62,21 @@ WEBCLIENT_JAR_NAME=webclient(VERSION_NUMBER).jar
|
||||
JAVAC_PROG=$(JDKHOME)\bin\javac
|
||||
|
||||
export::
|
||||
@echo +++ NOTE, you must have the org.w3c.dom classes in your classpath!
|
||||
@echo +++ If you do not have org.w3c.dom classes, webclient will not build.
|
||||
@echo +++ You can get the required dom classes at
|
||||
@echo +++ http://www.mozilla.org/projects/blackwood/webclient/bin/m3/dom2-20000307.jar
|
||||
@echo +++
|
||||
@echo +++ checking that org.mozilla.dom classes have been built...
|
||||
if not exist $(MOZ_SRC)\mozilla\dist\classes\org\mozilla\dom\DOMAccessor.class \
|
||||
stopbuild.exe
|
||||
@echo +++ Checking that org.mozilla.util classes have been built...
|
||||
if not exist $(MOZ_SRC)\mozilla\dist\classes\org\mozilla\util\Assert.class \
|
||||
stopbuild.exe
|
||||
|
||||
!ifdef CLASSPATH
|
||||
JAVAC_CLASSPATH=$(JAVAC_CLASSPATH);$(CLASSPATH)
|
||||
!endif
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package org.mozilla.webclient;
|
||||
|
||||
import java.util.Properties;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public interface CurrentPage
|
||||
{
|
||||
@@ -34,7 +35,7 @@ public void findNextInPage(boolean forward);
|
||||
|
||||
public String getCurrentURL();
|
||||
|
||||
// org.w3c.dom.Document getDOM();
|
||||
public Document getDOM();
|
||||
|
||||
public Properties getPageInfo();
|
||||
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* 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 <sdv@sparc.spb.su>
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
package org.mozilla.webclient.test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.mozilla.dom.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.*; //idk
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
public class DOMAccessPanel extends JPanel implements ActionListener, ItemListener, TreeSelectionListener {
|
||||
|
||||
private JTextField name, aValue;
|
||||
private JComboBox type, aName;
|
||||
private JTextArea value;
|
||||
private JButton newNode, insert, append, remove, set, removeAttr, save;
|
||||
private Node node, prv;
|
||||
private NamedNodeMap attrMap;
|
||||
private boolean updating;
|
||||
private String[] types = {
|
||||
"ELEMENT",
|
||||
"ATTRIBUTE",
|
||||
"TEXT",
|
||||
"CDATA_SECTION",
|
||||
"ENTITY_REF",
|
||||
"ENTITY",
|
||||
"PROC_INSTR",
|
||||
"COMMENT",
|
||||
"DOCUMENT",
|
||||
"DOCUMENT_TYPE",
|
||||
"DOC_FRAGM",
|
||||
"NOTATION"
|
||||
};
|
||||
|
||||
// private boolean debug = true;
|
||||
private boolean debug = false;
|
||||
|
||||
private Component tree;
|
||||
private DOMTreeNotifier treeNotifier;
|
||||
private TreePath nodePath;
|
||||
private DOMTreeDumper treeDumper;
|
||||
private JFileChooser chooser;
|
||||
|
||||
|
||||
public DOMAccessPanel() {
|
||||
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
JPanel nodeInfo = new JPanel();
|
||||
nodeInfo.setLayout(layout);
|
||||
|
||||
|
||||
JLabel l = new JLabel("Name:");
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
layout.setConstraints(l, c);
|
||||
nodeInfo.add(l);
|
||||
|
||||
l = new JLabel("Type:");
|
||||
c.gridwidth = GridBagConstraints.REMAINDER; //end row
|
||||
layout.setConstraints(l, c);
|
||||
nodeInfo.add(l);
|
||||
|
||||
c.gridwidth = GridBagConstraints.RELATIVE; //new row
|
||||
name = new JTextField(10);
|
||||
layout.setConstraints(name, c);
|
||||
nodeInfo.add(name);
|
||||
|
||||
c.gridwidth = GridBagConstraints.REMAINDER; //end row
|
||||
type = new JComboBox(types);
|
||||
layout.setConstraints(type, c);
|
||||
nodeInfo.add(type);
|
||||
|
||||
// Attribute panel
|
||||
|
||||
JPanel attrPanel = new JPanel();
|
||||
GridBagLayout attrLayout = new GridBagLayout();
|
||||
attrPanel.setLayout(attrLayout);
|
||||
|
||||
c.gridwidth = GridBagConstraints.RELATIVE; //new row
|
||||
aName = new JComboBox();
|
||||
aName.setEditable(true);
|
||||
aName.addItemListener(this);
|
||||
attrLayout.setConstraints(aName, c);
|
||||
attrPanel.add(aName);
|
||||
|
||||
JPanel p = new JPanel();
|
||||
l = new JLabel("=");
|
||||
p.add(l);
|
||||
aValue = new JTextField(9);
|
||||
p.add(aValue);
|
||||
c.gridwidth = GridBagConstraints.REMAINDER; //end row
|
||||
attrLayout.setConstraints(p, c);
|
||||
attrPanel.add(p);
|
||||
|
||||
p = new JPanel();
|
||||
set = new JButton("Set");
|
||||
set.addActionListener(this);
|
||||
p.add(set);
|
||||
removeAttr = new JButton("Remove");
|
||||
removeAttr.setActionCommand("remove_attr");
|
||||
removeAttr.addActionListener(this);
|
||||
p.add(removeAttr);
|
||||
attrLayout.setConstraints(p, c);
|
||||
attrPanel.add(p);
|
||||
attrPanel.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED), " Attributes "));
|
||||
layout.setConstraints(attrPanel, c);
|
||||
|
||||
// End Attribute panel
|
||||
|
||||
nodeInfo.add(attrPanel);
|
||||
|
||||
l = new JLabel("Value:");
|
||||
layout.setConstraints(l, c);
|
||||
nodeInfo.add(l);
|
||||
|
||||
value = new JTextArea(5, 23);
|
||||
value.addCaretListener (new CaretListener() {
|
||||
public void caretUpdate(CaretEvent e) {
|
||||
dbg("caret:");
|
||||
if (node == null || updating) return;
|
||||
String valueStr = value.getText();
|
||||
if (!valueStr.equals("")) {
|
||||
node.setNodeValue(valueStr);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
JScrollPane valueScrollPane = new JScrollPane(value);
|
||||
layout.setConstraints(valueScrollPane, c);
|
||||
nodeInfo.add(valueScrollPane);
|
||||
|
||||
JPanel nodeButtonPanel = new JPanel();
|
||||
GridLayout gl = new GridLayout(2, 2);
|
||||
nodeButtonPanel.setLayout(gl);
|
||||
newNode = new JButton("New");
|
||||
newNode.setToolTipText("Create a new node");
|
||||
newNode.addActionListener(this);
|
||||
nodeButtonPanel.add(newNode);
|
||||
insert = new JButton("Insert");
|
||||
insert.setToolTipText("Inserts a node before the selected node ");
|
||||
insert.addActionListener(this);
|
||||
nodeButtonPanel.add(insert);
|
||||
append = new JButton("Append");
|
||||
append.setToolTipText("Adds a node to the end of the list of children of the selected node");
|
||||
append.addActionListener(this);
|
||||
nodeButtonPanel.add(append);
|
||||
remove = new JButton("Remove");
|
||||
remove.setToolTipText("Removes the selected node from the tree");
|
||||
remove.addActionListener(this);
|
||||
nodeButtonPanel.add(remove);
|
||||
nodeButtonPanel.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED), " Node Manipulation "));
|
||||
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
layout.setConstraints(nodeButtonPanel, c);
|
||||
|
||||
nodeInfo.add(nodeButtonPanel);
|
||||
nodeInfo.setBorder(new TitledBorder(new EtchedBorder(), " Node info "));
|
||||
|
||||
|
||||
layout = new GridBagLayout();
|
||||
setLayout(layout);
|
||||
layout.setConstraints(nodeInfo, c);
|
||||
add(nodeInfo);
|
||||
|
||||
save = new JButton("Dump Tree To File");
|
||||
save.setActionCommand("save");
|
||||
save.addActionListener(this);
|
||||
c.anchor = GridBagConstraints.CENTER;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
layout.setConstraints(save, c);
|
||||
add(save);
|
||||
setMinimumSize(new Dimension(350, 400));
|
||||
setButtonState();
|
||||
|
||||
}
|
||||
|
||||
public void setTreeNotifier(DOMTreeNotifier newTreeNotifier)
|
||||
{
|
||||
treeNotifier = newTreeNotifier;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
dbg("AttrInfoPanel.actionPerformed: " + command);
|
||||
if (command.equalsIgnoreCase("new")) {
|
||||
prv = node;
|
||||
updateInfo(null);
|
||||
type.setEnabled(true);
|
||||
insert.setEnabled(true);
|
||||
append.setEnabled(true);
|
||||
} else if (command.equalsIgnoreCase("insert")) {
|
||||
insertNode();
|
||||
treeNotifier.treeStructureChanged(
|
||||
new TreeModelEvent(this, nodePath.getParentPath()));
|
||||
} else if (command.equalsIgnoreCase("append")) {
|
||||
appendNode();
|
||||
treeNotifier.treeStructureChanged(
|
||||
new TreeModelEvent(this, nodePath.getParentPath()));
|
||||
} else if (command.equalsIgnoreCase("remove")) {
|
||||
if (node == null) return;
|
||||
Node parent = node.getParentNode();
|
||||
parent.removeChild(node);
|
||||
node = parent;
|
||||
treeNotifier.treeStructureChanged(new TreeModelEvent(this, nodePath.getParentPath()));
|
||||
} else if (command.equalsIgnoreCase("save")) {
|
||||
saveDoc();
|
||||
} else if (command.equalsIgnoreCase("set")) {
|
||||
((Element)node).setAttribute((String)aName.getSelectedItem(), aValue.getText());
|
||||
updateInfo(node);
|
||||
} else if (command.equalsIgnoreCase("remove_attr")) {
|
||||
removeAttribute();
|
||||
}
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if ((node != null) && (aName.getSelectedItem() != null)) {
|
||||
set.setEnabled(true);
|
||||
if (((attrMap = node.getAttributes()) != null) &&
|
||||
(aName.getSelectedIndex() >=0)) {
|
||||
dbg("setting attr...");
|
||||
aValue.setText(attrMap.item(aName.getSelectedIndex()).getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateInfo(Node node) {
|
||||
updating = true;
|
||||
dbg("updateInfo" + node);
|
||||
this.node = node;
|
||||
setButtonState();
|
||||
name.setText("");
|
||||
value.setText("");
|
||||
aValue.setText("");
|
||||
aName.removeAllItems();
|
||||
if (node == null) {
|
||||
updating = false;
|
||||
return;
|
||||
}
|
||||
prv = node;
|
||||
name.setText(node.getNodeName());
|
||||
type.setSelectedIndex(node.getNodeType() - 1);
|
||||
dbg("1 update node name: " + node.getNodeName());
|
||||
dbg("1 update node value:" + node.getNodeValue());
|
||||
value.setText(node.getNodeValue());
|
||||
dbg("2 update node name: " + node.getNodeName());
|
||||
dbg("2 update node value:" + node.getNodeValue());
|
||||
attrMap = node.getAttributes();
|
||||
if (attrMap == null) {
|
||||
updating = false;
|
||||
return;
|
||||
}
|
||||
int length = attrMap.getLength();
|
||||
for (int i=0; i < length; i++) {
|
||||
Attr a = (Attr)attrMap.item(i);
|
||||
aName.addItem(a.getName());
|
||||
}
|
||||
if (length > 0) {
|
||||
aName.setSelectedIndex(0);
|
||||
aValue.setText(attrMap.item(0).getNodeValue());
|
||||
}
|
||||
updating = false;
|
||||
}
|
||||
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
dbg("DOMAccessPanel.valueChanged");
|
||||
if (e.isAddedPath()) {
|
||||
updateInfo((Node)e.getPath().getLastPathComponent());
|
||||
}
|
||||
nodePath = e.getPath();
|
||||
tree = (Component)e.getSource();
|
||||
}
|
||||
|
||||
private Node createNode() {
|
||||
int nodeType = type.getSelectedIndex();
|
||||
Document doc = prv.getOwnerDocument();
|
||||
Node newNode = null;
|
||||
switch (nodeType + 1) {
|
||||
case Node.ELEMENT_NODE:
|
||||
dbg("ELEMENT");
|
||||
newNode = doc.createElement(name.getText());
|
||||
break;
|
||||
case Node.ATTRIBUTE_NODE:
|
||||
dbg("ATTRIBUTE");
|
||||
return null;
|
||||
case Node.TEXT_NODE:
|
||||
dbg("TEXT");
|
||||
newNode = doc.createTextNode(value.getText());
|
||||
break;
|
||||
case Node.CDATA_SECTION_NODE:
|
||||
dbg("CDATA_SECTION");
|
||||
return null;
|
||||
case Node.ENTITY_REFERENCE_NODE:
|
||||
dbg("ENTITY_REFERENCE");
|
||||
return null;
|
||||
case Node.ENTITY_NODE:
|
||||
dbg("ENTITY");
|
||||
return null;
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
dbg("PROCESSING_INSTRUCTION");
|
||||
return null;
|
||||
case Node.COMMENT_NODE:
|
||||
dbg("COMMENT");
|
||||
newNode = doc.createComment(value.getText());
|
||||
break;
|
||||
case Node.DOCUMENT_NODE:
|
||||
dbg("DOCUMENT");
|
||||
return null;
|
||||
case Node.DOCUMENT_TYPE_NODE:
|
||||
dbg("DOCUMENT_TYPE");
|
||||
return null;
|
||||
case Node.DOCUMENT_FRAGMENT_NODE:
|
||||
dbg("DOCUMENT_FRAGMENT");
|
||||
return null;
|
||||
case Node.NOTATION_NODE:
|
||||
dbg("NOTATION");
|
||||
return null;
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
private void insertNode() {
|
||||
Node newNode = createNode();
|
||||
if (newNode == null) return;
|
||||
dbg("inserting...");
|
||||
prv.getParentNode().insertBefore(newNode, prv);
|
||||
}
|
||||
|
||||
private void appendNode() {
|
||||
Node newNode = createNode();
|
||||
if (newNode == null) return;
|
||||
dbg("appending...");
|
||||
prv.appendChild(newNode);
|
||||
}
|
||||
|
||||
private void removeAttribute() {
|
||||
((Element)node).removeAttribute((String)aName.getSelectedItem());
|
||||
updateInfo(node);
|
||||
}
|
||||
|
||||
private void saveDoc() {
|
||||
if (chooser == null) {
|
||||
chooser = new JFileChooser();
|
||||
}
|
||||
int returnVal = chooser.showSaveDialog(this);
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
String fileName = chooser.getSelectedFile().getPath();
|
||||
if (treeDumper == null) {
|
||||
treeDumper = new DOMTreeDumper(debug);
|
||||
}
|
||||
treeDumper.dumpToFile(fileName, node.getOwnerDocument());
|
||||
}
|
||||
}
|
||||
|
||||
private void setButtonState() {
|
||||
boolean nodeExists = (node != null);
|
||||
boolean attrExists = nodeExists && !(node.getAttributes() == null || node.getAttributes().getLength() == 0);
|
||||
type.setEnabled(nodeExists);
|
||||
newNode.setEnabled(nodeExists);
|
||||
insert.setEnabled(nodeExists);
|
||||
append.setEnabled(nodeExists);
|
||||
save.setEnabled(nodeExists);
|
||||
remove.setEnabled(nodeExists);
|
||||
set.setEnabled(attrExists);
|
||||
removeAttr.setEnabled(attrExists);
|
||||
}
|
||||
|
||||
private void dbg(String str) {
|
||||
if (debug) {
|
||||
System.out.println(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
package org.mozilla.webclient.test;
|
||||
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import javax.swing.JTree;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
class DOMCellRenderer implements TreeCellRenderer {
|
||||
private TreeCellRenderer cellRenderer;
|
||||
public DOMCellRenderer(TreeCellRenderer cellRenderer) {
|
||||
this.cellRenderer = cellRenderer;
|
||||
}
|
||||
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value,
|
||||
boolean selected,
|
||||
boolean expanded,
|
||||
boolean leaf, int row,
|
||||
boolean hasFocus) {
|
||||
return cellRenderer.getTreeCellRendererComponent(tree,
|
||||
((Node)value).getNodeName(),
|
||||
selected,
|
||||
expanded,
|
||||
leaf, row,
|
||||
hasFocus);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* 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 <sdv@sparc.spb.su>
|
||||
*
|
||||
*/
|
||||
|
||||
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("</" + node.getNodeName() + ">");
|
||||
}
|
||||
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<!--" + 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(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
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) {
|
||||
treeModelListeners.add(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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 Original Code is RaptorCanvas.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Kirk Baker and
|
||||
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
|
||||
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Kirk Baker <kbaker@eb.com>
|
||||
* Ian Wilkinson <iw@ennoble.com>
|
||||
* Mark Goddard
|
||||
* Ed Burns <edburns@acm.org>
|
||||
*/
|
||||
|
||||
package org.mozilla.webclient.test;
|
||||
|
||||
import org.mozilla.util.Assert;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JTree;
|
||||
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
* A dom viewer Frame
|
||||
|
||||
*
|
||||
* @version $Id: DOMViewerFrame.java,v 1.1 2000-06-04 22:16:04 edburns%acm.org Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlFactory
|
||||
|
||||
* Based on DOMViewerFactor.java by idk
|
||||
|
||||
* Contributor(s): Ed Burns <edburns@acm.org>
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class DOMViewerFrame extends JFrame {
|
||||
|
||||
private EmbeddedMozilla creator;
|
||||
|
||||
private Node rootNode;
|
||||
private DOMAccessPanel elementPanel;
|
||||
|
||||
private JScrollPane treePane;
|
||||
private JSplitPane splitPane;
|
||||
private JPanel panel;
|
||||
private JTree tree;
|
||||
|
||||
private Document doc;
|
||||
|
||||
|
||||
public DOMViewerFrame (String title, EmbeddedMozilla Creator)
|
||||
{
|
||||
super(title);
|
||||
creator = Creator;
|
||||
|
||||
this.getContentPane().setLayout(new BorderLayout());
|
||||
|
||||
// create the content for the top of the splitPane
|
||||
treePane = new JScrollPane();
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add("Center", treePane);
|
||||
|
||||
// create the content for the bottom of the splitPane
|
||||
elementPanel = new DOMAccessPanel();
|
||||
|
||||
// create the splitPane, adding the top and bottom content
|
||||
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel, elementPanel);
|
||||
|
||||
// add the splitPane to myself
|
||||
this.getContentPane().add(splitPane);
|
||||
this.pack();
|
||||
splitPane.setDividerLocation(0.35);
|
||||
|
||||
} // DOMViewerFrame() ctor
|
||||
|
||||
public void setDocument(Document newDocument)
|
||||
{
|
||||
if (null == newDocument) {
|
||||
return;
|
||||
}
|
||||
doc = newDocument;
|
||||
|
||||
try {
|
||||
// store the document as the root node
|
||||
Element e;
|
||||
e = doc.getDocumentElement();
|
||||
e.normalize();
|
||||
rootNode = e;
|
||||
|
||||
// create a tree model for the DOM tree
|
||||
DOMTreeModel treeModel = new DOMTreeModel(rootNode);
|
||||
|
||||
// hook the treeModel up to the elementPanel
|
||||
elementPanel.setTreeNotifier(treeModel);
|
||||
tree = new JTree(treeModel);
|
||||
|
||||
// hook the elementPanel up to the treeModel
|
||||
tree.addTreeSelectionListener(elementPanel);
|
||||
|
||||
tree.setCellRenderer(new DOMCellRenderer(tree.getCellRenderer()));
|
||||
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
treePane.setViewportView(tree);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// EOF
|
||||
@@ -43,6 +43,8 @@ import java.util.*;
|
||||
import org.mozilla.webclient.*;
|
||||
import org.mozilla.util.Assert;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -50,7 +52,7 @@ import org.mozilla.util.Assert;
|
||||
* This is a test application for using the BrowserControl.
|
||||
|
||||
*
|
||||
* @version $Id: EMWindow.java,v 1.9 2000-06-01 23:42:35 edburns%acm.org Exp $
|
||||
* @version $Id: EMWindow.java,v 1.10 2000-06-04 22:16:04 edburns%acm.org Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlFactory
|
||||
|
||||
@@ -68,8 +70,9 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
|
||||
|
||||
private CurrentPage currentPage;
|
||||
private Bookmarks bookmarks;
|
||||
private BookmarksFrame bookmarksFrame = null;
|
||||
private BookmarksFrame bookmarksFrame = null;
|
||||
private TreeModel bookmarksTree;
|
||||
private DOMViewerFrame domViewer;
|
||||
private Panel controlPanel;
|
||||
private Panel statusPanel;
|
||||
private Panel buttonsPanel;
|
||||
@@ -77,6 +80,8 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
|
||||
private MenuBar menuBar;
|
||||
private Label statusLabel;
|
||||
|
||||
private Document currentDocument = null;
|
||||
|
||||
private EmbeddedMozilla creator;
|
||||
private boolean viewMode = true;
|
||||
|
||||
@@ -143,6 +148,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
|
||||
makeItem(buttonsPanel, "Stop", 2, 0, 1, 1, 0.0, 0.0);
|
||||
makeItem(buttonsPanel, "Refresh", 3, 0, 1, 1, 0.0, 0.0);
|
||||
makeItem(buttonsPanel, "Bookmarks", 4, 0, 1, 1, 0.0, 0.0);
|
||||
makeItem(buttonsPanel, "DOMViewer", 5, 0, 1, 1, 0.0, 0.0);
|
||||
|
||||
// Create the control panel
|
||||
controlPanel = new Panel();
|
||||
@@ -284,6 +290,11 @@ public void delete()
|
||||
bookmarksFrame.dispose();
|
||||
bookmarksFrame = null;
|
||||
}
|
||||
if (null != domViewer) {
|
||||
domViewer.setVisible(false);
|
||||
domViewer.dispose();
|
||||
domViewer = null;
|
||||
}
|
||||
BrowserControlFactory.deleteBrowserControl(browserControl);
|
||||
browserControl = null;
|
||||
System.out.println("debug: edburns: about to hide");
|
||||
@@ -297,92 +308,108 @@ public void delete()
|
||||
bookmarksTree = null;
|
||||
controlPanel = null;
|
||||
buttonsPanel = null;
|
||||
currentDocument = null;
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed (ActionEvent evt) {
|
||||
String command = evt.getActionCommand();
|
||||
|
||||
public void actionPerformed (ActionEvent evt)
|
||||
{
|
||||
String command = evt.getActionCommand();
|
||||
|
||||
try {
|
||||
Navigation navigation = (Navigation)
|
||||
browserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
|
||||
CurrentPage currentPage = (CurrentPage)
|
||||
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
History history = (History)
|
||||
browserControl.queryInterface(BrowserControl.HISTORY_NAME);
|
||||
|
||||
try {
|
||||
Navigation navigation = (Navigation)
|
||||
browserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
|
||||
CurrentPage currentPage = (CurrentPage)
|
||||
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
History history = (History)
|
||||
browserControl.queryInterface(BrowserControl.HISTORY_NAME);
|
||||
if (evt.getSource() instanceof MenuItem) {
|
||||
if (command.equals("New Window")) {
|
||||
creator.CreateEMWindow();
|
||||
}
|
||||
else if (command.equals("Close")) {
|
||||
System.out.println("Got windowClosing");
|
||||
System.out.println("destroying the BrowserControl");
|
||||
EMWindow.this.delete();
|
||||
// deal with the menu item commands
|
||||
if (evt.getSource() instanceof MenuItem) {
|
||||
if (command.equals("New Window")) {
|
||||
creator.CreateEMWindow();
|
||||
}
|
||||
else if (command.equals("Close")) {
|
||||
System.out.println("Got windowClosing");
|
||||
System.out.println("destroying the BrowserControl");
|
||||
EMWindow.this.delete();
|
||||
// should close the BrowserControlCanvas
|
||||
creator.DestroyEMWindow(winNum);
|
||||
}
|
||||
else if (command.equals("Find")) {
|
||||
creator.DestroyEMWindow(winNum);
|
||||
}
|
||||
else if (command.equals("Find")) {
|
||||
if (null == findDialog) {
|
||||
Frame f = new Frame();
|
||||
f.setSize(350,150);
|
||||
findDialog = new FindDialog(this, this,
|
||||
"Find in Page", "Find ",
|
||||
"", 20, false);
|
||||
findDialog.setModal(false);
|
||||
Frame f = new Frame();
|
||||
f.setSize(350,150);
|
||||
findDialog = new FindDialog(this, this,
|
||||
"Find in Page", "Find ",
|
||||
"", 20, false);
|
||||
findDialog.setModal(false);
|
||||
}
|
||||
findDialog.setVisible(true);
|
||||
// currentPage.findInPage("Sun", true, true);
|
||||
}
|
||||
else if (command.equals("Find Next")) {
|
||||
currentPage.findNextInPage(false);
|
||||
}
|
||||
else if (command.equals("View Page Source")) {
|
||||
currentPage.getSourceBytes(viewMode);
|
||||
viewMode = !viewMode;
|
||||
}
|
||||
else if (command.equals("View Page Info")) {
|
||||
currentPage.getPageInfo();
|
||||
}
|
||||
else if (command.equals("Select All")) {
|
||||
currentPage.selectAll();
|
||||
}
|
||||
// currentPage.findInPage("Sun", true, true);
|
||||
}
|
||||
else if (command.equals("Find Next")) {
|
||||
currentPage.findNextInPage(false);
|
||||
}
|
||||
else if (command.equals("View Page Source")) {
|
||||
currentPage.getSourceBytes(viewMode);
|
||||
viewMode = !viewMode;
|
||||
}
|
||||
else if (command.equals("View Page Info")) {
|
||||
currentPage.getPageInfo();
|
||||
}
|
||||
else if (command.equals("Select All")) {
|
||||
currentPage.selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
// deal with the button bar commands
|
||||
else if(command.equals("Stop")) {
|
||||
navigation.stop();
|
||||
}
|
||||
else if (command.equals("Refresh")) {
|
||||
navigation.refresh(Navigation.LOAD_NORMAL);
|
||||
}
|
||||
else if (command.equals("Bookmarks")) {
|
||||
if (null == bookmarksTree) {
|
||||
bookmarksTree = bookmarks.getBookmarks();
|
||||
}
|
||||
if (null == bookmarksFrame) {
|
||||
bookmarksFrame = new BookmarksFrame(bookmarksTree);
|
||||
bookmarksFrame.setSize(new Dimension(320,480));
|
||||
}
|
||||
bookmarksFrame.setVisible(true);
|
||||
}
|
||||
else if (command.equals("Back")) {
|
||||
if (history.canBack()) {
|
||||
history.back();
|
||||
}
|
||||
}
|
||||
else if (command.equals("Forward")) {
|
||||
if (history.canForward()) {
|
||||
history.forward();
|
||||
}
|
||||
}
|
||||
else {
|
||||
navigation.loadURL(urlField.getText());
|
||||
}
|
||||
navigation.stop();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
else if (command.equals("Refresh")) {
|
||||
navigation.refresh(Navigation.LOAD_NORMAL);
|
||||
}
|
||||
} // actionPerformed()
|
||||
else if (command.equals("Bookmarks")) {
|
||||
if (null == bookmarksTree) {
|
||||
bookmarksTree = bookmarks.getBookmarks();
|
||||
}
|
||||
|
||||
if (null == bookmarksFrame) {
|
||||
bookmarksFrame = new BookmarksFrame(bookmarksTree);
|
||||
bookmarksFrame.setSize(new Dimension(320,480));
|
||||
bookmarksFrame.setLocation(defaultWidth + 5, 0);
|
||||
}
|
||||
bookmarksFrame.setVisible(true);
|
||||
}
|
||||
else if (command.equals("DOMViewer")) {
|
||||
if (null == domViewer) {
|
||||
domViewer = new DOMViewerFrame("DOM Viewer", creator);
|
||||
domViewer.setSize(new Dimension(300, 600));
|
||||
domViewer.setLocation(defaultWidth + 5, 0);
|
||||
}
|
||||
if (null != currentDocument) {
|
||||
domViewer.setDocument(currentDocument);
|
||||
domViewer.setVisible(true);
|
||||
}
|
||||
}
|
||||
else if (command.equals("Back")) {
|
||||
if (history.canBack()) {
|
||||
history.back();
|
||||
}
|
||||
}
|
||||
else if (command.equals("Forward")) {
|
||||
if (history.canForward()) {
|
||||
history.forward();
|
||||
}
|
||||
}
|
||||
else {
|
||||
navigation.loadURL(urlField.getText());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
} // actionPerformed()
|
||||
|
||||
|
||||
public void dialogDismissed(Dialog d) {
|
||||
@@ -482,9 +509,14 @@ public void eventDispatched(WebclientEvent event)
|
||||
currentURL);
|
||||
statusLabel.setText("Starting to load " + currentURL);
|
||||
urlField.setText(currentURL);
|
||||
currentDocument = null;
|
||||
break;
|
||||
case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK):
|
||||
statusLabel.setText("Done.");
|
||||
currentDocument = currentPage.getDOM();
|
||||
if (null != domViewer) {
|
||||
domViewer.setDocument(currentDocument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,12 @@ import java.util.Properties;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.mozilla.webclient.UnimplementedException;
|
||||
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
|
||||
public class CurrentPageImpl extends ImplObjectNative implements CurrentPage
|
||||
{
|
||||
//
|
||||
@@ -47,12 +51,15 @@ public class CurrentPageImpl extends ImplObjectNative implements CurrentPage
|
||||
// Class Variables
|
||||
//
|
||||
|
||||
private static boolean domInitialized = false;
|
||||
|
||||
//
|
||||
// Instance Variables
|
||||
//
|
||||
|
||||
// Attribute Instance Variables
|
||||
|
||||
|
||||
// Relationship Instance Variables
|
||||
|
||||
//
|
||||
@@ -63,6 +70,10 @@ public CurrentPageImpl(WrapperFactory yourFactory,
|
||||
BrowserControl yourBrowserControl)
|
||||
{
|
||||
super(yourFactory, yourBrowserControl);
|
||||
// force the class to be loaded, thus loading the JNI library
|
||||
if (!domInitialized) {
|
||||
DOMAccessor.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -116,7 +127,11 @@ public String getCurrentURL()
|
||||
return result;
|
||||
}
|
||||
|
||||
// org.w3c.dom.Document getDOM();
|
||||
public Document getDOM()
|
||||
{
|
||||
Document result = nativeGetDOM(nativeWebShell);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Properties getPageInfo()
|
||||
{
|
||||
@@ -221,7 +236,7 @@ native public void nativeFindNextInPage(int webShellPtr, boolean forward);
|
||||
|
||||
native public String nativeGetCurrentURL(int webShellPtr);
|
||||
|
||||
// org.w3c.dom.Document getDOM();
|
||||
native public Document nativeGetDOM(int webShellPtr);
|
||||
|
||||
// webclient.PageInfo getPageInfo();
|
||||
|
||||
@@ -245,7 +260,7 @@ public static void main(String [] args)
|
||||
Assert.setEnabled(true);
|
||||
Log.setApplicationName("CurrentPageImpl");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.5 2000-05-23 21:06:11 ashuk%eng.sun.com Exp $");
|
||||
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.6 2000-06-04 22:16:05 edburns%acm.org Exp $");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user