simplyx 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Daniel Hahn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = simplyx
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Daniel Hahn. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "simplyx"
8
+ gem.summary = "Simple XML tools for JRuby"
9
+ gem.description = "Simple XML tools for JRuby, e.g. XSLT transformations"
10
+ gem.email = "ghub@limitedcreativity.org"
11
+ gem.homepage = "http://github.com/net7/simplyx"
12
+ gem.authors = ["Danilo Giacomi", "Daniel Hahn"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "simplyx #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/java/saxon9.jar ADDED
Binary file
data/lib/simplyx.rb ADDED
@@ -0,0 +1 @@
1
+ require 'simplyx/jxslt'
@@ -0,0 +1,75 @@
1
+ include Java
2
+ module Simplyx
3
+ java_dir = File.join(File.dirname(__FILE__), '..', '..', 'java')
4
+ Dir["#{java_dir}/saxon*.jar"].each { |jar| require jar }
5
+ include_class "javax.xml.transform.TransformerFactory"
6
+ include_class "javax.xml.transform.Transformer"
7
+ include_class "javax.xml.transform.stream.StreamSource"
8
+ include_class "javax.xml.transform.stream.StreamResult"
9
+ include_class "java.lang.System"
10
+
11
+ class XsltProcessor
12
+
13
+ puts $CLASSPATH
14
+
15
+ # This is used to perform xsltransformation, you should pass it the xsl and
16
+ # xml file paths, and some parameters (an hash) if you need them
17
+ def self.perform_transformation(xsl_file, xml_file, transformer_parameters=nil)
18
+ file = File.open(xsl_file)
19
+ xsl = file.read
20
+ file.close
21
+ file = File.open(xml_file)
22
+ xml = file.read
23
+ file.close
24
+ saxon = Simplyx::Saxon.new
25
+ output = saxon.transform(xsl, xml, nil, options = {:in => "string", :out => "string", :xsl => "string", :transformer_parameters => transformer_parameters})
26
+ end
27
+
28
+ def transform(xslt, infile, outfile, options)
29
+ if options[:in] == "stream"
30
+ in_var = StreamSource.new(infile)
31
+ else
32
+ sr = java.io.StringReader.new(infile)
33
+ in_var = StreamSource.new(sr)
34
+ end
35
+ if options[:out] == "stream"
36
+ out_var = StreamResult.new(outfile)
37
+ else
38
+ sw = java.io.StringWriter.new()
39
+ out_var = StreamResult.new(sw)
40
+ end
41
+ if options[:xslt] == "stream"
42
+ xslt_var = StreamSource.new(xslt)
43
+ else
44
+ sxs = java.io.StringReader.new(xslt)
45
+ xslt_var = StreamSource.new(sxs)
46
+ end
47
+ transformer = @tf.newTransformer(xslt_var)
48
+ unless options[:transformer_parameters].nil?
49
+ options[:transformer_parameters].each do |key, value|
50
+ transformer.setParameter(key, java.lang.String.new(value))
51
+ end
52
+ end
53
+ transformer.transform(in_var, out_var)
54
+ if options[:out] != "stream"
55
+ outfile = sw.toString()
56
+ end
57
+ end
58
+ end # XsltProcessor
59
+
60
+ class Saxon < XsltProcessor
61
+ TRANSFORMER_FACTORY_IMPL = "net.sf.saxon.TransformerFactoryImpl"
62
+ def initialize
63
+ System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
64
+ @tf = TransformerFactory.newInstance
65
+ end
66
+ end
67
+ # This class can be used in order to use Xalan as a XSLTransformer
68
+ # of course xalan jars must be added and included in this file as well
69
+ # class Xalan < XsltProcessor
70
+ # TRANSFORMER_FACTORY_IMPL = "org.apache.xalan.processor.TransformerFactoryImpl"
71
+ # def initialize
72
+ # System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
73
+ # @tf = TransformerFactory.newInstance
74
+ # end
75
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'simplyx'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class TestSimplyx < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @test_dir = File.join(File.dirname(__FILE__))
7
+ end
8
+
9
+ def test_transform
10
+ Simplyx::XsltProcessor.perform_transformation(tf('xslt_test.xsl'), tf('xslt_test.xml'))
11
+ end
12
+
13
+ private
14
+
15
+ # Returns the full file name of the file in the test directory
16
+ def tf(file)
17
+ File.join(@test_dir, file)
18
+ end
19
+
20
+ end
data/test/xml_test.xml ADDED
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0"?>
2
+ <sources>
3
+ <source>
4
+ <attribute>
5
+ <predicate>created_at </predicate>
6
+ <value>Wed Sep 30 15:49:46 +0200 2009</value>
7
+ </attribute>
8
+ <attribute>
9
+ <predicate>type</predicate>
10
+ <value>TaliaCore::SourceTypes::DummySource</value>
11
+ </attribute>
12
+ <attribute>
13
+ <predicate>uri</predicate>
14
+ <value>http://xml_test/from_file</value>
15
+ </attribute>
16
+ <attribute>
17
+ <predicate>http://localnode.org/localthi</predicate>
18
+ <value>value</value>
19
+ </attribute>
20
+ <attribute>
21
+ <predicate>http://www.w3.org/1999/02/22-rdf-syntax-ns#relatit</predicate>
22
+ <object>http://localnode.org/as_create_attr_dummy_1</object>
23
+ <object>http://localnode.org/as_create_attr_dummy_2</object>
24
+ </attribute>
25
+ </source>
26
+ </sources>
@@ -0,0 +1 @@
1
+ <div>test</div>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
+
4
+ <!-- simple xslt which transforms div into span -->
5
+ <xsl:template match="/">
6
+ <xsl:apply-templates select="*"/>
7
+ </xsl:template>
8
+
9
+
10
+ <xsl:template match="div">
11
+ <span><xsl:apply-templates/></span>
12
+ </xsl:template>
13
+
14
+ </xsl:stylesheet>
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplyx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Danilo Giacomi
8
+ - Daniel Hahn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-05-13 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Simple XML tools for JRuby, e.g. XSLT transformations
18
+ email: ghub@limitedcreativity.org
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.rdoc
26
+ files:
27
+ - .document
28
+ - .gitignore
29
+ - LICENSE
30
+ - README.rdoc
31
+ - Rakefile
32
+ - VERSION
33
+ - java/saxon9-dom.jar
34
+ - java/saxon9-dom4j.jar
35
+ - java/saxon9-jdom.jar
36
+ - java/saxon9-s9api.jar
37
+ - java/saxon9-sql.jar
38
+ - java/saxon9-xom.jar
39
+ - java/saxon9-xpath.jar
40
+ - java/saxon9-xqj.jar
41
+ - java/saxon9.jar
42
+ - lib/simplyx.rb
43
+ - lib/simplyx/jxslt.rb
44
+ - test/helper.rb
45
+ - test/test_simplyx.rb
46
+ - test/xml_test.xml
47
+ - test/xslt_test.xml
48
+ - test/xslt_test.xsl
49
+ has_rdoc: true
50
+ homepage: http://github.com/net7/simplyx
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Simple XML tools for JRuby
77
+ test_files:
78
+ - test/helper.rb
79
+ - test/test_simplyx.rb