gravitext-xmlprod 1.4.1-java → 1.5.b.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,15 @@
1
+ === 1.5.b.0 (2012-1-29)
2
+ * New Element ruby extensions and XMLHelper for IO optimization (with
3
+ perf tests)
4
+ * Add Element.detachAllChildren for convenience/efficiency
5
+ * Add selectable attribute QuoteMark.DOUBLE (default) or SINGLE mode
6
+ Encoder and Producer.
7
+ * Add Tag.WILDCARD_NS for wildcard matching of namespaces
8
+ * Add Attribute.equals and hashCode for completeness, matching
9
+ * Add shortcut DEFAULT Namespace constructor
10
+ * Add java_import(s) for jruby
11
+ * Upgrade to tarpit ~> 2.0, bundler Gemfile, gemspec (dev)
12
+
1
13
  === 1.4.1 (2011-10-1)
2
14
  * Convert ruby tests to minitest
3
15
  * Fix ruby 1.9 compatibility (in test): o.to_a -> Array( o )
data/Manifest.txt CHANGED
@@ -7,7 +7,9 @@ pom.xml
7
7
  bin/gravitext-xmlprod-perftest
8
8
  lib/gravitext-xmlprod/version.rb
9
9
  lib/gravitext-xmlprod.rb
10
+ lib/gravitext-xmlprod/extensions.rb
11
+ test/setup.rb
10
12
  test/test_dom.rb
11
13
  test/test_tree.rb
12
14
  test/xml/huffingtonpost.full.atom.xml
13
- lib/gravitext-xmlprod/gravitext-xmlprod-1.4.1.jar
15
+ lib/gravitext-xmlprod/gravitext-xmlprod-1.5.b.0.jar
data/NOTICE.txt CHANGED
@@ -1,2 +1,2 @@
1
1
  gravitext-xmlprod
2
- Copyright (c) 2008-2011 David Kellum
2
+ Copyright (c) 2008-2012 David Kellum
data/README.rdoc CHANGED
@@ -16,7 +16,7 @@ extensible XML tree representation in Java.
16
16
 
17
17
  == License
18
18
 
19
- Copyright (c) 2008-2011 David Kellum
19
+ Copyright (c) 2008-2012 David Kellum
20
20
 
21
21
  Licensed under the Apache License, Version 2.0 (the "License"); you
22
22
  may not use this file except in compliance with the License. You
data/Rakefile CHANGED
@@ -1,41 +1,7 @@
1
1
  # -*- ruby -*-
2
2
 
3
- $LOAD_PATH << './lib'
4
- require 'gravitext-xmlprod/version'
5
-
6
3
  require 'rubygems'
7
- gem 'rjack-tarpit', '~> 1.4'
4
+ require 'bundler/setup'
8
5
  require 'rjack-tarpit'
9
6
 
10
- t = RJack::TarPit.new( 'gravitext-xmlprod',
11
- Gravitext::XMLProd::VERSION,
12
- :no_assembly, :java_platform )
13
-
14
- t.specify do |h|
15
- h.developer( "David Kellum", "dek-oss@gravitext.com" )
16
- h.extra_deps << [ 'gravitext-util', '~> 1.5.0' ]
17
-
18
- h.testlib = :minitest
19
- h.extra_dev_deps += [ [ 'rjack-jdom', '~> 1.1.0.0' ],
20
- [ 'minitest', '~> 2.3' ] ]
21
-
22
- h.rubyforge_name = "gravitext"
23
- end
24
-
25
- file 'Manifest.txt' => [ 'lib/gravitext-xmlprod/version.rb' ]
26
-
27
- task :check_pom_version do
28
- t.test_line_match( 'pom.xml', /<version>/, /#{t.version}/ )
29
- end
30
- task :check_history_version do
31
- t.test_line_match( 'History.rdoc', /^==/, / #{t.version} / )
32
- end
33
- task :check_history_date do
34
- t.test_line_match( 'History.rdoc', /^==/, /\([0-9\-]+\)$/ )
35
- end
36
-
37
- task :gem => [ :check_pom_version, :check_history_version ]
38
- task :tag => [ :check_pom_version, :check_history_version, :check_history_date ]
39
- task :push => [ :check_history_date ]
40
-
41
- t.define_tasks
7
+ RJack::TarPit.new( 'gravitext-xmlprod' ).define_tasks
@@ -2,7 +2,7 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  #--
5
- # Copyright (c) 2008-2011 David Kellum
5
+ # Copyright (c) 2008-2012 David Kellum
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License"); you
8
8
  # may not use this file except in compliance with the License. You
@@ -22,6 +22,7 @@ $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
22
22
  require 'rubygems'
23
23
 
24
24
  require 'gravitext-xmlprod'
25
+ require 'gravitext-xmlprod/extensions'
25
26
  require 'gravitext-util/perftest'
26
27
  require 'optparse'
27
28
 
@@ -29,11 +30,14 @@ require 'java'
29
30
 
30
31
  class TestCollection
31
32
  include Gravitext
33
+ include Gravitext::XMLProd
32
34
  include Gravitext::Concurrent
33
35
 
34
36
  import 'com.gravitext.xml.producer.perftests.PerfTestFactory'
35
37
  import 'com.gravitext.xml.producer.perftests.StringBufferEncodePerfTest'
36
38
  import 'com.gravitext.xml.tree.TreePerfTest'
39
+ import 'com.gravitext.xml.tree.StAXUtils'
40
+ import 'com.gravitext.xml.tree.TreeUtils'
37
41
 
38
42
  def run
39
43
  options = {}
@@ -89,6 +93,31 @@ class TestCollection
89
93
  TreePerfTest::Impl.values.map do |s|
90
94
  TreePerfTest.new( xml, s, ( name == 'tree_write' ) )
91
95
  end
96
+
97
+ when 'ruby_parse'
98
+ xfile = File.join( File.dirname(__FILE__), '..',
99
+ 'test/xml/huffingtonpost.full.atom.xml' )
100
+ xml = IO.read( xfile )
101
+ [ BlockTestFactory.new( "parse_tree-ext" ) do
102
+ parse_tree( xml ).children.length
103
+ end,
104
+ BlockTestFactory.new( "stax_parse" ) do
105
+ StAXUtils::staxParse( StAXUtils::staxInput( xml ) ).children.length
106
+ end ]
107
+
108
+ when 'ruby'
109
+ xfile = File.join( File.dirname(__FILE__), '..',
110
+ 'test/xml/huffingtonpost.full.atom.xml' )
111
+
112
+ root = parse_tree( IO.read( xfile ) )
113
+
114
+ [ BlockTestFactory.new( "write_element-ext" ) do
115
+ root.to_xml.length
116
+ end,
117
+ BlockTestFactory.new( "produce_string" ) do
118
+ TreeUtils.produce_string( root, Indentor::COMPRESSED ).length
119
+ end ]
120
+
92
121
  else
93
122
  raise "No test named #{name}."
94
123
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2008-2011 David Kellum
2
+ # Copyright (c) 2008-2012 David Kellum
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you
5
5
  # may not use this file except in compliance with the License. You
@@ -19,10 +19,20 @@ require 'java'
19
19
 
20
20
  require 'gravitext-util'
21
21
 
22
- module Gravitext
22
+ module Gravitext::XMLProd
23
23
 
24
- module XMLProd
25
- require File.join( LIB_DIR, "gravitext-xmlprod-#{ VERSION }.jar" )
26
- end
24
+ require File.join( LIB_DIR, "gravitext-xmlprod-#{ VERSION }.jar" )
25
+
26
+ java_import 'com.gravitext.xml.producer.CharacterEncoder'
27
+ java_import 'com.gravitext.xml.producer.Indentor'
28
+ java_import 'com.gravitext.xml.producer.Attribute'
29
+ java_import 'com.gravitext.xml.producer.Namespace'
30
+ java_import 'com.gravitext.xml.producer.Tag'
31
+
32
+ QuoteMark = CharacterEncoder::QuoteMark
33
+
34
+ java_import 'com.gravitext.xml.tree.Characters'
35
+ java_import 'com.gravitext.xml.tree.Element'
36
+ java_import 'com.gravitext.xml.tree.Node'
27
37
 
28
38
  end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Copyright (c) 2012 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You
6
+ # may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'gravitext-xmlprod'
18
+
19
+ # Magic loader hook -> XMLService
20
+ require 'com/gravitext/xml/jruby/XML'
21
+
22
+ module Gravitext::XMLProd
23
+
24
+ import 'com.gravitext.xml.jruby.ReturnElement'
25
+
26
+ def parse_tree( input )
27
+ rval = ReturnElement.new
28
+ XMLHelper.stax_parse_string( input, rval )
29
+ rval.value
30
+ end
31
+
32
+ module_function :parse_tree
33
+
34
+ class Element
35
+
36
+ # Shorthand for attribute accessed either by name (default
37
+ # Namespace) or Attribute object.
38
+ def []( name )
39
+ attribute( name )
40
+ end
41
+
42
+ def characters
43
+ XMLHelper.element_characters( self )
44
+ end
45
+
46
+ # Return Array of child elements matching tag and/or further
47
+ # constrained where yielding to block returns true.
48
+ def select( tag = nil )
49
+ tag = Tag.new( tag, Tag.WILDCARD_NS ) unless tag.nil? || tag.is_a?( Tag )
50
+ if block_given?
51
+ children.select do |c|
52
+ c.element? && ( tag.nil? || c.tag == tag ) && yield( c )
53
+ end
54
+ else
55
+ children.select do |c|
56
+ c.element? && ( c.tag == tag )
57
+ end
58
+ end
59
+ end
60
+
61
+ # Return first child element matching tag and/or where yielding to
62
+ # block returns true. Without a block is equivalent to
63
+ # first_element.
64
+ def find( tag = nil )
65
+ tag = Tag.new( tag, Tag.WILDCARD_NS ) unless tag.nil? || tag.is_a?( Tag )
66
+ if block_given?
67
+ children.find do |c|
68
+ c.element? && ( tag.nil? || c.tag == tag ) && yield( c )
69
+ end
70
+ else
71
+ first_element( tag )
72
+ end
73
+ end
74
+
75
+ # Serialize self to String of XML, using specified Indentor and
76
+ # QuoteMark to use for attributes.
77
+ def to_xml( indentor = Indentor::COMPRESSED, qmark = QuoteMark::DOUBLE )
78
+ XMLHelper.write_element( self, indentor, qmark )
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2008-2011 David Kellum
2
+ # Copyright (c) 2008-2012 David Kellum
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you
5
5
  # may not use this file except in compliance with the License. You
@@ -16,7 +16,7 @@
16
16
 
17
17
  module Gravitext
18
18
  module XMLProd
19
- VERSION = '1.4.1'
19
+ VERSION = '1.5.b.0'
20
20
 
21
21
  LIB_DIR = File.dirname(__FILE__) # :nodoc:
22
22
  end
data/pom.xml CHANGED
@@ -4,7 +4,7 @@
4
4
  <groupId>com.gravitext</groupId>
5
5
  <artifactId>gravitext-xmlprod</artifactId>
6
6
  <packaging>jar</packaging>
7
- <version>1.4.1</version>
7
+ <version>1.5.b.0</version>
8
8
  <name>Gravitext XML Producer</name>
9
9
  <url>http://gravitext.com/oss/gravitext-xmlprod</url>
10
10
 
@@ -32,7 +32,7 @@
32
32
  <parent>
33
33
  <groupId>com.gravitext</groupId>
34
34
  <artifactId>gravitext-parent</artifactId>
35
- <version>1.6</version>
35
+ <version>1.7</version>
36
36
  <relativePath>../gravitext-parent/pom.xml</relativePath>
37
37
  </parent>
38
38
 
@@ -49,7 +49,21 @@
49
49
  <dependency>
50
50
  <groupId>com.gravitext</groupId>
51
51
  <artifactId>gravitext-util</artifactId>
52
- <version>[1.5.0,1.6.0)</version>
52
+ <version>[1.6.b,1.6.9999)</version>
53
+ </dependency>
54
+
55
+ <dependency>
56
+ <groupId>org.jruby.extras</groupId>
57
+ <artifactId>bytelist</artifactId>
58
+ <version>1.0.10</version>
59
+ <optional>true</optional>
60
+ </dependency>
61
+
62
+ <dependency>
63
+ <groupId>org.jruby</groupId>
64
+ <artifactId>jruby-core</artifactId>
65
+ <version>1.6.5.1</version>
66
+ <optional>true</optional>
53
67
  </dependency>
54
68
 
55
69
  <dependency>
data/test/setup.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'minitest/unit'
5
+ require 'minitest/autorun'
data/test/test_dom.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #.hashdot.profile += jruby-shortlived
3
3
 
4
4
  #--
5
- # Copyright (c) 2008-2011 David Kellum
5
+ # Copyright (c) 2008-2012 David Kellum
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License"); you
8
8
  # may not use this file except in compliance with the License. You
@@ -17,10 +17,7 @@
17
17
  # permissions and limitations under the License.
18
18
  #++
19
19
 
20
- require 'rubygems'
21
- require 'minitest/unit'
22
-
23
- $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
20
+ require File.join( File.dirname( __FILE__ ), "setup" )
24
21
 
25
22
  require 'gravitext-xmlprod'
26
23
 
data/test/test_tree.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #.hashdot.profile += jruby-shortlived
3
3
 
4
4
  #--
5
- # Copyright (c) 2008-2011 David Kellum
5
+ # Copyright (c) 2008-2012 David Kellum
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License"); you
8
8
  # may not use this file except in compliance with the License. You
@@ -17,19 +17,18 @@
17
17
  # permissions and limitations under the License.
18
18
  #++
19
19
 
20
- require 'rubygems'
21
- require 'minitest/unit'
22
-
23
- $LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
20
+ require File.join( File.dirname( __FILE__ ), "setup" )
24
21
 
25
22
  require 'gravitext-xmlprod'
23
+ require 'gravitext-xmlprod/extensions'
26
24
 
27
25
  class TestTree < MiniTest::Unit::TestCase
26
+ include Gravitext::XMLProd
27
+
28
28
  import 'com.gravitext.xml.tree.TreeUtils'
29
29
  import 'com.gravitext.xml.tree.SAXUtils'
30
30
  import 'com.gravitext.xml.tree.StAXUtils'
31
- import 'com.gravitext.xml.producer.Indentor'
32
- import 'com.gravitext.xml.producer.Tag'
31
+ import 'javax.xml.stream.XMLStreamException'
33
32
 
34
33
  TEST_XML = {}
35
34
 
@@ -42,9 +41,10 @@ class TestTree < MiniTest::Unit::TestCase
42
41
  XML
43
42
 
44
43
  TEST_XML[ :atts ] = <<XML
45
- <doc>
44
+ <doc xmlns="foo">
46
45
  <a att1="a1value"/>
47
46
  <b att2="a2value"/>
47
+ <b att2="a2value.1"/>
48
48
  </doc>
49
49
  XML
50
50
 
@@ -97,9 +97,7 @@ XML
97
97
  end
98
98
 
99
99
  def assert_xml( xml, root )
100
- assert_equal( xml.rstrip,
101
- TreeUtils::produceString( root, Indentor::COMPRESSED ),
102
- show_node( root ) )
100
+ assert_equal( xml.rstrip, root.to_xml, show_node( root ) )
103
101
  end
104
102
 
105
103
  def test_find
@@ -117,7 +115,7 @@ XML
117
115
  </o2>
118
116
  </doc>
119
117
  XML
120
- root = StAXUtils::staxParse( StAXUtils::staxInput( xml ) )
118
+ root = parse_tree( xml )
121
119
  assert_equal( 'text', first( root, :o1, :i1 ).characters )
122
120
  assert_equal( 'next', first( root, :o1, :i2 ).characters )
123
121
 
@@ -128,6 +126,38 @@ XML
128
126
  assert_nil( first( root, :o3 ) )
129
127
  end
130
128
 
129
+ def test_find_namespace
130
+ root = SAXUtils::saxParse( SAXUtils::saxInput( TEST_XML[ :namespace_1 ] ) )
131
+ aelm = root.find( 'a' )
132
+ assert( aelm, "found using WILDCARD_NS" )
133
+ assert_equal( "bar", aelm.tag.namespace.nameIRI, "found the right s:a tag" )
134
+ end
135
+
136
+ def test_select_attribute
137
+ root = parse_tree( TEST_XML[ :atts ] )
138
+ # Note: Default NS (foo) is here irrelevent
139
+ avals = root.select( 'b' ) { |e| e['att2'] }
140
+ assert_equal( 2, avals.length, "element with att2 found" )
141
+
142
+ att = Attribute.new( 'att2' )
143
+ assert_equal( %w[ a2value a2value.1 ],
144
+ avals.map { |e| e[ att ] },
145
+ "Matching default NS attribute" )
146
+ end
147
+
148
+ def test_select_attribute_ns
149
+ root = parse_tree( TEST_XML[ :namespace_2 ] )
150
+ att = Attribute.new( 'att2', Namespace.new( 'bar' ) )
151
+ # Note: NS prefix is irrelevant
152
+ assert_equal( 1, root.select { |e| e[ att ] == 'a2value' }.length )
153
+ end
154
+
155
+ def test_invalid_xml_error
156
+ assert_raises( XMLStreamException ) do
157
+ parse_tree( "<doc><open></doc>" )
158
+ end
159
+ end
160
+
131
161
  def first( root, *tags )
132
162
  root.first_element( *( tags.map { |s| Tag.new( s.to_s ) } ) )
133
163
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravitext-xmlprod
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.4.1
4
+ prerelease: 4
5
+ version: 1.5.b.0
6
6
  platform: java
7
7
  authors:
8
8
  - David Kellum
@@ -10,55 +10,53 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-01 00:00:00 Z
13
+ date: 2012-01-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gravitext-util
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ version_requirements: &id001 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ~>
22
21
  - !ruby/object:Gem::Version
23
- version: 1.5.0
22
+ version: 1.6.b
23
+ requirement: *id001
24
+ prerelease: false
24
25
  type: :runtime
25
- version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rjack-jdom
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ~>
33
32
  - !ruby/object:Gem::Version
34
33
  version: 1.1.0.0
34
+ requirement: *id002
35
+ prerelease: false
35
36
  type: :development
36
- version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: minitest
39
- prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ~>
44
43
  - !ruby/object:Gem::Version
45
44
  version: "2.3"
45
+ requirement: *id003
46
+ prerelease: false
46
47
  type: :development
47
- version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rjack-tarpit
50
- prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ version_requirements: &id004 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
54
53
  - - ~>
55
54
  - !ruby/object:Gem::Version
56
- version: 1.4.0
55
+ version: "2.0"
56
+ requirement: *id004
57
+ prerelease: false
57
58
  type: :development
58
- version_requirements: *id004
59
- description: |-
60
- XML utilities, includes a fast XML streaming producer and an
61
- extensible XML tree representation in Java.
59
+ description:
62
60
  email:
63
61
  - dek-oss@gravitext.com
64
62
  executables:
@@ -66,8 +64,6 @@ executables:
66
64
  extensions: []
67
65
 
68
66
  extra_rdoc_files:
69
- - Manifest.txt
70
- - NOTICE.txt
71
67
  - History.rdoc
72
68
  - README.rdoc
73
69
  files:
@@ -80,11 +76,12 @@ files:
80
76
  - bin/gravitext-xmlprod-perftest
81
77
  - lib/gravitext-xmlprod/version.rb
82
78
  - lib/gravitext-xmlprod.rb
79
+ - lib/gravitext-xmlprod/extensions.rb
80
+ - test/setup.rb
83
81
  - test/test_dom.rb
84
82
  - test/test_tree.rb
85
83
  - test/xml/huffingtonpost.full.atom.xml
86
- - lib/gravitext-xmlprod/gravitext-xmlprod-1.4.1.jar
87
- - .gemtest
84
+ - lib/gravitext-xmlprod/gravitext-xmlprod-1.5.b.0.jar
88
85
  homepage: http://gravitext.rubyforge.org
89
86
  licenses: []
90
87
 
@@ -99,20 +96,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
96
  requirements:
100
97
  - - ">="
101
98
  - !ruby/object:Gem::Version
99
+ hash: 2
100
+ segments:
101
+ - 0
102
102
  version: "0"
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  none: false
105
105
  requirements:
106
- - - ">="
106
+ - - ">"
107
107
  - !ruby/object:Gem::Version
108
- version: "0"
108
+ version: 1.3.1
109
109
  requirements: []
110
110
 
111
- rubyforge_project: gravitext
112
- rubygems_version: 1.8.10
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.11
113
113
  signing_key:
114
114
  specification_version: 3
115
115
  summary: XML utilities, includes a fast XML streaming producer and an extensible XML tree representation in Java.
116
- test_files:
117
- - test/test_dom.rb
118
- - test/test_tree.rb
116
+ test_files: []
117
+
data/.gemtest DELETED
File without changes