hirobumi-chocolate_disco-jruby 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,123 @@
1
+ = Chocolate Disco
2
+
3
+ == Description
4
+
5
+ Provides methods to extract texts from various file formats like Microsoft Office (<= 2002, as well as >= 2007,) PDF and HTML.
6
+
7
+ == Installation
8
+
9
+ sudo gem install hirobumi-chocolate_disco-jruby -s http://gems.github.com/ --no-ri --no-rdoc
10
+
11
+ == Usage
12
+
13
+ require 'rubygems'
14
+ require 'chocolate_disco'
15
+
16
+ ChocolateDisco.extract('/path/to/file.ext')
17
+
18
+ == License
19
+
20
+ Copyright (c) 2009 Hirobumi Hama
21
+
22
+ Permission is hereby granted, free of charge, to any person
23
+ obtaining a copy of this software and associated documentation
24
+ files (the "Software"), to deal in the Software without
25
+ restriction, including without limitation the rights to use,
26
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ copies of the Software, and to permit persons to whom the
28
+ Software is furnished to do so, subject to the following
29
+ conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
36
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
38
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
39
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
40
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
41
+ OTHER DEALINGS IN THE SOFTWARE.
42
+
43
+ == Bundles
44
+
45
+ === JTextExtract
46
+
47
+ by Jaideep Pillai
48
+
49
+ http://code.google.com/p/jtextextract
50
+
51
+ JTextExtract is licensed under the GNU Lesser General Public License. (http://www.gnu.org/licenses/lgpl.html)
52
+
53
+ === PDFBox
54
+
55
+ http://incubator.apache.org/pdfbox
56
+
57
+ by the Apache Software Foundation
58
+
59
+ PDFBox is licensed under the the Apache License, Version 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
60
+
61
+ === The Bouncy Castle Crypto APIs
62
+
63
+ http://www.bouncycastle.org
64
+
65
+ by the Legion of the Bouncy Castle
66
+
67
+ Copyright (c) 2000 - 2008 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
68
+
69
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74
+
75
+ === dom4j
76
+
77
+ http://www.dom4j.org
78
+
79
+ by MetaStuff, Ltd.
80
+
81
+ Redistribution and use of this software and associated documentation ("Software"), with or without modification, are permitted provided that the following conditions are met:
82
+
83
+ Redistributions of source code must retain copyright statements and notices. Redistributions must also contain a copy of this document.
84
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
85
+ The name "DOM4J" must not be used to endorse or promote products derived from this Software without prior written permission of MetaStuff, Ltd. For written permission, please contact dom4j-info@metastuff.com.
86
+ Products derived from this Software may not be called "DOM4J" nor may "DOM4J" appear in their names without prior written permission of MetaStuff, Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
87
+ Due credit should be given to the DOM4J Project - http://www.dom4j.org
88
+ THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89
+
90
+ Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
91
+
92
+ === log4j
93
+
94
+ http://logging.apache.org/log4j
95
+
96
+ by the Apache Software Foundation
97
+
98
+ log4j is licensed under the the Apache License, Version 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
99
+
100
+ === OpenXML4J
101
+
102
+ http://openxml4j.org
103
+
104
+ by Wygwam
105
+
106
+ Copyright (c) 2006, Wygwam
107
+ All rights reserved.
108
+
109
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
110
+
111
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
112
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
113
+ - Neither the name of Wygwam nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114
+
115
+ We chose to use the BSD license and the open source development model because we think that allows developers and companies from all around the world to participate, use & contribute to the project without restriction.
116
+
117
+ === The Apache POI
118
+
119
+ http://poi.apache.org
120
+
121
+ by the Apache Software Foundation
122
+
123
+ The Apache POI is licensed under the the Apache License, Version 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/chocolate_disco/version'
6
+
7
+ task :default => :test
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = 'chocolate_disco-jruby'
11
+ s.version = ChocolateDisco::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.rdoc)
14
+ s.rdoc_options = %w(--main README.rdoc)
15
+ s.summary = "Provides methods to extract texts from various file formats like Microsoft Office (<= 2002, as well as >= 2007,) PDF and HTML."
16
+ s.author = 'Hirobumi Hama'
17
+ s.email = 'hama@yoidore.org'
18
+ s.homepage = 'http://yoidore.org/chocolate_disco'
19
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
20
+ s.executables = ['chocolate_disco']
21
+
22
+ s.add_dependency('mime-types', '>= 1.16')
23
+ end
24
+
25
+ Rake::GemPackageTask.new(spec) do |pkg|
26
+ pkg.gem_spec = spec
27
+ end
28
+
29
+ Rake::TestTask.new do |t|
30
+ t.libs << 'test'
31
+ t.test_files = FileList["test/**/*_test.rb"]
32
+ t.verbose = true
33
+ end
34
+
35
+ desc 'Generate the gemspec to serve this Gem from Github'
36
+ task :github do
37
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
38
+ File.open(file, 'w') {|f| f << spec.to_ruby }
39
+ puts "Created gemspec: #{file}"
40
+ end
41
+
42
+ desc 'Drops into interactive Ruby'
43
+ task :irb do
44
+ require 'lib/chocolate_disco'
45
+
46
+ ARGV.delete_at(ARGV.index('irb'))
47
+ require 'irb'
48
+ IRB.start
49
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'rubygems'
4
+ require 'open-uri'
5
+
6
+ begin
7
+ require 'chocolate_disco'
8
+ rescue LoadError
9
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'chocolate_disco'))
10
+ end
11
+
12
+ if ARGV.length == 0
13
+ STDERR.puts("#{File.basename(__FILE__)} #{ChocolateDisco::Version.to_s}")
14
+ STDERR.puts("USAGE: chocolate_disco /path/to/file_with.extension [mime]")
15
+ end # if ARGV.length == 0
16
+
17
+ unless ARGV[0].nil?
18
+ if File.exists?(ARGV[0]) && !File.directory?(ARGV[0])
19
+ STDERR.puts("Forcing MIME to be '#{ARGV[1]}'.") if ARGV[1].is_a?(String)
20
+ puts(ChocolateDisco.extract(ARGV[0], :force_mime => ARGV[1]))
21
+ else # if File.exists?(ARGV[0])
22
+ STDERR.puts("File '#{ARGV[0]}' not found.")
23
+ end # else if File.exists?(ARGV[0])
24
+ end # unless ARGV[0].nil?
@@ -0,0 +1,13 @@
1
+ raise(NotImplementedError.new([
2
+ 'ChocolateDisco (chocolate_disco-jruby) is not supported in this Ruby.',
3
+ 'Use JRuby or try The Apache POI Ruby Bindings.'
4
+ ].join("\n"))) unless RUBY_PLATFORM == 'java'
5
+
6
+ $:.unshift File.dirname(__FILE__)
7
+
8
+ module ChocolateDisco
9
+ end # module ChocolateDisco
10
+
11
+ require 'chocolate_disco/version'
12
+ require 'chocolate_disco/java'
13
+ require 'chocolate_disco/chocolate_disco'
@@ -0,0 +1,62 @@
1
+ gem 'mime-types', '>= 1.16'
2
+ require 'mime/types'
3
+
4
+ module ChocolateDisco
5
+
6
+ class << self
7
+
8
+ @@supported_mime_types = nil
9
+
10
+ # returns an array of supported mime types.
11
+ def supported_mime_types
12
+ @@supported_mime_types ||= Java::SupportedMimeTypes.constants.map { |const| eval("Java::SupportedMimeTypes::#{const}") }
13
+ end # def supported_mime_types
14
+
15
+ # returns whether or not the file is supported.
16
+ # :path to specify the file. :mime to specify the mime.
17
+ # :mimes to give an array of mimes.
18
+ def supported?(opts = {})
19
+ mimes = []
20
+ mimes << opts[:mime] if opts[:mime].is_a?(String)
21
+ mimes += opts[:mimes] if opts[:mimes].is_a?(Array)
22
+
23
+ if opts[:path].is_a?(String) && File.exists?(opts[:path]) && !File.directory?(opts[:path]) && File.file?(opts[:path])
24
+ begin
25
+ mimes << MIME::Types.of(opts[:path]).map { |mime| mime.simplified }
26
+ rescue NoMethodError # begin
27
+ raise(NotImplementedError.new("MIME types of a file '#{opts[:path]}' could not be inferred."))
28
+ end # rescue
29
+ end # if opts[:path].is_a?(String) && File.exists?(opts[:path]) && !File.directory?(opts[:path]) && File.file?(opts[:path])
30
+
31
+ mimes.flatten!
32
+ mimes.compact!
33
+ mimes.uniq!
34
+
35
+ mimes.map { |mime| return true if supported_mime_types.include?(mime) }
36
+
37
+ false
38
+ end # def supported?(opts = {})
39
+
40
+ # extracts text from path, returns string, empty string or nil.
41
+ def extract(path, opts = {})
42
+
43
+ if opts[:force_mime].is_a?(String)
44
+ mimes = [opts[:force_mime]]
45
+ else
46
+ mimes = MIME::Types.of(path).map { |mime| mime.simplified }
47
+ end
48
+
49
+ raise(NotImplementedError.new("MIME (#{mimes.join(', ')}) for '#{path}' is not supported by chocolate_disco.")) unless supported?(:mimes => mimes)
50
+
51
+ extractor = mimes.map { |mime| Java::TextExtractionFactory.getExtractor(mime) }[0]
52
+
53
+ raise(RuntimeError.new('TextExtractionFactory failed to get an instance of TextExtractor, which is impossible.')) if extractor.nil?
54
+
55
+ extractor.extractText(java.io.File.new(path))
56
+ end # def extract
57
+
58
+ alias :lets_party! :extract
59
+
60
+ end # class << self
61
+
62
+ end # module ChocolateDisco
@@ -0,0 +1,15 @@
1
+ module ChocolateDisco
2
+
3
+ module Java
4
+
5
+ Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), 'java', '*.jar'))).each do |jar|
6
+ require(jar)
7
+ end
8
+
9
+ %w(HTMLExtractor MSExcelExtractor MSOffice2007Extractor MSPPTExtractor MSVisioExtractor MSWordExtractor PDFExtractor SupportedMimeTypes TextExtractionFactory TxtTextExtractor XMLExtractor).each do |klass_name|
10
+ include_class "org.jaideep.jtextextract.#{klass_name}"
11
+ end # %w(...).each do |klass_name|
12
+
13
+ end # module Java
14
+
15
+ end # module ChocolateDisco
@@ -0,0 +1,13 @@
1
+ module ChocolateDisco
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 2
7
+
8
+ def self.to_s # :nodoc:
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # http://sneaq.net/textmate-wtf
2
+ $:.reject! { |e| e.include? 'TextMate' }
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+
7
+ gem 'thoughtbot-shoulda', '>= 2.10.1'
8
+ require 'shoulda'
9
+
10
+ require File.dirname(__FILE__) + '/../lib/chocolate_disco'
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class ChocolateDiscoTest < Test::Unit::TestCase
4
+
5
+ context 'bin/chocolate_disco' do
6
+
7
+ should 'have tests' do
8
+ flunk('TODO')
9
+ end
10
+
11
+ end
12
+
13
+ context 'ChocolateDisco' do
14
+
15
+ should 'have tests' do
16
+ flunk('TODO')
17
+ end
18
+
19
+ ["application/vnd.visio", "application/pdf", "text/html", "text/xml", "application/vnd.ms-excel", "application/vnd.openxmlformats ", "text", "application/rtf", "application/vnd.ms-powerpoint", "application/msword"].each do |mime|
20
+
21
+ should "support #{mime}" do
22
+ assert(ChocolateDisco.supported?(:mime => mime))
23
+ end
24
+
25
+ end # [mime, ...].each do |mime|
26
+
27
+ end
28
+
29
+ end # class ChocolateDiscoTest < Test::Unit::TestCase
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hirobumi-chocolate_disco-jruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Hirobumi Hama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-11 00:00:00 -07:00
13
+ default_executable: chocolate_disco
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mime-types
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.16"
24
+ version:
25
+ description:
26
+ email: hama@yoidore.org
27
+ executables:
28
+ - chocolate_disco
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/chocolate_disco
37
+ - lib/chocolate_disco/chocolate_disco.rb
38
+ - lib/chocolate_disco/java
39
+ - lib/chocolate_disco/java/apache-pdfbox-0.8.0-incubator-dev.jar
40
+ - lib/chocolate_disco/java/bcprov-jdk15-142.jar
41
+ - lib/chocolate_disco/java/dom4j-1.6.1.jar
42
+ - lib/chocolate_disco/java/JTextExtract.jar
43
+ - lib/chocolate_disco/java/log4j-1.2.13.jar
44
+ - lib/chocolate_disco/java/openxml4j-bin-beta.jar
45
+ - lib/chocolate_disco/java/poi-3.2-FINAL-20081019.jar
46
+ - lib/chocolate_disco/java/poi-scratchpad-3.2-FINAL-20081019.jar
47
+ - lib/chocolate_disco/java.rb
48
+ - lib/chocolate_disco/version.rb
49
+ - lib/chocolate_disco.rb
50
+ - test/sample
51
+ - test/test_helper.rb
52
+ - test/unit
53
+ - test/unit/chocolate_disco_test.rb
54
+ - bin/chocolate_disco
55
+ has_rdoc: true
56
+ homepage: http://yoidore.org/chocolate_disco
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --main
60
+ - README.rdoc
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.2.0
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: Provides methods to extract texts from various file formats like Microsoft Office (<= 2002, as well as >= 2007,) PDF and HTML.
82
+ test_files: []
83
+