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]
@@ -40,6 +40,7 @@ import org.xml.sax.SAXParseException;
40
40
  * Error Handler for XML document when recover is true (default).
41
41
  *
42
42
  * @author sergio
43
+ * @author Yoko Harada <yokolet@gmail.com>
43
44
  */
44
45
  public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler{
45
46
  public NokogiriNonStrictErrorHandler(boolean noerror, boolean nowarning) {
@@ -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]
@@ -41,6 +41,7 @@ import org.xml.sax.SAXParseException;
41
41
  * when NOERROR or/both NOWARNING is/are true.
42
42
  *
43
43
  * @author sergio
44
+ * @author Yoko Harada <yokolet@gmail.com>
44
45
  */
45
46
  public class NokogiriStrictErrorHandler extends NokogiriErrorHandler {
46
47
  public NokogiriStrictErrorHandler(boolean noerror, boolean nowarning) {
@@ -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,11 +32,14 @@
32
32
 
33
33
  package nokogiri.internals;
34
34
 
35
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
+
35
37
  import java.util.List;
36
38
 
37
39
  import javax.xml.xpath.XPathFunction;
38
40
  import javax.xml.xpath.XPathFunctionException;
39
41
 
42
+ import nokogiri.NokogiriService;
40
43
  import nokogiri.XmlNode;
41
44
  import nokogiri.XmlNodeSet;
42
45
 
@@ -55,6 +58,7 @@ import org.w3c.dom.NodeList;
55
58
  * Xpath function handler.
56
59
  *
57
60
  * @author sergio
61
+ * @author Yoko Harada <yokolet@gmail.com>
58
62
  */
59
63
  public class NokogiriXPathFunction implements XPathFunction {
60
64
  private final IRubyObject handler;
@@ -91,18 +95,18 @@ public class NokogiriXPathFunction implements XPathFunction {
91
95
 
92
96
  private IRubyObject fromObjectToRuby(Object o) {
93
97
  // argument object type is one of NodeList, String, Boolean, or Double.
94
- Ruby ruby = this.handler.getRuntime();
98
+ Ruby runtime = this.handler.getRuntime();
95
99
  if (o instanceof NodeList) {
96
- return new XmlNodeSet(ruby, (NodeList) o);
97
- //} else if (o instanceof Node) {
98
- // return NokogiriHelpers.getCachedNodeOrCreate(ruby, (Node) o);
100
+ XmlNodeSet xmlNodeSet = (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
101
+ xmlNodeSet.setNodeList((NodeList) o);
102
+ return xmlNodeSet;
99
103
  } else {
100
- return JavaUtil.convertJavaToUsableRubyObject(ruby, o);
104
+ return JavaUtil.convertJavaToUsableRubyObject(runtime, o);
101
105
  }
102
106
  }
103
107
 
104
108
  private Object fromRubyToObject(IRubyObject o) {
105
- Ruby ruby = this.handler.getRuntime();
109
+ Ruby runtime = this.handler.getRuntime();
106
110
  if(o instanceof RubyString) {
107
111
  return o.toJava(String.class);
108
112
  } else if (o instanceof RubyFloat) {
@@ -110,9 +114,11 @@ public class NokogiriXPathFunction implements XPathFunction {
110
114
  } else if (o instanceof RubyBoolean) {
111
115
  return o.toJava(Boolean.class);
112
116
  } else if (o instanceof XmlNodeSet) {
113
- return ((XmlNodeSet) o).toNodeList(ruby);
117
+ return ((XmlNodeSet) o).toNodeList(runtime);
114
118
  } else if (o instanceof RubyArray) {
115
- return (new XmlNodeSet(ruby, (RubyArray) o)).toNodeList(ruby);
119
+ XmlNodeSet xmlNodeSet = (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
120
+ xmlNodeSet.setInitialNodes((RubyArray)o);
121
+ return xmlNodeSet.toNodeList(runtime);
116
122
  } else /*if (o instanceof XmlNode)*/ {
117
123
  return ((XmlNode) o).getNode();
118
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]
@@ -46,6 +46,7 @@ import org.jruby.RubyClass;
46
46
  import org.jruby.RubyIO;
47
47
  import org.jruby.RubyObject;
48
48
  import org.jruby.RubyString;
49
+ import org.jruby.RubyStringIO;
49
50
  import org.jruby.exceptions.RaiseException;
50
51
  import org.jruby.runtime.ThreadContext;
51
52
  import org.jruby.runtime.builtin.IRubyObject;
@@ -110,7 +111,7 @@ public class ParserContext extends RubyObject {
110
111
  public void setInputSource(ThreadContext context,
111
112
  IRubyObject data) {
112
113
  Ruby ruby = context.getRuntime();
113
-
114
+ RubyString stringData = null;
114
115
  if (invoke(context, data, "respond_to?",
115
116
  ruby.newSymbol("to_io").to_sym()).isTrue()) {
116
117
  /* IO or other object that responds to :to_io */
@@ -119,20 +120,30 @@ public class ParserContext extends RubyObject {
119
120
  ruby.getIO(),
120
121
  "to_io");
121
122
  source = new InputSource(io.getInStream());
123
+ } else if (((RubyObject)data).getInstanceVariable("@io") != null) {
124
+ // in case of EncodingReader is used
125
+ // since EncodingReader won't respond to :to_io
126
+ RubyObject dataObject = (RubyObject) ((RubyObject)data).getInstanceVariable("@io");
127
+ if (dataObject instanceof RubyIO) {
128
+ RubyIO io = (RubyIO)dataObject;
129
+ source = new InputSource(io.getInStream());
130
+ } else if (dataObject instanceof RubyStringIO) {
131
+ stringData = (RubyString)((RubyStringIO)dataObject).string();
132
+ }
122
133
  } else {
123
- RubyString str;
124
134
  if (invoke(context, data, "respond_to?",
125
135
  ruby.newSymbol("string").to_sym()).isTrue()) {
126
136
  /* StringIO or other object that responds to :string */
127
- str = invoke(context, data, "string").convertToString();
137
+ stringData = invoke(context, data, "string").convertToString();
128
138
  } else if (data instanceof RubyString) {
129
- str = (RubyString) data;
139
+ stringData = (RubyString) data;
130
140
  } else {
131
141
  throw ruby.newArgumentError(
132
142
  "must be kind_of String or respond to :to_io or :string");
133
143
  }
134
-
135
- ByteList bytes = str.getByteList();
144
+ }
145
+ if (stringData != null) {
146
+ ByteList bytes = stringData.getByteList();
136
147
  source = new InputSource(new ByteArrayInputStream(bytes.unsafeBytes(), bytes.begin(), bytes.length()));
137
148
  }
138
149
  }
@@ -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]
@@ -46,6 +46,7 @@ import java.util.Map;
46
46
  import java.util.Set;
47
47
  import java.util.Stack;
48
48
 
49
+ import nokogiri.NokogiriService;
49
50
  import nokogiri.XmlAttr;
50
51
  import nokogiri.XmlDocument;
51
52
  import nokogiri.XmlSyntaxError;
@@ -112,13 +113,13 @@ public abstract class ReaderNode {
112
113
  RubyArray array = RubyArray.newArray(ruby);
113
114
  if (attributeList != null && attributeList.length > 0) {
114
115
  if (document == null) {
115
- document = ((XmlDocument) getNokogiriClass(ruby, "Nokogiri::XML::Document").allocate()).getDocument();
116
+ document = ((XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Document"))).getDocument();
116
117
  }
117
118
  for (int i=0; i<attributeList.length; i++) {
118
119
  if (!isNamespace(attributeList.names.get(i))) {
119
120
  Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
120
121
  attr.setValue(attributeList.values.get(i));
121
- XmlAttr xmlAttr = (XmlAttr) getNokogiriClass(ruby, "Nokogiri::XML::Attr").allocate();
122
+ XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Attr"));
122
123
  xmlAttr.setNode(ruby.getCurrentContext(), attr);
123
124
  array.append(xmlAttr);
124
125
  }
@@ -430,9 +431,9 @@ public abstract class ReaderNode {
430
431
  private final XmlSyntaxError exception;
431
432
 
432
433
  // Still don't know what to do with ex.
433
- public ExceptionNode(Ruby ruby, SAXParseException ex) {
434
- super(ruby);
435
- this.exception = new XmlSyntaxError(ruby);
434
+ public ExceptionNode(Ruby runtime, SAXParseException ex) {
435
+ super(runtime);
436
+ exception = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(ruby, "Nokogiri::XML::SyntaxError"));
436
437
  }
437
438
 
438
439
  @Override
@@ -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,18 +32,25 @@
32
32
 
33
33
  package nokogiri.internals;
34
34
 
35
- import java.lang.Character;
35
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
+
37
+ import java.nio.charset.Charset;
38
+
36
39
  import org.jruby.Ruby;
37
40
  import org.jruby.RubyClass;
41
+ import org.jruby.RubyEncoding;
38
42
  import org.jruby.RubyString;
39
43
  import org.jruby.javasupport.util.RuntimeHelpers;
40
44
  import org.jruby.runtime.ThreadContext;
41
45
  import org.jruby.runtime.builtin.IRubyObject;
46
+ import org.jruby.util.ByteList;
42
47
 
43
48
  /**
44
49
  * A class for serializing a document.
45
50
  *
46
51
  * @author sergio
52
+ * @author Patrick Mahoney <pat@polycrystal.org>
53
+ * @author Yoko Harada <yokolet@gmail.com>
47
54
  */
48
55
  public class SaveContext {
49
56
 
@@ -70,12 +77,9 @@ public class SaveContext {
70
77
  public static final int AS_XML = 32;
71
78
  public static final int AS_HTML = 64;
72
79
 
73
- public SaveContext(ThreadContext context, int options, String indentString,
74
- String encoding) {
80
+ public SaveContext(ThreadContext context, int options, String indentString, String encoding) {
75
81
  this.context = context;
76
- this.elementDescription =
77
- (RubyClass) context.getRuntime().getClassFromPath(
78
- "Nokogiri::HTML::ElementDescription");
82
+ this.elementDescription = (RubyClass)getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::ElementDescription");
79
83
  this.options = options;
80
84
  this.encoding = encoding;
81
85
  this.indentString = indentString;
@@ -88,8 +92,7 @@ public class SaveContext {
88
92
  asXml = (options & AS_XML) == AS_XML;
89
93
  asHtml = (options & AS_HTML) == AS_HTML;
90
94
  }
91
-
92
-
95
+
93
96
  public void append(String s) {
94
97
  this.buffer.append(s);
95
98
  }
@@ -263,7 +266,10 @@ public class SaveContext {
263
266
  public String toString() { return this.buffer.toString(); }
264
267
 
265
268
  public RubyString toRubyString(Ruby runtime) {
266
- return new RubyString(runtime, runtime.getString(), buffer);
269
+ ByteList bytes;
270
+ if (encoding == null) bytes = new ByteList(buffer.toString().getBytes());
271
+ else bytes = new ByteList(RubyEncoding.encode(buffer.toString(), Charset.forName(encoding)), false);
272
+ return RubyString.newString(runtime, bytes);
267
273
  }
268
274
 
269
275
  public boolean Xhtml() { return this.xhtml; }
@@ -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,7 +32,10 @@
32
32
 
33
33
  package nokogiri.internals;
34
34
 
35
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
+ import nokogiri.NokogiriService;
35
37
  import nokogiri.XmlSyntaxError;
38
+
36
39
  import org.jruby.Ruby;
37
40
  import org.jruby.RubyArray;
38
41
  import org.xml.sax.ErrorHandler;
@@ -43,22 +46,27 @@ import org.xml.sax.SAXParseException;
43
46
  * Error handler for Relax and W3C XML Schema.
44
47
  *
45
48
  * @author sergio
49
+ * @author Yoko Harada <yokolet@gmail.com>
46
50
  */
47
51
  public class SchemaErrorHandler implements ErrorHandler{
48
52
  private RubyArray errors;
49
- private Ruby ruby;
53
+ private Ruby runtime;
50
54
 
51
55
  public SchemaErrorHandler(Ruby ruby, RubyArray array) {
52
- this.ruby = ruby;
56
+ this.runtime = ruby;
53
57
  this.errors = array;
54
58
  }
55
59
 
56
60
  public void warning(SAXParseException ex) throws SAXException {
57
- this.errors.append(new XmlSyntaxError(ruby, ex));
61
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
62
+ xmlSyntaxError.setException(ex);
63
+ this.errors.append(xmlSyntaxError);
58
64
  }
59
65
 
60
66
  public void error(SAXParseException ex) throws SAXException {
61
- this.errors.append(new XmlSyntaxError(ruby, ex));
67
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
68
+ xmlSyntaxError.setException(ex);
69
+ this.errors.append(xmlSyntaxError);
62
70
  }
63
71
 
64
72
  public void fatalError(SAXParseException ex) throws SAXException {
@@ -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]
@@ -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]
@@ -40,6 +40,7 @@ import java.io.IOException;
40
40
  import java.util.ArrayList;
41
41
  import java.util.List;
42
42
 
43
+ import nokogiri.NokogiriService;
43
44
  import nokogiri.XmlDocument;
44
45
  import nokogiri.XmlSyntaxError;
45
46
 
@@ -63,6 +64,7 @@ import org.xml.sax.SAXException;
63
64
  * we delay creating objects for performance.
64
65
  *
65
66
  * @author sergio
67
+ * @author Yoko Harada <yokolet@gmail.com>
66
68
  */
67
69
  public class XmlDomParserContext extends ParserContext {
68
70
  protected static final String FEATURE_LOAD_EXTERNAL_DTD =
@@ -161,18 +163,20 @@ public class XmlDomParserContext extends ParserContext {
161
163
  if (options.recover) {
162
164
  XmlDocument doc = this.getNewEmptyDocument(context);
163
165
  this.addErrorsIfNecessary(context, doc);
164
- ((RubyArray) doc.getInstanceVariable("@errors")).append(new XmlSyntaxError(context.getRuntime(), ex));
166
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
167
+ xmlSyntaxError.setException(ex);
168
+ ((RubyArray) doc.getInstanceVariable("@errors")).append(xmlSyntaxError);
165
169
  return doc;
166
170
  } else {
167
- throw new RaiseException(new XmlSyntaxError(context.getRuntime(), ex));
171
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
172
+ xmlSyntaxError.setException(ex);
173
+ throw new RaiseException(xmlSyntaxError);
168
174
  }
169
175
  }
170
176
 
171
177
  protected XmlDocument getNewEmptyDocument(ThreadContext context) {
172
178
  IRubyObject[] args = new IRubyObject[0];
173
- return (XmlDocument) XmlDocument.rbNew(context,
174
- getNokogiriClass(context.getRuntime(), "Nokogiri::XML::Document"),
175
- args);
179
+ return (XmlDocument) XmlDocument.rbNew(context, getNokogiriClass(context.getRuntime(), "Nokogiri::XML::Document"), args);
176
180
  }
177
181
 
178
182
  /**
@@ -180,9 +184,10 @@ public class XmlDomParserContext extends ParserContext {
180
184
  * override it.
181
185
  */
182
186
  protected XmlDocument wrapDocument(ThreadContext context,
183
- RubyClass klass,
187
+ RubyClass klazz,
184
188
  Document doc) {
185
- XmlDocument xmlDocument = new XmlDocument(context.getRuntime(), klass, doc);
189
+ XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
190
+ xmlDocument.setNode(context, doc);
186
191
  xmlDocument.setEncoding(ruby_encoding);
187
192
  return xmlDocument;
188
193
  }
@@ -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]