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

Peter Muir peter at bleepbleep.org.uk
Fri Feb 2 18:16:33 EST 2007


  User: pmuir   
  Date: 07/02/02 18:16:33

  Modified:    src/mail/org/jboss/seam/mail/ui  UIAttachment.java
  Log:
  Improve attachment support
  
  Revision  Changes    Path
  1.2       +59 -4     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.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UIAttachment.java	2 Feb 2007 21:20:41 -0000	1.1
  +++ UIAttachment.java	2 Feb 2007 23:16:33 -0000	1.2
  @@ -2,6 +2,7 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.net.URL;
   
   import javax.activation.DataHandler;
  @@ -13,6 +14,7 @@
   import javax.mail.BodyPart;
   import javax.mail.MessagingException;
   import javax.mail.internet.MimeBodyPart;
  +import javax.mail.util.ByteArrayDataSource;
   
   import org.jboss.seam.util.Resources;
   
  @@ -23,6 +25,8 @@
   
      private String contentType;
   
  +   private String fileName;
  +
      public Object getValue()
      {
         if (value != null)
  @@ -45,8 +49,6 @@
      {
         DataSource ds = null;
         // TODO Support seam-pdf
  -      // TODO Support byte array, input stream
  -      // TODO Override content type, file name
         try
         {
            if (getValue() instanceof URL)
  @@ -64,12 +66,24 @@
               String string = (String) getValue();
               ds = new URLDataSource(Resources.getResource(string));
            }
  +         else if (getValue() instanceof InputStream)
  +         {
  +            InputStream is = (InputStream) getValue();
  +            ds = new ByteArrayDataSource(is, getContentType());
  +         }
  +         else if (getValue() != null && getValue().getClass().isArray())
  +         {
  +            if (getValue().getClass().getComponentType().isAssignableFrom(Byte.class))
  +            {
  +               byte[] b = (byte[]) getValue();
  +               ds = new ByteArrayDataSource(b, getContentType());
  +            }
  +         }
            if (ds != null)
            {
               BodyPart attachment = new MimeBodyPart();
               attachment.setDataHandler(new DataHandler(ds));
  -            // TODO Make this default to just the filename
  -            attachment.setFileName(ds.getName());
  +            attachment.setFileName(getName(ds.getName()));
               super.getRootMultipart().addBodyPart(attachment);
            }
         }
  @@ -102,4 +116,45 @@
         this.contentType = contentType;
      }
   
  +   public String getFileName()
  +   {
  +      if (fileName == null)
  +      {
  +         return getString("fileName");
  +      }
  +      else
  +      {
  +         return fileName;
  +      }
  +   }
  +
  +   public void setFileName(String fileName)
  +   {
  +      this.fileName = fileName;
  +   }
  +
  +   private String removePath(String fileName)
  +   {
  +      if (fileName.lastIndexOf("/") > 0)
  +      {
  +         return fileName.substring(fileName.lastIndexOf("/"));
  +      }
  +      else
  +      {
  +         return fileName;
  +      }
  +   }
  +
  +   private String getName(String name)
  +   {
  +      if (getFileName() != null)
  +      {
  +         return getFileName();
  +      }
  +      else
  +      {
  +         return removePath(name);
  +      }
  +   }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list