com.webmethods.caf.faces.data.attachments
Class URLFileItem

java.lang.Object
  extended by com.webmethods.caf.faces.data.attachments.URLFileItem

public class URLFileItem
extends Object

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 URLFileItem.location property should be set with a URL, local file path or a web resource path.

Since:
8.0

Field Summary
protected  URLConnection connection
          Holds the connection to the file URL
protected  URL fileUrl
          Holds the file URL
protected  String location
          Holds the location of the file
 
Constructor Summary
URLFileItem()
          Default Constructor.
URLFileItem(File localFile)
          FileItem for a local file.
URLFileItem(String location)
          FileItem for a location
URLFileItem(URL fileUrl)
          FileItem for any URL
 
Method Summary
 void delete()
          Not Implemented.
 byte[] get()
          Not Implemented.
protected  URLConnection getConnection()
          Returns a connection to the file URL
 String getContentType()
          Returns the ContentType returned by the URL connection.
 String getFieldName()
          Not Implemented.
 InputStream getInputStream()
          Returns the InputStream returned by the URL connection.
 String getLocation()
          Gets the location of the file
 String getName()
          Returns the last segment of the URL.
 OutputStream getOutputStream()
          Not Implemented.
 long getSize()
          Returns the ContentLength returned by the URL connection.
 String getString()
          Not Implemented.
 String getString(String arg0)
          Not Implemented.
 boolean isFormField()
          Not Implemented.
 boolean isInMemory()
          Not Implemented.
 void setFieldName(String arg0)
          Not Implemented.
 void setFormField(boolean arg0)
          Not Implemented.
 void setLocation(String location)
          Initializes bean with file location which can be either URL, local file fully qualified path, or web application resource path
 void write(File arg0)
          Not Implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

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 Detail

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.

See Also:
org.apache.commons.fileupload.FileItem#getName()

getContentType

public String getContentType()
Returns the ContentType returned by the URL connection.

See Also:
org.apache.commons.fileupload.FileItem#getContentType(), URLConnection.getContentType()

getSize

public long getSize()
Returns the ContentLength returned by the URL connection.

See Also:
org.apache.commons.fileupload.FileItem#getSize(), URLConnection.getContentLength()

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns the InputStream returned by the URL connection.

Throws:
IOException
See Also:
org.apache.commons.fileupload.FileItem#getInputStream()

delete

public void delete()
Not Implemented. Throws UnsupportedOperationException if called.


get

public byte[] get()
Not Implemented. Throws UnsupportedOperationException if called.


getFieldName

public String getFieldName()
Not Implemented. Throws UnsupportedOperationException if called.


getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Not Implemented. Throws UnsupportedOperationException if called.

Throws:
IOException

getString

public String getString()
Not Implemented. Throws UnsupportedOperationException if called.


getString

public String getString(String arg0)
                 throws UnsupportedEncodingException
Not Implemented. Throws UnsupportedOperationException if called.

Throws:
UnsupportedEncodingException

isFormField

public boolean isFormField()
Not Implemented. Throws UnsupportedOperationException if called.


isInMemory

public boolean isInMemory()
Not Implemented. Throws UnsupportedOperationException if called.


setFieldName

public void setFieldName(String arg0)
Not Implemented. Throws UnsupportedOperationException if called.


setFormField

public void setFormField(boolean arg0)
Not Implemented. Throws UnsupportedOperationException if called.


write

public void write(File arg0)
           throws Exception
Not Implemented. Throws UnsupportedOperationException if called.

Throws:
Exception