You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by tc...@apache.org on 2003/05/20 21:22:50 UTC

cvs commit: cocoon-2.1/src/blocks/itext/lib itext-0.99.jar itext-xml-0.99.jar itext-0.93b.jar itext-xml-0.93.jar

tcurdt      2003/05/20 12:22:50

  Modified:    src/blocks/itext/java/org/apache/cocoon/serialization
                        iTextSerializer.java
  Added:       src/blocks/itext/lib itext-0.99.jar itext-xml-0.99.jar
  Removed:     src/blocks/itext/lib itext-0.93b.jar itext-xml-0.93.jar
  Log:
  fixed bug #19842 thanks to Michael Enke
  and added the page-size and page-orientation parameters
  
  Revision  Changes    Path
  1.4       +51 -4     cocoon-2.1/src/blocks/itext/java/org/apache/cocoon/serialization/iTextSerializer.java
  
  Index: iTextSerializer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/itext/java/org/apache/cocoon/serialization/iTextSerializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- iTextSerializer.java	19 Mar 2003 15:42:15 -0000	1.3
  +++ iTextSerializer.java	20 May 2003 19:22:49 -0000	1.4
  @@ -64,6 +64,8 @@
   import org.xml.sax.SAXException;
   
   import com.lowagie.text.Document;
  +import com.lowagie.text.PageSize;
  +import com.lowagie.text.Rectangle;
   import com.lowagie.text.pdf.PdfWriter;
   import com.lowagie.text.xml.SAXiTextHandler;
   
  @@ -73,15 +75,55 @@
    */
   final public class iTextSerializer extends AbstractSerializer implements Configurable, CacheableProcessingComponent {
   
  +    private final static boolean LANDSCAPE = true;
  +    private final static boolean PORTRAIT = false;
  +
       private String mimetype = "application/pdf";
       private boolean setContentLength = true;
  +    private Rectangle pageSize;
  +    private boolean pageOrientation;
       private Document document = null;
   
  +    private Rectangle getPageSize(final String s) throws ConfigurationException {
  +        // TC: we could use reflection here instead
  +        if ("letter".equalsIgnoreCase(s)) {
  +            return PageSize.LETTER;
  +        }
  +        else if ("a4".equalsIgnoreCase(s)) {
  +            return PageSize.A4;
  +        }
  +        else if ("a5".equalsIgnoreCase(s)) {
  +            return PageSize.A5;
  +        }
  +        else {
  +            throw new ConfigurationException("page size [" + String.valueOf(s) + "] is not yet recognized");
  +        }
  +    }
  +
  +    private boolean getOrientation(final String o) throws ConfigurationException {
  +        if ("portrait".equalsIgnoreCase(o)) {
  +            return PORTRAIT;
  +        }
  +        else if ("landscape".equalsIgnoreCase(o)) {
  +            return LANDSCAPE;
  +        }
  +        else {
  +            throw new ConfigurationException("orientation must be either portrait or landscape but is [" + String.valueOf(o) + "]");
  +        }
  +    }
  +
       public void configure(Configuration conf) throws ConfigurationException {
           this.setContentLength = conf.getChild("set-content-length").getValueAsBoolean(true);
           this.mimetype = conf.getAttribute("mime-type");
  +
  +        this.pageSize = getPageSize(conf.getAttribute("page-size","A4"));
  +        this.pageOrientation = getOrientation(conf.getAttribute("page-orientation","portrait"));
  +
  +        if (pageOrientation == LANDSCAPE) {
  +            pageSize.rotate();
  +        }
  +
           getLogger().debug("iTextSerializer mime-type:" + mimetype);
  -        this.document = new Document();
       }
   
       public String getMimeType() {
  @@ -99,14 +141,19 @@
       }
   
       public void setOutputStream(OutputStream out) {
  +        this.document = new Document(this.pageSize);
  +
           try {
  -        PdfWriter.getInstance(document, out);
  +            PdfWriter.getInstance(document, out);
           }
           catch(Exception e) {
               getLogger().error("cannot create pdf writer instance",e);
               //TC: FIXME! shouldn't we throw an exception here? what kind?
           }
  -        this.contentHandler = new SAXiTextHandler(document);
  +
  +        SAXiTextHandler handler = new SAXiTextHandler(document);
  +        handler.setControlOpenClose(true);
  +        this.contentHandler = handler;
       }
   
       public java.io.Serializable getKey() {
  
  
  
  1.1                  cocoon-2.1/src/blocks/itext/lib/itext-0.99.jar
  
  	<<Binary file>>
  
  
  1.1                  cocoon-2.1/src/blocks/itext/lib/itext-xml-0.99.jar
  
  	<<Binary file>>