[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf/ui ...

Norman Richards norman.richards at jboss.com
Mon Jan 15 14:36:41 EST 2007


  User: nrichards
  Date: 07/01/15 14:36:41

  Modified:    src/pdf/org/jboss/seam/pdf/ui  UIDocument.java
  Log:
  basic support for RTF
  
  Revision  Changes    Path
  1.6       +54 -10    jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIDocument.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- UIDocument.java	11 Jan 2007 05:32:06 -0000	1.5
  +++ UIDocument.java	15 Jan 2007 19:36:41 -0000	1.6
  @@ -1,23 +1,42 @@
   package org.jboss.seam.pdf.ui;
   
   import org.jboss.seam.pdf.ITextUtils;
  -import org.jboss.seam.pdf.PDFStore;
  +import org.jboss.seam.pdf.DocumentStore;
   
   import javax.faces.context.*;
   import java.io.*;
   
   import com.lowagie.text.*;
   import com.lowagie.text.pdf.*;
  +import com.lowagie.text.rtf.RtfWriter;
  +import com.lowagie.text.rtf.RtfWriter2;
   
   public class UIDocument 
       extends ITextComponent
   {
       public static final String COMPONENT_TYPE   = "org.jboss.seam.pdf.ui.UIDocument";
   
  +    enum DocType { 
  +           PDF("application/pdf"), 
  +           RTF("text/rtf");
  +           
  +           private String mimeType;
  +
  +           DocType(String mimeType) {
  +               this.mimeType = mimeType;
  +           }
  +           
  +           public String getMimeType() {
  +               return mimeType;
  +           }
  +    }
  +    
       Document document;
       ByteArrayOutputStream stream;
       String id;
  +    DocType docType;
   
  +    String type;
       String title;
       String subject;
       String keywords;
  @@ -28,6 +47,9 @@
       String margins;
       Boolean marginMirroring;
    
  +    public void setType(String type) {
  +        this.type = type;
  +    }
   
       public void setMargins(String margins) {
          this.margins = margins;
  @@ -66,6 +88,9 @@
       }
   
       public void createITextObject(FacesContext context) {
  +        type = (String) valueBinding(context, "type", type);        
  +        docType = docTypeForName(type);
  +        
           document = new Document();
           // most of this needs to be done BEFORE document.open();
           
  @@ -139,11 +164,19 @@
       {
           super.encodeBegin(context);
           
  -        id = PDFStore.instance().newId();
  +        id = DocumentStore.instance().newId();
           stream = new ByteArrayOutputStream();
   
           try {
  +            switch (docType) {
  +            case PDF:
               PdfWriter.getInstance(document, stream);
  +                break;
  +            case RTF:
  +                RtfWriter2.getInstance(document, stream);
  +                break;
  +            }
  +
               
               initMetaData(context);
               
  @@ -157,7 +190,7 @@
           response.startElement("head", this);
           response.startElement("meta", this);
           response.writeAttribute("http-equiv", "Refresh", null);
  -        response.writeAttribute("content", "0; URL=seam-pdf.seam?pdfId="+id, null);
  +        response.writeAttribute("content", "0; URL=seam-doc.seam?docId="+id, null);
   
           response.endElement("meta");
           response.endElement("head");
  @@ -171,7 +204,9 @@
       {
           document.close();
   
  -        PDFStore.instance().saveData(id,stream.toByteArray());        
  +        DocumentStore.instance().saveData(id,
  +                                          docType.getMimeType(),
  +                                          stream.toByteArray());        
   
           ResponseWriter response = context.getResponseWriter();
           response.endElement("body");
  @@ -180,5 +215,14 @@
           removeITextObject();
       }
   
  -
  +    private DocType docTypeForName(String typeName) {    
  +        if (typeName != null) {
  +            if (typeName.equalsIgnoreCase(DocType.PDF.name())) {
  +                return DocType.PDF;
  +            } else if (typeName.equalsIgnoreCase(DocType.RTF.name())) {
  +                return DocType.RTF;
  +            }
  +        }
  +        return DocType.PDF;
  +    }
   }
  
  
  



More information about the jboss-cvs-commits mailing list