From 10d25b3cb8b18b52d6529aa630c62951d043a3fd Mon Sep 17 00:00:00 2001 From: "akhil.arora%sun.com" Date: Fri, 6 Aug 1999 00:28:53 +0000 Subject: [PATCH] initial check-in of the java dom api (not part of regular build) git-svn-id: svn://10.0.0.236/trunk@42384 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/dom/Makefile | 50 ++ mozilla/java/dom/Makefile.in | 50 ++ mozilla/java/dom/Makefile.linux | 50 ++ mozilla/java/dom/README | 105 +++ mozilla/java/dom/jni/AttrImpl.java | 32 + mozilla/java/dom/jni/CDATASectionImpl.java | 26 + mozilla/java/dom/jni/CharacterDataImpl.java | 36 + mozilla/java/dom/jni/CommentImpl.java | 25 + mozilla/java/dom/jni/DOMAccessor.java | 24 + mozilla/java/dom/jni/DOMAccessorImpl.java | 124 +++ mozilla/java/dom/jni/DOMExceptionImpl.java | 27 + mozilla/java/dom/jni/DOMFactory.java | 199 +++++ mozilla/java/dom/jni/DOMGarbageCollector.java | 22 + .../java/dom/jni/DOMImplementationImpl.java | 31 + .../java/dom/jni/DocumentFragmentImpl.java | 24 + mozilla/java/dom/jni/DocumentImpl.java | 60 ++ .../java/dom/jni/DocumentLoadListener.java | 31 + mozilla/java/dom/jni/DocumentTypeImpl.java | 32 + mozilla/java/dom/jni/ElementImpl.java | 39 + mozilla/java/dom/jni/EntityReferenceImpl.java | 25 + mozilla/java/dom/jni/Makefile | 43 ++ mozilla/java/dom/jni/Makefile.in | 43 ++ mozilla/java/dom/jni/NamedNodeMapImpl.java | 34 + mozilla/java/dom/jni/NodeImpl.java | 91 +++ mozilla/java/dom/jni/NodeListImpl.java | 33 + .../dom/jni/ProcessingInstructionImpl.java | 31 + mozilla/java/dom/jni/TextImpl.java | 30 + mozilla/java/dom/jni/javaDOMGlobals.cpp | 352 +++++++++ mozilla/java/dom/jni/javaDOMGlobals.h | 78 ++ mozilla/java/dom/jni/makefile.win | 89 +++ .../java/dom/jni/org_mozilla_dom_AttrImpl.cpp | 171 +++++ .../java/dom/jni/org_mozilla_dom_AttrImpl.h | 53 ++ .../jni/org_mozilla_dom_CharacterDataImpl.cpp | 296 ++++++++ .../jni/org_mozilla_dom_CharacterDataImpl.h | 85 +++ .../jni/org_mozilla_dom_DOMAccessorImpl.cpp | 78 ++ .../dom/jni/org_mozilla_dom_DOMAccessorImpl.h | 29 + .../org_mozilla_dom_DOMGarbageCollector.cpp | 29 + .../jni/org_mozilla_dom_DOMGarbageCollector.h | 21 + .../org_mozilla_dom_DOMImplementationImpl.cpp | 85 +++ .../org_mozilla_dom_DOMImplementationImpl.h | 29 + .../dom/jni/org_mozilla_dom_DocumentImpl.cpp | 659 ++++++++++++++++ .../dom/jni/org_mozilla_dom_DocumentImpl.h | 125 +++ .../jni/org_mozilla_dom_DocumentTypeImpl.cpp | 160 ++++ .../jni/org_mozilla_dom_DocumentTypeImpl.h | 46 ++ .../dom/jni/org_mozilla_dom_ElementImpl.cpp | 430 +++++++++++ .../dom/jni/org_mozilla_dom_ElementImpl.h | 93 +++ .../jni/org_mozilla_dom_NamedNodeMapImpl.cpp | 264 +++++++ .../jni/org_mozilla_dom_NamedNodeMapImpl.h | 61 ++ .../java/dom/jni/org_mozilla_dom_NodeImpl.cpp | 718 ++++++++++++++++++ .../java/dom/jni/org_mozilla_dom_NodeImpl.h | 165 ++++ .../dom/jni/org_mozilla_dom_NodeListImpl.cpp | 110 +++ .../dom/jni/org_mozilla_dom_NodeListImpl.h | 37 + ..._mozilla_dom_ProcessingInstructionImpl.cpp | 144 ++++ ...rg_mozilla_dom_ProcessingInstructionImpl.h | 45 ++ .../java/dom/jni/org_mozilla_dom_TextImpl.cpp | 81 ++ .../java/dom/jni/org_mozilla_dom_TextImpl.h | 29 + mozilla/java/dom/makefile.win | 73 ++ mozilla/java/dom/nsIJavaDOM.h | 95 +++ mozilla/java/dom/nsJavaDOMCID.h | 24 + mozilla/java/dom/nsJavaDOMFactory.cpp | 142 ++++ mozilla/java/dom/nsJavaDOMFactory.h | 40 + mozilla/java/dom/nsJavaDOMImpl.cpp | 666 ++++++++++++++++ mozilla/java/dom/nsJavaDOMImpl.h | 106 +++ mozilla/java/dom/nsWebShell.cpp.patch | 38 + 64 files changed, 7063 insertions(+) create mode 100644 mozilla/java/dom/Makefile create mode 100644 mozilla/java/dom/Makefile.in create mode 100644 mozilla/java/dom/Makefile.linux create mode 100644 mozilla/java/dom/README create mode 100644 mozilla/java/dom/jni/AttrImpl.java create mode 100644 mozilla/java/dom/jni/CDATASectionImpl.java create mode 100644 mozilla/java/dom/jni/CharacterDataImpl.java create mode 100644 mozilla/java/dom/jni/CommentImpl.java create mode 100644 mozilla/java/dom/jni/DOMAccessor.java create mode 100644 mozilla/java/dom/jni/DOMAccessorImpl.java create mode 100644 mozilla/java/dom/jni/DOMExceptionImpl.java create mode 100644 mozilla/java/dom/jni/DOMFactory.java create mode 100644 mozilla/java/dom/jni/DOMGarbageCollector.java create mode 100644 mozilla/java/dom/jni/DOMImplementationImpl.java create mode 100644 mozilla/java/dom/jni/DocumentFragmentImpl.java create mode 100644 mozilla/java/dom/jni/DocumentImpl.java create mode 100644 mozilla/java/dom/jni/DocumentLoadListener.java create mode 100644 mozilla/java/dom/jni/DocumentTypeImpl.java create mode 100644 mozilla/java/dom/jni/ElementImpl.java create mode 100644 mozilla/java/dom/jni/EntityReferenceImpl.java create mode 100644 mozilla/java/dom/jni/Makefile create mode 100644 mozilla/java/dom/jni/Makefile.in create mode 100644 mozilla/java/dom/jni/NamedNodeMapImpl.java create mode 100644 mozilla/java/dom/jni/NodeImpl.java create mode 100644 mozilla/java/dom/jni/NodeListImpl.java create mode 100644 mozilla/java/dom/jni/ProcessingInstructionImpl.java create mode 100644 mozilla/java/dom/jni/TextImpl.java create mode 100644 mozilla/java/dom/jni/javaDOMGlobals.cpp create mode 100644 mozilla/java/dom/jni/javaDOMGlobals.h create mode 100755 mozilla/java/dom/jni/makefile.win create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.h create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_TextImpl.cpp create mode 100644 mozilla/java/dom/jni/org_mozilla_dom_TextImpl.h create mode 100755 mozilla/java/dom/makefile.win create mode 100644 mozilla/java/dom/nsIJavaDOM.h create mode 100644 mozilla/java/dom/nsJavaDOMCID.h create mode 100644 mozilla/java/dom/nsJavaDOMFactory.cpp create mode 100644 mozilla/java/dom/nsJavaDOMFactory.h create mode 100755 mozilla/java/dom/nsJavaDOMImpl.cpp create mode 100644 mozilla/java/dom/nsJavaDOMImpl.h create mode 100644 mozilla/java/dom/nsWebShell.cpp.patch diff --git a/mozilla/java/dom/Makefile b/mozilla/java/dom/Makefile new file mode 100644 index 00000000000..35ee1d8c516 --- /dev/null +++ b/mozilla/java/dom/Makefile @@ -0,0 +1,50 @@ +# +# 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. + +DEPTH = /opt/mozilla +topsrcdir = $(DEPTH) +srcdir = . +VPATH = . + +include $(DEPTH)/config/autoconf.mk + +MODULE = javadom +LIBRARY_NAME = javadom +IS_COMPONENT = 1 + +CPPSRCS = \ + nsJavaDOMImpl.cpp \ + nsJavaDOMFactory.cpp + +include $(topsrcdir)/config/config.mk + +JAVA_HOME = /opt/jdk +INCLUDES += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/solaris +DSO_LDOPTS += \ + -L$(JAVA_HOME)/jre/lib/sparc \ + -L$(JAVA_HOME)/jre/lib/sparc/classic \ + -L$(JAVA_HOME)/jre/lib/sparc/native_threads \ + -R$(JAVA_HOME)/jre/lib/sparc \ + -R$(JAVA_HOME)/jre/lib/sparc/classic \ + -R$(JAVA_HOME)/jre/lib/sparc/native_threads \ + -ljvm -lhpi -lsunwjit + +EXPORTS = \ + nsJavaDOMCID.h \ + nsIJavaDOM.h + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/dom/Makefile.in b/mozilla/java/dom/Makefile.in new file mode 100644 index 00000000000..4eaad69cc4f --- /dev/null +++ b/mozilla/java/dom/Makefile.in @@ -0,0 +1,50 @@ +# +# 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. + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = javadom +LIBRARY_NAME = javadom +IS_COMPONENT = 1 + +CPPSRCS = \ + nsJavaDOMImpl.cpp \ + nsJavaDOMFactory.cpp + +include $(topsrcdir)/config/config.mk + +JAVA_HOME = /opt/jdk +INCLUDES += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/solaris +DSO_LDOPTS += \ + -L$(JAVA_HOME)/jre/lib/sparc \ + -L$(JAVA_HOME)/jre/lib/sparc/classic \ + -L$(JAVA_HOME)/jre/lib/sparc/native_threads \ + -R$(JAVA_HOME)/jre/lib/sparc \ + -R$(JAVA_HOME)/jre/lib/sparc/classic \ + -R$(JAVA_HOME)/jre/lib/sparc/native_threads \ + -ljvm -lhpi -lsunwjit + +EXPORTS = \ + nsJavaDOMCID.h \ + nsIJavaDOM.h + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/dom/Makefile.linux b/mozilla/java/dom/Makefile.linux new file mode 100644 index 00000000000..417b8c32279 --- /dev/null +++ b/mozilla/java/dom/Makefile.linux @@ -0,0 +1,50 @@ +# +# 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. + +DEPTH = /opt/mozilla +topsrcdir = $(DEPTH) +srcdir = . +VPATH = . + +include $(DEPTH)/config/autoconf.mk + +MODULE = javadom +LIBRARY_NAME = javadom +IS_COMPONENT = 1 + +CPPSRCS = \ + nsJavaDOMImpl.cpp \ + nsJavaDOMFactory.cpp + +include $(topsrcdir)/config/config.mk + +JAVA_HOME = /opt/jdk +INCLUDES += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/solaris +DSO_LDOPTS += \ + -L$(JAVA_HOME)/jre/lib/i386 \ + -L$(JAVA_HOME)/jre/lib/i386/classic \ + -L$(JAVA_HOME)/jre/lib/i386/native_threads \ + -Xlinker -rpath $(JAVA_HOME)/jre/lib/i386 \ + -Xlinker -rpath $(JAVA_HOME)/jre/lib/i386/classic \ + -Xlinker -rpath $(JAVA_HOME)/jre/lib/i386/native_threads \ + -ljvm -lhpi -lsunwjit + +EXPORTS = \ + nsJavaDOMCID.h \ + nsIJavaDOM.h + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/dom/README b/mozilla/java/dom/README new file mode 100644 index 00000000000..94a15651bb4 --- /dev/null +++ b/mozilla/java/dom/README @@ -0,0 +1,105 @@ +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, currently this does not work and one has to apply a +patch to webshell/src/nsWebShell.cpp. See the section on Building for +instructions on how to apply the patch. + +The nsJavaDOM component by means of this patch registers itself as a +DocumentLoadObserver with the DocumentLoader service. It then loads a +class called DOMFactory, asks it for a Java DocumentLoadListener and +starts sending all document load notifications that it recieves to the +Java listener. + +So the first place to start hacking would be DOMFactory.java. + + +Makefiles +--------- + +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. + +That is also why I have a separate Makefile.linux for Linux. (Does not +work with Linux... last time I checked, the Blackdown JDK had a +problem creating the JVM in +nsJavaDOMImpl.cpp::Initialize:CreateJavaVM). + + +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 0) { + for (int i=0; i 0) { + ps.println(); + for (int i=0; i"; + } + + private static String nodeTypeString(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"; + } + + public native Node appendChild(Node newChild); + public native Node cloneNode(boolean deep); + public native NamedNodeMap getAttributes(); + public native NodeList getChildNodes(); + public native Node getFirstChild(); + public native Node getLastChild(); + public native Node getNextSibling(); + public native String getNodeName(); + public native short getNodeType(); + public native String getNodeValue(); + public native Document getOwnerDocument(); + public native Node getParentNode(); + public native Node getPreviousSibling(); + public native boolean hasChildNodes(); + public native Node insertBefore(Node newChild, Node refChild); + public native Node removeChild(Node oldChild); + public native Node replaceChild(Node newChild, Node oldChild); + public native void setNodeValue(String nodeValue); + + protected native void finalize(); +} diff --git a/mozilla/java/dom/jni/NodeListImpl.java b/mozilla/java/dom/jni/NodeListImpl.java new file mode 100644 index 00000000000..4eae32b2e5c --- /dev/null +++ b/mozilla/java/dom/jni/NodeListImpl.java @@ -0,0 +1,33 @@ +/* +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. +*/ + +package org.mozilla.dom; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class NodeListImpl implements NodeList { + + private long p_nsIDOMNodeList = 0; + + // instantiated from JNI or Document.createAttribute() + private NodeListImpl() {} + + public native int getLength(); + public native Node item(int index); + + protected native void finalize(); +} diff --git a/mozilla/java/dom/jni/ProcessingInstructionImpl.java b/mozilla/java/dom/jni/ProcessingInstructionImpl.java new file mode 100644 index 00000000000..afc96143b50 --- /dev/null +++ b/mozilla/java/dom/jni/ProcessingInstructionImpl.java @@ -0,0 +1,31 @@ +/* +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. +*/ + +package org.mozilla.dom; + +import org.w3c.dom.ProcessingInstruction; + +public class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction { + + // instantiated from JNI or Document.createProcessingInstruction() + private ProcessingInstructionImpl() {} + + public native String getData(); + public native String getTarget(); + public native void setData(String data); + + protected native void finalize(); +} diff --git a/mozilla/java/dom/jni/TextImpl.java b/mozilla/java/dom/jni/TextImpl.java new file mode 100644 index 00000000000..09e8343925d --- /dev/null +++ b/mozilla/java/dom/jni/TextImpl.java @@ -0,0 +1,30 @@ +/* +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. +*/ + +package org.mozilla.dom; + +import org.w3c.dom.Text; + +public class TextImpl extends CharacterDataImpl implements Text { + + // instantiated from JNI or Document.createTextNode() + protected TextImpl() {} + + public native Text splitText(int offset); + + protected native void finalize(); +} + diff --git a/mozilla/java/dom/jni/javaDOMGlobals.cpp b/mozilla/java/dom/jni/javaDOMGlobals.cpp new file mode 100644 index 00000000000..126e3ea09f6 --- /dev/null +++ b/mozilla/java/dom/jni/javaDOMGlobals.cpp @@ -0,0 +1,352 @@ +/* +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. +*/ + +#include "prlog.h" +#include "prmon.h" +#include "nsAutoLock.h" +#include "nsIDOMNode.h" +#include "javaDOMGlobals.h" + +jclass JavaDOMGlobals::attrClass = NULL; +jclass JavaDOMGlobals::cDataSectionClass = NULL; +jclass JavaDOMGlobals::commentClass = NULL; +jclass JavaDOMGlobals::documentClass = NULL; +jclass JavaDOMGlobals::documentFragmentClass = NULL; +jclass JavaDOMGlobals::documentTypeClass = NULL; +jclass JavaDOMGlobals::domImplementationClass = NULL; +jclass JavaDOMGlobals::elementClass = NULL; +jclass JavaDOMGlobals::entityClass = NULL; +jclass JavaDOMGlobals::entityReferenceClass = NULL; +jclass JavaDOMGlobals::namedNodeMapClass = NULL; +jclass JavaDOMGlobals::nodeClass = NULL; +jclass JavaDOMGlobals::nodeListClass = NULL; +jclass JavaDOMGlobals::notationClass = NULL; +jclass JavaDOMGlobals::processingInstructionClass = NULL; +jclass JavaDOMGlobals::textClass = NULL; + +jfieldID JavaDOMGlobals::nodePtrFID = NULL; +jfieldID JavaDOMGlobals::nodeListPtrFID = NULL; +jfieldID JavaDOMGlobals::domImplementationPtrFID = NULL; + +jfieldID JavaDOMGlobals::nodeTypeAttributeFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeCDataSectionFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeCommentFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeDocumentFragmentFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeDocumentFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeDocumentTypeFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeElementFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeEntityFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeEntityReferenceFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeNotationFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeProcessingInstructionFID = NULL; +jfieldID JavaDOMGlobals::nodeTypeTextFID = NULL; + +PRLogModuleInfo* JavaDOMGlobals::log = NULL; + +PRCList JavaDOMGlobals::garbage = PR_INIT_STATIC_CLIST(&garbage); +PRLock* JavaDOMGlobals::garbageLock = NULL; + +class jniDOMGarbage : public PRCList { +public: + jniDOMGarbage(nsISupports* p) { domObject = p; } + nsISupports* domObject; +}; + +void JavaDOMGlobals::Initialize(JNIEnv *env) +{ + garbageLock = PR_NewLock(); + log = PR_NewLogModule("javadom"); + PR_INIT_CLIST(&garbage); + + /* Node is loaded first because it is the base class of a lot of the + others */ + nodeClass = env->FindClass("org/mozilla/dom/NodeImpl"); + if (!nodeClass) return; + nodeClass = (jclass) env->NewGlobalRef(nodeClass); + if (!nodeClass) return; + nodePtrFID = + env->GetFieldID(nodeClass, "p_nsIDOMNode", "J"); + if (!nodePtrFID) return; + + attrClass = env->FindClass("org/mozilla/dom/AttrImpl"); + if (!attrClass) return; + attrClass = (jclass) env->NewGlobalRef(attrClass); + if (!attrClass) return; + + documentClass = env->FindClass("org/mozilla/dom/DocumentImpl"); + if (!documentClass) return; + documentClass = (jclass) env->NewGlobalRef(documentClass); + if (!documentClass) return; + + documentTypeClass = env->FindClass("org/mozilla/dom/DocumentTypeImpl"); + if (!documentTypeClass) return; + documentTypeClass = (jclass) env->NewGlobalRef(documentTypeClass); + if (!documentTypeClass) return; + + domImplementationClass = env->FindClass("org/mozilla/dom/DOMImplementationImpl"); + if (!domImplementationClass) return; + domImplementationClass = (jclass) env->NewGlobalRef(domImplementationClass); + if (!domImplementationClass) return; + domImplementationPtrFID = + env->GetFieldID(domImplementationClass, "p_nsIDOMDOMImplementation", "J"); + if (!domImplementationPtrFID) return; + + elementClass = env->FindClass("org/mozilla/dom/ElementImpl"); + if (!elementClass) return; + elementClass = (jclass) env->NewGlobalRef(elementClass); + if (!elementClass) return; + + namedNodeMapClass = env->FindClass("org/mozilla/dom/NamedNodeMapImpl"); + if (!namedNodeMapClass) return; + namedNodeMapClass = (jclass) env->NewGlobalRef(namedNodeMapClass); + if (!namedNodeMapClass) return; + + nodeListClass = env->FindClass("org/mozilla/dom/NodeListImpl"); + if (!nodeListClass) return; + nodeListClass = (jclass) env->NewGlobalRef(nodeListClass); + if (!nodeListClass) return; + nodeListPtrFID = + env->GetFieldID(nodeListClass, "p_nsIDOMNodeList", "J"); + if (!nodeListPtrFID) return; + + nodeTypeAttributeFID = + env->GetStaticFieldID(nodeClass, "ATTRIBUTE_NODE", "S"); + if (!nodeTypeAttributeFID) return; + nodeTypeCDataSectionFID = + env->GetStaticFieldID(nodeClass, "CDATA_SECTION_NODE", "S"); + if (!nodeTypeCDataSectionFID) return; + nodeTypeCommentFID = + env->GetStaticFieldID(nodeClass, "COMMENT_NODE", "S"); + if (!nodeTypeCommentFID) return; + nodeTypeDocumentFragmentFID = + env->GetStaticFieldID(nodeClass, "DOCUMENT_FRAGMENT_NODE", "S"); + if (!nodeTypeDocumentFragmentFID) return; + nodeTypeDocumentFID = + env->GetStaticFieldID(nodeClass, "DOCUMENT_NODE", "S"); + if (!nodeTypeDocumentFID) return; + nodeTypeDocumentTypeFID = + env->GetStaticFieldID(nodeClass, "DOCUMENT_TYPE_NODE", "S"); + if (!nodeTypeDocumentTypeFID) return; + nodeTypeElementFID = + env->GetStaticFieldID(nodeClass, "ELEMENT_NODE", "S"); + if (!nodeTypeElementFID) return; + nodeTypeEntityFID = + env->GetStaticFieldID(nodeClass, "ENTITY_NODE", "S"); + if (!nodeTypeEntityFID) return; + nodeTypeEntityReferenceFID = + env->GetStaticFieldID(nodeClass, "ENTITY_REFERENCE_NODE", "S"); + if (!nodeTypeEntityReferenceFID) return; + nodeTypeNotationFID = + env->GetStaticFieldID(nodeClass, "NOTATION_NODE", "S"); + if (!nodeTypeNotationFID) return; + nodeTypeProcessingInstructionFID = + env->GetStaticFieldID(nodeClass, "PROCESSING_INSTRUCTION_NODE", "S"); + if (!nodeTypeProcessingInstructionFID) return; + nodeTypeTextFID = + env->GetStaticFieldID(nodeClass, "TEXT_NODE", "S"); + if (!nodeTypeTextFID) return; +} + +void JavaDOMGlobals::Destroy(JNIEnv *env) +{ + env->DeleteGlobalRef(attrClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete Attr global ref %x\n", + attrClass)); + return; + } + attrClass = NULL; + + env->DeleteGlobalRef(documentClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete Document global ref %x\n", + attrClass)); + return; + } + documentClass = NULL; + + env->DeleteGlobalRef(documentTypeClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete DocumentType global ref %x\n", + attrClass)); + return; + } + documentTypeClass = NULL; + + env->DeleteGlobalRef(domImplementationClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete DOMImplementation global ref %x\n", + attrClass)); + return; + } + domImplementationClass = NULL; + + env->DeleteGlobalRef(elementClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete Element global ref %x\n", + attrClass)); + return; + } + elementClass = NULL; + + env->DeleteGlobalRef(namedNodeMapClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete NamedNodeMap global ref %x\n", + attrClass)); + return; + } + namedNodeMapClass = NULL; + + env->DeleteGlobalRef(nodeListClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete NodeList global ref %x\n", + attrClass)); + return; + } + nodeListClass = NULL; + + env->DeleteGlobalRef(nodeClass); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::Destroy: failed to delete Node global ref %x\n", + attrClass)); + return; + } + nodeClass = NULL; + + TakeOutGarbage(); + PR_DestroyLock(garbageLock); +} + +jobject JavaDOMGlobals::CreateNodeSubtype(JNIEnv *env, + nsIDOMNode *node) +{ + PRUint16 nodeType = 0; + (void) node->GetNodeType(&nodeType); + + jclass clazz = nodeClass; + switch (nodeType) { + case nsIDOMNode::ATTRIBUTE_NODE: + clazz = attrClass; + break; + + case nsIDOMNode::CDATA_SECTION_NODE: + clazz = cDataSectionClass; + break; + + case nsIDOMNode::COMMENT_NODE: + clazz = commentClass; + break; + + case nsIDOMNode::DOCUMENT_NODE: + clazz = documentClass; + break; + + case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: + clazz = documentFragmentClass; + break; + + case nsIDOMNode::DOCUMENT_TYPE_NODE: + clazz = documentTypeClass; + break; + + case nsIDOMNode::ENTITY_NODE: + clazz = entityClass; + break; + + case nsIDOMNode::ENTITY_REFERENCE_NODE: + clazz = entityReferenceClass; + break; + + case nsIDOMNode::NOTATION_NODE: + clazz = notationClass; + break; + + case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: + clazz = processingInstructionClass; + break; + + case nsIDOMNode::TEXT_NODE: + clazz = textClass; + break; + } + + jobject jnode = env->AllocObject(clazz); + if (!jnode) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::CreateNodeSubtype: failed to allocate Node of type %d\n", + nodeType)); + return NULL; + } + + env->SetLongField(jnode, nodePtrFID, (jlong) node); + if (env->ExceptionOccurred()) { + PR_LOG(log, PR_LOG_ERROR, + ("JavaDOMGlobals::CreateNodeSubtype: failed to set native ptr %x\n", + (jlong) node)); + return NULL; + } + node->AddRef(); + + return jnode; +} + +void JavaDOMGlobals::AddToGarbage(nsISupports* domObject) +{ + nsAutoLock lock(garbageLock); + jniDOMGarbage* elem = new jniDOMGarbage(domObject); + PR_INSERT_BEFORE(elem, &garbage); + PR_LOG(log, PR_LOG_DEBUG, + ("JavaDOMGlobals::AddToGarbage: Scheduling %x\n", domObject)); +} + +void JavaDOMGlobals::TakeOutGarbage() +{ + nsAutoLock lock(garbageLock); + + PRUint32 count = 0; + nsISupports* domo = NULL; + + PRCList* chain = NULL; + PRCList* elem = NULL; + for (chain = garbage.next; + chain != &garbage; + chain = PR_NEXT_LINK(chain)) { + elem = chain; + + domo = ((jniDOMGarbage*) elem)->domObject; + PR_LOG(log, PR_LOG_DEBUG, + ("JavaDOMGlobals::TakeOutGarbage: Releasing %x\n", domo)); + domo->Release(); + domo = NULL; + + delete elem; + count++; + } + PR_INIT_CLIST(&garbage); + + if (count) + PR_LOG(log, PR_LOG_DEBUG, + ("JavaDOMGlobals::TakeOutGarbage: Released %d objects\n", count)); +} + diff --git a/mozilla/java/dom/jni/javaDOMGlobals.h b/mozilla/java/dom/jni/javaDOMGlobals.h new file mode 100644 index 00000000000..5f712729aee --- /dev/null +++ b/mozilla/java/dom/jni/javaDOMGlobals.h @@ -0,0 +1,78 @@ +/* +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. +*/ + +#ifndef __JavaDOMGlobals_h__ +#define __JavaDOMGlobals_h__ + +#include "jni.h" +#include "prclist.h" + +class nsISupports; +class nsIDOMNode; +class PRLogModuleInfo; +class PRLock; + +class JavaDOMGlobals { + + public: + static jclass attrClass; + static jclass cDataSectionClass; + static jclass commentClass; + static jclass documentClass; + static jclass documentFragmentClass; + static jclass documentTypeClass; + static jclass domImplementationClass; + static jclass elementClass; + static jclass entityClass; + static jclass entityReferenceClass; + static jclass namedNodeMapClass; + static jclass nodeClass; + static jclass nodeListClass; + static jclass notationClass; + static jclass processingInstructionClass; + static jclass textClass; + + static jfieldID nodePtrFID; + static jfieldID nodeListPtrFID; + static jfieldID domImplementationPtrFID; + + static jfieldID nodeTypeAttributeFID; + static jfieldID nodeTypeCDataSectionFID; + static jfieldID nodeTypeCommentFID; + static jfieldID nodeTypeDocumentFragmentFID; + static jfieldID nodeTypeDocumentFID; + static jfieldID nodeTypeDocumentTypeFID; + static jfieldID nodeTypeElementFID; + static jfieldID nodeTypeEntityFID; + static jfieldID nodeTypeEntityReferenceFID; + static jfieldID nodeTypeNotationFID; + static jfieldID nodeTypeProcessingInstructionFID; + static jfieldID nodeTypeTextFID; + + static PRLogModuleInfo* log; + static PRCList garbage; + static PRLock* garbageLock; + + static void Initialize(JNIEnv *env); + static void Destroy(JNIEnv *env); + static jobject CreateNodeSubtype(JNIEnv *env, + nsIDOMNode *node); + + static void AddToGarbage(nsISupports* domObject); + static void TakeOutGarbage(); +}; + +#endif /* __JavaDOMGlobals_h__ */ diff --git a/mozilla/java/dom/jni/makefile.win b/mozilla/java/dom/jni/makefile.win new file mode 100755 index 00000000000..5ab38f6e1c0 --- /dev/null +++ b/mozilla/java/dom/jni/makefile.win @@ -0,0 +1,89 @@ +#!nmake +# +# 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. + +DEPTH=..\..\.. +IGNORE_MANIFEST=1 + +DEFINES=-D_IMPL_NS_WEB -DWIN32_LEAN_AND_MEAN +MODULE=javadomjni + +CPPSRCS= \ + javaDOMGlobals.cpp \ + org_mozilla_dom_DOMAccessorImpl.cpp \ + org_mozilla_dom_DOMGarbageCollector.cpp \ + org_mozilla_dom_AttrImpl.cpp \ + org_mozilla_dom_CharacterDataImpl.cpp \ + org_mozilla_dom_DocumentImpl.cpp \ + org_mozilla_dom_DocumentTypeImpl.cpp \ + org_mozilla_dom_DOMImplementationImpl.cpp \ + org_mozilla_dom_ElementImpl.cpp \ + org_mozilla_dom_NamedNodeMapImpl.cpp \ + org_mozilla_dom_NodeImpl.cpp \ + org_mozilla_dom_NodeListImpl.cpp \ + org_mozilla_dom_ProcessingInstructionImpl.cpp \ + org_mozilla_dom_TextImpl.cpp \ + $(NULL) + +CPP_OBJS= \ + .\$(OBJDIR)\javaDOMGlobals.obj \ + .\$(OBJDIR)\org_mozilla_dom_DOMAccessorImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_DOMGarbageCollector.obj \ + .\$(OBJDIR)\org_mozilla_dom_AttrImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_CharacterDataImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_DocumentImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_DocumentTypeImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_DOMImplementationImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_ElementImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_NamedNodeMapImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_NodeImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_NodeListImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_ProcessingInstructionImpl.obj \ + .\$(OBJDIR)\org_mozilla_dom_TextImpl.obj \ + $(NULL) + +LINCS= + +MAKE_OBJ_TYPE = DLL +DLLNAME = javadomjni +DLL=.\$(OBJDIR)\$(DLLNAME).dll +LIBRARY_NAME=javadomimpl + +LCFLAGS = \ + $(LCFLAGS) \ + $(DEFINES) \ + $(NULL) + +# These are the libraries we need to link with to create the dll +LLIBS= \ + $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\raptorgfxwin.lib \ + $(DIST)\lib\img32$(VERSION_NUMBER).lib \ + $(DIST)\lib\util.lib \ + $(DIST)\lib\plc3.lib \ + $(DIST)\lib\jsdom.lib \ + $(LIBNSPR) + +include <$(DEPTH)\config\config.mak> + +include <$(DEPTH)\config\rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib + +clobber:: + rm -f $(DIST)\bin\$(DLLNAME).dll + rm -f $(DIST)\lib\$(DLLNAME).lib diff --git a/mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.cpp new file mode 100644 index 00000000000..27b6c8d8d2c --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.cpp @@ -0,0 +1,171 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMAttr.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_AttrImpl.h" + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: getName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_AttrImpl_getName + (JNIEnv *env, jobject jthis) +{ + nsIDOMAttr* attr = (nsIDOMAttr*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!attr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getName: NULL pointer\n")); + return NULL; + } + + nsString name; + nsresult rv = attr->GetName(name); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getName: failed (%x)\n", rv)); + return NULL; + } + + char* cname = name.ToNewCString(); + jstring jname = env->NewStringUTF(cname); + if (!jname) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getName: NewStringUTF failed: %s\n", cname)); + } + delete[] cname; + + return jname; +} + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: getSpecified + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_AttrImpl_getSpecified + (JNIEnv *env, jobject jthis) +{ + nsIDOMAttr* attr = (nsIDOMAttr*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!attr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getSpecified: NULL pointer\n")); + return JNI_FALSE; + } + + PRBool specified = PR_FALSE; + nsresult rv = attr->GetSpecified(&specified); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getSpecified: failed (%x)\n", rv)); + return JNI_FALSE; + } + + return (specified == PR_TRUE) ? JNI_TRUE : JNI_FALSE; +} + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: getValue + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_AttrImpl_getValue + (JNIEnv *env, jobject jthis) +{ + nsIDOMAttr* attr = (nsIDOMAttr*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!attr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getValue: NULL pointer\n")); + return NULL; + } + + nsString value; + nsresult rv = attr->GetValue(value); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getValue: failed (%x)\n", rv)); + return NULL; + } + + char* cvalue = value.ToNewCString(); + jstring jval = env->NewStringUTF(cvalue); + if (!jval) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.getValue: NewStringUTF failed: %s\n", cvalue)); + } + delete[] cvalue; + + return jval; +} + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: setValue + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_AttrImpl_setValue + (JNIEnv *env, jobject jthis, jstring jval) +{ + nsIDOMAttr* attr = (nsIDOMAttr*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!attr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.setValue: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* cvalue = env->GetStringUTFChars(jval, &iscopy); + if (!cvalue) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.setValue: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = attr->SetValue(cvalue); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jval, cvalue); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.setValue: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_AttrImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMAttr* attr = (nsIDOMAttr*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!attr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Attr.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(attr); +} + diff --git a/mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.h new file mode 100644 index 00000000000..21372e028a9 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_AttrImpl.h @@ -0,0 +1,53 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_AttrImpl */ + +#ifndef _Included_org_mozilla_dom_AttrImpl +#define _Included_org_mozilla_dom_AttrImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_AttrImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_AttrImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: getName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_AttrImpl_getName + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: getSpecified + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_AttrImpl_getSpecified + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: getValue + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_AttrImpl_getValue + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_AttrImpl + * Method: setValue + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_AttrImpl_setValue + (JNIEnv *, jobject, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.cpp new file mode 100644 index 00000000000..d23d7cbe78e --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.cpp @@ -0,0 +1,296 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMCharacterData.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_CharacterDataImpl.h" + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: appendData + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_appendData + (JNIEnv *env, jobject jthis, jstring jvalue) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.appendData: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* value = env->GetStringUTFChars(jvalue, &iscopy); + if (!value) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.appendData: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = data->AppendData(value); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jvalue, value); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.appendData: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: deleteData + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_deleteData + (JNIEnv *env, jobject jthis, jint offset, jint count) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.deleteData: NULL pointer\n")); + return; + } + + nsresult rv = data->DeleteData((PRUint32) offset, (PRUint32) count); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.deleteData: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(data); +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: getData + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_CharacterDataImpl_getData + (JNIEnv *env, jobject jthis) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.getData: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = data->GetData(ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.getData: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.getData: NewStringUTF failed: %s\n", cret)); + } + delete[] cret; + + return jret; +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: getLength + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_dom_CharacterDataImpl_getLength + (JNIEnv *env, jobject jthis) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.getLength: NULL pointer\n")); + return 0; + } + + PRUint32 len = 0; + nsresult rv = data->GetLength(&len); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.getLength: failed (%x)\n", rv)); + return 0; + } + + return (jint) len; +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: insertData + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_insertData + (JNIEnv *env, jobject jthis, jint offset, jstring jvalue) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.insertData: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* value = env->GetStringUTFChars(jvalue, &iscopy); + if (!value) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.insertData: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = data->InsertData((PRUint32) offset, value); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jvalue, value); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.insertData: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: replaceData + * Signature: (IILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_replaceData + (JNIEnv *env, jobject jthis, jint offset, jint count, jstring jvalue) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.replaceData: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* value = env->GetStringUTFChars(jvalue, &iscopy); + if (!value) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.replaceData: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = data->ReplaceData((PRUint32) offset, (PRUint32) count, value); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jvalue, value); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.replaceData: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: setData + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_setData + (JNIEnv *env, jobject jthis, jstring jvalue) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.setData: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* value = env->GetStringUTFChars(jvalue, &iscopy); + if (!value) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.setData: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = data->SetData(value); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jvalue, value); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.setData: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: substringData + * Signature: (II)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_CharacterDataImpl_substringData + (JNIEnv *env, jobject jthis, jint offset, jint count) +{ + nsIDOMCharacterData* data = (nsIDOMCharacterData*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.substringData: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = data->SubstringData((PRUint32) offset, (PRUint32) count, ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.substringData: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("CharacterData.substringData: NewStringUTF failed: %s\n", cret)); + } + delete[] cret; + + return jret; +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.h new file mode 100644 index 00000000000..de815d0b6e9 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_CharacterDataImpl.h @@ -0,0 +1,85 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_CharacterDataImpl */ + +#ifndef _Included_org_mozilla_dom_CharacterDataImpl +#define _Included_org_mozilla_dom_CharacterDataImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: appendData + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_appendData + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: deleteData + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_deleteData + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: getData + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_CharacterDataImpl_getData + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: getLength + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_dom_CharacterDataImpl_getLength + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: insertData + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_insertData + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: replaceData + * Signature: (IILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_replaceData + (JNIEnv *, jobject, jint, jint, jstring); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: setData + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_CharacterDataImpl_setData + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_CharacterDataImpl + * Method: substringData + * Signature: (II)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_CharacterDataImpl_substringData + (JNIEnv *, jobject, jint, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.cpp new file mode 100644 index 00000000000..8b062b608a9 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.cpp @@ -0,0 +1,78 @@ +#include "org_mozilla_dom_DOMAccessorImpl.h" + +#include "prlog.h" +#include "javaDOMGlobals.h" +#include "nsIDocumentLoader.h" +#include "nsIServiceManager.h" + +#include "nsIJavaDOM.h" +#include "nsJavaDOMCID.h" + +static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID); + +static NS_DEFINE_IID(kJavaDOMFactoryCID, NS_JAVADOMFACTORY_CID); +static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID); + +/* + * Class: org_mozilla_dom_DOMAccessorImpl + * Method: register + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_register + (JNIEnv *, jclass jthis) +{ + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("DOMAccessor::register: registering %x\n", jthis)); + + nsIDocumentLoader* docLoaderService = nsnull; + nsISupports* javaDOM = nsnull; + + nsresult rv = nsServiceManager::GetService(kJavaDOMFactoryCID, + kIJavaDOMIID, + (nsISupports**) &javaDOM); + if (NS_FAILED(rv) || !javaDOM) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMAccessor::register: GetService(JavaDOM) failed: %x\n", + rv)); + } else { + rv = docLoaderService->AddObserver((nsIDocumentLoaderObserver*)javaDOM); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMAccessor::register: AddObserver(JavaDOM) failed x\n", + rv)); + } + } + nsServiceManager::ReleaseService(kDocLoaderServiceCID, docLoaderService); +} + +/* + * Class: org_mozilla_dom_DOMAccessorImpl + * Method: unregister + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_unregister + (JNIEnv *, jclass jthis) +{ + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("DOMAccessor::unregister: unregistering %x\n", jthis)); + + nsIDocumentLoader* docLoaderService = nsnull; + nsISupports* javaDOM = nsnull; + + nsresult rv = nsServiceManager::GetService(kJavaDOMFactoryCID, + kIJavaDOMIID, + (nsISupports**) &javaDOM); + if (NS_FAILED(rv) || !javaDOM) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMAccessor::unregister: GetService(JavaDOM) failed %x\n", + rv)); + } else { + rv = docLoaderService->RemoveObserver((nsIDocumentLoaderObserver*)javaDOM); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMAccessor::unregister: RemoveObserver(JavaDOM) failed x\n", + rv)); + } + } + nsServiceManager::ReleaseService(kDocLoaderServiceCID, docLoaderService); +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.h new file mode 100644 index 00000000000..ae493346328 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DOMAccessorImpl.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_DOMAccessorImpl */ + +#ifndef _Included_org_mozilla_dom_DOMAccessorImpl +#define _Included_org_mozilla_dom_DOMAccessorImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * 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); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.cpp b/mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.cpp new file mode 100644 index 00000000000..6d46b25d1f7 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.cpp @@ -0,0 +1,29 @@ +/* +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. +*/ + +#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(); +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.h b/mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.h new file mode 100644 index 00000000000..cba1e6a4735 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DOMGarbageCollector.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* 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 diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.cpp new file mode 100644 index 00000000000..aeeec8cfd5f --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.cpp @@ -0,0 +1,85 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMDOMImplementation.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_DOMImplementationImpl.h" + +/* + * Class: org_mozilla_dom_DOMImplementationImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMImplementationImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMDOMImplementation* dom = (nsIDOMDOMImplementation*) + env->GetLongField(jthis, JavaDOMGlobals::domImplementationPtrFID); + if (!dom) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("DOMImplementation.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(dom); +} + +/* + * Class: org_mozilla_dom_DOMImplementationImpl + * Method: hasFeature + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_DOMImplementationImpl_hasFeature + (JNIEnv *env, jobject jthis, jstring jfeature, jstring jversion) +{ + nsIDOMDOMImplementation* dom = (nsIDOMDOMImplementation*) + env->GetLongField(jthis, JavaDOMGlobals::domImplementationPtrFID); + if (!dom) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("DOMImplementation.hasFeature: NULL pointer\n")); + return JNI_FALSE; + } + + jboolean iscopy = JNI_FALSE; + const char* feature = env->GetStringUTFChars(jfeature, &iscopy); + if (!feature) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMImplementation.hasFeature: GetStringUTFChars feature failed\n")); + return JNI_FALSE; + } + + jboolean iscopy2 = JNI_FALSE; + const char* version = env->GetStringUTFChars(jversion, &iscopy2); + if (!version) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMImplementation.hasFeature: GetStringUTFChars version failed\n")); + return JNI_FALSE; + } + + PRBool ret = PR_FALSE; + nsresult rv = dom->HasFeature(feature, version, &ret); + if (iscopy2 == JNI_TRUE) + env->ReleaseStringUTFChars(jversion, version); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jfeature, feature); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DOMImplementation.hasFeature: failed (%x)\n", rv)); + } + + return ret == PR_TRUE ? JNI_TRUE : JNI_FALSE; +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.h new file mode 100644 index 00000000000..a2a228c17f7 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DOMImplementationImpl.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_DOMImplementationImpl */ + +#ifndef _Included_org_mozilla_dom_DOMImplementationImpl +#define _Included_org_mozilla_dom_DOMImplementationImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_DOMImplementationImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMImplementationImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_DOMImplementationImpl + * Method: hasFeature + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_DOMImplementationImpl_hasFeature + (JNIEnv *, jobject, jstring, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp new file mode 100644 index 00000000000..37b0b47362f --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp @@ -0,0 +1,659 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMDocument.h" +#include "nsIDOMAttr.h" +#include "nsIDOMComment.h" +#include "nsIDOMElement.h" +#include "nsIDOMDocumentType.h" +#include "nsIDOMDocumentFragment.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMCDATASection.h" +#include "nsIDOMDOMImplementation.h" +#include "nsIDOMProcessingInstruction.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_DocumentImpl.h" + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: initialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DocumentImpl_initialize + (JNIEnv *env, jclass) +{ + if (!JavaDOMGlobals::log) { + JavaDOMGlobals::Initialize(env); + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("Document.initialize\n")); + } +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DocumentImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(doc); +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createAttribute + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createAttribute + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createAttribute: NULL pointer\n")); + return NULL; + } + + nsIDOMAttr* ret = nsnull; + jboolean iscopy = JNI_FALSE; + const char* name = env->GetStringUTFChars(jname, &iscopy); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createAttribute: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = doc->CreateAttribute(name, &ret); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, name); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createAttribute: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::attrClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createAttribute: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createAttribute: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createCDATASection + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/CDATASection; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createCDATASection + (JNIEnv *env, jobject jthis, jstring jdata) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createCDATASection: NULL pointer\n")); + return NULL; + } + + nsIDOMCDATASection* ret = nsnull; + jboolean iscopy = JNI_FALSE; + const char* data = env->GetStringUTFChars(jdata, &iscopy); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createCDATASection: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = doc->CreateCDATASection(data, &ret); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jdata, data); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createCDATASection: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::cDataSectionClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createCDATASection: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createCDATASection: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createComment + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Comment; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createComment + (JNIEnv *env, jobject jthis, jstring jdata) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createComment: NULL pointer\n")); + return NULL; + } + + nsIDOMComment* ret = nsnull; + jboolean iscopy = JNI_FALSE; + const char* data = env->GetStringUTFChars(jdata, &iscopy); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createComment: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = doc->CreateComment(data, &ret); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jdata, data); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createComment: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::commentClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createComment: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createComment: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createDocumentFragment + * Signature: ()Lorg/w3c/dom/DocumentFragment; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createDocumentFragment + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createDocumentFragment: NULL pointer\n")); + return NULL; + } + + nsIDOMDocumentFragment* ret = nsnull; + nsresult rv = doc->CreateDocumentFragment(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createDocumentFragment: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::documentFragmentClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createDocumentFragment: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createDocumentFragment: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createElement + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Element; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createElement + (JNIEnv *env, jobject jthis, jstring jtagName) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createElement: NULL pointer\n")); + return NULL; + } + + nsIDOMElement* ret = nsnull; + jboolean iscopy = JNI_FALSE; + const char* tagName = env->GetStringUTFChars(jtagName, &iscopy); + if (!tagName) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createElement: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = doc->CreateElement(tagName, &ret); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jtagName, tagName); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createElement: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::elementClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createElement: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createElement: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createEntityReference + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/EntityReference; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createEntityReference + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createEntityReference: NULL pointer\n")); + return NULL; + } + + nsIDOMCDATASection* ret = nsnull; + jboolean iscopy = JNI_FALSE; + const char* name = env->GetStringUTFChars(jname, &iscopy); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createEntityReference: GetStringUTFChars failed\n")); + return NULL; + } + + + nsresult rv = doc->CreateCDATASection(name, &ret); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, name); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createEntityReference: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::entityReferenceClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createEntityReference: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createEntityReference: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createProcessingInstruction + * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/w3c/dom/ProcessingInstruction; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createProcessingInstruction + (JNIEnv *env, jobject jthis, jstring jtarget, jstring jdata) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createProcessingInstruction: NULL pointer\n")); + return NULL; + } + + nsIDOMProcessingInstruction* ret = nsnull; + jboolean iscopy = JNI_FALSE; + jboolean iscopy2 = JNI_FALSE; + const char* target = env->GetStringUTFChars(jtarget, &iscopy); + if (!target) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createProcessingInstruction: GetStringUTFChars target failed\n")); + return NULL; + } + + const char* data = env->GetStringUTFChars(jdata, &iscopy2); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createProcessingInstruction: GetStringUTFChars data failed\n")); + return NULL; + } + + nsresult rv = doc->CreateProcessingInstruction(target, data, &ret); + if (iscopy2 == JNI_TRUE) + env->ReleaseStringUTFChars(jdata, data); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jtarget, target); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createProcessingInstruction: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::processingInstructionClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createProcessingInstruction: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createProcessingInstruction: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createTextNode + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Text; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createTextNode + (JNIEnv *env, jobject jthis, jstring jdata) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Document.createTextNode: NULL pointer\n")); + return NULL; + } + + nsIDOMText* ret = nsnull; + jboolean iscopy = JNI_FALSE; + const char* data = env->GetStringUTFChars(jdata, &iscopy); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createAttribute: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = doc->CreateTextNode(data, &ret); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jdata, data); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createTextNode: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::textClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createTextNode: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.createTextNode: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getDoctype + * Signature: ()Lorg/w3c/dom/DocumentType; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getDoctype + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDoctype: NULL pointer\n")); + return NULL; + } + + nsIDOMDocumentType* docType = nsnull; + nsresult rv = doc->GetDoctype(&docType); + if (NS_FAILED(rv) || !docType) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDoctype: error %x\n", rv)); + return NULL; + } + + jobject jDocType = env->AllocObject(JavaDOMGlobals::documentTypeClass); + jobject jret = env->AllocObject(JavaDOMGlobals::attrClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDoctype: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jDocType, JavaDOMGlobals::nodePtrFID, (jlong) docType); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDoctype: failed to set node ptr: %x\n", docType)); + return NULL; + } + + docType->AddRef(); + return jDocType; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getDocumentElement + * Signature: ()Lorg/w3c/dom/Element; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getDocumentElement + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDocumentElement: NULL pointer\n")); + return NULL; + } + + nsIDOMElement* element = nsnull; + nsresult rv = doc->GetDocumentElement(&element); + if (NS_FAILED(rv) || !element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDocumentElement: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::elementClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDocumentElement: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) element); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getDocumentElement: failed to set node ptr: %x\n", element)); + return NULL; + } + + element->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getElementsByTagName + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/NodeList; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getElementsByTagName + (JNIEnv *env, jobject jthis, jstring jtagName) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getElementsByTagName: NULL pointer\n")); + return NULL; + } + + nsIDOMNodeList* elements = nsnull; + jboolean iscopy = JNI_FALSE; + const char* tagName = env->GetStringUTFChars(jtagName, &iscopy); + if (!tagName) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getElementsByTagName: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = doc->GetElementsByTagName(tagName, &elements); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jtagName, tagName); + if (NS_FAILED(rv) || !elements) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getElementsByTagName: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::nodeListClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getElementsByTagName: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) elements); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getElementsByTagName: failed to set node ptr: %x\n", elements)); + return NULL; + } + + elements->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getImplementation + * Signature: ()Lorg/w3c/dom/DOMImplementation; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getImplementation + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocument* doc = (nsIDOMDocument*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!doc) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getImplementation: NULL pointer\n")); + return NULL; + } + + nsIDOMDOMImplementation* impl = nsnull; + nsresult rv = doc->GetImplementation(&impl); + if (NS_FAILED(rv) || !impl) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getImplementation: error %x\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::domImplementationClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getImplementation: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) impl); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Document.getImplementation: failed to set node ptr: %x\n", impl)); + return NULL; + } + + impl->AddRef(); + return jret; +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.h new file mode 100644 index 00000000000..d3728f4ec1c --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DocumentImpl.h @@ -0,0 +1,125 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_DocumentImpl */ + +#ifndef _Included_org_mozilla_dom_DocumentImpl +#define _Included_org_mozilla_dom_DocumentImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createAttribute + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createAttribute + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createCDATASection + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/CDATASection; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createCDATASection + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createComment + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Comment; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createComment + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createDocumentFragment + * Signature: ()Lorg/w3c/dom/DocumentFragment; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createDocumentFragment + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createElement + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Element; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createElement + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createEntityReference + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/EntityReference; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createEntityReference + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createProcessingInstruction + * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/w3c/dom/ProcessingInstruction; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createProcessingInstruction + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: createTextNode + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Text; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_createTextNode + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DocumentImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getDoctype + * Signature: ()Lorg/w3c/dom/DocumentType; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getDoctype + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getDocumentElement + * Signature: ()Lorg/w3c/dom/Element; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getDocumentElement + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getElementsByTagName + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/NodeList; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getElementsByTagName + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: getImplementation + * Signature: ()Lorg/w3c/dom/DOMImplementation; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_getImplementation + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_DocumentImpl + * Method: initialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DocumentImpl_initialize + (JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.cpp new file mode 100644 index 00000000000..565a498baf5 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.cpp @@ -0,0 +1,160 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMDocumentType.h" +#include "nsIDOMNamedNodeMap.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_DocumentImpl.h" + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DocumentTypeImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocumentType* docType = (nsIDOMDocumentType*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!docType) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("DocumentType.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(docType); +} + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: getEntities + * Signature: ()Lorg/w3c/dom/NamedNodeMap; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentTypeImpl_getEntities + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocumentType* docType = (nsIDOMDocumentType*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!docType) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("DocumentType.getEntities: NULL pointer\n")); + return NULL; + } + + nsIDOMNamedNodeMap* nodeMap = nsnull; + nsresult rv = docType->GetEntities(&nodeMap); + if (NS_FAILED(rv) || !nodeMap) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getEntities: failed (%x)\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::namedNodeMapClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getEntities: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) nodeMap); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getEntities: failed to set node ptr: %x\n", nodeMap)); + return NULL; + } + + nodeMap->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: getName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_DocumentTypeImpl_getName + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocumentType* docType = (nsIDOMDocumentType*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!docType) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("DocumentType.getName: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = docType->GetName(ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getName: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getName: NewStringUTF failed: %s\n", cret)); + } + delete[] cret; + + return jret; +} + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: getNotations + * Signature: ()Lorg/w3c/dom/NamedNodeMap; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentTypeImpl_getNotations + (JNIEnv *env, jobject jthis) +{ + nsIDOMDocumentType* docType = (nsIDOMDocumentType*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!docType) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("DocumentType.getNotations: NULL pointer\n")); + return NULL; + } + + nsIDOMNamedNodeMap* nodeMap = nsnull; + nsresult rv = docType->GetNotations(&nodeMap); + if (NS_FAILED(rv) || !nodeMap) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getNotations: failed (%x)\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::namedNodeMapClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getNotations: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) nodeMap); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("DocumentType.getNotations: failed to set node ptr: %x\n", nodeMap)); + return NULL; + } + + nodeMap->AddRef(); + return jret; +} + diff --git a/mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.h new file mode 100644 index 00000000000..e35861670ea --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_DocumentTypeImpl.h @@ -0,0 +1,46 @@ +#include "nsIDOMDocumentType.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_DocumentTypeImpl.h" + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_DocumentTypeImpl_finalize + (JNIEnv *, jobject) +{ +} + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: getEntities + * Signature: ()Lorg/w3c/dom/NamedNodeMap; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentTypeImpl_getEntities + (JNIEnv *, jobject) +{ + return NULL; +} + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: getName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_DocumentTypeImpl_getName + (JNIEnv *, jobject) +{ + return NULL; +} + +/* + * Class: org_mozilla_dom_DocumentTypeImpl + * Method: getNotations + * Signature: ()Lorg/w3c/dom/NamedNodeMap; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentTypeImpl_getNotations + (JNIEnv *, jobject) +{ + return NULL; +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.cpp new file mode 100644 index 00000000000..ec22f030ac1 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.cpp @@ -0,0 +1,430 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMElement.h" +#include "nsIDOMAttr.h" +#include "nsIDOMNodeList.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_ElementImpl.h" + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(element); +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getAttribute + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ElementImpl_getAttribute + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.getAttribute: NULL pointer\n")); + return NULL; + } + + jboolean iscopy = JNI_FALSE; + const char* cname = env->GetStringUTFChars(jname, &iscopy); + if (!cname) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttribute: GetStringUTFChars failed\n")); + return NULL; + } + + nsString attr; + nsresult rv = element->GetAttribute(cname, attr); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, cname); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttribute: failed (%x)\n", rv)); + return NULL; + } + + char* cattr = attr.ToNewCString(); + jstring jattr = env->NewStringUTF(cattr); + if (!jattr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttribute: NewStringUTF failed (%s)\n", cattr)); + return NULL; + } + delete[] cattr; + + return jattr; +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getAttributeNode + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_getAttributeNode + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.getAttributeNode: NULL pointer\n")); + return NULL; + } + + jboolean iscopy = JNI_FALSE; + const char* cname = env->GetStringUTFChars(jname, &iscopy); + if (!cname) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttributeNode: GetStringUTFChars failed\n")); + return NULL; + } + + nsIDOMAttr* attr = nsnull; + nsresult rv = element->GetAttributeNode(cname, &attr); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, cname); + if (NS_FAILED(rv) || !attr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttributeNode: failed (%x)\n", rv)); + return NULL; + } + + jobject jattr = env->AllocObject(JavaDOMGlobals::attrClass); + if (!jattr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttributeNode: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jattr, JavaDOMGlobals::nodePtrFID, (jlong) attr); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getAttributeNode: failed to set node ptr: %x\n", attr)); + return NULL; + } + + attr->AddRef(); + return jattr; +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getElementsByTagName + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/NodeList; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_getElementsByTagName + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.getElementsByTagName: NULL pointer\n")); + return NULL; + } + + jboolean iscopy = JNI_FALSE; + const char* cname = env->GetStringUTFChars(jname, &iscopy); + if (!cname) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getElementsByTagName: GetStringUTFChars failed\n")); + return NULL; + } + + nsIDOMNodeList* nodes = nsnull; + nsresult rv = element->GetElementsByTagName(cname, &nodes); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, cname); + if (NS_FAILED(rv) || !nodes) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getElementsByTagName: failed (%x)\n", rv)); + return NULL; + } + + jobject jnodes = env->AllocObject(JavaDOMGlobals::nodeListClass); + if (!jnodes) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getElementsByTagName: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jnodes, JavaDOMGlobals::nodeListPtrFID, (jlong) nodes); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getElementsByTagName: failed to set node ptr: %x\n", nodes)); + return NULL; + } + + nodes->AddRef(); + return jnodes; +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getTagName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ElementImpl_getTagName + (JNIEnv *env, jobject jthis) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.getTagName: NULL pointer\n")); + return NULL; + } + + nsString tagName; + nsresult rv = element->GetTagName(tagName); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getTagName: failed (%x)\n", rv)); + return NULL; + } + + char* cTagName = tagName.ToNewCString(); + jstring jTagName = env->NewStringUTF(cTagName); + if (!jTagName) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.getTagName: NewStringUTF failed (%s)\n", cTagName)); + return NULL; + } + delete[] cTagName; + + return jTagName; +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: normalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_normalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.normalize: NULL pointer\n")); + return; + } + + nsresult rv = element->Normalize(); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.normalize: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: removeAttribute + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_removeAttribute + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.removeAttribute: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* name = env->GetStringUTFChars(jname, &iscopy); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.removeAttribute: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = element->RemoveAttribute(name); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, name); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.removeAttribute: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: removeAttributeNode + * Signature: (Lorg/w3c/dom/Attr;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_removeAttributeNode + (JNIEnv *env, jobject jthis, jobject joldAttr) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.removeAttributeNode: NULL pointer\n")); + return NULL; + } + + nsIDOMAttr* oldAttr = (nsIDOMAttr*) + env->GetLongField(joldAttr, JavaDOMGlobals::nodePtrFID); + if (!oldAttr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.removeAttributeNode: NULL arg pointer\n")); + return NULL; + } + + nsIDOMAttr* ret = nsnull; + nsresult rv = element->RemoveAttributeNode(oldAttr, &ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.removeAttributeNode: failed (%x)\n", rv)); + return NULL; + } + + jobject jattr = env->AllocObject(JavaDOMGlobals::attrClass); + if (!jattr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.removeAttributeNode: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jattr, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.removeAttributeNode: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jattr; +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: setAttribute + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_setAttribute + (JNIEnv *env, jobject jthis, jstring jname, jstring jvalue) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.setAttribute: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* name = env->GetStringUTFChars(jname, &iscopy); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.setAttribute: GetStringUTFChars name failed\n")); + return; + } + + jboolean iscopy2 = JNI_FALSE; + const char* value = env->GetStringUTFChars(jvalue, &iscopy2); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.setAttribute: GetStringUTFChars value failed\n")); + return; + } + + nsresult rv = element->SetAttribute(name, value); + if (iscopy2 == JNI_TRUE) + env->ReleaseStringUTFChars(jvalue, value); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, name); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.setAttribute: failed (%x)\n", rv)); + return; + } +} + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: setAttributeNode + * Signature: (Lorg/w3c/dom/Attr;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_setAttributeNode + (JNIEnv *env, jobject jthis, jobject jnewAttr) +{ + nsIDOMElement* element = (nsIDOMElement*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!element) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.setAttributeNode: NULL pointer\n")); + return NULL; + } + + nsIDOMAttr* newAttr = (nsIDOMAttr*) + env->GetLongField(jnewAttr, JavaDOMGlobals::nodePtrFID); + if (!newAttr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Element.setAttributeNode: NULL arg pointer\n")); + return NULL; + } + + nsIDOMAttr* ret = nsnull; + nsresult rv = element->SetAttributeNode(newAttr, &ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.setAttributeNode: failed (%x)\n", rv)); + return NULL; + } + + jobject jattr = env->AllocObject(JavaDOMGlobals::attrClass); + if (!jattr) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.setAttributeNode: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jattr, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Element.setAttributeNode: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jattr; +} + diff --git a/mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.h new file mode 100644 index 00000000000..1ea682cf3dd --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_ElementImpl.h @@ -0,0 +1,93 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_ElementImpl */ + +#ifndef _Included_org_mozilla_dom_ElementImpl +#define _Included_org_mozilla_dom_ElementImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_ElementImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getAttribute + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ElementImpl_getAttribute + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getAttributeNode + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_getAttributeNode + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getElementsByTagName + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/NodeList; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_getElementsByTagName + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: getTagName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ElementImpl_getTagName + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: normalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_normalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: removeAttribute + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_removeAttribute + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: removeAttributeNode + * Signature: (Lorg/w3c/dom/Attr;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_removeAttributeNode + (JNIEnv *, jobject, jobject); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: setAttribute + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ElementImpl_setAttribute + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_mozilla_dom_ElementImpl + * Method: setAttributeNode + * Signature: (Lorg/w3c/dom/Attr;)Lorg/w3c/dom/Attr; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_ElementImpl_setAttributeNode + (JNIEnv *, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.cpp new file mode 100644 index 00000000000..0a6c4d13d4c --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.cpp @@ -0,0 +1,264 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMNamedNodeMap.h" +#include "nsIDOMNode.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_NamedNodeMapImpl.h" + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!map) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(map); +} + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: getLength + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_getLength + (JNIEnv *env, jobject jthis) +{ + nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!map) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.getLength: NULL pointer\n")); + return 0; + } + + PRUint32 length = 0; + nsresult rv = map->GetLength(&length); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.getLength: failed (%x)\n", rv)); + return 0; + } + + return (jint) length; +} + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: getNamedItem + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_getNamedItem + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!map) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.getNamedItem: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* node = nsnull; + jboolean iscopy = JNI_FALSE; + const char* name = env->GetStringUTFChars(jname, &iscopy); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.getNamedItem: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = map->GetNamedItem(name, &node); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, name); + if (NS_FAILED(rv) || !node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.getNamedItem: failed (%x)\n", rv)); + return NULL; + } + + jobject jnode = env->AllocObject(JavaDOMGlobals::nodeClass); + if (!jnode) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.getNamedItem: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jnode, JavaDOMGlobals::nodePtrFID, (jlong) node); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.getNamedItem: failed to set node ptr: %x\n", node)); + return NULL; + } + + node->AddRef(); + return jnode; +} + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: item + * Signature: (I)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_item + (JNIEnv *env, jobject jthis, jint jindex) +{ + nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!map) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.item: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* node = nsnull; + nsresult rv = map->Item((PRUint32) jindex, &node); + if (NS_FAILED(rv) || !node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.item: failed (%x)\n", rv)); + return NULL; + } + + jobject jnode = env->AllocObject(JavaDOMGlobals::nodeClass); + if (!jnode) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.item: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jnode, JavaDOMGlobals::nodePtrFID, (jlong) node); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.item: failed to set node ptr: %x\n", node)); + return NULL; + } + + node->AddRef(); + return jnode; +} + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: removeNamedItem + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_removeNamedItem + (JNIEnv *env, jobject jthis, jstring jname) +{ + nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!map) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.removeNamedItem: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* node = nsnull; + jboolean iscopy = JNI_FALSE; + const char* name = env->GetStringUTFChars(jname, &iscopy); + if (!name) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.removeNamedItem: GetStringUTFChars failed\n")); + return NULL; + } + + nsresult rv = map->RemoveNamedItem(name, &node); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jname, name); + if (NS_FAILED(rv) || !node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.removeNamedItem: failed (%x)\n", rv)); + return NULL; + } + + jobject jnode = env->AllocObject(JavaDOMGlobals::nodeClass); + if (!jnode) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.removeNamedItem: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jnode, JavaDOMGlobals::nodePtrFID, (jlong) node); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.removeNamedItem: failed to set node ptr: %x\n", node)); + return NULL; + } + + node->AddRef(); + return jnode; +} + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: setNamedItem + * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_setNamedItem + (JNIEnv *env, jobject jthis, jobject jarg) +{ + nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!map) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.setNamedItem: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* arg = (nsIDOMNode*) + env->GetLongField(jarg, JavaDOMGlobals::nodePtrFID); + if (!arg) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeMap.setNamedItem: NULL item pointer\n")); + return NULL; + } + + nsIDOMNode* node = nsnull; + nsresult rv = map->SetNamedItem(arg, &node); + if (NS_FAILED(rv) || !node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeMap.setNamedItem: failed (%x)\n", rv)); + return NULL; + } + + jobject jnode = env->AllocObject(JavaDOMGlobals::nodeClass); + if (!jnode) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.setNamedItem: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jnode, JavaDOMGlobals::nodePtrFID, (jlong) node); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NamedNodeMap.setNamedItem: failed to set node ptr: %x\n", node)); + return NULL; + } + + node->AddRef(); + return jnode; +} + diff --git a/mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.h new file mode 100644 index 00000000000..7a207d630ae --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_NamedNodeMapImpl.h @@ -0,0 +1,61 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_NamedNodeMapImpl */ + +#ifndef _Included_org_mozilla_dom_NamedNodeMapImpl +#define _Included_org_mozilla_dom_NamedNodeMapImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: getLength + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_getLength + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: getNamedItem + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_getNamedItem + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: item + * Signature: (I)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_item + (JNIEnv *, jobject, jint); + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: removeNamedItem + * Signature: (Ljava/lang/String;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_removeNamedItem + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_dom_NamedNodeMapImpl + * Method: setNamedItem + * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_setNamedItem + (JNIEnv *, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.cpp new file mode 100644 index 00000000000..596d76de422 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.cpp @@ -0,0 +1,718 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMNamedNodeMap.h" +#include "nsIDOMDocument.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_NodeImpl.h" + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(node); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: appendChild + * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_appendChild + (JNIEnv *env, jobject jthis, jobject jchild) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.appendChild: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* child = (nsIDOMNode*) + env->GetLongField(jchild, JavaDOMGlobals::nodePtrFID); + if (!child) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.appendChild: NULL child pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->AppendChild(child, &ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.appendChild: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: cloneNode + * Signature: (Z)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_cloneNode + (JNIEnv *env, jobject jthis, jboolean jdeep) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.cloneNode: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + PRBool deep = jdeep == JNI_TRUE ? PR_TRUE : PR_FALSE; + nsresult rv = node->CloneNode(deep, &ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.cloneNode: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getAttributes + * Signature: ()Lorg/w3c/dom/NamedNodeMap; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getAttributes + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getAttributes: NULL pointer\n")); + return NULL; + } + + nsIDOMNamedNodeMap* nodeMap = nsnull; + nsresult rv = node->GetAttributes(&nodeMap); + if (NS_FAILED(rv) || !nodeMap) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getAttributes: failed (%x)\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::namedNodeMapClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getAttributes: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) nodeMap); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getAttributes: failed to set node ptr: %x\n", nodeMap)); + return NULL; + } + + nodeMap->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getChildNodes + * Signature: ()Lorg/w3c/dom/NodeList; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getChildNodes + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getChildNodes: NULL pointer\n")); + return NULL; + } + + nsIDOMNodeList* nodeList = nsnull; + nsresult rv = node->GetChildNodes(&nodeList); + if (NS_FAILED(rv) || !nodeList) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getChildNodes: failed (%x)\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::nodeListClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getChildNodes: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodeListPtrFID, (jlong) nodeList); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getChildNodes: failed to set node ptr: %x\n", nodeList)); + return NULL; + } + + nodeList->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getFirstChild + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getFirstChild + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getFirstChild: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->GetFirstChild(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getFirstChild: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getLastChild + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getLastChild + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getLastChild: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->GetLastChild(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getLastChild: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNextSibling + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getNextSibling + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getNextSibling: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->GetNextSibling(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNextSibling: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNodeName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_NodeImpl_getNodeName + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getNodeName: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = node->GetNodeName(ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeName: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeName: NewStringUTF failed (%s)\n", cret)); + return NULL; + } + delete[] cret; + + return jret; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNodeType + * Signature: ()S + */ +JNIEXPORT jshort JNICALL Java_org_mozilla_dom_NodeImpl_getNodeType + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getNodeType: NULL pointer\n")); + return (jshort) NULL; + } + + PRUint16 type; + nsresult rv = node->GetNodeType(&type); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeType: failed (%x)\n", rv)); + return (jshort) NULL; + } + + jfieldID typeFID = NULL; + switch (type) { + case nsIDOMNode::ATTRIBUTE_NODE: + typeFID = JavaDOMGlobals::nodeTypeAttributeFID; + break; + + case nsIDOMNode::CDATA_SECTION_NODE: + typeFID = JavaDOMGlobals::nodeTypeCDataSectionFID; + break; + + case nsIDOMNode::COMMENT_NODE: + typeFID = JavaDOMGlobals::nodeTypeCommentFID; + break; + + case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: + typeFID = JavaDOMGlobals::nodeTypeDocumentFragmentFID; + break; + + case nsIDOMNode::DOCUMENT_NODE: + typeFID = JavaDOMGlobals::nodeTypeDocumentFID; + break; + + case nsIDOMNode::DOCUMENT_TYPE_NODE: + typeFID = JavaDOMGlobals::nodeTypeDocumentTypeFID; + break; + + case nsIDOMNode::ELEMENT_NODE: + typeFID = JavaDOMGlobals::nodeTypeElementFID; + break; + + case nsIDOMNode::ENTITY_NODE: + typeFID = JavaDOMGlobals::nodeTypeEntityFID; + break; + + case nsIDOMNode::ENTITY_REFERENCE_NODE: + typeFID = JavaDOMGlobals::nodeTypeEntityReferenceFID; + break; + + case nsIDOMNode::NOTATION_NODE: + typeFID = JavaDOMGlobals::nodeTypeNotationFID; + break; + + case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: + typeFID = JavaDOMGlobals::nodeTypeProcessingInstructionFID; + break; + + case nsIDOMNode::TEXT_NODE: + typeFID = JavaDOMGlobals::nodeTypeTextFID; + break; + } + + jshort ret = 0; + if (typeFID) { + jclass nodeClass = env->GetObjectClass(jthis); + if (!nodeClass) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeType: GetObjectClass failed (%x)\n", jthis)); + return ret; + } + + ret = env->GetStaticShortField(nodeClass, typeFID); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeType: typeFID failed\n")); + return ret; + } + } else { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeType: illegal type %d\n", type)); + } + + return ret; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNodeValue + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_NodeImpl_getNodeValue + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getNodeValue: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = node->GetNodeValue(ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeValue: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getNodeValue: NewStringUTF failed (%s)\n", cret)); + return NULL; + } + delete[] cret; + + return jret; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getOwnerDocument + * Signature: ()Lorg/w3c/dom/Document; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getOwnerDocument + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getOwnerDocument: NULL pointer\n")); + return NULL; + } + + nsIDOMDocument* ret = nsnull; + nsresult rv = node->GetOwnerDocument(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getOwnerDocument: failed (%x)\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::documentClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getOwnerDocument: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getOwnerDocument: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getParentNode + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getParentNode + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getParentNode: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->GetParentNode(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getParentNode: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getPreviousSibling + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getPreviousSibling + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.getPreviousSibling: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->GetPreviousSibling(&ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.getPreviousSibling: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: hasChildNodes + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_NodeImpl_hasChildNodes + (JNIEnv *env, jobject jthis) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.hasChildNodes: NULL pointer\n")); + return (jboolean) NULL; + } + + PRBool ret = PR_FALSE; + nsresult rv = node->HasChildNodes(&ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.hasChildNodes: failed (%x)\n", rv)); + return (jboolean) NULL; + } + + return ret == PR_TRUE ? JNI_TRUE : JNI_FALSE; +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: insertBefore + * Signature: (Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_insertBefore + (JNIEnv *env, jobject jthis, jobject jnewChild, jobject jrefChild) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.insertBefore: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* newChild = (nsIDOMNode*) + env->GetLongField(jnewChild, JavaDOMGlobals::nodePtrFID); + if (!newChild) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.insertBefore: NULL newChild pointer\n")); + return NULL; + } + + nsIDOMNode* refChild = (nsIDOMNode*) + env->GetLongField(jrefChild, JavaDOMGlobals::nodePtrFID); + if (!refChild) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.insertBefore: NULL refChild pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->InsertBefore(newChild, refChild, &ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.insertBefore: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: removeChild + * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_removeChild + (JNIEnv *env, jobject jthis, jobject joldChild) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.removeChild: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* oldChild = (nsIDOMNode*) + env->GetLongField(joldChild, JavaDOMGlobals::nodePtrFID); + if (!oldChild) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.removeChild: NULL oldChild pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->RemoveChild(oldChild, &ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.removeChild: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: replaceChild + * Signature: (Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_replaceChild + (JNIEnv *env, jobject jthis, jobject jnewChild, jobject joldChild) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.replaceChild: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* newChild = (nsIDOMNode*) + env->GetLongField(jnewChild, JavaDOMGlobals::nodePtrFID); + if (!newChild) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.replaceChild: NULL newChild pointer\n")); + return NULL; + } + + nsIDOMNode* oldChild = (nsIDOMNode*) + env->GetLongField(joldChild, JavaDOMGlobals::nodePtrFID); + if (!oldChild) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.replaceChild: NULL oldChild pointer\n")); + return NULL; + } + + nsIDOMNode* ret = nsnull; + nsresult rv = node->ReplaceChild(newChild, oldChild, &ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.replaceChild: failed (%x)\n", rv)); + return NULL; + } + + return JavaDOMGlobals::CreateNodeSubtype(env, ret); +} + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: setNodeValue + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeImpl_setNodeValue + (JNIEnv *env, jobject jthis, jstring jvalue) +{ + nsIDOMNode* node = (nsIDOMNode*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Node.setNodeValue: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* value = env->GetStringUTFChars(jvalue, &iscopy); + if (!value) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.setNodeValue: GetStringUTFChars failed\n")); + return; + } + + nsresult rv = node->SetNodeValue(value); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jvalue, value); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Node.setNodeValue: failed (%x)\n", rv)); + return; + } +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.h new file mode 100644 index 00000000000..55aac51117e --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_NodeImpl.h @@ -0,0 +1,165 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_NodeImpl */ + +#ifndef _Included_org_mozilla_dom_NodeImpl +#define _Included_org_mozilla_dom_NodeImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_NodeImpl + * Method: appendChild + * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_appendChild + (JNIEnv *, jobject, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: cloneNode + * Signature: (Z)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_cloneNode + (JNIEnv *, jobject, jboolean); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getAttributes + * Signature: ()Lorg/w3c/dom/NamedNodeMap; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getAttributes + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getChildNodes + * Signature: ()Lorg/w3c/dom/NodeList; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getChildNodes + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getFirstChild + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getFirstChild + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getLastChild + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getLastChild + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNextSibling + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getNextSibling + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNodeName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_NodeImpl_getNodeName + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNodeType + * Signature: ()S + */ +JNIEXPORT jshort JNICALL Java_org_mozilla_dom_NodeImpl_getNodeType + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getNodeValue + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_NodeImpl_getNodeValue + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getOwnerDocument + * Signature: ()Lorg/w3c/dom/Document; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getOwnerDocument + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getParentNode + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getParentNode + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: getPreviousSibling + * Signature: ()Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_getPreviousSibling + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: hasChildNodes + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_NodeImpl_hasChildNodes + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: insertBefore + * Signature: (Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_insertBefore + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: removeChild + * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_removeChild + (JNIEnv *, jobject, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: replaceChild + * Signature: (Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_replaceChild + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: org_mozilla_dom_NodeImpl + * Method: setNodeValue + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeImpl_setNodeValue + (JNIEnv *, jobject, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.cpp new file mode 100644 index 00000000000..4bdccf0644c --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.cpp @@ -0,0 +1,110 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_NodeListImpl.h" + +/* + * Class: org_mozilla_dom_NodeListImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeListImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMNodeList* nodes = (nsIDOMNodeList*) + env->GetLongField(jthis, JavaDOMGlobals::nodeListPtrFID); + if (!nodes) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeList.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(nodes); +} + +/* + * Class: org_mozilla_dom_NodeListImpl + * Method: getLength + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_dom_NodeListImpl_getLength + (JNIEnv *env, jobject jthis) +{ + nsIDOMNodeList* nodes = (nsIDOMNodeList*) + env->GetLongField(jthis, JavaDOMGlobals::nodeListPtrFID); + if (!nodes) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeList.getLength: NULL pointer\n")); + return 0; + } + + PRUint32 length = 0; + nsresult rv = nodes->GetLength(&length); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeList.getLength: failed (%x)\n", rv)); + return 0; + } + + return (jint) length; +} + +/* + * Class: org_mozilla_dom_NodeListImpl + * Method: item + * Signature: (I)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeListImpl_item + (JNIEnv *env, jobject jthis, jint jindex) +{ + nsIDOMNodeList* nodes = (nsIDOMNodeList*) + env->GetLongField(jthis, JavaDOMGlobals::nodeListPtrFID); + if (!nodes) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NodeList.item: NULL pointer\n")); + return NULL; + } + + nsIDOMNode* node = NULL; + nsresult rv = nodes->Item((PRUint32) jindex, &node); + if (NS_FAILED(rv) || !node) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeList.item: failed (%x)\n", rv)); + return NULL; + } + + jobject jnode = env->AllocObject(JavaDOMGlobals::nodeClass); + if (!jnode) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeList.item: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jnode, JavaDOMGlobals::nodePtrFID, (jlong) node); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("NodeList.item: failed to set node ptr: %x\n", node)); + return NULL; + } + + node->AddRef(); + return jnode; +} + diff --git a/mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.h new file mode 100644 index 00000000000..30bc172683e --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_NodeListImpl.h @@ -0,0 +1,37 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_NodeListImpl */ + +#ifndef _Included_org_mozilla_dom_NodeListImpl +#define _Included_org_mozilla_dom_NodeListImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_NodeListImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeListImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeListImpl + * Method: getLength + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_dom_NodeListImpl_getLength + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_NodeListImpl + * Method: item + * Signature: (I)Lorg/w3c/dom/Node; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeListImpl_item + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.cpp new file mode 100644 index 00000000000..45e34a25b16 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.cpp @@ -0,0 +1,144 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMProcessingInstruction.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_ProcessingInstructionImpl.h" + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!pi) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("ProcessingInstruction.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(pi); +} + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: getData + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_getData + (JNIEnv *env, jobject jthis) +{ + nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!pi) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("ProcessingInstruction.getData: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = pi->GetData(ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("ProcessingInstruction.getData: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("ProcessingInstruction.getData: NewStringUTF failed (%s)\n", cret)); + return NULL; + } + delete[] cret; + + return jret; +} + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: getTarget + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_getTarget + (JNIEnv *env, jobject jthis) +{ + nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!pi) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("ProcessingInstruction.getTarget: NULL pointer\n")); + return NULL; + } + + nsString ret; + nsresult rv = pi->GetData(ret); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("ProcessingInstruction.getTarget: failed (%x)\n", rv)); + return NULL; + } + + char* cret = ret.ToNewCString(); + jstring jret = env->NewStringUTF(cret); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("ProcessingInstruction.getTarget: NewStringUTF failed (%s)\n", cret)); + return NULL; + } + delete[] cret; + + return jret; +} + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: setData + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_setData + (JNIEnv *env, jobject jthis, jstring jdata) +{ + nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!pi) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("ProcessingInstruction.setData: NULL pointer\n")); + return; + } + + jboolean iscopy = JNI_FALSE; + const char* data = env->GetStringUTFChars(jdata, &iscopy); + if (!data) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("ProcessingInstruction.setData: GetStringUTFChars failed\n")); + return; + } + nsresult rv = pi->SetData(data); + if (iscopy == JNI_TRUE) + env->ReleaseStringUTFChars(jdata, data); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("ProcessingInstruction.setData: failed (%x)\n", rv)); + return; + } +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.h new file mode 100644 index 00000000000..c320b7f0868 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_ProcessingInstructionImpl */ + +#ifndef _Included_org_mozilla_dom_ProcessingInstructionImpl +#define _Included_org_mozilla_dom_ProcessingInstructionImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: getData + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_getData + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: getTarget + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_getTarget + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_ProcessingInstructionImpl + * Method: setData + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_setData + (JNIEnv *, jobject, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/jni/org_mozilla_dom_TextImpl.cpp b/mozilla/java/dom/jni/org_mozilla_dom_TextImpl.cpp new file mode 100644 index 00000000000..f9918f680c5 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_TextImpl.cpp @@ -0,0 +1,81 @@ +/* +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. +*/ + +#include "prlog.h" +#include "nsIDOMText.h" +#include "javaDOMGlobals.h" +#include "org_mozilla_dom_TextImpl.h" + +/* + * Class: org_mozilla_dom_TextImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_TextImpl_finalize + (JNIEnv *env, jobject jthis) +{ + nsIDOMText* text = (nsIDOMText*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!text) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Text.finalize: NULL pointer\n")); + return; + } + + JavaDOMGlobals::AddToGarbage(text); +} + +/* + * Class: org_mozilla_dom_TextImpl + * Method: splitText + * Signature: (I)Lorg/w3c/dom/Text; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_TextImpl_splitText + (JNIEnv *env, jobject jthis, jint joffset) +{ + nsIDOMText* text = (nsIDOMText*) + env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID); + if (!text) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("Text.splitText: NULL pointer\n")); + return NULL; + } + + nsIDOMText* ret = nsnull; + nsresult rv = text->SplitText((PRUint32) joffset, &ret); + if (NS_FAILED(rv) || !ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Text.splitText: failed (%x)\n", rv)); + return NULL; + } + + jobject jret = env->AllocObject(JavaDOMGlobals::textClass); + if (!jret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Text.splitText: failed to allocate object\n")); + return NULL; + } + + env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret); + if (env->ExceptionOccurred()) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, + ("Text.splitText: failed to set node ptr: %x\n", ret)); + return NULL; + } + + ret->AddRef(); + return jret; +} diff --git a/mozilla/java/dom/jni/org_mozilla_dom_TextImpl.h b/mozilla/java/dom/jni/org_mozilla_dom_TextImpl.h new file mode 100644 index 00000000000..44063e374c7 --- /dev/null +++ b/mozilla/java/dom/jni/org_mozilla_dom_TextImpl.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_dom_TextImpl */ + +#ifndef _Included_org_mozilla_dom_TextImpl +#define _Included_org_mozilla_dom_TextImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_dom_TextImpl + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_dom_TextImpl_finalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_dom_TextImpl + * Method: splitText + * Signature: (I)Lorg/w3c/dom/Text; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_dom_TextImpl_splitText + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/dom/makefile.win b/mozilla/java/dom/makefile.win new file mode 100755 index 00000000000..0845da78cf8 --- /dev/null +++ b/mozilla/java/dom/makefile.win @@ -0,0 +1,73 @@ +#!nmake +# +# 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. + +DEPTH=..\.. +IGNORE_MANIFEST=1 + +DEFINES=-D_IMPL_NS_WEB -DWIN32_LEAN_AND_MEAN +MODULE=javadom +IS_COMPONENT=1 +LIBRARY_NAME=libjavadom + +CPPSRCS= \ + nsJavaDOMFactory.cpp \ + nsJavaDOMImpl.cpp \ + $(NULL) + +CPP_OBJS= \ + .\$(OBJDIR)\nsJavaDOMFactory.obj \ + .\$(OBJDIR)\nsJavaDOMImpl.obj \ + $(NULL) + +EXPORTS = \ + nsJavaDOMCID.h \ + nsIJavaDOM.h + +LINCS= \ + -I..\..\..\jdk\include \ + -I..\..\..\jdk\include\win32 + +MAKE_OBJ_TYPE = DLL +DLLNAME = javadom +DLL=.\$(OBJDIR)\$(DLLNAME).dll + +LCFLAGS = \ + $(LCFLAGS) \ + $(DEFINES) \ + $(NULL) + +LLIBS= \ + ..\..\..\jdk\lib\jvm.lib \ + $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\raptorgfxwin.lib \ + $(DIST)\lib\img32$(VERSION_NUMBER).lib \ + $(DIST)\lib\util.lib \ + $(DIST)\lib\plc3.lib \ + $(DIST)\lib\jsdom.lib \ + $(DIST)\lib\js3250.lib \ + $(LIBNSPR) + +include <$(DEPTH)\config\config.mak> + +include <$(DEPTH)\config\rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib + +clobber:: + rm -f $(DIST)\bin\components\$(DLLNAME).dll + rm -f $(DIST)\lib\$(DLLNAME).lib diff --git a/mozilla/java/dom/nsIJavaDOM.h b/mozilla/java/dom/nsIJavaDOM.h new file mode 100644 index 00000000000..595f1f7efda --- /dev/null +++ b/mozilla/java/dom/nsIJavaDOM.h @@ -0,0 +1,95 @@ +/* +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. +*/ + +#ifndef __nsIJavaDOM_h__ +#define __nsIJavaDOM_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIDocumentLoaderObserver.h" +#include "jni.h" + +class nsIURI; + +/* {9cc0ca50-0e31-11d3-8a61-0004ac56c4a5} */ +#define NS_IJAVADOM_IID_STR "9cc0ca50-0e31-11d3-8a61-0004ac56c4a5" +#define NS_IJAVADOM_IID \ + {0x9cc0ca50, 0x0e31, 0x11d3, \ + { 0x8a, 0x61, 0x00, 0x04, 0xac, 0x56, 0xc4, 0xa5 }} + +class nsIJavaDOM : public nsIDocumentLoaderObserver { + public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJAVADOM_IID) + + /* nsIDocumentLoaderObserver methods */ + NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, + nsIURI* aURL, + const char* aCommand) = 0; + + NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRInt32 aStatus, + nsIDocumentLoaderObserver* aObserver) = 0; + + NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, + const char* aContentType, +#endif + nsIContentViewer* aViewer) = 0; + + NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRUint32 aProgress, + PRUint32 aProgressMax) = 0; + + NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + nsString& aMsg) = 0; + + NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRInt32 aStatus) = 0; + + NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + const char *aContentType, + const char *aCommand) = 0; +}; + +#endif /* __nsIJavaDOM_h__ */ diff --git a/mozilla/java/dom/nsJavaDOMCID.h b/mozilla/java/dom/nsJavaDOMCID.h new file mode 100644 index 00000000000..b242d57c7f7 --- /dev/null +++ b/mozilla/java/dom/nsJavaDOMCID.h @@ -0,0 +1,24 @@ +/* +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. +*/ + +#ifndef __nsJavaDOMCID_h__ +#define __nsJavaDOMCID_h__ + +#define NS_JAVADOMFACTORY_CID \ + {0x12c2fa66, 0x0fef, 0x11d3, \ + {0x87, 0x14, 0x00, 0x04, 0xac, 0x56, 0xc4, 0xa5}} + +#endif /* __nsJavaDOMCID_h__ */ diff --git a/mozilla/java/dom/nsJavaDOMFactory.cpp b/mozilla/java/dom/nsJavaDOMFactory.cpp new file mode 100644 index 00000000000..6d009ba0e51 --- /dev/null +++ b/mozilla/java/dom/nsJavaDOMFactory.cpp @@ -0,0 +1,142 @@ +/* +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. +*/ + +#include "pratom.h" +#include "nsCOMPtr.h" +#include "nsIServiceManager.h" + +#include "nsJavaDOMCID.h" +#include "nsJavaDOMImpl.h" +#include "nsJavaDOMFactory.h" + +static PRInt32 gLockCount = 0; + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); +static NS_DEFINE_IID(kJavaDOMFactoryCID, NS_JAVADOMFACTORY_CID); +static NS_DEFINE_IID(kJavaDOMFactoryIID, NS_JAVADOMFACTORY_IID); + +NS_IMPL_ISUPPORTS(nsJavaDOMFactory, kJavaDOMFactoryIID) + +nsJavaDOMFactory::nsJavaDOMFactory() +{ + NS_INIT_REFCNT(); +} + +nsresult nsJavaDOMFactory::CreateInstance(nsISupports* aOuter, + const nsIID& aIID, + void** aResult) +{ + if (aOuter != NULL) + return NS_ERROR_NO_AGGREGATION; + + if (aResult == NULL) + return NS_ERROR_NULL_POINTER; + + *aResult = NULL; + + nsISupports* inst = new nsJavaDOMImpl(); + if (inst == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = inst->QueryInterface(aIID, aResult); + if (NS_FAILED(res)) + delete inst; + + return res; +} + +nsresult nsJavaDOMFactory::LockFactory(PRBool aLock) +{ + if (aLock) + PR_AtomicIncrement(&gLockCount); + else + PR_AtomicDecrement(&gLockCount); + return NS_OK; +} + +extern "C" +NS_EXPORT nsresult NSGetFactory(nsISupports* serviceMgr, + const nsCID& aClass, + const char* aClassName, + const char* aProgID, + nsIFactory** aFactory) +{ + if (aFactory == NULL) + return NS_ERROR_NULL_POINTER; + + *aFactory = NULL; + nsISupports *inst = NULL; + static NS_DEFINE_IID(kJavaDOMFactoryCID, NS_JAVADOMFACTORY_CID); + if (aClass.Equals(kJavaDOMFactoryCID)) + inst = new nsJavaDOMFactory(); + else + return NS_ERROR_ILLEGAL_VALUE; + + if (inst == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = inst->QueryInterface(kJavaDOMFactoryIID, + (void**) aFactory); + if (res != NS_OK) + delete inst; + + return res; +} + +extern "C" +NS_EXPORT PRBool NSCanUnload(nsISupports* serviceMgr) +{ + return (PRBool) (gLockCount == 0); +} + +extern "C" +NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char* aPath) +{ + nsresult rv; + nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) + return rv; + + nsIComponentManager* cm = nsnull; + rv = servMgr->GetService(kComponentManagerCID, + nsIComponentManager::GetIID(), + (nsISupports**)&cm); + if (NS_FAILED(rv)) + return rv; + + rv = cm->RegisterComponent(kJavaDOMFactoryCID, NULL, NULL, + aPath, PR_TRUE, PR_TRUE); + return rv; +} + +extern "C" +NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char* aPath) +{ + nsresult rv; + nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) + return rv; + + nsIComponentManager* cm = nsnull; + rv = servMgr->GetService(kComponentManagerCID, + nsIComponentManager::GetIID(), + (nsISupports**)&cm); + if (NS_FAILED(rv)) + return rv; + + rv = cm->UnregisterComponent(kJavaDOMFactoryCID, aPath); + return rv; +} diff --git a/mozilla/java/dom/nsJavaDOMFactory.h b/mozilla/java/dom/nsJavaDOMFactory.h new file mode 100644 index 00000000000..d9dea49c132 --- /dev/null +++ b/mozilla/java/dom/nsJavaDOMFactory.h @@ -0,0 +1,40 @@ +/* +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. +*/ + +#ifndef __nsJavaDOMFactory_h__ +#define __nsJavaDOMFactory_h__ + +#include "nsIFactory.h" + +#define NS_JAVADOMFACTORY_IID \ + {0x6a07c434, 0x0e58, 0x11d3, \ + {0x86, 0xea, 0x00, 0x04, 0xac, 0x56, 0xc4, 0xa5}} + +class nsJavaDOMFactory : public nsIFactory { + NS_DECL_ISUPPORTS + + public: + + nsJavaDOMFactory(); + + NS_IMETHOD CreateInstance(nsISupports* aOuter, + const nsIID& iid, + void** retval); + + NS_IMETHOD LockFactory(PRBool lock); +}; + +#endif /* __nsJavaDOMFactory_h__ */ diff --git a/mozilla/java/dom/nsJavaDOMImpl.cpp b/mozilla/java/dom/nsJavaDOMImpl.cpp new file mode 100755 index 00000000000..9cc49e35d70 --- /dev/null +++ b/mozilla/java/dom/nsJavaDOMImpl.cpp @@ -0,0 +1,666 @@ +/* +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. +*/ + +#include "prenv.h" +#include "nsISupportsUtils.h" +#include "nsIURL.h" +#include "nsIContentViewerContainer.h" +#include "nsIDocument.h" +#include "nsIDocumentLoader.h" +#include "nsIDocumentLoaderObserver.h" +#include "nsIDocumentViewer.h" +#include "nsIDOMDocument.h" +#include "nsJavaDOMImpl.h" + +#if defined(DEBUG) +#include +#include "nsIDOMElement.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMNamedNodeMap.h" +static void dump_document(nsIDOMDocument* dom, const char* urlSpec); +static void dump_node(FILE* of, nsIDOMNode* node, int indent, + PRBool isMapNode); +static void dump_map(FILE* of, nsIDOMNamedNodeMap* map, int indent); +static char* strip_whitespace(char* input); +static const char* describe_type(int type); +#endif + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID); +static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); +static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID); + +NS_IMPL_ADDREF(nsJavaDOMImpl); +NS_IMPL_RELEASE(nsJavaDOMImpl); + +NS_IMETHODIMP nsJavaDOMImpl::QueryInterface(REFNSIID aIID, void** aInstance) +{ + if (NULL == aInstance) + return NS_ERROR_NULL_POINTER; + + *aInstance = NULL; + + if (aIID.Equals(kIJavaDOMIID)) { + *aInstance = (void*) ((nsIJavaDOM*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIDocumentLoaderObserverIID)) { + *aInstance = (void*) ((nsIDocumentLoaderObserver*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstance = (void*) ((nsISupports*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +JavaVM* nsJavaDOMImpl::jvm = NULL; +JNIEnv* nsJavaDOMImpl::env = NULL; + +jclass nsJavaDOMImpl::factoryClass = NULL; +jclass nsJavaDOMImpl::documentClass = NULL; +jclass nsJavaDOMImpl::listenerClass = NULL; +jclass nsJavaDOMImpl::gcClass = NULL; + +jobject nsJavaDOMImpl::factory = NULL; +jobject nsJavaDOMImpl::docListener = NULL; + +jfieldID nsJavaDOMImpl::documentPtrFID = NULL; + +jmethodID nsJavaDOMImpl::getListenerMID = 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(); + + if (jvm) + return; + + JDK1_1InitArgs vm_args; + JNI_GetDefaultJavaVMInitArgs(&vm_args); + vm_args.version = 0x00010001; + vm_args.verifyMode = JNI_TRUE; +#ifdef DEBUG + vm_args.verbose = JNI_TRUE; + vm_args.enableVerboseGC = JNI_TRUE; +#endif // DEBUG + char* cp = PR_GetEnv("CLASSPATH"); + char* p = new char[strlen(cp) + strlen(vm_args.classpath) + 2]; + strcpy(p, vm_args.classpath); + if (cp) { +#ifdef XP_PC + strcat(p, ";"); +#else + strcat(p, ":"); +#endif + strcat(p, cp); + vm_args.classpath = p; + } +#ifdef DEBUG + printf("classpath is \"%s\"\n", vm_args.classpath); +#endif // DEBUG +#ifdef XP_PC + // for some reason, vc++ 6.0 requires this cast + JNI_CreateJavaVM(&jvm, (void**) &env, &vm_args); +#else + JNI_CreateJavaVM(&jvm, &env, &vm_args); +#endif + delete[] p; + + gcClass = env->FindClass("org/mozilla/dom/DOMGarbageCollector"); + if (!gcClass) return; + gcClass = (jclass) env->NewGlobalRef(gcClass); + if (!gcClass) return; + + gcMID = + env->GetStaticMethodID(gcClass, + "doGC", + "()V"); + if (!gcMID) return; + + factoryClass = env->FindClass("org/mozilla/dom/DOMFactory"); + if (!factoryClass) return; + factoryClass = (jclass) env->NewGlobalRef(factoryClass); + if (!factoryClass) return; + + factory = env->AllocObject(factoryClass); + if (!factory) return; + factory = (jclass) env->NewGlobalRef(factory); + if (!factory) return; + + getListenerMID = + env->GetMethodID(factoryClass, + "getDocumentLoadListener", + "()Lorg/mozilla/dom/DocumentLoadListener;"); + if (!getListenerMID) return; + + docListener = + env->CallObjectMethod(factory, getListenerMID); + 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; + + 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(); +} + +nsJavaDOMImpl::~nsJavaDOMImpl() +{ +} + +PRBool nsJavaDOMImpl::Cleanup() +{ + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + return PR_TRUE; + } + + return PR_FALSE; +} + +nsIDOMDocument* nsJavaDOMImpl::GetDocument(nsIDocumentLoader* loader) +{ + nsIContentViewerContainer* container = nsnull; + nsIContentViewer* contentv = nsnull; + nsIDocumentViewer* docv = nsnull; + nsIDocument* document = nsnull; + nsIDOMDocument* domDoc = nsnull; + + nsresult rv = loader->GetContainer(&container); + if (NS_SUCCEEDED(rv) && container) + rv = container->GetContentViewer(&contentv); + + if (NS_SUCCEEDED(rv) && contentv) { + rv = contentv->QueryInterface(kIDocumentViewerIID, + (void**) &docv); + if (NS_SUCCEEDED(rv) && docv) { + docv->GetDocument(document); + rv = document->QueryInterface(kIDOMDocumentIID, + (void**) &domDoc); + if (NS_SUCCEEDED(rv) && docv) { + return domDoc; + } + } + } + + fprintf(stderr, + "nsJavaDOMImpl::GetDocument: failed: " + "container=%x, contentViewer=%x, documentViewer=%x, document=%x, " + "domDocument=%x, error=%x\n", + (unsigned) (void*) container, (unsigned) (void*) contentv, + (unsigned) (void*) docv, (unsigned) (void*) document, + (unsigned) (void*) domDoc, rv); + return NULL; +} + +// convert nsIDOMDocument to org.mozilla.dom.DocumentImpl +jobject nsJavaDOMImpl::CaffienateDOMDocument(nsIDOMDocument* domDoc) +{ + if (!domDoc) return NULL; + + jobject jdoc = env->AllocObject(documentClass); + if (!jdoc) return NULL; + env->SetLongField(jdoc, documentPtrFID, (jlong) (void*) domDoc); + if (Cleanup() == PR_TRUE) return NULL; + + return jdoc; +} + +/* nsIDocumentLoaderObserver methods */ + +NS_IMETHODIMP nsJavaDOMImpl::OnStartDocumentLoad(nsIDocumentLoader* loader, + nsIURI* aURL, + const char* aCommand) +{ + char* urlSpec = ""; + if (aURL) + aURL->GetSpec(&urlSpec); + jstring jURL = env->NewStringUTF(urlSpec); + if (!jURL) return NS_ERROR_FAILURE; + + env->CallVoidMethod(docListener, + startDocumentLoadMID, + jURL); + if (Cleanup() == PR_TRUE) return NS_ERROR_FAILURE; + + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRInt32 aStatus, + nsIDocumentLoaderObserver* aObserver) +{ + char* urlSpec = ""; +#ifdef NECKO + nsIURI* url = nsnull; + if (channel && NS_SUCCEEDED(channel->GetURI(&url))) + url->GetSpec(&urlSpec); +#else + if (aURL) + aURL->GetSpec(&urlSpec); +#endif + jstring jURL = env->NewStringUTF(urlSpec); + if (!jURL) return NS_ERROR_FAILURE; + + nsIDOMDocument* domDoc = GetDocument(loader); + jobject jdoc = CaffienateDOMDocument(domDoc); + + env->CallVoidMethod(docListener, + endDocumentLoadMID, + jURL, + (jint) aStatus, + jdoc); + if (Cleanup() == PR_TRUE) return NS_ERROR_FAILURE; + + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, + const char* aContentType, +#endif + nsIContentViewer* aViewer) +{ + char* urlSpec = ""; +#ifdef NECKO + nsIURI* url = nsnull; + if (channel && NS_SUCCEEDED(channel->GetURI(&url))) + url->GetSpec(&urlSpec); +#else + if (aURL) + aURL->GetSpec(&urlSpec); +#endif + jstring jURL = env->NewStringUTF(urlSpec); + if (!jURL) return NS_ERROR_FAILURE; + + char* contentType = ""; +#ifdef NECKO + if (channel) + channel->GetContentType(&contentType); +#else + if (aContentType) + contentType = aContentType; +#endif + jstring jContentType = env->NewStringUTF(contentType); + if (!jContentType) return NS_ERROR_FAILURE; + + nsIDOMDocument* domDoc = GetDocument(loader); + jobject jdoc = CaffienateDOMDocument(domDoc); + + env->CallVoidMethod(docListener, + startURLLoadMID, + jURL, + jContentType, + jdoc); + if (Cleanup() == PR_TRUE) return NS_ERROR_FAILURE; + + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRUint32 aProgress, + PRUint32 aProgressMax) +{ + char* urlSpec = ""; +#ifdef NECKO + nsIURI* url = nsnull; + if (channel && NS_SUCCEEDED(channel->GetURI(&url))) + url->GetSpec(&urlSpec); +#else + if (aURL) + aURL->GetSpec(&urlSpec); +#endif + jstring jURL = env->NewStringUTF(urlSpec); + if (!jURL) return NS_ERROR_FAILURE; + + nsIDOMDocument* domDoc = GetDocument(loader); + jobject jdoc = CaffienateDOMDocument(domDoc); + + env->CallVoidMethod(docListener, + progressURLLoadMID, + jURL, + (jint) aProgress, + (jint) aProgressMax, + jdoc); + if (Cleanup() == PR_TRUE) return NS_ERROR_FAILURE; + + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + nsString& aMsg) +{ + char* urlSpec = ""; +#ifdef NECKO + nsIURI* url = nsnull; + if (channel && NS_SUCCEEDED(channel->GetURI(&url))) + url->GetSpec(&urlSpec); +#else + if (aURL) + aURL->GetSpec(&urlSpec); +#endif + jstring jURL = env->NewStringUTF(urlSpec); + if (!jURL) return NS_ERROR_FAILURE; + + char* cMsg = aMsg.ToNewCString(); + jstring jMessage = env->NewStringUTF(cMsg); + delete[] cMsg; + if (!jMessage) return NS_ERROR_FAILURE; + + nsIDOMDocument* domDoc = GetDocument(loader); + jobject jdoc = CaffienateDOMDocument(domDoc); + + env->CallVoidMethod(docListener, + statusURLLoadMID, + jURL, + jMessage, + jdoc); + if (Cleanup() == PR_TRUE) return NS_ERROR_FAILURE; + + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRInt32 aStatus) +{ + char* urlSpec = ""; +#ifdef NECKO + nsIURI* url = nsnull; + if (channel && NS_SUCCEEDED(channel->GetURI(&url))) + url->GetSpec(&urlSpec); +#else + if (aURL) + aURL->GetSpec(&urlSpec); +#endif + jstring jURL = env->NewStringUTF(urlSpec); + 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); + if (Cleanup() == PR_TRUE) return NS_ERROR_FAILURE; + + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +NS_IMETHODIMP nsJavaDOMImpl::HandleUnknownContentType(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + const char *aContentType, + const char *aCommand) +{ + env->CallStaticVoidMethod(gcClass, gcMID); + Cleanup(); + return NS_OK; +} + +#if defined(DEBUG) +static void dump_document(nsIDOMDocument* domDoc, const char* urlSpec) +{ + if (!domDoc) return; + + if (strstr(urlSpec, ".xul") || + strstr(urlSpec, ".js") || + strstr(urlSpec, ".css") || + strstr(urlSpec, "file:")) return; + + FILE* of = fopen("dom-cpp.txt", "a"); + if (!of) { + perror("nsJavaDOMImpl::dump_document: failed to open output file\n"); + return; + } + + nsIDOMElement* element = nsnull; + nsresult rv = domDoc->GetDocumentElement(&element); + if (NS_FAILED(rv) || !element) + return; + + (void) element->Normalize(); + + fprintf(of, "\n+++ %s +++\n", urlSpec); + dump_node(of, (nsIDOMNode*) element, 0, PR_FALSE); + fprintf(of, "\n"); + fflush(of); + fclose(of); +} + +static void dump_node(FILE* of, nsIDOMNode* node, int indent, + PRBool isMapNode) +{ + if (!node) return; + + fprintf(of, "\n"); + for (int i=0; i < indent; i++) + fprintf(of, " "); + + nsString name; + nsString value; + PRUint16 type; + + node->GetNodeName(name); + node->GetNodeValue(value); + node->GetNodeType(&type); + + char* cname = name.ToNewCString(); + char* cvalue = value.ToNewCString(); + char* cnorm = strip_whitespace(cvalue); + fprintf(of, "name=\"%s\" type=%s value=\"%s\"", + cname, describe_type(type), cnorm); + delete[] cnorm; + delete[] cname; + + if (isMapNode) return; + + nsIDOMNamedNodeMap* map = nsnull; + node->GetAttributes(&map); + dump_map(of, map, indent); + + nsIDOMNodeList* children = nsnull; + node->GetChildNodes(&children); + if (!children) return; + + PRUint32 length=0; + children->GetLength(&length); + for (PRUint32 j=0; j < length; j++) { + nsIDOMNode* child = nsnull; + children->Item(j, &child); + dump_node(of, child, indent+2, PR_FALSE); + } +} + +static void dump_map(FILE* of, nsIDOMNamedNodeMap* map, int indent) +{ + if (!map) return; + + fprintf(of, "\n"); + PRUint32 length=0; + map->GetLength(&length); + if (length > 0) { + for (int i=0; i < indent; i++) + fprintf(of, " "); + fprintf(of, "------- start attributes -------"); + } + + for (PRUint32 j=0; j < length; j++) { + nsIDOMNode* node = nsnull; + map->Item(j, &node); + dump_node(of, node, indent, PR_TRUE); + } + + if (length > 0) { + fprintf(of, "\n"); + for (int k=0; k < indent; k++) + fprintf(of, " "); + fprintf(of, "------- end attributes -------"); + } +} + +static char* strip_whitespace(char* input) +{ + int len = strlen(input); + char* out = new char[len]; + + char* op = out; + char* ip = input; + char c = ' '; + char pc = ' '; + + for (c = *ip++; c; c = *ip++) { + if ((pc == ' ' || pc == '\n' || pc == '\t') && + (c == ' ' || c == '\n' || c == '\t')) + continue; + *op++ = c; + pc = c; + } + *op++ = 0; + + delete[] input; + return out; +} + +static const char* describe_type(int type) +{ + switch (type) { + case nsIDOMNode::ELEMENT_NODE: return "ELEMENT"; + case nsIDOMNode::ATTRIBUTE_NODE: return "ATTRIBUTE"; + case nsIDOMNode::TEXT_NODE: return "TEXT"; + case nsIDOMNode::CDATA_SECTION_NODE: return "CDATA_SECTION"; + case nsIDOMNode::ENTITY_REFERENCE_NODE: return "ENTITY_REFERENCE"; + case nsIDOMNode::ENTITY_NODE: return "ENTITY"; + case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: return "PROCESSING_INSTRUCTION"; + case nsIDOMNode::COMMENT_NODE: return "COMMENT"; + case nsIDOMNode::DOCUMENT_NODE: return "DOCUMENT"; + case nsIDOMNode::DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE"; + case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: return "DOCUMENT_FRAGMENT"; + case nsIDOMNode::NOTATION_NODE: return "NOTATION"; + } + return "ERROR"; +} +#endif diff --git a/mozilla/java/dom/nsJavaDOMImpl.h b/mozilla/java/dom/nsJavaDOMImpl.h new file mode 100644 index 00000000000..f5f867de96d --- /dev/null +++ b/mozilla/java/dom/nsJavaDOMImpl.h @@ -0,0 +1,106 @@ +#ifndef __nsJavaDOMImpl_h__ +#define __nsJavaDOMImpl_h__ + +#include +#include "nsIJavaDOM.h" + +class nsIURI; +class nsIDOMDocument; +class nsIDocumentLoader; + +class nsJavaDOMImpl : public nsIJavaDOM { + NS_DECL_ISUPPORTS + + public: + nsJavaDOMImpl(); + virtual ~nsJavaDOMImpl(); + + /* nsIDocumentLoaderObserver methods */ + NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, + nsIURI* aURL, + const char* aCommand); + + NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRInt32 aStatus, + nsIDocumentLoaderObserver* aObserver); + + NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, + const char* aContentType, +#endif + nsIContentViewer* aViewer); + + NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRUint32 aProgress, + PRUint32 aProgressMax); + + NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + nsString& aMsg); + + NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + PRInt32 aStatus); + + NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader, +#ifdef NECKO + nsIChannel* channel, +#else + nsIURI* aURL, +#endif + const char *aContentType, + const char *aCommand); + + private: + static JavaVM* jvm; + static JNIEnv* env; + + static jclass factoryClass; + static jclass documentClass; + static jclass listenerClass; + static jclass gcClass; + + static jobject factory; + static jobject docListener; + + static jfieldID documentPtrFID; + + static jmethodID getListenerMID; + static jmethodID startURLLoadMID; + static jmethodID endURLLoadMID; + static jmethodID progressURLLoadMID; + static jmethodID statusURLLoadMID; + static jmethodID startDocumentLoadMID; + static jmethodID endDocumentLoadMID; + + static jmethodID gcMID; + + // cleanup after a JNI method invocation + static PRBool Cleanup(); + + nsIDOMDocument* GetDocument(nsIDocumentLoader* loader); + jobject CaffienateDOMDocument(nsIDOMDocument* domDoc); +}; + +#endif /* __nsJavaDOMImpl_h__ */ diff --git a/mozilla/java/dom/nsWebShell.cpp.patch b/mozilla/java/dom/nsWebShell.cpp.patch new file mode 100644 index 00000000000..19ed67b796e --- /dev/null +++ b/mozilla/java/dom/nsWebShell.cpp.patch @@ -0,0 +1,38 @@ +Index: nsWebShell.cpp +=================================================================== +RCS file: /cvsroot/mozilla/webshell/src/nsWebShell.cpp,v +retrieving revision 1.200 +diff -r1.200 nsWebShell.cpp +70a71,75 +> #ifdef JAVA_DOM +> #include "nsIJavaDOM.h" +> #include "nsJavaDOMCID.h" +> #endif // JAVA_DOM +> +566a572 +> +577a584,588 +> #ifdef JAVA_DOM +> static NS_DEFINE_IID(kJavaDOMFactoryCID, NS_JAVADOMFACTORY_CID); +> static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID); +> #endif // JAVA_DOM +> +1036a1048,1065 +> #ifdef JAVA_DOM +> nsISupports* javaDOM = nsnull; +> nsresult jrv = nsServiceManager::GetService(kJavaDOMFactoryCID, +> kIJavaDOMIID, +> (nsISupports**) &javaDOM); +> if (NS_FAILED(jrv) || !javaDOM) { +> fprintf(stderr, +> "nsWebShell::Init: GetService of JavaDOM failed (error %x)\n", +> jrv); +> } else { +> jrv = docLoaderService->AddObserver((nsIDocumentLoaderObserver*)javaDOM); +> if (NS_FAILED(jrv)) { +> fprintf(stderr, +> "nsWebShell::Init: AddObserver of JavaDOM failed (error %x)\n", +> jrv); +> } +> } +> #endif // JAVA_DOM