nokogiri 1.8.5-java → 1.9.0-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/README.md +0 -1
- data/ext/java/nokogiri/XmlAttr.java +3 -1
- data/ext/java/nokogiri/XmlDtd.java +20 -16
- data/ext/java/nokogiri/XmlElement.java +6 -6
- data/ext/java/nokogiri/XmlNode.java +29 -9
- data/ext/java/nokogiri/XmlNodeSet.java +258 -77
- data/ext/java/nokogiri/XmlXpathContext.java +10 -12
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +25 -23
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +5 -5
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +11 -10
- data/ext/java/{org/apache/xml/dtm/ref/dom2dtm/DOM2DTMExt.java → nokogiri/internals/dom2dtm/DOM2DTM.java} +3 -7
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +685 -0
- data/ext/nokogiri/extconf.rb +10 -6
- data/ext/nokogiri/xml_attr.c +26 -21
- data/ext/nokogiri/xml_document.c +4 -1
- data/ext/nokogiri/xml_namespace.c +3 -3
- data/ext/nokogiri/xml_namespace.h +1 -2
- data/ext/nokogiri/xml_node.c +55 -15
- data/lib/nokogiri/css/parser.rb +61 -61
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml/document_fragment.rb +11 -0
- data/lib/nokogiri/xml/node.rb +12 -0
- data/lib/nokogiri/xml/node_set.rb +4 -8
- data/lib/xercesImpl.jar +0 -0
- metadata +17 -152
- data/.autotest +0 -22
- data/.cross_rubies +0 -8
- data/.editorconfig +0 -17
- data/.gemtest +0 -0
- data/.travis.yml +0 -63
- data/CHANGELOG.md +0 -1368
- data/CONTRIBUTING.md +0 -42
- data/C_CODING_STYLE.rdoc +0 -33
- data/Gemfile +0 -23
- data/Gemfile-libxml-ruby +0 -3
- data/Manifest.txt +0 -370
- data/ROADMAP.md +0 -111
- data/Rakefile +0 -348
- data/SECURITY.md +0 -19
- data/STANDARD_RESPONSES.md +0 -47
- data/Y_U_NO_GEMSPEC.md +0 -155
- data/appveyor.yml +0 -29
- data/build_all +0 -44
- data/patches/sort-patches-by-date +0 -25
- data/suppressions/README.txt +0 -1
- data/suppressions/nokogiri_ruby-2.supp +0 -10
- data/tasks/test.rb +0 -100
- data/test/css/test_nthiness.rb +0 -226
- data/test/css/test_parser.rb +0 -386
- data/test/css/test_tokenizer.rb +0 -215
- data/test/css/test_xpath_visitor.rb +0 -96
- data/test/decorators/test_slop.rb +0 -23
- data/test/files/2ch.html +0 -108
- data/test/files/GH_1042.html +0 -18
- data/test/files/address_book.rlx +0 -12
- data/test/files/address_book.xml +0 -10
- data/test/files/atom.xml +0 -344
- data/test/files/bar/bar.xsd +0 -4
- data/test/files/bogus.xml +0 -0
- data/test/files/dont_hurt_em_why.xml +0 -422
- data/test/files/encoding.html +0 -82
- data/test/files/encoding.xhtml +0 -84
- data/test/files/exslt.xml +0 -8
- data/test/files/exslt.xslt +0 -35
- data/test/files/foo/foo.xsd +0 -4
- data/test/files/metacharset.html +0 -10
- data/test/files/namespace_pressure_test.xml +0 -1684
- data/test/files/noencoding.html +0 -47
- data/test/files/po.xml +0 -32
- data/test/files/po.xsd +0 -66
- data/test/files/saml/saml20assertion_schema.xsd +0 -283
- data/test/files/saml/saml20protocol_schema.xsd +0 -302
- data/test/files/saml/xenc_schema.xsd +0 -146
- data/test/files/saml/xmldsig_schema.xsd +0 -318
- data/test/files/shift_jis.html +0 -10
- data/test/files/shift_jis.xml +0 -5
- data/test/files/shift_jis_no_charset.html +0 -9
- data/test/files/slow-xpath.xml +0 -25509
- data/test/files/snuggles.xml +0 -3
- data/test/files/staff.dtd +0 -10
- data/test/files/staff.xml +0 -59
- data/test/files/staff.xslt +0 -32
- data/test/files/test_document_url/bar.xml +0 -2
- data/test/files/test_document_url/document.dtd +0 -4
- data/test/files/test_document_url/document.xml +0 -6
- data/test/files/tlm.html +0 -851
- data/test/files/to_be_xincluded.xml +0 -2
- data/test/files/valid_bar.xml +0 -2
- data/test/files/xinclude.xml +0 -4
- data/test/helper.rb +0 -271
- data/test/html/sax/test_parser.rb +0 -168
- data/test/html/sax/test_parser_context.rb +0 -46
- data/test/html/sax/test_parser_text.rb +0 -163
- data/test/html/sax/test_push_parser.rb +0 -87
- data/test/html/test_attributes.rb +0 -85
- data/test/html/test_builder.rb +0 -164
- data/test/html/test_document.rb +0 -712
- data/test/html/test_document_encoding.rb +0 -143
- data/test/html/test_document_fragment.rb +0 -310
- data/test/html/test_element_description.rb +0 -105
- data/test/html/test_named_characters.rb +0 -14
- data/test/html/test_node.rb +0 -212
- data/test/html/test_node_encoding.rb +0 -91
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
- data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
- data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
- data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
- data/test/namespaces/test_namespaces_preservation.rb +0 -31
- data/test/test_convert_xpath.rb +0 -135
- data/test/test_css_cache.rb +0 -47
- data/test/test_encoding_handler.rb +0 -48
- data/test/test_memory_leak.rb +0 -156
- data/test/test_nokogiri.rb +0 -138
- data/test/test_soap4r_sax.rb +0 -52
- data/test/test_xslt_transforms.rb +0 -314
- data/test/xml/node/test_save_options.rb +0 -28
- data/test/xml/node/test_subclass.rb +0 -44
- data/test/xml/sax/test_parser.rb +0 -402
- data/test/xml/sax/test_parser_context.rb +0 -115
- data/test/xml/sax/test_parser_text.rb +0 -202
- data/test/xml/sax/test_push_parser.rb +0 -265
- data/test/xml/test_attr.rb +0 -74
- data/test/xml/test_attribute_decl.rb +0 -86
- data/test/xml/test_builder.rb +0 -341
- data/test/xml/test_c14n.rb +0 -180
- data/test/xml/test_cdata.rb +0 -54
- data/test/xml/test_comment.rb +0 -40
- data/test/xml/test_document.rb +0 -982
- data/test/xml/test_document_encoding.rb +0 -31
- data/test/xml/test_document_fragment.rb +0 -298
- data/test/xml/test_dtd.rb +0 -187
- data/test/xml/test_dtd_encoding.rb +0 -31
- data/test/xml/test_element_content.rb +0 -56
- data/test/xml/test_element_decl.rb +0 -73
- data/test/xml/test_entity_decl.rb +0 -122
- data/test/xml/test_entity_reference.rb +0 -262
- data/test/xml/test_namespace.rb +0 -96
- data/test/xml/test_node.rb +0 -1325
- data/test/xml/test_node_attributes.rb +0 -115
- data/test/xml/test_node_encoding.rb +0 -75
- data/test/xml/test_node_inheritance.rb +0 -32
- data/test/xml/test_node_reparenting.rb +0 -592
- data/test/xml/test_node_set.rb +0 -809
- data/test/xml/test_parse_options.rb +0 -64
- data/test/xml/test_processing_instruction.rb +0 -30
- data/test/xml/test_reader.rb +0 -620
- data/test/xml/test_reader_encoding.rb +0 -134
- data/test/xml/test_relax_ng.rb +0 -60
- data/test/xml/test_schema.rb +0 -142
- data/test/xml/test_syntax_error.rb +0 -36
- data/test/xml/test_text.rb +0 -60
- data/test/xml/test_unparented_node.rb +0 -483
- data/test/xml/test_xinclude.rb +0 -83
- data/test/xml/test_xpath.rb +0 -470
- data/test/xslt/test_custom_functions.rb +0 -133
- data/test/xslt/test_exception_handling.rb +0 -37
@@ -36,10 +36,12 @@ import java.util.Set;
|
|
36
36
|
|
37
37
|
import javax.xml.transform.TransformerException;
|
38
38
|
|
39
|
-
import
|
40
|
-
import
|
41
|
-
import
|
42
|
-
|
39
|
+
import org.apache.xml.dtm.DTM;
|
40
|
+
import org.apache.xpath.XPath;
|
41
|
+
import org.apache.xpath.XPathContext;
|
42
|
+
import org.apache.xpath.jaxp.JAXPPrefixResolver;
|
43
|
+
import org.apache.xpath.jaxp.JAXPVariableStack;
|
44
|
+
import org.apache.xpath.objects.XObject;
|
43
45
|
import org.jruby.Ruby;
|
44
46
|
import org.jruby.RubyClass;
|
45
47
|
import org.jruby.RubyObject;
|
@@ -51,13 +53,9 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
51
53
|
import org.jruby.util.SafePropertyAccessor;
|
52
54
|
import org.w3c.dom.Node;
|
53
55
|
|
54
|
-
import
|
55
|
-
import
|
56
|
-
import
|
57
|
-
import org.apache.xpath.jaxp.JAXPExtensionsProvider;
|
58
|
-
import org.apache.xpath.jaxp.JAXPPrefixResolver;
|
59
|
-
import org.apache.xpath.jaxp.JAXPVariableStack;
|
60
|
-
import org.apache.xpath.objects.XObject;
|
56
|
+
import nokogiri.internals.NokogiriNamespaceContext;
|
57
|
+
import nokogiri.internals.NokogiriXPathFunctionResolver;
|
58
|
+
import nokogiri.internals.NokogiriXPathVariableResolver;
|
61
59
|
|
62
60
|
/**
|
63
61
|
* Class for Nokogiri::XML::XpathContext
|
@@ -186,7 +184,7 @@ public class XmlXpathContext extends RubyObject {
|
|
186
184
|
case XObject.CLASS_BOOLEAN : return context.getRuntime().newBoolean(xobj.bool());
|
187
185
|
case XObject.CLASS_NUMBER : return context.getRuntime().newFloat(xobj.num());
|
188
186
|
case XObject.CLASS_NODESET :
|
189
|
-
XmlNodeSet xmlNodeSet = XmlNodeSet.
|
187
|
+
XmlNodeSet xmlNodeSet = XmlNodeSet.newEmptyNodeSet(context);
|
190
188
|
xmlNodeSet.setNodeList(xobj.nodelist());
|
191
189
|
xmlNodeSet.initialize(context.getRuntime(), this.context);
|
192
190
|
return xmlNodeSet;
|
@@ -34,7 +34,6 @@ package nokogiri.internals;
|
|
34
34
|
|
35
35
|
import java.io.ByteArrayInputStream;
|
36
36
|
import java.io.File;
|
37
|
-
import java.io.UnsupportedEncodingException;
|
38
37
|
import java.lang.reflect.InvocationTargetException;
|
39
38
|
import java.lang.reflect.Method;
|
40
39
|
import java.nio.ByteBuffer;
|
@@ -44,6 +43,20 @@ import java.util.Set;
|
|
44
43
|
import java.util.regex.Matcher;
|
45
44
|
import java.util.regex.Pattern;
|
46
45
|
|
46
|
+
import org.jruby.Ruby;
|
47
|
+
import org.jruby.RubyArray;
|
48
|
+
import org.jruby.RubyClass;
|
49
|
+
import org.jruby.RubyString;
|
50
|
+
import org.jruby.runtime.ThreadContext;
|
51
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
52
|
+
import org.jruby.util.ByteList;
|
53
|
+
import org.w3c.dom.Attr;
|
54
|
+
import org.w3c.dom.DOMException;
|
55
|
+
import org.w3c.dom.Document;
|
56
|
+
import org.w3c.dom.NamedNodeMap;
|
57
|
+
import org.w3c.dom.Node;
|
58
|
+
import org.w3c.dom.NodeList;
|
59
|
+
|
47
60
|
import nokogiri.HtmlDocument;
|
48
61
|
import nokogiri.NokogiriService;
|
49
62
|
import nokogiri.XmlAttr;
|
@@ -59,21 +72,6 @@ import nokogiri.XmlProcessingInstruction;
|
|
59
72
|
import nokogiri.XmlText;
|
60
73
|
import nokogiri.XmlXpathContext;
|
61
74
|
|
62
|
-
import org.jruby.Ruby;
|
63
|
-
import org.jruby.RubyArray;
|
64
|
-
import org.jruby.RubyClass;
|
65
|
-
import org.jruby.RubyEncoding;
|
66
|
-
import org.jruby.RubyString;
|
67
|
-
import org.jruby.runtime.ThreadContext;
|
68
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
69
|
-
import org.jruby.util.ByteList;
|
70
|
-
import org.w3c.dom.Attr;
|
71
|
-
import org.w3c.dom.Document;
|
72
|
-
import org.w3c.dom.NamedNodeMap;
|
73
|
-
import org.w3c.dom.Node;
|
74
|
-
import org.w3c.dom.NodeList;
|
75
|
-
import org.w3c.dom.DOMException;
|
76
|
-
|
77
75
|
/**
|
78
76
|
* A class for various utility methods.
|
79
77
|
*
|
@@ -627,16 +625,20 @@ public class NokogiriHelpers {
|
|
627
625
|
return newPrefix + ':' + tagName;
|
628
626
|
}
|
629
627
|
|
630
|
-
public static
|
631
|
-
|
632
|
-
|
628
|
+
public static IRubyObject[] nodeListToRubyArray(Ruby ruby, NodeList nodes) {
|
629
|
+
IRubyObject[] array = new IRubyObject[nodes.getLength()];
|
630
|
+
for (int i = 0; i < nodes.getLength(); i++) {
|
631
|
+
array[i] = NokogiriHelpers.getCachedNodeOrCreate(ruby, nodes.item(i));
|
632
|
+
}
|
633
|
+
return array;
|
633
634
|
}
|
634
635
|
|
635
|
-
public static
|
636
|
-
|
637
|
-
|
636
|
+
public static IRubyObject[] nodeArrayToArray(Ruby ruby, Node[] nodes) {
|
637
|
+
IRubyObject[] result = new IRubyObject[nodes.length];
|
638
|
+
for(int i = 0; i < nodes.length; i++) {
|
639
|
+
result[i] = NokogiriHelpers.getCachedNodeOrCreate(ruby, nodes[i]);
|
638
640
|
}
|
639
|
-
return
|
641
|
+
return result;
|
640
642
|
}
|
641
643
|
|
642
644
|
public static RubyArray nodeArrayToRubyArray(Ruby ruby, Node[] nodes) {
|
@@ -37,9 +37,6 @@ import java.util.List;
|
|
37
37
|
import javax.xml.xpath.XPathFunction;
|
38
38
|
import javax.xml.xpath.XPathFunctionException;
|
39
39
|
|
40
|
-
import nokogiri.XmlNode;
|
41
|
-
import nokogiri.XmlNodeSet;
|
42
|
-
|
43
40
|
import org.jruby.Ruby;
|
44
41
|
import org.jruby.RubyArray;
|
45
42
|
import org.jruby.RubyBoolean;
|
@@ -53,6 +50,9 @@ import org.jruby.runtime.ThreadContext;
|
|
53
50
|
import org.jruby.runtime.builtin.IRubyObject;
|
54
51
|
import org.w3c.dom.NodeList;
|
55
52
|
|
53
|
+
import nokogiri.XmlNode;
|
54
|
+
import nokogiri.XmlNodeSet;
|
55
|
+
|
56
56
|
/**
|
57
57
|
* Xpath function handler.
|
58
58
|
*
|
@@ -99,7 +99,7 @@ public class NokogiriXPathFunction implements XPathFunction {
|
|
99
99
|
private static IRubyObject fromObjectToRuby(final Ruby runtime, Object obj) {
|
100
100
|
// argument object type is one of NodeList, String, Boolean, or Double.
|
101
101
|
if (obj instanceof NodeList) {
|
102
|
-
XmlNodeSet xmlNodeSet = XmlNodeSet.
|
102
|
+
XmlNodeSet xmlNodeSet = XmlNodeSet.newEmptyNodeSet(runtime.getCurrentContext());
|
103
103
|
xmlNodeSet.setNodeList((NodeList) obj);
|
104
104
|
return xmlNodeSet;
|
105
105
|
}
|
@@ -116,7 +116,7 @@ public class NokogiriXPathFunction implements XPathFunction {
|
|
116
116
|
}
|
117
117
|
if (obj instanceof XmlNodeSet) return obj;
|
118
118
|
if (obj instanceof RubyArray) {
|
119
|
-
return XmlNodeSet.newXmlNodeSet(runtime, (RubyArray) obj);
|
119
|
+
return XmlNodeSet.newXmlNodeSet(runtime.getCurrentContext(), ((RubyArray) obj).toJavaArray());
|
120
120
|
}
|
121
121
|
/*if (o instanceof XmlNode)*/ return ((XmlNode) obj).getNode();
|
122
122
|
}
|
@@ -19,15 +19,16 @@
|
|
19
19
|
*/
|
20
20
|
package nokogiri.internals;
|
21
21
|
|
22
|
+
import javax.xml.transform.dom.DOMSource;
|
23
|
+
|
22
24
|
import org.apache.xml.dtm.DTM;
|
25
|
+
import nokogiri.internals.dom2dtm.DOM2DTM;
|
26
|
+
import nokogiri.internals.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode;
|
23
27
|
import org.apache.xml.dtm.DTMWSFilter;
|
24
|
-
import org.apache.xml.dtm.ref.dom2dtm.DOM2DTMExt;
|
25
28
|
import org.apache.xml.res.XMLErrorResources;
|
26
29
|
import org.apache.xml.res.XMLMessages;
|
27
30
|
import org.w3c.dom.Node;
|
28
31
|
|
29
|
-
import javax.xml.transform.dom.DOMSource;
|
30
|
-
|
31
32
|
/**
|
32
33
|
* @author kares
|
33
34
|
*/
|
@@ -75,8 +76,8 @@ public final class XalanDTMManagerPatch extends org.apache.xml.dtm.ref.DTMManage
|
|
75
76
|
// Have each DTM cache last DOM node search?
|
76
77
|
for(int i = 0; i < m_dtms.length; i++) {
|
77
78
|
DTM thisDTM = m_dtms[i];
|
78
|
-
if (thisDTM instanceof
|
79
|
-
int handle = ((
|
79
|
+
if (thisDTM instanceof DOM2DTM) {
|
80
|
+
int handle = ((DOM2DTM) thisDTM).getHandleOfNode(node);
|
80
81
|
if (handle != DTM.NULL) {
|
81
82
|
return handle;
|
82
83
|
}
|
@@ -107,11 +108,12 @@ public final class XalanDTMManagerPatch extends org.apache.xml.dtm.ref.DTMManage
|
|
107
108
|
for (; p != null; p = p.getParentNode()) root = p;
|
108
109
|
|
109
110
|
// DOM2DTM dtm = (DOM2DTM) getDTM(new DOMSource(root), false, null);
|
110
|
-
|
111
|
+
DOM2DTM dtm = getDTM(new DOMSource(root), false, null/*, true, true*/);
|
111
112
|
|
112
113
|
int handle;
|
113
114
|
|
114
|
-
if (node instanceof org.apache.xml.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode
|
115
|
+
if (node instanceof org.apache.xml.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode
|
116
|
+
|| node instanceof DOM2DTMdefaultNamespaceDeclarationNode) {
|
115
117
|
// Can't return the same node since it's unique to a specific DTM,
|
116
118
|
// but can return the equivalent node -- find the corresponding
|
117
119
|
// Document Element, then ask it for the xml: namespace decl.
|
@@ -153,12 +155,11 @@ public final class XalanDTMManagerPatch extends org.apache.xml.dtm.ref.DTMManage
|
|
153
155
|
return handle;
|
154
156
|
}
|
155
157
|
|
156
|
-
private
|
158
|
+
private DOM2DTM getDTM(DOMSource source, boolean unique, DTMWSFilter whiteSpaceFilter/*, boolean incremental, boolean doIndexing*/) {
|
157
159
|
int dtmPos = getFirstFreeDTMID();
|
158
160
|
int documentID = dtmPos << IDENT_DTM_NODE_BITS;
|
159
161
|
|
160
|
-
|
161
|
-
DOM2DTMExt dtm = new DOM2DTMExt(this, source, documentID, whiteSpaceFilter, m_xsf, true);
|
162
|
+
DOM2DTM dtm = new DOM2DTM(this, source, documentID, whiteSpaceFilter, m_xsf, true);
|
162
163
|
|
163
164
|
addDTM(dtm, dtmPos, 0);
|
164
165
|
return dtm;
|
@@ -15,10 +15,7 @@
|
|
15
15
|
* See the License for the specific language governing permissions and
|
16
16
|
* limitations under the License.
|
17
17
|
*/
|
18
|
-
|
19
|
-
* $Id: DOM2DTM.java 478671 2006-11-23 21:00:31Z minchau $
|
20
|
-
*/
|
21
|
-
package org.apache.xml.dtm.ref.dom2dtm;
|
18
|
+
package nokogiri.internals.dom2dtm;
|
22
19
|
|
23
20
|
import javax.xml.transform.SourceLocator;
|
24
21
|
import javax.xml.transform.dom.DOMSource;
|
@@ -30,7 +27,6 @@ import org.apache.xml.dtm.ref.DTMDefaultBaseIterators;
|
|
30
27
|
import org.apache.xml.dtm.ref.DTMManagerDefault;
|
31
28
|
import org.apache.xml.dtm.ref.ExpandedNameTable;
|
32
29
|
import org.apache.xml.dtm.ref.IncrementalSAXSource;
|
33
|
-
//import org.apache.xml.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode;
|
34
30
|
import org.apache.xml.res.XMLErrorResources;
|
35
31
|
import org.apache.xml.res.XMLMessages;
|
36
32
|
import org.apache.xml.utils.FastStringBuffer;
|
@@ -62,7 +58,7 @@ import org.xml.sax.ContentHandler;
|
|
62
58
|
* mutation. If you alter the DOM after wrapping DOM2DTM around it,
|
63
59
|
* all bets are off.
|
64
60
|
* */
|
65
|
-
public class
|
61
|
+
public class DOM2DTM extends DTMDefaultBaseIterators
|
66
62
|
{
|
67
63
|
// static final boolean JJK_DEBUG=false;
|
68
64
|
// static final boolean JJK_NEWCODE=true;
|
@@ -114,7 +110,7 @@ public class DOM2DTMExt extends DTMDefaultBaseIterators
|
|
114
110
|
* @param doIndexing true if the caller considers it worth it to use
|
115
111
|
* indexing schemes.
|
116
112
|
*/
|
117
|
-
public
|
113
|
+
public DOM2DTM(DTMManager mgr, DOMSource domSource,
|
118
114
|
int dtmIdentity, DTMWSFilter whiteSpaceFilter,
|
119
115
|
XMLStringFactory xstringfactory,
|
120
116
|
boolean doIndexing)
|
@@ -0,0 +1,685 @@
|
|
1
|
+
/*
|
2
|
+
* reserved comment block
|
3
|
+
* DO NOT REMOVE OR ALTER!
|
4
|
+
*/
|
5
|
+
/*
|
6
|
+
* Copyright 1999-2004 The Apache Software Foundation.
|
7
|
+
*
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
* you may not use this file except in compliance with the License.
|
10
|
+
* You may obtain a copy of the License at
|
11
|
+
*
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
*
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
* See the License for the specific language governing permissions and
|
18
|
+
* limitations under the License.
|
19
|
+
*/
|
20
|
+
/*
|
21
|
+
* $Id: DOM2DTMdefaultNamespaceDeclarationNode.java,v 1.2.4.1 2005/09/15 08:15:11 suresh_emailid Exp $
|
22
|
+
*/
|
23
|
+
|
24
|
+
// This is copied directly out of the original
|
25
|
+
// com.sun.org.apache.xml.internal.dtm.ref.dom2dtm path to allow modifying
|
26
|
+
// DOM2DTM and working around package private constructors. Other than the
|
27
|
+
// package declaration, this class is unmodified
|
28
|
+
|
29
|
+
package nokogiri.internals.dom2dtm;
|
30
|
+
|
31
|
+
import org.apache.xml.dtm.DTMException;
|
32
|
+
|
33
|
+
import org.w3c.dom.Attr;
|
34
|
+
import org.w3c.dom.Document;
|
35
|
+
import org.w3c.dom.Element;
|
36
|
+
import org.w3c.dom.NamedNodeMap;
|
37
|
+
import org.w3c.dom.Node;
|
38
|
+
import org.w3c.dom.NodeList;
|
39
|
+
import org.w3c.dom.TypeInfo;
|
40
|
+
import org.w3c.dom.UserDataHandler;
|
41
|
+
import org.w3c.dom.DOMException;
|
42
|
+
|
43
|
+
/** This is a kluge to let us shove a declaration for xml: into the
|
44
|
+
* DOM2DTM model. Basically, it creates a proxy node in DOM space to
|
45
|
+
* carry the additional information. This is _NOT_ a full DOM
|
46
|
+
* implementation, and shouldn't be one since it sits alongside the
|
47
|
+
* DOM rather than becoming part of the DOM model.
|
48
|
+
*
|
49
|
+
* (This used to be an internal class within DOM2DTM. Moved out because
|
50
|
+
* I need to perform an instanceof operation on it to support a temporary
|
51
|
+
* workaround in DTMManagerDefault.)
|
52
|
+
*
|
53
|
+
* %REVIEW% What if the DOM2DTM was built around a DocumentFragment and
|
54
|
+
* there isn't a single root element? I think this fails that case...
|
55
|
+
*
|
56
|
+
* %REVIEW% An alternative solution would be to create the node _only_
|
57
|
+
* in DTM space, but given how DOM2DTM is currently written I think
|
58
|
+
* this is simplest.
|
59
|
+
* */
|
60
|
+
public class DOM2DTMdefaultNamespaceDeclarationNode implements Attr,TypeInfo
|
61
|
+
{
|
62
|
+
final String NOT_SUPPORTED_ERR="Unsupported operation on pseudonode";
|
63
|
+
|
64
|
+
Element pseudoparent;
|
65
|
+
String prefix,uri,nodename;
|
66
|
+
int handle;
|
67
|
+
DOM2DTMdefaultNamespaceDeclarationNode(Element pseudoparent,String prefix,String uri,int handle)
|
68
|
+
{
|
69
|
+
this.pseudoparent=pseudoparent;
|
70
|
+
this.prefix=prefix;
|
71
|
+
this.uri=uri;
|
72
|
+
this.handle=handle;
|
73
|
+
this.nodename="xmlns:"+prefix;
|
74
|
+
}
|
75
|
+
public String getNodeName() {return nodename;}
|
76
|
+
public String getName() {return nodename;}
|
77
|
+
public String getNamespaceURI() {return "http://www.w3.org/2000/xmlns/";}
|
78
|
+
public String getPrefix() {return prefix;}
|
79
|
+
public String getLocalName() {return prefix;}
|
80
|
+
public String getNodeValue() {return uri;}
|
81
|
+
public String getValue() {return uri;}
|
82
|
+
public Element getOwnerElement() {return pseudoparent;}
|
83
|
+
|
84
|
+
public boolean isSupported(String feature, String version) {return false;}
|
85
|
+
public boolean hasChildNodes() {return false;}
|
86
|
+
public boolean hasAttributes() {return false;}
|
87
|
+
public Node getParentNode() {return null;}
|
88
|
+
public Node getFirstChild() {return null;}
|
89
|
+
public Node getLastChild() {return null;}
|
90
|
+
public Node getPreviousSibling() {return null;}
|
91
|
+
public Node getNextSibling() {return null;}
|
92
|
+
public boolean getSpecified() {return false;}
|
93
|
+
public void normalize() {return;}
|
94
|
+
public NodeList getChildNodes() {return null;}
|
95
|
+
public NamedNodeMap getAttributes() {return null;}
|
96
|
+
public short getNodeType() {return Node.ATTRIBUTE_NODE;}
|
97
|
+
public void setNodeValue(String value) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
98
|
+
public void setValue(String value) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
99
|
+
public void setPrefix(String value) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
100
|
+
public Node insertBefore(Node a, Node b) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
101
|
+
public Node replaceChild(Node a, Node b) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
102
|
+
public Node appendChild(Node a) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
103
|
+
public Node removeChild(Node a) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
104
|
+
public Document getOwnerDocument() {return pseudoparent.getOwnerDocument();}
|
105
|
+
public Node cloneNode(boolean deep) {throw new DTMException(NOT_SUPPORTED_ERR);}
|
106
|
+
|
107
|
+
/** Non-DOM method, part of the temporary kluge
|
108
|
+
* %REVIEW% This would be a pruning problem, but since it will always be
|
109
|
+
* added to the root element and we prune on elements, we shouldn't have
|
110
|
+
* to worry.
|
111
|
+
*/
|
112
|
+
public int getHandleOfNode()
|
113
|
+
{
|
114
|
+
return handle;
|
115
|
+
}
|
116
|
+
|
117
|
+
//RAMESH: PENDING=> Add proper implementation for the below DOM L3 additions
|
118
|
+
|
119
|
+
/**
|
120
|
+
* @see org.w3c.dom.TypeInfo#getTypeName()
|
121
|
+
*/
|
122
|
+
public String getTypeName() {return null; }
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @see org.w3c.dom.TypeInfo#getTypeNamespace()
|
126
|
+
*/
|
127
|
+
public String getTypeNamespace() { return null;}
|
128
|
+
|
129
|
+
/**
|
130
|
+
* @see or.gw3c.dom.TypeInfo#isDerivedFrom(String,String,int)
|
131
|
+
*/
|
132
|
+
public boolean isDerivedFrom( String ns, String localName, int derivationMethod ) {
|
133
|
+
return false;
|
134
|
+
}
|
135
|
+
|
136
|
+
public TypeInfo getSchemaTypeInfo() { return this; }
|
137
|
+
|
138
|
+
public boolean isId( ) { return false; }
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Associate an object to a key on this node. The object can later be
|
142
|
+
* retrieved from this node by calling <code>getUserData</code> with the
|
143
|
+
* same key.
|
144
|
+
* @param key The key to associate the object to.
|
145
|
+
* @param data The object to associate to the given key, or
|
146
|
+
* <code>null</code> to remove any existing association to that key.
|
147
|
+
* @param handler The handler to associate to that key, or
|
148
|
+
* <code>null</code>.
|
149
|
+
* @return Returns the <code>DOMObject</code> previously associated to
|
150
|
+
* the given key on this node, or <code>null</code> if there was none.
|
151
|
+
* @since DOM Level 3
|
152
|
+
*/
|
153
|
+
public Object setUserData(String key,
|
154
|
+
Object data,
|
155
|
+
UserDataHandler handler) {
|
156
|
+
return getOwnerDocument().setUserData( key, data, handler);
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Retrieves the object associated to a key on a this node. The object
|
161
|
+
* must first have been set to this node by calling
|
162
|
+
* <code>setUserData</code> with the same key.
|
163
|
+
* @param key The key the object is associated to.
|
164
|
+
* @return Returns the <code>DOMObject</code> associated to the given key
|
165
|
+
* on this node, or <code>null</code> if there was none.
|
166
|
+
* @since DOM Level 3
|
167
|
+
*/
|
168
|
+
public Object getUserData(String key) {
|
169
|
+
return getOwnerDocument().getUserData( key);
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* This method returns a specialized object which implements the
|
174
|
+
* specialized APIs of the specified feature and version. The
|
175
|
+
* specialized object may also be obtained by using binding-specific
|
176
|
+
* casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations.
|
177
|
+
* @param feature The name of the feature requested (case-insensitive).
|
178
|
+
* @param version This is the version number of the feature to test. If
|
179
|
+
* the version is <code>null</code> or the empty string, supporting
|
180
|
+
* any version of the feature will cause the method to return an
|
181
|
+
* object that supports at least one version of the feature.
|
182
|
+
* @return Returns an object which implements the specialized APIs of
|
183
|
+
* the specified feature and version, if any, or <code>null</code> if
|
184
|
+
* there is no object which implements interfaces associated with that
|
185
|
+
* feature. If the <code>DOMObject</code> returned by this method
|
186
|
+
* implements the <code>Node</code> interface, it must delegate to the
|
187
|
+
* primary core <code>Node</code> and not return results inconsistent
|
188
|
+
* with the primary core <code>Node</code> such as attributes,
|
189
|
+
* childNodes, etc.
|
190
|
+
* @since DOM Level 3
|
191
|
+
*/
|
192
|
+
public Object getFeature(String feature, String version) {
|
193
|
+
// we don't have any alternate node, either this node does the job
|
194
|
+
// or we don't have anything that does
|
195
|
+
return isSupported(feature, version) ? this : null;
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Tests whether two nodes are equal.
|
200
|
+
* <br>This method tests for equality of nodes, not sameness (i.e.,
|
201
|
+
* whether the two nodes are references to the same object) which can be
|
202
|
+
* tested with <code>Node.isSameNode</code>. All nodes that are the same
|
203
|
+
* will also be equal, though the reverse may not be true.
|
204
|
+
* <br>Two nodes are equal if and only if the following conditions are
|
205
|
+
* satisfied: The two nodes are of the same type.The following string
|
206
|
+
* attributes are equal: <code>nodeName</code>, <code>localName</code>,
|
207
|
+
* <code>namespaceURI</code>, <code>prefix</code>, <code>nodeValue</code>
|
208
|
+
* , <code>baseURI</code>. This is: they are both <code>null</code>, or
|
209
|
+
* they have the same length and are character for character identical.
|
210
|
+
* The <code>attributes</code> <code>NamedNodeMaps</code> are equal.
|
211
|
+
* This is: they are both <code>null</code>, or they have the same
|
212
|
+
* length and for each node that exists in one map there is a node that
|
213
|
+
* exists in the other map and is equal, although not necessarily at the
|
214
|
+
* same index.The <code>childNodes</code> <code>NodeLists</code> are
|
215
|
+
* equal. This is: they are both <code>null</code>, or they have the
|
216
|
+
* same length and contain equal nodes at the same index. This is true
|
217
|
+
* for <code>Attr</code> nodes as for any other type of node. Note that
|
218
|
+
* normalization can affect equality; to avoid this, nodes should be
|
219
|
+
* normalized before being compared.
|
220
|
+
* <br>For two <code>DocumentType</code> nodes to be equal, the following
|
221
|
+
* conditions must also be satisfied: The following string attributes
|
222
|
+
* are equal: <code>publicId</code>, <code>systemId</code>,
|
223
|
+
* <code>internalSubset</code>.The <code>entities</code>
|
224
|
+
* <code>NamedNodeMaps</code> are equal.The <code>notations</code>
|
225
|
+
* <code>NamedNodeMaps</code> are equal.
|
226
|
+
* <br>On the other hand, the following do not affect equality: the
|
227
|
+
* <code>ownerDocument</code> attribute, the <code>specified</code>
|
228
|
+
* attribute for <code>Attr</code> nodes, the
|
229
|
+
* <code>isWhitespaceInElementContent</code> attribute for
|
230
|
+
* <code>Text</code> nodes, as well as any user data or event listeners
|
231
|
+
* registered on the nodes.
|
232
|
+
* @param arg The node to compare equality with.
|
233
|
+
* @param deep If <code>true</code>, recursively compare the subtrees; if
|
234
|
+
* <code>false</code>, compare only the nodes themselves (and its
|
235
|
+
* attributes, if it is an <code>Element</code>).
|
236
|
+
* @return If the nodes, and possibly subtrees are equal,
|
237
|
+
* <code>true</code> otherwise <code>false</code>.
|
238
|
+
* @since DOM Level 3
|
239
|
+
*/
|
240
|
+
public boolean isEqualNode(Node arg) {
|
241
|
+
if (arg == this) {
|
242
|
+
return true;
|
243
|
+
}
|
244
|
+
if (arg.getNodeType() != getNodeType()) {
|
245
|
+
return false;
|
246
|
+
}
|
247
|
+
// in theory nodeName can't be null but better be careful
|
248
|
+
// who knows what other implementations may be doing?...
|
249
|
+
if (getNodeName() == null) {
|
250
|
+
if (arg.getNodeName() != null) {
|
251
|
+
return false;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
else if (!getNodeName().equals(arg.getNodeName())) {
|
255
|
+
return false;
|
256
|
+
}
|
257
|
+
|
258
|
+
if (getLocalName() == null) {
|
259
|
+
if (arg.getLocalName() != null) {
|
260
|
+
return false;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
else if (!getLocalName().equals(arg.getLocalName())) {
|
264
|
+
return false;
|
265
|
+
}
|
266
|
+
|
267
|
+
if (getNamespaceURI() == null) {
|
268
|
+
if (arg.getNamespaceURI() != null) {
|
269
|
+
return false;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
else if (!getNamespaceURI().equals(arg.getNamespaceURI())) {
|
273
|
+
return false;
|
274
|
+
}
|
275
|
+
|
276
|
+
if (getPrefix() == null) {
|
277
|
+
if (arg.getPrefix() != null) {
|
278
|
+
return false;
|
279
|
+
}
|
280
|
+
}
|
281
|
+
else if (!getPrefix().equals(arg.getPrefix())) {
|
282
|
+
return false;
|
283
|
+
}
|
284
|
+
|
285
|
+
if (getNodeValue() == null) {
|
286
|
+
if (arg.getNodeValue() != null) {
|
287
|
+
return false;
|
288
|
+
}
|
289
|
+
}
|
290
|
+
else if (!getNodeValue().equals(arg.getNodeValue())) {
|
291
|
+
return false;
|
292
|
+
}
|
293
|
+
/*
|
294
|
+
if (getBaseURI() == null) {
|
295
|
+
if (((NodeImpl) arg).getBaseURI() != null) {
|
296
|
+
return false;
|
297
|
+
}
|
298
|
+
}
|
299
|
+
else if (!getBaseURI().equals(((NodeImpl) arg).getBaseURI())) {
|
300
|
+
return false;
|
301
|
+
}
|
302
|
+
*/
|
303
|
+
|
304
|
+
return true;
|
305
|
+
}
|
306
|
+
|
307
|
+
/**
|
308
|
+
* DOM Level 3 - Experimental:
|
309
|
+
* Look up the namespace URI associated to the given prefix, starting from this node.
|
310
|
+
* Use lookupNamespaceURI(null) to lookup the default namespace
|
311
|
+
*
|
312
|
+
* @param namespaceURI
|
313
|
+
* @return th URI for the namespace
|
314
|
+
* @since DOM Level 3
|
315
|
+
*/
|
316
|
+
public String lookupNamespaceURI(String specifiedPrefix) {
|
317
|
+
short type = this.getNodeType();
|
318
|
+
switch (type) {
|
319
|
+
case Node.ELEMENT_NODE : {
|
320
|
+
|
321
|
+
String namespace = this.getNamespaceURI();
|
322
|
+
String prefix = this.getPrefix();
|
323
|
+
if (namespace !=null) {
|
324
|
+
// REVISIT: is it possible that prefix is empty string?
|
325
|
+
if (specifiedPrefix== null && prefix==specifiedPrefix) {
|
326
|
+
// looking for default namespace
|
327
|
+
return namespace;
|
328
|
+
} else if (prefix != null && prefix.equals(specifiedPrefix)) {
|
329
|
+
// non default namespace
|
330
|
+
return namespace;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
if (this.hasAttributes()) {
|
334
|
+
NamedNodeMap map = this.getAttributes();
|
335
|
+
int length = map.getLength();
|
336
|
+
for (int i=0;i<length;i++) {
|
337
|
+
Node attr = map.item(i);
|
338
|
+
String attrPrefix = attr.getPrefix();
|
339
|
+
String value = attr.getNodeValue();
|
340
|
+
namespace = attr.getNamespaceURI();
|
341
|
+
if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) {
|
342
|
+
// at this point we are dealing with DOM Level 2 nodes only
|
343
|
+
if (specifiedPrefix == null &&
|
344
|
+
attr.getNodeName().equals("xmlns")) {
|
345
|
+
// default namespace
|
346
|
+
return value;
|
347
|
+
} else if (attrPrefix !=null &&
|
348
|
+
attrPrefix.equals("xmlns") &&
|
349
|
+
attr.getLocalName().equals(specifiedPrefix)) {
|
350
|
+
// non default namespace
|
351
|
+
return value;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
/*
|
357
|
+
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
|
358
|
+
if (ancestor != null) {
|
359
|
+
return ancestor.lookupNamespaceURI(specifiedPrefix);
|
360
|
+
}
|
361
|
+
*/
|
362
|
+
|
363
|
+
return null;
|
364
|
+
|
365
|
+
|
366
|
+
}
|
367
|
+
/*
|
368
|
+
case Node.DOCUMENT_NODE : {
|
369
|
+
return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ;
|
370
|
+
}
|
371
|
+
*/
|
372
|
+
case Node.ENTITY_NODE :
|
373
|
+
case Node.NOTATION_NODE:
|
374
|
+
case Node.DOCUMENT_FRAGMENT_NODE:
|
375
|
+
case Node.DOCUMENT_TYPE_NODE:
|
376
|
+
// type is unknown
|
377
|
+
return null;
|
378
|
+
case Node.ATTRIBUTE_NODE:{
|
379
|
+
if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
|
380
|
+
return getOwnerElement().lookupNamespaceURI(specifiedPrefix);
|
381
|
+
|
382
|
+
}
|
383
|
+
return null;
|
384
|
+
}
|
385
|
+
default:{
|
386
|
+
/*
|
387
|
+
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
|
388
|
+
if (ancestor != null) {
|
389
|
+
return ancestor.lookupNamespaceURI(specifiedPrefix);
|
390
|
+
}
|
391
|
+
*/
|
392
|
+
return null;
|
393
|
+
}
|
394
|
+
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* DOM Level 3: Experimental
|
400
|
+
* This method checks if the specified <code>namespaceURI</code> is the
|
401
|
+
* default namespace or not.
|
402
|
+
* @param namespaceURI The namespace URI to look for.
|
403
|
+
* @return <code>true</code> if the specified <code>namespaceURI</code>
|
404
|
+
* is the default namespace, <code>false</code> otherwise.
|
405
|
+
* @since DOM Level 3
|
406
|
+
*/
|
407
|
+
public boolean isDefaultNamespace(String namespaceURI){
|
408
|
+
/*
|
409
|
+
// REVISIT: remove casts when DOM L3 becomes REC.
|
410
|
+
short type = this.getNodeType();
|
411
|
+
switch (type) {
|
412
|
+
case Node.ELEMENT_NODE: {
|
413
|
+
String namespace = this.getNamespaceURI();
|
414
|
+
String prefix = this.getPrefix();
|
415
|
+
|
416
|
+
// REVISIT: is it possible that prefix is empty string?
|
417
|
+
if (prefix == null || prefix.length() == 0) {
|
418
|
+
if (namespaceURI == null) {
|
419
|
+
return (namespace == namespaceURI);
|
420
|
+
}
|
421
|
+
return namespaceURI.equals(namespace);
|
422
|
+
}
|
423
|
+
if (this.hasAttributes()) {
|
424
|
+
ElementImpl elem = (ElementImpl)this;
|
425
|
+
NodeImpl attr = (NodeImpl)elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns");
|
426
|
+
if (attr != null) {
|
427
|
+
String value = attr.getNodeValue();
|
428
|
+
if (namespaceURI == null) {
|
429
|
+
return (namespace == value);
|
430
|
+
}
|
431
|
+
return namespaceURI.equals(value);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
|
436
|
+
if (ancestor != null) {
|
437
|
+
return ancestor.isDefaultNamespace(namespaceURI);
|
438
|
+
}
|
439
|
+
return false;
|
440
|
+
}
|
441
|
+
case Node.DOCUMENT_NODE:{
|
442
|
+
return((NodeImpl)((Document)this).getDocumentElement()).isDefaultNamespace(namespaceURI);
|
443
|
+
}
|
444
|
+
|
445
|
+
case Node.ENTITY_NODE :
|
446
|
+
case Node.NOTATION_NODE:
|
447
|
+
case Node.DOCUMENT_FRAGMENT_NODE:
|
448
|
+
case Node.DOCUMENT_TYPE_NODE:
|
449
|
+
// type is unknown
|
450
|
+
return false;
|
451
|
+
case Node.ATTRIBUTE_NODE:{
|
452
|
+
if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) {
|
453
|
+
return ownerNode.isDefaultNamespace(namespaceURI);
|
454
|
+
|
455
|
+
}
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
default:{
|
459
|
+
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
|
460
|
+
if (ancestor != null) {
|
461
|
+
return ancestor.isDefaultNamespace(namespaceURI);
|
462
|
+
}
|
463
|
+
return false;
|
464
|
+
}
|
465
|
+
|
466
|
+
}
|
467
|
+
*/
|
468
|
+
return false;
|
469
|
+
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
/**
|
474
|
+
*
|
475
|
+
* DOM Level 3 - Experimental:
|
476
|
+
* Look up the prefix associated to the given namespace URI, starting from this node.
|
477
|
+
*
|
478
|
+
* @param namespaceURI
|
479
|
+
* @return the prefix for the namespace
|
480
|
+
*/
|
481
|
+
public String lookupPrefix(String namespaceURI){
|
482
|
+
|
483
|
+
// REVISIT: When Namespaces 1.1 comes out this may not be true
|
484
|
+
// Prefix can't be bound to null namespace
|
485
|
+
if (namespaceURI == null) {
|
486
|
+
return null;
|
487
|
+
}
|
488
|
+
|
489
|
+
short type = this.getNodeType();
|
490
|
+
|
491
|
+
switch (type) {
|
492
|
+
/*
|
493
|
+
case Node.ELEMENT_NODE: {
|
494
|
+
|
495
|
+
String namespace = this.getNamespaceURI(); // to flip out children
|
496
|
+
return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
|
497
|
+
}
|
498
|
+
|
499
|
+
case Node.DOCUMENT_NODE:{
|
500
|
+
return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
|
501
|
+
}
|
502
|
+
*/
|
503
|
+
case Node.ENTITY_NODE :
|
504
|
+
case Node.NOTATION_NODE:
|
505
|
+
case Node.DOCUMENT_FRAGMENT_NODE:
|
506
|
+
case Node.DOCUMENT_TYPE_NODE:
|
507
|
+
// type is unknown
|
508
|
+
return null;
|
509
|
+
case Node.ATTRIBUTE_NODE:{
|
510
|
+
if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) {
|
511
|
+
return getOwnerElement().lookupPrefix(namespaceURI);
|
512
|
+
|
513
|
+
}
|
514
|
+
return null;
|
515
|
+
}
|
516
|
+
default:{
|
517
|
+
/*
|
518
|
+
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
|
519
|
+
if (ancestor != null) {
|
520
|
+
return ancestor.lookupPrefix(namespaceURI);
|
521
|
+
}
|
522
|
+
*/
|
523
|
+
return null;
|
524
|
+
}
|
525
|
+
}
|
526
|
+
}
|
527
|
+
|
528
|
+
/**
|
529
|
+
* Returns whether this node is the same node as the given one.
|
530
|
+
* <br>This method provides a way to determine whether two
|
531
|
+
* <code>Node</code> references returned by the implementation reference
|
532
|
+
* the same object. When two <code>Node</code> references are references
|
533
|
+
* to the same object, even if through a proxy, the references may be
|
534
|
+
* used completely interchangably, such that all attributes have the
|
535
|
+
* same values and calling the same DOM method on either reference
|
536
|
+
* always has exactly the same effect.
|
537
|
+
* @param other The node to test against.
|
538
|
+
* @return Returns <code>true</code> if the nodes are the same,
|
539
|
+
* <code>false</code> otherwise.
|
540
|
+
* @since DOM Level 3
|
541
|
+
*/
|
542
|
+
public boolean isSameNode(Node other) {
|
543
|
+
// we do not use any wrapper so the answer is obvious
|
544
|
+
return this == other;
|
545
|
+
}
|
546
|
+
|
547
|
+
/**
|
548
|
+
* This attribute returns the text content of this node and its
|
549
|
+
* descendants. When it is defined to be null, setting it has no effect.
|
550
|
+
* When set, any possible children this node may have are removed and
|
551
|
+
* replaced by a single <code>Text</code> node containing the string
|
552
|
+
* this attribute is set to. On getting, no serialization is performed,
|
553
|
+
* the returned string does not contain any markup. No whitespace
|
554
|
+
* normalization is performed, the returned string does not contain the
|
555
|
+
* element content whitespaces . Similarly, on setting, no parsing is
|
556
|
+
* performed either, the input string is taken as pure textual content.
|
557
|
+
* <br>The string returned is made of the text content of this node
|
558
|
+
* depending on its type, as defined below:
|
559
|
+
* <table border='1'>
|
560
|
+
* <tr>
|
561
|
+
* <th>Node type</th>
|
562
|
+
* <th>Content</th>
|
563
|
+
* </tr>
|
564
|
+
* <tr>
|
565
|
+
* <td valign='top' rowspan='1' colspan='1'>
|
566
|
+
* ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE,
|
567
|
+
* DOCUMENT_FRAGMENT_NODE</td>
|
568
|
+
* <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code>
|
569
|
+
* attribute value of every child node, excluding COMMENT_NODE and
|
570
|
+
* PROCESSING_INSTRUCTION_NODE nodes</td>
|
571
|
+
* </tr>
|
572
|
+
* <tr>
|
573
|
+
* <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE,
|
574
|
+
* CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td>
|
575
|
+
* <td valign='top' rowspan='1' colspan='1'>
|
576
|
+
* <code>nodeValue</code></td>
|
577
|
+
* </tr>
|
578
|
+
* <tr>
|
579
|
+
* <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td>
|
580
|
+
* <td valign='top' rowspan='1' colspan='1'>
|
581
|
+
* null</td>
|
582
|
+
* </tr>
|
583
|
+
* </table>
|
584
|
+
* @exception DOMException
|
585
|
+
* NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
|
586
|
+
* @exception DOMException
|
587
|
+
* DOMSTRING_SIZE_ERR: Raised when it would return more characters than
|
588
|
+
* fit in a <code>DOMString</code> variable on the implementation
|
589
|
+
* platform.
|
590
|
+
* @since DOM Level 3
|
591
|
+
*/
|
592
|
+
public void setTextContent(String textContent)
|
593
|
+
throws DOMException {
|
594
|
+
setNodeValue(textContent);
|
595
|
+
}
|
596
|
+
|
597
|
+
/**
|
598
|
+
* This attribute returns the text content of this node and its
|
599
|
+
* descendants. When it is defined to be null, setting it has no effect.
|
600
|
+
* When set, any possible children this node may have are removed and
|
601
|
+
* replaced by a single <code>Text</code> node containing the string
|
602
|
+
* this attribute is set to. On getting, no serialization is performed,
|
603
|
+
* the returned string does not contain any markup. No whitespace
|
604
|
+
* normalization is performed, the returned string does not contain the
|
605
|
+
* element content whitespaces . Similarly, on setting, no parsing is
|
606
|
+
* performed either, the input string is taken as pure textual content.
|
607
|
+
* <br>The string returned is made of the text content of this node
|
608
|
+
* depending on its type, as defined below:
|
609
|
+
* <table border='1'>
|
610
|
+
* <tr>
|
611
|
+
* <th>Node type</th>
|
612
|
+
* <th>Content</th>
|
613
|
+
* </tr>
|
614
|
+
* <tr>
|
615
|
+
* <td valign='top' rowspan='1' colspan='1'>
|
616
|
+
* ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE,
|
617
|
+
* DOCUMENT_FRAGMENT_NODE</td>
|
618
|
+
* <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code>
|
619
|
+
* attribute value of every child node, excluding COMMENT_NODE and
|
620
|
+
* PROCESSING_INSTRUCTION_NODE nodes</td>
|
621
|
+
* </tr>
|
622
|
+
* <tr>
|
623
|
+
* <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE,
|
624
|
+
* CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td>
|
625
|
+
* <td valign='top' rowspan='1' colspan='1'>
|
626
|
+
* <code>nodeValue</code></td>
|
627
|
+
* </tr>
|
628
|
+
* <tr>
|
629
|
+
* <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td>
|
630
|
+
* <td valign='top' rowspan='1' colspan='1'>
|
631
|
+
* null</td>
|
632
|
+
* </tr>
|
633
|
+
* </table>
|
634
|
+
* @exception DOMException
|
635
|
+
* NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
|
636
|
+
* @exception DOMException
|
637
|
+
* DOMSTRING_SIZE_ERR: Raised when it would return more characters than
|
638
|
+
* fit in a <code>DOMString</code> variable on the implementation
|
639
|
+
* platform.
|
640
|
+
* @since DOM Level 3
|
641
|
+
*/
|
642
|
+
public String getTextContent() throws DOMException {
|
643
|
+
return getNodeValue(); // overriden in some subclasses
|
644
|
+
}
|
645
|
+
|
646
|
+
/**
|
647
|
+
* Compares a node with this node with regard to their position in the
|
648
|
+
* document.
|
649
|
+
* @param other The node to compare against this node.
|
650
|
+
* @return Returns how the given node is positioned relatively to this
|
651
|
+
* node.
|
652
|
+
* @since DOM Level 3
|
653
|
+
*/
|
654
|
+
public short compareDocumentPosition(Node other) throws DOMException {
|
655
|
+
return 0;
|
656
|
+
}
|
657
|
+
|
658
|
+
/**
|
659
|
+
* The absolute base URI of this node or <code>null</code> if undefined.
|
660
|
+
* This value is computed according to . However, when the
|
661
|
+
* <code>Document</code> supports the feature "HTML" , the base URI is
|
662
|
+
* computed using first the value of the href attribute of the HTML BASE
|
663
|
+
* element if any, and the value of the <code>documentURI</code>
|
664
|
+
* attribute from the <code>Document</code> interface otherwise.
|
665
|
+
* <br> When the node is an <code>Element</code>, a <code>Document</code>
|
666
|
+
* or a a <code>ProcessingInstruction</code>, this attribute represents
|
667
|
+
* the properties [base URI] defined in . When the node is a
|
668
|
+
* <code>Notation</code>, an <code>Entity</code>, or an
|
669
|
+
* <code>EntityReference</code>, this attribute represents the
|
670
|
+
* properties [declaration base URI] in the . How will this be affected
|
671
|
+
* by resolution of relative namespace URIs issue?It's not.Should this
|
672
|
+
* only be on Document, Element, ProcessingInstruction, Entity, and
|
673
|
+
* Notation nodes, according to the infoset? If not, what is it equal to
|
674
|
+
* on other nodes? Null? An empty string? I think it should be the
|
675
|
+
* parent's.No.Should this be read-only and computed or and actual
|
676
|
+
* read-write attribute?Read-only and computed (F2F 19 Jun 2000 and
|
677
|
+
* teleconference 30 May 2001).If the base HTML element is not yet
|
678
|
+
* attached to a document, does the insert change the Document.baseURI?
|
679
|
+
* Yes. (F2F 26 Sep 2001)
|
680
|
+
* @since DOM Level 3
|
681
|
+
*/
|
682
|
+
public String getBaseURI() {
|
683
|
+
return null;
|
684
|
+
}
|
685
|
+
}
|