librepdf 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+
2
+ package librepdf.document;
3
+
4
+ import librepdf.Connection;
5
+ import org.jruby.Ruby;
6
+ import org.jruby.RubyProc;
7
+ import com.sun.star.lang.XComponent;
8
+ import com.sun.star.lang.XServiceInfo;
9
+ import com.sun.star.uno.UnoRuntime;
10
+
11
+ public final class Factory
12
+ {
13
+ public static Document factory(Connection connection, Ruby runtime, XComponent document) {
14
+ final XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, document);
15
+
16
+ if (info.supportsService("com.sun.star.text.TextDocument")) {
17
+ return new Writer(connection, runtime, document);
18
+ } else if (info.supportsService("com.sun.star.text.WebDocument")) {
19
+ return new Web(connection, runtime, document);
20
+ } else if (info.supportsService("com.sun.star.text.GlobalDocument")) {
21
+ return new Global(connection, runtime, document);
22
+ } else if (info.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
23
+ return new Calc(connection, runtime, document);
24
+ } else if (info.supportsService("com.sun.star.presentation.PresentationDocument")) {
25
+ return new Impress(connection, runtime, document);
26
+ } else if (info.supportsService("com.sun.star.drawing.DrawingDocument")) {
27
+ return new Draw(connection, runtime, document);
28
+ } else if (info.supportsService("com.sun.star.formula.FormulaProperties")) {
29
+ return new Math(connection, runtime, document);
30
+ }
31
+
32
+ throw new RuntimeException("unsupported document type");
33
+ }
34
+
35
+ public static Document factory(Connection connection, Ruby runtime, XComponent document, RubyProc proc) {
36
+ final XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, document);
37
+
38
+ if (info.supportsService("com.sun.star.text.TextDocument")) {
39
+ return new Writer(connection, runtime, document, proc);
40
+ } else if (info.supportsService("com.sun.star.text.WebDocument")) {
41
+ return new Web(connection, runtime, document, proc);
42
+ } else if (info.supportsService("com.sun.star.text.GlobalDocument")) {
43
+ return new Global(connection, runtime, document, proc);
44
+ } else if (info.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
45
+ return new Calc(connection, runtime, document, proc);
46
+ } else if (info.supportsService("com.sun.star.presentation.PresentationDocument")) {
47
+ return new Impress(connection, runtime, document, proc);
48
+ } else if (info.supportsService("com.sun.star.drawing.DrawingDocument")) {
49
+ return new Draw(connection, runtime, document, proc);
50
+ } else if (info.supportsService("com.sun.star.formula.FormulaProperties")) {
51
+ return new Math(connection, runtime, document, proc);
52
+ }
53
+
54
+ throw new RuntimeException("unsupported document type");
55
+ }
56
+
57
+ private Factory() {}
58
+ }
59
+
@@ -0,0 +1,25 @@
1
+
2
+ package librepdf.document;
3
+
4
+ import librepdf.Connection;
5
+ import java.util.Map;
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyProc;
8
+ import com.sun.star.lang.XComponent;
9
+
10
+ class Global extends Document
11
+ {
12
+ Global(Connection connection, Ruby runtime, XComponent document) {
13
+ super(connection, runtime, document);
14
+ }
15
+
16
+ Global(Connection connection, Ruby runtime, XComponent document, RubyProc proc) {
17
+ super(connection, runtime, document, proc);
18
+ }
19
+
20
+ @Override
21
+ protected void setDefaultOptions(Map<String, Object> options) {
22
+ options.put("FilterName", "writer_globaldocument_pdf_Export");
23
+ }
24
+ }
25
+
@@ -0,0 +1,25 @@
1
+
2
+ package librepdf.document;
3
+
4
+ import librepdf.Connection;
5
+ import java.util.Map;
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyProc;
8
+ import com.sun.star.lang.XComponent;
9
+
10
+ class Impress extends Document
11
+ {
12
+ Impress(Connection connection, Ruby runtime, XComponent document) {
13
+ super(connection, runtime, document);
14
+ }
15
+
16
+ Impress(Connection connection, Ruby runtime, XComponent document, RubyProc proc) {
17
+ super(connection, runtime, document, proc);
18
+ }
19
+
20
+ @Override
21
+ protected void setDefaultOptions(Map<String, Object> options) {
22
+ options.put("FilterName", "impress_pdf_Export");
23
+ }
24
+ }
25
+
@@ -0,0 +1,25 @@
1
+
2
+ package librepdf.document;
3
+
4
+ import librepdf.Connection;
5
+ import java.util.Map;
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyProc;
8
+ import com.sun.star.lang.XComponent;
9
+
10
+ class Math extends Document
11
+ {
12
+ Math(Connection connection, Ruby runtime, XComponent document) {
13
+ super(connection, runtime, document);
14
+ }
15
+
16
+ Math(Connection connection, Ruby runtime, XComponent document, RubyProc proc) {
17
+ super(connection, runtime, document, proc);
18
+ }
19
+
20
+ @Override
21
+ protected void setDefaultOptions(Map<String, Object> options) {
22
+ options.put("FilterName", "math_pdf_Export");
23
+ }
24
+ }
25
+
@@ -0,0 +1,25 @@
1
+
2
+ package librepdf.document;
3
+
4
+ import librepdf.Connection;
5
+ import java.util.Map;
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyProc;
8
+ import com.sun.star.lang.XComponent;
9
+
10
+ class Web extends Document
11
+ {
12
+ Web(Connection connection, Ruby runtime, XComponent document) {
13
+ super(connection, runtime, document);
14
+ }
15
+
16
+ Web(Connection connection, Ruby runtime, XComponent document, RubyProc proc) {
17
+ super(connection, runtime, document, proc);
18
+ }
19
+
20
+ @Override
21
+ protected void setDefaultOptions(Map<String, Object> options) {
22
+ options.put("FilterName", "writer_web_pdf_Export");
23
+ }
24
+ }
25
+
@@ -0,0 +1,25 @@
1
+
2
+ package librepdf.document;
3
+
4
+ import librepdf.Connection;
5
+ import java.util.Map;
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyProc;
8
+ import com.sun.star.lang.XComponent;
9
+
10
+ class Writer extends Document
11
+ {
12
+ Writer(Connection connection, Ruby runtime, XComponent document) {
13
+ super(connection, runtime, document);
14
+ }
15
+
16
+ Writer(Connection connection, Ruby runtime, XComponent document, RubyProc proc) {
17
+ super(connection, runtime, document, proc);
18
+ }
19
+
20
+ @Override
21
+ protected void setDefaultOptions(Map<String, Object> options) {
22
+ options.put("FilterName", "writer_pdf_Export");
23
+ }
24
+ }
25
+
@@ -0,0 +1,29 @@
1
+ require "librepdf/version"
2
+
3
+ if defined?(Java) and defined?(JRUBY_VERSION) and PLATFORM == 'java'
4
+ require 'java'
5
+
6
+ module Librepdf
7
+ require 'librepdf/java/juh'
8
+ require 'librepdf/java/jurt'
9
+ require 'librepdf/java/ridl'
10
+ require 'librepdf/java/unoil'
11
+ require 'librepdf/java/librepdf'
12
+
13
+ import 'librepdf.Connection'
14
+ import 'librepdf.document.Document'
15
+ class Document
16
+ import 'librepdf.document.Calc'
17
+ import 'librepdf.document.Chart'
18
+ import 'librepdf.document.Draw'
19
+ import 'librepdf.document.Global'
20
+ import 'librepdf.document.Impress'
21
+ import 'librepdf.document.Math'
22
+ import 'librepdf.document.Web'
23
+ import 'librepdf.document.Writer'
24
+ end
25
+ end
26
+ else
27
+ warn "librepdf is for use with JRuby only"
28
+ end
29
+
@@ -0,0 +1,3 @@
1
+ module Librepdf
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/librepdf/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["hamajyotan"]
6
+ gem.email = ["hamajyotan@gmail.com"]
7
+ gem.description = %q{This software changes a document into PDF by Libreoffice assistance under JRuby.}
8
+ gem.summary = %q{This software changes a document into PDF by Libreoffice assistance under JRuby.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = Dir['lib/librepdf/java/*.jar'] << `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "librepdf"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Librepdf::VERSION
17
+
18
+ gem.add_development_dependency 'rspec', '>= 2.0.0'
19
+ end
20
+
Binary file
@@ -0,0 +1,92 @@
1
+
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ include Librepdf
5
+
6
+ require 'fileutils'
7
+ require 'tmpdir'
8
+
9
+ # Precondition.
10
+ #
11
+ # Required start libreoffice as a service.
12
+ #
13
+ describe Connection do
14
+ before(:all) do
15
+ @host = ENV['SOFFICE_HOST'] || '127.0.0.1'
16
+ @port = ENV['SOFFICE_PORT'] || 8100
17
+
18
+ @dir = Dir.mktmpdir
19
+ end
20
+
21
+ it "Connection should be able to create a instance" do
22
+ @con = Connection.new 'host' => @host, 'port' => @port
23
+ end
24
+
25
+ context "given block argument to #initialize" do
26
+ it "Only within the block, to be connected" do
27
+ con = Connection.new('host' => @host, 'port' => @port) { |con|
28
+ con.closed?.should == false
29
+ }
30
+ con.closed?.should == true
31
+ end
32
+
33
+ it "As an exception has occurred, it is similar to" do
34
+ con = nil
35
+ begin
36
+ Connection.new('host' => @host, 'port' => @port) { |c|
37
+ con = c
38
+ raise RuntimeError
39
+ }
40
+ rescue; end
41
+ closed = !! con.closed?
42
+ closed.should == true
43
+ end
44
+ end
45
+
46
+ context "when connect" do
47
+ before do
48
+ @con = Connection.new 'host' => @host, 'port' => @port
49
+ end
50
+
51
+ it "should not closed" do
52
+ @con.closed?.should_not == true
53
+ end
54
+
55
+ it "should be able to load document" do
56
+ inputUrl = "file://#{File.dirname(__FILE__)}/data/test.odt"
57
+ doc = @con.load inputUrl
58
+ doc.close rescue nil
59
+ end
60
+
61
+ context "when load document" do
62
+ before do
63
+ inputUrl = "file://#{File.dirname(__FILE__)}/data/test.odt"
64
+ @doc = @con.load inputUrl
65
+ end
66
+
67
+ it "document should not closed" do
68
+ @doc.closed?.should_not == true
69
+ end
70
+
71
+ it "should be able to convert to pdf" do
72
+ outputUrl = "file://#{@dir}/test01.pdf"
73
+ @doc.convert_pdf outputUrl
74
+ File.file?("#{@dir}/test01.pdf").should == true
75
+ end
76
+
77
+ after do
78
+ @doc.close
79
+ end
80
+ end
81
+
82
+ after do
83
+ @con.close
84
+ end
85
+ end
86
+
87
+ after(:all) do
88
+ FileUtils.rm_r @dir
89
+ @con.close if @con and !@con.closed?
90
+ end
91
+ end
92
+
@@ -0,0 +1,7 @@
1
+
2
+ gem 'rspec', '>= 2.0.0'
3
+ require 'rspec'
4
+
5
+ $:.unshift(File.dirname(__FILE__) + '../lib')
6
+ require 'librepdf'
7
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: librepdf
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - hamajyotan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-04-03 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: This software changes a document into PDF by Libreoffice assistance under JRuby.
27
+ email:
28
+ - hamajyotan@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/librepdf/java/ridl.jar
37
+ - lib/librepdf/java/jurt.jar
38
+ - lib/librepdf/java/juh.jar
39
+ - lib/librepdf/java/unoil.jar
40
+ - lib/librepdf/java/librepdf.jar
41
+ - .gitignore
42
+ - Gemfile
43
+ - History.md
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - java/lib/LibreOffice-LICENSE
48
+ - java/lib/juh.jar
49
+ - java/lib/jurt.jar
50
+ - java/lib/ridl.jar
51
+ - java/lib/unoil.jar
52
+ - java/src/librepdf/Connection.java
53
+ - java/src/librepdf/Utils.java
54
+ - java/src/librepdf/document/Calc.java
55
+ - java/src/librepdf/document/Chart.java
56
+ - java/src/librepdf/document/Document.java
57
+ - java/src/librepdf/document/Draw.java
58
+ - java/src/librepdf/document/Factory.java
59
+ - java/src/librepdf/document/Global.java
60
+ - java/src/librepdf/document/Impress.java
61
+ - java/src/librepdf/document/Math.java
62
+ - java/src/librepdf/document/Web.java
63
+ - java/src/librepdf/document/Writer.java
64
+ - lib/librepdf.rb
65
+ - lib/librepdf/version.rb
66
+ - librepdf.gemspec
67
+ - spec/data/test.odt
68
+ - spec/librepdf_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: ""
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.15
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: This software changes a document into PDF by Libreoffice assistance under JRuby.
97
+ test_files:
98
+ - spec/data/test.odt
99
+ - spec/librepdf_spec.rb
100
+ - spec/spec_helper.rb