junodoc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -6
- data/Readme +1 -1
- data/jars/j2w-ejb-2.0_2011Jun06.jar +0 -0
- data/jars/xstream-1.3.1.jar +0 -0
- data/junodoc.gemspec +2 -2
- data/lib/junodoc/document.rb +26 -50
- data/lib/junodoc/version.rb +1 -1
- data/spec/benchmark_test.rb +11 -11
- data/spec/document_spec.rb +2 -8
- data/spec/spec_helper.rb +1 -3
- metadata +6 -4
data/Rakefile
CHANGED
data/Readme
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
JunoDoc - a jRuby interface to OpenOffice.org's UNO interface.
|
2
2
|
|
3
|
-
This is a jruby
|
3
|
+
This is a jruby gem to provide a programatic way to create word documents using jruby
|
4
4
|
|
5
5
|
TODO:
|
6
6
|
|
Binary file
|
Binary file
|
data/junodoc.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Dan Herrera"]
|
9
9
|
s.email = ["dan@revelationglobal.com"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{JunoDoc is a jRuby wrapper to the
|
12
|
-
s.description = %q{JunoDoc makes
|
11
|
+
s.summary = %q{JunoDoc is a jRuby wrapper to the java2word java library}
|
12
|
+
s.description = %q{JunoDoc makes a ruby wrapper around the java2word library to create word compatible documents.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "junodoc"
|
15
15
|
|
data/lib/junodoc/document.rb
CHANGED
@@ -1,75 +1,51 @@
|
|
1
1
|
module JunoDoc
|
2
|
+
require 'jars/j2w-ejb-2.0_2011Jun06'
|
3
|
+
require 'jars/xstream-1.3.1'
|
4
|
+
|
2
5
|
class Document
|
6
|
+
import 'java.io.PrintWriter'
|
7
|
+
import 'java.io.File'
|
8
|
+
import 'word.api.interfaces.IDocument'
|
9
|
+
import 'word.w2004.Document2004'
|
10
|
+
import 'word.w2004.elements.BreakLine'
|
11
|
+
import 'word.w2004.elements.Heading1'
|
12
|
+
import 'word.w2004.elements.Image'
|
13
|
+
import 'word.w2004.elements.ImageLocation'
|
14
|
+
import 'word.w2004.elements.Paragraph'
|
15
|
+
import 'word.w2004.elements.Table'
|
16
|
+
|
3
17
|
attr_accessor :name
|
4
18
|
|
5
19
|
def initialize
|
6
|
-
|
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
|
20
|
+
@doc = create_document
|
18
21
|
end
|
19
22
|
|
20
23
|
def add_text(text)
|
21
|
-
@
|
24
|
+
@doc.getBody.addEle(Paragraph.new(text))
|
22
25
|
end
|
23
26
|
|
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
27
|
|
33
|
-
|
34
|
-
@
|
28
|
+
def add_image(image_url)
|
29
|
+
@doc.getBody.addEle(Image.from_WEB_URL(image_url))
|
35
30
|
end
|
36
31
|
|
37
32
|
def add_paragraph_break
|
38
|
-
@
|
33
|
+
@doc.getBody.addEle(BreakLine.new)
|
39
34
|
end
|
40
35
|
|
41
36
|
def write_document(path)
|
42
|
-
|
43
|
-
|
44
|
-
|
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)
|
37
|
+
writer = PrintWriter.new(File.new(path + @name))
|
38
|
+
writer.println(@doc.getContent)
|
39
|
+
writer.close
|
53
40
|
end
|
54
41
|
|
55
|
-
def
|
56
|
-
|
57
|
-
xCloseable.close(false)
|
42
|
+
def stream_document
|
43
|
+
@doc.getContent
|
58
44
|
end
|
59
45
|
|
60
46
|
private
|
61
|
-
def
|
62
|
-
|
47
|
+
def create_document
|
48
|
+
@doc = Document2004.new
|
63
49
|
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
50
|
end
|
75
51
|
end
|
data/lib/junodoc/version.rb
CHANGED
data/spec/benchmark_test.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
require 'benchmark'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
Benchmark.benchmark do |x|
|
5
|
+
x.report("creating 1 docs with 500 images and paragraphs") do
|
6
|
+
@junodoc = JunoDoc::Document.new
|
7
|
+
@junodoc.name = "test.doc"
|
8
|
+
500.times do
|
9
|
+
@junodoc.add_text("istanbul, not constantinople")
|
10
|
+
@junodoc.add_paragraph_break
|
11
|
+
@junodoc.add_image("file://#{Dir.pwd}/spec/fixtures/image.jpg")
|
12
|
+
end
|
13
|
+
@junodoc.write_document(Dir.pwd + '/spec/output/')
|
11
14
|
end
|
12
|
-
@junodoc.write_document(Dir.pwd + '/spec/output/test.doc')
|
13
|
-
@junodoc.close_document
|
14
|
-
puts Time.now
|
15
15
|
end
|
data/spec/document_spec.rb
CHANGED
@@ -3,42 +3,36 @@ require File.dirname(__FILE__) + "/spec_helper"
|
|
3
3
|
describe JunoDoc::Document do
|
4
4
|
before do
|
5
5
|
@junodoc = JunoDoc::Document.new
|
6
|
+
@junodoc.name = "what's_up.doc"
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should be an instance of JunoDoc::Document" do
|
9
10
|
@junodoc.class.must_equal(JunoDoc::Document)
|
10
|
-
@junodoc.close_document
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should be able to set the name of the document" do
|
14
|
-
@junodoc.name = "what's_up.doc"
|
15
14
|
@junodoc.name.must_equal("what's_up.doc")
|
16
|
-
@junodoc.close_document
|
17
15
|
end
|
18
16
|
|
19
17
|
it "should be able to add text to the document" do
|
20
18
|
@junodoc.add_text("istanbul, not constantinople")
|
21
|
-
@junodoc.close_document
|
22
19
|
end
|
23
20
|
|
24
21
|
it "should be able to add a paragraph break" do
|
25
22
|
@junodoc.add_text("istanbul, not constantinople")
|
26
23
|
@junodoc.add_paragraph_break
|
27
|
-
@junodoc.close_document
|
28
24
|
end
|
29
25
|
|
30
26
|
it "should be able to add an image by url" do
|
31
27
|
@junodoc.add_text("istanbul, not constantinople")
|
32
28
|
@junodoc.add_paragraph_break
|
33
29
|
@junodoc.add_image("file://#{Dir.pwd}/spec/fixtures/image.jpg")
|
34
|
-
@junodoc.close_document
|
35
30
|
end
|
36
31
|
|
37
32
|
it "should be able to write out the document to disk" do
|
38
33
|
@junodoc.add_text("istanbul, not constantinople")
|
39
34
|
@junodoc.add_paragraph_break
|
40
35
|
@junodoc.add_image("file://#{Dir.pwd}/spec/fixtures/image.jpg")
|
41
|
-
@junodoc.write_document(Dir.pwd + '/spec/output/
|
42
|
-
@junodoc.close_document
|
36
|
+
@junodoc.write_document(Dir.pwd + '/spec/output/')
|
43
37
|
end
|
44
38
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,5 @@ require 'minitest/autorun'
|
|
2
2
|
require 'lib/junodoc'
|
3
3
|
|
4
4
|
JunoDoc.configure do |config|
|
5
|
-
config.class_path << '/
|
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'
|
5
|
+
config.class_path << 'jars/'
|
8
6
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: junodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Herrera
|
@@ -10,11 +10,11 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-10 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
17
|
-
description: JunoDoc makes
|
17
|
+
description: JunoDoc makes a ruby wrapper around the java2word library to create word compatible documents.
|
18
18
|
email:
|
19
19
|
- dan@revelationglobal.com
|
20
20
|
executables: []
|
@@ -28,6 +28,8 @@ files:
|
|
28
28
|
- Gemfile
|
29
29
|
- Rakefile
|
30
30
|
- Readme
|
31
|
+
- jars/j2w-ejb-2.0_2011Jun06.jar
|
32
|
+
- jars/xstream-1.3.1.jar
|
31
33
|
- junodoc.gemspec
|
32
34
|
- lib/junodoc.rb
|
33
35
|
- lib/junodoc/configuration.rb
|
@@ -72,7 +74,7 @@ rubyforge_project: junodoc
|
|
72
74
|
rubygems_version: 1.5.1
|
73
75
|
signing_key:
|
74
76
|
specification_version: 3
|
75
|
-
summary: JunoDoc is a jRuby wrapper to the
|
77
|
+
summary: JunoDoc is a jRuby wrapper to the java2word java library
|
76
78
|
test_files:
|
77
79
|
- spec/benchmark_test.rb
|
78
80
|
- spec/configuration_spec.rb
|