Class: Libis::Format::Tool::FopPdf

Inherits:
Object
  • Object
show all
Includes:
Tools::Logger
Defined in:
lib/libis/format/tool/fop_pdf.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(xml, target, options = []) ⇒ Object



16
17
18
# File 'lib/libis/format/tool/fop_pdf.rb', line 16

def self.run(xml, target, options = [])
  self.new.run xml, target, options
end

Instance Method Details

#run(xml, target, options = []) ⇒ Object

Raises:

  • (RuntimeError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/libis/format/tool/fop_pdf.rb', line 20

def run(xml, target, options = [])

  if OS.java?
    # TODO: import library and execute in current VM. For now do exactly as in MRI.
  end

  timeout = Libis::Format::Config[:timeouts][:fop]
  result = Libis::Tools::Command.run(
      Libis::Format::Config[:java_path],
      "-Dfop.home=#{File.dirname(Libis::Format::Config[:fop_jar])}",
      '-jar', Libis::Format::Config[:fop_jar],
      '-fo', xml,
      '-pdf', target,
      timeout: timeout,
      kill_after: timeout * 2
  )

  raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
  raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0

end