smile-xml 1.0.0-jruby → 1.0.2-jruby
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/smile-xml.jar +0 -0
- data/src/main/java/smile/xml/AttrJ.java +160 -0
- data/src/main/java/smile/xml/AttributesJ.java +212 -0
- data/src/main/java/smile/xml/BaseJ.java +60 -0
- data/src/main/java/smile/xml/DocumentJ.java +435 -0
- data/src/main/java/smile/xml/EncodingJ.java +94 -0
- data/src/main/java/smile/xml/ErrorJ.java +162 -0
- data/src/main/java/smile/xml/NamespaceJ.java +67 -0
- data/src/main/java/smile/xml/NamespacesJ.java +62 -0
- data/src/main/java/smile/xml/NodeJ.java +1029 -0
- data/src/main/java/smile/xml/NodeSetJ.java +90 -0
- data/src/main/java/smile/xml/ParserContextJ.java +44 -0
- data/src/main/java/smile/xml/ParserJ.java +196 -0
- data/src/main/java/smile/xml/ParserOptionsJ.java +58 -0
- data/src/main/java/smile/xml/ReaderJ.java +34 -0
- data/src/main/java/smile/xml/SchemaJ.java +66 -0
- data/src/main/java/smile/xml/SmileXML.java +65 -0
- data/src/main/java/smile/xml/XmlJ.java +58 -0
- data/src/main/java/smile/xml/sax/CallbackHandler.java +113 -0
- data/src/main/java/smile/xml/sax/SaxParserCallbacksJ.java +71 -0
- data/src/main/java/smile/xml/sax/SaxParserJ.java +153 -0
- data/src/main/java/smile/xml/util/UtilJ.java +424 -0
- data/src/main/java/smile/xml/xpath/CustomNamespaceContext.java +59 -0
- data/src/main/java/smile/xml/xpath/XPathContextJ.java +154 -0
- data/src/main/java/smile/xml/xpath/XPathExpressionJ.java +62 -0
- data/src/main/java/smile/xml/xpath/XPathJ.java +36 -0
- data/src/main/java/smile/xml/xpath/XPathObjectJ.java +196 -0
- data/src/main/java/smile/xml/xpath/XPointerJ.java +32 -0
- data/src/main/ruby/xml/libxml.rb +1 -0
- data/src/main/ruby/xml.rb +5 -0
- data/src/test/ruby/etc_doc_to_s.rb +21 -0
- data/src/test/ruby/ets_doc_file.rb +17 -0
- data/src/test/ruby/ets_doc_to_s.rb +23 -0
- data/src/test/ruby/ets_gpx.rb +28 -0
- data/src/test/ruby/ets_node_gc.rb +23 -0
- data/src/test/ruby/ets_test.xml +2 -0
- data/src/test/ruby/ets_tsr.rb +11 -0
- data/src/test/ruby/model/atom.xml +13 -0
- data/src/test/ruby/model/bands.iso-8859-1.xml +5 -0
- data/src/test/ruby/model/bands.utf-8.xml +5 -0
- data/src/test/ruby/model/bands.xml +5 -0
- data/src/test/ruby/model/books.xml +146 -0
- data/src/test/ruby/model/merge_bug_data.xml +58 -0
- data/src/test/ruby/model/ruby-lang.html +238 -0
- data/src/test/ruby/model/rubynet.xml +79 -0
- data/src/test/ruby/model/shiporder.rnc +28 -0
- data/src/test/ruby/model/shiporder.rng +86 -0
- data/src/test/ruby/model/shiporder.xml +23 -0
- data/src/test/ruby/model/shiporder.xsd +31 -0
- data/src/test/ruby/model/soap.xml +27 -0
- data/src/test/ruby/model/xinclude.xml +5 -0
- data/src/test/ruby/smile_xml_test.rb +64 -0
- data/src/test/ruby/tc_attr.rb +191 -0
- data/src/test/ruby/tc_attr_decl.rb +133 -0
- data/src/test/ruby/tc_attributes.rb +135 -0
- data/src/test/ruby/tc_deprecated_require.rb +13 -0
- data/src/test/ruby/tc_document.rb +162 -0
- data/src/test/ruby/tc_document_write.rb +212 -0
- data/src/test/ruby/tc_dtd.rb +125 -0
- data/src/test/ruby/tc_error.rb +150 -0
- data/src/test/ruby/tc_html_parser.rb +140 -0
- data/src/test/ruby/tc_namespace.rb +62 -0
- data/src/test/ruby/tc_namespaces.rb +210 -0
- data/src/test/ruby/tc_node.rb +273 -0
- data/src/test/ruby/tc_node_cdata.rb +51 -0
- data/src/test/ruby/tc_node_comment.rb +33 -0
- data/src/test/ruby/tc_node_copy.rb +42 -0
- data/src/test/ruby/tc_node_edit.rb +178 -0
- data/src/test/ruby/tc_node_text.rb +73 -0
- data/src/test/ruby/tc_node_write.rb +108 -0
- data/src/test/ruby/tc_node_xlink.rb +29 -0
- data/src/test/ruby/tc_parser.rb +371 -0
- data/src/test/ruby/tc_parser_context.rb +189 -0
- data/src/test/ruby/tc_properties.rb +40 -0
- data/src/test/ruby/tc_reader.rb +306 -0
- data/src/test/ruby/tc_relaxng.rb +54 -0
- data/src/test/ruby/tc_sax_parser.rb +340 -0
- data/src/test/ruby/tc_schema.rb +59 -0
- data/src/test/ruby/tc_traversal.rb +222 -0
- data/src/test/ruby/tc_xinclude.rb +21 -0
- data/src/test/ruby/tc_xml.rb +226 -0
- data/src/test/ruby/tc_xpath.rb +210 -0
- data/src/test/ruby/tc_xpath_context.rb +80 -0
- data/src/test/ruby/tc_xpath_expression.rb +38 -0
- data/src/test/ruby/tc_xpointer.rb +74 -0
- data/src/test/ruby/test_helper.rb +23 -0
- data/src/test/ruby/test_suite.rb +41 -0
- metadata +91 -5
@@ -0,0 +1,90 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import javax.xml.xpath.XPathExpressionException;
|
4
|
+
import org.jruby.Ruby;
|
5
|
+
import org.jruby.RubyArray;
|
6
|
+
import org.jruby.RubyBoolean;
|
7
|
+
import org.jruby.RubyClass;
|
8
|
+
import org.jruby.RubyFixnum;
|
9
|
+
import org.jruby.RubyNumeric;
|
10
|
+
import org.jruby.RubyObject;
|
11
|
+
import org.jruby.anno.JRubyClass;
|
12
|
+
import org.jruby.anno.JRubyMethod;
|
13
|
+
import org.jruby.runtime.Block;
|
14
|
+
import org.jruby.runtime.ObjectAllocator;
|
15
|
+
import org.jruby.runtime.ThreadContext;
|
16
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
17
|
+
import smile.xml.util.UtilJ;
|
18
|
+
|
19
|
+
@JRubyClass(name = "LibXML::XML::Node::Set", include = "Enumerable")
|
20
|
+
public class NodeSetJ extends RubyObject {
|
21
|
+
|
22
|
+
private static final long serialVersionUID = 8212708453693594157L;
|
23
|
+
|
24
|
+
public static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
25
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
26
|
+
return new NodeSetJ(runtime, klass);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
private RubyArray array;
|
31
|
+
|
32
|
+
public static RubyClass define(Ruby runtime) {
|
33
|
+
return UtilJ.defineClass(runtime, NodeSetJ.class, ALLOCATOR);
|
34
|
+
}
|
35
|
+
|
36
|
+
private static RubyClass getRubyClass(Ruby runtime) {
|
37
|
+
return UtilJ.getClass(runtime, NodeSetJ.class);
|
38
|
+
}
|
39
|
+
|
40
|
+
public static NodeSetJ newInstance(ThreadContext context, RubyArray array) {
|
41
|
+
return (NodeSetJ) getRubyClass(context.getRuntime()).newInstance(
|
42
|
+
context, new IRubyObject[] { array }, null);
|
43
|
+
}
|
44
|
+
|
45
|
+
private NodeSetJ(Ruby runtime, RubyClass metaClass) {
|
46
|
+
super(runtime, metaClass);
|
47
|
+
}
|
48
|
+
|
49
|
+
@JRubyMethod(name = { "initialize" })
|
50
|
+
public void initialize(ThreadContext context, IRubyObject pArray) {
|
51
|
+
this.array = ((RubyArray) pArray);
|
52
|
+
}
|
53
|
+
|
54
|
+
@JRubyMethod(name = { "[]" })
|
55
|
+
public IRubyObject get(ThreadContext context, IRubyObject pIndex)
|
56
|
+
throws XPathExpressionException {
|
57
|
+
RubyNumeric index = (RubyNumeric) pIndex;
|
58
|
+
return (IRubyObject) this.array.get((int) index.getLongValue());
|
59
|
+
}
|
60
|
+
|
61
|
+
@JRubyMethod(name = { "each" })
|
62
|
+
public void each(ThreadContext context, Block block) {
|
63
|
+
for (int i = 0; i < this.array.getLength(); i++) {
|
64
|
+
IRubyObject obj = (IRubyObject) this.array.get(i);
|
65
|
+
block.yield(context, obj);
|
66
|
+
if (block.isEscaped())
|
67
|
+
break;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
@JRubyMethod(name = { "empty?" })
|
72
|
+
public RubyBoolean isEmpty(ThreadContext context)
|
73
|
+
throws XPathExpressionException {
|
74
|
+
return UtilJ.toBool(context, this.array.isEmpty());
|
75
|
+
}
|
76
|
+
|
77
|
+
@JRubyMethod(name = { "first" })
|
78
|
+
public IRubyObject getFirst(ThreadContext context)
|
79
|
+
throws XPathExpressionException {
|
80
|
+
if (this.array.isEmpty())
|
81
|
+
return context.getRuntime().getNil();
|
82
|
+
return (NodeJ) this.array.get(0);
|
83
|
+
}
|
84
|
+
|
85
|
+
@JRubyMethod(name = { "length" }, alias = { "size" })
|
86
|
+
public RubyFixnum getLength(ThreadContext context)
|
87
|
+
throws XPathExpressionException {
|
88
|
+
return context.getRuntime().newFixnum(this.array.getLength());
|
89
|
+
}
|
90
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyClass;
|
5
|
+
import org.jruby.RubyObject;
|
6
|
+
import org.jruby.anno.JRubyClass;
|
7
|
+
import org.jruby.runtime.ObjectAllocator;
|
8
|
+
import org.jruby.runtime.ThreadContext;
|
9
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
10
|
+
|
11
|
+
import smile.xml.util.UtilJ;
|
12
|
+
|
13
|
+
@JRubyClass( name="LibXML::XML::Parser::Context" )
|
14
|
+
public class ParserContextJ extends RubyObject {
|
15
|
+
|
16
|
+
|
17
|
+
private static final long serialVersionUID = -1085726141041314973L;
|
18
|
+
|
19
|
+
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
20
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
21
|
+
return new ParserContextJ(runtime, klass);
|
22
|
+
}
|
23
|
+
};
|
24
|
+
|
25
|
+
public static RubyClass define(Ruby runtime) {
|
26
|
+
return UtilJ.defineClass(runtime, ParserContextJ.class, ALLOCATOR);
|
27
|
+
}
|
28
|
+
|
29
|
+
private static RubyClass getRubyClass( ThreadContext context ) {
|
30
|
+
return UtilJ.getClass( context.getRuntime(), ParserContextJ.class );
|
31
|
+
}
|
32
|
+
|
33
|
+
private ParserContextJ(Ruby runtime, RubyClass metaClass) {
|
34
|
+
super(runtime, metaClass);
|
35
|
+
}
|
36
|
+
|
37
|
+
public static IRubyObject newInstance(ThreadContext context) {
|
38
|
+
IRubyObject[] args = {};
|
39
|
+
return getRubyClass(context).newInstance( context, args, null );
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
}
|
@@ -0,0 +1,196 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import java.io.File;
|
4
|
+
import java.io.StringReader;
|
5
|
+
|
6
|
+
import javax.xml.parsers.DocumentBuilder;
|
7
|
+
|
8
|
+
import org.jruby.Ruby;
|
9
|
+
import org.jruby.RubyClass;
|
10
|
+
import org.jruby.RubyHash;
|
11
|
+
import org.jruby.RubyModule;
|
12
|
+
import org.jruby.RubyObject;
|
13
|
+
import org.jruby.RubyString;
|
14
|
+
import org.jruby.anno.JRubyClass;
|
15
|
+
import org.jruby.anno.JRubyMethod;
|
16
|
+
import org.jruby.runtime.ObjectAllocator;
|
17
|
+
import org.jruby.runtime.ThreadContext;
|
18
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
19
|
+
import org.w3c.dom.Document;
|
20
|
+
import org.xml.sax.InputSource;
|
21
|
+
import org.xml.sax.SAXParseException;
|
22
|
+
|
23
|
+
import smile.xml.util.UtilJ;
|
24
|
+
|
25
|
+
@JRubyClass(name = "LibXML::XML::Parser" )
|
26
|
+
public class ParserJ extends RubyObject {
|
27
|
+
|
28
|
+
private static final long serialVersionUID = 4634367713101505188L;
|
29
|
+
|
30
|
+
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
31
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
32
|
+
return new ParserJ(runtime, klass);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
private RubyString fileName;
|
37
|
+
private RubyString string;
|
38
|
+
|
39
|
+
public static RubyClass define(Ruby runtime) {
|
40
|
+
return UtilJ.defineClass(runtime, ParserJ.class, ALLOCATOR );
|
41
|
+
}
|
42
|
+
|
43
|
+
private static RubyClass getRubyClass(ThreadContext context) {
|
44
|
+
return UtilJ.getClass(context.getRuntime(), ParserJ.class);
|
45
|
+
}
|
46
|
+
|
47
|
+
private static ParserJ newInstance(ThreadContext context) {
|
48
|
+
IRubyObject[] args = {};
|
49
|
+
return (ParserJ) getRubyClass( context ).newInstance(context, args, null);
|
50
|
+
}
|
51
|
+
|
52
|
+
public ParserJ(Ruby runtime, RubyClass metaClass) {
|
53
|
+
super(runtime, metaClass);
|
54
|
+
}
|
55
|
+
|
56
|
+
public static ParserJ fromFile(ThreadContext context, IRubyObject pName,
|
57
|
+
IRubyObject pHash) {
|
58
|
+
IRubyObject[] args = { pName, pHash };
|
59
|
+
return fromFile(context, getRubyClass(context), args );
|
60
|
+
}
|
61
|
+
|
62
|
+
@JRubyMethod(name = "file", module = true, required=1, optional=1)
|
63
|
+
public static ParserJ fromFile(ThreadContext context, IRubyObject klass, IRubyObject[] args ) {
|
64
|
+
|
65
|
+
if( args.length == 0 || args[0].isNil() )
|
66
|
+
throw context.getRuntime().newTypeError("can't convert nil into String");
|
67
|
+
|
68
|
+
RubyString name = (RubyString) args[0];
|
69
|
+
|
70
|
+
if( new File( name.asJavaString() ).exists() == false )
|
71
|
+
throw ErrorJ.newRaiseException(context, "Warning: failed to load external entity \"" + name.asJavaString() + "\".");
|
72
|
+
|
73
|
+
if( args.length > 1 && args[1].isNil()==false ) {
|
74
|
+
RubyHash hash = (RubyHash) args[1];
|
75
|
+
hash.get(context.getRuntime().newSymbol("encoding"));
|
76
|
+
hash.get(context.getRuntime().newSymbol("options"));
|
77
|
+
}
|
78
|
+
|
79
|
+
ParserJ parser = ParserJ.newInstance(context);
|
80
|
+
parser.fileName = name;
|
81
|
+
return parser;
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
@JRubyMethod(name = { "initialize" }, optional = 1)
|
86
|
+
public void initialize(ThreadContext context, IRubyObject[] args) {
|
87
|
+
}
|
88
|
+
|
89
|
+
@JRubyMethod(name = { "io=" })
|
90
|
+
public void setIo(ThreadContext context, IRubyObject io) {
|
91
|
+
if( io.isNil() )
|
92
|
+
throw context.getRuntime().newTypeError("Must pass in an IO object");
|
93
|
+
RubyString string = (RubyString) io.callMethod(context, "read");
|
94
|
+
this.string = string;
|
95
|
+
}
|
96
|
+
|
97
|
+
@JRubyMethod(name = { "string=" })
|
98
|
+
public void setString(ThreadContext context, IRubyObject pString) {
|
99
|
+
if( pString.isNil() ) {
|
100
|
+
throw context.getRuntime().newTypeError("");
|
101
|
+
}
|
102
|
+
this.string = ((RubyString) pString);
|
103
|
+
}
|
104
|
+
|
105
|
+
@JRubyMethod(name = "context" )
|
106
|
+
public IRubyObject getContext(ThreadContext context) throws Exception {
|
107
|
+
return ParserContextJ.newInstance( context );
|
108
|
+
}
|
109
|
+
|
110
|
+
@JRubyMethod(name = { "document=" })
|
111
|
+
public void setDocument(ThreadContext context, IRubyObject pDocument) throws Exception {
|
112
|
+
DocumentJ document = (DocumentJ) pDocument;
|
113
|
+
string = document.toString(context, new IRubyObject[]{} );
|
114
|
+
}
|
115
|
+
|
116
|
+
@JRubyMethod(name ="file=" )
|
117
|
+
public void setFile(ThreadContext context, IRubyObject pDocument) throws Exception {
|
118
|
+
string = (RubyString) UtilJ.toRubyString( context, pDocument );
|
119
|
+
}
|
120
|
+
|
121
|
+
@JRubyMethod(name = "parse")
|
122
|
+
public DocumentJ parse(ThreadContext context) throws Exception {
|
123
|
+
|
124
|
+
DocumentBuilder builder = UtilJ.getBuilder();
|
125
|
+
Document doc = null;
|
126
|
+
|
127
|
+
if (this.fileName != null) {
|
128
|
+
doc = builder.parse(this.fileName.asJavaString());
|
129
|
+
|
130
|
+
} else if (this.string != null) {
|
131
|
+
StringReader reader = new StringReader(string.asJavaString());
|
132
|
+
try {
|
133
|
+
doc = builder.parse(new InputSource(reader));
|
134
|
+
} catch( SAXParseException e ) {
|
135
|
+
throw ErrorJ.newRaiseException(context, e.getMessage() );
|
136
|
+
} finally {
|
137
|
+
reader.close();
|
138
|
+
}
|
139
|
+
} else {
|
140
|
+
throw context.getRuntime().newTypeError("");
|
141
|
+
}
|
142
|
+
DocumentJ document = DocumentJ.newInstance(context);
|
143
|
+
document.setJavaObject(doc);
|
144
|
+
|
145
|
+
if (doc.getXmlEncoding() != null)
|
146
|
+
document.setEncoding(context, context.getRuntime().newString(doc.getXmlEncoding()));
|
147
|
+
|
148
|
+
return document;
|
149
|
+
}
|
150
|
+
|
151
|
+
@JRubyMethod(name = "document", module = true)
|
152
|
+
public static ParserJ fromDocument(ThreadContext context, IRubyObject self, IRubyObject pDocument) throws Exception {
|
153
|
+
if( pDocument.isNil() )
|
154
|
+
throw context.getRuntime().newTypeError("Must pass an XML::Document object");
|
155
|
+
|
156
|
+
DocumentJ document = (DocumentJ) pDocument;
|
157
|
+
|
158
|
+
ParserJ parser = ParserJ.newInstance(context);
|
159
|
+
parser.setDocument(context, document );
|
160
|
+
return parser;
|
161
|
+
|
162
|
+
}
|
163
|
+
|
164
|
+
@JRubyMethod(name = "io", module = true)
|
165
|
+
public static ParserJ fromIo(ThreadContext context, IRubyObject klass, IRubyObject io) throws Exception {
|
166
|
+
if( io.isNil() )
|
167
|
+
throw context.getRuntime().newTypeError("Must pass in an IO object");
|
168
|
+
RubyString string = (RubyString) io.callMethod(context, "read");
|
169
|
+
ParserJ parser = ParserJ.newInstance(context);
|
170
|
+
parser.string = string;
|
171
|
+
return parser;
|
172
|
+
}
|
173
|
+
|
174
|
+
@JRubyMethod(name ="io")
|
175
|
+
public IRubyObject getIo(ThreadContext context) throws Exception {
|
176
|
+
return context.getRuntime().getNil();
|
177
|
+
}
|
178
|
+
|
179
|
+
@JRubyMethod(name = "string", module = true, required=1, optional = 1)
|
180
|
+
public static ParserJ fromString(ThreadContext context, IRubyObject klass, IRubyObject[] args) throws Exception {
|
181
|
+
|
182
|
+
if( args.length == 0 || args[0].isNil() )
|
183
|
+
throw context.getRuntime().newTypeError("wrong argument type nil (expected String)");
|
184
|
+
|
185
|
+
RubyString string = (RubyString) args[0];
|
186
|
+
RubyHash hash;
|
187
|
+
if (args.length > 1) {
|
188
|
+
hash = (RubyHash) args[1];
|
189
|
+
}
|
190
|
+
|
191
|
+
ParserJ parser = ParserJ.newInstance(context);
|
192
|
+
parser.string = string;
|
193
|
+
return parser;
|
194
|
+
}
|
195
|
+
|
196
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyModule;
|
5
|
+
import org.jruby.anno.JRubyConstant;
|
6
|
+
import org.jruby.anno.JRubyModule;
|
7
|
+
|
8
|
+
import smile.xml.util.UtilJ;
|
9
|
+
|
10
|
+
@JRubyModule(name = "LibXML::XML::Parser::Options")
|
11
|
+
public class ParserOptionsJ {
|
12
|
+
|
13
|
+
@JRubyConstant
|
14
|
+
public static final String RECOVER = null;
|
15
|
+
@JRubyConstant
|
16
|
+
public static final String NOENT = null;
|
17
|
+
@JRubyConstant
|
18
|
+
public static final String DTDLOAD = null;
|
19
|
+
@JRubyConstant
|
20
|
+
public static final String DTDATTR = null;
|
21
|
+
@JRubyConstant
|
22
|
+
public static final String DTDVALID = null;
|
23
|
+
@JRubyConstant
|
24
|
+
public static final String NOERROR = null;
|
25
|
+
@JRubyConstant
|
26
|
+
public static final String NOWARNING = null;
|
27
|
+
@JRubyConstant
|
28
|
+
public static final String PEDANTIC = null;
|
29
|
+
@JRubyConstant
|
30
|
+
public static final String NOBLANKS = null;
|
31
|
+
@JRubyConstant
|
32
|
+
public static final String SAX1 = null;
|
33
|
+
@JRubyConstant
|
34
|
+
public static final String XINCLUDE = null;
|
35
|
+
@JRubyConstant
|
36
|
+
public static final String NONET = null;
|
37
|
+
@JRubyConstant
|
38
|
+
public static final String NODICT = null;
|
39
|
+
@JRubyConstant
|
40
|
+
public static final String NSCLEAN = null;
|
41
|
+
@JRubyConstant
|
42
|
+
public static final String NOCDATA = null;
|
43
|
+
@JRubyConstant
|
44
|
+
public static final String NOXINCNODE = null;
|
45
|
+
@JRubyConstant
|
46
|
+
public static final String COMPACT = null;
|
47
|
+
@JRubyConstant
|
48
|
+
public static final String PARSE_OLD10 = null;
|
49
|
+
@JRubyConstant
|
50
|
+
public static final String NOBASEFIX = null;
|
51
|
+
@JRubyConstant
|
52
|
+
public static final String HUGE = null;
|
53
|
+
|
54
|
+
public static RubyModule define(Ruby runtime) {
|
55
|
+
return UtilJ.defineModule(runtime, ParserOptionsJ.class);
|
56
|
+
}
|
57
|
+
|
58
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyClass;
|
5
|
+
import org.jruby.RubyModule;
|
6
|
+
import org.jruby.RubyObject;
|
7
|
+
import org.jruby.runtime.ObjectAllocator;
|
8
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
9
|
+
import smile.xml.util.UtilJ;
|
10
|
+
|
11
|
+
public class ReaderJ extends RubyObject
|
12
|
+
{
|
13
|
+
private static final long serialVersionUID = -120431027715516425L;
|
14
|
+
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator()
|
15
|
+
{
|
16
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass)
|
17
|
+
{
|
18
|
+
return new ReaderJ(runtime, klass);
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
private ReaderJ(Ruby runtime, RubyClass metaClass)
|
23
|
+
{
|
24
|
+
super(runtime, metaClass);
|
25
|
+
}
|
26
|
+
|
27
|
+
public static RubyClass define(Ruby runtime)
|
28
|
+
{
|
29
|
+
RubyModule module = UtilJ.getModule(runtime, new String[] { "LibXML", "XML" });
|
30
|
+
RubyClass result = module.defineClassUnder("Reader", runtime.getObject(), ALLOCATOR);
|
31
|
+
result.defineAnnotatedMethods(ReaderJ.class);
|
32
|
+
return result;
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import javax.xml.transform.Source;
|
4
|
+
import javax.xml.transform.dom.DOMSource;
|
5
|
+
import javax.xml.validation.Schema;
|
6
|
+
import javax.xml.validation.SchemaFactory;
|
7
|
+
import org.jruby.Ruby;
|
8
|
+
import org.jruby.RubyClass;
|
9
|
+
import org.jruby.RubyModule;
|
10
|
+
import org.jruby.anno.JRubyMethod;
|
11
|
+
import org.jruby.runtime.ObjectAllocator;
|
12
|
+
import org.jruby.runtime.ThreadContext;
|
13
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
14
|
+
import org.w3c.dom.Node;
|
15
|
+
import org.xml.sax.SAXException;
|
16
|
+
import smile.xml.util.UtilJ;
|
17
|
+
|
18
|
+
public class SchemaJ extends BaseJ<Schema>
|
19
|
+
{
|
20
|
+
private static final long serialVersionUID = -6424527398086774781L;
|
21
|
+
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator()
|
22
|
+
{
|
23
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass)
|
24
|
+
{
|
25
|
+
return new SchemaJ(runtime, klass);
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
public static RubyClass define(Ruby runtime)
|
30
|
+
{
|
31
|
+
RubyModule module = UtilJ.getModule(runtime, new String[] { "LibXML", "XML" });
|
32
|
+
RubyClass result = module.defineClassUnder("Schema", runtime.getObject(), ALLOCATOR);
|
33
|
+
result.defineAnnotatedMethods(SchemaJ.class);
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
|
37
|
+
private static RubyClass getRubyClass(Ruby runtime)
|
38
|
+
{
|
39
|
+
return UtilJ.getClass(runtime, new String[] { "LibXML", "XML", "Schema" });
|
40
|
+
}
|
41
|
+
|
42
|
+
@JRubyMethod(name={"document"}, meta=true)
|
43
|
+
public static SchemaJ fromDocument(ThreadContext context, IRubyObject klass, IRubyObject pDocument) throws SAXException {
|
44
|
+
DocumentJ document = (DocumentJ)pDocument;
|
45
|
+
SchemaFactory schemaFactory = UtilJ.getSchemaFactoryInstance();
|
46
|
+
Source schemaFile = new DOMSource((Node)document.getJavaObject());
|
47
|
+
Schema schema = schemaFactory.newSchema(schemaFile);
|
48
|
+
|
49
|
+
SchemaJ result = newInstance(context);
|
50
|
+
result.setJavaObject(schema);
|
51
|
+
return result;
|
52
|
+
}
|
53
|
+
|
54
|
+
public static SchemaJ newInstance(ThreadContext context) {
|
55
|
+
return (SchemaJ)getRubyClass(context.getRuntime()).newInstance(context, new IRubyObject[0], null);
|
56
|
+
}
|
57
|
+
|
58
|
+
private SchemaJ(Ruby ruby, RubyClass clazz) {
|
59
|
+
super(ruby, clazz);
|
60
|
+
}
|
61
|
+
|
62
|
+
@JRubyMethod(name={"initialize"}, rest=true)
|
63
|
+
public void initialize(ThreadContext context, IRubyObject[] args)
|
64
|
+
{
|
65
|
+
}
|
66
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyClass;
|
5
|
+
import org.jruby.RubyModule;
|
6
|
+
import org.jruby.compiler.ir.instructions.THROW_EXCEPTION_Instr;
|
7
|
+
|
8
|
+
import smile.xml.sax.SaxParserCallbacksJ;
|
9
|
+
import smile.xml.sax.SaxParserJ;
|
10
|
+
import smile.xml.xpath.XPathContextJ;
|
11
|
+
import smile.xml.xpath.XPathExpressionJ;
|
12
|
+
import smile.xml.xpath.XPathJ;
|
13
|
+
import smile.xml.xpath.XPathObjectJ;
|
14
|
+
import smile.xml.xpath.XPointerJ;
|
15
|
+
|
16
|
+
public class SmileXML {
|
17
|
+
public static void define(Ruby runtime) {
|
18
|
+
|
19
|
+
try {
|
20
|
+
RubyModule libxml = runtime.fastGetModule("LibXML");
|
21
|
+
if (libxml == null) {
|
22
|
+
libxml = runtime.defineModule("LibXML");
|
23
|
+
}
|
24
|
+
|
25
|
+
RubyModule xml = XmlJ.define(runtime);
|
26
|
+
|
27
|
+
ParserJ.define(runtime);
|
28
|
+
ParserContextJ.define(runtime);
|
29
|
+
ParserOptionsJ.define(runtime);
|
30
|
+
DocumentJ.define(runtime);
|
31
|
+
NodeJ.define(runtime);
|
32
|
+
NodeSetJ.define(runtime);
|
33
|
+
AttributesJ.define(runtime);
|
34
|
+
AttrJ.define(runtime);
|
35
|
+
|
36
|
+
SaxParserJ.define(runtime);
|
37
|
+
SaxParserCallbacksJ.define(runtime);
|
38
|
+
|
39
|
+
XPathJ.define(runtime);
|
40
|
+
XPathObjectJ.define(runtime);
|
41
|
+
XPathContextJ.define(runtime);
|
42
|
+
XPathExpressionJ.define(runtime);
|
43
|
+
XPointerJ.define(runtime);
|
44
|
+
|
45
|
+
EncodingJ.define(runtime);
|
46
|
+
|
47
|
+
ErrorJ.define(runtime);
|
48
|
+
|
49
|
+
RubyClass ns = NamespaceJ.define(runtime);
|
50
|
+
NamespacesJ.define(runtime);
|
51
|
+
|
52
|
+
SchemaJ.define(runtime);
|
53
|
+
|
54
|
+
runtime.addModule(xml);
|
55
|
+
|
56
|
+
xml.setConstant("NS", ns);
|
57
|
+
|
58
|
+
runtime.defineGlobalConstant( "XML", xml );
|
59
|
+
|
60
|
+
} catch( RuntimeException e ) {
|
61
|
+
e.printStackTrace();
|
62
|
+
throw e;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
package smile.xml;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyModule;
|
5
|
+
import org.jruby.anno.JRubyConstant;
|
6
|
+
import org.jruby.anno.JRubyMethod;
|
7
|
+
import org.jruby.anno.JRubyModule;
|
8
|
+
import org.jruby.runtime.ThreadContext;
|
9
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
10
|
+
|
11
|
+
import smile.xml.util.UtilJ;
|
12
|
+
|
13
|
+
@JRubyModule(name="LibXML::XML")
|
14
|
+
public class XmlJ {
|
15
|
+
|
16
|
+
public static RubyModule define(Ruby runtime) {
|
17
|
+
return UtilJ.defineModule(runtime, XmlJ.class);
|
18
|
+
}
|
19
|
+
|
20
|
+
@JRubyConstant
|
21
|
+
public static final String VERSION = "1";
|
22
|
+
|
23
|
+
@JRubyConstant
|
24
|
+
public static final String VERNUM = "1";
|
25
|
+
|
26
|
+
@JRubyMethod( name="default_substitute_entities=", module=true )
|
27
|
+
public static void setDefaultSubstituteEntities( ThreadContext context, IRubyObject self, IRubyObject pValue ) {
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
@JRubyMethod( name="indent_tree_output=", module=true )
|
32
|
+
public static void setIndentTreeOutput( ThreadContext context, IRubyObject self, IRubyObject pValue ) {
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
@JRubyMethod( name="indent_tree_output", module=true )
|
37
|
+
public static IRubyObject getIndentTreeOutput( ThreadContext context, IRubyObject self ) {
|
38
|
+
return context.getRuntime().getFalse();
|
39
|
+
}
|
40
|
+
|
41
|
+
@JRubyMethod( name="default_keep_blanks=", module=true )
|
42
|
+
public static void setDefaultKeepBlanks( ThreadContext context, IRubyObject self, IRubyObject pValue ) {
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
@JRubyMethod( name="enabled_zlib?", module=true )
|
47
|
+
public static IRubyObject isEnabledZlib( ThreadContext context, IRubyObject self ) {
|
48
|
+
// TODO
|
49
|
+
return context.getRuntime().getFalse();
|
50
|
+
}
|
51
|
+
|
52
|
+
@JRubyMethod( name="enabled_zlib=", module=true )
|
53
|
+
public static void setEnabledZlib( ThreadContext context, IRubyObject self, IRubyObject pValue ) {
|
54
|
+
// TODO
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
}
|