nokogiri 1.5.0.beta.3 → 1.5.0.beta.4

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 (87) 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/version.rb +1 -1
  72. data/lib/nokogiri/xml/node.rb +2 -2
  73. data/lib/nokogiri/xml/node/save_options.rb +3 -0
  74. data/lib/nokogiri/xml/node_set.rb +1 -1
  75. data/test/css/test_tokenizer.rb +8 -0
  76. data/test/helper.rb +2 -0
  77. data/test/html/sax/test_parser.rb +43 -0
  78. data/test/html/test_document.rb +59 -0
  79. data/test/html/test_document_encoding.rb +48 -0
  80. data/test/html/test_element_description.rb +1 -1
  81. data/test/xml/sax/test_parser.rb +16 -0
  82. data/test/xml/test_document.rb +3 -1
  83. data/test/xml/test_node.rb +4 -1
  84. data/test/xml/test_node_set.rb +10 -0
  85. metadata +90 -107
  86. data/lib/nokogiri/css/generated_parser.rb +0 -676
  87. 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]
@@ -65,6 +65,7 @@ import org.xml.sax.SAXParseException;
65
65
  * Base class for the SAX parsers.
66
66
  *
67
67
  * @author Patrick Mahoney <pat@polycrystal.org>
68
+ * @author Yoko Harada <yokolet@gmail.com>
68
69
  */
69
70
  @JRubyClass(name="Nokogiri::XML::SAX::ParserContext")
70
71
  public class XmlSaxParserContext extends ParserContext {
@@ -82,14 +83,27 @@ public class XmlSaxParserContext extends ParserContext {
82
83
 
83
84
  public XmlSaxParserContext(final Ruby ruby, RubyClass rubyClass) {
84
85
  super(ruby, rubyClass);
85
- replaceEntities = ruby.getTrue();
86
+ }
87
+
88
+ protected void initialize(Ruby runtime) {
89
+ replaceEntities = runtime.getTrue();
86
90
  try {
87
91
  parser = createParser();
88
92
  } catch (SAXException se) {
89
- throw RaiseException.createNativeRaiseException(ruby, se);
93
+ throw RaiseException.createNativeRaiseException(runtime, se);
90
94
  }
91
95
  }
92
96
 
97
+ /**
98
+ * Create and return a copy of this object.
99
+ *
100
+ * @return a clone of this object
101
+ */
102
+ @Override
103
+ public Object clone() throws CloneNotSupportedException {
104
+ return super.clone();
105
+ }
106
+
93
107
  protected AbstractSAXParser createParser() throws SAXException {
94
108
  XmlSaxParser parser = new XmlSaxParser();
95
109
  parser.setFeature(FEATURE_NAMESPACE_PREFIXES, true);
@@ -105,8 +119,8 @@ public class XmlSaxParserContext extends ParserContext {
105
119
  public static IRubyObject parse_memory(ThreadContext context,
106
120
  IRubyObject klazz,
107
121
  IRubyObject data) {
108
- XmlSaxParserContext ctx = new XmlSaxParserContext(context.getRuntime(),
109
- (RubyClass) klazz);
122
+ XmlSaxParserContext ctx = (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
123
+ ctx.initialize(context.getRuntime());
110
124
  ctx.setInputSource(context, data);
111
125
  return ctx;
112
126
  }
@@ -119,8 +133,8 @@ public class XmlSaxParserContext extends ParserContext {
119
133
  public static IRubyObject parse_file(ThreadContext context,
120
134
  IRubyObject klazz,
121
135
  IRubyObject data) {
122
- XmlSaxParserContext ctx = new XmlSaxParserContext(context.getRuntime(),
123
- (RubyClass) klazz);
136
+ XmlSaxParserContext ctx = (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
137
+ ctx.initialize(context.getRuntime());
124
138
  ctx.setInputSourceFile(context, data);
125
139
  return ctx;
126
140
  }
@@ -137,8 +151,8 @@ public class XmlSaxParserContext extends ParserContext {
137
151
  IRubyObject data,
138
152
  IRubyObject enc) {
139
153
  //int encoding = (int)enc.convertToInteger().getLongValue();
140
- XmlSaxParserContext ctx = new XmlSaxParserContext(context.getRuntime(),
141
- (RubyClass) klazz);
154
+ XmlSaxParserContext ctx = (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
155
+ ctx.initialize(context.getRuntime());
142
156
  ctx.setInputSource(context, data);
143
157
  return ctx;
144
158
  }
@@ -151,8 +165,8 @@ public class XmlSaxParserContext extends ParserContext {
151
165
  public static IRubyObject parse_stream(ThreadContext context,
152
166
  IRubyObject klazz,
153
167
  InputStream stream) {
154
- XmlSaxParserContext ctx =
155
- new XmlSaxParserContext(context.getRuntime(), (RubyClass)klazz);
168
+ XmlSaxParserContext ctx = (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
169
+ ctx.initialize(context.getRuntime());
156
170
  ctx.setInputSource(stream);
157
171
  return ctx;
158
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]
@@ -56,6 +56,8 @@ import org.jruby.runtime.builtin.IRubyObject;
56
56
  /**
57
57
  * Class for Nokogiri::XML::SAX::PushParser
58
58
  *
59
+ * @author Patrick Mahoney <pat@polycrystal.org>
60
+ * @author Yoko Harada <yokolet@gmail.com>
59
61
  */
60
62
  @JRubyClass(name="Nokogiri::XML::SAX::PushParser")
61
63
  public class XmlSaxPushParser extends RubyObject {
@@ -112,7 +114,8 @@ public class XmlSaxPushParser extends RubyObject {
112
114
  if (chunk instanceof RubyString || chunk.respondsTo("to_str")) {
113
115
  data = chunk.convertToString().getBytes();
114
116
  } else {
115
- throw new RaiseException(new XmlSyntaxError(context.getRuntime()));
117
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
118
+ throw new RaiseException(xmlSyntaxError);
116
119
  }
117
120
 
118
121
  int errorCount0 = runner.getErrorCount();
@@ -161,8 +164,7 @@ public class XmlSaxPushParser extends RubyObject {
161
164
 
162
165
  this.context = context;
163
166
  this.handler = handler;
164
- this.parser = (XmlSaxParserContext)
165
- XmlSaxParserContext.parse_stream(context, klazz, stream);
167
+ this.parser = (XmlSaxParserContext) XmlSaxParserContext.parse_stream(context, klazz, stream);
166
168
  }
167
169
 
168
170
  public void run() {
@@ -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,8 @@ package nokogiri;
35
35
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
36
 
37
37
  import java.io.IOException;
38
+ import java.io.InputStream;
39
+ import java.io.Reader;
38
40
  import java.io.StringReader;
39
41
 
40
42
  import javax.xml.XMLConstants;
@@ -60,6 +62,8 @@ import org.jruby.runtime.ThreadContext;
60
62
  import org.jruby.runtime.Visibility;
61
63
  import org.jruby.runtime.builtin.IRubyObject;
62
64
  import org.w3c.dom.Document;
65
+ import org.w3c.dom.ls.LSInput;
66
+ import org.w3c.dom.ls.LSResourceResolver;
63
67
  import org.xml.sax.ErrorHandler;
64
68
  import org.xml.sax.SAXException;
65
69
 
@@ -67,52 +71,63 @@ import org.xml.sax.SAXException;
67
71
  * Class for Nokogiri::XML::Schema
68
72
  *
69
73
  * @author sergio
74
+ * @author Yoko Harada <yokolet@gmail.com>
70
75
  */
71
76
  @JRubyClass(name="Nokogiri::XML::Schema")
72
77
  public class XmlSchema extends RubyObject {
73
-
74
- protected Source source;
78
+ private Validator validator;
75
79
 
76
80
  public XmlSchema(Ruby ruby, RubyClass klazz) {
77
81
  super(ruby, klazz);
78
82
  }
83
+
84
+ /**
85
+ * Create and return a copy of this object.
86
+ *
87
+ * @return a clone of this object
88
+ */
89
+ @Override
90
+ public Object clone() throws CloneNotSupportedException {
91
+ return super.clone();
92
+ }
79
93
 
80
- private Schema getSchema(ThreadContext context) {
81
-
82
- Schema schema = null;
83
-
84
- String uri=XMLConstants.W3C_XML_SCHEMA_NS_URI;
85
-
86
- try {
87
- schema = SchemaFactory.newInstance(uri).newSchema(source);
88
- } catch(SAXException ex) {
89
- throw context.getRuntime().newRuntimeError("Could not parse document: "+ex.getMessage());
90
- }
91
- return schema;
94
+ private Schema getSchema(Source source, String currentDir) throws SAXException {
95
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
96
+ SchemaResourceResolver resourceResolver = new SchemaResourceResolver(currentDir, null);
97
+ schemaFactory.setResourceResolver(resourceResolver);
98
+ return schemaFactory.newSchema(source);
99
+ }
100
+
101
+ private void setValidator(Validator validator) {
102
+ this.validator = validator;
92
103
  }
93
104
 
94
- protected static XmlSchema createSchemaWithSource(ThreadContext context, RubyClass klazz, Source source) {
95
- Ruby ruby = context.getRuntime();
96
- XmlSchema schema = null;
97
- if( klazz.ancestors(context).include_p(context,
98
- getNokogiriClass(ruby, "Nokogiri::XML::RelaxNG")).isTrue()) {
99
- schema = new XmlRelaxng(ruby, klazz);
100
- } else {
101
- schema = new XmlSchema(ruby, klazz);
105
+ static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source) {
106
+ Ruby runtime = context.getRuntime();
107
+ XmlSchema xmlSchema = (XmlSchema) NokogiriService.XML_SCHEMA_ALLOCATOR.allocate(runtime, klazz);
108
+ xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());
109
+
110
+ try {
111
+ Schema schema = xmlSchema.getSchema(source, context.getRuntime().getCurrentDirectory());
112
+ xmlSchema.setValidator(schema.newValidator());
113
+ return xmlSchema;
114
+ } catch (SAXException ex) {
115
+ throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
102
116
  }
103
- schema.source = source;
104
-
105
- schema.setInstanceVariable("@errors", ruby.newEmptyArray());
106
- return schema;
107
117
  }
108
118
 
119
+ /*
120
+ * call-seq:
121
+ * from_document(doc)
122
+ *
123
+ * Create a new Schema from the Nokogiri::XML::Document +doc+
124
+ */
109
125
  @JRubyMethod(meta=true)
110
126
  public static IRubyObject from_document(ThreadContext context, IRubyObject klazz, IRubyObject document) {
111
127
  XmlDocument doc = ((XmlDocument) ((XmlNode) document).document(context));
112
128
 
113
129
  RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors");
114
-
115
- if(!errors.isEmpty()) {
130
+ if (!errors.isEmpty()) {
116
131
  throw new RaiseException((XmlSyntaxError) errors.first());
117
132
  }
118
133
 
@@ -120,20 +135,27 @@ public class XmlSchema extends RubyObject {
120
135
 
121
136
  IRubyObject uri = doc.url(context);
122
137
 
123
- if(!uri.isNil()) {
138
+ if (!uri.isNil()) {
124
139
  source.setSystemId(uri.convertToString().asJavaString());
125
140
  }
126
-
127
- return createSchemaWithSource(context, (RubyClass) klazz, source);
141
+
142
+ return getSchema(context, (RubyClass)klazz, source);
143
+ }
144
+
145
+ private static IRubyObject getSchema(ThreadContext context, RubyClass klazz, Source source) {
146
+ String moduleName = klazz.getName();
147
+ if ("Nokogiri::XML::Schema".equals(moduleName)) {
148
+ return XmlSchema.createSchemaInstance(context, klazz, source);
149
+ } else if ("Nokogiri::XML::RelaxNG".equals(moduleName)) {
150
+ return XmlRelaxng.createSchemaInstance(context, klazz, source);
151
+ }
152
+ return context.getRuntime().getNil();
128
153
  }
129
154
 
130
155
  @JRubyMethod(meta=true)
131
156
  public static IRubyObject read_memory(ThreadContext context, IRubyObject klazz, IRubyObject content) {
132
-
133
157
  String data = content.convertToString().asJavaString();
134
-
135
- return createSchemaWithSource(context, (RubyClass) klazz,
136
- new StreamSource(new StringReader(data)));
158
+ return getSchema(context, (RubyClass) klazz, new StreamSource(new StringReader(data)));
137
159
  }
138
160
 
139
161
  @JRubyMethod(visibility=Visibility.PRIVATE)
@@ -151,25 +173,147 @@ public class XmlSchema extends RubyObject {
151
173
  return validate_document_or_file(context, xmlDocument);
152
174
  }
153
175
 
154
- private IRubyObject validate_document_or_file(ThreadContext context, XmlDocument xmlDocument) {
155
- Document doc = xmlDocument.getDocument();
156
-
157
- DOMSource docSource = new DOMSource(doc);
158
- Validator validator = getSchema(context).newValidator();
159
-
176
+ IRubyObject validate_document_or_file(ThreadContext context, XmlDocument xmlDocument) {
160
177
  RubyArray errors = (RubyArray) this.getInstanceVariable("@errors");
161
178
  ErrorHandler errorHandler = new SchemaErrorHandler(context.getRuntime(), errors);
162
-
163
- validator.setErrorHandler(errorHandler);
179
+ setErrorHandler(errorHandler);
164
180
 
165
181
  try {
166
- validator.validate(docSource);
182
+ validate(xmlDocument.getDocument());
167
183
  } catch(SAXException ex) {
168
- errors.append(new XmlSyntaxError(context.getRuntime(), ex));
184
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
185
+ xmlSyntaxError.setException(ex);
186
+ errors.append(xmlSyntaxError);
169
187
  } catch (IOException ex) {
170
188
  throw context.getRuntime().newIOError(ex.getMessage());
171
189
  }
172
190
 
173
191
  return errors;
174
192
  }
193
+
194
+ protected void setErrorHandler(ErrorHandler errorHandler) {
195
+ validator.setErrorHandler(errorHandler);
196
+ }
197
+
198
+ protected void validate(Document document) throws SAXException, IOException {
199
+ DOMSource docSource = new DOMSource(document);
200
+ validator.validate(docSource);
201
+ }
202
+
203
+ private class SchemaResourceResolver implements LSResourceResolver {
204
+ SchemaLSInput lsInput = new SchemaLSInput();
205
+ String defaultURI;
206
+
207
+ SchemaResourceResolver(String currentDir, Object input) {
208
+ defaultURI = currentDir + "/nokogiri_default_fake.xsd";
209
+ if (input == null) return;
210
+ if (input instanceof String) {
211
+ lsInput.setStringData((String)input);
212
+ } else if (input instanceof Reader) {
213
+ lsInput.setCharacterStream((Reader)input);
214
+ } else if (input instanceof InputStream) {
215
+ lsInput.setByteStream((InputStream)input);
216
+ }
217
+ }
218
+
219
+ @Override
220
+ public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
221
+ lsInput.setPublicId(publicId);
222
+ lsInput.setSystemId(systemId);
223
+ lsInput.setBaseURI(baseURI != null ? baseURI : defaultURI);
224
+ return lsInput;
225
+ }
226
+ }
227
+
228
+ private class SchemaLSInput implements LSInput {
229
+ protected String fPublicId;
230
+ protected String fSystemId;
231
+ protected String fBaseSystemId;
232
+ protected InputStream fByteStream;
233
+ protected Reader fCharStream;
234
+ protected String fData;
235
+ protected String fEncoding;
236
+ protected boolean fCertifiedText = false;
237
+
238
+ @Override
239
+ public String getBaseURI() {
240
+ return fBaseSystemId;
241
+ }
242
+
243
+ @Override
244
+ public InputStream getByteStream() {
245
+ return fByteStream;
246
+ }
247
+
248
+ @Override
249
+ public boolean getCertifiedText() {
250
+ return fCertifiedText;
251
+ }
252
+
253
+ @Override
254
+ public Reader getCharacterStream() {
255
+ return fCharStream;
256
+ }
257
+
258
+ @Override
259
+ public String getEncoding() {
260
+ return fEncoding;
261
+ }
262
+
263
+ @Override
264
+ public String getPublicId() {
265
+ return fPublicId;
266
+ }
267
+
268
+ @Override
269
+ public String getStringData() {
270
+ return fData;
271
+ }
272
+
273
+ @Override
274
+ public String getSystemId() {
275
+ return fSystemId;
276
+ }
277
+
278
+ @Override
279
+ public void setBaseURI(String baseURI) {
280
+ fBaseSystemId = baseURI;
281
+ }
282
+
283
+ @Override
284
+ public void setByteStream(InputStream byteStream) {
285
+ fByteStream = byteStream;
286
+ }
287
+
288
+ @Override
289
+ public void setCertifiedText(boolean certified) {
290
+ fCertifiedText = certified;
291
+ }
292
+
293
+ @Override
294
+ public void setCharacterStream(Reader charStream) {
295
+ fCharStream = charStream;
296
+ }
297
+
298
+ @Override
299
+ public void setEncoding(String encoding) {
300
+ fEncoding = encoding;
301
+ }
302
+
303
+ @Override
304
+ public void setPublicId(String pubId) {
305
+ fPublicId = pubId;
306
+ }
307
+
308
+ @Override
309
+ public void setStringData(String stringData) {
310
+ fData = stringData;
311
+ }
312
+
313
+ @Override
314
+ public void setSystemId(String sysId) {
315
+ fSystemId = sysId;
316
+ }
317
+
318
+ }
175
319
  }
@@ -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,12 +32,12 @@
32
32
 
33
33
  package nokogiri;
34
34
 
35
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
35
36
  import static nokogiri.internals.NokogiriHelpers.stringOrNil;
36
37
 
37
38
  import org.jruby.Ruby;
38
39
  import org.jruby.RubyClass;
39
40
  import org.jruby.RubyException;
40
- import org.jruby.RubyModule;
41
41
  import org.jruby.anno.JRubyClass;
42
42
  import org.jruby.anno.JRubyMethod;
43
43
  import org.jruby.runtime.ThreadContext;
@@ -47,58 +47,64 @@ import org.xml.sax.SAXParseException;
47
47
  /**
48
48
  * Class for Nokogiri::XML::SyntaxError
49
49
  *
50
+ * @author sergio
51
+ * @author Yoko Harada <yokolet@gmail.com>
50
52
  */
51
53
  @JRubyClass(name="Nokogiri::XML::SyntaxError", parent="Nokogiri::SyntaxError")
52
54
  public class XmlSyntaxError extends RubyException {
55
+ private Exception exception;
53
56
 
54
- protected Exception exception;
55
-
56
- public static RubyClass getRubyClass(Ruby ruby) {
57
- return ((RubyModule) ruby.getModule("Nokogiri").getConstant("XML")).getClass("SyntaxError");
58
- }
59
-
60
- public XmlSyntaxError(Ruby ruby){
61
- this(ruby, getRubyClass(ruby));
57
+ public XmlSyntaxError(Ruby runtime, RubyClass klazz) {
58
+ super(runtime, klazz);
62
59
  }
63
-
64
- public XmlSyntaxError(Ruby ruby, RubyClass rubyClass) {
65
- super(ruby, rubyClass);
60
+
61
+ /**
62
+ * Create and return a copy of this object.
63
+ *
64
+ * @return a clone of this object
65
+ */
66
+ @Override
67
+ public Object clone() throws CloneNotSupportedException {
68
+ return super.clone();
66
69
  }
67
70
 
68
- public XmlSyntaxError(Ruby ruby, Exception ex) {
69
- this(ruby);
71
+ public XmlSyntaxError(Ruby runtime, RubyClass rubyClass, Exception ex) {
72
+ super(runtime, rubyClass, ex.getMessage());
70
73
  this.exception = ex;
71
74
  }
72
75
 
73
- public XmlSyntaxError(Ruby ruby, RubyClass rubyClass, Exception ex) {
74
- super(ruby, rubyClass, ex.getMessage());
75
- this.exception = ex;
76
+ public static XmlSyntaxError createWarning(Ruby runtime, SAXParseException e) {
77
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
78
+ xmlSyntaxError.setException(runtime, e, 1);
79
+ return xmlSyntaxError;
76
80
  }
77
81
 
78
- public static XmlSyntaxError createWarning(Ruby ruby, SAXParseException e) {
79
- return new XmlSyntaxError(ruby, e, 1);
82
+ public static XmlSyntaxError createError(Ruby runtime, SAXParseException e) {
83
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
84
+ xmlSyntaxError.setException(runtime, e, 2);
85
+ return xmlSyntaxError;
80
86
  }
81
87
 
82
- public static XmlSyntaxError createError(Ruby ruby, SAXParseException e) {
83
- return new XmlSyntaxError(ruby, e, 2);
88
+ public static XmlSyntaxError createFatalError(Ruby runtime, SAXParseException e) {
89
+ XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
90
+ xmlSyntaxError.setException(runtime, e, 3);
91
+ return xmlSyntaxError;
84
92
  }
85
-
86
- public static XmlSyntaxError createFatalError(Ruby ruby, SAXParseException e) {
87
- return new XmlSyntaxError(ruby, e, 3);
93
+
94
+ public void setException(Exception exception) {
95
+ this.exception = exception;
88
96
  }
89
-
90
- public XmlSyntaxError(Ruby ruby, SAXParseException e, int level) {
91
- super(ruby, getRubyClass(ruby), e.getMessage());
92
- this.exception = e;
93
- setInstanceVariable("@level", ruby.newFixnum(level));
94
- setInstanceVariable("@line", ruby.newFixnum(e.getLineNumber()));
95
- setInstanceVariable("@column", ruby.newFixnum(e.getColumnNumber()));
96
- setInstanceVariable("@file", stringOrNil(ruby, e.getSystemId()));
97
+
98
+ public void setException(Ruby runtime, Exception exception, int level) {
99
+ this.exception = exception;
100
+ setInstanceVariable("@level", runtime.newFixnum(level));
101
+ setInstanceVariable("@line", runtime.newFixnum(((SAXParseException)exception).getLineNumber()));
102
+ setInstanceVariable("@column", runtime.newFixnum(((SAXParseException)exception).getColumnNumber()));
103
+ setInstanceVariable("@file", stringOrNil(runtime, ((SAXParseException)exception).getSystemId()));
97
104
  }
98
105
 
99
106
  public static RubyException createXPathSyntaxError(Ruby runtime, Exception e) {
100
- RubyClass klazz = (RubyClass)
101
- runtime.getClassFromPath("Nokogiri::XML::XPath::SyntaxError");
107
+ RubyClass klazz = (RubyClass)runtime.getClassFromPath("Nokogiri::XML::XPath::SyntaxError");
102
108
  return new XmlSyntaxError(runtime, klazz, e);
103
109
  }
104
110
 
@@ -108,7 +114,6 @@ public class XmlSyntaxError extends RubyException {
108
114
  if (exception != null && exception.getMessage() != null)
109
115
  return context.getRuntime().newString(exception.getMessage());
110
116
  else
111
- return super.to_s(context);
112
-
117
+ return super.to_s(context);
113
118
  }
114
119
  }