Package com.facilita.fc.web
Class FileElement
- java.lang.Object
-
- com.facilita.fc.web.HtmlElement
-
- com.facilita.fc.web.InputElement
-
- com.facilita.fc.web.FileElement
-
public class FileElement extends InputElement
Represents anInputElementwhich is a file select control. A file select control allows the user to select one or more files to upload.e.g.
<input name="uploadedfile" type="file" />If files are added to a
FileElementobject, they will be uploaded when the containingFormis sent to the web server.- See Also:
Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.facilita.fc.web.InputElement
InputElement.InputElementType
-
-
Constructor Summary
Constructors Constructor Description FileElement(long cPtr, boolean cMemoryOwn)For internal use only.FileElement(java.lang.String elementName)Creates aFileElementobject with the specified name
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFile(java.lang.String filename, java.lang.String path)Adds a file to the list of files to upload.voidaddFile(java.lang.String filename, java.lang.String path, java.lang.String contentType)Adds a file to the list of files to upload.voidaddFile(java.lang.String filename, java.lang.String path, java.lang.String contentType, java.lang.String contentTransferEncoding)Adds a file to the list of files to upload.voidclearFiles()Clears the list of files to be uploaded.HtmlElementclone()Creates a copy of this HTML element.voiddelete()static longgetCPtr(FileElement obj)For internal use only.java.lang.StringgetMultipartBoundary()Gets theStringthat will be used as the boundary between files (including the--prefix), when encoding this element as multipart/form-data.voidremoveFile(java.lang.String filename)Removes a file from the list of files to be uploaded.voidsetMultipartBoundary(java.lang.String boundary)Sets theStringthat will be used as the boundary between files (including the--prefix), when encoding this element as multipart/form-data.-
Methods inherited from class com.facilita.fc.web.InputElement
getCPtr, getType, isChecked, isSubmitted, isSuccessfulControl, makeFrom, setChecked, setSubmitted
-
Methods inherited from class com.facilita.fc.web.HtmlElement
getAfterEndTagPosition, getAfterStartTagPosition, getAttribute, getAttributes, getCharEncoding, getContent, getContentPosition, getCPtr, getId, getName, getTag, getValue, hasAttribute, isDisabled, removeAttribute, setAttribute, setAttribute, setCharEncoding, setContent, setDisabled, setId, setName, setValue
-
-
-
-
Constructor Detail
-
FileElement
public FileElement(long cPtr, boolean cMemoryOwn)For internal use only. Of no interest to the user.- Parameters:
cPtr- pointer to the CPP wrapped objectcMemoryOwn- indicates if this object is responsible for memory management of the CPP object
-
FileElement
public FileElement(java.lang.String elementName)
Creates aFileElementobject with the specified name- Parameters:
elementName- the name attribute of the FileElement
-
-
Method Detail
-
getCPtr
public static long getCPtr(FileElement obj)
For internal use only. Of no interest to the user.- Parameters:
obj- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
- Overrides:
deletein classInputElement
-
addFile
public void addFile(java.lang.String filename, java.lang.String path, java.lang.String contentType, java.lang.String contentTransferEncoding) throws java.io.UnsupportedEncodingExceptionAdds a file to the list of files to upload. It will be uploaded when theFormwhich contains thisFileElementis sent to the web server.- Parameters:
filename- the name of the filepath- the location of the file on disk. This can either be an absolute path, or a relative path. If it is a relative path, then it is relative to thedata/Filesdirectory for the current injectorcontentType- the Content-Type to specify when sending this file (e.g."text/plain","image/gif")contentTransferEncoding- the Content-Transfer-Encoding to specify when sending this file (e.g."binary")- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.
-
addFile
public void addFile(java.lang.String filename, java.lang.String path, java.lang.String contentType) throws java.io.UnsupportedEncodingExceptionAdds a file to the list of files to upload. It will be uploaded when theFormwhich contains thisFileElementis sent to the web server.The default Content-Transfer-Encoding is
"".- Parameters:
filename- the name of the filepath- the location of the file on disk. This can either be an absolute path, or a relative path. If it is a relative path, then it is relative to thedata/Filesdirectory for the current injectorcontentType- the Content-Type to specify when sending this file (e.g."text/plain","image/gif")- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.
-
addFile
public void addFile(java.lang.String filename, java.lang.String path) throws java.io.UnsupportedEncodingExceptionAdds a file to the list of files to upload. It will be uploaded when theFormwhich contains thisFileElementis sent to the web server.The default Content-Type is
"text/plain", and the default Content-Transfer-Encoding is"".- Parameters:
filename- the name of the filepath- the location of the file on disk. This can either be an absolute path, or a relative path. If it is a relative path, then it is relative to thedata/Filesdirectory for the current injector- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.
-
removeFile
public void removeFile(java.lang.String filename) throws java.io.UnsupportedEncodingExceptionRemoves a file from the list of files to be uploaded.- Parameters:
filename- the name of the file to remove from the list- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.
-
clearFiles
public void clearFiles()
Clears the list of files to be uploaded.
-
getMultipartBoundary
public java.lang.String getMultipartBoundary()
Gets theStringthat will be used as the boundary between files (including the--prefix), when encoding this element as multipart/form-data.e.g. for this POST data message body:
--multipart-form-boundary Content-Disposition: form-data; name="input1" value1 --multipart-form-boundary Content-Disposition: form-data; name="files-to-upload[]" Content-Type: multipart/mixed; boundary=multipart-file-boundary --multipart-file-boundary Content-Disposition: file; filename="image.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary Content-Disposition: file; filename="image2.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary-- --multipart-form-boundary--form.getFileElement("files-to-upload[]").getMultipartBoundary()will return"--multipart-file-boundary"- Returns:
- the
Stringthat will be used as the boundary between files (including the--prefix), when encoding this element as multipart/form-data - See Also:
setMultipartBoundary(String)
-
setMultipartBoundary
public void setMultipartBoundary(java.lang.String boundary)
Sets theStringthat will be used as the boundary between files (including the--prefix), when encoding this element as multipart/form-data.e.g.
The POST data message body contains:// Populate form with data Form form = previousResponse.extractForm("myForm"); form.getInputElement("input1").setValue("value1"); form.getFileElement("files-to-upload[]").addFile("image.bmp", "C:\\dataFiles\\image.bmp", "image/bmp"); form.getFileElement("files-to-upload[]").addFile("image2.bmp", "C:\\dataFiles\\image2.bmp", "image/bmp"); // Set the multipart boundary for the FileElement form.getFileElement("files-to-upload[]").setMultipartBoundary("--multipart-file-boundary"); // Send the POST request Request request = getWebBrowser().createRequest(HttpMethod.POST, myUrl); request.setMessageBody(form); Response response = request.send();--multipart-form-boundary Content-Disposition: form-data; name="input1" value1 --multipart-form-boundary Content-Disposition: form-data; name="files-to-upload[]" Content-Type: multipart/mixed; boundary=multipart-file-boundary --multipart-file-boundary Content-Disposition: file; filename="image.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary Content-Disposition: file; filename="image2.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary-- --multipart-form-boundary--- Parameters:
boundary- theStringthat will be used as the boundary between files (including the--prefix), when encoding this element as multipart/form-data- See Also:
getMultipartBoundary()
-
clone
public HtmlElement clone()
Description copied from class:HtmlElementCreates a copy of this HTML element.- Overrides:
clonein classInputElement- Returns:
- a new
HtmlElementobject which is an exact copy of this HTML element
-
-