nokogiri 1.5.0.beta.3-java → 1.5.0.beta.4-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 (88) hide show
  1. data/CHANGELOG.ja.rdoc +32 -16
  2. data/CHANGELOG.rdoc +18 -0
  3. data/Manifest.txt +1 -2
  4. data/README.rdoc +27 -3
  5. data/Rakefile +39 -83
  6. data/ext/java/nokogiri/EncodingHandler.java +1 -1
  7. data/ext/java/nokogiri/HtmlDocument.java +11 -14
  8. data/ext/java/nokogiri/HtmlElementDescription.java +1 -1
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +1 -1
  10. data/ext/java/nokogiri/HtmlSaxParserContext.java +13 -10
  11. data/ext/java/nokogiri/NokogiriService.java +103 -34
  12. data/ext/java/nokogiri/XmlAttr.java +14 -6
  13. data/ext/java/nokogiri/XmlAttributeDecl.java +1 -1
  14. data/ext/java/nokogiri/XmlCdata.java +3 -1
  15. data/ext/java/nokogiri/XmlComment.java +3 -1
  16. data/ext/java/nokogiri/XmlDocument.java +29 -8
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +14 -13
  18. data/ext/java/nokogiri/XmlDtd.java +5 -2
  19. data/ext/java/nokogiri/XmlElement.java +2 -1
  20. data/ext/java/nokogiri/XmlElementContent.java +1 -1
  21. data/ext/java/nokogiri/XmlElementDecl.java +2 -1
  22. data/ext/java/nokogiri/XmlEntityDecl.java +2 -1
  23. data/ext/java/nokogiri/XmlEntityReference.java +1 -1
  24. data/ext/java/nokogiri/XmlNamespace.java +3 -2
  25. data/ext/java/nokogiri/XmlNode.java +17 -10
  26. data/ext/java/nokogiri/XmlNodeSet.java +40 -13
  27. data/ext/java/nokogiri/XmlProcessingInstruction.java +1 -1
  28. data/ext/java/nokogiri/XmlReader.java +3 -1
  29. data/ext/java/nokogiri/XmlRelaxng.java +37 -92
  30. data/ext/java/nokogiri/XmlSaxParserContext.java +25 -11
  31. data/ext/java/nokogiri/XmlSaxPushParser.java +6 -4
  32. data/ext/java/nokogiri/XmlSchema.java +190 -46
  33. data/ext/java/nokogiri/XmlSyntaxError.java +42 -37
  34. data/ext/java/nokogiri/XmlText.java +3 -2
  35. data/ext/java/nokogiri/XmlXpathContext.java +8 -4
  36. data/ext/java/nokogiri/XsltStylesheet.java +12 -10
  37. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +8 -7
  38. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +1 -1
  39. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +11 -5
  40. data/ext/java/nokogiri/internals/NokogiriHandler.java +36 -9
  41. data/ext/java/nokogiri/internals/NokogiriHelpers.java +21 -22
  42. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +5 -4
  43. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +1 -1
  44. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +2 -1
  45. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +1 -1
  46. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +2 -1
  47. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +15 -9
  48. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +1 -1
  49. data/ext/java/nokogiri/internals/ParserContext.java +18 -7
  50. data/ext/java/nokogiri/internals/PushInputStream.java +1 -1
  51. data/ext/java/nokogiri/internals/ReaderNode.java +7 -6
  52. data/ext/java/nokogiri/internals/SaveContext.java +16 -10
  53. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +13 -5
  54. data/ext/java/nokogiri/internals/XmlDeclHandler.java +1 -1
  55. data/ext/java/nokogiri/internals/XmlDomParser.java +1 -1
  56. data/ext/java/nokogiri/internals/XmlDomParserContext.java +13 -8
  57. data/ext/java/nokogiri/internals/XmlSaxParser.java +1 -1
  58. data/ext/java/nokogiri/internals/XsltExtensionFunction.java +1 -1
  59. data/ext/nokogiri/extconf.rb +3 -3
  60. data/ext/nokogiri/xml_document.c +9 -0
  61. data/ext/nokogiri/xml_sax_parser.c +4 -2
  62. data/lib/nokogiri.rb +9 -6
  63. data/lib/nokogiri/css.rb +1 -3
  64. data/lib/nokogiri/css/parser.rb +665 -70
  65. data/lib/nokogiri/css/parser.y +3 -1
  66. data/lib/nokogiri/css/parser_extras.rb +91 -0
  67. data/lib/nokogiri/css/tokenizer.rb +148 -3
  68. data/lib/nokogiri/css/tokenizer.rex +1 -1
  69. data/lib/nokogiri/html/document.rb +138 -11
  70. data/lib/nokogiri/html/sax/parser.rb +6 -2
  71. data/lib/nokogiri/nokogiri.jar +0 -0
  72. data/lib/nokogiri/version.rb +1 -1
  73. data/lib/nokogiri/xml/node.rb +2 -2
  74. data/lib/nokogiri/xml/node/save_options.rb +3 -0
  75. data/lib/nokogiri/xml/node_set.rb +1 -1
  76. data/test/css/test_tokenizer.rb +8 -0
  77. data/test/helper.rb +2 -0
  78. data/test/html/sax/test_parser.rb +43 -0
  79. data/test/html/test_document.rb +59 -0
  80. data/test/html/test_document_encoding.rb +48 -0
  81. data/test/html/test_element_description.rb +1 -1
  82. data/test/xml/sax/test_parser.rb +16 -0
  83. data/test/xml/test_document.rb +3 -1
  84. data/test/xml/test_node.rb +4 -1
  85. data/test/xml/test_node_set.rb +10 -0
  86. metadata +73 -82
  87. data/lib/nokogiri/css/generated_parser.rb +0 -676
  88. data/lib/nokogiri/css/generated_tokenizer.rb +0 -145
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -42,7 +42,6 @@ import org.jruby.Ruby;
42
42
  import org.jruby.RubyClass;
43
43
  import org.jruby.anno.JRubyClass;
44
44
  import org.jruby.anno.JRubyMethod;
45
- import org.jruby.javasupport.JavaUtil;
46
45
  import org.jruby.runtime.ThreadContext;
47
46
  import org.jruby.runtime.builtin.IRubyObject;
48
47
  import org.w3c.dom.Document;
@@ -51,6 +50,8 @@ import org.w3c.dom.Node;
51
50
  /**
52
51
  * Class for Nokogiri::XML::Text
53
52
  *
53
+ * @author sergio
54
+ * @author Yoko Harada <yokolet@gmail.com>
54
55
  */
55
56
  @JRubyClass(name="Nokogiri::XML::Text", parent="Nokogiri::XML::CharacterData")
56
57
  public class XmlText extends XmlNode {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -32,6 +32,8 @@
32
32
 
33
33
  package nokogiri;
34
34
 
35
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
+
35
37
  import java.util.Set;
36
38
  import java.util.regex.Matcher;
37
39
  import java.util.regex.Pattern;
@@ -63,6 +65,8 @@ import org.w3c.dom.NodeList;
63
65
  /**
64
66
  * Class for Nokogiri::XML::XpathContext
65
67
  *
68
+ * @author sergio
69
+ * @author Yoko Harada <yokolet@gmail.com>
66
70
  */
67
71
  @JRubyClass(name="Nokogiri::XML::XPathContext")
68
72
  public class XmlXpathContext extends RubyObject {
@@ -98,7 +102,6 @@ public class XmlXpathContext extends RubyObject {
98
102
  }
99
103
  XPathExpression xpathExpression = xpath.compile(src);
100
104
  return node_set(context, xpathExpression);
101
- //return new XmlXpath(context.getRuntime(), (RubyClass)context.getRuntime().getClassFromPath("Nokogiri::XML::XPath"), xpathExpression, this.context);
102
105
  } catch (XPathExpressionException xpee) {
103
106
  xpee = new XPathExpressionException(src);
104
107
  RubyException e =
@@ -111,7 +114,6 @@ public class XmlXpathContext extends RubyObject {
111
114
  XmlNodeSet result = null;
112
115
  try {
113
116
  result = tryGetNodeSet(xpathExpression);
114
- // result.relink_namespace(context);
115
117
  result.setDocument(context.document(rbctx));
116
118
  return result;
117
119
  } catch (XPathExpressionException xpee) {
@@ -126,7 +128,9 @@ public class XmlXpathContext extends RubyObject {
126
128
 
127
129
  private XmlNodeSet tryGetNodeSet(XPathExpression xpathExpression) throws XPathExpressionException {
128
130
  NodeList nodes = (NodeList)xpathExpression.evaluate(context.node, XPathConstants.NODESET);
129
- return new XmlNodeSet(getRuntime(), nodes);
131
+ XmlNodeSet xmlNodeSet = (XmlNodeSet) NokogiriService.XML_NODESET_ALLOCATOR.allocate(getRuntime(), getNokogiriClass(getRuntime(), "Nokogiri::XML::NodeSet"));
132
+ xmlNodeSet.setNodeList(nodes);
133
+ return xmlNodeSet;
130
134
  }
131
135
 
132
136
  private static Pattern number_pattern = Pattern.compile("\\d.*");
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -61,6 +61,8 @@ import org.w3c.dom.Document;
61
61
  /**
62
62
  * Class for Nokogiri::XSLT::Stylesheet
63
63
  *
64
+ * @author sergio
65
+ * @author Yoko Harada <yokolet@gmail.com>
64
66
  */
65
67
  @JRubyClass(name="Nokogiri::XSLT::Stylesheet")
66
68
  public class XsltStylesheet extends RubyObject {
@@ -140,7 +142,7 @@ public class XsltStylesheet extends RubyObject {
140
142
 
141
143
  @JRubyMethod(rest = true, required=1, optional=2)
142
144
  public IRubyObject transform(ThreadContext context, IRubyObject[] args) {
143
- Ruby ruby = context.getRuntime();
145
+ Ruby runtime = context.getRuntime();
144
146
 
145
147
  DOMSource docSource = new DOMSource(((XmlDocument) args[0]).getDocument());
146
148
  DOMResult result = new DOMResult();
@@ -152,19 +154,19 @@ public class XsltStylesheet extends RubyObject {
152
154
  }
153
155
  transf.transform(docSource, result);
154
156
  } catch(TransformerConfigurationException ex) {
155
- throw ruby.newRuntimeError("Could not transform the document.");
157
+ throw runtime.newRuntimeError("Could not transform the document.");
156
158
  } catch(TransformerException ex) {
157
- throw ruby.newRuntimeError("Could not transform the document.");
159
+ throw runtime.newRuntimeError("Could not transform the document.");
158
160
  }
159
161
 
160
162
  if ("html".equals(result.getNode().getFirstChild().getNodeName())) {
161
- return new HtmlDocument(ruby,
162
- getNokogiriClass(ruby, "Nokogiri::HTML::Document"),
163
- (Document) result.getNode());
163
+ HtmlDocument htmlDocument = (HtmlDocument) getNokogiriClass(runtime, "Nokogiri::HTML::Document").allocate();
164
+ htmlDocument.setNode(context, (Document) result.getNode());
165
+ return htmlDocument;
164
166
  } else {
165
- return new XmlDocument(ruby,
166
- getNokogiriClass(ruby, "Nokogiri::XML::Document"),
167
- (Document) result.getNode());
167
+ XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"));
168
+ xmlDocument.setNode(context, (Document) result.getNode());
169
+ return xmlDocument;
168
170
  }
169
171
  }
170
172
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -35,6 +35,7 @@ package nokogiri.internals;
35
35
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
36
  import static nokogiri.internals.NokogiriHelpers.isNamespace;
37
37
  import nokogiri.HtmlDocument;
38
+ import nokogiri.NokogiriService;
38
39
  import nokogiri.XmlDocument;
39
40
 
40
41
  import org.apache.xerces.parsers.DOMParser;
@@ -56,6 +57,7 @@ import org.w3c.dom.Document;
56
57
  * Parser for HtmlDocument. This class actually parses HtmlDocument using NekoHtml.
57
58
  *
58
59
  * @author sergio
60
+ * @author Yoko Harada <yokolet@gmail.com>
59
61
  */
60
62
  public class HtmlDomParserContext extends XmlDomParserContext {
61
63
 
@@ -108,16 +110,15 @@ public class HtmlDomParserContext extends XmlDomParserContext {
108
110
  @Override
109
111
  protected XmlDocument getNewEmptyDocument(ThreadContext context) {
110
112
  IRubyObject[] args = new IRubyObject[0];
111
- return (XmlDocument) XmlDocument.rbNew(context,
112
- getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::Document"),
113
- args);
113
+ return (XmlDocument) XmlDocument.rbNew(context, getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::Document"), args);
114
114
  }
115
115
 
116
116
  @Override
117
117
  protected XmlDocument wrapDocument(ThreadContext context,
118
- RubyClass klass,
119
- Document doc) {
120
- HtmlDocument htmlDocument = new HtmlDocument(context.getRuntime(), klass, doc);
118
+ RubyClass klazz,
119
+ Document document) {
120
+ HtmlDocument htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
121
+ htmlDocument.setNode(context, document);
121
122
  htmlDocument.setEncoding(ruby_encoding);
122
123
  return htmlDocument;
123
124
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -32,9 +32,12 @@
32
32
 
33
33
  package nokogiri.internals;
34
34
 
35
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
+
35
37
  import java.util.ArrayList;
36
38
  import java.util.List;
37
39
 
40
+ import nokogiri.NokogiriService;
38
41
  import nokogiri.XmlSyntaxError;
39
42
 
40
43
  import org.apache.xerces.xni.parser.XMLErrorHandler;
@@ -50,6 +53,7 @@ import org.xml.sax.ErrorHandler;
50
53
  * uses this type of the error handler.
51
54
  *
52
55
  * @author sergio
56
+ * @author Yoko Harada <yokolet@gmail.com>
53
57
  */
54
58
  public abstract class NokogiriErrorHandler implements ErrorHandler, XMLErrorHandler {
55
59
  protected List<Exception> errors;
@@ -64,11 +68,13 @@ public abstract class NokogiriErrorHandler implements ErrorHandler, XMLErrorHand
64
68
 
65
69
  public List<Exception> getErrors() { return errors; }
66
70
 
67
- public List<IRubyObject> getErrorsReadyForRuby(ThreadContext context){
68
- Ruby ruby = context.getRuntime();
71
+ public List<IRubyObject> getErrorsReadyForRuby(ThreadContext context) {
72
+ Ruby runtime = context.getRuntime();
69
73
  List<IRubyObject> res = new ArrayList<IRubyObject>();
70
- for(int i = 0; i < errors.size(); i++) {
71
- res.add(new XmlSyntaxError(ruby, errors.get(i)));
74
+ for (int i = 0; i < errors.size(); i++) {
75
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
76
+ xmlSyntaxError.setException(errors.get(i));
77
+ res.add(xmlSyntaxError);
72
78
  }
73
79
  return res;
74
80
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -59,6 +59,7 @@ import org.xml.sax.ext.DefaultHandler2;
59
59
  * A handler for SAX parsing.
60
60
  *
61
61
  * @author sergio
62
+ * @author Yoko Harada <yokolet@gmail.com>
62
63
  */
63
64
  public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
64
65
 
@@ -79,13 +80,17 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
79
80
  private Locator locator;
80
81
  private ArrayDeque<Integer> lines;
81
82
  private ArrayDeque<Integer> columns;
83
+ private static String htmlParserName = "Nokogiri::HTML::SAX::Parser";
84
+ private boolean needEmptyAttrCheck = false;
82
85
 
83
- public NokogiriHandler(Ruby ruby, IRubyObject object) {
84
- this.ruby = ruby;
85
- this.attrClass = (RubyClass) ruby.getClassFromPath("Nokogiri::XML::SAX::Parser::Attribute");
86
+ public NokogiriHandler(Ruby runtime, IRubyObject object) {
87
+ this.ruby = runtime;
88
+ this.attrClass = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SAX::Parser::Attribute");
86
89
  this.object = object;
87
90
  lines = new ArrayDeque<Integer>();
88
91
  columns = new ArrayDeque<Integer>();
92
+ String objectName = object.getMetaClass().getName();
93
+ if (htmlParserName.equals(objectName)) needEmptyAttrCheck = true;
89
94
  }
90
95
 
91
96
  public void setDocumentLocator(Locator locator) {
@@ -150,11 +155,22 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
150
155
  ns.add(ruby.newString(val));
151
156
  rubyNSAttr.add(ns);
152
157
  } else {
153
- IRubyObject[] args = new IRubyObject[4];
154
- args[0] = stringOrNil(ruby, ln);
155
- args[1] = stringOrNil(ruby, pre);
156
- args[2] = stringOrNil(ruby, u);
157
- args[3] = stringOrNil(ruby, val);
158
+ IRubyObject[] args = null;
159
+ if (needEmptyAttrCheck) {
160
+ if (isEmptyAttr(ln)) {
161
+ args = new IRubyObject[3];
162
+ args[0] = stringOrNil(ruby, ln);
163
+ args[1] = stringOrNil(ruby, pre);
164
+ args[2] = stringOrNil(ruby, u);
165
+ }
166
+ }
167
+ if (args == null) {
168
+ args = new IRubyObject[4];
169
+ args[0] = stringOrNil(ruby, ln);
170
+ args[1] = stringOrNil(ruby, pre);
171
+ args[2] = stringOrNil(ruby, u);
172
+ args[3] = stringOrNil(ruby, val);
173
+ }
158
174
 
159
175
  IRubyObject attr = RuntimeHelpers.invoke(context, attrClass, "new", args);
160
176
  rubyAttr.add(attr);
@@ -170,6 +186,17 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
170
186
  rubyNSAttr);
171
187
  }
172
188
 
189
+ private static String[] emptyAttrs =
190
+ {"checked", "compact", "declare", "defer", "disabled", "ismap", "multiple",
191
+ "noresize", "nohref", "noshade", "nowrap", "readonly", "selected"};
192
+
193
+ private boolean isEmptyAttr(String name) {
194
+ for (String emptyAttr : emptyAttrs) {
195
+ if (emptyAttr.equals(name)) return true;
196
+ }
197
+ return false;
198
+ }
199
+
173
200
  public Integer getLine() {
174
201
  return lines.pop();
175
202
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -50,7 +50,6 @@ import org.jruby.Ruby;
50
50
  import org.jruby.RubyArray;
51
51
  import org.jruby.RubyClass;
52
52
  import org.jruby.RubyEncoding;
53
- import org.jruby.RubyHash;
54
53
  import org.jruby.RubyString;
55
54
  import org.jruby.runtime.builtin.IRubyObject;
56
55
  import org.jruby.util.ByteList;
@@ -63,6 +62,8 @@ import org.w3c.dom.NodeList;
63
62
  * A class for various utility methods.
64
63
  *
65
64
  * @author serabe
65
+ * @author Patrick Mahoney <pat@polycrystal.org>
66
+ * @author Yoko Harada <yokolet@gmail.com>
66
67
  */
67
68
  public class NokogiriHelpers {
68
69
  public static final String CACHED_NODE = "NOKOGIRI_CACHED_NODE";
@@ -103,47 +104,45 @@ public class NokogiriHelpers {
103
104
  * subclass of XmlNode is chosen based on the type of
104
105
  * <code>node</code>.
105
106
  */
106
- public static IRubyObject constructNode(Ruby ruby, Node node) {
107
- if (node == null) return ruby.getNil();
107
+ public static IRubyObject constructNode(Ruby runtime, Node node) {
108
+ if (node == null) return runtime.getNil();
108
109
  // this is slow; need a way to cache nokogiri classes/modules somewhere
109
110
  switch (node.getNodeType()) {
110
111
  case Node.ELEMENT_NODE:
111
- XmlElement xmlElement = (XmlElement) getNokogiriClass(ruby, "Nokogiri::XML::Element").allocate();
112
- xmlElement.setNode(ruby.getCurrentContext(), node);
112
+ XmlElement xmlElement = (XmlElement) NokogiriService.XML_ELEMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Element"));
113
+ xmlElement.setNode(runtime.getCurrentContext(), node);
113
114
  return xmlElement;
114
115
  case Node.ATTRIBUTE_NODE:
115
- XmlAttr xmlAttr = (XmlAttr) getNokogiriClass(ruby, "Nokogiri::XML::Attr").allocate();
116
- xmlAttr.setNode(ruby.getCurrentContext(), node);
116
+ XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Attr"));
117
+ xmlAttr.setNode(runtime.getCurrentContext(), node);
117
118
  return xmlAttr;
118
119
  case Node.TEXT_NODE:
119
- XmlText xmlText = (XmlText) getNokogiriClass(ruby, "Nokogiri::XML::Text").allocate();
120
- xmlText.setNode(ruby.getCurrentContext(), node);
120
+ XmlText xmlText = (XmlText) NokogiriService.XML_TEXT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Text"));
121
+ xmlText.setNode(runtime.getCurrentContext(), node);
121
122
  return xmlText;
122
123
  case Node.COMMENT_NODE:
123
- XmlComment xmlComment = (XmlComment) getNokogiriClass(ruby, "Nokogiri::XML::Comment").allocate();
124
- xmlComment.setNode(ruby.getCurrentContext(), node);
124
+ XmlComment xmlComment = (XmlComment) NokogiriService.XML_COMMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Comment"));
125
+ xmlComment.setNode(runtime.getCurrentContext(), node);
125
126
  return xmlComment;
126
127
  case Node.ENTITY_NODE:
127
- return new XmlNode(ruby, getNokogiriClass(ruby, "Nokogiri::XML::EntityDecl"), node);
128
+ return new XmlNode(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityDecl"), node);
128
129
  case Node.CDATA_SECTION_NODE:
129
- XmlCdata xmlCdata = (XmlCdata) getNokogiriClass(ruby, "Nokogiri::XML::CDATA").allocate();
130
- xmlCdata.setNode(ruby.getCurrentContext(), node);
130
+ XmlCdata xmlCdata = (XmlCdata) NokogiriService.XML_CDATA_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::CDATA"));
131
+ xmlCdata.setNode(runtime.getCurrentContext(), node);
131
132
  return xmlCdata;
132
133
  case Node.DOCUMENT_NODE:
133
- XmlDocument xmlDocument = (XmlDocument) getNokogiriClass(ruby, "Nokogiri::XML::Document").allocate();
134
- xmlDocument.setNode(ruby.getCurrentContext(), node);
134
+ XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"));
135
+ xmlDocument.setNode(runtime.getCurrentContext(), node);
135
136
  return xmlDocument;
136
137
  default:
137
- XmlNode xmlNode = (XmlNode) getNokogiriClass(ruby, "Nokogiri::XML::Node").allocate();
138
- xmlNode.setNode(ruby.getCurrentContext(), node);
138
+ XmlNode xmlNode = (XmlNode) NokogiriService.XML_NODE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Node"));
139
+ xmlNode.setNode(runtime.getCurrentContext(), node);
139
140
  return xmlNode;
140
141
  }
141
142
  }
142
143
 
143
144
  public static RubyClass getNokogiriClass(Ruby ruby, String name) {
144
- RubyHash classCache = (RubyHash) ruby.getGlobalVariables().get(NokogiriService.nokogiriClassCacheGvarName);
145
- IRubyObject rubyName = RubyString.newString(ruby, name);
146
- return (RubyClass)classCache.fastARef(rubyName);
145
+ return NokogiriService.nokogiriClassCache.get(name);
147
146
  }
148
147
 
149
148
  public static IRubyObject stringOrNil(Ruby runtime, String s) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -36,10 +36,11 @@ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
36
  import static nokogiri.internals.NokogiriHelpers.isNamespace;
37
37
 
38
38
  import java.util.ArrayList;
39
- import java.util.HashMap;
39
+ import java.util.LinkedHashMap;
40
40
  import java.util.List;
41
41
  import java.util.Map;
42
42
 
43
+ import nokogiri.NokogiriService;
43
44
  import nokogiri.XmlDocument;
44
45
  import nokogiri.XmlNamespace;
45
46
 
@@ -62,7 +63,7 @@ public class NokogiriNamespaceCache {
62
63
 
63
64
  public NokogiriNamespaceCache() {
64
65
  keys = new ArrayList<Long>();
65
- cache = new HashMap<Integer, CacheEntry>();
66
+ cache = new LinkedHashMap<Integer, CacheEntry>();
66
67
  }
67
68
 
68
69
  private Long hashCode(String prefix, String href) {
@@ -121,7 +122,7 @@ public class NokogiriNamespaceCache {
121
122
  keys.add(hash);
122
123
  index = keys.size() - 1;
123
124
  String actualPrefix = (prefix.equals("")) ? null : prefix;
124
- XmlNamespace namespace = (XmlNamespace) getNokogiriClass(ruby, "Nokogiri::XML::Namespace").allocate();
125
+ XmlNamespace namespace = (XmlNamespace) NokogiriService.XML_NAMESPACE_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Namespace"));
125
126
  namespace.setDefinition(ruby, actualPrefix, href);
126
127
  namespace.setDocument(document);
127
128
  CacheEntry entry = new CacheEntry(namespace, node);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2010:
4
+ * Copyright (c) 2008 - 2011:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]