mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
A major update:
- reduces a number of c++<--> java calls - added NULL checks - made DOMAccessor to be secure - added util and tests packages - wrote test applets - updated README
This commit is contained in:
parent
79d0581135
commit
26937e21bf
@ -1,12 +0,0 @@
|
||||
Index: DocumentImpl.java
|
||||
===================================================================
|
||||
RCS file: /cvsroot/mozilla/java/dom/jni/DocumentImpl.java,v
|
||||
retrieving revision 1.4
|
||||
diff -r1.4 DocumentImpl.java
|
||||
40a41,42
|
||||
> import org.mozilla.dom.tests.TestDocLoadListener;
|
||||
>
|
||||
64d65
|
||||
<
|
||||
71a73
|
||||
> DOMAccessorImpl.getInstance().addDocumentLoadListener(new TestDocLoadListener());
|
124
java/dom/README
124
java/dom/README
@ -1,57 +1,90 @@
|
||||
|
||||
Sources
|
||||
=======
|
||||
|
||||
The sources are located in mozilla/java/dom.
|
||||
Subdirectories
|
||||
|
||||
classes
|
||||
jni
|
||||
src
|
||||
tests
|
||||
|
||||
contain Java sources, Java native methods implementation,
|
||||
native c++ code and Java DOM API tests respectively.
|
||||
|
||||
Building
|
||||
========
|
||||
|
||||
Requirenments:
|
||||
--------------
|
||||
Current mozilla build
|
||||
JDK1.2 or JDK1.3
|
||||
Perl 5 must be in your path
|
||||
JDKHOME environment variable set to your JDK dir
|
||||
CLASSPATH environment cvariable set to contain
|
||||
org.w3c.dom classes. The sources can be found at
|
||||
http://www.w3.org/TR/WD-DOM-Level-2/java-binding.zip
|
||||
|
||||
Solaris specific
|
||||
----------------
|
||||
Add following directories to LD_LIBRARY_PATH environment variable:
|
||||
$MOZILLA_FIVE_HOME
|
||||
$JDKHOME/jre/lib/$HOSTTYPE/native_threads
|
||||
$JDKHOME/jre/lib/$HOSTTYPE/classic
|
||||
$JDKHOME/jre/lib/$HOSTTYPE/
|
||||
|
||||
goto mozilla/java/dom directory and type "gmake"
|
||||
|
||||
|
||||
Windows NT specific
|
||||
-------------------
|
||||
To enable OJI usage set environment variable JAVA_DOM_OJI_ENABLE=1
|
||||
Add following directories to PATH environment variable:
|
||||
%MOZILLA_FIVE_HOME%
|
||||
%JDKHOME%\jre\bin\classic (only in case you don't use OJI)
|
||||
|
||||
goto mozilla/java/dom directory and type "nmake /f makefile.win"
|
||||
|
||||
|
||||
Using the Java DOM API
|
||||
----------------------
|
||||
======================
|
||||
|
||||
A Java component obtains a org.w3c.dom.Document by registering for
|
||||
Document load notifications. The Document is passed in along with the
|
||||
notifications. The preferred way for a Java component to register for
|
||||
Document load notifications is to register via the DOMAccessor
|
||||
class. However if OJI is not use to obtain JNIEnv one has to apply
|
||||
two patches
|
||||
Document load notifications is to register via the DOMAccessor class.
|
||||
|
||||
webshell/src/nsWebShell.cpp.patch
|
||||
java/dom/jni/DocumentImpl.java.patch
|
||||
However, this is possible only if OJI usage is enabled. This works
|
||||
on Windows NT platform.
|
||||
|
||||
The first one inits nsJavaDOM component and starts jvm. The second one
|
||||
registers a document load listener via DOMAccessor.
|
||||
On Solaris currently the nsJavaDOM component instantiates its own JVM.
|
||||
When an OJI-compatible JVM is available, we will move over to using it.
|
||||
So, one has to apply two patches to
|
||||
|
||||
mozilla/webshell/src/nsWebShell.cpp
|
||||
mozilla/java/dom/classes/org/mozilla/dom/DOMAccessor.java
|
||||
|
||||
They can be found at mozilla/java/dom directory.
|
||||
The first one inits nsJavaDOM component and adds it as a
|
||||
document load observer listener.
|
||||
|
||||
The second one registers a document load listener via DOMAccessor.
|
||||
Note:
|
||||
any class that implements the DocumentLoadListener interface may
|
||||
stand for TestDocLoadListener.
|
||||
See the section on Building for instructions on how to apply the patches.
|
||||
stand for GenericDocLoadListener.
|
||||
|
||||
To enable OJI usage on win nt add -DJAVA_DOM_OJI_ENABLE to the
|
||||
DEFINES variable in makefile.win and also set an environment
|
||||
variable JAVA_DOM_OJI_ENABLE=true
|
||||
After applying a patch to nsWebShell.cpp edit
|
||||
mozilla/webshell/src/Makefile.in to add -DJAVA_DOM to the list of
|
||||
defines. Then do a gmake in this directory.
|
||||
|
||||
After applying a patch to DOMAccessor.java go to mozilla/java/dom/classes
|
||||
and do a gmake. No changes in makefiles are needed.
|
||||
|
||||
Makefiles
|
||||
---------
|
||||
You can find examples of Java DOM API usage in
|
||||
|
||||
You may have to set DEPTH to point to the mozilla CVS workspace root
|
||||
in Makefile and jni/Makefile. Since this stuff is not part of the
|
||||
regular SeaMonkeyBuild, Makefiles are not generated from Makefile.in,
|
||||
so just go ahead and hack the Makefile.
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
After having done a configure at the top level of SeaMonkey, do a make
|
||||
in the dom and the dom/jni directories. This will copy over a few
|
||||
header files that are needed by the patch to nsWebShell. You can then
|
||||
apply the patch to nsWebShell.cpp by executing
|
||||
|
||||
`patch nsWebShell.cpp <nsWebShell.cpp.patch`
|
||||
|
||||
Edit Makefile.in to add -DJAVA_DOM to the list of defines. Then do a
|
||||
gmake in this directory.
|
||||
|
||||
Similarly apply the DocumetnImpl.java patch. Then recompile the
|
||||
DocumentImpl class. No changes in makefiles are needed.
|
||||
|
||||
Define JDKHOME so that $JDKHOME/bin points to javac.
|
||||
|
||||
You will also need to get the w3c DOM level 2 interfaces from
|
||||
http://www.w3.org/TR/WD-DOM-Level-2/java-binding.zip
|
||||
and put the class files in your CLASSPATH.
|
||||
mozilla/java/dom/classes/org/mozilla/dom/util
|
||||
mozilla/java/dom/classes/org/mozilla/dom/tests
|
||||
|
||||
|
||||
DOM2 events
|
||||
@ -76,8 +109,6 @@ The basic implementation architecture is following:
|
||||
- javaDOMEventsGlobals class is used much like javaDOMGlobals for caching
|
||||
(this code may be moved to javaDOMGlobals)
|
||||
|
||||
|
||||
|
||||
NSPR Logging
|
||||
------------
|
||||
|
||||
@ -96,13 +127,6 @@ and from Java. The two should be identical. The code to write these
|
||||
files is, essentially, my regression test. Feel free to add to it.
|
||||
|
||||
|
||||
OJI
|
||||
---
|
||||
|
||||
Currently the nsJavaDOM component instantiates its own JVM. When an
|
||||
OJI-compatible JVM is available, we will move over to using it.
|
||||
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
|
@ -29,6 +29,8 @@ NO_CAFE=1
|
||||
|
||||
JDIRS = org/mozilla/dom \
|
||||
org/mozilla/dom/events \
|
||||
org/mozilla/dom/util \
|
||||
org/mozilla/dom/tests \
|
||||
$(NULL)
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
@ -29,6 +29,8 @@ NO_CAFE=1
|
||||
|
||||
JDIRS = org/mozilla/dom \
|
||||
org/mozilla/dom/events \
|
||||
org/mozilla/dom/util \
|
||||
org/mozilla/dom/tests \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@ include <$(DEPTH)\java\config\localdefs.mak>
|
||||
|
||||
JDIRS = org\mozilla\dom \
|
||||
org\mozilla\dom\events \
|
||||
org\mozilla\dom\util \
|
||||
org\mozilla\dom\tests \
|
||||
$(NULL)
|
||||
|
||||
JAVAC_PROG=$(JDKHOME)\bin\javac
|
||||
|
@ -21,15 +21,124 @@
|
||||
|
||||
package org.mozilla.dom;
|
||||
|
||||
public interface DOMAccessor {
|
||||
public void addDocumentLoadListener(DocumentLoadListener listener);
|
||||
public void removeDocumentLoadListener(DocumentLoadListener listener);
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* The getInstance method is available, it is not declared because
|
||||
* it is a static method and the Java Language Spec does not allow
|
||||
* us to declare a static method in an interface.
|
||||
*
|
||||
* public static synchronized DOMAccessor getInstance();
|
||||
*/
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import java.security.AccessController;
|
||||
|
||||
public final class DOMAccessor {
|
||||
|
||||
private static Vector documentLoadListeners = new Vector();
|
||||
private static JavaDOMPermission permission = new JavaDOMPermission("JavaDOM");
|
||||
|
||||
static {
|
||||
System.loadLibrary("javadomjni");
|
||||
}
|
||||
|
||||
private void DOMAccessorImpl() {}
|
||||
|
||||
private static native void register();
|
||||
private static native void unregister();
|
||||
private static native Node getNodeByHandle(long p);
|
||||
private static native void doGC();
|
||||
|
||||
public static synchronized void
|
||||
addDocumentLoadListener(DocumentLoadListener listener) {
|
||||
if (documentLoadListeners.size() == 0) {
|
||||
register();
|
||||
}
|
||||
documentLoadListeners.addElement(listener);
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
removeDocumentLoadListener(DocumentLoadListener listener) {
|
||||
|
||||
documentLoadListeners.removeElement(listener);
|
||||
if (documentLoadListeners.size() == 0) {
|
||||
unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
startURLLoad(String url, String contentType, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.startURLLoad(url, contentType, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
endURLLoad(String url, int status, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.endURLLoad(url, status, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
progressURLLoad(String url, int progress, int progressMax,
|
||||
long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.progressURLLoad(url, progress, progressMax, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
statusURLLoad(String url, String message, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.statusURLLoad(url, message, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void
|
||||
startDocumentLoad(String url) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.startDocumentLoad(url);
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
endDocumentLoad(String url, int status, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.endDocumentLoad(url, status, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
}
|
||||
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class DOMAccessorImpl implements DOMAccessor, DocumentLoadListener {
|
||||
|
||||
private static DOMAccessor instance = null;
|
||||
private Vector documentLoadListeners = new Vector();
|
||||
|
||||
static {
|
||||
System.loadLibrary("javadomjni");
|
||||
}
|
||||
|
||||
private void DOMAccessorImpl() {}
|
||||
|
||||
private static native void register();
|
||||
private static native void unregister();
|
||||
private static native Element getElementByHandle(long p);
|
||||
|
||||
public static synchronized DOMAccessor getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new DOMAccessorImpl();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
addDocumentLoadListener(DocumentLoadListener listener) {
|
||||
if (documentLoadListeners.size() == 0) {
|
||||
register();
|
||||
}
|
||||
documentLoadListeners.addElement(listener);
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
removeDocumentLoadListener(DocumentLoadListener listener) {
|
||||
|
||||
documentLoadListeners.removeElement(listener);
|
||||
if (documentLoadListeners.size() == 0) {
|
||||
unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
startURLLoad(String url, String contentType, Document doc) {
|
||||
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.startURLLoad(url, contentType, doc);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
endURLLoad(String url, int status, Document doc) {
|
||||
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.endURLLoad(url, status, doc);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
progressURLLoad(String url, int progress, int progressMax,
|
||||
Document doc) {
|
||||
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.progressURLLoad(url, progress, progressMax, doc);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
statusURLLoad(String url, String message, Document doc) {
|
||||
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.statusURLLoad(url, message, doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void
|
||||
startDocumentLoad(String url) {
|
||||
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.startDocumentLoad(url);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
endDocumentLoad(String url, int status, Document doc) {
|
||||
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.endDocumentLoad(url, status, doc);
|
||||
}
|
||||
}
|
||||
}
|
@ -42,9 +42,6 @@ public class DocumentImpl extends NodeImpl implements Document, DocumentEvent {
|
||||
|
||||
// instantiated from JNI only
|
||||
private DocumentImpl() {}
|
||||
public DocumentImpl(long p) {
|
||||
super(p);
|
||||
}
|
||||
|
||||
public native Attr createAttribute(String name);
|
||||
public native CDATASection createCDATASection(String data);
|
||||
|
@ -21,8 +21,16 @@
|
||||
|
||||
package org.mozilla.dom;
|
||||
|
||||
public class DOMGarbageCollector {
|
||||
import java.security.BasicPermission;
|
||||
|
||||
// private static native void doGC();
|
||||
public static native void doGC();
|
||||
public final class JavaDOMPermission extends BasicPermission {
|
||||
public JavaDOMPermission(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public JavaDOMPermission(String name, String actions)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.applet.Applet;
|
||||
import org.w3c.dom.Document;
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
import org.mozilla.dom.util.DOMTreeDumper;
|
||||
import org.mozilla.dom.util.GenericDocLoadListener;
|
||||
|
||||
public class DOMTreeDumperApplet extends Applet
|
||||
{
|
||||
private DOMAccessor accessor;
|
||||
private final String name = "DOMTreeDumperApplet";
|
||||
|
||||
public void init()
|
||||
{
|
||||
DOMAccessor.addDocumentLoadListener(new DOMTreeDumperListener(name));
|
||||
System.out.println(name + " init...");
|
||||
}
|
||||
|
||||
class DOMTreeDumperListener extends GenericDocLoadListener {
|
||||
public DOMTreeDumperListener(String name) {
|
||||
super(name);
|
||||
}
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
new DOMTreeDumper(name).dumpToStream(System.out, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,20 +23,16 @@ package org.mozilla.dom.tests;
|
||||
|
||||
import java.applet.Applet;
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
import org.mozilla.dom.DOMAccessorImpl;
|
||||
import org.mozilla.dom.tests.TestDocLoadListener;
|
||||
import org.mozilla.dom.util.GenericDocLoadListener;
|
||||
|
||||
public class TestDOMAccessorApplet extends java.applet.Applet
|
||||
{
|
||||
private DOMAccessor accessor;
|
||||
|
||||
private final String name = "TestDOMAccessorApplet";
|
||||
|
||||
public void init()
|
||||
{
|
||||
accessor = DOMAccessorImpl.getInstance();
|
||||
accessor.addDocumentLoadListener(
|
||||
new TestDocLoadListener("TestDOMAccessorApplet"));
|
||||
System.out.println("inited......");
|
||||
System.out.println("accsessor: " + accessor);
|
||||
DOMAccessor.addDocumentLoadListener(new GenericDocLoadListener(name));
|
||||
System.out.println(name + " init...");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.applet.Applet;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
import org.w3c.dom.events.EventTarget;
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
import org.mozilla.dom.NodeImpl;
|
||||
import org.mozilla.dom.util.GenericEventListener;
|
||||
import org.mozilla.dom.util.GenericDocLoadListener;
|
||||
|
||||
public class TestDOMEventsApplet extends Applet {
|
||||
|
||||
private final String name = "TestDOMEventsApplet";
|
||||
|
||||
public void init()
|
||||
{
|
||||
DOMAccessor.addDocumentLoadListener(new TestDOMEventsListener(name));
|
||||
System.out.println(name + " init...");
|
||||
}
|
||||
|
||||
class TestDOMEventsListener extends GenericDocLoadListener {
|
||||
public TestDOMEventsListener(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
if (url.endsWith(".html")){
|
||||
Vector v;
|
||||
Object o;
|
||||
Node n;
|
||||
NodeList l;
|
||||
int i;
|
||||
EventListener listener;
|
||||
NodeImpl target;
|
||||
String [] types = {"mouseover", "dblclick", "mouseout", "keydown", "keyup",
|
||||
"mousedown", "mouseup", "click", "keypress",
|
||||
"mousemove", "focus", "blur", "submit", "reset",
|
||||
"change", "select", "input", "load", "unload",
|
||||
"abort", "error", "paint", "create", "destroy",
|
||||
"command", "broadcast", "commandupdate",
|
||||
"dragenter", "dragover", "dragexit", "dragdrop",
|
||||
"draggesture"};
|
||||
|
||||
listener = new GenericEventListener("name");
|
||||
v = new Vector (20, 10);
|
||||
v.add(doc);
|
||||
|
||||
while(!v.isEmpty()) {
|
||||
o = v.elementAt(0);
|
||||
if (o instanceof Node) {
|
||||
n = (Node) o;
|
||||
if (n instanceof NodeImpl)
|
||||
for(i=0; i < types.length; i++) {
|
||||
target = (NodeImpl) n;
|
||||
target.addEventListener(types[i], listener, false);
|
||||
}
|
||||
|
||||
l = n.getChildNodes();
|
||||
for(i=0; i<l.getLength(); i++)
|
||||
v.add(l.item(i));
|
||||
}
|
||||
v.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
java/dom/classes/org/mozilla/dom/tests/TestRunnerApplet.java
Normal file
58
java/dom/classes/org/mozilla/dom/tests/TestRunnerApplet.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.applet.Applet;
|
||||
import org.w3c.dom.Document;
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
import org.mozilla.dom.util.DOMTreeDumper;
|
||||
import org.mozilla.dom.util.GenericDocLoadListener;
|
||||
import org.mozilla.dom.test.TestLoader;
|
||||
|
||||
public class TestRunnerApplet extends Applet {
|
||||
|
||||
private final String name = "TestRunnerApplet";
|
||||
|
||||
public void init()
|
||||
{
|
||||
DOMAccessor.addDocumentLoadListener(new TestRunnerListener(name));
|
||||
System.out.println(name + " init...");
|
||||
}
|
||||
|
||||
private void runTests(Document doc) {
|
||||
Object obj = (Object) doc;
|
||||
TestLoader tl = new TestLoader(obj, 0);
|
||||
if (tl != null) {
|
||||
Object retobj = tl.loadTest();
|
||||
}
|
||||
}
|
||||
|
||||
class TestRunnerListener extends GenericDocLoadListener {
|
||||
public TestRunnerListener(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
runTests(doc);
|
||||
}
|
||||
}
|
||||
}
|
231
java/dom/classes/org/mozilla/dom/util/DOMTreeDumper.java
Normal file
231
java/dom/classes/org/mozilla/dom/util/DOMTreeDumper.java
Normal file
@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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.dom.util;
|
||||
|
||||
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 name;
|
||||
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("DOMTreeDumper", true);
|
||||
}
|
||||
|
||||
public DOMTreeDumper(boolean debug) {
|
||||
this("DOMTreeDumper", debug);
|
||||
}
|
||||
|
||||
public DOMTreeDumper(String name) {
|
||||
this(name, true);
|
||||
}
|
||||
|
||||
public DOMTreeDumper(String name, boolean debug) {
|
||||
this.name = name;
|
||||
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...");
|
||||
}
|
||||
|
||||
public void dumpToStream(PrintStream ps, Document doc) {
|
||||
this.ps = ps;
|
||||
dbg("dumping to stream...");
|
||||
dumpDocument(doc);
|
||||
dbg("finished dumping...");
|
||||
}
|
||||
|
||||
private void dbg(String str) {
|
||||
if (debug) {
|
||||
System.out.println(name + ": " + str);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.util;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import org.w3c.dom.Document;
|
||||
import org.mozilla.dom.DocumentLoadListener;
|
||||
|
||||
public class GenericDocLoadListener implements DocumentLoadListener {
|
||||
|
||||
private String name;
|
||||
private PrintStream ps;
|
||||
|
||||
public GenericDocLoadListener() {
|
||||
this("GenericDocLoadListener",
|
||||
new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericDocLoadListener(String name) {
|
||||
this(name,
|
||||
new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericDocLoadListener(PrintStream ps) {
|
||||
this("GenericDocLoadListener", ps);
|
||||
}
|
||||
|
||||
public GenericDocLoadListener(String name, PrintStream ps) {
|
||||
this.name = name;
|
||||
this.ps = ps;
|
||||
}
|
||||
|
||||
public DocumentLoadListener getDocumentLoadListener() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void startURLLoad(String url, String contentType, Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :start URL load - " +
|
||||
url.toString() + " " +
|
||||
contentType);
|
||||
}
|
||||
}
|
||||
|
||||
public void endURLLoad(String url, int status, Document doc) {
|
||||
|
||||
if (ps != null) {
|
||||
ps.println(name + " :end URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
}
|
||||
|
||||
public void progressURLLoad(String url, int progress, int progressMax,
|
||||
Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :progress URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toString(progress) + "/" +
|
||||
Integer.toString(progressMax));
|
||||
}
|
||||
}
|
||||
|
||||
public void statusURLLoad(String url, String message, Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :status URL load - " +
|
||||
url.toString() + " (" +
|
||||
message + ")");
|
||||
}
|
||||
}
|
||||
|
||||
public void startDocumentLoad(String url) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :start doc load - " +
|
||||
url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :end doc load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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):
|
||||
*
|
||||
*/
|
||||
package org.mozilla.dom.util;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
|
||||
public class GenericEventListener implements EventListener {
|
||||
|
||||
private String name;
|
||||
private PrintStream ps;
|
||||
|
||||
public GenericEventListener() {
|
||||
this("GenericEventListener",
|
||||
new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericEventListener(String name) {
|
||||
this(name, new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericEventListener(PrintStream ps) {
|
||||
this("GenericEventListener", ps);
|
||||
}
|
||||
|
||||
public GenericEventListener(String name, PrintStream ps) {
|
||||
this.name = name;
|
||||
this.ps = ps;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called whenever an event occurs of the type for which the
|
||||
* <code> EventListener</code> interface was registered.
|
||||
* @param event The <code>Event</code> contains contextual information about
|
||||
* the event. It also contains the <code>returnValue</code> and
|
||||
* <code>cancelBubble</code> properties which are used in determining
|
||||
* proper event flow.
|
||||
*/
|
||||
public void handleEvent(Event event) {
|
||||
try {
|
||||
if (ps != null) {
|
||||
ps.println(name + ": got event " + event);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (ps != null) {
|
||||
ps.println(name + ": exception in handleEvent " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ CPPSRCS = \
|
||||
javaDOMGlobals.cpp \
|
||||
javaDOMEventsGlobals.cpp \
|
||||
nativeDOMProxyListener.cpp \
|
||||
org_mozilla_dom_DOMGarbageCollector.cpp \
|
||||
org_mozilla_dom_DOMAccessorImpl.cpp \
|
||||
org_mozilla_dom_DOMAccessor.cpp \
|
||||
org_mozilla_dom_AttrImpl.cpp \
|
||||
org_mozilla_dom_CharacterDataImpl.cpp \
|
||||
org_mozilla_dom_DocumentImpl.cpp \
|
||||
|
@ -32,8 +32,7 @@ CPPSRCS = \
|
||||
javaDOMGlobals.cpp \
|
||||
javaDOMEventsGlobals.cpp \
|
||||
nativeDOMProxyListener.cpp \
|
||||
org_mozilla_dom_DOMGarbageCollector.cpp \
|
||||
org_mozilla_dom_DOMAccessorImpl.cpp \
|
||||
org_mozilla_dom_DOMAccessor.cpp \
|
||||
org_mozilla_dom_AttrImpl.cpp \
|
||||
org_mozilla_dom_CharacterDataImpl.cpp \
|
||||
org_mozilla_dom_DocumentImpl.cpp \
|
||||
|
@ -1,60 +0,0 @@
|
||||
Index: DOMFactory.java
|
||||
===================================================================
|
||||
RCS file: /cvsroot/mozilla/java/dom/jni/DOMFactory.java,v
|
||||
retrieving revision 1.2
|
||||
diff -r1.2 DOMFactory.java
|
||||
23a24,25
|
||||
> import java.util.Vector;
|
||||
>
|
||||
30a33,37
|
||||
> import org.w3c.dom.events.TestEventListener;
|
||||
> import org.w3c.dom.events.EventListener;
|
||||
> import org.w3c.dom.events.EventTarget;
|
||||
> import org.mozilla.dom.NodeImpl;
|
||||
>
|
||||
76c83,84
|
||||
<
|
||||
---
|
||||
>
|
||||
>
|
||||
108a117,156
|
||||
> if (url.endsWith("test.html")){
|
||||
> System.out.println("TestCases Tuned to run with test.html...");
|
||||
> Vector v;
|
||||
> Object o;
|
||||
> Node n;
|
||||
> NodeList l;
|
||||
> int i;
|
||||
> EventListener listener;
|
||||
> NodeImpl target;
|
||||
> String [] types = {"mouseover", "dblclick", "mouseout", "keydown", "keyup",
|
||||
> "mousedown", "mouseup", "click", "keypress",
|
||||
> "mousemove", "focus", "blur", "submit", "reset",
|
||||
> "change", "select", "input", "load", "unload",
|
||||
> "abort", "error", "paint", "create", "destroy",
|
||||
> "command", "broadcast", "commandupdate",
|
||||
> "dragenter", "dragover", "dragexit", "dragdrop",
|
||||
> "draggesture"};
|
||||
>
|
||||
> listener = new TestEventListener();
|
||||
> v = new Vector (20, 10);
|
||||
> v.add(doc);
|
||||
>
|
||||
> while(!v.isEmpty()) {
|
||||
> o = v.elementAt(0);
|
||||
> if (o instanceof Node) {
|
||||
> n = (Node) o;
|
||||
> if (n instanceof NodeImpl)
|
||||
> for(i=0; i < types.length; i++) {
|
||||
> target = (NodeImpl) n;
|
||||
> target.addEventListener(types[i], listener, false);
|
||||
> // target.removeEventListener(types[i], listener, false);
|
||||
> }
|
||||
>
|
||||
> l = n.getChildNodes();
|
||||
> for(i=0; i<l.getLength(); i++)
|
||||
> v.add(l.item(i));
|
||||
> }
|
||||
> v.remove(0);
|
||||
> }
|
||||
> }
|
@ -1,28 +0,0 @@
|
||||
package org.w3c.dom.events;
|
||||
|
||||
import org.w3c.dom.events.EventListener;
|
||||
import org.w3c.dom.events.Event;
|
||||
|
||||
public class TestEventListener implements EventListener {
|
||||
|
||||
|
||||
public TestEventListener() {};
|
||||
|
||||
/**
|
||||
* This method is called whenever an event occurs of the type for which the
|
||||
* <code> EventListener</code> interface was registered.
|
||||
* @param event The <code>Event</code> contains contextual information about
|
||||
* the event. It also contains the <code>returnValue</code> and
|
||||
* <code>cancelBubble</code> properties which are used in determining
|
||||
* proper event flow.
|
||||
*/
|
||||
public void handleEvent(Event event) {
|
||||
try {
|
||||
System.out.println("In JAVA: Got event" + event);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Got exception in handleEvent "+e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ CPPSRCS= \
|
||||
javaDOMGlobals.cpp \
|
||||
javaDOMEventsGlobals.cpp \
|
||||
nativeDOMProxyListener.cpp \
|
||||
org_mozilla_dom_DOMAccessorImpl.cpp \
|
||||
org_mozilla_dom_DOMGarbageCollector.cpp \
|
||||
org_mozilla_dom_DOMAccessor.cpp \
|
||||
org_mozilla_dom_AttrImpl.cpp \
|
||||
org_mozilla_dom_CharacterDataImpl.cpp \
|
||||
org_mozilla_dom_DocumentImpl.cpp \
|
||||
@ -53,8 +52,7 @@ CPP_OBJS= \
|
||||
.\$(OBJDIR)\javaDOMGlobals.obj \
|
||||
.\$(OBJDIR)\javaDOMEventsGlobals.obj \
|
||||
.\$(OBJDIR)\nativeDOMProxyListener.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DOMAccessorImpl.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DOMGarbageCollector.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DOMAccessor.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_AttrImpl.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_CharacterDataImpl.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DocumentImpl.obj \
|
||||
|
@ -7,17 +7,17 @@
|
||||
#include "nsCURILoader.h"
|
||||
|
||||
#include "nsIJavaDOM.h"
|
||||
#include "org_mozilla_dom_DOMAccessorImpl.h"
|
||||
#include "org_mozilla_dom_DOMAccessor.h"
|
||||
|
||||
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
||||
static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: register
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_register
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_register
|
||||
(JNIEnv *env, jclass jthis)
|
||||
{
|
||||
if (!JavaDOMGlobals::log) {
|
||||
@ -47,11 +47,11 @@ JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_register
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: unregister
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_unregister
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_unregister
|
||||
(JNIEnv *, jclass jthis)
|
||||
{
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG,
|
||||
@ -81,11 +81,11 @@ JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_unregister
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: createElement
|
||||
* Signature: (J)Lorg/w3c/dom/Element;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessorImpl_getElementByHandle
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessor_getNodeByHandle
|
||||
(JNIEnv *env, jclass jthis, jlong p)
|
||||
{
|
||||
if (!JavaDOMGlobals::log) {
|
||||
@ -94,3 +94,16 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessorImpl_getElementByHandl
|
||||
nsIDOMNode *node = (nsIDOMNode*)p;
|
||||
return JavaDOMGlobals::CreateNodeSubtype(env, node);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: doGC
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_doGC
|
||||
(JNIEnv *, jclass)
|
||||
{
|
||||
JavaDOMGlobals::TakeOutGarbage();
|
||||
}
|
||||
|
||||
|
47
java/dom/jni/org_mozilla_dom_DOMAccessor.h
Normal file
47
java/dom/jni/org_mozilla_dom_DOMAccessor.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_mozilla_dom_DOMAccessor */
|
||||
|
||||
#ifndef _Included_org_mozilla_dom_DOMAccessor
|
||||
#define _Included_org_mozilla_dom_DOMAccessor
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Inaccessible static: documentLoadListeners */
|
||||
/* Inaccessible static: permission */
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: register
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_register
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: unregister
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_unregister
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: getNodeByHandle
|
||||
* Signature: (J)Lorg/w3c/dom/Node;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessor_getNodeByHandle
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: doGC
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_doGC
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_mozilla_dom_DOMAccessorImpl */
|
||||
|
||||
#ifndef _Included_org_mozilla_dom_DOMAccessorImpl
|
||||
#define _Included_org_mozilla_dom_DOMAccessorImpl
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Inaccessible static: instance */
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
* Method: register
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_register
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
* Method: unregister
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_unregister
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
* Method: getElementByHandle
|
||||
* Signature: (J)Lorg/w3c/dom/Element;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessorImpl_getElementByHandle
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
#include "org_mozilla_dom_DOMGarbageCollector.h"
|
||||
#include "javaDOMGlobals.h"
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMGarbageCollector
|
||||
* Method: doGC
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMGarbageCollector_doGC
|
||||
(JNIEnv *, jclass)
|
||||
{
|
||||
JavaDOMGlobals::TakeOutGarbage();
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_mozilla_dom_DOMGarbageCollector */
|
||||
|
||||
#ifndef _Included_org_mozilla_dom_DOMGarbageCollector
|
||||
#define _Included_org_mozilla_dom_DOMGarbageCollector
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMGarbageCollector
|
||||
* Method: doGC
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMGarbageCollector_doGC
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -1,28 +1,25 @@
|
||||
Index: nsWebShell.cpp
|
||||
===================================================================
|
||||
RCS file: /cvsroot/mozilla/webshell/src/nsWebShell.cpp,v
|
||||
retrieving revision 1.377
|
||||
diff -r1.377 nsWebShell.cpp
|
||||
70a71
|
||||
>
|
||||
97a99,106
|
||||
retrieving revision 1.429
|
||||
diff -r1.429 nsWebShell.cpp
|
||||
111a112,116
|
||||
> #ifdef JAVA_DOM
|
||||
> #include "nsIJavaDOM.h"
|
||||
> static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
|
||||
> static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID);
|
||||
> #endif // JAVA_DOM
|
||||
3107a3113,3125
|
||||
>
|
||||
>
|
||||
>
|
||||
566a576
|
||||
>
|
||||
984a995,1003
|
||||
> #ifdef JAVA_DOM
|
||||
> nsresult jrv = NS_OK;
|
||||
> NS_WITH_SERVICE(nsISupports, javaDOM, kJavaDOMCID, &jrv);
|
||||
> NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &jrv);
|
||||
> if (NS_FAILED(jrv) || !javaDOM) {
|
||||
> fprintf(stderr,
|
||||
> "nsWebShell::Init: GetService of JavaDOM failed (error %x)\n",
|
||||
> jrv);
|
||||
> } else {
|
||||
> printf("\n webshell: added JAVADOM as observer...\n");
|
||||
> mDocLoader->AddObserver(javaDOM);
|
||||
> }
|
||||
> #endif // JAVA_DOM
|
||||
|
@ -34,11 +34,6 @@
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
#include "ProxyJNI.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
#include <stdio.h>
|
||||
#include "nsIDOMElement.h"
|
||||
@ -53,8 +48,15 @@ static const char* describe_type(int type);
|
||||
#endif
|
||||
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
#include "ProxyJNI.h"
|
||||
#include "nsIServiceManager.h"
|
||||
nsJVMManager* nsJavaDOMImpl::jvmManager = NULL;
|
||||
JavaDOMSecurityContext* nsJavaDOMImpl::securityContext = NULL;
|
||||
static NS_DEFINE_CID(kJVMManagerCID,NS_JVMMANAGER_CID);
|
||||
#else
|
||||
JavaVM* nsJavaDOMImpl::jvm = NULL;
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_IID(kIDocShellIID, NS_IDOCSHELL_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID);
|
||||
@ -65,6 +67,14 @@ static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_I
|
||||
NS_IMPL_ADDREF(nsJavaDOMImpl);
|
||||
NS_IMPL_RELEASE(nsJavaDOMImpl);
|
||||
|
||||
jclass nsJavaDOMImpl::domAccessorClass = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::startURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::progressURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::statusURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startDocumentLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endDocumentLoadMID = NULL;
|
||||
|
||||
#define NS_JAVADOM_PROGID \
|
||||
"component://netscape/blackwood/java-dom"
|
||||
@ -83,8 +93,6 @@ static nsModuleComponentInfo components[] =
|
||||
|
||||
NS_IMPL_NSGETMODULE("JavaDOMModule",components);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::QueryInterface(REFNSIID aIID, void** aInstance)
|
||||
{
|
||||
if (NULL == aInstance)
|
||||
@ -111,126 +119,77 @@ NS_IMETHODIMP nsJavaDOMImpl::QueryInterface(REFNSIID aIID, void** aInstance)
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
nsJVMManager* nsJavaDOMImpl::jvmManager = NULL;
|
||||
JavaDOMSecurityContext* nsJavaDOMImpl::securityContext = NULL;
|
||||
#else
|
||||
JavaVM* nsJavaDOMImpl::jvm = NULL;
|
||||
#endif
|
||||
|
||||
jclass nsJavaDOMImpl::domAccessorClass = NULL;
|
||||
jclass nsJavaDOMImpl::documentClass = NULL;
|
||||
jclass nsJavaDOMImpl::listenerClass = NULL;
|
||||
jclass nsJavaDOMImpl::gcClass = NULL;
|
||||
|
||||
jobject nsJavaDOMImpl::docListener = NULL;
|
||||
|
||||
jfieldID nsJavaDOMImpl::documentPtrFID = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::documentInitID = NULL;
|
||||
jmethodID nsJavaDOMImpl::getInstanceMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::progressURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::statusURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startDocumentLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endDocumentLoadMID = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::gcMID = NULL;
|
||||
|
||||
nsJavaDOMImpl::nsJavaDOMImpl()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
PRBool nsJavaDOMImpl::Init(JNIEnv** jniEnv) {
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
if (!env) return PR_FALSE;
|
||||
*jniEnv = env;
|
||||
|
||||
gcClass = env->FindClass("org/mozilla/dom/DOMGarbageCollector");
|
||||
if (!gcClass) return;
|
||||
gcClass = (jclass) env->NewGlobalRef(gcClass);
|
||||
if (!gcClass) return;
|
||||
if (!domAccessorClass) {
|
||||
domAccessorClass = env->FindClass("org/mozilla/dom/DOMAccessor");
|
||||
if (!domAccessorClass) return PR_FALSE;
|
||||
domAccessorClass = (jclass) env->NewGlobalRef(domAccessorClass);
|
||||
if (!domAccessorClass) return PR_FALSE;
|
||||
|
||||
gcMID =
|
||||
env->GetStaticMethodID(gcClass,
|
||||
"doGC",
|
||||
"()V");
|
||||
if (!gcMID) return;
|
||||
startURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"startURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;J)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
endURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"endURLLoad",
|
||||
"(Ljava/lang/String;IJ)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
domAccessorClass = env->FindClass("org/mozilla/dom/DOMAccessorImpl");
|
||||
if (!domAccessorClass) return;
|
||||
domAccessorClass = (jclass) env->NewGlobalRef(domAccessorClass);
|
||||
if (!domAccessorClass) return;
|
||||
progressURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"progressURLLoad",
|
||||
"(Ljava/lang/String;IIJ)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
getInstanceMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"getInstance",
|
||||
"()Lorg/mozilla/dom/DOMAccessor;");
|
||||
if (!getInstanceMID) return;
|
||||
|
||||
docListener =
|
||||
env->CallStaticObjectMethod(domAccessorClass, getInstanceMID);
|
||||
if (!docListener) return;
|
||||
docListener = (jclass) env->NewGlobalRef(docListener);
|
||||
if (!docListener) return;
|
||||
|
||||
listenerClass =
|
||||
env->GetObjectClass(docListener);
|
||||
if (!listenerClass) return;
|
||||
listenerClass = (jclass) env->NewGlobalRef(listenerClass);
|
||||
if (!listenerClass) return;
|
||||
|
||||
documentClass =
|
||||
env->FindClass("org/mozilla/dom/DocumentImpl");
|
||||
if (!documentClass) return;
|
||||
documentClass = (jclass) env->NewGlobalRef(documentClass);
|
||||
if (!documentClass) return;
|
||||
|
||||
documentInitID =
|
||||
env->GetMethodID(documentClass, "<init>", "(J)V");
|
||||
if (!documentInitID) return;
|
||||
|
||||
documentPtrFID =
|
||||
env->GetFieldID(documentClass,
|
||||
"p_nsIDOMNode",
|
||||
"J");
|
||||
if (!documentPtrFID) return;
|
||||
|
||||
startURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"startURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Lorg/w3c/dom/Document;)V");
|
||||
if (!startURLLoadMID) return;
|
||||
|
||||
endURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"endURLLoad",
|
||||
"(Ljava/lang/String;ILorg/w3c/dom/Document;)V");
|
||||
if (!endURLLoadMID) return;
|
||||
|
||||
progressURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"progressURLLoad",
|
||||
"(Ljava/lang/String;IILorg/w3c/dom/Document;)V");
|
||||
if (!progressURLLoadMID) return;
|
||||
|
||||
statusURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"statusURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Lorg/w3c/dom/Document;)V");
|
||||
if (!statusURLLoadMID) return;
|
||||
|
||||
startDocumentLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"startDocumentLoad",
|
||||
"(Ljava/lang/String;)V");
|
||||
if (!startDocumentLoadMID) return;
|
||||
|
||||
endDocumentLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"endDocumentLoad",
|
||||
"(Ljava/lang/String;ILorg/w3c/dom/Document;)V");
|
||||
if (!endDocumentLoadMID) return;
|
||||
|
||||
Cleanup(env);
|
||||
statusURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"statusURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;J)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
startDocumentLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"startDocumentLoad",
|
||||
"(Ljava/lang/String;)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
endDocumentLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"endDocumentLoad",
|
||||
"(Ljava/lang/String;IJ)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsJavaDOMImpl::~nsJavaDOMImpl()
|
||||
@ -243,7 +202,6 @@ PRBool nsJavaDOMImpl::Cleanup(JNIEnv* env)
|
||||
env->ExceptionDescribe();
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
@ -290,43 +248,23 @@ nsIDOMDocument* nsJavaDOMImpl::GetDocument(nsIDocumentLoader* loader)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// convert nsIDOMDocument to org.mozilla.dom.DocumentImpl
|
||||
jobject nsJavaDOMImpl::CaffienateDOMDocument(nsIDOMDocument* domDoc)
|
||||
{
|
||||
if (!domDoc) return NULL;
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
|
||||
// jobject jdoc = env->AllocObject(documentClass);
|
||||
jobject jdoc = env->NewObject(documentClass,
|
||||
documentInitID,
|
||||
(jlong) (void*) domDoc);
|
||||
if (!jdoc) return NULL;
|
||||
// env->SetLongField(jdoc, documentPtrFID, (jlong) (void*) domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NULL;
|
||||
|
||||
return jdoc;
|
||||
}
|
||||
|
||||
/* nsIDocumentLoaderObserver methods */
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnStartDocumentLoad(nsIDocumentLoader* loader,
|
||||
nsIURI* aURL,
|
||||
const char* aCommand)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
startDocumentLoadMID,
|
||||
jURL);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
startDocumentLoadMID,
|
||||
jURL);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -334,7 +272,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
@ -343,24 +283,21 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
endDocumentLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
endDocumentLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
@ -377,17 +314,12 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
if (!jContentType) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
startURLLoadMID,
|
||||
jURL,
|
||||
jContentType,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
startURLLoadMID,
|
||||
jURL,
|
||||
jContentType,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -396,7 +328,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
@ -405,18 +339,13 @@ NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
progressURLLoadMID,
|
||||
jURL,
|
||||
(jint) aProgress,
|
||||
(jint) aProgressMax,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
progressURLLoadMID,
|
||||
jURL,
|
||||
(jint) aProgress,
|
||||
(jint) aProgressMax,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -424,7 +353,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
nsString& aMsg)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
@ -437,17 +368,12 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
if (!jMessage) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
statusURLLoadMID,
|
||||
jURL,
|
||||
jMessage,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
statusURLLoadMID,
|
||||
jURL,
|
||||
jMessage,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -455,7 +381,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
@ -464,21 +392,15 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
#if defined(DEBUG)
|
||||
dump_document(domDoc, urlSpec);
|
||||
#endif
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
endURLLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
endURLLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -487,13 +409,9 @@ NS_IMETHODIMP nsJavaDOMImpl::HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
const char *aContentType,
|
||||
const char *aCommand)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
JNIEnv* nsJavaDOMImpl::GetJNIEnv() {
|
||||
JNIEnv* env;
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
@ -511,7 +429,7 @@ JNIEnv* nsJavaDOMImpl::GetJNIEnv() {
|
||||
// if (!securityContext) {
|
||||
// securityContext = new JavaDOMSecurityContext();
|
||||
// }
|
||||
// SetSecurityContext(env,securityContext);
|
||||
// SetSecurityContext(env, securityContext);
|
||||
SetSecurityContext(env, new JavaDOMSecurityContext());
|
||||
#else /* JAVA_DOM_OJI_ENABLE */
|
||||
if (!jvm) {
|
||||
|
@ -58,16 +58,7 @@ class nsJavaDOMImpl : public nsIJavaDOM {
|
||||
#endif
|
||||
|
||||
static jclass domAccessorClass;
|
||||
static jclass documentClass;
|
||||
static jclass listenerClass;
|
||||
static jclass gcClass;
|
||||
|
||||
static jobject docListener;
|
||||
|
||||
static jfieldID documentPtrFID;
|
||||
static jmethodID documentInitID;
|
||||
|
||||
static jmethodID getInstanceMID;
|
||||
static jmethodID startURLLoadMID;
|
||||
static jmethodID endURLLoadMID;
|
||||
static jmethodID progressURLLoadMID;
|
||||
@ -75,14 +66,12 @@ class nsJavaDOMImpl : public nsIJavaDOM {
|
||||
static jmethodID startDocumentLoadMID;
|
||||
static jmethodID endDocumentLoadMID;
|
||||
|
||||
static jmethodID gcMID;
|
||||
|
||||
// cleanup after a JNI method invocation
|
||||
static PRBool Cleanup(JNIEnv* env);
|
||||
static JNIEnv* GetJNIEnv(void);
|
||||
static void StartJVM(void);
|
||||
static PRBool Init(JNIEnv**);
|
||||
// cleanup after a JNI method invocation
|
||||
static PRBool Cleanup(JNIEnv* env);
|
||||
nsIDOMDocument* GetDocument(nsIDocumentLoader* loader);
|
||||
jobject CaffienateDOMDocument(nsIDOMDocument* domDoc);
|
||||
};
|
||||
|
||||
#endif /* __nsJavaDOMImpl_h__ */
|
||||
|
@ -1,219 +0,0 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
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;
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
import org.mozilla.dom.DOMAccessorImpl;
|
||||
import org.mozilla.dom.DocumentLoadListener;
|
||||
import org.mozilla.dom.tests.TestDocLoadListener;
|
||||
import org.mozilla.dom.test.*;
|
||||
|
||||
public class TestDOMAccessorApplet1 extends Applet implements DocumentLoadListener
|
||||
{
|
||||
private DOMAccessor accessor;
|
||||
private static final boolean debug = true;
|
||||
private static final String prefix = "TestDOMAccessorApplet1: ";
|
||||
|
||||
public void init()
|
||||
{
|
||||
accessor = DOMAccessorImpl.getInstance();
|
||||
accessor.addDocumentLoadListener(this);
|
||||
System.out.println("inited......");
|
||||
System.out.println("accsessor: " + accessor);
|
||||
}
|
||||
|
||||
public void startURLLoad(String url, String contentType, Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + "start URL load - " +
|
||||
url.toString() + " " +
|
||||
contentType);
|
||||
}
|
||||
|
||||
public void endURLLoad(String url, int status, Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + "end URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
|
||||
public void progressURLLoad(String url, int progress, int progressMax,
|
||||
Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + "progress URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toString(progress) + "/" +
|
||||
Integer.toString(progressMax));
|
||||
}
|
||||
|
||||
public void statusURLLoad(String url, String message, Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + "status URL load - " +
|
||||
url.toString() + " (" +
|
||||
message + ")");
|
||||
}
|
||||
|
||||
public void startDocumentLoad(String url) {
|
||||
if (debug)
|
||||
System.err.println(prefix + "start load - " +
|
||||
url.toString());
|
||||
}
|
||||
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
if (debug) {
|
||||
System.err.println(prefix + "end load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
dumpDocument(url, doc);
|
||||
//runTests(doc);
|
||||
}
|
||||
|
||||
private void dump(PrintStream ps, Node node, int indent, boolean isMapNode) {
|
||||
if (node == null) return;
|
||||
|
||||
ps.println();
|
||||
for (int i=0; i<indent; i++)
|
||||
ps.print(' ');
|
||||
|
||||
ps.print("name=\"" + node.getNodeName() + "\"" +
|
||||
" type=" + dumpType(node.getNodeType()) +
|
||||
" value=\"" + stripWhiteSpace(node.getNodeValue()) + "\"");
|
||||
|
||||
if (isMapNode) return;
|
||||
|
||||
NamedNodeMap map = node.getAttributes();
|
||||
dumpMap(ps, map, indent);
|
||||
|
||||
NodeList children = node.getChildNodes();
|
||||
if (children == null) return;
|
||||
|
||||
/*
|
||||
Node fc = node.getFirstChild();
|
||||
if (fc != null)
|
||||
System.out.println("firstchild=" + fc.toString());
|
||||
Node lc = node.getLastChild();
|
||||
if (lc != null)
|
||||
System.out.println("lastchild=" + lc.toString());
|
||||
*/
|
||||
|
||||
int length = children.getLength();
|
||||
for (int i=0; i < length; i++) {
|
||||
dump(ps, children.item(i), indent+2, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpMap(PrintStream ps, NamedNodeMap map, int indent) {
|
||||
if (map == null) return;
|
||||
|
||||
ps.println();
|
||||
int length = map.getLength();
|
||||
if (length > 0) {
|
||||
for (int i=0; i<indent; i++)
|
||||
ps.print(' ');
|
||||
ps.print("------- start attributes -------");
|
||||
}
|
||||
|
||||
for (int i=0; i < length; i++) {
|
||||
Node item = map.item(i);
|
||||
dump(ps, item, indent, true);
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
ps.println();
|
||||
for (int i=0; i<indent; i++)
|
||||
ps.print(' ');
|
||||
ps.print("------- end attributes -------");
|
||||
}
|
||||
}
|
||||
|
||||
private static String dumpType(int type) {
|
||||
switch (type) {
|
||||
case Node.ELEMENT_NODE: return "ELEMENT";
|
||||
case Node.ATTRIBUTE_NODE: return "ATTRIBUTE";
|
||||
case Node.TEXT_NODE: return "TEXT";
|
||||
case Node.CDATA_SECTION_NODE: return "CDATA_SECTION";
|
||||
case Node.ENTITY_REFERENCE_NODE: return "ENTITY_REFERENCE";
|
||||
case Node.ENTITY_NODE: return "ENTITY";
|
||||
case Node.PROCESSING_INSTRUCTION_NODE: return "PROCESSING_INSTRUCTION";
|
||||
case Node.COMMENT_NODE: return "COMMENT";
|
||||
case Node.DOCUMENT_NODE: return "DOCUMENT";
|
||||
case Node.DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE";
|
||||
case Node.DOCUMENT_FRAGMENT_NODE: return "DOCUMENT_FRAGMENT";
|
||||
case Node.NOTATION_NODE: return "NOTATION";
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
private static String stripWhiteSpace(String s) {
|
||||
int len = s.length();
|
||||
StringBuffer sb = new StringBuffer(len);
|
||||
char c = ' ';
|
||||
char pc = ' ';
|
||||
for (int i=0; i < len; i++) {
|
||||
c = s.charAt(i);
|
||||
if ((pc == ' ' || pc == '\n' || pc == '\t') &&
|
||||
(c == ' ' || c == '\n' || c == '\t'))
|
||||
continue;
|
||||
sb.append(c);
|
||||
pc = c;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void dumpDocument(String url, Document doc) {
|
||||
if (!(url.endsWith(".xml") || url.endsWith(".html"))) return;
|
||||
if (doc == null) return;
|
||||
Element element = doc.getDocumentElement();
|
||||
if (element == null) return;
|
||||
element.normalize();
|
||||
|
||||
PrintStream ps = null;
|
||||
ps = new PrintStream(new BufferedOutputStream(System.out, 1024));
|
||||
ps.println("\n+++ " + url.toString() + " +++");
|
||||
|
||||
dump(ps, element, 0, false);
|
||||
ps.println();
|
||||
ps.flush();
|
||||
|
||||
element = null;
|
||||
doc = null;
|
||||
}
|
||||
|
||||
private void runTests(Document doc) {
|
||||
Object obj = (Object) doc;
|
||||
TestLoader tl = new TestLoader(obj, 0);
|
||||
if (tl != null) {
|
||||
Object retobj = tl.loadTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,211 +0,0 @@
|
||||
/*
|
||||
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 mozilla.org code.
|
||||
|
||||
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):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
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;
|
||||
|
||||
import org.mozilla.dom.DocumentLoadListener;
|
||||
|
||||
public class TestDocLoadListener implements DocumentLoadListener {
|
||||
|
||||
private static final boolean debug = true;
|
||||
private static String prefix = "TestDocLoadListener";
|
||||
|
||||
public TestDocLoadListener(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public DocumentLoadListener getDocumentLoadListener() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void startURLLoad(String url, String contentType, Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + "start URL load - " +
|
||||
url.toString() + " " +
|
||||
contentType);
|
||||
}
|
||||
|
||||
public void endURLLoad(String url, int status, Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + " :end URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
|
||||
if (!(url.endsWith(".xml") || url.endsWith(".html"))) return;
|
||||
|
||||
if (doc == null) return;
|
||||
Element element = doc.getDocumentElement();
|
||||
if (element == null) return;
|
||||
element.normalize();
|
||||
|
||||
FileOutputStream fos = null;
|
||||
PrintStream ps = null;
|
||||
try {
|
||||
fos = new FileOutputStream("dom-java.txt", true);
|
||||
ps = new PrintStream(new BufferedOutputStream(fos, 1024));
|
||||
ps.println("\n+++ " + url.toString() + " +++");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
dump(ps, element, 0, false);
|
||||
ps.println();
|
||||
ps.flush();
|
||||
|
||||
element = null;
|
||||
doc = null;
|
||||
}
|
||||
|
||||
public void progressURLLoad(String url, int progress, int progressMax,
|
||||
Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + " :progress URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toString(progress) + "/" +
|
||||
Integer.toString(progressMax));
|
||||
}
|
||||
|
||||
public void statusURLLoad(String url, String message, Document doc) {
|
||||
if (debug)
|
||||
System.err.println(prefix + " :status URL load - " +
|
||||
url.toString() + " (" +
|
||||
message + ")");
|
||||
}
|
||||
|
||||
public void startDocumentLoad(String url) {
|
||||
if (debug)
|
||||
System.err.println(prefix + " :start doc load - " +
|
||||
url.toString());
|
||||
}
|
||||
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
if (debug) {
|
||||
System.err.println(prefix + " :end doc load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
}
|
||||
|
||||
private void dump(PrintStream ps, Node node, int indent, boolean isMapNode) {
|
||||
if (node == null) return;
|
||||
|
||||
ps.println();
|
||||
for (int i=0; i<indent; i++)
|
||||
ps.print(' ');
|
||||
|
||||
ps.print("name=\"" + node.getNodeName() + "\"" +
|
||||
" type=" + dumpType(node.getNodeType()) +
|
||||
" value=\"" + stripWhiteSpace(node.getNodeValue()) + "\"");
|
||||
|
||||
if (isMapNode) return;
|
||||
|
||||
NamedNodeMap map = node.getAttributes();
|
||||
dumpMap(ps, map, indent);
|
||||
|
||||
NodeList children = node.getChildNodes();
|
||||
if (children == null) return;
|
||||
|
||||
/*
|
||||
Node fc = node.getFirstChild();
|
||||
if (fc != null)
|
||||
System.out.println("firstchild=" + fc.toString());
|
||||
Node lc = node.getLastChild();
|
||||
if (lc != null)
|
||||
System.out.println("lastchild=" + lc.toString());
|
||||
*/
|
||||
|
||||
int length = children.getLength();
|
||||
for (int i=0; i < length; i++) {
|
||||
dump(ps, children.item(i), indent+2, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpMap(PrintStream ps, NamedNodeMap map, int indent) {
|
||||
if (map == null) return;
|
||||
|
||||
ps.println();
|
||||
int length = map.getLength();
|
||||
if (length > 0) {
|
||||
for (int i=0; i<indent; i++)
|
||||
ps.print(' ');
|
||||
ps.print("------- start attributes -------");
|
||||
}
|
||||
|
||||
for (int i=0; i < length; i++) {
|
||||
Node item = map.item(i);
|
||||
dump(ps, item, indent, true);
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
ps.println();
|
||||
for (int i=0; i<indent; i++)
|
||||
ps.print(' ');
|
||||
ps.print("------- end attributes -------");
|
||||
}
|
||||
}
|
||||
|
||||
private static String dumpType(int type) {
|
||||
switch (type) {
|
||||
case Node.ELEMENT_NODE: return "ELEMENT";
|
||||
case Node.ATTRIBUTE_NODE: return "ATTRIBUTE";
|
||||
case Node.TEXT_NODE: return "TEXT";
|
||||
case Node.CDATA_SECTION_NODE: return "CDATA_SECTION";
|
||||
case Node.ENTITY_REFERENCE_NODE: return "ENTITY_REFERENCE";
|
||||
case Node.ENTITY_NODE: return "ENTITY";
|
||||
case Node.PROCESSING_INSTRUCTION_NODE: return "PROCESSING_INSTRUCTION";
|
||||
case Node.COMMENT_NODE: return "COMMENT";
|
||||
case Node.DOCUMENT_NODE: return "DOCUMENT";
|
||||
case Node.DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE";
|
||||
case Node.DOCUMENT_FRAGMENT_NODE: return "DOCUMENT_FRAGMENT";
|
||||
case Node.NOTATION_NODE: return "NOTATION";
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
private static String stripWhiteSpace(String s) {
|
||||
int len = s.length();
|
||||
StringBuffer sb = new StringBuffer(len);
|
||||
char c = ' ';
|
||||
char pc = ' ';
|
||||
for (int i=0; i < len; i++) {
|
||||
c = s.charAt(i);
|
||||
if ((pc == ' ' || pc == '\n' || pc == '\t') &&
|
||||
(c == ' ' || c == '\n' || c == '\t'))
|
||||
continue;
|
||||
sb.append(c);
|
||||
pc = c;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
21
java/dom/tests/src/applets/index.html
Normal file
21
java/dom/tests/src/applets/index.html
Normal file
@ -0,0 +1,21 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Java DOM Tests</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000099" VLINK="#330066">
|
||||
<PRE>
|
||||
In order to run tests you need to have a working java plugin for
|
||||
Mozilla browser and compliled Java DOM classes in your classpath.
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="testa.html">DOMAccessor test</A></LI>
|
||||
<LI><A HREF="testb.html">DOM API test runner</A></LI>
|
||||
<LI><A HREF="testc.html">DOM tree dumper</A></LI>
|
||||
<LI><A HREF="testd.html">DOM events test</A></LI>
|
||||
</UL>
|
||||
</PRE>
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
<html>
|
||||
<body name="test_dom_accessor">
|
||||
<head>
|
||||
<title>
|
||||
DOMAccessor test
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre>
|
||||
This should run DOMAccessor test.
|
||||
Look into the java plugin console for
|
22
java/dom/tests/src/applets/testb.html
Normal file
22
java/dom/tests/src/applets/testb.html
Normal file
@ -0,0 +1,22 @@
|
||||
<html>
|
||||
<body>
|
||||
<head>
|
||||
<title>
|
||||
DOM API test runner
|
||||
</title>
|
||||
</head>
|
||||
<pre>
|
||||
This should run java dom api tests.
|
||||
TestRunnerApplet registers itself
|
||||
as a DocumentLoadListener via DOMAccessor
|
||||
and runs tests on endURLLoad notification and dumps
|
||||
test results into the java plugin console.
|
||||
<pre>
|
||||
<applet code="org.mozilla.dom.tests.TestRunnerApplet"
|
||||
width=0
|
||||
height=0
|
||||
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason.">
|
||||
Your browser is completely ignoring the <APPLET> tag!
|
||||
</applet>
|
||||
</body>
|
||||
</html>
|
@ -1,13 +1,18 @@
|
||||
<html>
|
||||
<body name="test_dom_accessor">
|
||||
<body>
|
||||
<head>
|
||||
<title>
|
||||
DOM tree dumper
|
||||
</title>
|
||||
</head>
|
||||
<pre>
|
||||
This should run DOMAccessor test.
|
||||
TestDOMAccessorApplet1 registers itself
|
||||
This should run DOMTreeDumper test.
|
||||
DOMTreeDumperApplet registers itself
|
||||
as a DocumentLoadListener via DOMAccessor
|
||||
and dumps load notifications and document
|
||||
source into the java plugin console.
|
||||
and dumps document source into the
|
||||
java plugin console.
|
||||
<pre>
|
||||
<applet code="org.mozilla.dom.tests.TestDOMAccessorApplet1"
|
||||
<applet code="org.mozilla.dom.tests.DOMTreeDumperApplet"
|
||||
width=0
|
||||
height=0
|
||||
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason.">
|
23
java/dom/tests/src/applets/testd.html
Normal file
23
java/dom/tests/src/applets/testd.html
Normal file
@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<body>
|
||||
<head>
|
||||
<title>
|
||||
DOM events test
|
||||
</title>
|
||||
</head>
|
||||
<pre>
|
||||
This should run DOM events test.
|
||||
TestDOMEvents registers itself
|
||||
as a DocumentLoadListener via DOMAccessor
|
||||
and adds DOM events listeners do loading
|
||||
documents. DOM events info is dumped
|
||||
into the java plugin console.
|
||||
<pre>
|
||||
<applet code="org.mozilla.dom.tests.TestDOMEventsApplet"
|
||||
width=0
|
||||
height=0
|
||||
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason.">
|
||||
Your browser is completely ignoring the <APPLET> tag!
|
||||
</applet>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user