Class URLFileItem

java.lang.Object
com.webmethods.caf.faces.data.attachments.URLFileItem
All Implemented Interfaces:
org.apache.commons.fileupload.FileItem, org.apache.commons.fileupload.FileItemHeadersSupport

public class URLFileItem extends Object implements org.apache.commons.fileupload.FileItem
Simple implementation of the FileItem interface that can be used for adding/updating attachments programmatically from a URL, local file or web application resource. For loading web application resources this class must be used during JSF life cycle.
NOTE: only the methods needed for attachments are implemented, so this should not be used as a generic FileItem in other contexts.
Usage Example:

                IAttachmentsProvider provider; //get or create attachment provider here

                //add a local text file
                FileItem item = new URLFileItem(new File("c:\\file.txt"));
                provider.addAttachment(item, "UTF-8");

                //add a local binary file
                FileItem item2 = new URLFileItem(new File("c:\\file.gif"));
                provider.addAttachment(item, null);

                //add a remote binary file
                FileItem item2 = new URLFileItem(new URL("http://localhost/file.gif"));
                provider.addAttachment(item, null);

                //add a web application resource file
                FileItem item2 = new URLFileItem("/MyPortlet/myfile.gif");
                provider.addAttachment(item, null);

 

When used in a java bean context location property should be set with a URL, local file path or a web resource path.
Since:
8.0
  • Field Details

    • fileUrl

      protected URL fileUrl
      Holds the file URL
    • connection

      protected URLConnection connection
      Holds the connection to the file URL
    • location

      protected String location
      Holds the location of the file
  • Constructor Details

    • URLFileItem

      public URLFileItem()
      Default Constructor. The item must be initialized va the 'location' bean property.
    • URLFileItem

      public URLFileItem(File localFile) throws MalformedURLException
      FileItem for a local file.
      Parameters:
      localFile - the local file to use
      Throws:
      MalformedURLException
    • URLFileItem

      public URLFileItem(URL fileUrl)
      FileItem for any URL
      Parameters:
      fileUrl - the URL of the file
    • URLFileItem

      public URLFileItem(String location)
      FileItem for a location
      Parameters:
      location - the location of the file
  • Method Details

    • getLocation

      public String getLocation()
      Gets the location of the file
    • setLocation

      public void setLocation(String location)
      Initializes bean with file location which can be either URL, local file fully qualified path, or web application resource path
      Parameters:
      location - file location
    • getConnection

      protected URLConnection getConnection()
      Returns a connection to the file URL
    • getName

      public String getName()
      Returns the last segment of the URL.
      Specified by:
      getName in interface org.apache.commons.fileupload.FileItem
      See Also:
      • FileItem.getName()
    • getContentType

      public String getContentType()
      Returns the ContentType returned by the URL connection.
      Specified by:
      getContentType in interface org.apache.commons.fileupload.FileItem
      See Also:
    • getSize

      public long getSize()
      Returns the ContentLength returned by the URL connection.
      Specified by:
      getSize in interface org.apache.commons.fileupload.FileItem
      See Also:
    • getInputStream

      public InputStream getInputStream() throws IOException
      Returns the InputStream returned by the URL connection.
      Specified by:
      getInputStream in interface org.apache.commons.fileupload.FileItem
      Throws:
      IOException
      See Also:
      • FileItem.getInputStream()
    • delete

      public void delete()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      delete in interface org.apache.commons.fileupload.FileItem
    • get

      public byte[] get()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      get in interface org.apache.commons.fileupload.FileItem
    • getFieldName

      public String getFieldName()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      getFieldName in interface org.apache.commons.fileupload.FileItem
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      getOutputStream in interface org.apache.commons.fileupload.FileItem
      Throws:
      IOException
    • getString

      public String getString()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      getString in interface org.apache.commons.fileupload.FileItem
    • getString

      public String getString(String arg0) throws UnsupportedEncodingException
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      getString in interface org.apache.commons.fileupload.FileItem
      Throws:
      UnsupportedEncodingException
    • isFormField

      public boolean isFormField()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      isFormField in interface org.apache.commons.fileupload.FileItem
    • isInMemory

      public boolean isInMemory()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      isInMemory in interface org.apache.commons.fileupload.FileItem
    • setFieldName

      public void setFieldName(String arg0)
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      setFieldName in interface org.apache.commons.fileupload.FileItem
    • setFormField

      public void setFormField(boolean arg0)
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      setFormField in interface org.apache.commons.fileupload.FileItem
    • write

      public void write(File arg0) throws Exception
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      write in interface org.apache.commons.fileupload.FileItem
      Throws:
      Exception
    • getHeaders

      public org.apache.commons.fileupload.FileItemHeaders getHeaders()
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      getHeaders in interface org.apache.commons.fileupload.FileItemHeadersSupport
    • setHeaders

      public void setHeaders(org.apache.commons.fileupload.FileItemHeaders headers)
      Not Implemented. Throws UnsupportedOperationException if called.
      Specified by:
      setHeaders in interface org.apache.commons.fileupload.FileItemHeadersSupport