nokogiri 1.10.9-java → 1.11.0.rc4-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.

Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +1015 -947
  3. data/README.md +24 -22
  4. data/ext/java/nokogiri/HtmlDocument.java +34 -46
  5. data/ext/java/nokogiri/HtmlSaxParserContext.java +88 -58
  6. data/ext/java/nokogiri/HtmlSaxPushParser.java +1 -1
  7. data/ext/java/nokogiri/NokogiriService.java +1 -1
  8. data/ext/java/nokogiri/XmlAttr.java +13 -20
  9. data/ext/java/nokogiri/XmlAttributeDecl.java +11 -12
  10. data/ext/java/nokogiri/XmlCdata.java +3 -4
  11. data/ext/java/nokogiri/XmlComment.java +1 -1
  12. data/ext/java/nokogiri/XmlDocument.java +148 -175
  13. data/ext/java/nokogiri/XmlDocumentFragment.java +13 -31
  14. data/ext/java/nokogiri/XmlDtd.java +5 -8
  15. data/ext/java/nokogiri/XmlElement.java +1 -20
  16. data/ext/java/nokogiri/XmlElementDecl.java +23 -28
  17. data/ext/java/nokogiri/XmlEntityDecl.java +23 -27
  18. data/ext/java/nokogiri/XmlEntityReference.java +2 -2
  19. data/ext/java/nokogiri/XmlNamespace.java +72 -89
  20. data/ext/java/nokogiri/XmlNode.java +303 -406
  21. data/ext/java/nokogiri/XmlNodeSet.java +70 -76
  22. data/ext/java/nokogiri/XmlReader.java +12 -13
  23. data/ext/java/nokogiri/XmlRelaxng.java +10 -3
  24. data/ext/java/nokogiri/XmlSaxParserContext.java +15 -10
  25. data/ext/java/nokogiri/XmlSchema.java +87 -27
  26. data/ext/java/nokogiri/XmlSyntaxError.java +2 -6
  27. data/ext/java/nokogiri/XmlText.java +12 -9
  28. data/ext/java/nokogiri/XmlXpathContext.java +55 -25
  29. data/ext/java/nokogiri/XsltStylesheet.java +7 -15
  30. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +52 -46
  31. data/ext/java/nokogiri/internals/NokogiriHandler.java +1 -1
  32. data/ext/java/nokogiri/internals/NokogiriHelpers.java +71 -135
  33. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +90 -58
  34. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +9 -2
  35. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +67 -10
  36. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +4 -2
  37. data/ext/java/nokogiri/internals/ParserContext.java +27 -73
  38. data/ext/java/nokogiri/internals/ReaderNode.java +2 -4
  39. data/ext/java/nokogiri/internals/XmlDomParserContext.java +18 -33
  40. data/ext/nokogiri/depend +476 -357
  41. data/ext/nokogiri/extconf.rb +485 -352
  42. data/ext/nokogiri/html_document.c +79 -78
  43. data/ext/nokogiri/html_sax_parser_context.c +2 -2
  44. data/ext/nokogiri/nokogiri.c +34 -40
  45. data/ext/nokogiri/xml_document.c +18 -4
  46. data/ext/nokogiri/xml_io.c +8 -6
  47. data/ext/nokogiri/xml_node.c +21 -1
  48. data/ext/nokogiri/xml_node_set.c +1 -1
  49. data/ext/nokogiri/xml_reader.c +6 -17
  50. data/ext/nokogiri/xml_relax_ng.c +29 -11
  51. data/ext/nokogiri/xml_sax_parser.c +2 -7
  52. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  53. data/ext/nokogiri/xml_schema.c +55 -13
  54. data/ext/nokogiri/xml_xpath_context.c +80 -4
  55. data/ext/nokogiri/xslt_stylesheet.c +1 -8
  56. data/lib/nokogiri.rb +4 -21
  57. data/lib/nokogiri/css.rb +1 -0
  58. data/lib/nokogiri/css/node.rb +1 -0
  59. data/lib/nokogiri/css/parser.rb +63 -62
  60. data/lib/nokogiri/css/parser.y +2 -2
  61. data/lib/nokogiri/css/parser_extras.rb +39 -36
  62. data/lib/nokogiri/css/syntax_error.rb +1 -0
  63. data/lib/nokogiri/css/tokenizer.rb +1 -0
  64. data/lib/nokogiri/css/xpath_visitor.rb +73 -43
  65. data/lib/nokogiri/decorators/slop.rb +1 -0
  66. data/lib/nokogiri/html.rb +1 -0
  67. data/lib/nokogiri/html/builder.rb +1 -0
  68. data/lib/nokogiri/html/document.rb +13 -26
  69. data/lib/nokogiri/html/document_fragment.rb +1 -0
  70. data/lib/nokogiri/html/element_description.rb +1 -0
  71. data/lib/nokogiri/html/element_description_defaults.rb +1 -0
  72. data/lib/nokogiri/html/entity_lookup.rb +1 -0
  73. data/lib/nokogiri/html/sax/parser.rb +1 -0
  74. data/lib/nokogiri/html/sax/parser_context.rb +1 -0
  75. data/lib/nokogiri/html/sax/push_parser.rb +1 -0
  76. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  77. data/lib/nokogiri/nokogiri.jar +0 -0
  78. data/lib/nokogiri/syntax_error.rb +1 -0
  79. data/lib/nokogiri/version.rb +3 -109
  80. data/lib/nokogiri/version/constant.rb +5 -0
  81. data/lib/nokogiri/version/info.rb +182 -0
  82. data/lib/nokogiri/xml.rb +1 -0
  83. data/lib/nokogiri/xml/attr.rb +1 -0
  84. data/lib/nokogiri/xml/attribute_decl.rb +1 -0
  85. data/lib/nokogiri/xml/builder.rb +3 -2
  86. data/lib/nokogiri/xml/cdata.rb +1 -0
  87. data/lib/nokogiri/xml/character_data.rb +1 -0
  88. data/lib/nokogiri/xml/document.rb +20 -15
  89. data/lib/nokogiri/xml/document_fragment.rb +5 -6
  90. data/lib/nokogiri/xml/dtd.rb +1 -0
  91. data/lib/nokogiri/xml/element_content.rb +1 -0
  92. data/lib/nokogiri/xml/element_decl.rb +1 -0
  93. data/lib/nokogiri/xml/entity_decl.rb +1 -0
  94. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  95. data/lib/nokogiri/xml/namespace.rb +1 -0
  96. data/lib/nokogiri/xml/node.rb +587 -249
  97. data/lib/nokogiri/xml/node/save_options.rb +1 -0
  98. data/lib/nokogiri/xml/node_set.rb +1 -0
  99. data/lib/nokogiri/xml/notation.rb +1 -0
  100. data/lib/nokogiri/xml/parse_options.rb +10 -3
  101. data/lib/nokogiri/xml/pp.rb +1 -0
  102. data/lib/nokogiri/xml/pp/character_data.rb +1 -0
  103. data/lib/nokogiri/xml/pp/node.rb +1 -0
  104. data/lib/nokogiri/xml/processing_instruction.rb +1 -0
  105. data/lib/nokogiri/xml/reader.rb +7 -3
  106. data/lib/nokogiri/xml/relax_ng.rb +7 -2
  107. data/lib/nokogiri/xml/sax.rb +1 -0
  108. data/lib/nokogiri/xml/sax/document.rb +1 -0
  109. data/lib/nokogiri/xml/sax/parser.rb +1 -0
  110. data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
  111. data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
  112. data/lib/nokogiri/xml/schema.rb +13 -4
  113. data/lib/nokogiri/xml/searchable.rb +25 -16
  114. data/lib/nokogiri/xml/syntax_error.rb +1 -0
  115. data/lib/nokogiri/xml/text.rb +1 -0
  116. data/lib/nokogiri/xml/xpath.rb +1 -0
  117. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
  118. data/lib/nokogiri/xml/xpath_context.rb +1 -0
  119. data/lib/nokogiri/xslt.rb +1 -0
  120. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  121. data/lib/xsd/xmlparser/nokogiri.rb +1 -0
  122. metadata +89 -96
  123. data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +0 -107
  124. data/ext/java/nokogiri/internals/UncloseableInputStream.java +0 -102
  125. data/ext/nokogiri/html_document.h +0 -10
  126. data/ext/nokogiri/html_element_description.h +0 -10
  127. data/ext/nokogiri/html_entity_lookup.h +0 -8
  128. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  129. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  130. data/ext/nokogiri/nokogiri.h +0 -121
  131. data/ext/nokogiri/xml_attr.h +0 -9
  132. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  133. data/ext/nokogiri/xml_cdata.h +0 -9
  134. data/ext/nokogiri/xml_comment.h +0 -9
  135. data/ext/nokogiri/xml_document.h +0 -23
  136. data/ext/nokogiri/xml_document_fragment.h +0 -10
  137. data/ext/nokogiri/xml_dtd.h +0 -10
  138. data/ext/nokogiri/xml_element_content.h +0 -10
  139. data/ext/nokogiri/xml_element_decl.h +0 -9
  140. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  141. data/ext/nokogiri/xml_entity_decl.h +0 -10
  142. data/ext/nokogiri/xml_entity_reference.h +0 -9
  143. data/ext/nokogiri/xml_io.h +0 -11
  144. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  145. data/ext/nokogiri/xml_namespace.h +0 -14
  146. data/ext/nokogiri/xml_node.h +0 -13
  147. data/ext/nokogiri/xml_node_set.h +0 -12
  148. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  149. data/ext/nokogiri/xml_reader.h +0 -10
  150. data/ext/nokogiri/xml_relax_ng.h +0 -9
  151. data/ext/nokogiri/xml_sax_parser.h +0 -39
  152. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  153. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  154. data/ext/nokogiri/xml_schema.h +0 -9
  155. data/ext/nokogiri/xml_syntax_error.h +0 -13
  156. data/ext/nokogiri/xml_text.h +0 -9
  157. data/ext/nokogiri/xml_xpath_context.h +0 -10
  158. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -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
- private XmlElement fragmentContext = null;
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
- if(args.length < 1) {
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.getRuntime().newArgumentError("first parameter must be a Nokogiri::XML::Document instance");
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
- if (XmlDocumentFragment.isTag((RubyString)args[1])) {
93
- args[1] = RubyString.newString(context.getRuntime(), addNamespaceDeclIfNeeded(doc, rubyStringToString(args[1])));
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.getRuntime(), (RubyClass)cls);
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
- ((XmlNodeSet) children(context)).relink_namespace(context);
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.getRuntime();
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.newXmlNodeSet(context, extractDecls(context, node.getFirstChild()));
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 = (XmlAttributeDecl)
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 = (XmlElementDecl)
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 = (XmlEntityDecl)
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
- XmlNodeSet xmlNodeSet = (XmlNodeSet) children(context);
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 ruby, RubyClass klazz) {
60
- super(ruby, klazz);
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
- public static IRubyObject create(ThreadContext context, Node elemDeclNode) {
80
- XmlElementDecl self =
81
- new XmlElementDecl(context.getRuntime(),
82
- getNokogiriClass(context.getRuntime(), "Nokogiri::XML::ElementDecl"),
83
- elemDeclNode);
84
- return self;
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
- return context.getRuntime().getNil();
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.getRuntime().newString(ename);
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.getRuntime()
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.getRuntime()
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.getRuntime().newFixnum(node.getNodeType());
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
- public XmlEntityDecl(Ruby ruby, RubyClass klass) {
68
- super(ruby, klass);
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 ruby, RubyClass klass, Node entDeclNode) {
77
- super(ruby, klass, entDeclNode);
78
- entityType = RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL);
79
- name = external_id = system_id = content = ruby.getNil();
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 ruby, RubyClass klass, Node entDeclNode, IRubyObject[] argv) {
83
- super(ruby, klass, entDeclNode);
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(ruby, XmlEntityDecl.INTERNAL_GENERAL);
86
- external_id = system_id = content = ruby.getNil();
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
- public static IRubyObject create(ThreadContext context, Node entDeclNode) {
96
- XmlEntityDecl self =
97
- new XmlEntityDecl(context.getRuntime(),
98
- getNokogiriClass(context.getRuntime(), "Nokogiri::XML::EntityDecl"),
99
- entDeclNode);
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
- public static IRubyObject create(ThreadContext context, Node entDeclNode, IRubyObject[] argv) {
105
- XmlEntityDecl self =
106
- new XmlEntityDecl(context.getRuntime(),
107
- getNokogiriClass(context.getRuntime(), "Nokogiri::XML::EntityDecl"),
108
- entDeclNode, argv);
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.getRuntime()
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 getRuntime().newArgumentError(args.length, 2);
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 prefix;
65
- private IRubyObject href;
66
- private String prefixString;
67
- private String hrefString;
60
+ private transient IRubyObject prefixRuby;
61
+ private transient IRubyObject hrefRuby;
62
+ private String prefix;
63
+ private String href;
68
64
 
69
- public XmlNamespace(Ruby ruby, RubyClass klazz) {
70
- super(ruby, klazz);
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 prefixString;
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 hrefString;
98
+ return href;
83
99
  }
84
100
 
85
101
  void deleteHref() {
86
- hrefString = "http://www.w3.org/XML/1998/namespace";
87
- href = NokogiriHelpers.stringOrNil(getRuntime(), hrefString);
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 prefixValue = getLocalNameForNamespace(attr.getName());
106
- IRubyObject prefix_value;
107
- if (prefixValue == null) {
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.initializeNamespaceCacheIfNecessary();
118
- XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefixValue, hrefValue);
119
- if (xmlNamespace != null) return xmlNamespace;
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
- public static XmlNamespace createFromPrefixAndHref(Node owner, IRubyObject prefix, IRubyObject href) {
132
- String prefixValue = prefix.isNil() ? "" : (String) prefix.toJava(String.class);
133
- String hrefValue = (String) href.toJava(String.class);
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
- // check namespace cache
137
- XmlDocument xmlDocument = (XmlDocument)getCachedNodeOrCreate(runtime, document);
138
- xmlDocument.initializeNamespaceCacheIfNecessary();
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 (!"".equals(prefixValue)) {
147
- attrName = attrName + ":" + prefixValue;
148
- }
131
+ if (prefixStr != null && !prefixStr.isEmpty()) attrName = attrName + ':' + prefixStr;
132
+
149
133
  Attr attrNode = document.createAttribute(attrName);
150
- attrNode.setNodeValue(hrefValue);
134
+ attrNode.setNodeValue(hrefStr);
151
135
 
152
- // initialize XmlNamespace object
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 prefixValue = owner.getPrefix();
163
- String hrefValue = owner.getNamespaceURI();
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, document);
167
- XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefixValue, hrefValue);
168
- if (xmlNamespace != null) return xmlNamespace;
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
- // creating XmlNamespace instance
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.isNil() && href.isNil();
166
+ return prefix == null && href == null;
196
167
  }
197
168
 
198
169
  @JRubyMethod
199
170
  public IRubyObject href(ThreadContext context) {
200
- return href;
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
- return prefix;
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 string = " " + prefix + "=\"" + href + "\"";
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?