nokogiri 1.10.8-java → 1.11.0.rc3-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 +4 -4
- data/README.md +24 -22
- data/ext/java/nokogiri/HtmlDocument.java +34 -46
- data/ext/java/nokogiri/HtmlSaxParserContext.java +87 -57
- data/ext/java/nokogiri/NokogiriService.java +1 -1
- data/ext/java/nokogiri/XmlAttr.java +13 -20
- data/ext/java/nokogiri/XmlAttributeDecl.java +11 -12
- data/ext/java/nokogiri/XmlCdata.java +3 -4
- data/ext/java/nokogiri/XmlComment.java +1 -1
- data/ext/java/nokogiri/XmlDocument.java +148 -175
- data/ext/java/nokogiri/XmlDocumentFragment.java +13 -31
- data/ext/java/nokogiri/XmlDtd.java +5 -8
- data/ext/java/nokogiri/XmlElement.java +1 -20
- data/ext/java/nokogiri/XmlElementDecl.java +23 -28
- data/ext/java/nokogiri/XmlEntityDecl.java +23 -27
- data/ext/java/nokogiri/XmlEntityReference.java +2 -2
- data/ext/java/nokogiri/XmlNamespace.java +72 -89
- data/ext/java/nokogiri/XmlNode.java +300 -401
- data/ext/java/nokogiri/XmlNodeSet.java +72 -77
- data/ext/java/nokogiri/XmlReader.java +10 -11
- data/ext/java/nokogiri/XmlSaxParserContext.java +7 -7
- data/ext/java/nokogiri/XmlSchema.java +3 -3
- data/ext/java/nokogiri/XmlText.java +12 -9
- data/ext/java/nokogiri/XmlXpathContext.java +7 -7
- data/ext/java/nokogiri/XsltStylesheet.java +7 -15
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +4 -10
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +71 -135
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +90 -58
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +5 -4
- data/ext/java/nokogiri/internals/ParserContext.java +27 -73
- data/ext/java/nokogiri/internals/ReaderNode.java +2 -4
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +17 -32
- data/ext/nokogiri/extconf.rb +50 -37
- data/ext/nokogiri/nokogiri.c +12 -6
- data/ext/nokogiri/nokogiri.h +13 -0
- data/ext/nokogiri/xml_document.c +16 -2
- data/ext/nokogiri/xml_io.c +8 -6
- data/ext/nokogiri/xml_node.c +20 -0
- data/ext/nokogiri/xml_reader.c +6 -17
- data/ext/nokogiri/xml_schema.c +29 -0
- data/ext/nokogiri/xslt_stylesheet.c +0 -4
- data/lib/nokogiri.rb +3 -20
- data/lib/nokogiri/css.rb +1 -0
- data/lib/nokogiri/css/node.rb +1 -0
- data/lib/nokogiri/css/parser.rb +61 -60
- data/lib/nokogiri/css/parser_extras.rb +39 -36
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +1 -0
- data/lib/nokogiri/css/xpath_visitor.rb +3 -1
- data/lib/nokogiri/decorators/slop.rb +1 -0
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/builder.rb +1 -0
- data/lib/nokogiri/html/document.rb +1 -0
- data/lib/nokogiri/html/document_fragment.rb +1 -0
- data/lib/nokogiri/html/element_description.rb +1 -0
- data/lib/nokogiri/html/element_description_defaults.rb +1 -0
- data/lib/nokogiri/html/entity_lookup.rb +1 -0
- data/lib/nokogiri/html/sax/parser.rb +1 -0
- data/lib/nokogiri/html/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html/sax/push_parser.rb +1 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version.rb +86 -45
- data/lib/nokogiri/xml.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +1 -0
- data/lib/nokogiri/xml/attribute_decl.rb +1 -0
- data/lib/nokogiri/xml/builder.rb +3 -2
- data/lib/nokogiri/xml/cdata.rb +1 -0
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +3 -8
- data/lib/nokogiri/xml/document_fragment.rb +1 -0
- data/lib/nokogiri/xml/dtd.rb +1 -0
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +1 -0
- data/lib/nokogiri/xml/entity_decl.rb +1 -0
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +1 -0
- data/lib/nokogiri/xml/node.rb +539 -224
- data/lib/nokogiri/xml/node/save_options.rb +1 -0
- data/lib/nokogiri/xml/node_set.rb +1 -0
- data/lib/nokogiri/xml/notation.rb +1 -0
- data/lib/nokogiri/xml/parse_options.rb +4 -3
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/pp/character_data.rb +1 -0
- data/lib/nokogiri/xml/pp/node.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +1 -0
- data/lib/nokogiri/xml/reader.rb +7 -3
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +1 -0
- data/lib/nokogiri/xml/sax/parser.rb +1 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +1 -0
- data/lib/nokogiri/xml/searchable.rb +22 -15
- data/lib/nokogiri/xml/syntax_error.rb +1 -0
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
- data/lib/nokogiri/xml/xpath_context.rb +1 -0
- data/lib/nokogiri/xslt.rb +1 -0
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/xsd/xmlparser/nokogiri.rb +1 -0
- metadata +53 -34
- data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +0 -107
- data/ext/java/nokogiri/internals/UncloseableInputStream.java +0 -102
@@ -64,7 +64,8 @@ import org.w3c.dom.NamedNodeMap;
|
|
64
64
|
*/
|
65
65
|
@JRubyClass(name="Nokogiri::XML::DocumentFragment", parent="Nokogiri::XML::Node")
|
66
66
|
public class XmlDocumentFragment extends XmlNode {
|
67
|
-
|
67
|
+
|
68
|
+
private XmlElement fragmentContext;
|
68
69
|
|
69
70
|
public XmlDocumentFragment(Ruby ruby) {
|
70
71
|
this(ruby, getNokogiriClass(ruby, "Nokogiri::XML::DocumentFragment"));
|
@@ -76,27 +77,27 @@ public class XmlDocumentFragment extends XmlNode {
|
|
76
77
|
|
77
78
|
@JRubyMethod(name="new", meta = true, required=1, optional=2)
|
78
79
|
public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args) {
|
79
|
-
|
80
|
-
|
81
|
-
throw context.getRuntime().newArgumentError(args.length, 1);
|
80
|
+
if (args.length < 1) {
|
81
|
+
throw context.runtime.newArgumentError(args.length, 1);
|
82
82
|
}
|
83
83
|
|
84
|
-
if(!(args[0] instanceof XmlDocument)){
|
85
|
-
throw context.
|
84
|
+
if (!(args[0] instanceof XmlDocument)){
|
85
|
+
throw context.runtime.newArgumentError("first parameter must be a Nokogiri::XML::Document instance");
|
86
86
|
}
|
87
87
|
|
88
88
|
XmlDocument doc = (XmlDocument) args[0];
|
89
89
|
|
90
90
|
// make wellformed fragment, ignore invalid namespace, or add appropriate namespace to parse
|
91
91
|
if (args.length > 1 && args[1] instanceof RubyString) {
|
92
|
-
|
93
|
-
|
92
|
+
final RubyString arg1 = (RubyString) args[1];
|
93
|
+
if (XmlDocumentFragment.isTag(arg1)) {
|
94
|
+
args[1] = RubyString.newString(context.runtime, addNamespaceDeclIfNeeded(doc, rubyStringToString(arg1)));
|
94
95
|
}
|
95
96
|
}
|
96
97
|
|
97
|
-
XmlDocumentFragment fragment = (XmlDocumentFragment) NokogiriService.XML_DOCUMENT_FRAGMENT_ALLOCATOR.allocate(context.
|
98
|
+
XmlDocumentFragment fragment = (XmlDocumentFragment) NokogiriService.XML_DOCUMENT_FRAGMENT_ALLOCATOR.allocate(context.runtime, (RubyClass)cls);
|
98
99
|
fragment.setDocument(context, doc);
|
99
|
-
fragment.setNode(context, doc.getDocument().createDocumentFragment());
|
100
|
+
fragment.setNode(context.runtime, doc.getDocument().createDocumentFragment());
|
100
101
|
|
101
102
|
//TODO: Get namespace definitions from doc.
|
102
103
|
if (args.length == 3 && args[2] != null && args[2] instanceof XmlElement) {
|
@@ -118,7 +119,7 @@ public class XmlDocumentFragment extends XmlNode {
|
|
118
119
|
for (int i=0; i < nodeMap.getLength(); i++) {
|
119
120
|
Attr attr = (Attr)nodeMap.item(i);
|
120
121
|
if (isNamespace(attr.getNodeName())) {
|
121
|
-
String localPart = getLocalNameForNamespace(attr.getNodeName());
|
122
|
+
String localPart = getLocalNameForNamespace(attr.getNodeName(), null);
|
122
123
|
if (getPrefix(qName).equals(localPart)) {
|
123
124
|
return true;
|
124
125
|
}
|
@@ -177,27 +178,8 @@ public class XmlDocumentFragment extends XmlNode {
|
|
177
178
|
return fragmentContext;
|
178
179
|
}
|
179
180
|
|
180
|
-
//@Override
|
181
|
-
public void add_child(ThreadContext context, XmlNode child) {
|
182
|
-
// Some magic for DocumentFragment
|
183
|
-
|
184
|
-
Ruby ruby = context.getRuntime();
|
185
|
-
XmlNodeSet children = (XmlNodeSet) child.children(context);
|
186
|
-
|
187
|
-
long length = children.length();
|
188
|
-
|
189
|
-
RubyArray childrenArray = children.convertToArray();
|
190
|
-
|
191
|
-
if(length != 0) {
|
192
|
-
for(int i = 0; i < length; i++) {
|
193
|
-
XmlNode item = (XmlNode) ((XmlNode) childrenArray.aref(ruby.newFixnum(i))).dup_implementation(context, true);
|
194
|
-
add_child(context, item);
|
195
|
-
}
|
196
|
-
}
|
197
|
-
}
|
198
|
-
|
199
181
|
@Override
|
200
182
|
public void relink_namespace(ThreadContext context) {
|
201
|
-
(
|
183
|
+
relink_namespace(context, getChildren());
|
202
184
|
}
|
203
185
|
}
|
@@ -369,7 +369,7 @@ public class XmlDtd extends XmlNode {
|
|
369
369
|
* the various collections.
|
370
370
|
*/
|
371
371
|
protected void extractDecls(ThreadContext context) {
|
372
|
-
Ruby runtime = context.
|
372
|
+
Ruby runtime = context.runtime;
|
373
373
|
|
374
374
|
// initialize data structures
|
375
375
|
attributes = RubyHash.newHash(runtime);
|
@@ -383,7 +383,7 @@ public class XmlDtd extends XmlNode {
|
|
383
383
|
if (node == null) return; // leave all the decl hash's empty
|
384
384
|
|
385
385
|
// convert allDecls to a NodeSet
|
386
|
-
children = XmlNodeSet.
|
386
|
+
children = XmlNodeSet.newNodeSet(runtime, extractDecls(context, node.getFirstChild()));
|
387
387
|
|
388
388
|
// add attribute decls as attributes to the matching element decl
|
389
389
|
RubyArray keys = attributes.keys();
|
@@ -432,18 +432,15 @@ public class XmlDtd extends XmlNode {
|
|
432
432
|
if (isExternalSubset(node)) {
|
433
433
|
break;
|
434
434
|
} else if (isAttributeDecl(node)) {
|
435
|
-
XmlAttributeDecl decl = (
|
436
|
-
XmlAttributeDecl.create(context, node);
|
435
|
+
XmlAttributeDecl decl = XmlAttributeDecl.create(context, node);
|
437
436
|
attributes.op_aset(context, decl.attribute_name(context), decl);
|
438
437
|
decls.add(decl);
|
439
438
|
} else if (isElementDecl(node)) {
|
440
|
-
XmlElementDecl decl = (
|
441
|
-
XmlElementDecl.create(context, node);
|
439
|
+
XmlElementDecl decl = XmlElementDecl.create(context, node);
|
442
440
|
elements.op_aset(context, decl.element_name(context), decl);
|
443
441
|
decls.add(decl);
|
444
442
|
} else if (isEntityDecl(node)) {
|
445
|
-
XmlEntityDecl decl = (
|
446
|
-
XmlEntityDecl.create(context, node);
|
443
|
+
XmlEntityDecl decl = XmlEntityDecl.create(context, node);
|
447
444
|
entities.op_aset(context, decl.node_name(context), decl);
|
448
445
|
decls.add(decl);
|
449
446
|
} else if (isNotationDecl(node)) {
|
@@ -59,29 +59,10 @@ public class XmlElement extends XmlNode {
|
|
59
59
|
super(runtime, klazz, element);
|
60
60
|
}
|
61
61
|
|
62
|
-
@Override
|
63
|
-
public void setNode(ThreadContext context, Node node) {
|
64
|
-
super.setNode(context, node);
|
65
|
-
if (doc != null)
|
66
|
-
setInstanceVariable("@document", doc);
|
67
|
-
}
|
68
|
-
|
69
62
|
@Override
|
70
63
|
public void accept(ThreadContext context, SaveContextVisitor visitor) {
|
71
64
|
visitor.enter((Element) node);
|
72
|
-
|
73
|
-
if (xmlNodeSet.length() > 0) {
|
74
|
-
IRubyObject[] nodes = XmlNodeSet.getNodes(context, xmlNodeSet);
|
75
|
-
for( int i = 0; i < nodes.length; i++ ) {
|
76
|
-
Object item = nodes[i];
|
77
|
-
if (item instanceof XmlNode) {
|
78
|
-
((XmlNode) item).accept(context, visitor);
|
79
|
-
}
|
80
|
-
else if (item instanceof XmlNamespace) {
|
81
|
-
((XmlNamespace) item).accept(context, visitor);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
}
|
65
|
+
acceptChildren(context, getChildren(), visitor);
|
85
66
|
visitor.leave((Element) node);
|
86
67
|
}
|
87
68
|
}
|
@@ -56,32 +56,31 @@ public class XmlElementDecl extends XmlNode {
|
|
56
56
|
RubyArray attrDecls;
|
57
57
|
IRubyObject contentModel;
|
58
58
|
|
59
|
-
public XmlElementDecl(Ruby
|
60
|
-
super(
|
61
|
-
|
62
|
-
|
63
|
-
public void setNode(ThreadContext context, Node node) {
|
64
|
-
super.setNode(context, node);
|
65
|
-
attrDecls = RubyArray.newArray(context.getRuntime());
|
66
|
-
contentModel = context.getRuntime().getNil();
|
59
|
+
public XmlElementDecl(Ruby runtime, RubyClass klazz) {
|
60
|
+
super(runtime, klazz);
|
61
|
+
attrDecls = RubyArray.newArray(runtime);
|
62
|
+
contentModel = runtime.getNil();
|
67
63
|
}
|
68
64
|
|
69
65
|
/**
|
70
|
-
* Initialize based on an elementDecl node from a NekoDTD parsed
|
71
|
-
* DTD.
|
66
|
+
* Initialize based on an elementDecl node from a NekoDTD parsed DTD.
|
72
67
|
*/
|
73
68
|
public XmlElementDecl(Ruby ruby, RubyClass klass, Node elemDeclNode) {
|
74
69
|
super(ruby, klass, elemDeclNode);
|
75
|
-
attrDecls = RubyArray.newArray(ruby);
|
76
|
-
contentModel = ruby.getNil();
|
77
70
|
}
|
78
71
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
72
|
+
@Override // gets called from constructor ^^^
|
73
|
+
public void setNode(Ruby runtime, Node node) {
|
74
|
+
super.setNode(runtime, node);
|
75
|
+
attrDecls = RubyArray.newArray(runtime);
|
76
|
+
contentModel = runtime.getNil();
|
77
|
+
}
|
78
|
+
|
79
|
+
static XmlElementDecl create(ThreadContext context, Node elemDeclNode) {
|
80
|
+
return new XmlElementDecl(context.runtime,
|
81
|
+
getNokogiriClass(context.runtime, "Nokogiri::XML::ElementDecl"),
|
82
|
+
elemDeclNode
|
83
|
+
);
|
85
84
|
}
|
86
85
|
|
87
86
|
public IRubyObject element_name(ThreadContext context) {
|
@@ -105,10 +104,8 @@ public class XmlElementDecl extends XmlNode {
|
|
105
104
|
@JRubyMethod
|
106
105
|
public IRubyObject prefix(ThreadContext context) {
|
107
106
|
String enamePrefix = getPrefix(getAttribute("ename"));
|
108
|
-
if (enamePrefix == null)
|
109
|
-
|
110
|
-
else
|
111
|
-
return context.getRuntime().newString(enamePrefix);
|
107
|
+
if (enamePrefix == null) return context.nil;
|
108
|
+
return context.runtime.newString(enamePrefix);
|
112
109
|
}
|
113
110
|
|
114
111
|
/**
|
@@ -118,14 +115,13 @@ public class XmlElementDecl extends XmlNode {
|
|
118
115
|
@JRubyMethod
|
119
116
|
public IRubyObject node_name(ThreadContext context) {
|
120
117
|
String ename = getLocalPart(getAttribute("ename"));
|
121
|
-
return context.
|
118
|
+
return context.runtime.newString(ename);
|
122
119
|
}
|
123
120
|
|
124
121
|
@Override
|
125
122
|
@JRubyMethod(name = "node_name=")
|
126
123
|
public IRubyObject node_name_set(ThreadContext context, IRubyObject name) {
|
127
|
-
throw context.
|
128
|
-
.newRuntimeError("cannot change name of DTD decl");
|
124
|
+
throw context.runtime.newRuntimeError("cannot change name of DTD decl");
|
129
125
|
}
|
130
126
|
|
131
127
|
@Override
|
@@ -137,8 +133,7 @@ public class XmlElementDecl extends XmlNode {
|
|
137
133
|
@Override
|
138
134
|
@JRubyMethod
|
139
135
|
public IRubyObject attribute(ThreadContext context, IRubyObject name) {
|
140
|
-
throw context.
|
141
|
-
.newRuntimeError("attribute by name not implemented");
|
136
|
+
throw context.runtime.newRuntimeError("attribute by name not implemented");
|
142
137
|
}
|
143
138
|
|
144
139
|
public void appendAttrDecl(XmlAttributeDecl decl) {
|
@@ -147,6 +142,6 @@ public class XmlElementDecl extends XmlNode {
|
|
147
142
|
|
148
143
|
@JRubyMethod
|
149
144
|
public IRubyObject element_type(ThreadContext context) {
|
150
|
-
return context.
|
145
|
+
return context.runtime.newFixnum(node.getNodeType());
|
151
146
|
}
|
152
147
|
}
|
@@ -64,26 +64,25 @@ public class XmlEntityDecl extends XmlNode {
|
|
64
64
|
private IRubyObject system_id;
|
65
65
|
private IRubyObject content;
|
66
66
|
|
67
|
-
|
68
|
-
super(
|
69
|
-
throw ruby.newRuntimeError("node required");
|
67
|
+
XmlEntityDecl(Ruby runtime, RubyClass klass) {
|
68
|
+
super(runtime, klass);
|
70
69
|
}
|
71
70
|
|
72
71
|
/**
|
73
|
-
* Initialize based on an entityDecl node from a NekoDTD parsed
|
74
|
-
* DTD.
|
72
|
+
* Initialize based on an entityDecl node from a NekoDTD parsed DTD.
|
75
73
|
*/
|
76
|
-
public XmlEntityDecl(Ruby
|
77
|
-
super(
|
78
|
-
entityType = RubyFixnum.newFixnum(
|
79
|
-
name = external_id = system_id = content =
|
74
|
+
public XmlEntityDecl(Ruby runtime, RubyClass klass, Node entDeclNode) {
|
75
|
+
super(runtime, klass, entDeclNode);
|
76
|
+
entityType = RubyFixnum.newFixnum(runtime, XmlEntityDecl.INTERNAL_GENERAL);
|
77
|
+
name = external_id = system_id = content = runtime.getNil();
|
80
78
|
}
|
81
79
|
|
82
|
-
public XmlEntityDecl(Ruby
|
83
|
-
super(
|
80
|
+
public XmlEntityDecl(Ruby runtime, RubyClass klass, Node entDeclNode, IRubyObject[] argv) {
|
81
|
+
super(runtime, klass, entDeclNode);
|
84
82
|
name = argv[0];
|
85
|
-
entityType = RubyFixnum.newFixnum(
|
86
|
-
external_id = system_id = content =
|
83
|
+
entityType = RubyFixnum.newFixnum(runtime, XmlEntityDecl.INTERNAL_GENERAL);
|
84
|
+
external_id = system_id = content = runtime.getNil();
|
85
|
+
|
87
86
|
if (argv.length > 1) entityType = argv[1];
|
88
87
|
if (argv.length > 4) {
|
89
88
|
external_id = argv[2];
|
@@ -92,21 +91,19 @@ public class XmlEntityDecl extends XmlNode {
|
|
92
91
|
}
|
93
92
|
}
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
return self;
|
94
|
+
static XmlEntityDecl create(ThreadContext context, Node entDeclNode) {
|
95
|
+
return new XmlEntityDecl(context.runtime,
|
96
|
+
getNokogiriClass(context.runtime, "Nokogiri::XML::EntityDecl"),
|
97
|
+
entDeclNode
|
98
|
+
);
|
101
99
|
}
|
102
100
|
|
103
101
|
// when entity is created by create_entity method
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
return self;
|
102
|
+
static XmlEntityDecl create(ThreadContext context, Node entDeclNode, IRubyObject... argv) {
|
103
|
+
return new XmlEntityDecl(context.runtime,
|
104
|
+
getNokogiriClass(context.runtime, "Nokogiri::XML::EntityDecl"),
|
105
|
+
entDeclNode, argv
|
106
|
+
);
|
110
107
|
}
|
111
108
|
|
112
109
|
/**
|
@@ -123,8 +120,7 @@ public class XmlEntityDecl extends XmlNode {
|
|
123
120
|
@Override
|
124
121
|
@JRubyMethod(name = "node_name=")
|
125
122
|
public IRubyObject node_name_set(ThreadContext context, IRubyObject name) {
|
126
|
-
throw context.
|
127
|
-
.newRuntimeError("cannot change name of DTD decl");
|
123
|
+
throw context.runtime.newRuntimeError("cannot change name of DTD decl");
|
128
124
|
}
|
129
125
|
|
130
126
|
@JRubyMethod
|
@@ -65,7 +65,7 @@ public class XmlEntityReference extends XmlNode {
|
|
65
65
|
|
66
66
|
protected void init(ThreadContext context, IRubyObject[] args) {
|
67
67
|
if (args.length < 2) {
|
68
|
-
throw
|
68
|
+
throw context.runtime.newArgumentError(args.length, 2);
|
69
69
|
}
|
70
70
|
|
71
71
|
IRubyObject doc = args[0];
|
@@ -78,7 +78,7 @@ public class XmlEntityReference extends XmlNode {
|
|
78
78
|
internalDocument.setErrorChecking(false);
|
79
79
|
Node node = document.createEntityReference(rubyStringToString(name));
|
80
80
|
internalDocument.setErrorChecking(oldErrorChecking);
|
81
|
-
setNode(context, node);
|
81
|
+
setNode(context.runtime, node);
|
82
82
|
}
|
83
83
|
|
84
84
|
@Override
|
@@ -32,18 +32,14 @@
|
|
32
32
|
|
33
33
|
package nokogiri;
|
34
34
|
|
35
|
-
import static nokogiri.internals.NokogiriHelpers.CACHED_NODE;
|
36
35
|
import static nokogiri.internals.NokogiriHelpers.getCachedNodeOrCreate;
|
37
36
|
import static nokogiri.internals.NokogiriHelpers.getLocalNameForNamespace;
|
38
37
|
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
39
|
-
import static nokogiri.internals.NokogiriHelpers.stringOrNil;
|
40
|
-
import nokogiri.internals.NokogiriHelpers;
|
41
38
|
import nokogiri.internals.SaveContextVisitor;
|
42
39
|
|
43
40
|
import org.jruby.Ruby;
|
44
41
|
import org.jruby.RubyClass;
|
45
42
|
import org.jruby.RubyObject;
|
46
|
-
import org.jruby.RubyString;
|
47
43
|
import org.jruby.anno.JRubyClass;
|
48
44
|
import org.jruby.anno.JRubyMethod;
|
49
45
|
import org.jruby.runtime.ThreadContext;
|
@@ -61,122 +57,97 @@ import org.w3c.dom.Node;
|
|
61
57
|
@JRubyClass(name="Nokogiri::XML::Namespace")
|
62
58
|
public class XmlNamespace extends RubyObject {
|
63
59
|
private Attr attr;
|
64
|
-
private IRubyObject
|
65
|
-
private IRubyObject
|
66
|
-
private String
|
67
|
-
private String
|
60
|
+
private transient IRubyObject prefixRuby;
|
61
|
+
private transient IRubyObject hrefRuby;
|
62
|
+
private String prefix;
|
63
|
+
private String href;
|
68
64
|
|
69
|
-
public XmlNamespace(Ruby
|
70
|
-
super(
|
65
|
+
public XmlNamespace(Ruby runtime, RubyClass klazz) {
|
66
|
+
super(runtime, klazz);
|
71
67
|
}
|
72
|
-
|
68
|
+
|
69
|
+
XmlNamespace(Ruby runtime, Attr attr, String prefix, String href, IRubyObject document) {
|
70
|
+
this(runtime, attr, prefix, null, href, null, document);
|
71
|
+
}
|
72
|
+
|
73
|
+
private XmlNamespace(Ruby runtime, Attr attr, String prefix, IRubyObject prefixRuby,
|
74
|
+
String href, IRubyObject hrefRuby, IRubyObject document) {
|
75
|
+
super(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
|
76
|
+
|
77
|
+
this.attr = attr;
|
78
|
+
this.prefix = prefix;
|
79
|
+
this.href = href;
|
80
|
+
this.prefixRuby = prefixRuby;
|
81
|
+
this.hrefRuby = hrefRuby;
|
82
|
+
setInstanceVariable("@document", document);
|
83
|
+
}
|
84
|
+
|
73
85
|
public Node getNode() {
|
74
86
|
return attr;
|
75
87
|
}
|
76
88
|
|
77
89
|
public String getPrefix() {
|
78
|
-
return
|
90
|
+
return prefix;
|
79
91
|
}
|
80
|
-
|
92
|
+
|
93
|
+
boolean hasPrefix(String prefix) {
|
94
|
+
return prefix == null ? this.prefix == null : prefix.equals(this.prefix);
|
95
|
+
}
|
96
|
+
|
81
97
|
public String getHref() {
|
82
|
-
return
|
98
|
+
return href;
|
83
99
|
}
|
84
100
|
|
85
101
|
void deleteHref() {
|
86
|
-
|
87
|
-
|
102
|
+
href = "http://www.w3.org/XML/1998/namespace";
|
103
|
+
hrefRuby = null;
|
88
104
|
attr.getOwnerElement().removeAttributeNode(attr);
|
89
105
|
}
|
90
|
-
|
91
|
-
public void init(Attr attr, IRubyObject prefix, IRubyObject href, IRubyObject xmlDocument) {
|
92
|
-
init(attr, prefix, href, (String) prefix.toJava(String.class), (String) href.toJava(String.class), xmlDocument);
|
93
|
-
}
|
94
|
-
|
95
|
-
public void init(Attr attr, IRubyObject prefix, IRubyObject href, String prefixString, String hrefString, IRubyObject xmlDocument) {
|
96
|
-
this.attr = attr;
|
97
|
-
this.prefix = prefix;
|
98
|
-
this.href = href;
|
99
|
-
this.prefixString = prefixString;
|
100
|
-
this.hrefString = hrefString;
|
101
|
-
setInstanceVariable("@document", xmlDocument);
|
102
|
-
}
|
103
106
|
|
104
107
|
public static XmlNamespace createFromAttr(Ruby runtime, Attr attr) {
|
105
|
-
String
|
106
|
-
IRubyObject
|
107
|
-
|
108
|
-
prefix_value = runtime.getNil();
|
109
|
-
prefixValue = "";
|
110
|
-
} else {
|
111
|
-
prefix_value = RubyString.newString(runtime, prefixValue);
|
112
|
-
}
|
113
|
-
String hrefValue = attr.getValue();
|
114
|
-
IRubyObject href_value = RubyString.newString(runtime, hrefValue);
|
108
|
+
String prefixStr = getLocalNameForNamespace(attr.getName(), null);
|
109
|
+
IRubyObject prefix = prefixStr == null ? runtime.getNil() : null;
|
110
|
+
String hrefStr = attr.getValue();
|
115
111
|
// check namespace cache
|
116
|
-
XmlDocument xmlDocument = (XmlDocument)getCachedNodeOrCreate(runtime, attr.getOwnerDocument());
|
117
|
-
xmlDocument.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
// creating XmlNamespace instance
|
122
|
-
XmlNamespace namespace =
|
123
|
-
(XmlNamespace) NokogiriService.XML_NAMESPACE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
|
124
|
-
namespace.init(attr, prefix_value, href_value, prefixValue, hrefValue, xmlDocument);
|
125
|
-
|
126
|
-
// updateing namespace cache
|
112
|
+
XmlDocument xmlDocument = (XmlDocument) getCachedNodeOrCreate(runtime, attr.getOwnerDocument());
|
113
|
+
XmlNamespace namespace = xmlDocument.getNamespaceCache().get(prefixStr, hrefStr);
|
114
|
+
if (namespace != null) return namespace;
|
115
|
+
|
116
|
+
namespace = new XmlNamespace(runtime, attr, prefixStr, prefix, hrefStr, null, xmlDocument);
|
127
117
|
xmlDocument.getNamespaceCache().put(namespace, attr.getOwnerElement());
|
128
118
|
return namespace;
|
129
119
|
}
|
130
120
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
Ruby runtime = prefix.getRuntime();
|
121
|
+
static XmlNamespace createImpl(Node owner, IRubyObject prefix, String prefixStr, IRubyObject href, String hrefStr) {
|
122
|
+
final Ruby runtime = prefix.getRuntime();
|
123
|
+
|
135
124
|
Document document = owner.getOwnerDocument();
|
136
|
-
|
137
|
-
|
138
|
-
xmlDocument.
|
139
|
-
XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefixValue, hrefValue);
|
140
|
-
if (xmlNamespace != null) return xmlNamespace;
|
125
|
+
XmlDocument xmlDocument = (XmlDocument) getCachedNodeOrCreate(runtime, document);
|
126
|
+
|
127
|
+
assert xmlDocument.getNamespaceCache().get(prefixStr, hrefStr) == null;
|
141
128
|
|
142
129
|
// creating XmlNamespace instance
|
143
|
-
XmlNamespace namespace =
|
144
|
-
(XmlNamespace) NokogiriService.XML_NAMESPACE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
|
145
130
|
String attrName = "xmlns";
|
146
|
-
if (!
|
147
|
-
|
148
|
-
}
|
131
|
+
if (prefixStr != null && !prefixStr.isEmpty()) attrName = attrName + ':' + prefixStr;
|
132
|
+
|
149
133
|
Attr attrNode = document.createAttribute(attrName);
|
150
|
-
attrNode.setNodeValue(
|
134
|
+
attrNode.setNodeValue(hrefStr);
|
151
135
|
|
152
|
-
|
153
|
-
namespace.init(attrNode, prefix, href, prefixValue, hrefValue, xmlDocument);
|
154
|
-
|
155
|
-
// updating namespace cache
|
136
|
+
XmlNamespace namespace = new XmlNamespace(runtime, attrNode, prefixStr, prefix, hrefStr, href, xmlDocument);
|
156
137
|
xmlDocument.getNamespaceCache().put(namespace, owner);
|
157
138
|
return namespace;
|
158
139
|
}
|
159
140
|
|
160
141
|
// owner should be an Attr node
|
161
142
|
public static XmlNamespace createDefaultNamespace(Ruby runtime, Node owner) {
|
162
|
-
String
|
163
|
-
String
|
164
|
-
Document document = owner.getOwnerDocument();
|
143
|
+
String prefixStr = owner.getPrefix();
|
144
|
+
String hrefStr = owner.getNamespaceURI();
|
165
145
|
// check namespace cache
|
166
|
-
XmlDocument xmlDocument = (XmlDocument)getCachedNodeOrCreate(runtime,
|
167
|
-
XmlNamespace
|
168
|
-
if (
|
146
|
+
XmlDocument xmlDocument = (XmlDocument) getCachedNodeOrCreate(runtime, owner.getOwnerDocument());
|
147
|
+
XmlNamespace namespace = xmlDocument.getNamespaceCache().get(prefixStr, hrefStr);
|
148
|
+
if (namespace != null) return namespace;
|
169
149
|
|
170
|
-
|
171
|
-
XmlNamespace namespace =
|
172
|
-
(XmlNamespace) NokogiriService.XML_NAMESPACE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
|
173
|
-
|
174
|
-
IRubyObject prefix = stringOrNil(runtime, prefixValue);
|
175
|
-
IRubyObject href = stringOrNil(runtime, hrefValue);
|
176
|
-
// initialize XmlNamespace object
|
177
|
-
namespace.init((Attr)owner, prefix, href, prefixValue, hrefValue, xmlDocument);
|
178
|
-
|
179
|
-
// updating namespace cache
|
150
|
+
namespace = new XmlNamespace(runtime, (Attr) owner, prefixStr, hrefStr, xmlDocument);
|
180
151
|
xmlDocument.getNamespaceCache().put(namespace, owner);
|
181
152
|
return namespace;
|
182
153
|
}
|
@@ -192,21 +163,33 @@ public class XmlNamespace extends RubyObject {
|
|
192
163
|
}
|
193
164
|
|
194
165
|
public boolean isEmpty() {
|
195
|
-
return prefix
|
166
|
+
return prefix == null && href == null;
|
196
167
|
}
|
197
168
|
|
198
169
|
@JRubyMethod
|
199
170
|
public IRubyObject href(ThreadContext context) {
|
200
|
-
|
171
|
+
if (hrefRuby == null) {
|
172
|
+
if (href == null) return hrefRuby = context.nil;
|
173
|
+
return hrefRuby = context.runtime.newString(href);
|
174
|
+
}
|
175
|
+
return hrefRuby;
|
201
176
|
}
|
202
177
|
|
203
178
|
@JRubyMethod
|
204
179
|
public IRubyObject prefix(ThreadContext context) {
|
205
|
-
|
180
|
+
if (prefixRuby == null) {
|
181
|
+
if (prefix == null) return prefixRuby = context.nil;
|
182
|
+
return prefixRuby = context.runtime.newString(prefix);
|
183
|
+
}
|
184
|
+
return prefixRuby;
|
206
185
|
}
|
207
186
|
|
208
187
|
public void accept(ThreadContext context, SaveContextVisitor visitor) {
|
209
|
-
String
|
188
|
+
String prefix = this.prefix;
|
189
|
+
if (prefix == null) prefix = "";
|
190
|
+
String href = this.href;
|
191
|
+
if (href == null) href = "";
|
192
|
+
String string = ' ' + prefix + '=' + '"' + href + '"';
|
210
193
|
visitor.enter(string);
|
211
194
|
visitor.leave(string);
|
212
195
|
// is below better?
|