nokogiri-fitzsimmons 1.5.5.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +26 -0
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +666 -0
- data/CHANGELOG.rdoc +659 -0
- data/C_CODING_STYLE.rdoc +33 -0
- data/Manifest.txt +295 -0
- data/README.ja.rdoc +106 -0
- data/README.rdoc +178 -0
- data/ROADMAP.md +86 -0
- data/Rakefile +194 -0
- data/STANDARD_RESPONSES.md +47 -0
- data/Y_U_NO_GEMSPEC.md +155 -0
- data/bin/nokogiri +63 -0
- data/build_all +58 -0
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +163 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +145 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +259 -0
- data/ext/java/nokogiri/NokogiriService.java +598 -0
- data/ext/java/nokogiri/XmlAttr.java +190 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +130 -0
- data/ext/java/nokogiri/XmlCdata.java +84 -0
- data/ext/java/nokogiri/XmlComment.java +95 -0
- data/ext/java/nokogiri/XmlDocument.java +580 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +234 -0
- data/ext/java/nokogiri/XmlDtd.java +469 -0
- data/ext/java/nokogiri/XmlElement.java +97 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +152 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +162 -0
- data/ext/java/nokogiri/XmlEntityReference.java +97 -0
- data/ext/java/nokogiri/XmlNamespace.java +215 -0
- data/ext/java/nokogiri/XmlNode.java +1534 -0
- data/ext/java/nokogiri/XmlNodeSet.java +270 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +99 -0
- data/ext/java/nokogiri/XmlReader.java +456 -0
- data/ext/java/nokogiri/XmlRelaxng.java +144 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +356 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +215 -0
- data/ext/java/nokogiri/XmlSchema.java +324 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +136 -0
- data/ext/java/nokogiri/XmlText.java +119 -0
- data/ext/java/nokogiri/XmlXpathContext.java +203 -0
- data/ext/java/nokogiri/XsltStylesheet.java +360 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +243 -0
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +333 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +800 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +163 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +130 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +74 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +141 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +67 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +87 -0
- data/ext/java/nokogiri/internals/ParserContext.java +288 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +531 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +775 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +76 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParser.java +105 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +266 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/XsltExtensionFunction.java +72 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +142 -0
- data/ext/nokogiri/html_document.c +170 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +276 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +133 -0
- data/ext/nokogiri/nokogiri.h +160 -0
- data/ext/nokogiri/xml_attr.c +94 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +56 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +54 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +576 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +56 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +78 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +1480 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +467 -0
- data/ext/nokogiri/xml_node_set.h +14 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +684 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +161 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +293 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +222 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +115 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +58 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +319 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +270 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/css.rb +27 -0
- data/lib/nokogiri/css/node.rb +102 -0
- data/lib/nokogiri/css/parser.rb +720 -0
- data/lib/nokogiri/css/parser.y +258 -0
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +152 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +171 -0
- data/lib/nokogiri/decorators/slop.rb +35 -0
- data/lib/nokogiri/html.rb +37 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +254 -0
- data/lib/nokogiri/html/document_fragment.rb +41 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/entity_lookup.rb +13 -0
- data/lib/nokogiri/html/sax/parser.rb +52 -0
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/html/sax/push_parser.rb +16 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +88 -0
- data/lib/nokogiri/xml.rb +73 -0
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +431 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +267 -0
- data/lib/nokogiri/xml/document_fragment.rb +103 -0
- data/lib/nokogiri/xml/dtd.rb +22 -0
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +946 -0
- data/lib/nokogiri/xml/node/save_options.rb +61 -0
- data/lib/nokogiri/xml/node_set.rb +357 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +98 -0
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +112 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +4 -0
- data/lib/nokogiri/xml/sax/document.rb +164 -0
- data/lib/nokogiri/xml/sax/parser.rb +115 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +63 -0
- data/lib/nokogiri/xml/syntax_error.rb +47 -0
- data/lib/nokogiri/xml/text.rb +9 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +56 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xsd/xmlparser/nokogiri.rb +90 -0
- data/tasks/cross_compile.rb +153 -0
- data/tasks/nokogiri.org.rb +24 -0
- data/tasks/test.rb +95 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +341 -0
- data/test/css/test_tokenizer.rb +198 -0
- data/test/css/test_xpath_visitor.rb +91 -0
- data/test/decorators/test_slop.rb +16 -0
- data/test/files/2ch.html +108 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/staff.dtd +10 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/files/to_be_xincluded.xml +2 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/files/xinclude.xml +4 -0
- data/test/helper.rb +147 -0
- data/test/html/sax/test_parser.rb +138 -0
- data/test/html/sax/test_parser_context.rb +46 -0
- data/test/html/test_builder.rb +164 -0
- data/test/html/test_document.rb +529 -0
- data/test/html/test_document_encoding.rb +138 -0
- data/test/html/test_document_fragment.rb +254 -0
- data/test/html/test_element_description.rb +100 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +188 -0
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +135 -0
- data/test/test_css_cache.rb +45 -0
- data/test/test_encoding_handler.rb +46 -0
- data/test/test_memory_leak.rb +152 -0
- data/test/test_nokogiri.rb +132 -0
- data/test/test_reader.rb +488 -0
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +254 -0
- data/test/xml/node/test_save_options.rb +28 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +338 -0
- data/test/xml/sax/test_parser_context.rb +106 -0
- data/test/xml/sax/test_push_parser.rb +157 -0
- data/test/xml/test_attr.rb +64 -0
- data/test/xml/test_attribute_decl.rb +86 -0
- data/test/xml/test_builder.rb +248 -0
- data/test/xml/test_c14n.rb +151 -0
- data/test/xml/test_cdata.rb +48 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +742 -0
- data/test/xml/test_document_encoding.rb +28 -0
- data/test/xml/test_document_fragment.rb +216 -0
- data/test/xml/test_dtd.rb +103 -0
- data/test/xml/test_dtd_encoding.rb +33 -0
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +122 -0
- data/test/xml/test_entity_reference.rb +235 -0
- data/test/xml/test_namespace.rb +75 -0
- data/test/xml/test_node.rb +1029 -0
- data/test/xml/test_node_attributes.rb +53 -0
- data/test/xml/test_node_encoding.rb +107 -0
- data/test/xml/test_node_inheritance.rb +32 -0
- data/test/xml/test_node_reparenting.rb +374 -0
- data/test/xml/test_node_set.rb +755 -0
- data/test/xml/test_parse_options.rb +64 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +142 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +94 -0
- data/test/xml/test_syntax_error.rb +12 -0
- data/test/xml/test_text.rb +45 -0
- data/test/xml/test_unparented_node.rb +413 -0
- data/test/xml/test_xinclude.rb +83 -0
- data/test/xml/test_xpath.rb +295 -0
- data/test/xslt/test_custom_functions.rb +129 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- data/test_all +84 -0
- metadata +571 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
#ifndef NOKOGIRI_XML_XPATH_CONTEXT
|
2
|
+
#define NOKOGIRI_XML_XPATH_CONTEXT
|
3
|
+
|
4
|
+
#include <nokogiri.h>
|
5
|
+
|
6
|
+
void init_xml_xpath_context();
|
7
|
+
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name) ;
|
8
|
+
|
9
|
+
extern VALUE cNokogiriXmlXpathContext;
|
10
|
+
#endif
|
@@ -0,0 +1,270 @@
|
|
1
|
+
#include <xslt_stylesheet.h>
|
2
|
+
|
3
|
+
#include <libxslt/xsltInternals.h>
|
4
|
+
#include <libxslt/xsltutils.h>
|
5
|
+
#include <libxslt/transform.h>
|
6
|
+
#include <libexslt/exslt.h>
|
7
|
+
|
8
|
+
VALUE xslt;
|
9
|
+
|
10
|
+
int vasprintf (char **strp, const char *fmt, va_list ap);
|
11
|
+
void vasprintf_free (void *p);
|
12
|
+
|
13
|
+
static void mark(nokogiriXsltStylesheetTuple *wrapper)
|
14
|
+
{
|
15
|
+
rb_gc_mark(wrapper->func_instances);
|
16
|
+
}
|
17
|
+
|
18
|
+
static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
|
19
|
+
{
|
20
|
+
xsltStylesheetPtr doc = wrapper->ss;
|
21
|
+
|
22
|
+
NOKOGIRI_DEBUG_START(doc);
|
23
|
+
xsltFreeStylesheet(doc); /* commented out for now. */
|
24
|
+
NOKOGIRI_DEBUG_END(doc);
|
25
|
+
|
26
|
+
free(wrapper);
|
27
|
+
}
|
28
|
+
|
29
|
+
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
30
|
+
{
|
31
|
+
char * message;
|
32
|
+
|
33
|
+
va_list args;
|
34
|
+
va_start(args, msg);
|
35
|
+
vasprintf(&message, msg, args);
|
36
|
+
va_end(args);
|
37
|
+
|
38
|
+
rb_str_cat2((VALUE)ctx, message);
|
39
|
+
|
40
|
+
vasprintf_free(message);
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
|
44
|
+
{
|
45
|
+
VALUE self;
|
46
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
47
|
+
|
48
|
+
self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
|
49
|
+
mark, dealloc, wrapper);
|
50
|
+
|
51
|
+
ss->_private = (void *)self;
|
52
|
+
wrapper->ss = ss;
|
53
|
+
wrapper->func_instances = rb_ary_new();
|
54
|
+
|
55
|
+
return self;
|
56
|
+
}
|
57
|
+
|
58
|
+
/*
|
59
|
+
* call-seq:
|
60
|
+
* parse_stylesheet_doc(document)
|
61
|
+
*
|
62
|
+
* Parse a stylesheet from +document+.
|
63
|
+
*/
|
64
|
+
static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
65
|
+
{
|
66
|
+
xmlDocPtr xml, xml_cpy;
|
67
|
+
VALUE errstr, exception;
|
68
|
+
xsltStylesheetPtr ss ;
|
69
|
+
Data_Get_Struct(xmldocobj, xmlDoc, xml);
|
70
|
+
exsltRegisterAll();
|
71
|
+
|
72
|
+
errstr = rb_str_new(0, 0);
|
73
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
74
|
+
|
75
|
+
xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
|
76
|
+
ss = xsltParseStylesheetDoc(xml_cpy);
|
77
|
+
|
78
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
79
|
+
|
80
|
+
if (!ss) {
|
81
|
+
xmlFreeDoc(xml_cpy);
|
82
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
83
|
+
rb_exc_raise(exception);
|
84
|
+
}
|
85
|
+
|
86
|
+
return Nokogiri_wrap_xslt_stylesheet(ss);
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
/*
|
91
|
+
* call-seq:
|
92
|
+
* serialize(document)
|
93
|
+
*
|
94
|
+
* Serialize +document+ to an xml string.
|
95
|
+
*/
|
96
|
+
static VALUE serialize(VALUE self, VALUE xmlobj)
|
97
|
+
{
|
98
|
+
xmlDocPtr xml ;
|
99
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
100
|
+
xmlChar* doc_ptr ;
|
101
|
+
int doc_len ;
|
102
|
+
VALUE rval ;
|
103
|
+
|
104
|
+
Data_Get_Struct(xmlobj, xmlDoc, xml);
|
105
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
106
|
+
xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
|
107
|
+
rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
|
108
|
+
xmlFree(doc_ptr);
|
109
|
+
return rval ;
|
110
|
+
}
|
111
|
+
|
112
|
+
static void swallow_superfluous_xml_errors(void * userdata, xmlErrorPtr error, ...)
|
113
|
+
{
|
114
|
+
}
|
115
|
+
|
116
|
+
/*
|
117
|
+
* call-seq:
|
118
|
+
* transform(document, params = [])
|
119
|
+
*
|
120
|
+
* Apply an XSLT stylesheet to an XML::Document.
|
121
|
+
* +params+ is an array of strings used as XSLT parameters.
|
122
|
+
* returns Nokogiri::XML::Document
|
123
|
+
*
|
124
|
+
* Example:
|
125
|
+
*
|
126
|
+
* doc = Nokogiri::XML(File.read(ARGV[0]))
|
127
|
+
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
|
128
|
+
* puts xslt.transform(doc, ['key', 'value'])
|
129
|
+
*
|
130
|
+
*/
|
131
|
+
static VALUE transform(int argc, VALUE* argv, VALUE self)
|
132
|
+
{
|
133
|
+
VALUE xmldoc, paramobj, errstr, exception ;
|
134
|
+
xmlDocPtr xml ;
|
135
|
+
xmlDocPtr result ;
|
136
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
137
|
+
const char** params ;
|
138
|
+
long param_len, j ;
|
139
|
+
int parse_error_occurred ;
|
140
|
+
|
141
|
+
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
|
142
|
+
if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
|
143
|
+
if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
|
144
|
+
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
|
145
|
+
|
146
|
+
/* handle hashes as arguments. */
|
147
|
+
if(T_HASH == TYPE(paramobj)) {
|
148
|
+
paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
|
149
|
+
paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
|
150
|
+
}
|
151
|
+
|
152
|
+
Check_Type(paramobj, T_ARRAY);
|
153
|
+
|
154
|
+
Data_Get_Struct(xmldoc, xmlDoc, xml);
|
155
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
156
|
+
|
157
|
+
param_len = RARRAY_LEN(paramobj);
|
158
|
+
params = calloc((size_t)param_len+1, sizeof(char*));
|
159
|
+
for (j = 0 ; j < param_len ; j++) {
|
160
|
+
VALUE entry = rb_ary_entry(paramobj, j);
|
161
|
+
const char * ptr = StringValuePtr(entry);
|
162
|
+
params[j] = ptr;
|
163
|
+
}
|
164
|
+
params[param_len] = 0 ;
|
165
|
+
|
166
|
+
errstr = rb_str_new(0, 0);
|
167
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
168
|
+
xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)&swallow_superfluous_xml_errors);
|
169
|
+
|
170
|
+
result = xsltApplyStylesheet(wrapper->ss, xml, params);
|
171
|
+
free(params);
|
172
|
+
|
173
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
174
|
+
xmlSetGenericErrorFunc(NULL, NULL);
|
175
|
+
|
176
|
+
parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));
|
177
|
+
|
178
|
+
if (parse_error_occurred) {
|
179
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
180
|
+
rb_exc_raise(exception);
|
181
|
+
}
|
182
|
+
|
183
|
+
return Nokogiri_wrap_xml_document((VALUE)0, result) ;
|
184
|
+
}
|
185
|
+
|
186
|
+
static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
|
187
|
+
{
|
188
|
+
VALUE handler;
|
189
|
+
const char *function_name;
|
190
|
+
xsltTransformContextPtr transform;
|
191
|
+
const xmlChar *functionURI;
|
192
|
+
|
193
|
+
transform = xsltXPathGetTransformContext(ctxt);
|
194
|
+
functionURI = ctxt->context->functionURI;
|
195
|
+
handler = (VALUE)xsltGetExtData(transform, functionURI);
|
196
|
+
function_name = (const char*)(ctxt->context->function);
|
197
|
+
|
198
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(ctxt, nargs, handler, (const char*)function_name);
|
199
|
+
}
|
200
|
+
|
201
|
+
static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
|
202
|
+
{
|
203
|
+
VALUE modules = rb_iv_get(xslt, "@modules");
|
204
|
+
VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
|
205
|
+
VALUE args = { Qfalse };
|
206
|
+
VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
|
207
|
+
VALUE inst;
|
208
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
209
|
+
int i;
|
210
|
+
|
211
|
+
for(i = 0; i < RARRAY_LEN(methods); i++) {
|
212
|
+
VALUE method_name = rb_obj_as_string(RARRAY_PTR(methods)[i]);
|
213
|
+
xsltRegisterExtFunction(ctxt,
|
214
|
+
(unsigned char *)StringValuePtr(method_name), uri, method_caller);
|
215
|
+
}
|
216
|
+
|
217
|
+
Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
218
|
+
wrapper);
|
219
|
+
inst = rb_class_new_instance(0, NULL, obj);
|
220
|
+
rb_ary_push(wrapper->func_instances, inst);
|
221
|
+
|
222
|
+
return (void *)inst;
|
223
|
+
}
|
224
|
+
|
225
|
+
static void shutdownFunc(xsltTransformContextPtr ctxt,
|
226
|
+
const xmlChar *uri, void *data)
|
227
|
+
{
|
228
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
229
|
+
|
230
|
+
Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
231
|
+
wrapper);
|
232
|
+
|
233
|
+
rb_ary_clear(wrapper->func_instances);
|
234
|
+
}
|
235
|
+
|
236
|
+
/*
|
237
|
+
* call-seq:
|
238
|
+
* register(uri, custom_handler_class)
|
239
|
+
*
|
240
|
+
* Register a class that implements custom XLST transformation functions.
|
241
|
+
*/
|
242
|
+
static VALUE registr(VALUE self, VALUE uri, VALUE obj)
|
243
|
+
{
|
244
|
+
VALUE modules = rb_iv_get(self, "@modules");
|
245
|
+
if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set");
|
246
|
+
|
247
|
+
rb_hash_aset(modules, uri, obj);
|
248
|
+
xsltRegisterExtModule((unsigned char *)StringValuePtr(uri), initFunc, shutdownFunc);
|
249
|
+
return self;
|
250
|
+
}
|
251
|
+
|
252
|
+
VALUE cNokogiriXsltStylesheet ;
|
253
|
+
void init_xslt_stylesheet()
|
254
|
+
{
|
255
|
+
VALUE nokogiri;
|
256
|
+
VALUE klass;
|
257
|
+
|
258
|
+
nokogiri = rb_define_module("Nokogiri");
|
259
|
+
xslt = rb_define_module_under(nokogiri, "XSLT");
|
260
|
+
klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
|
261
|
+
|
262
|
+
rb_iv_set(xslt, "@modules", rb_hash_new());
|
263
|
+
|
264
|
+
cNokogiriXsltStylesheet = klass;
|
265
|
+
|
266
|
+
rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
|
267
|
+
rb_define_singleton_method(xslt, "register", registr, 2);
|
268
|
+
rb_define_method(klass, "serialize", serialize, 1);
|
269
|
+
rb_define_method(klass, "transform", transform, -1);
|
270
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef NOKOGIRI_XSLT_STYLESHEET
|
2
|
+
#define NOKOGIRI_XSLT_STYLESHEET
|
3
|
+
|
4
|
+
#include <nokogiri.h>
|
5
|
+
|
6
|
+
void init_xslt_stylesheet();
|
7
|
+
|
8
|
+
extern VALUE cNokogiriXsltStylesheet ;
|
9
|
+
|
10
|
+
typedef struct _nokogiriXsltStylesheetTuple {
|
11
|
+
xsltStylesheetPtr ss;
|
12
|
+
VALUE func_instances;
|
13
|
+
} nokogiriXsltStylesheetTuple;
|
14
|
+
#endif
|
data/lib/isorelax.jar
ADDED
Binary file
|
data/lib/jing.jar
ADDED
Binary file
|
data/lib/nekodtd.jar
ADDED
Binary file
|
data/lib/nekohtml.jar
ADDED
Binary file
|
data/lib/nokogiri.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Modify the PATH on windows so that the external DLLs will get loaded.
|
3
|
+
|
4
|
+
require 'rbconfig'
|
5
|
+
ENV['PATH'] = [File.expand_path(
|
6
|
+
File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
|
7
|
+
), ENV['PATH']].compact.join(';') if RbConfig::CONFIG['host_os'] =~ /(mswin|mingw)/i
|
8
|
+
|
9
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
10
|
+
# The line below caused a problem on non-GAE rack environment.
|
11
|
+
# unless defined?(JRuby::Rack::VERSION) || defined?(AppEngine::ApiProxy)
|
12
|
+
#
|
13
|
+
# However, simply cutting defined?(JRuby::Rack::VERSION) off resulted in
|
14
|
+
# an unable-to-load-nokogiri problem. Thus, now, Nokogiri checks the presense
|
15
|
+
# of appengine-rack.jar in $LOAD_PATH. If Nokogiri is on GAE, Nokogiri
|
16
|
+
# should skip loading xml jars. This is because those are in WEB-INF/lib and
|
17
|
+
# already set in the classpath.
|
18
|
+
unless $LOAD_PATH.to_s.include?("appengine-rack")
|
19
|
+
require 'isorelax.jar'
|
20
|
+
require 'jing.jar'
|
21
|
+
require 'nekohtml.jar'
|
22
|
+
require 'nekodtd.jar'
|
23
|
+
require 'xercesImpl.jar'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'nokogiri/nokogiri'
|
28
|
+
require 'nokogiri/version'
|
29
|
+
require 'nokogiri/syntax_error'
|
30
|
+
require 'nokogiri/xml'
|
31
|
+
require 'nokogiri/xslt'
|
32
|
+
require 'nokogiri/html'
|
33
|
+
require 'nokogiri/decorators/slop'
|
34
|
+
require 'nokogiri/css'
|
35
|
+
require 'nokogiri/html/builder'
|
36
|
+
|
37
|
+
# Nokogiri parses and searches XML/HTML very quickly, and also has
|
38
|
+
# correctly implemented CSS3 selector support as well as XPath support.
|
39
|
+
#
|
40
|
+
# Parsing a document returns either a Nokogiri::XML::Document, or a
|
41
|
+
# Nokogiri::HTML::Document depending on the kind of document you parse.
|
42
|
+
#
|
43
|
+
# Here is an example:
|
44
|
+
#
|
45
|
+
# require 'nokogiri'
|
46
|
+
# require 'open-uri'
|
47
|
+
#
|
48
|
+
# # Get a Nokogiri::HTML:Document for the page we’re interested in...
|
49
|
+
#
|
50
|
+
# doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
|
51
|
+
#
|
52
|
+
# # Do funky things with it using Nokogiri::XML::Node methods...
|
53
|
+
#
|
54
|
+
# ####
|
55
|
+
# # Search for nodes by css
|
56
|
+
# doc.css('h3.r a.l').each do |link|
|
57
|
+
# puts link.content
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# See Nokogiri::XML::Node#css for more information about CSS searching.
|
61
|
+
# See Nokogiri::XML::Node#xpath for more information about XPath searching.
|
62
|
+
module Nokogiri
|
63
|
+
class << self
|
64
|
+
###
|
65
|
+
# Parse an HTML or XML document. +string+ contains the document.
|
66
|
+
def parse string, url = nil, encoding = nil, options = nil
|
67
|
+
doc =
|
68
|
+
if string.respond_to?(:read) ||
|
69
|
+
string =~ /^\s*<[^Hh>]*html/i # Probably html
|
70
|
+
Nokogiri.HTML(
|
71
|
+
string,
|
72
|
+
url,
|
73
|
+
encoding, options || XML::ParseOptions::DEFAULT_HTML
|
74
|
+
)
|
75
|
+
else
|
76
|
+
Nokogiri.XML(string, url, encoding,
|
77
|
+
options || XML::ParseOptions::DEFAULT_XML)
|
78
|
+
end
|
79
|
+
yield doc if block_given?
|
80
|
+
doc
|
81
|
+
end
|
82
|
+
|
83
|
+
###
|
84
|
+
# Create a new Nokogiri::XML::DocumentFragment
|
85
|
+
def make input = nil, opts = {}, &blk
|
86
|
+
if input
|
87
|
+
Nokogiri::HTML.fragment(input).children.first
|
88
|
+
else
|
89
|
+
Nokogiri(&blk)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
###
|
94
|
+
# Parse a document and add the Slop decorator. The Slop decorator
|
95
|
+
# implements method_missing such that methods may be used instead of CSS
|
96
|
+
# or XPath. For example:
|
97
|
+
#
|
98
|
+
# doc = Nokogiri::Slop(<<-eohtml)
|
99
|
+
# <html>
|
100
|
+
# <body>
|
101
|
+
# <p>first</p>
|
102
|
+
# <p>second</p>
|
103
|
+
# </body>
|
104
|
+
# </html>
|
105
|
+
# eohtml
|
106
|
+
# assert_equal('second', doc.html.body.p[1].text)
|
107
|
+
#
|
108
|
+
def Slop(*args, &block)
|
109
|
+
Nokogiri(*args, &block).slop!
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
###
|
115
|
+
# Parser a document contained in +args+. Nokogiri will try to guess what
|
116
|
+
# type of document you are attempting to parse. For more information, see
|
117
|
+
# Nokogiri.parse
|
118
|
+
#
|
119
|
+
# To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
|
120
|
+
def Nokogiri(*args, &block)
|
121
|
+
if block_given?
|
122
|
+
builder = Nokogiri::HTML::Builder.new(&block)
|
123
|
+
return builder.doc.root
|
124
|
+
else
|
125
|
+
Nokogiri.parse(*args)
|
126
|
+
end
|
127
|
+
end
|
data/lib/nokogiri/css.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'nokogiri/css/node'
|
2
|
+
require 'nokogiri/css/xpath_visitor'
|
3
|
+
x = $-w
|
4
|
+
$-w = false
|
5
|
+
require 'nokogiri/css/parser'
|
6
|
+
$-w = x
|
7
|
+
|
8
|
+
require 'nokogiri/css/tokenizer'
|
9
|
+
require 'nokogiri/css/syntax_error'
|
10
|
+
|
11
|
+
module Nokogiri
|
12
|
+
module CSS
|
13
|
+
class << self
|
14
|
+
###
|
15
|
+
# Parse this CSS selector in +selector+. Returns an AST.
|
16
|
+
def parse selector
|
17
|
+
Parser.new.parse selector
|
18
|
+
end
|
19
|
+
|
20
|
+
###
|
21
|
+
# Get the XPath for +selector+.
|
22
|
+
def xpath_for selector, options={}
|
23
|
+
Parser.new(options[:ns] || {}).xpath_for selector, options
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|