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 CHANGED
@@ -5,11 +5,5 @@ require 'bundler'
5
5
  Bundler.setup
6
6
 
7
7
  Rake::TestTask.new do |t|
8
- #ENV['JAVA_OPTS'] = "-d32"
9
8
  t.pattern = "spec/*_spec.rb"
10
9
  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 CHANGED
@@ -1,6 +1,6 @@
1
1
  JunoDoc - a jRuby interface to OpenOffice.org's UNO interface.
2
2
 
3
- This is a jruby library to test the feasibility of using the UNO Java API to generate documents programmatically.
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 OpenOffice UNO API}
12
- s.description = %q{JunoDoc makes it easier to work with the OpenOffice API to create word97 compatible documents.}
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
 
@@ -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
- 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
20
+ @doc = create_document
18
21
  end
19
22
 
20
23
  def add_text(text)
21
- @document_text.insertString(@cursor, text, false)
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
- xTextContent = com::sun::star::uno::UnoRuntime.queryInterface(com::sun::star::text::XTextContent.java_class, oGraphic)
34
- @document_text.insertTextContent(@cursor, xTextContent, true);
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
- @document_text.insertControlCharacter(@cursor, com::sun::star::text::ControlCharacter.PARAGRAPH_BREAK, false)
33
+ @doc.getBody.addEle(BreakLine.new)
39
34
  end
40
35
 
41
36
  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)
37
+ writer = PrintWriter.new(File.new(path + @name))
38
+ writer.println(@doc.getContent)
39
+ writer.close
53
40
  end
54
41
 
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)
42
+ def stream_document
43
+ @doc.getContent
58
44
  end
59
45
 
60
46
  private
61
- def create_context
62
- com::sun::star::comp::helper::Bootstrap.bootstrap()
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
@@ -1,3 +1,3 @@
1
1
  module Junodoc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,15 +1,15 @@
1
1
  require File.dirname(__FILE__) + "/spec_helper"
2
+ require 'benchmark'
2
3
 
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")
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
@@ -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/test.doc')
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 << '/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'
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.1
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-09 00:00:00 -07:00
13
+ date: 2011-06-10 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
- description: JunoDoc makes it easier to work with the OpenOffice API to create word97 compatible documents.
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 OpenOffice UNO API
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