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

Norman Richards norman.richards at jboss.com
Fri May 11 19:58:25 EDT 2007


  User: nrichards
  Date: 07/05/11 19:58:25

  Modified:    src/pdf/org/jboss/seam/pdf/ui  UIChart.java
  Log:
  use image store
  
  Revision  Changes    Path
  1.8       +34 -41    jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChart.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIChart.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChart.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- UIChart.java	9 May 2007 19:08:42 -0000	1.7
  +++ UIChart.java	11 May 2007 23:58:25 -0000	1.8
  @@ -8,14 +8,17 @@
   import java.io.IOException;
   import javax.faces.component.UIComponent;
   import javax.faces.context.FacesContext;
  +import javax.faces.context.ResponseStream;
   import javax.faces.context.ResponseWriter;
   
  -import org.jboss.seam.core.Conversation;
   import org.jboss.seam.core.Manager;
  +import org.jboss.seam.core.Pages;
  +import org.jboss.seam.core.Image.Type;
   import org.jboss.seam.pdf.DocumentData;
  -import org.jboss.seam.pdf.DocumentStore;
   import org.jboss.seam.pdf.ITextUtils;
  -import org.jboss.seam.pdf.DocumentData.DocType;
  +import org.jboss.seam.ui.graphicImage.GraphicImageResource;
  +import org.jboss.seam.ui.graphicImage.GraphicImageStore;
  +import org.jboss.seam.ui.graphicImage.GraphicImageStore.ImageWrapper;
   import org.jfree.chart.ChartUtilities;
   import org.jfree.chart.JFreeChart;
   import org.jfree.chart.plot.Plot;
  @@ -27,6 +30,7 @@
   import com.lowagie.text.pdf.PdfContentByte;
   import com.lowagie.text.pdf.PdfTemplate;
   import com.lowagie.text.pdf.PdfWriter;
  +import com.sun.faces.taglib.html_basic.GraphicImageTag;
   
   public abstract class UIChart 
       extends ITextComponent 
  @@ -34,20 +38,20 @@
       private Image image = null;
       private JFreeChart chart = null;
       
  -    float height = 300;
  -    float width  = 400;    
  +    private float height = 300;
  +    private float width  = 400;    
       
  -    String borderBackgroundPaint;
  -    String borderPaint;
  -    String borderStroke;
  -    boolean borderVisible = true;
  -    
  -    String plotBackgroundPaint;
  -    Float  plotBackgroundAlpha;
  -    Float  plotForegroundAlpha;
  -    String plotOutlineStroke; 
  -    String plotOutlinePaint;
  -    private String imageId;
  +    private String borderBackgroundPaint;
  +    private String borderPaint;
  +    private String borderStroke;
  +    private boolean borderVisible = true;
  +    
  +    private String plotBackgroundPaint;
  +    private Float  plotBackgroundAlpha;
  +    private Float  plotForegroundAlpha;
  +    private String plotOutlineStroke; 
  +    private String plotOutlinePaint;
  +    private byte[] imageData;
       
       
       public void setHeight(float height) {
  @@ -160,24 +164,6 @@
           return chart;
       }
           
  -
  -    private void renderImageLink(FacesContext context) 
  -        throws IOException     
  -    {
  -        ResponseWriter response = context.getResponseWriter();        
  -        response.startElement("image", this);
  -        
  -        DocumentStore store = DocumentStore.instance();
  -        DocumentData data = store.getDocumentData(imageId);
  -        String url = store.preferredUrlForContent(data.getBaseName(), data.getDocType(), imageId);
  -        url = Manager.instance().encodeConversationId(url, context.getViewRoot().getId());
  -        response.writeAttribute("src",  url, null);
  -        response.endElement("image");   
  -        
  -        Conversation conv = Conversation.instance();
  -        System.out.println("conv=" + conv.getId() + " lr=" + conv.isLongRunning());
  -    }
  -    
       @Override
       public void createITextObject(FacesContext context) {                        
           if (borderBackgroundPaint != null) {
  @@ -214,10 +200,7 @@
                   ByteArrayOutputStream stream = new ByteArrayOutputStream();
                   ChartUtilities.writeChartAsJPEG(stream, chart, (int)width, (int)height);
   
  -                DocumentStore store = DocumentStore.instance();
  -                
  -                imageId = store.newId();
  -                store.saveData(imageId, new DocumentData("randomChart", DocType.JPEG, stream.toByteArray()));
  +                imageData = stream.toByteArray();
                   stream.close();
               }
           } catch (Exception e) {             
  @@ -274,9 +257,19 @@
           // call create here so that we'll have a valid chart  
           createITextObject(context);
   
  -        if (imageId != null) {
  -            renderImageLink(context);
  -            imageId = null;
  +        if (imageData != null) {
  +            ResponseWriter response = context.getResponseWriter();
  +            response.startElement("img", null);                   
  +            GraphicImageStore store = GraphicImageStore.instance();
  +            String key = store.put(new ImageWrapper(imageData, Type.IMAGE_JPEG));
  +            String url = context.getExternalContext().getRequestContextPath() +
  +                         GraphicImageResource.GRAPHIC_IMAGE_RESOURCE_PATH + "/" + key + Type.IMAGE_JPEG.getExtension();
  +
  +            response.writeAttribute("src", url, null);
  +
  +            response.endElement("img");
  +
  +            Manager.instance().beforeRedirect();           
           }
           
           super.encodeEnd(context);
  
  
  



More information about the jboss-cvs-commits mailing list