saxon-xslt 0.2.0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ tmp
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in saxon-xslt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matt Patterson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Saxon::Xslt
2
+
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
+
5
+ This is a super-minimal first cut, it doesn't do many, many, things that it should.
6
+
7
+ It only runs under JRuby.
8
+
9
+ [![Build Status](https://travis-ci.org/fidothe/saxon-xslt.png)](https://travis-ci.org/fidothe/saxon-xslt)
10
+
11
+ You can find Saxon HE at http://sourceforge.net/projects/saxon/ and Saxonica at http://www.saxonica.com/
12
+
13
+ Saxon HE is (c) Michael H. Kay and released under the Mozilla MPL 1.0 (http://www.mozilla.org/MPL/1.0/)
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'saxon-xslt'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install saxon-xslt
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require 'saxon-xslt'
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)
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/saxon-xslt.rb ADDED
@@ -0,0 +1 @@
1
+ require 'saxon/xslt'
@@ -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
data/lib/saxon/xslt.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'saxon/s9api'
2
+ require 'saxon/source_helpers'
3
+ require 'saxon/processor'
4
+ require 'saxon/xml'
5
+
6
+ module Saxon
7
+ def self.XSLT(string_or_io)
8
+ Saxon::Processor.default.XSLT(string_or_io)
9
+ end
10
+
11
+ module XSLT
12
+ class Stylesheet
13
+ include Saxon::SourceHelpers
14
+
15
+ def initialize(processor, string_or_io)
16
+ compiler = processor.newXsltCompiler()
17
+ @xslt = compiler.compile(to_stream_source(string_or_io))
18
+ end
19
+
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
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Saxon
2
+ module XSLT
3
+ VERSION = "0.2.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'saxon/xslt/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "saxon-xslt"
8
+ gem.version = Saxon::XSLT::VERSION
9
+ gem.authors = ["Matt Patterson"]
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. Sticks closely to the Nokogiri API}
12
+ gem.summary = %q{Saxon 9.4 HE XSLT 2.0 for JRuby with Nokogiri's API}
13
+ gem.homepage = "https://github.com/fidothe/saxon-xslt"
14
+ gem.licenses = ["MIT", "MPL-1.0"]
15
+ gem.platform = 'java'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.add_development_dependency('rake', '~> 10.1.0')
23
+ gem.add_development_dependency('rspec', '~> 2.14.0')
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 ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saxon-xslt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.0.1
6
+ platform: java
7
+ authors:
8
+ - Matt Patterson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-19 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
47
+ email:
48
+ - matt@reprocessed.org
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .ruby-version
55
+ - .travis.yml
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
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
65
+ - lib/saxon/xslt.rb
66
+ - lib/saxon/xslt/version.rb
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
74
+ - vendor/saxonica/saxon9-unpack.jar
75
+ - vendor/saxonica/saxon9he.jar
76
+ homepage: https://github.com/fidothe/saxon-xslt
77
+ licenses:
78
+ - MIT
79
+ - MPL-1.0
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ none: false
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ none: false
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
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