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
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:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected URLConnection
Holds the connection to the file URLprotected URL
Holds the file URLprotected String
Holds the location of the file -
Constructor Summary
ConstructorsConstructorDescriptionDefault Constructor.URLFileItem
(File localFile) FileItem for a local file.URLFileItem
(String location) FileItem for a locationURLFileItem
(URL fileUrl) FileItem for any URL -
Method Summary
Modifier and TypeMethodDescriptionvoid
delete()
Not Implemented.byte[]
get()
Not Implemented.protected URLConnection
Returns a connection to the file URLReturns the ContentType returned by the URL connection.Not Implemented.org.apache.commons.fileupload.FileItemHeaders
Not Implemented.Returns the InputStream returned by the URL connection.Gets the location of the filegetName()
Returns the last segment of the URL.Not Implemented.long
getSize()
Returns the ContentLength returned by the URL connection.Not Implemented.Not Implemented.boolean
Not Implemented.boolean
Not Implemented.void
setFieldName
(String arg0) Not Implemented.void
setFormField
(boolean arg0) Not Implemented.void
setHeaders
(org.apache.commons.fileupload.FileItemHeaders headers) 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 pathvoid
Not Implemented.
-
Field Details
-
fileUrl
Holds the file URL -
connection
Holds the connection to the file URL -
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
FileItem for a local file.- Parameters:
localFile
- the local file to use- Throws:
MalformedURLException
-
URLFileItem
FileItem for any URL- Parameters:
fileUrl
- the URL of the file
-
URLFileItem
FileItem for a location- Parameters:
location
- the location of the file
-
-
Method Details
-
getLocation
Gets the location of the file -
setLocation
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
Returns a connection to the file URL -
getName
Returns the last segment of the URL.- Specified by:
getName
in interfaceorg.apache.commons.fileupload.FileItem
- See Also:
-
FileItem.getName()
-
getContentType
Returns the ContentType returned by the URL connection.- Specified by:
getContentType
in interfaceorg.apache.commons.fileupload.FileItem
- See Also:
-
FileItem.getContentType()
URLConnection.getContentType()
-
getSize
public long getSize()Returns the ContentLength returned by the URL connection.- Specified by:
getSize
in interfaceorg.apache.commons.fileupload.FileItem
- See Also:
-
FileItem.getSize()
URLConnection.getContentLength()
-
getInputStream
Returns the InputStream returned by the URL connection.- Specified by:
getInputStream
in interfaceorg.apache.commons.fileupload.FileItem
- Throws:
IOException
- See Also:
-
FileItem.getInputStream()
-
delete
public void delete()Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
delete
in interfaceorg.apache.commons.fileupload.FileItem
-
get
public byte[] get()Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
get
in interfaceorg.apache.commons.fileupload.FileItem
-
getFieldName
Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
getFieldName
in interfaceorg.apache.commons.fileupload.FileItem
-
getOutputStream
Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
getOutputStream
in interfaceorg.apache.commons.fileupload.FileItem
- Throws:
IOException
-
getString
Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
getString
in interfaceorg.apache.commons.fileupload.FileItem
-
getString
Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
getString
in interfaceorg.apache.commons.fileupload.FileItem
- Throws:
UnsupportedEncodingException
-
isFormField
public boolean isFormField()Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
isFormField
in interfaceorg.apache.commons.fileupload.FileItem
-
isInMemory
public boolean isInMemory()Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
isInMemory
in interfaceorg.apache.commons.fileupload.FileItem
-
setFieldName
Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
setFieldName
in interfaceorg.apache.commons.fileupload.FileItem
-
setFormField
public void setFormField(boolean arg0) Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
setFormField
in interfaceorg.apache.commons.fileupload.FileItem
-
write
Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
write
in interfaceorg.apache.commons.fileupload.FileItem
- Throws:
Exception
-
getHeaders
public org.apache.commons.fileupload.FileItemHeaders getHeaders()Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
getHeaders
in interfaceorg.apache.commons.fileupload.FileItemHeadersSupport
-
setHeaders
public void setHeaders(org.apache.commons.fileupload.FileItemHeaders headers) Not Implemented. Throws UnsupportedOperationException if called.- Specified by:
setHeaders
in interfaceorg.apache.commons.fileupload.FileItemHeadersSupport
-