[jboss-cvs] jboss-seam/examples/itext/extra ...

Norman Richards norman.richards at jboss.com
Wed Feb 7 15:44:05 EST 2007


  User: nrichards
  Date: 07/02/07 15:44:05

  Added:       examples/itext/extra            PDFRenderKit.java
                        PDFResponseWriter.java SeamFaceletViewHandler.java
                        TextRenderer.java hdr.bar.jpg hdr.bg.gif
                        pdf-x.xhtml render.xhtml test.xhtml x.xhtml y.xhtml
  Log:
  itext example
  
  Revision  Changes    Path
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/PDFRenderKit.java
  
  Index: PDFRenderKit.java
  ===================================================================
  package org.jboss.seam.ui.pdf;
  
  import javax.faces.event.*;
  import javax.faces.context.*;
  import javax.faces.component.*;
  import javax.faces.render.*;
  import javax.servlet.http.*;
  
  import java.io.*;
  import java.util.*;
  
  import com.lowagie.text.*;
  import com.lowagie.text.pdf.*;
  
  public class PDFRenderKit 
      extends RenderKit 
  {
      Map<String,Renderer> renderers = new HashMap<String,Renderer>();
  
      public ResponseStream createResponseStream(OutputStream stream) {
          System.out.println("RESPONSE STREAM!");
          return null;
      }
  
      
      public ResponseWriter createResponseWriter(Writer writer, 
                                                 String contentTypeList, 
                                                 String characterEncoding) 
      {
          return new PDFResponseWriter(FacesContext.getCurrentInstance(),
                                       writer);
      }
  
      public ResponseStateManager getResponseStateManager() {
          System.out.println("GET RESPONSE STATE MANAGER");
          return null;
      }
  
      public Renderer getRenderer(String family, String rendererType) {
          System.out.println("GET RENDERER: " + family + "/" + rendererType);
          return renderers.get(key(family,rendererType));
      }
  
      public void addRenderer(String family, String rendererType, Renderer renderer) {
          System.out.println("ADD RENDER " + family + "/" + rendererType + ":" + renderer);
          renderers.put(key(family,rendererType), renderer);
      }
                                                                    
      private String key(String family, String rendererType) {
          return family + "#" + rendererType;
      }
  }
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/PDFResponseWriter.java
  
  Index: PDFResponseWriter.java
  ===================================================================
  package org.jboss.seam.ui.pdf;
  
  import javax.faces.*;
  import javax.faces.event.*;
  import javax.faces.context.*;
  import javax.faces.component.*;
  import javax.faces.render.*;
  import javax.servlet.http.*;
  
  import java.io.*;
  
  import com.lowagie.text.*;
  import com.lowagie.text.pdf.*;
  import com.lowagie.text.html.*;
  
  public class PDFResponseWriter
      extends ResponseWriter 
  {
      FacesContext context;
      Writer writer;
      Document document;
  
      public PDFResponseWriter(FacesContext context, Writer writer)
      {
          System.out.println("Context is " + context);
          this.writer = writer;
          this.context = context;
      }
  
  
      public Document getDocument() {
          return document;
      }
      
      public String getContentType() {
          // return "application/pdf";
          return "text/html";
      }
  
  
      public String getCharacterEncoding() {
          return "ISO-8859-1";
      }
  
  
      public void startDocument() 
          throws IOException 
      {
  //         System.out.println("-- START");
  
  //         try {
  //             document = new Document();
  //             System.out.println("stream: " + context.getResponseStream());
  //             HtmlWriter.getInstance(document, context.getResponseStream());
              
  //             document.open();
  //             document.add(new Paragraph("Hello World: " + new java.util.Date()));
  //         } catch (DocumentException e) {
  //             throw new RuntimeException(e);
  //         }
      }
  
  
      public void endDocument() 
          throws IOException 
      {  
  //         System.out.println("-- END");
  //         document.close();
      }
  
  
      public ResponseWriter cloneWithWriter(Writer writer) {
          return new PDFResponseWriter(context, writer);
      }
  
      public void flush() throws IOException { 
          writer.flush();
      }
  
      public void startElement(String name, UIComponent componentForElement)
          throws IOException 
      {
          System.out.println("XXX-Writer:startElement");
      }
  
      public void endElement(String name) 
          throws IOException 
      {
          System.out.println("XXX-Writer:endElement");
      }
  
      public void writeAttribute(String name, 
                                 Object value,
                                 String componentPropertyName)
            throws IOException 
      {
          System.out.println("XXX-Writer:writeAttribute");
      }
  
  
      public void writeURIAttribute(String name, 
                                    Object value,
                                    String componentPropertyName)
          throws IOException 
      {
          System.out.println("XXX-Writer:writeURIAttribute");
      }
  
      public void writeComment(Object comment) 
          throws IOException 
                 
      {
          System.out.println("XXX-Writer:writeComment");
      }
  
  
      public void writeText(Object text, String componentPropertyName)
          throws IOException 
      {
          System.out.println("YYY-Writer:writeText prop=" + componentPropertyName + " text=" + text);
          writer.write(text.toString());
      }
  
      public void writeText(char text) 
          throws IOException 
      {
          System.out.println("YYY-Writer:writeText");
          writer.write(text);
      }
  
      public void writeText(char[] text) 
          throws IOException 
      {
          System.out.println("YYY-Writer:writeText");
          writer.write(text);
      }
  
  
      public void writeText(char text[], int off, int len)
            throws IOException 
      {
          System.out.println("YYY-Writer:writeText");
          writer.write(text,off,len);
      }
  
  
      public void close() throws IOException {
          writer.close();
      }
  
  
      public void write(char cbuf) throws IOException {
          writer.write(cbuf);
      }
  
  
      public void write(char[] cbuf, int off, int len) throws IOException {
          writer.write(cbuf, off, len);
      }
  
  
      public void write(int c) throws IOException {
          writer.write(c);
      }
  
  
      public void write(String str) throws IOException {
          writer.write(str);
      }
  
  
      public void write(String str, int off, int len) throws IOException {
          writer.write(str, off, len);
      }
  }
  
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/SeamFaceletViewHandler.java
  
  Index: SeamFaceletViewHandler.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  
  package org.jboss.seam.ui.facelet;
  
  import javax.faces.FacesException;
  import javax.faces.component.UIViewRoot;
  import javax.faces.context.FacesContext;
  import javax.faces.application.ViewHandler;
  
  import com.sun.facelets.FaceletViewHandler;
  import com.sun.facelets.compiler.Compiler;
  
  import java.io.IOException;
  
  
  
  /**
   * This class just extends the FaceletViewHandler to set the ExpressionFactory
   * to the Seam version.
   *
   * @author Stan Silvert
   */
  public class SeamFaceletViewHandler extends FaceletViewHandler 
  {
      private static final String SEAM_EXPRESSION_FACTORY = "org.jboss.seam.ui.facelet.SeamExpressionFactory";
      
      public SeamFaceletViewHandler(ViewHandler parent)
      {
          super(parent);
      }
      
      @Override
      protected Compiler createCompiler() 
      {
          Compiler compiler = super.createCompiler();
          compiler.setFeature(Compiler.EXPRESSION_FACTORY, SEAM_EXPRESSION_FACTORY);
          return compiler;
      }
  
  
      public void myBuildView(FacesContext context, UIViewRoot viewToRender)
          throws IOException, FacesException 
      {        
          initialize(context); // shouldn't have to do this
  
          System.out.println("Building: " + viewToRender + " -> " + viewToRender.getChildCount());
          buildView(context, viewToRender);
          System.out.println("Built: "    + viewToRender + " -> " + viewToRender.getChildCount());
      }
  
  }
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/TextRenderer.java
  
  Index: TextRenderer.java
  ===================================================================
  package org.jboss.seam.ui.pdf;
  
  import javax.faces.event.*;
  import javax.faces.context.*;
  import javax.faces.component.*;
  import javax.faces.render.*;
  import javax.servlet.http.*;
  
  import java.io.*;
  import java.util.*;
  
  import com.lowagie.text.*;
  import com.lowagie.text.pdf.*;
  
  import org.jboss.seam.ui.facelet.*;
  
  public class TextRenderer
      extends Renderer
  {
      public void encodeBegin(FacesContext context,
                              UIComponent component)
              throws IOException
      {
          System.out.println("BEGIN RENDER " + component);
      }
  
      public void encodeEnd(FacesContext context,
                            UIComponent component)
              throws IOException
      {
          System.out.println("END RENDER " + component);
          if (component instanceof ValueHolder) {
              ValueHolder holder = (ValueHolder) component;
              Object value = holder.getValue();
              System.out.println("*VALUE IS " + value);
              if (value != null) {
                  Chunk c = new Chunk(value.toString());
                  
                  UIComponent parent = component.getParent();
                  if (parent instanceof ITextComponent) {
                      ((ITextComponent) parent).add(c);
                  }
              }
          }
      }
  
  }
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/hdr.bar.jpg
  
  	<<Binary file>>
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/hdr.bg.gif
  
  	<<Binary file>>
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/pdf-x.xhtml
  
  Index: pdf-x.xhtml
  ===================================================================
  <f:view xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:s="http://jboss.com/products/seam/taglib">
  
      __ the pdf view __
      <h:outputText value="hi" />
  </f:view>
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/render.xhtml
  
  Index: render.xhtml
  ===================================================================
  <f:view renderKitId="PDF"  
          xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:s="http://jboss.com/products/seam/taglib">
  
      __ the pdf view __
      <h:outputText value="hi" />
  </f:view>
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/test.xhtml
  
  Index: test.xhtml
  ===================================================================
  <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:s="http://jboss.com/products/seam/taglib"
        template="template.xhtml">
  <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Seam Pay</title>
      <link href="screen.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
        
  hello: #{org}
      
  </body>
  </html>
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/x.xhtml
  
  Index: x.xhtml
  ===================================================================
  <p:document xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:p="http://jboss.com/products/seam/pdf">
      <p:paragraph alignment="center">Generated at #{currentTime}</p:paragraph>
      
      <p:font size="18" style="bold">
          <p:paragraph>This is paragraph #1</p:paragraph>
      </p:font>
      
      <p:font size="20">
          <p:paragraph><p:font family="TIMES_ROMAN" size="24">This is paragraph #2</p:font></p:paragraph>
      </p:font>
      <p:font family="COURIER" size="34" style="italic">
          <p:paragraph>This is #{foo.value}</p:paragraph>
      </p:font>
      
      <p:image rotation="10" height="100" width="400" resource="hdr.bar.jpg" />
      
      <p:font family="HELVETICA" size="36">
          <p:paragraph>This is paragraph #1</p:paragraph>
          <p:paragraph>This is paragraph #2</p:paragraph>
          <p:paragraph>#{foo.value}</p:paragraph>
      </p:font>
      
      <p:list numbered="false" lettered="true" indent="20">
          <ui:repeat value="#{foo.names}" var="name">
              <p:listItem><p:font style="bold">#{name}</p:font>: This is some information...</p:listItem>
          </ui:repeat>
      </p:list>
      
      <ui:repeat value="#{foo.names}" var="name">
          <p:newPage />
          <p:paragraph alignment="justify">This is a simple paragraph that is generated by a ui:repeat.  This paragraph has the value  <p:font style="bold">#{name}</p:font>, but there are other potential values too.  You'll see those in future paragraphs.  Or, at least I hope that you will.  I'm not really entirely sure if you will, but that's ok.  I'm just rambling now with the hopes that there is enough text to continue accross multiple lines.  By the way, have I  mentioned that the value is #{name}.  Have I?  Ok, good!!!</p:paragraph>
      </ui:repeat>
  </p:document>
  
  
  
  
  1.1      date: 2007/02/07 20:44:05;  author: nrichards;  state: Exp;jboss-seam/examples/itext/extra/y.xhtml
  
  Index: y.xhtml
  ===================================================================
  <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:s="http://jboss.com/products/seam/taglib"
        template="template.xhtml">
  <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Seam Pay</title>
      <link href="screen.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
        
  
      <s:link action="#{foo.hi(param.message)}" value="now">
          <f:param name="message" value="whatever" />
      </s:link>
      ::
      <s:link action="#{foo.hi('one')}" value="now" />
      :: 
      <s:link action="#{foo.bye}" value="later" />
      
  </body>
  </html>
  
  
  



More information about the jboss-cvs-commits mailing list