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

Peter Muir peter at bleepbleep.org.uk
Sat Feb 3 20:21:20 EST 2007


  User: pmuir   
  Date: 07/02/03 20:21:20

  Modified:    src/mail/org/jboss/seam/mail/ui  UIAttachment.java
  Log:
  JBSEAM-693 More UIAttachment support
  
  Revision  Changes    Path
  1.3       +40 -9     jboss-seam/src/mail/org/jboss/seam/mail/ui/UIAttachment.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIAttachment.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIAttachment.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- UIAttachment.java	2 Feb 2007 23:16:33 -0000	1.2
  +++ UIAttachment.java	4 Feb 2007 01:21:20 -0000	1.3
  @@ -10,15 +10,19 @@
   import javax.activation.FileDataSource;
   import javax.activation.URLDataSource;
   import javax.faces.FacesException;
  +import javax.faces.component.ValueHolder;
   import javax.faces.context.FacesContext;
  +import javax.faces.convert.Converter;
   import javax.mail.BodyPart;
   import javax.mail.MessagingException;
   import javax.mail.internet.MimeBodyPart;
   import javax.mail.util.ByteArrayDataSource;
   
  +import org.jboss.seam.pdf.ui.UIDocument;
  +import org.jboss.seam.ui.JSF;
   import org.jboss.seam.util.Resources;
   
  -public class UIAttachment extends MailComponent
  +public class UIAttachment extends MailComponent implements ValueHolder
   {
   
      private Object value;
  @@ -47,6 +51,23 @@
      @Override
      public void encodeBegin(FacesContext context) throws IOException
      {
  +      if (this.getChildCount() > 0) {
  +         if (this.getChildren().get(0) instanceof UIDocument) {
  +            UIDocument document = (UIDocument) this.getChildren().get(0);
  +            document.setSendRedirect(false);
  +            // TODO Set contenttype and filename
  +            JSF.renderChildren(context, this);
  +         } else {
  +            // Assume this is an HTML document
  +            setValue(encode(context).getBytes());
  +            setContentType("text/html");
  +         }
  +      }
  +   }
  +
  +   @Override
  +   public void encodeEnd(FacesContext context) throws IOException
  +   {
         DataSource ds = null;
         // TODO Support seam-pdf
         try
  @@ -73,7 +94,8 @@
            }
            else if (getValue() != null && getValue().getClass().isArray())
            {
  -            if (getValue().getClass().getComponentType().isAssignableFrom(Byte.class))
  +            Class clazz = getValue().getClass().getComponentType();
  +            if (getValue().getClass().getComponentType().isAssignableFrom(Byte.TYPE))
               {
                  byte[] b = (byte[]) getValue();
                  ds = new ByteArrayDataSource(b, getContentType());
  @@ -93,12 +115,6 @@
         }
      }
   
  -   @Override
  -   public void encodeChildren(FacesContext context) throws IOException
  -   {
  -      // No children
  -   }
  -
      public String getContentType()
      {
         if (contentType == null)
  @@ -157,4 +173,19 @@
         }
      }
   
  +   public Converter getConverter()
  +   {
  +      return null;
  +   }
  +
  +   public Object getLocalValue()
  +   {
  +      return value;
  +   }
  +
  +   public void setConverter(Converter converter)
  +   {
  +      throw new UnsupportedOperationException("Cannot attach a converter to an attachment");
  +   }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list