junodoc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +11 -0
- data/Rakefile +15 -0
- data/Readme +24 -0
- data/junodoc.gemspec +20 -0
- data/lib/junodoc/configuration.rb +13 -0
- data/lib/junodoc/document.rb +75 -0
- data/lib/junodoc/version.rb +3 -0
- data/lib/junodoc.rb +19 -0
- data/spec/benchmark_test.rb +15 -0
- data/spec/configuration_spec.rb +16 -0
- data/spec/document_spec.rb +44 -0
- data/spec/fixtures/image.jpg +0 -0
- data/spec/junodoc_spec.rb +19 -0
- data/spec/spec_helper.rb +8 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
#ENV['JAVA_OPTS'] = "-d32"
|
9
|
+
t.pattern = "spec/*_spec.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
#task :default do
|
13
|
+
# `JAVA_OPTS="-d32" bundle exec ruby ./spec/junodoc_spec.rb`
|
14
|
+
# `JAVA_OPTS="-d32" rake test`
|
15
|
+
#end
|
data/Readme
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
JunoDoc - a jRuby interface to OpenOffice.org's UNO interface.
|
2
|
+
|
3
|
+
This is a jruby library to test the feasibility of using the UNO Java API to generate documents programmatically.
|
4
|
+
|
5
|
+
TODO:
|
6
|
+
|
7
|
+
- Close the server when finished
|
8
|
+
- Fix the server to start without registration wizard
|
9
|
+
- Embed images within the document
|
10
|
+
|
11
|
+
LICENSE:
|
12
|
+
|
13
|
+
Copyright (c) 2011 Revelation, Inc.
|
14
|
+
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
16
|
+
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
|
17
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
18
|
+
furnished to do so, subject to the following conditions:
|
19
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
22
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
24
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/junodoc.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "junodoc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "junodoc"
|
7
|
+
s.version = Junodoc::VERSION
|
8
|
+
s.authors = ["Dan Herrera"]
|
9
|
+
s.email = ["dan@revelationglobal.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{JunoDoc is a jRuby wrapper to the OpenOffice UNO API}
|
12
|
+
s.description = %q{JunoDoc makes it easier to work with the OpenOffice API to create word97 compatible documents.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "junodoc"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module JunoDoc
|
2
|
+
class Document
|
3
|
+
attr_accessor :name
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
require 'java_uno.jar'
|
7
|
+
require 'juh.jar'
|
8
|
+
require 'jurt.jar'
|
9
|
+
require 'ridl.jar'
|
10
|
+
require 'unoloader.jar'
|
11
|
+
require 'unoil.jar'
|
12
|
+
|
13
|
+
@context = create_context
|
14
|
+
@doc = open_writer
|
15
|
+
@stored_document = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::frame::XStorable.java_class, @doc)
|
16
|
+
@document_text = @doc.getText
|
17
|
+
@cursor = @document_text.createTextCursor
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_text(text)
|
21
|
+
@document_text.insertString(@cursor, text, false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_image(image_url)
|
25
|
+
xMSFDoc = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::lang::XMultiServiceFactory.java_class, @doc)
|
26
|
+
oGraphic = xMSFDoc.createInstance("com.sun.star.text.TextGraphicObject")
|
27
|
+
|
28
|
+
xPropSet = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::beans::XPropertySet.java_class, oGraphic)
|
29
|
+
xPropSet.setPropertyValue("GraphicURL", image_url)
|
30
|
+
xPropSet.setPropertyValue("Height", 4000.to_java(:int))
|
31
|
+
xPropSet.setPropertyValue("Width", 5000.to_java(:int))
|
32
|
+
|
33
|
+
xTextContent = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::text::XTextContent.java_class, oGraphic)
|
34
|
+
@document_text.insertTextContent(@cursor, xTextContent, true);
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_paragraph_break
|
38
|
+
@document_text.insertControlCharacter(@cursor, com::sun::star::text::ControlCharacter.PARAGRAPH_BREAK, false)
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_document(path)
|
42
|
+
propertyValues = Java::com::sun::star::beans::PropertyValue[2].new
|
43
|
+
propertyValues[0] = Java::com::sun::star::beans::PropertyValue.new
|
44
|
+
propertyValues[0].Name = "Overwrite"
|
45
|
+
propertyValues[0].Value = true
|
46
|
+
|
47
|
+
propertyValues[1] = Java::com::sun::star::beans::PropertyValue.new
|
48
|
+
propertyValues[1].Name = "FilterName"
|
49
|
+
propertyValues[1].Value = "swriter: MS Word 97"
|
50
|
+
|
51
|
+
sStoreUrl = "file://#{path}"
|
52
|
+
@stored_document.storeAsURL(sStoreUrl, propertyValues)
|
53
|
+
end
|
54
|
+
|
55
|
+
def close_document
|
56
|
+
xCloseable = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::util::XCloseable.java_class, @stored_document)
|
57
|
+
xCloseable.close(false)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def create_context
|
62
|
+
com::sun::star::comp::helper::Bootstrap.bootstrap()
|
63
|
+
end
|
64
|
+
|
65
|
+
def open_writer
|
66
|
+
xMCF = @context.getServiceManager()
|
67
|
+
oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", @context)
|
68
|
+
xCLoader = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::frame::XComponentLoader.java_class, oDesktop)
|
69
|
+
szEmptyArgs = Java::com.sun.star.beans.PropertyValue[0].new
|
70
|
+
xComp = xCLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, szEmptyArgs)
|
71
|
+
com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::text::XTextDocument.java_class, xComp)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/lib/junodoc.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'junodoc/version'
|
3
|
+
require 'junodoc/configuration'
|
4
|
+
require 'junodoc/document'
|
5
|
+
|
6
|
+
module JunoDoc
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
|
10
|
+
def configure
|
11
|
+
self.configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
|
14
|
+
configuration[:class_path].each do |path|
|
15
|
+
$CLASSPATH << path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
10.times do |n|
|
4
|
+
puts "Iteration #{n}"
|
5
|
+
puts Time.now
|
6
|
+
@junodoc = JunoDoc::Document.new
|
7
|
+
1000.times do
|
8
|
+
@junodoc.add_text("istanbul, not constantinople")
|
9
|
+
@junodoc.add_paragraph_break
|
10
|
+
@junodoc.add_image("file://#{Dir.pwd}/spec/fixtures/image.jpg")
|
11
|
+
end
|
12
|
+
@junodoc.write_document(Dir.pwd + '/spec/output/test.doc')
|
13
|
+
@junodoc.close_document
|
14
|
+
puts Time.now
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe JunoDoc::Document do
|
4
|
+
before do
|
5
|
+
@config = JunoDoc::Configuration.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should store the class path" do
|
9
|
+
@config.class_path << '/Applications/OpenOffice.org.app/Contents/MacOS/'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to read configuration variables like a hash" do
|
13
|
+
@config.class_path << '/Applications/OpenOffice.org.app/Contents/MacOS/'
|
14
|
+
@config[:class_path].must_equal ['/Applications/OpenOffice.org.app/Contents/MacOS/']
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe JunoDoc::Document do
|
4
|
+
before do
|
5
|
+
@junodoc = JunoDoc::Document.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be an instance of JunoDoc::Document" do
|
9
|
+
@junodoc.class.must_equal(JunoDoc::Document)
|
10
|
+
@junodoc.close_document
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to set the name of the document" do
|
14
|
+
@junodoc.name = "what's_up.doc"
|
15
|
+
@junodoc.name.must_equal("what's_up.doc")
|
16
|
+
@junodoc.close_document
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to add text to the document" do
|
20
|
+
@junodoc.add_text("istanbul, not constantinople")
|
21
|
+
@junodoc.close_document
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be able to add a paragraph break" do
|
25
|
+
@junodoc.add_text("istanbul, not constantinople")
|
26
|
+
@junodoc.add_paragraph_break
|
27
|
+
@junodoc.close_document
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to add an image by url" do
|
31
|
+
@junodoc.add_text("istanbul, not constantinople")
|
32
|
+
@junodoc.add_paragraph_break
|
33
|
+
@junodoc.add_image("file://#{Dir.pwd}/spec/fixtures/image.jpg")
|
34
|
+
@junodoc.close_document
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be able to write out the document to disk" do
|
38
|
+
@junodoc.add_text("istanbul, not constantinople")
|
39
|
+
@junodoc.add_paragraph_break
|
40
|
+
@junodoc.add_image("file://#{Dir.pwd}/spec/fixtures/image.jpg")
|
41
|
+
@junodoc.write_document(Dir.pwd + '/spec/output/test.doc')
|
42
|
+
@junodoc.close_document
|
43
|
+
end
|
44
|
+
end
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe JunoDoc do
|
4
|
+
describe "#configure" do
|
5
|
+
it "should yield a configuration object" do
|
6
|
+
JunoDoc.configure do |config|
|
7
|
+
config.class.must_equal(JunoDoc::Configuration)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should yield to a block to set up it's configuration" do
|
12
|
+
JunoDoc.configure do |config|
|
13
|
+
config.class_path << '/duh/buh/fuh'
|
14
|
+
end
|
15
|
+
|
16
|
+
JunoDoc.configuration[:class_path].must_include '/duh/buh/fuh'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'lib/junodoc'
|
3
|
+
|
4
|
+
JunoDoc.configure do |config|
|
5
|
+
config.class_path << '/Applications/OpenOffice.org.app/Contents/MacOS/'
|
6
|
+
config.class_path << '/Applications/OpenOffice.org.app/Contents/basis-link/ure-link/share/java'
|
7
|
+
config.class_path << '/Applications/OpenOffice.org.app/Contents/basis-link/program/classes'
|
8
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: junodoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Herrera
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-09 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: JunoDoc makes it easier to work with the OpenOffice API to create word97 compatible documents.
|
18
|
+
email:
|
19
|
+
- dan@revelationglobal.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- Rakefile
|
30
|
+
- Readme
|
31
|
+
- junodoc.gemspec
|
32
|
+
- lib/junodoc.rb
|
33
|
+
- lib/junodoc/configuration.rb
|
34
|
+
- lib/junodoc/document.rb
|
35
|
+
- lib/junodoc/version.rb
|
36
|
+
- spec/benchmark_test.rb
|
37
|
+
- spec/configuration_spec.rb
|
38
|
+
- spec/document_spec.rb
|
39
|
+
- spec/fixtures/image.jpg
|
40
|
+
- spec/junodoc_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: ""
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 2
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 2
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: junodoc
|
72
|
+
rubygems_version: 1.5.1
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: JunoDoc is a jRuby wrapper to the OpenOffice UNO API
|
76
|
+
test_files:
|
77
|
+
- spec/benchmark_test.rb
|
78
|
+
- spec/configuration_spec.rb
|
79
|
+
- spec/document_spec.rb
|
80
|
+
- spec/fixtures/image.jpg
|
81
|
+
- spec/junodoc_spec.rb
|
82
|
+
- spec/spec_helper.rb
|