rasper 0.1.0-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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rasper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rodrigo Manhães
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.rst ADDED
@@ -0,0 +1,71 @@
1
+ Rasper
2
+ ======
3
+
4
+ JRuby client to JasperReports API.
5
+
6
+ Currently, only does compilation of JRXML files and generation of PDF reports.
7
+
8
+
9
+ Installation
10
+ ------------
11
+
12
+ After installing the gem::
13
+
14
+ gem install rasper
15
+
16
+ You should install `Apache Maven 2 <http://maven.apache.org>`_ in order to
17
+ download the JAR files needed to run JasperReports. This done, run a rake task
18
+ for generating ``pom.xml``::
19
+
20
+ rake rasper:pom
21
+
22
+ and run Maven to download all dependencies::
23
+
24
+ mvn dependency:copy-dependencies -DoutputDirectory=/project-root/java/jars
25
+
26
+ where ``project-root`` is the rasper directory.
27
+
28
+
29
+ Usage
30
+ -----
31
+
32
+ To compile a JRXML file, just run::
33
+
34
+ Rasper::Compiler.compile("path-to-jrxml-file", "output-directory")
35
+
36
+ and Rasper will compile JRXML file and generate a ``jasper`` file. The second
37
+ argument is optional and, if provided, should point to directory in which you
38
+ want jasper file be stored. If it is omitted, jasper file is stored at the same
39
+ directory as JRXML file.
40
+
41
+
42
+ Having a compiled jasper file, you can generate a PDF report::
43
+
44
+ Rasper::Report.jasper_dir = "/home/user/jasper/directory"
45
+ Rasper::Report.image_dir = "/home/user/image/directory"
46
+ pdf_content = Rasper::Report.generate('programmers', [
47
+ { name: 'Linus', software: 'Linux' },
48
+ { name: 'Yukihiro', software: 'Ruby' },
49
+ { name: 'Guido', software: 'Python' } ],
50
+ { 'CITY' => 'Campos dos Goytacazes, Rio de Janeiro, Brazil',
51
+ 'DATE' => '02/01/2013' })
52
+
53
+
54
+ In example above, jasper directory and image directory (if there's some)
55
+ should be configured.
56
+
57
+ ``Rasper::Report.generate`` returns an array containing PDF content. It takes
58
+ the jasper file name, an array of hashes having the fields and values for the
59
+ report, and an optional third hash argument containing the report parameters.
60
+ All the hash keys should match the fields and parameter names within the JRXML
61
+ report.
62
+
63
+
64
+ Contributing
65
+ ------------
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ namespace :rasper do
2
+ task :pom do
3
+ print "Generating pom.xml..."
4
+ path = File.join(File.expand_path(File.dirname(__FILE__)), 'java', 'pom.xml')
5
+ File.open('./pom.xml', 'w') {|f| f.write(File.read(path)) }
6
+ end
7
+ end
data/java/pom.xml ADDED
@@ -0,0 +1,51 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+ <groupId>rasper</groupId>
5
+ <artifactId>rasper-dependencies</artifactId>
6
+ <packaging>jar</packaging>
7
+ <version>0.1.0</version>
8
+ <name>rasper-dependencies</name>
9
+ <url>https://github.com/rodrigomanhaes/rasper</url>
10
+
11
+ <dependencies>
12
+ <dependency>
13
+ <groupId>commons-beanutils</groupId>
14
+ <artifactId>commons-beanutils</artifactId>
15
+ <version>1.8.0</version>
16
+ </dependency>
17
+ <dependency>
18
+ <groupId>commons-digester</groupId>
19
+ <artifactId>commons-digester</artifactId>
20
+ <version>2.0</version>
21
+ </dependency>
22
+ <dependency>
23
+ <groupId>commons-collections</groupId>
24
+ <artifactId>commons-collections</artifactId>
25
+ <version>3.2</version>
26
+ </dependency>
27
+ <dependency>
28
+ <groupId>commons-logging</groupId>
29
+ <artifactId>commons-logging</artifactId>
30
+ <version>1.1.1</version>
31
+ </dependency>
32
+ <dependency>
33
+ <groupId>com.lowagie</groupId>
34
+ <artifactId>itext</artifactId>
35
+ <version>2.1.0</version>
36
+ </dependency>
37
+ <dependency>
38
+ <groupId>jasperreports</groupId>
39
+ <artifactId>jasperreports</artifactId>
40
+ <version>3.5.3</version>
41
+ </dependency>
42
+ <dependency>
43
+ <groupId>xalan</groupId>
44
+ <artifactId>xalan</artifactId>
45
+ <version>2.7.1</version>
46
+ </dependency>
47
+ </dependencies>
48
+
49
+ <build>
50
+ </build>
51
+ </project>
data/lib/rasper.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "rasper/version"
2
+
3
+ module Rasper
4
+ autoload :Compiler, 'rasper/compiler'
5
+ autoload :Report, 'rasper/report'
6
+ autoload :JARLoader, 'rasper/jar_loader'
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'java'
2
+
3
+ Rasper::JARLoader.load
4
+
5
+ java_import Java::net::sf::jasperreports::engine::JasperCompileManager
6
+
7
+ module Rasper
8
+ class Compiler
9
+ def self.compile(jrxml_file, output_dir = nil)
10
+ output_dir ||= File.dirname(jrxml_file)
11
+ output_file = File.join(output_dir, File.basename(jrxml_file, '.jrxml') + '.jasper')
12
+ JasperCompileManager.compile_report_to_file(jrxml_file, output_file)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Rasper
2
+ class JARLoader
3
+ class << self
4
+ attr_accessor :jar_dir
5
+
6
+ def load
7
+ root_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
8
+ jar_dir ||= File.join(root_dir, 'java', 'jars')
9
+ Dir.entries(jar_dir).each do |lib|
10
+ require File.join(jar_dir, lib) if lib =~ /\.jar$/
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ require 'java'
2
+
3
+ Rasper::JARLoader.load
4
+
5
+ java_import Java::net::sf::jasperreports::engine::data::JRXmlDataSource
6
+ java_import Java::net::sf::jasperreports::engine::util::FileResolver
7
+ java_import Java::net::sf::jasperreports::engine::JasperRunManager
8
+ java_import Java::java::io::ByteArrayInputStream
9
+ java_import Java::java::io::BufferedInputStream
10
+
11
+ require 'active_support/core_ext'
12
+
13
+ module Rasper
14
+ class Report
15
+ class << self
16
+ attr_accessor :jasper_dir, :image_dir
17
+
18
+ def generate(jasper_name, data, params = {})
19
+ set_file_resolver(params)
20
+
21
+ file_name = File.join(jasper_dir || '.', jasper_name + '.jasper')
22
+ jasper_content = File.read(file_name)
23
+ data = { jasper_name => data }.to_xml
24
+ xpath_criteria = "/hash/#{jasper_name}/#{jasper_name.singularize}"
25
+ source = JRXmlDataSource.new(
26
+ ByteArrayInputStream.new(data.to_java_bytes), xpath_criteria)
27
+ input = BufferedInputStream.new(
28
+ ByteArrayInputStream.new(jasper_content.to_java_bytes))
29
+ String.from_java_bytes(
30
+ JasperRunManager.runReportToPdf(input, params, source))
31
+ end
32
+
33
+ private
34
+
35
+ def set_file_resolver(params)
36
+ resolver = FileResolver.new
37
+ image_directory = image_dir
38
+ resolver.singleton_class.instance_eval do
39
+ define_method :resolve_file do |filename|
40
+ java::io::File.new("#{image_directory}/#{filename}")
41
+ end
42
+ end
43
+ params['REPORT_FILE_RESOLVER'] = resolver
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Rasper
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rasper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: java
7
+ authors:
8
+ - Rodrigo Manhães
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ MA==
22
+ none: false
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: !binary |-
28
+ MA==
29
+ none: false
30
+ prerelease: false
31
+ type: :runtime
32
+ - !ruby/object:Gem::Dependency
33
+ name: activesupport
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: !binary |-
39
+ MA==
40
+ none: false
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: !binary |-
46
+ MA==
47
+ none: false
48
+ prerelease: false
49
+ type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: !binary |-
57
+ MA==
58
+ none: false
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: !binary |-
64
+ MA==
65
+ none: false
66
+ prerelease: false
67
+ type: :runtime
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: !binary |-
75
+ MA==
76
+ none: false
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: !binary |-
82
+ MA==
83
+ none: false
84
+ prerelease: false
85
+ type: :development
86
+ - !ruby/object:Gem::Dependency
87
+ name: docsplit
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: !binary |-
93
+ MA==
94
+ none: false
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: !binary |-
100
+ MA==
101
+ none: false
102
+ prerelease: false
103
+ type: :development
104
+ description: JRuby client to JasperReports API.
105
+ email:
106
+ - rmanhaes@gmail.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - lib/rasper.rb
112
+ - lib/rasper/compiler.rb
113
+ - lib/rasper/report.rb
114
+ - lib/rasper/version.rb
115
+ - lib/rasper/jar_loader.rb
116
+ - java/pom.xml
117
+ - README.rst
118
+ - LICENSE.txt
119
+ - Rakefile
120
+ - Gemfile
121
+ homepage: https://github.com/rodrigomanhaes/rasper
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: !binary |-
133
+ MA==
134
+ none: false
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: !binary |-
140
+ MA==
141
+ none: false
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.24
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: JRuby client to JasperReports API. Currently, only does compilation of JRXML files and generation of PDF reports.
148
+ test_files: []