Class: JavaHelp::JarConverter
- Inherits:
-
Object
- Object
- JavaHelp::JarConverter
- Defined in:
- lib/javahelp.rb
Overview
This class converts Javahelp jar files to TOC objects.
Instance Attribute Summary collapse
-
#jar_file ⇒ Object
readonly
Returns the value of attribute jar_file.
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
Instance Method Summary collapse
-
#convert_tocs ⇒ Object
Converts the Javahelp table of contents files to TOC objects and returns them in an array.
-
#copyContentsTo(target) ⇒ Object
Copy the contents of the Javahelp jar into the target ZipFile.
-
#initialize(jar_file) ⇒ JarConverter
constructor
A new instance of JarConverter.
Constructor Details
#initialize(jar_file) ⇒ JarConverter
Returns a new instance of JarConverter.
11 12 13 14 15 16 |
# File 'lib/javahelp.rb', line 11 def initialize(jar_file) raise "Javehelp file must be supplied" unless jar_file @jar_file = jar_file init_maps init_urls end |
Instance Attribute Details
#jar_file ⇒ Object (readonly)
Returns the value of attribute jar_file.
9 10 11 |
# File 'lib/javahelp.rb', line 9 def jar_file @jar_file end |
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
9 10 11 |
# File 'lib/javahelp.rb', line 9 def maps @maps end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
9 10 11 |
# File 'lib/javahelp.rb', line 9 def urls @urls end |
Instance Method Details
#convert_tocs ⇒ Object
Converts the Javahelp table of contents files to TOC objects and returns them in an array.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/javahelp.rb', line 20 def convert_tocs tocs = [] Zip::ZipFile.open(@jar_file) do |zf| zf.dir.foreach('.') do |entry| if File.extname(entry).downcase.eql?('.hs') contents = zf.file.read(entry) doc = REXML::Document.new(contents) doc.elements.each('helpset/view') do |e| view_type = e.elements['type'].texts.join if view_type.eql?('javax.help.TOCView') toc_name = e.elements['data'].texts.join tocs << TOC.new(toc_name) end end end end tocs.each do |toc| contents = zf.file.read(toc.name) doc = REXML::Document.new(contents) root = doc.root io = StringIO.new xml = Builder::XmlMarkup.new(:indent => 2, :target => io) xml.instruct! xml.toc(:label => 'toc') do root.elements.each do |e| (e, xml) end end toc.xml = io.string end end return tocs end |
#copyContentsTo(target) ⇒ Object
Copy the contents of the Javahelp jar into the target ZipFile. The block is called for each entry in the Javahelp file. If the block returns false, the entry is not copied.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/javahelp.rb', line 58 def copyContentsTo(target) Zip::ZipFile.open(@jar_file) do |zf| zf.each do |entry| if (yield(entry)) target.get_output_stream(entry) do |out| contents = zf.read(entry.name) out.write(contents) end end end end end |