landed the code for doing post attachments (the infamous paperclip)
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -32,9 +32,10 @@ import javax.servlet.*;
|
||||
|
||||
public class ServletMultipartHandler
|
||||
{
|
||||
private MimeMultipart multipart; // holds all the multipart data
|
||||
private Hashtable param_byname; // parameters by name
|
||||
private Vector param_order; // parameters in order
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal wrapper around the ServletRequest that implements DataSource
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ServletDataSource implements DataSource
|
||||
{
|
||||
@@ -75,6 +76,11 @@ public class ServletMultipartHandler
|
||||
|
||||
} // end class ServletDataSource
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class representing a data value
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static class MultipartDataValue implements Blob
|
||||
{
|
||||
private byte[] actual_data; // the actual data we contain
|
||||
@@ -83,7 +89,7 @@ public class ServletMultipartHandler
|
||||
{
|
||||
InputStream in = part.getInputStream();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] copybuf = new byte[1024];
|
||||
byte[] copybuf = new byte[4096];
|
||||
int ct = in.read(copybuf);
|
||||
while (ct>=0)
|
||||
{ // do a simple read and write
|
||||
@@ -133,6 +139,11 @@ public class ServletMultipartHandler
|
||||
|
||||
} // end class MultipartDataValue
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class representing a request parameter
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class MultipartParameter
|
||||
{
|
||||
private MimeBodyPart part; // the actual body part data
|
||||
@@ -178,7 +189,8 @@ public class ServletMultipartHandler
|
||||
public String getValue()
|
||||
{
|
||||
if (filename!=null)
|
||||
return filename;
|
||||
return filename; // "value" for file parts is the filename
|
||||
|
||||
try
|
||||
{ // Retrieve the part's actual content and convert it to a String. (Since non-file
|
||||
// fields are of type text/plain, the Object "val" should actually be a String, in
|
||||
@@ -228,7 +240,7 @@ public class ServletMultipartHandler
|
||||
public MultipartDataValue getContent() throws ServletMultipartException
|
||||
{
|
||||
if (filename==null)
|
||||
return null;
|
||||
return null; // not a file parameter
|
||||
|
||||
if (cached_value==null)
|
||||
{ // we don't have the value cached yet
|
||||
@@ -256,6 +268,20 @@ public class ServletMultipartHandler
|
||||
|
||||
} // end class MultipartParameter
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private MimeMultipart multipart; // holds all the multipart data
|
||||
private Hashtable param_byname; // parameters by name
|
||||
private Vector param_order; // parameters in order
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public ServletMultipartHandler(ServletRequest request) throws ServletMultipartException
|
||||
{
|
||||
if (!canHandle(request))
|
||||
@@ -286,6 +312,11 @@ public class ServletMultipartHandler
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns <CODE>true</CODE> if the given <CODE>ServletRequest</CODE> can be handled by
|
||||
* the <CODE>ServletMultipartHandler</CODE>, <CODE>false</CODE> if not.
|
||||
@@ -301,6 +332,11 @@ public class ServletMultipartHandler
|
||||
|
||||
} // end canHandle
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public Enumeration getNames()
|
||||
{
|
||||
Vector tmp_vector = new Vector();
|
||||
|
||||
Reference in New Issue
Block a user