saxon-xslt 0.0.3-universal-java-1.6 → 0.2.0-universal-java-1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.4
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ jruby-19mode
4
+ jdk:
5
+ - openjdk7
6
+ - oraclejdk7
7
+ - openjdk6
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # Saxon::Xslt
2
2
 
3
- Wraps the Saxon 9 HE XSLT processor Java API so it's easy to use from your JRuby project
3
+ Wraps the Saxon 9 HE XSLT processor Java API so it's easy to use from your JRuby project, with an API modelled on Nokogiri's.
4
4
 
5
- This is a super-minimal first cut, it doesn't do many, many, things that it should and it is entirely untested. You probably shouldn't be using in production systems.
5
+ This is a super-minimal first cut, it doesn't do many, many, things that it should.
6
6
 
7
7
  It only runs under JRuby.
8
8
 
9
+ [![Build Status](https://travis-ci.org/fidothe/saxon-xslt.png)](https://travis-ci.org/fidothe/saxon-xslt)
10
+
9
11
  You can find Saxon HE at http://sourceforge.net/projects/saxon/ and Saxonica at http://www.saxonica.com/
10
12
 
11
13
  Saxon HE is (c) Michael H. Kay and released under the Mozilla MPL 1.0 (http://www.mozilla.org/MPL/1.0/)
@@ -28,8 +30,9 @@ Or install it yourself as:
28
30
 
29
31
  ```ruby
30
32
  require 'saxon-xslt'
31
- transformer = Saxon::Xslt.new('/path/to/your.xsl')
32
- output = transformer.transform('/path/to/your.xml')
33
+ transformer = Saxon.XSLT(File.open('/path/to/your.xsl'))
34
+ input = Saxon.XML(File.open('/path/to/your.xml'))
35
+ output = transformer.transform(input)
33
36
  ```
34
37
 
35
38
  ## Contributing
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ require 'saxon/s9api'
2
+ require 'saxon/xslt'
3
+ require 'saxon/xml'
4
+
5
+ module Saxon
6
+ class Processor
7
+ def self.default
8
+ @processor ||= new
9
+ end
10
+
11
+ def initialize
12
+ @processor = S9API::Processor.new(false)
13
+ end
14
+
15
+ def XSLT(*args)
16
+ Saxon::XSLT::Stylesheet.new(@processor, *args)
17
+ end
18
+
19
+ def XML(*args)
20
+ Saxon::XML::Document.new(@processor, *args)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ require 'java'
2
+ $CLASSPATH << File.expand_path('../../../vendor/saxonica/saxon9he.jar', __FILE__)
3
+ $CLASSPATH << File.expand_path('../../../vendor/saxonica/saxon9-unpack.jar', __FILE__)
4
+
5
+ java_import javax.xml.transform.stream.StreamSource
6
+
7
+ module Saxon
8
+ module S9API
9
+ java_import 'net.sf.saxon.s9api.Processor'
10
+ java_import 'net.sf.saxon.s9api.XdmDestination'
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Saxon
2
+ module SourceHelpers
3
+ private
4
+
5
+ def to_stream_source(path_io_or_string)
6
+ StreamSource.new(to_inputstream(path_io_or_string))
7
+ end
8
+
9
+ def to_inputstream(path_io_or_string)
10
+ return path_io_or_string.to_inputstream if path_io_or_string.respond_to?(:read)
11
+ return java.io.StringReader.new(path_io_or_string)
12
+ end
13
+ end
14
+ end
data/lib/saxon/xml.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'saxon/s9api'
2
+ require 'saxon/source_helpers'
3
+ require 'saxon/processor'
4
+
5
+ module Saxon
6
+ def self.XML(string_or_io)
7
+ Saxon::Processor.default.XML(string_or_io)
8
+ end
9
+
10
+ module XML
11
+ class Document
12
+ class << self
13
+ include Saxon::SourceHelpers
14
+
15
+ def new(processor, string_or_io)
16
+ builder = processor.newDocumentBuilder()
17
+ builder.build(to_stream_source(string_or_io))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Saxon
2
- class Xslt
3
- VERSION = "0.0.3"
2
+ module XSLT
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/saxon/xslt.rb CHANGED
@@ -1,39 +1,30 @@
1
- require 'saxon/xslt/version'
2
- require 'java'
3
- $CLASSPATH << File.expand_path('../../../vendor/saxonica/saxon9he.jar', __FILE__)
4
- $CLASSPATH << File.expand_path('../../../vendor/saxonica/saxon9-unpack.jar', __FILE__)
5
-
6
- java_import javax.xml.transform.stream.StreamSource
1
+ require 'saxon/s9api'
2
+ require 'saxon/source_helpers'
3
+ require 'saxon/processor'
4
+ require 'saxon/xml'
7
5
 
8
6
  module Saxon
9
- module S9API
10
- java_import 'net.sf.saxon.s9api.Processor'
7
+ def self.XSLT(string_or_io)
8
+ Saxon::Processor.default.XSLT(string_or_io)
11
9
  end
12
10
 
13
- class Xslt
14
- def self.compile(xslt_path)
15
- new(xslt_path)
16
- end
11
+ module XSLT
12
+ class Stylesheet
13
+ include Saxon::SourceHelpers
17
14
 
18
- def initialize(xslt_path)
19
- @processor = S9API::Processor.new(false)
20
- @compiler = @processor.newXsltCompiler()
21
- @xslt = @compiler.compile(StreamSource.new(java.io.File.new(xslt_path)))
22
- end
15
+ def initialize(processor, string_or_io)
16
+ compiler = processor.newXsltCompiler()
17
+ @xslt = compiler.compile(to_stream_source(string_or_io))
18
+ end
23
19
 
24
- def transform(xml_path_or_io)
25
- unless xml_path_or_io.respond_to?(:read)
26
- xml_path_or_io = File.open(xml_path_or_io, 'r')
20
+ def transform(xdm_node)
21
+ output = S9API::XdmDestination.new
22
+ transformer = @xslt.load
23
+ transformer.setInitialContextNode(xdm_node)
24
+ transformer.setDestination(output)
25
+ transformer.transform
26
+ output.getXdmNode
27
27
  end
28
- serializer = @processor.newSerializer()
29
- output = java.io.StringWriter.new()
30
- serializer.setOutputWriter(output)
31
- xml = @processor.newDocumentBuilder().build(StreamSource.new(xml_path_or_io.to_inputstream))
32
- transformer = @xslt.load
33
- transformer.setInitialContextNode(xml)
34
- transformer.setDestination(serializer)
35
- transformer.transform
36
- output.toString
37
28
  end
38
29
  end
39
30
  end
data/saxon-xslt.gemspec CHANGED
@@ -5,11 +5,11 @@ require 'saxon/xslt/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "saxon-xslt"
8
- gem.version = Saxon::Xslt::VERSION
8
+ gem.version = Saxon::XSLT::VERSION
9
9
  gem.authors = ["Matt Patterson"]
10
10
  gem.email = ["matt@reprocessed.org"]
11
- gem.description = %q{Wraps the Saxon 9.4 HE XSLT 2.0 processor so that you can transform XSLT 2 stylesheets in JRuby}
12
- gem.summary = %q{Saxon 9.4 HE XSLT 2.0 for JRuby}
11
+ gem.description = %q{Wraps the Saxon 9.4 HE XSLT 2.0 processor so that you can transform XSLT 2 stylesheets in JRuby. Sticks closely to the Nokogiri API}
12
+ gem.summary = %q{Saxon 9.4 HE XSLT 2.0 for JRuby with Nokogiri's API}
13
13
  gem.homepage = "https://github.com/fidothe/saxon-xslt"
14
14
  gem.licenses = ["MIT", "MPL-1.0"]
15
15
  gem.platform = Gem::Platform.local
@@ -18,4 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
20
  gem.require_paths = ["lib"]
21
+
22
+ gem.add_development_dependency('rake', '~> 10.1.0')
23
+ gem.add_development_dependency('rspec', '~> 2.14.0')
21
24
  end
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <input/>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
3
+ <xsl:template match="input">
4
+ <output/>
5
+ </xsl:template>
6
+ <xsl:template match="output">
7
+ <piped/>
8
+ </xsl:template>
9
+ </xsl:stylesheet>
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'saxon/processor'
3
+
4
+ describe Saxon::Processor do
5
+ let(:processor) { Saxon::Processor.new }
6
+ let(:xsl_file) { File.open(fixture_path('eg.xsl')) }
7
+
8
+ it "can make a new XSLT instance" do
9
+ expect(processor.XSLT(xsl_file)).to respond_to(:transform)
10
+ end
11
+
12
+ it "can make a new XML instance" do
13
+ expect(processor.XML(xsl_file)).to respond_to(:getNodeKind)
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'saxon/xml'
3
+
4
+ describe Saxon::XML do
5
+ context "parsing a document" do
6
+ it "can parse a document from a File object" do
7
+ expect(Saxon.XML(File.open(fixture_path('eg.xml')))).to respond_to(:getNodeKind)
8
+ end
9
+
10
+ it "can parse a document from a string" do
11
+ xml = File.read(fixture_path('eg.xml'))
12
+ expect(Saxon.XML(xml)).to respond_to(:getNodeKind)
13
+ end
14
+
15
+ it "can parse a document from an IO object" do
16
+ xml = File.read(fixture_path('eg.xml'))
17
+ io = StringIO.new(xml)
18
+ expect(Saxon.XML(io)).to respond_to(:getNodeKind)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'saxon-xslt'
3
+ require 'stringio'
4
+
5
+ describe Saxon::XSLT do
6
+ context "compiling the stylesheet" do
7
+ it "can compile a stylesheet from a File object" do
8
+ expect(Saxon.XSLT(File.open(fixture_path('eg.xsl')))).to respond_to(:transform)
9
+ end
10
+
11
+ it "can compile a stylesheet from a string" do
12
+ xsl = File.read(fixture_path('eg.xsl'))
13
+ expect(Saxon.XSLT(xsl)).to respond_to(:transform)
14
+ end
15
+
16
+ it "can compile a stylesheet from an IO object" do
17
+ xsl = File.read(fixture_path('eg.xsl'))
18
+ io = StringIO.new(xsl)
19
+ expect(Saxon.XSLT(io)).to respond_to(:transform)
20
+ end
21
+ end
22
+
23
+ context "transforming a document" do
24
+ context "emitting a Document object as the result" do
25
+ let(:xsl) { Saxon.XSLT(File.open(fixture_path('eg.xsl'))) }
26
+ let(:xml) { Saxon.XML(File.open(fixture_path('eg.xml'))) }
27
+
28
+ it "takes a Document object as input for a transformation" do
29
+ expect(xsl.transform(xml)).to respond_to(:getNodeKind)
30
+ end
31
+
32
+ context "the transform result" do
33
+ let(:result) { xsl.transform(xml) }
34
+
35
+ it "was produced by a correctly executed XSLT" do
36
+ expect(result.to_s.strip).to eq('<output/>')
37
+ end
38
+
39
+ it "can be used as the input document for a transform" do
40
+ expect(xsl.transform(result).to_s.strip).to eq('<piped/>')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ module FixtureHelpers
2
+ def fixture_path(path)
3
+ File.expand_path(File.join('../fixtures', path), __FILE__)
4
+ end
5
+ end
6
+
7
+ RSpec.configure do |c|
8
+ c.include FixtureHelpers
9
+ end
Binary file
Binary file
metadata CHANGED
@@ -2,16 +2,48 @@
2
2
  name: saxon-xslt
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.2.0
6
6
  platform: universal-java-1.6
7
7
  authors:
8
8
  - Matt Patterson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Wraps the Saxon 9.4 HE XSLT 2.0 processor so that you can transform XSLT 2 stylesheets in JRuby
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 10.1.0
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 10.1.0
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 2.14.0
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: 2.14.0
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ description: Wraps the Saxon 9.4 HE XSLT 2.0 processor so that you can transform XSLT 2 stylesheets in JRuby. Sticks closely to the Nokogiri API
15
47
  email:
16
48
  - matt@reprocessed.org
17
49
  executables: []
@@ -19,15 +51,26 @@ extensions: []
19
51
  extra_rdoc_files: []
20
52
  files:
21
53
  - .gitignore
22
- - .rbenv-version
54
+ - .ruby-version
55
+ - .travis.yml
23
56
  - Gemfile
24
57
  - LICENSE.txt
25
58
  - README.md
26
59
  - Rakefile
27
60
  - lib/saxon-xslt.rb
61
+ - lib/saxon/processor.rb
62
+ - lib/saxon/s9api.rb
63
+ - lib/saxon/source_helpers.rb
64
+ - lib/saxon/xml.rb
28
65
  - lib/saxon/xslt.rb
29
66
  - lib/saxon/xslt/version.rb
30
67
  - saxon-xslt.gemspec
68
+ - spec/fixtures/eg.xml
69
+ - spec/fixtures/eg.xsl
70
+ - spec/saxon/processor_spec.rb
71
+ - spec/saxon/xml_spec.rb
72
+ - spec/saxon/xslt_spec.rb
73
+ - spec/spec_helper.rb
31
74
  - vendor/saxonica/saxon9-unpack.jar
32
75
  - vendor/saxonica/saxon9he.jar
33
76
  homepage: https://github.com/fidothe/saxon-xslt
@@ -40,22 +83,26 @@ require_paths:
40
83
  - lib
41
84
  required_ruby_version: !ruby/object:Gem::Requirement
42
85
  requirements:
43
- - - ! '>='
86
+ - - '>='
44
87
  - !ruby/object:Gem::Version
45
- version: !binary |-
46
- MA==
88
+ version: '0'
47
89
  none: false
48
90
  required_rubygems_version: !ruby/object:Gem::Requirement
49
91
  requirements:
50
- - - ! '>='
92
+ - - '>='
51
93
  - !ruby/object:Gem::Version
52
- version: !binary |-
53
- MA==
94
+ version: '0'
54
95
  none: false
55
96
  requirements: []
56
97
  rubyforge_project:
57
98
  rubygems_version: 1.8.24
58
99
  signing_key:
59
100
  specification_version: 3
60
- summary: Saxon 9.4 HE XSLT 2.0 for JRuby
61
- test_files: []
101
+ summary: Saxon 9.4 HE XSLT 2.0 for JRuby with Nokogiri's API
102
+ test_files:
103
+ - spec/fixtures/eg.xml
104
+ - spec/fixtures/eg.xsl
105
+ - spec/saxon/processor_spec.rb
106
+ - spec/saxon/xml_spec.rb
107
+ - spec/saxon/xslt_spec.rb
108
+ - spec/spec_helper.rb
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- jruby-1.7.1