Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/gendiapo/publisher/FlowPublisher.java


1   package org.gendiapo.publisher;
2   
3   import javax.xml.transform.*;
4   import javax.xml.transform.sax.*;
5   import javax.xml.transform.stream.*;
6   
7   import org.w3c.dom.*;
8   import org.xml.sax.*;
9   import org.apache.fop.apps.*;
10    
11  import java.io.*;  
12  import java.util.*;
13  import java.net.*;
14  
15  import org.merlotxml.util.xml.*;
16  
17  public class FlowPublisher {
18  
19      Publisher   _publisher;
20      InputStream _document;
21  
22      public FlowPublisher(Publisher publisher, InputStream document) {    
23    _publisher = publisher;
24    _document  = document;
25      }
26      
27      /**
28       * apply to current document xsl transformation describes by file xslFile.
29       * current document is replace by the result document.
30       * @return if transformation was apply
31       */
32      public boolean applyXslt(String xslFile) {
33    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
34    boolean retval = _publisher.applyXslt(_document, xslFile, outputStream);
35    byte[] byteDocument = outputStream.toByteArray();
36    _document = new ByteArrayInputStream(byteDocument);
37    return retval;
38      }
39      
40      /**
41       * apply to current document
42       *
43       */
44      public Document applyXsltToDocument(String xslFile) {
45    Document doc;
46    try {
47        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
48        boolean retval = _publisher.applyXslt(_document, xslFile, outputStream);
49        _document.reset();
50        byte[] byteDocument = outputStream.toByteArray();
51        InputStream is = new ByteArrayInputStream(byteDocument);
52        doc = DOMLiaisonFactory.getDOMLiaison().parseXMLStream(is);
53    } catch (Exception e) {
54        doc = null;
55        _publisher.addError("exception(applyXsltToDocument):"+e);
56    }
57    return doc;
58      }
59      
60      public boolean applyXslt(String xslFile, File output) {
61    boolean retval = false;  
62    try {
63              retval = _publisher.applyXslt(_document, xslFile, new FileOutputStream(output));
64              _document.reset();
65    } 
66    catch (FileNotFoundException e) {
67        retval = false;
68    } 
69    catch (IOException e) {
70        retval = false;
71    }
72    return retval;
73      }
74      
75      public void parseXslfo(File output) {
76    _publisher.applyXslfo(_document, output);
77      }
78      
79  
80  }