Class: ASFop
- Inherits:
 - 
      Object
      
        
- Object
 - ASFop
 
 - Defined in:
 - backend/app/lib/AS_fop.rb
 
Instance Attribute Summary (collapse)
- 
  
    
      - (Object) output 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute output.
 - 
  
    
      - (Object) source 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute source.
 - 
  
    
      - (Object) xslt 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute xslt.
 
Instance Method Summary (collapse)
- 
  
    
      - (ASFop) initialize(source, output = nil) 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of ASFop.
 - 
  
    
      - (Object) to_fo 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      - (Object) to_pdf 
    
    
  
  
  
  
  
  
  
  
  
    
returns a temp file with the converted PDF.
 - 
  
    
      - (Object) to_pdf_stream 
    
    
  
  
  
  
  
  
  
  
  
    
 
Constructor Details
- (ASFop) initialize(source, output = nil)
Returns a new instance of ASFop
      23 24 25 26 27  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 23 def initialize(source, output= nil) @source = source @output = output ? output : ASUtils.tempfile('fop.pdf') @xslt = File.read( StaticAssetFinder.new(File.join('stylesheets')).find('as-ead-pdf.xsl')) end  | 
  
Instance Attribute Details
- (Object) output
Returns the value of attribute output
      20 21 22  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 20 def output @output end  | 
  
- (Object) source
Returns the value of attribute source
      19 20 21  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 19 def source @source end  | 
  
- (Object) xslt
Returns the value of attribute xslt
      21 22 23  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 21 def xslt @xslt end  | 
  
Instance Method Details
- (Object) to_fo
      30 31 32 33  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 30 def to_fo transformer = Saxon.XSLT(@xslt, system_id: File.join(ASUtils.find_base_directory, 'stylesheets', 'as-ead-pdf.xsl') ) transformer.transform(Saxon.XML(@source)).to_s end  | 
  
- (Object) to_pdf
returns a temp file with the converted PDF
      36 37 38 39 40 41 42 43 44 45 46 47 48 49  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 36 def to_pdf begin fo = StringIO.new(to_fo).to_inputstream fopfac = FopFactory.newInstance fopfac.setBaseURL( File.join(ASUtils.find_base_directory, 'stylesheets') ) fop = fopfac.newFop(MimeConstants::MIME_PDF, @output.to_outputstream) transformer = TransformerFactory.newInstance.newTransformer() res = SAXResult.new(fop.getDefaultHandler) transformer.transform(StreamSource.new(fo), res) ensure @output.close end @output end  | 
  
- (Object) to_pdf_stream
      51 52 53 54 55 56 57 58 59 60 61 62 63 64  | 
    
      # File 'backend/app/lib/AS_fop.rb', line 51 def to_pdf_stream begin fo = StringIO.new(to_fo).to_inputstream fop = FopFactory.newInstance.newFop(MimeConstants::MIME_PDF, @output.to_outputstream) transformer = TransformerFactory.newInstance.newTransformer() res = SAXResult.new(fop.getDefaultHandler) transformer.transform(StreamSource.new(fo), res) @output.rewind @output.read ensure @output.close @output.unlink end end  |