You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Matthias Wessendorf <ma...@apache.org> on 2007/11/28 16:18:27 UTC

Re: svn commit: r599022 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces: custom/fileupload/ webapp/filter/

can you add the license headers?
:-)

On Nov 28, 2007 4:14 PM,  <mm...@apache.org> wrote:
> Author: mmarinschek
> Date: Wed Nov 28 07:14:17 2007
> New Revision: 599022
>
> URL: http://svn.apache.org/viewvc?rev=599022&view=rev
> Log:
> fix for https://issues.apache.org/jira/browse/TOMAHAWK-6 (TOMAHAWK-6): Thanks to Alexander Jesse for helping me fixing this and testing the fix
>
> Added:
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java
> Modified:
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java
>     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java
>
> Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java?rev=599022&view=auto
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java (added)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java Wed Nov 28 07:14:17 2007
> @@ -0,0 +1,9 @@
> +package org.apache.myfaces.custom.fileupload;
> +
> +import java.io.File;
> +
> +public abstract class DiskStorageStrategy extends StorageStrategy {
> +
> +  public abstract File getTempFile();
> +
> +}
>
> Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java?rev=599022&r1=599021&r2=599022&view=diff
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java (original)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java Wed Nov 28 07:14:17 2007
> @@ -31,6 +31,7 @@
>
>  import javax.faces.component.UIComponent;
>  import javax.faces.context.FacesContext;
> +import javax.faces.FacesException;
>  import javax.faces.context.ResponseWriter;
>  import javax.faces.context.ExternalContext;
>  import javax.faces.convert.ConverterException;
> @@ -126,7 +127,7 @@
>                      ((HtmlInputFileUpload)uiComponent).setSubmittedValue(upFile);
>                      ((HtmlInputFileUpload)uiComponent).setValid(true);
>                  }catch(IOException ioe){
> -                    log.error(ioe);
> +                    throw new FacesException("Exception while processing file upload for file-input : " + uiComponent.getClientId(facesContext),ioe);
>                  }
>              }
>              return;
> @@ -165,7 +166,7 @@
>                          ((HtmlInputFileUpload)uiComponent).setSubmittedValue(upFile);
>                          ((HtmlInputFileUpload)uiComponent).setValid(true);
>                      }catch(IOException ioe){
> -                        log.error(ioe);
> +                      throw new FacesException("Exception while processing file upload for file-input : " + uiComponent.getClientId(facesContext),ioe);
>                      }
>                  }
>              }
>
> Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java?rev=599022&r1=599021&r2=599022&view=diff
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java (original)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java Wed Nov 28 07:14:17 2007
> @@ -20,8 +20,10 @@
>
>  import org.apache.myfaces.component.UserRoleAware;
>  import org.apache.myfaces.component.UserRoleUtils;
> +import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
>  import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
>
> +import javax.faces.application.FacesMessage;
>  import javax.faces.component.html.HtmlInputText;
>  import javax.faces.context.FacesContext;
>  import javax.faces.el.ValueBinding;
> @@ -34,6 +36,9 @@
>          extends HtmlInputText
>          implements UserRoleAware
>  {
> +    private static final String SIZE_LIMIT_EXCEEDED = "sizeLimitExceeded";
> +    private static final String FILEUPLOAD_MAX_SIZE = "org.apache.myfaces.custom.fileupload.maxSize";
> +    private static final String FILEUPLOAD_EXCEPTION = "org.apache.myfaces.custom.fileupload.exception";
>      public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlInputFileUpload";
>      public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.FileUpload";
>      public static final String SIZE_LIMIT_MESSAGE_ID = "org.apache.myfaces.FileUpload.SIZE_LIMIT";
> @@ -113,22 +118,29 @@
>          return super.isRendered();
>      }
>
> -//    protected void validateValue(FacesContext context, Object convertedValue)
> -//    {
> -//        super.validateValue(context, convertedValue);
> -//        if (isValid())
> -//        {
> -//            UploadedFile file = (UploadedFile) convertedValue;
> -//            if(file != null && file.getSize() > getMaxlength())
> -//            {
> -//                MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,
> -//                        SIZE_LIMIT_MESSAGE_ID, new Object[] { getId(),
> -//                                new Integer(getMaxlength()) },
> -//                        getClientId(context), context);
> -//                setValid(false);
> -//            }
> -//        }
> -//    }
> +    protected void validateValue(FacesContext context, Object convertedValue)
> +    {
> +        super.validateValue(context, convertedValue);
> +
> +        if (isValid())
> +        {
> +              String exception =
> +                (String) context.getExternalContext().getRequestMap().get(FILEUPLOAD_EXCEPTION);
> +
> +              if(exception != null && exception.equals(SIZE_LIMIT_EXCEEDED)) {
> +                Integer maxSize =
> +                  (Integer) context.getExternalContext().getRequestMap().get(FILEUPLOAD_MAX_SIZE);
> +                MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,
> +                            SIZE_LIMIT_MESSAGE_ID, new Object[] { getId(),
> +                                    maxSize},
> +                            getClientId(context), context);
> +                    setValid(false);
> +             }
> +             else {
> +               throw new IllegalStateException("other exceptions not handled yet.");
> +             }
> +         }
> +     }
>
>      public Object saveState(FacesContext context)
>      {
>
> Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java?rev=599022&view=auto
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java (added)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java Wed Nov 28 07:14:17 2007
> @@ -0,0 +1,6 @@
> +package org.apache.myfaces.custom.fileupload;
> +
> +public abstract class StorageStrategy {
> +
> +  public abstract void deleteFileContents();
> +}
>
> Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java?rev=599022&r1=599021&r2=599022&view=diff
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java (original)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java Wed Nov 28 07:14:17 2007
> @@ -50,21 +50,28 @@
>
>
>      /**
> -     * @return Returns the _contentType.
> +     * @return Returns the contentType.
>       */
>      String getContentType();
>
>
>
>      /**
> -     * @return Returns the _name.
> +     * @return Returns the name.
>       */
>      String getName();
>
>
>      /**
> -     * Answer the size of this file.
> +     * Returns the size of this file.
>       * @return long
>       */
>      long getSize();
> +
> +    /**Allows to get more information/interact more with the file, depending
> +     * on where it is stored
> +     *
> +     * @return StorageStrategy the storage strategy of this file,
> +     */
> +    StorageStrategy getStorageStrategy();
>  }
>
> Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java?rev=599022&r1=599021&r2=599022&view=diff
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java (original)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java Wed Nov 28 07:14:17 2007
> @@ -18,9 +18,11 @@
>   */
>  package org.apache.myfaces.custom.fileupload;
>
> +import org.apache.commons.fileupload.DefaultFileItem;
>  import org.apache.commons.fileupload.FileItem;
>
>  import java.io.ByteArrayInputStream;
> +import java.io.File;
>  import java.io.IOException;
>  import java.io.InputStream;
>
> @@ -32,20 +34,24 @@
>  public class UploadedFileDefaultFileImpl extends UploadedFileDefaultImplBase
>  {
>    private static final long serialVersionUID = -6401426361519246443L;
> -  private transient FileItem fileItem = null;
> +  private transient DefaultFileItem fileItem = null;
> +  private StorageStrategy storageStrategy;
>
> -    /*
> -    TODO/manolito: Do we need an empty constructor?!
> -    public UploadedFileDefaultFileImpl()
> -    {
> -    }
> -    */
> -
> -
> -    public UploadedFileDefaultFileImpl(FileItem fileItem) throws IOException
> +    public UploadedFileDefaultFileImpl(final FileItem fileItem) throws IOException
>      {
>          super(fileItem.getName(), fileItem.getContentType());
> -       this.fileItem = fileItem;
> +       this.fileItem = (DefaultFileItem) fileItem;
> +      storageStrategy = new DiskStorageStrategy() {
> +
> +        public File getTempFile() {
> +          return UploadedFileDefaultFileImpl.this.fileItem.getStoreLocation();
> +        }
> +
> +        public void deleteFileContents() {
> +          UploadedFileDefaultFileImpl.this.fileItem.delete();
> +        }
> +
> +      };
>      }
>
>
> @@ -83,5 +89,10 @@
>      public long getSize()
>      {
>         return fileItem != null ? fileItem.getSize() : 0;
> +    }
> +
> +
> +    public StorageStrategy getStorageStrategy() {
> +      return storageStrategy;
>      }
>  }
>
> Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java?rev=599022&r1=599021&r2=599022&view=diff
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java (original)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java Wed Nov 28 07:14:17 2007
> @@ -33,22 +33,23 @@
>  {
>      private static final long serialVersionUID = -6006333070975059090L;
>      private byte[] bytes;
> +    private StorageStrategy storageStrategy;
>
>
> -    public UploadedFileDefaultMemoryImpl(FileItem fileItem) throws IOException
> +    public UploadedFileDefaultMemoryImpl(final FileItem fileItem) throws IOException
>      {
>          super(fileItem.getName(), fileItem.getContentType());
>          int sizeInBytes = (int)fileItem.getSize();
>         bytes = new byte[sizeInBytes];
>         fileItem.getInputStream().read(bytes);
> +      this.storageStrategy = new StorageStrategy() {
>
> -        /*
> -        TODO/manolito: what was the reason for this if?
> -       if (bytes.length != 0) {
> -               _name = fileItem.getName();
> -               _contentType = fileItem.getContentType();
> -       }
> -        */
> +        public void deleteFileContents() {
> +          fileItem.delete();
> +          bytes = null;
> +        }
> +
> +      };
>      }
>
>
> @@ -84,4 +85,11 @@
>                 return 0;
>         return bytes.length;
>      }
> +
> +
> +    public StorageStrategy getStorageStrategy() {
> +      return storageStrategy;
> +    }
> +
> +
>  }
>
> Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java
> URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java?rev=599022&r1=599021&r2=599022&view=diff
> ==============================================================================
> --- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java (original)
> +++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java Wed Nov 28 07:14:17 2007
> @@ -85,11 +85,11 @@
>              requestParameters = fileUpload.parseRequest(request);
>          } catch (FileUploadBase.SizeLimitExceededException e) {
>
> -            // TODO: find a way to notify the user about the fact that the uploaded file exceeded size limit
> -
> -            if(log.isInfoEnabled())
> -                log.info("user tried to upload a file that exceeded file-size limitations.",e);
> -
> +            request.setAttribute(
> +                "org.apache.myfaces.custom.fileupload.exception","sizeLimitExceeded");
> +            request.setAttribute("org.apache.myfaces.custom.fileupload.maxSize",
> +                new Integer(maxSize));
> +
>              requestParameters = Collections.EMPTY_LIST;
>
>          }catch(FileUploadException fue){
>
>
>



-- 
Matthias Wessendorf

further stuff:
blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
mail: matzew-at-apache-dot-org

Re: svn commit: r599022 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces: custom/fileupload/ webapp/filter/

Posted by Martin Marinschek <ma...@gmail.com>.
sure, done - sorry.

regards,

Martin

On 11/28/07, Matthias Wessendorf <ma...@apache.org> wrote:
> can you add the license headers?
> :-)
>
> On Nov 28, 2007 4:14 PM,  <mm...@apache.org> wrote:
> > Author: mmarinschek
> > Date: Wed Nov 28 07:14:17 2007
> > New Revision: 599022
> >
> > URL: http://svn.apache.org/viewvc?rev=599022&view=rev
> > Log:
> > fix for https://issues.apache.org/jira/browse/TOMAHAWK-6 (TOMAHAWK-6):
> Thanks to Alexander Jesse for helping me fixing this and testing the fix
> >
> > Added:
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java
> > Modified:
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java
> >
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java
> >
> > Added:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java?rev=599022&view=auto
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java
> (added)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/DiskStorageStrategy.java
> Wed Nov 28 07:14:17 2007
> > @@ -0,0 +1,9 @@
> > +package org.apache.myfaces.custom.fileupload;
> > +
> > +import java.io.File;
> > +
> > +public abstract class DiskStorageStrategy extends StorageStrategy {
> > +
> > +  public abstract File getTempFile();
> > +
> > +}
> >
> > Modified:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java?rev=599022&r1=599021&r2=599022&view=diff
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java
> (original)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRenderer.java
> Wed Nov 28 07:14:17 2007
> > @@ -31,6 +31,7 @@
> >
> >  import javax.faces.component.UIComponent;
> >  import javax.faces.context.FacesContext;
> > +import javax.faces.FacesException;
> >  import javax.faces.context.ResponseWriter;
> >  import javax.faces.context.ExternalContext;
> >  import javax.faces.convert.ConverterException;
> > @@ -126,7 +127,7 @@
> >
> ((HtmlInputFileUpload)uiComponent).setSubmittedValue(upFile);
> >                      ((HtmlInputFileUpload)uiComponent).setValid(true);
> >                  }catch(IOException ioe){
> > -                    log.error(ioe);
> > +                    throw new FacesException("Exception while processing
> file upload for file-input : " + uiComponent.getClientId(facesContext),ioe);
> >                  }
> >              }
> >              return;
> > @@ -165,7 +166,7 @@
> >
> ((HtmlInputFileUpload)uiComponent).setSubmittedValue(upFile);
> >
> ((HtmlInputFileUpload)uiComponent).setValid(true);
> >                      }catch(IOException ioe){
> > -                        log.error(ioe);
> > +                      throw new FacesException("Exception while
> processing file upload for file-input : " +
> uiComponent.getClientId(facesContext),ioe);
> >                      }
> >                  }
> >              }
> >
> > Modified:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java?rev=599022&r1=599021&r2=599022&view=diff
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java
> (original)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/HtmlInputFileUpload.java
> Wed Nov 28 07:14:17 2007
> > @@ -20,8 +20,10 @@
> >
> >  import org.apache.myfaces.component.UserRoleAware;
> >  import org.apache.myfaces.component.UserRoleUtils;
> > +import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
> >  import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
> >
> > +import javax.faces.application.FacesMessage;
> >  import javax.faces.component.html.HtmlInputText;
> >  import javax.faces.context.FacesContext;
> >  import javax.faces.el.ValueBinding;
> > @@ -34,6 +36,9 @@
> >          extends HtmlInputText
> >          implements UserRoleAware
> >  {
> > +    private static final String SIZE_LIMIT_EXCEEDED =
> "sizeLimitExceeded";
> > +    private static final String FILEUPLOAD_MAX_SIZE =
> "org.apache.myfaces.custom.fileupload.maxSize";
> > +    private static final String FILEUPLOAD_EXCEPTION =
> "org.apache.myfaces.custom.fileupload.exception";
> >      public static final String COMPONENT_TYPE =
> "org.apache.myfaces.HtmlInputFileUpload";
> >      public static final String DEFAULT_RENDERER_TYPE =
> "org.apache.myfaces.FileUpload";
> >      public static final String SIZE_LIMIT_MESSAGE_ID =
> "org.apache.myfaces.FileUpload.SIZE_LIMIT";
> > @@ -113,22 +118,29 @@
> >          return super.isRendered();
> >      }
> >
> > -//    protected void validateValue(FacesContext context, Object
> convertedValue)
> > -//    {
> > -//        super.validateValue(context, convertedValue);
> > -//        if (isValid())
> > -//        {
> > -//            UploadedFile file = (UploadedFile) convertedValue;
> > -//            if(file != null && file.getSize() > getMaxlength())
> > -//            {
> > -//                MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,
> > -//                        SIZE_LIMIT_MESSAGE_ID, new Object[] { getId(),
> > -//                                new Integer(getMaxlength()) },
> > -//                        getClientId(context), context);
> > -//                setValid(false);
> > -//            }
> > -//        }
> > -//    }
> > +    protected void validateValue(FacesContext context, Object
> convertedValue)
> > +    {
> > +        super.validateValue(context, convertedValue);
> > +
> > +        if (isValid())
> > +        {
> > +              String exception =
> > +                (String)
> context.getExternalContext().getRequestMap().get(FILEUPLOAD_EXCEPTION);
> > +
> > +              if(exception != null &&
> exception.equals(SIZE_LIMIT_EXCEEDED)) {
> > +                Integer maxSize =
> > +                  (Integer)
> context.getExternalContext().getRequestMap().get(FILEUPLOAD_MAX_SIZE);
> > +                MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,
> > +                            SIZE_LIMIT_MESSAGE_ID, new Object[] {
> getId(),
> > +                                    maxSize},
> > +                            getClientId(context), context);
> > +                    setValid(false);
> > +             }
> > +             else {
> > +               throw new IllegalStateException("other exceptions not
> handled yet.");
> > +             }
> > +         }
> > +     }
> >
> >      public Object saveState(FacesContext context)
> >      {
> >
> > Added:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java?rev=599022&view=auto
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java
> (added)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/StorageStrategy.java
> Wed Nov 28 07:14:17 2007
> > @@ -0,0 +1,6 @@
> > +package org.apache.myfaces.custom.fileupload;
> > +
> > +public abstract class StorageStrategy {
> > +
> > +  public abstract void deleteFileContents();
> > +}
> >
> > Modified:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java?rev=599022&r1=599021&r2=599022&view=diff
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java
> (original)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFile.java
> Wed Nov 28 07:14:17 2007
> > @@ -50,21 +50,28 @@
> >
> >
> >      /**
> > -     * @return Returns the _contentType.
> > +     * @return Returns the contentType.
> >       */
> >      String getContentType();
> >
> >
> >
> >      /**
> > -     * @return Returns the _name.
> > +     * @return Returns the name.
> >       */
> >      String getName();
> >
> >
> >      /**
> > -     * Answer the size of this file.
> > +     * Returns the size of this file.
> >       * @return long
> >       */
> >      long getSize();
> > +
> > +    /**Allows to get more information/interact more with the file,
> depending
> > +     * on where it is stored
> > +     *
> > +     * @return StorageStrategy the storage strategy of this file,
> > +     */
> > +    StorageStrategy getStorageStrategy();
> >  }
> >
> > Modified:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java?rev=599022&r1=599021&r2=599022&view=diff
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java
> (original)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultFileImpl.java
> Wed Nov 28 07:14:17 2007
> > @@ -18,9 +18,11 @@
> >   */
> >  package org.apache.myfaces.custom.fileupload;
> >
> > +import org.apache.commons.fileupload.DefaultFileItem;
> >  import org.apache.commons.fileupload.FileItem;
> >
> >  import java.io.ByteArrayInputStream;
> > +import java.io.File;
> >  import java.io.IOException;
> >  import java.io.InputStream;
> >
> > @@ -32,20 +34,24 @@
> >  public class UploadedFileDefaultFileImpl extends
> UploadedFileDefaultImplBase
> >  {
> >    private static final long serialVersionUID = -6401426361519246443L;
> > -  private transient FileItem fileItem = null;
> > +  private transient DefaultFileItem fileItem = null;
> > +  private StorageStrategy storageStrategy;
> >
> > -    /*
> > -    TODO/manolito: Do we need an empty constructor?!
> > -    public UploadedFileDefaultFileImpl()
> > -    {
> > -    }
> > -    */
> > -
> > -
> > -    public UploadedFileDefaultFileImpl(FileItem fileItem) throws
> IOException
> > +    public UploadedFileDefaultFileImpl(final FileItem fileItem) throws
> IOException
> >      {
> >          super(fileItem.getName(), fileItem.getContentType());
> > -       this.fileItem = fileItem;
> > +       this.fileItem = (DefaultFileItem) fileItem;
> > +      storageStrategy = new DiskStorageStrategy() {
> > +
> > +        public File getTempFile() {
> > +          return
> UploadedFileDefaultFileImpl.this.fileItem.getStoreLocation();
> > +        }
> > +
> > +        public void deleteFileContents() {
> > +          UploadedFileDefaultFileImpl.this.fileItem.delete();
> > +        }
> > +
> > +      };
> >      }
> >
> >
> > @@ -83,5 +89,10 @@
> >      public long getSize()
> >      {
> >         return fileItem != null ? fileItem.getSize() : 0;
> > +    }
> > +
> > +
> > +    public StorageStrategy getStorageStrategy() {
> > +      return storageStrategy;
> >      }
> >  }
> >
> > Modified:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java?rev=599022&r1=599021&r2=599022&view=diff
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java
> (original)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/fileupload/UploadedFileDefaultMemoryImpl.java
> Wed Nov 28 07:14:17 2007
> > @@ -33,22 +33,23 @@
> >  {
> >      private static final long serialVersionUID = -6006333070975059090L;
> >      private byte[] bytes;
> > +    private StorageStrategy storageStrategy;
> >
> >
> > -    public UploadedFileDefaultMemoryImpl(FileItem fileItem) throws
> IOException
> > +    public UploadedFileDefaultMemoryImpl(final FileItem fileItem) throws
> IOException
> >      {
> >          super(fileItem.getName(), fileItem.getContentType());
> >          int sizeInBytes = (int)fileItem.getSize();
> >         bytes = new byte[sizeInBytes];
> >         fileItem.getInputStream().read(bytes);
> > +      this.storageStrategy = new StorageStrategy() {
> >
> > -        /*
> > -        TODO/manolito: what was the reason for this if?
> > -       if (bytes.length != 0) {
> > -               _name = fileItem.getName();
> > -               _contentType = fileItem.getContentType();
> > -       }
> > -        */
> > +        public void deleteFileContents() {
> > +          fileItem.delete();
> > +          bytes = null;
> > +        }
> > +
> > +      };
> >      }
> >
> >
> > @@ -84,4 +85,11 @@
> >                 return 0;
> >         return bytes.length;
> >      }
> > +
> > +
> > +    public StorageStrategy getStorageStrategy() {
> > +      return storageStrategy;
> > +    }
> > +
> > +
> >  }
> >
> > Modified:
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java?rev=599022&r1=599021&r2=599022&view=diff
> >
> ==============================================================================
> > ---
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java
> (original)
> > +++
> myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/webapp/filter/MultipartRequestWrapper.java
> Wed Nov 28 07:14:17 2007
> > @@ -85,11 +85,11 @@
> >              requestParameters = fileUpload.parseRequest(request);
> >          } catch (FileUploadBase.SizeLimitExceededException e) {
> >
> > -            // TODO: find a way to notify the user about the fact that
> the uploaded file exceeded size limit
> > -
> > -            if(log.isInfoEnabled())
> > -                log.info("user tried to upload a file that exceeded
> file-size limitations.",e);
> > -
> > +            request.setAttribute(
> > +
> "org.apache.myfaces.custom.fileupload.exception","sizeLimitExceeded");
> > +
> request.setAttribute("org.apache.myfaces.custom.fileupload.maxSize",
> > +                new Integer(maxSize));
> > +
> >              requestParameters = Collections.EMPTY_LIST;
> >
> >          }catch(FileUploadException fue){
> >
> >
> >
>
>
>
> --
> Matthias Wessendorf
>
> further stuff:
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> mail: matzew-at-apache-dot-org
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces