rasper 0.1.0-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1b9e0e3ad94e281532abb8128e6cbd9c4db7595
4
+ data.tar.gz: a7c956802e2aabfde75ba8dfb0aa7331c392b831
5
+ SHA512:
6
+ metadata.gz: 6653828af81014ea846c6dace90113e9fa2743c9799ce5520fb594deb2e92f5debbf60825c67ded80bc288f838b68f701d8bb42ce87d334dfb2cdc53f7dfbe40
7
+ data.tar.gz: a5466660ab9ace35a62edede737d85470191c2d6c33a5342264d1f3c168abb2ca836e7e591f6725e650ea0b4c5a17bf412a2aa1505f7fbc2d65b362468dc5fc8
@@ -0,0 +1,26 @@
1
+ Rasper
2
+ ======
3
+
4
+ 2018-03-15 Rodrigo Manhães <rmanhaes@gmail.com>
5
+ 0.2.0
6
+
7
+ - Upgrade JasperReports to 6.5.1
8
+
9
+
10
+ 2013-07-10 Rodrigo Manhães <rmanhaes@gmail.com>
11
+ 0.1.4
12
+
13
+ - Extend locale support to compilation.
14
+
15
+
16
+ 2013-07-08 Rodrigo Manhães <rmanhaes@gmail.com>
17
+ 0.1.3
18
+
19
+ - Added configuration for locales.
20
+
21
+
22
+ 2013-02-22 Rodrigo Manhães <rmanhaes@gmail.com>
23
+ 0.1.2
24
+
25
+ - Dropped configuration directly on specific classes. All configurations now
26
+ should be applied to Rasper::Config.
data/README.rst CHANGED
@@ -14,21 +14,35 @@ After installing the gem::
14
14
  gem install rasper
15
15
 
16
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
17
+ download the JAR files needed to run JasperReports. This done, run a command
18
18
  for generating ``pom.xml``::
19
19
 
20
- rake rasper:pom
20
+ rasper generate_pom
21
21
 
22
22
  and run Maven to download all dependencies::
23
23
 
24
- mvn dependency:copy-dependencies -DoutputDirectory=/project-root/java/jars
24
+ mvn dependency:copy-dependencies -DoutputDirectory=/dir/for/jars
25
25
 
26
- where ``project-root`` is the rasper directory.
26
+ where ``/dir/for/jars`` is the directory in which JARs will be downloaded.
27
+
28
+ For running tests, JAR files should be stored in ``java/jars`` directory.
27
29
 
28
30
 
29
31
  Usage
30
32
  -----
31
33
 
34
+ Before doing anything, you should configure Rasper::
35
+
36
+ Rasper::Config.configure do |config|
37
+ config.jar_dir = "/dir/of/jars"
38
+ config.jasper_dir = "/dir/of/compiled/reports"
39
+ config.image_dir = "/dir/of/images"
40
+ config.locale = 'pt_BR'
41
+ end
42
+
43
+ Locale can be any Java-supported locale, in the format above.
44
+
45
+
32
46
  To compile a JRXML file, just run::
33
47
 
34
48
  Rasper::Compiler.compile("path-to-jrxml-file", "output-directory")
@@ -41,8 +55,7 @@ directory as JRXML file.
41
55
 
42
56
  Having a compiled jasper file, you can generate a PDF report::
43
57
 
44
- Rasper::Report.jasper_dir = "/home/user/jasper/directory"
45
- Rasper::Report.image_dir = "/home/user/image/directory"
58
+
46
59
  pdf_content = Rasper::Report.generate('programmers', [
47
60
  { name: 'Linus', software: 'Linux' },
48
61
  { name: 'Yukihiro', software: 'Ruby' },
@@ -54,7 +67,7 @@ Having a compiled jasper file, you can generate a PDF report::
54
67
  In example above, jasper directory and image directory (if there's some)
55
68
  should be configured.
56
69
 
57
- ``Rasper::Report.generate`` returns an array containing PDF content. It takes
70
+ ``Rasper::Report.generate`` returns an array containing PDF bytes. It takes
58
71
  the jasper file name, an array of hashes having the fields and values for the
59
72
  report, and an optional third hash argument containing the report parameters.
60
73
  All the hash keys should match the fields and parameter names within the JRXML
@@ -0,0 +1,34 @@
1
+ #! /usr/bin/env jruby
2
+
3
+ if ARGV[0] == 'generate_pom'
4
+ STDOUT.puts "Generating pom.xml..."
5
+ File.open('./pom.xml', 'w') {|f| f.write('''<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
7
+ <modelVersion>4.0.0</modelVersion>
8
+ <groupId>rasper</groupId>
9
+ <artifactId>rasper-dependencies</artifactId>
10
+ <packaging>jar</packaging>
11
+ <version>0.1.0</version>
12
+ <name>rasper-dependencies</name>
13
+ <url>https://github.com/rodrigomanhaes/rasper</url>
14
+
15
+ <dependencies>
16
+ <dependency>
17
+ <groupId>net.sf.jasperreports</groupId>
18
+ <artifactId>jasperreports</artifactId>
19
+ <version>6.5.1</version>
20
+ </dependency>
21
+ <dependency>
22
+ <groupId>xalan</groupId>
23
+ <artifactId>xalan</artifactId>
24
+ <version>2.7.1</version>
25
+ </dependency>
26
+ </dependencies>
27
+
28
+ <build>
29
+ </build>
30
+ </project>
31
+ ''') }
32
+ else
33
+ STDOUT.puts "Usage: rasper generate_pom"
34
+ end
@@ -4,4 +4,6 @@ module Rasper
4
4
  autoload :Compiler, 'rasper/compiler'
5
5
  autoload :Report, 'rasper/report'
6
6
  autoload :JARLoader, 'rasper/jar_loader'
7
+ autoload :Config, 'rasper/config'
8
+ autoload :Locale, 'rasper/locale'
7
9
  end
@@ -6,10 +6,14 @@ java_import Java::net::sf::jasperreports::engine::JasperCompileManager
6
6
 
7
7
  module Rasper
8
8
  class Compiler
9
+ extend Locale
10
+
9
11
  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)
12
+ run_with_locale do
13
+ output_dir ||= File.dirname(jrxml_file)
14
+ output_file = File.join(output_dir, File.basename(jrxml_file, '.jrxml') + '.jasper')
15
+ JasperCompileManager.compile_report_to_file(jrxml_file, output_file)
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -0,0 +1,22 @@
1
+ module Rasper
2
+ class Config
3
+ class << self
4
+ attr_reader :jar_dir, :jasper_dir, :image_dir, :locale
5
+ end
6
+
7
+ def self.configure
8
+ conf = Configuration.new
9
+ yield conf
10
+ @jar_dir = conf.jar_dir if conf.jar_dir
11
+ @jasper_dir = conf.jasper_dir if conf.jasper_dir
12
+ @image_dir = conf.image_dir if conf.image_dir
13
+ @locale = conf.locale if conf.locale
14
+ end
15
+
16
+ private
17
+
18
+ class Configuration
19
+ attr_accessor :jar_dir, :jasper_dir, :image_dir, :locale
20
+ end
21
+ end
22
+ end
@@ -1,14 +1,8 @@
1
1
  module Rasper
2
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
3
+ def self.load
4
+ Dir.entries(Config.jar_dir).each do |lib|
5
+ require File.join(Config.jar_dir, lib) if lib =~ /\.jar$/
12
6
  end
13
7
  end
14
8
  end
@@ -0,0 +1,29 @@
1
+ require 'java'
2
+
3
+ java_import Java::java::util::Locale
4
+
5
+ module Rasper
6
+ module Locale
7
+
8
+ def run_with_locale
9
+ set_locale
10
+ begin
11
+ yield
12
+ ensure
13
+ restore_locale
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def set_locale
20
+ return unless Config.locale
21
+ @default_locale = ::Locale.get_default
22
+ ::Locale.set_default(::Locale.new(*Config.locale.split('_')))
23
+ end
24
+
25
+ def restore_locale
26
+ ::Locale.set_default(@default_locale) if @default_locale
27
+ end
28
+ end
29
+ end
@@ -7,41 +7,52 @@ java_import Java::net::sf::jasperreports::engine::util::FileResolver
7
7
  java_import Java::net::sf::jasperreports::engine::JasperRunManager
8
8
  java_import Java::java::io::ByteArrayInputStream
9
9
  java_import Java::java::io::BufferedInputStream
10
+ java_import Java::java::util::Locale
10
11
 
11
12
  require 'active_support/core_ext'
12
13
 
13
14
  module Rasper
14
15
  class Report
15
- class << self
16
- attr_accessor :jasper_dir, :image_dir
16
+ extend Locale
17
17
 
18
+ class << self
18
19
  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))
20
+ run_with_locale do
21
+ namespace, jasper_name = extract_namespace(jasper_name)
22
+ set_file_resolver(params, namespace)
23
+ file_name = File.join(Config.jasper_dir || '.', namespace,
24
+ jasper_name + '.jasper')
25
+ jasper_content = File.read(file_name)
26
+ data = { jasper_name => data }.to_xml
27
+ xpath_criteria = "/hash/#{jasper_name}/#{jasper_name.singularize}"
28
+ source = JRXmlDataSource.new(
29
+ ByteArrayInputStream.new(data.to_java_bytes), xpath_criteria)
30
+ input = BufferedInputStream.new(
31
+ ByteArrayInputStream.new(jasper_content.to_java_bytes))
32
+ String.from_java_bytes(
33
+ JasperRunManager.runReportToPdf(input, params, source))
34
+ end
31
35
  end
32
36
 
33
37
  private
34
38
 
35
- def set_file_resolver(params)
36
- resolver = FileResolver.new
37
- image_directory = image_dir
39
+ def set_file_resolver(params, namespace = '')
40
+ resolver = Class.new { include FileResolver }.new
41
+ image_directory = Config.image_dir
38
42
  resolver.singleton_class.instance_eval do
39
43
  define_method :resolve_file do |filename|
40
- java::io::File.new("#{image_directory}/#{filename}")
44
+ java::io::File.new(File.join(image_directory, namespace, filename))
41
45
  end
42
46
  end
43
47
  params['REPORT_FILE_RESOLVER'] = resolver
44
48
  end
49
+
50
+ def extract_namespace(name)
51
+ parts = name.split('/')
52
+ jasper_name = parts.pop
53
+ namespace = parts.join('/')
54
+ [namespace, jasper_name]
55
+ end
45
56
  end
46
57
  end
47
- end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Rasper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,126 +1,110 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: java
7
6
  authors:
8
7
  - Rodrigo Manhães
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !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
14
  requirement: !ruby/object:Gem::Requirement
24
15
  requirements:
25
16
  - - ">="
26
17
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
- none: false
18
+ version: '0'
19
+ name: builder
30
20
  prerelease: false
31
21
  type: :runtime
32
- - !ruby/object:Gem::Dependency
33
- name: activesupport
34
22
  version_requirements: !ruby/object:Gem::Requirement
35
23
  requirements:
36
24
  - - ">="
37
25
  - !ruby/object:Gem::Version
38
- version: !binary |-
39
- MA==
40
- none: false
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
41
28
  requirement: !ruby/object:Gem::Requirement
42
29
  requirements:
43
30
  - - ">="
44
31
  - !ruby/object:Gem::Version
45
- version: !binary |-
46
- MA==
47
- none: false
32
+ version: '0'
33
+ name: activesupport
48
34
  prerelease: false
49
35
  type: :runtime
50
- - !ruby/object:Gem::Dependency
51
- name: rake
52
36
  version_requirements: !ruby/object:Gem::Requirement
53
37
  requirements:
54
38
  - - ">="
55
39
  - !ruby/object:Gem::Version
56
- version: !binary |-
57
- MA==
58
- none: false
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
59
42
  requirement: !ruby/object:Gem::Requirement
60
43
  requirements:
61
44
  - - ">="
62
45
  - !ruby/object:Gem::Version
63
- version: !binary |-
64
- MA==
65
- none: false
46
+ version: '0'
47
+ name: rake
66
48
  prerelease: false
67
49
  type: :runtime
68
- - !ruby/object:Gem::Dependency
69
- name: rspec
70
50
  version_requirements: !ruby/object:Gem::Requirement
71
51
  requirements:
72
52
  - - ">="
73
53
  - !ruby/object:Gem::Version
74
- version: !binary |-
75
- MA==
76
- none: false
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
77
56
  requirement: !ruby/object:Gem::Requirement
78
57
  requirements:
79
58
  - - ">="
80
59
  - !ruby/object:Gem::Version
81
- version: !binary |-
82
- MA==
83
- none: false
60
+ version: '0'
61
+ name: rspec
84
62
  prerelease: false
85
63
  type: :development
86
- - !ruby/object:Gem::Dependency
87
- name: docsplit
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
65
  requirements:
90
66
  - - ">="
91
67
  - !ruby/object:Gem::Version
92
- version: !binary |-
93
- MA==
94
- none: false
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
95
70
  requirement: !ruby/object:Gem::Requirement
96
71
  requirements:
97
72
  - - ">="
98
73
  - !ruby/object:Gem::Version
99
- version: !binary |-
100
- MA==
101
- none: false
74
+ version: '0'
75
+ name: docsplit
102
76
  prerelease: false
103
77
  type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
104
83
  description: JRuby client to JasperReports API.
105
84
  email:
106
85
  - rmanhaes@gmail.com
107
- executables: []
86
+ executables:
87
+ - rasper
108
88
  extensions: []
109
89
  extra_rdoc_files: []
110
90
  files:
91
+ - CHANGELOG
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.rst
95
+ - Rakefile
96
+ - bin/rasper
111
97
  - lib/rasper.rb
112
98
  - lib/rasper/compiler.rb
99
+ - lib/rasper/config.rb
100
+ - lib/rasper/jar_loader.rb
101
+ - lib/rasper/locale.rb
113
102
  - lib/rasper/report.rb
114
103
  - 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
104
  homepage: https://github.com/rodrigomanhaes/rasper
122
105
  licenses:
123
106
  - MIT
107
+ metadata: {}
124
108
  post_install_message:
125
109
  rdoc_options: []
126
110
  require_paths:
@@ -129,20 +113,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
113
  requirements:
130
114
  - - ">="
131
115
  - !ruby/object:Gem::Version
132
- version: !binary |-
133
- MA==
134
- none: false
116
+ version: '0'
135
117
  required_rubygems_version: !ruby/object:Gem::Requirement
136
118
  requirements:
137
119
  - - ">="
138
120
  - !ruby/object:Gem::Version
139
- version: !binary |-
140
- MA==
141
- none: false
121
+ version: '0'
142
122
  requirements: []
143
123
  rubyforge_project:
144
- rubygems_version: 1.8.24
124
+ rubygems_version: 2.6.14
145
125
  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.
126
+ specification_version: 4
127
+ summary: JRuby client to JasperReports API. Currently, only does compilation of JRXML
128
+ files and generation of PDF reports.
148
129
  test_files: []
@@ -1,51 +0,0 @@
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>