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

Peter Muir peter at bleepbleep.org.uk
Sun Mar 4 16:51:51 EST 2007


  User: pmuir   
  Date: 07/03/04 16:51:51

  Modified:    src/ui/org/jboss/seam/ui   JSF.java
  Added:       src/ui/org/jboss/seam/ui   UIGraphicImage.java
  Log:
  JBSEAM-985
  
  Revision  Changes    Path
  1.4       +210 -193  jboss-seam/src/ui/org/jboss/seam/ui/JSF.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JSF.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/JSF.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- JSF.java	14 Nov 2006 04:59:39 -0000	1.3
  +++ JSF.java	4 Mar 2007 21:51:51 -0000	1.4
  @@ -25,8 +25,8 @@
   /**
    * Constant declarations for JSF tags
    * 
  - * @author Anton Koinov (latest modification by $Author: gavin $)
  - * @version $Revision: 1.3 $ $Date: 2006/11/14 04:59:39 $
  + * @author Anton Koinov (latest modification by $Author: pmuir $)
  + * @version $Revision: 1.4 $ $Date: 2007/03/04 21:51:51 $
    */
   public class JSF
   {
  @@ -190,4 +190,21 @@
          return value.toString();
      }
   
  +   static Boolean getBooleanValue(FacesContext context, ValueBinding vb)
  +   {
  +       Object value = vb.getValue(context);
  +       if (value == null)
  +       {
  +          return null;
  +       }
  +       if (value instanceof Boolean) 
  +       {
  +          return (Boolean) value;
  +       }
  +       else
  +       {
  +          return Boolean.valueOf(value.toString());
  +       }
  +   }
  +
   }
  
  
  
  1.1      date: 2007/03/04 21:51:51;  author: pmuir;  state: Exp;jboss-seam/src/ui/org/jboss/seam/ui/UIGraphicImage.java
  
  Index: UIGraphicImage.java
  ===================================================================
  package org.jboss.seam.ui;
  
  import java.io.IOException;
  
  import javax.faces.component.html.HtmlGraphicImage;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseWriter;
  import javax.faces.el.ValueBinding;
  import javax.faces.render.Renderer;
  
  import org.jboss.seam.core.Image;
  import org.jboss.seam.ui.resource.DynamicImageResource;
  import org.jboss.seam.ui.resource.DynamicImageStore;
  import org.jboss.seam.ui.resource.DynamicImageStore.ImageWrapper;
  
  public class UIGraphicImage extends HtmlGraphicImage
  {
  
     public static final String FAMILY = "org.jboss.seam.ui.UIGraphicImage";
  
     private Boolean maintainRatio = true;
  
     private String contentType;
     
     private String fileName;
  
     @Override
     public String getFamily()
     {
        return FAMILY;
     }
  
     @Override
     public Object saveState(FacesContext context)
     {
        Object[] values = new Object[4];
        values[0] = super.saveState(context);
        values[1] = contentType;
        values[2] = maintainRatio;
        values[3] = fileName;
        return values;
     }
  
     @Override
     public void restoreState(FacesContext context, Object state)
     {
        Object values[] = (Object[]) state;
        super.restoreState(context, values[0]);
        maintainRatio = (Boolean) values[2];
        contentType = (String) values[1];
        fileName = (String) values[3];
     }
  
     public boolean isMaintainRatio()
     {
        if (contentType != null)
        {
           return maintainRatio;
        }
        else
        {
           ValueBinding vb = getValueBinding("maintainRatio");
           return vb == null ? false : JSF.getBooleanValue(getFacesContext(), vb);
        }
        
     }
  
     public void setMaintainRatio(boolean maintainRatio)
     {
        this.maintainRatio = maintainRatio;
     }
  
     @Override
     public void encodeBegin(FacesContext context) throws IOException
     {
        ResponseWriter writer = context.getResponseWriter();
        String key = getFileName();
        String extension = null;
        if (!DynamicImageStore.instance().contains(key)) 
        {
           Image image = Image.instance();
           image.set(getValue());
     
           if (isMaintainRatio() && getWidth() != null)
           {
              // TODO reduce number of decimal places
              setHeight(((Double) (Double.valueOf(getWidth()) / image.getRatio())).toString());
           }
           else if (isMaintainRatio() && getHeight() != null)
           {
              setWidth(((Double) (Double.valueOf(getHeight()) / image.getRatio())).toString());
           }
           
           if (getContentType() != null) {
              image.setContentType(Image.Type.getType(getContentType()));
           }
           
           key = DynamicImageStore.instance().put(new ImageWrapper(image.get(),
                    image.getContentType()), key);
           extension = image.getContentType().getExtension();
        } 
        else 
        {
           extension = DynamicImageStore.instance().get(key).getContentType().getExtension();
        }
        writer.startElement(HTML.IMG_ELEM, this);
        String url = context.getExternalContext().getRequestContextPath()
                 + DynamicImageResource.DYNAMIC_IMAGE_RESOURCE_PATH + "/" + key + extension;
        writer.writeAttribute(HTML.SRC_ATTR, url, HTML.SRC_ATTR);
        HTML.renderHTMLAttributes(writer, this, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
        writer.endElement(HTML.IMG_ELEM);
     }
  
     public String getContentType()
     {
        if (contentType != null)
        {
           return contentType;
        }
        else
        {
           ValueBinding vb = getValueBinding("contentType");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
     }
  
     public void setContentType(String contentType)
     {
        this.contentType = contentType;
     }
     
     public String getFileName()
     {
        if (fileName != null)
        {
           return fileName;
        }
        else
        {
           ValueBinding vb = getValueBinding("fileName");
           return vb == null ? null : JSF.getStringValue(getFacesContext(), vb);
        }
           
     }
     
     public void setFileName(String fileName)
     {
        this.fileName = fileName;
     }
  
     @Override
     protected Renderer getRenderer(FacesContext context)
     {
        return null;
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list