public
Description: JREXML is an add-on for JRuby that uses a Java pull parser library to speed up REXML.
Homepage: http://caldersphere.rubyforge.org/jrexml
Clone URL: git://github.com/nicksieger/jrexml.git
Tagging 0.5.3


git-svn-id: 
http://svn.caldersphere.net/svn/main/rubyforge/jrexml/tags/0.5.3@194 
b03c2d0b-2f10-0410-a2f9-fc8001506dfa
nicksieger (author)
Wed Jan 16 14:45:24 -0800 2008
commit  028d37ae214536d040746dd11a6aab2000952b88
tree    5bc27ea6b1f0134dd72b31f0d68cd235d56d66a1
parent  e9b8b36401ae2fc25b94be35de00c858c71c1615
...
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
0
@@ -1,3 +1,7 @@
0
+= 0.5.3
0
+
0
+* Take advantage of the fact that the XPP parser expands entities for us, so that we don't have to use the ridiculously slow REXML::Text::unnormalize method.
0
+
0
 = 0.5.2
0
 
0
 * Raise REXML::ParseException on parse errors, instead of a custom error.
...
3
4
5
 
 
 
6
7
8
 
9
10
11
...
3
4
5
6
7
8
9
10
 
11
12
13
14
0
@@ -3,9 +3,12 @@ require 'spec/rake/spectask'
0
 MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "LICENSE.txt", "Rakefile",
0
   "lib/**/*.rb", "lib/xpp*", "spec/**/*.rb", "spec/*.xml"]
0
 
0
+File.open("Manifest.txt", "w") {|f| MANIFEST.each {|l| f.puts l } }
0
+
0
+require './lib/jrexml/version'
0
 begin
0
   require 'hoe'
0
- hoe = Hoe.new("jrexml", "0.5.2") do |p|
0
+ hoe = Hoe.new("jrexml", JREXML::Version) do |p|
0
     p.rubyforge_name = "caldersphere"
0
     p.url = "http://caldersphere.rubyforge.org/jrexml"
0
     p.author = "Nick Sieger"
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
...
 
1
 
 
 
 
 
 
 
 
 
 
 
2
3
4
0
@@ -1,13 +1,3 @@
0
-require 'rexml/parsers/baseparser'
0
 require 'jrexml/java_pull_parser'
0
-
0
-class REXML::Parsers::BaseParser #:nodoc:
0
- # Extend every REXML base parser with a version that uses a Java pull parser
0
- # library
0
- def self.new(*args)
0
- obj = allocate
0
- obj.extend(JREXML::JavaPullParser)
0
- obj.send :initialize, *args
0
- obj
0
- end
0
-end
0
\ No newline at end of file
0
+require 'jrexml/ext/base_parser'
0
+require 'jrexml/ext/no_unnormalize'
...
 
 
1
2
3
...
98
99
100
101
 
 
 
 
 
 
102
103
104
...
108
109
110
111
 
112
113
114
...
168
169
170
 
 
 
 
171
172
...
1
2
3
4
5
...
100
101
102
 
103
104
105
106
107
108
109
110
111
...
115
116
117
 
118
119
120
121
...
175
176
177
178
179
180
181
182
183
0
@@ -1,3 +1,5 @@
0
+require 'rexml/parseexception'
0
+
0
 module JREXML
0
   begin
0
     XmlPullParser = Java::org.xmlpull.v1.XmlPullParser
0
@@ -98,7 +100,12 @@ module JREXML
0
           when TEXT
0
             text << @source.text
0
           when ENTITY_REF
0
- text << "&#{@source.name};"
0
+ val = @source.text
0
+ if val
0
+ text << val
0
+ else
0
+ text << "&#{@source.name};"
0
+ end
0
           end
0
           event = event_stack.shift
0
           break unless event
0
@@ -108,7 +115,7 @@ module JREXML
0
           end
0
         end
0
       end
0
- convert_event_without_text_or_entityref(event)
0
+ convert_event_without_text_or_entityref(event)
0
     end
0
 
0
     def convert_event_without_text_or_entityref(event)
0
@@ -168,5 +175,9 @@ module JREXML
0
     def debug_event(event)
0
       "XmlPullParser::#{XmlPullParser::TYPES[event]}" if event
0
     end
0
+
0
+ def using_jrexml?
0
+ true
0
+ end
0
   end
0
 end
...
3
4
5
6
7
8
9
10
 
11
12
13
...
20
21
22
 
 
23
24
25
...
30
31
32
 
 
 
 
33
34
35
...
91
92
93
 
 
 
 
 
 
 
 
 
94
95
96
...
3
4
5
 
6
7
8
 
9
10
11
12
...
19
20
21
22
23
24
25
26
...
31
32
33
34
35
36
37
38
39
40
...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
0
@@ -3,11 +3,10 @@ require File.dirname(__FILE__) + '/spec_helper'
0
 describe JREXML::JavaPullParser do
0
   def parse(source)
0
     @parser = REXML::Parsers::BaseParser.new(source)
0
- @parser.extend(JREXML::JavaPullParser)
0
     @parser.stream = source
0
     (class << @parser; self; end).send :define_method, "base_events" do
0
       events = []
0
- baseparser = REXML::Parsers::BaseParser.new(source)
0
+ baseparser = REXML::Parsers::BaseParser.new_default_parser(source)
0
       loop do
0
         event = baseparser.pull
0
         events << event
0
@@ -20,6 +19,8 @@ describe JREXML::JavaPullParser do
0
 
0
   def verify_events
0
     @parser.base_events.each do |evt|
0
+ # still need to expand entities to compare to REXML's base parser
0
+ evt[1] = REXML::Text::unnormalize(evt[1]) if evt[0] == :text
0
       @parser.pull.should == evt
0
     end
0
     @parser.should be_empty
0
@@ -30,6 +31,10 @@ describe JREXML::JavaPullParser do
0
     verify_events
0
   end
0
 
0
+ it "should use JREXML by default once it's loaded" do
0
+ REXML::Parsers::BaseParser.new("<doc/>").should be_using_jrexml
0
+ end
0
+
0
   it "should parse a document consisting of a single empty element" do
0
     parse_and_verify %q(<document/>)
0
   end
0
@@ -91,6 +96,15 @@ XML
0
     parse_and_verify %q(<document>text &lt; other &gt;&#x20;text</document>)
0
   end
0
 
0
+ it "should not expand extended (e.g., HTML) entities" do
0
+ parse "<doc>&eacute;</doc>"
0
+ events = @parser.all_events
0
+
0
+ events[0].should == [:start_element, "doc", {}]
0
+ events[1].should == [:text, "&eacute;"]
0
+ events[2].should == [:end_element, "doc"]
0
+ end
0
+
0
   it "should handle a longer, more complex document (50+K atom feed)" do
0
     File.open(File.dirname(__FILE__) + "/atom_feed.xml") do |f|
0
       parse_and_verify f.read
...
1
2
3
 
 
4
5
6
...
1
 
 
2
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
0
-require 'rexml/parsers/baseparser'
0
-require 'jrexml'
0
+require 'jrexml/java_pull_parser'
0
+require 'jrexml/ext/base_parser'
0
 
0
 Spec::Runner.configure do |config|
0
   config.before :all do

Comments

    No one has commented yet.