Oracle interMedia Java Classes User's Guide and Reference Release 9.0.1 Part Number A88785-01 |
|
Oracle interMedia Java Classes for servlets and JavaServer Pages (JSPs) facilitates retrieving and uploading multimedia data from and to an Oracle database.
The OrdHttpResponseHandler class facilitates the retrieval of multimedia data from an Oracle database and its delivery to a browser or other HTTP client from a Java servlet. The OrdHttpJspResponseHandler class provides the same features for JSPs.
File uploading using HTML forms encodes form data and uploaded files in POST requests using the multipart/form-data format. The OrdHttpUploadFormData class facilitates the processing of such requests by parsing the POST data and making the contents of regular form fields and the contents of uploaded files readily accessible to a Java servlet or JSP. The handling of uploaded files is facilitated by the OrdHttpUploadFile class, which provides an easy-to-use API that applications call to load multimedia data into an Oracle database.
You will need to include the following import statements in your Java file in order to execute interMedia methods:
import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import oracle.jdbc.driver.*; import oracle.sql.*; import oracle.ord.im.*;
The OrdHttpResponseHandler class facilitates the retrieval of multimedia data from an Oracle database and the delivery of the data to a browser or other HTTP client from a Java servlet.
This class extends java.lang.Object.
This class contains the following field:
The default size of the buffer used to retrieve LOB data from the database and deliver it to the client. The default is 32768; however, you can set your own value for your request with the setBufferSize( ) method.
The following example shows how to use the OrdHttpResponseHandler class to retrieve an image from a database and deliver it to a browser:
PreparedStatement stmt = conn.prepareStatement("select photo from photo_album where id = ?"); stmt.setString(1, request.getParameter("photo_id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdImage img = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request, response); handler.sendImage(img); } else{ response.setStatus(response.SC_NOT_FOUND); rset.close( ); stmt.close( );
If an OrdDoc object contains a text-based document that uses a character set (or charset) other than ISO-8859-1 (also called Latin-1) and you want to retrieve the document and deliver it to a browser, your application must specify the charset name in the HTTP Content-Type header.
If the charset specification is included in the MIME type attribute of the OrdDoc object, then your application needs to call only the sendDoc( ) method to retrieve the document and deliver it to the browser. For example, an HTML page that is written in Japanese might be stored in the OrdDoc object with a MIME type of text/html; charset=Shift_JIS.
In this case, calling the sendDoc( ) method will send the appropriate Content-Type header, allowing the browser to display the page correctly.
However, if the MIME type in the OrdDoc object does not include the charset specification, then you must use one of the sendResponse( ) methods and specify the MIME type explicitly. For example, if the MIME type of an HTML page written in Japanese is stored in the OrdDoc object as text/html,
and the charset name is specified in a separate column, then the application must append the charset specification to the MIME type before calling the sendResponse( ) method. For example:
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement( "select doc, charset from documents where id = ?"); stmt.setString(1, request.getParameter("id"); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdDoc doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( )); String charset = rset.getString(2); String mimeType = doc.getMimeType( ) + "; charset=" + charset; OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request, response); handler.sendResponse(mimeType, doc.getContentLength( ), doc.getContent( ), doc.getUpdateTime( )); return; } else{ response.setStatus(response.SC_NOT_FOUND); } rset.close( ); stmt.close( );
public OrdHttpResponseHandler( )
Creates an OrdHttpResponseHandler object to handle the response to a multimedia retrieval request. The application must subsequently specify the HttpServletResponse object with the setServletRequest( ) method, and can optionally specify the HttpServletRequest object with the setServletRequest( ) method.
None.
None.
None.
See setServletRequest( ) for an example of this method.
public OrdHttpResponseHandler(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Creates an OrdHttpResponseHandler object to handle the response to a multimedia retrieval request specifying the HttpServletRequest and HttpServletResponse objects.
The HttpServletRequest object for this request.
The HttpServletResponse object for this request.
None.
None.
See sendAudio( ) for an example of this method.
public void sendAudio(oracle.ord.im.OrdAudio audio)
Retrieves an audio clip from an OrdAudio object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The OrdAudio object whose contents will be delivered to the browser.
None.
java.io.IOException - if an error occurs reading the audio data
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the audio data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
OrdHttpResponseException - if the source type is not recognized
OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("select audio from sounds where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdAudio audio = (OrdAudio)rset.getCustomDatum(1, OrdAudio.getFactory( )); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendAudio(audio); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendDoc(oracle.ord.im.OrdDoc doc)
Retrieves multimedia data from an OrdDoc object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The OrdDoc object whose contents will be delivered to the browser.
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
OrdHttpResponseException - if the source type is not recognized
OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("select doc from documents where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdDoc doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( )); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendDoc(doc); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendImage(oracle.ord.im.OrdImage image)
Retrieves an image from an OrdImage object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The OrdImage object whose contents will be delivered to the browser.
None.
java.io.IOException - if an error occurs reading the image data
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the image data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
OrdHttpResponseException - if the source type is not recognized
OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("select image from photos where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdImage image = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendImage(image); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendResponse(String contentType, int length, oracle.sql.BFILE bfile,
java.sql.Timestamp lastModified)
Builds an HTTP response header, then retrieves the contents of the BFILE from the database and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The MIME type of the content.
The length of the data.
The BFILE from which the multimedia data is retrieved.
A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalArgumentException - if the length is negative
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement ("select mimetype, len, doc, updatetime from docfiles where id = ?"); stmt.setString( 1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ String mimeType = rset.getString(1); int len = rset.getInt(2); BFILE bfile = rset.getBFILE(3); Timestamp updateTime = rset.getTimestamp(4); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendResponse(mimeType, len, bfile, updateTime); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendResponse(String contentType, int length, oracle.sql.BLOB blob,
java.sql.Timestamp lastModified)
Builds an HTTP response header, then retrieves the contents of the BLOB from the database and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The MIME type of the content.
The length of the data.
The BLOB from which the multimedia data is retrieved.
A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalArgumentException - if the length is negative
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement ("select mimetype, len, doc, updatetime from docblobs where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ String mimeType = rset.getString(1); int len = rset.getInt(2); BLOB blob = rset.getBLOB(3); Timestamp updateTime = rset.getTimestamp(4); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendResponse(mimeType, len, blob, updateTime); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendResponse(String contentType, int length, java.io.InputStream in,
java.sql.Timestamp lastModified)
Builds an HTTP response header, then retrieves the contents of the InputStream and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The MIME type of the content.
The length of the data.
The InputStream object from which the multimedia data is retrieved.
A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.
None.
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
java.lang.IllegalArgumentException - if the length is negative
javax.servlet.ServletException - if an error occurs accessing the binary output stream
java.io.IOException - if an error occurs reading the multimedia data
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement ("select mimetype, len, doc, updatetime from docblobs where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if ( rset.next( ) ){ String mimeType = rset.getString(1); int len = rset.getInt(2); BLOB blob = rset.getBLOB(3); Timestamp updateTime = rset.getTimestamp(4); InputStream blobInputStream = blob.getBinaryStream( ); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendResponse(mimeType, len, blobInputStream, updateTime); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendResponseBody(int length, oracle.sql.BFILE bfile)
Retrieves the contents of a BFILE from the database and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.
The length of the data.
The BFILE from which the multimedia data is retrieved.
None.
java.lang.IllegalStateException - if HttpServletRequest has not been specified
java.lang.IllegalArgumentException - if the length is negative
javax.servlet.ServletException - if an error occurs accessing the binary output stream
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
java.io.IOException - if an error occurs reading the multimedia data
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement ("select mimetype, len, doc from docfiles where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ String mimeType = rset.getString(1); int len = rset.getInt(2); BFILE bfile = rset.getBFILE(3); response.setContentLength(len); response.setContentType(mimeType); OrdHttpResponseHandler handler = new OrdHttpResponseHandler( ); handler.setServletResponse(response); handler.sendResponseBody(len, bfile); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendResponseBody(int length, oracle.sql.BLOB blob)
Retrieves the contents of a BLOB from the database and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.
The length of the data.
The BLOB from which the multimedia data is retrieved.
None.
java.lang.IllegalStateException - if HttpServletRequest has not been specified
java.lang.IllegalArgumentException - if the length is negative
javax.servlet.ServletException - if an error occurs accessing the binary output stream
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
java.io.IOException - if an error occurs reading the multimedia data
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement ("select mimetype, len, doc from docblobs where id = ?"); stmt.setString( 1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ String mimeType = rset.getString(1); int len = rset.getInt(2); BLOB blob = rset.getBLOB(3); response.setContentLength(len); response.setContentType(mimeType); OrdHttpResponseHandler handler = new OrdHttpResponseHandler( ); handler.setServletResponse(response); handler.sendResponseBody(len, blob); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendResponseBody(int length, java.io.InputStream in)
Retrieves the contents of the InputStream and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.
The length of the data.
The InputStream object from which the multimedia data is retrieved.
None.
java.lang.IllegalStateException - if HttpServletRequest has not been specified
java.lang.IllegalArgumentException - if the length is negative
javax.servlet.ServletException - if an error occurs accessing the binary output stream
java.io.IOException - if an error occurs reading the multimedia data
OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement ("select mimetype, len, doc from docblobs where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ String mimeType = rset.getString(1); int len = rset.getInt(2); BLOB blob = rset.getBLOB(3); response.setContentLength(len); response.setContentType(mimeType); InputStream blobInputStream = blob.getBinaryStream( ); OrdHttpResponseHandler handler = new OrdHttpResponseHandler( ); handler.setServletResponse(response); handler.sendResponseBody(len, blobInputStream); return; } else{ response.setStatus(response.SC_NOT_FOUND); }
public void sendVideo(oracle.ord.im.OrdVideo video)
Retrieves a video clip from an OrdVideo object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.
The OrdVideo object whose contents will be delivered to the browser.
None.
java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified
OrdHttpResponseException - if the source type is not recognized
javax.servlet.ServletException - if an error occurs accessing the binary output stream
java.sql.SQLException - if an error occurs obtaining an InputStream to read the video data
java.io.IOException - if an error occurs reading the video data
OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("select video from movies where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdVideo video = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( )); OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response); handler.sendVideo(video); return; } else{ response.setStatus( response.SC_NOT_FOUND ); }
public void setBufferSize(int bufferSize)
Sets the buffer size for LOB read and response write operations.
The buffer size to be set.
None.
java.lang.IllegalArgumentException - if the buffer size is negative or zero
OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request, response); handler.setBufferSize(16000);
public void setServletRequest(javax.servlet.http.HttpServletRequest request)
Specifies the HttpServletRequest object for this request. You must call this method if you did not set the HttpServletRequest object in the constructor and you want to use any of the send methods other than the sendResponseBody methods; you do not need to set the HttpServletRequest object if you use only the sendResponseBody methods.
The HttpServletRequest object to set for this request.
None.
None.
OrdHttpResponseHandler handler = new OrdHttpResponseHandler( ); handler.setServletRequest(request); handler.setServletResponse(response);
public void setServletResponse(javax.servlet.http.HttpServletResponse response)
Sets the HttpServletResponse object for this request. You must call this method if you did not set the HttpServletResponse object in the constructor.
The HttpServletResponse object to set for this request.
None.
None.
See setServletRequest( ) for an example of this method.
This section presents reference information on the methods of the OrdHttpJspResponseHandler class.
The OrdHttpJspResponseHandler class facilitates the retrieval of multimedia data from an Oracle database and the delivery from the database to a browser or another HTTP client from a JSP.
The methods provided by this class that deliver multimedia data all use the JspWriter.clear method to clear the page output buffer prior to delivering the media data; therefore, the page must use the buffered output model, which is the default.
This class extends OrdHttpResponseHandler.
The following example demonstrates how to use the OrdHttpJspResponseHandler class to retrieve an image from a database and deliver it to a browser. The return statement ensures that the trailing newline characters following the final end tag (represented by a percent mark and right-angle bracket, or %>)
are not transmitted to the browser following the image.
<%@ page language="java" %> <%@ page import="OrdSamplePhotoAlbumBean" %> <%@ page import="oracle.ord.im.OrdHttpJspResponseHandler" %> <jsp:useBean id="photos" scope="page" class="OrdSamplePhotoAlbumBean"/> <jsp:useBean id="handler" scope="page" class="oracle.ord.im.OrdHttpJspResponseHandler"/> <% // Select the entry from the table using the id request parameter, // then fetch the row. photos.selectRowById(request.getParameter("id")); if (!photos.fetch( )){ response.setStatus(response.SC_NOT_FOUND); return; } // Set the page context for the retrieve request, then retrieve // the image from the database and deliver it to the browser. The // getImage( ) method returns an object of type oracle.ord.im.OrdImage. if (true){ handler.setPageContext(pageContext); handler.sendImage(photos.getImage( )); return; } %>
JSP engines do not have to support access to the servlet binary output stream. Therefore, not all JSP engines support the delivery of multimedia data using the OrdHttpJspResponseHandler class.
All multimedia data stored in the database using interMedia objects, including text documents stored in OrdDoc objects, is stored using a binary LOB data type. Multimedia data that is stored internally in the database is stored using a BLOB. Multimedia data that is stored in an operating system file outside the database is stored using a BFILE. Therefore, all multimedia data is delivered to the browser through the servlet binary output stream using the ServletOutputStream class.
All the send methods in the OrdHttpJspResponseHandler class mirror the initial processing of the jsp:forward tag by calling the JspWriter.clear method to clear the output buffer of the page prior to obtaining the binary output stream. However, JSP engines are not required to support a call to the ServletResponse.getOutputStream( ) method with a JSP. A JSP engine that does not support this usage typically throws an IllegalStateException from the getOutputStream( ) method. However, the exact behavior is specific to the implementation used.
If your JSP engine does not support access to the binary output stream from within a JSP, then you must use a servlet to deliver multimedia data. For example, perform one of the following operations:
When delivering multimedia data from a JSP, a return statement is always required following a call to any of the send methods of the OrdHttpJspResponseHandler class. The return statement is necessary to ensure that no data other than the multimedia data is written to the output stream associated with the JSP.
An if(true){... return...}
construct may be used to avoid the "statement not reachable" error that may result from the presence of additional code generated by the JSP engine. This construct, which mirrors the code produced by some JSP engines to handle the <jsp:forward...>
directive, is illustrated in the previous example.
public OrcHttpJspResponseHandler( )
Creates an OrdHttpJspResponseHandler object to handle the response to a multimedia retrieval request. The application must subsequently specify the PageContent object.
None.
None.
None.
The default constructor is typically invoked implicitly when the OrdHttpJspResponseHandler class is used as a JavaBean. See setPageContext( ) for an example of the implicit use of the constructor.
public OrdHttpJspResponseHandler(javax.servlet.jsp.PageContext pageContext)
Creates an OrdHttpJspResponseHandler object to handle the response to a multimedia retrieval request specifying the PageContext object.
The PageContext object for the request.
None.
None.
OrdHttpJspResponseHandler handler = new OrdHttpJspResponseHandler(pageContext);
public void sendAudio(oracle.ord.im.OrdAudio audio)
Retrieves an audio clip from an OrdAudio object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
The OrdAudio object whose contents will be delivered to the browser.
None.
java.io.IOException - if an error occurs reading the audio data
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the data
OrdHttpResponseException - if the source type is not recognized
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendAudio( ) method extends the OrdHttpResponseHandler.sendAudio( ) method. See sendAudio( ) in Section 9.2 for an example of this method in the base class.
public void sendDoc(oracle.ord.im.OrdDoc doc)
Retrieves multimedia data from an OrdDoc object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
The OrdDoc object whose contents will be delivered to the browser..
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the data
OrdHttpResponseException - if the source type is not recognized
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendDoc( ) method extends the OrdHttpResponseHandler.sendDoc( ) method. See sendDoc( ) in Section 9.2 for an example of this method in the base class.
public void sendImage(oracle.ord.im.OrdImage image)
Retrieves an image from an OrdImage object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
An OrdImage object whose contents will be delivered to the browser..
None.
java.io.IOException - if an error occurs reading the image data
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the data
OrdHttpResponseException - if the source type is not recognized
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendImage( ) method extends the OrdHttpResponseHandler.sendImage( ) method. See sendImage( ) in Section 9.2 for an example of this method in the base class.
public void sendResponse(String contentType, int length, oracle.sql.BFILE bfile,
java.sql.Timestamp lastModified)
Builds an HTTP response header and retrieves the contents of the BFILE from the database and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
The MIME type of the contents.
The length of the data.
The BFILE whose contents will be delivered to the browser.
A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalArgumentException - if the length is negative
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendResponse(String, int, BFILE, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, BFILE, Timestamp) method. See sendResponse(String,int,BFILE,Timestamp) in Section 9.2 for an example of this method in the base class.
public void sendResponse(String contentType, int length, oracle.sql.BLOB blob,
java.sql.Timestamp lastModified)
Builds an HTTP response header and retrieves the contents of the BLOB from the database and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
The MIME type of the contents.
The length of the data.
The BLOB whose contents will be delivered to the browser.
A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalArgumentException - if the length is negative
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendResponse(String, int, BLOB, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, BLOB, Timestamp) method. See sendResponse(String,int,BLOB,Timestamp) in Section 9.2 for an example of this method in the base class.
public void sendResponse(String contentType, int length, java.io.InputStream in,
java.sql.Timestamp lastModified)
Builds an HTTP response header and retrieves the contents of the InputStream and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
The MIME type of the contents.
The length of the data.
The InputStream whose contents will be delivered to the browser.
A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.
None.
java.io.IOException - if an error occurs reading the multimedia data
java.lang.IllegalArgumentException - if the length is negative
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendResponse(String, int, InputStream, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, InputStream, Timestamp) method.
See sendResponse(String,int,InputStream,Timestamp) in Section 9.2 for an example of this method in the base class.
public void sendVideo(oracle.ord.im.OrdVideo video)
Retrieves a video clip from an OrdVideo object and delivers it to the browser.
This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.
The OrdVideo object whose contents will be delivered to the browser.
None.
java.io.IOException - if an error occurs reading the video data
java.lang.IllegalStateException - if PageContext has not been specified
java.sql.SQLException - if an error occurs obtaining an InputStream to read the data
OrdHttpResponseException - if the source type is not recognized
javax.servlet.ServletException - if an error occurs accessing the binary output stream
The OrdHttpJspResponseHandler.sendVideo( ) method extends the OrdHttpResponseHandler.sendVideo( ) method. See sendVideo( ) in Section 9.2 for an example of this method in the base class.
public void setPageContext(javax.servlet.jsp.PageContext pageContext)
Specifies the PageContext object for this request. You must call this method if you did not set the PageContext object in the constructor.
The PageContext object for this request.
None.
None.
<jsp:useBean id="handler" scope="page" class="oracle.ord.im.OrdHttpJspResponseHandler"/> <% OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("select image from photos where id = ?"); stmt.setString(1, request.getParameter("id")); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (rset.next( )){ OrdImage image = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); handler.setPageContext(pageContext); handler.sendImage(image); return; }else{ response.setStatus(response.SC_NOT_FOUND); } %>
This section presents reference information on the methods of the OrdHttpUploadFormData class.
File uploading using HTML forms encodes form data and uploaded files in POST requests using the multipart/form-data format. The OrdHttpUploadFormData class facilitates the processing of such requests by parsing the POST data and making the contents of regular form fields and uploaded files readily accessible to a Java Servlet or JavaServer Page. The OrdHttpUploadFormData class provides methods to access text-based form field parameters that are identical to the getParameter( ), getParameterValues( ), and getParameterNames( ) methods provided by the ServletRequest class. Access to uploaded files is provided by a similar set of methods, namely getFileParameter( ), getFileParameterValues( ), and getFileParameterNames( ). The OrdHttpUploadFile objects returned by the getFileParameter( ) and getFileParameterValues( ) methods provide simple access to the MIME type, length, and contents of each uploaded file.
For more information on the OrdHttpUploadFile class, see Section 9.5.
This class extends java.lang.Object.
The following is an example of how to use the OrdHttpUploadFormData class:
// Create an OrdHttpUploadFormData object and use it to parse the // multipart/form-data message. // OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request ); formData.parseFormData( ); // Get the description, location, and photo. // String id = formData.getParameter("id"); String description = formData.getParameter("description"); String location = formData.getParameter("location"); OrdHttpUploadFile photo = formData.getFileParameter("photo"); // Prepare and execute a SQL statement to insert a new row into // the table and return the sequence number for the new row. // Disable auto-commit to allow the LOB to be written correctly. // conn.setAutoCommit(false); PreparedStatement stmt = conn.prepareStatement("insert into photo_album (id, description, location, photo) values (?, ?, ?, ORDSYS.ORDIMAGE.INIT( ))"); stmt.setString(1, id); stmt.setString(2, description); stmt.setString(3, location); stmt.executeUpdate( ); // Prepare and execute a SQL statement to fetch the new OrdImage // object from the database. // stmt = conn.prepareStatement("select photo from photo_album where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } OrdImage image = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); // Load the photo into the database and set the properties. // photo.loadImage(image); // Prepare and execute a SQL statement to update the image object. // stmt = (OraclePreparedStatement)conn.prepareStatement("update photo_album set photo = ? where id = ?"); stmt.setCustomDatum(1, image); stmt.setString(2 id); stmt.execute( ); stmt.close( ); // Commit the changes. // conn.commit( );
Every parameter in the optional query string of a request produces a corresponding parameter of type String, whether or not any data is associated with the parameter name. Likewise, every text-based input field in an HTML form also produces a corresponding parameter of type String, whether or not any data is entered into a field. When processing query string parameters and text-based input fields, applications can test the length of the corresponding String object to determine if any data is present.
The parseFormData( ) method merges all query string and form field parameters into a single, ordered parameter set, where the query string parameters are processed first, followed by the form field parameters. Thus, query string parameters take precedence over form field parameters. For example, if a request is made with a query string of arg=hello&arg=world and the values 'greetings' and 'everyone' are entered into two HTML form fields named 'arg', then the resulting parameter set would include the following entry: arg=(hello, world, greetings, everyone).
Every input field of type FILE in an HTML form produces a corresponding parameter of type OrdUploadFile, whether or not a valid file name is entered into a field of type FILE. When processing a field of type FILE, applications can test either the length of the file name, the length of content, or a combination of the two to determine if a valid file name was entered by a user and if the file was successfully uploaded by the browser. See the OrdHttpUploadFile class in Section 9.5 for more information.
Microsoft's Internet Explorer (IE) browser allows data to be entered into an HTML form using a character set encoding that is different from that being used to view the form. For example, it is possible to copy Simplified Chinese (GB2312) character set data from one browser window and paste it into a form being viewed using the Western European (ISO) character set in a different browser window. In this situation, IE can sometimes transmit the form data twice in such a way that the multipart/form-data parser cannot detect the duplicated data. Furthermore, the non-Western European language form data is sometimes sent as a Unicode escape sequence, sometimes in its raw binary form, and sometimes duplicated using both formats in different portions of the POST data.
Although this same problem does not exist with the Netscape browser, care must still be taken to ensure that the correct character set is being used. For example, although it is possible to copy Simplified Chinese (GB2312) character set data from one browser window and paste it into a form being viewed using the Western European (ISO) character set in a different browser window, when the data is pasted into the form field, the two bytes that comprise each Simplified Chinese character are stored as two individual Western European (ISO) characters.
Therefore, care must be taken to view an HTML form using the correct character set, no matter which Web browser is used. For example, the HTML META tag can be used to specify the character set as follows:
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=GB2312">
public void enableParameterTranslation(java.lang.Sting encoding)
Enables the translation of all HTML form parameter names and all text-based parameter values using the specified character encoding when parsing the body of a multipart/form-data POST request.
Prior to calling the parseFormData( ) method, applications that process requests and responses using character encodings other than ISO-8859-1 can call the enableParameterTranslation( ) method to specify the character encoding to be used to translate the names of all HTML form parameters and the values of all text-based HTML form parameters when parsing the body of a multipart/form-data POST request.
Query string parameters that accompany multipart/form-data POST requests are not translated prior to being merged into the list of multipart/form-data parameters. This is because there is no way to determine if the underlying servlet container or JSP engine has decoded the query string or translated the parameter names and values already. Therefore, the application is responsible for translating any multibyte query string parameter names or values in the case where the underlying servlet container or JSP engine does not perform the translation.
The contents of uploaded files are never translated; nor is the associated content type attribute, which is always represented using the ISO-8859-1 character encoding. However, the file name attribute of an uploaded file is translated.
Query string parameters in GET requests and query string and POST data parameters in application/x-www-form-urlencoded POST requests are never translated.
To correctly handle the translation of HTML form parameter names and values, applications must call the enableParameterTranslation( ) method for multipart/form-data POST requests, even if the servlet container or JSP engine translates parameter names and values for GET requests and application/x-www-form-urlencoded POST requests.
Do not call the enableParameterTranslation( ) method if the application contains code that handles the translation of parameter names and values.
Calling the enableParameterTranslation( ) method with a character encoding other than ISO-8859-1 affects the following methods when called for multipart/form-data POST requests:
For GET requests and application/x-www-form-urlencoded POST requests, calls to the getParameter( ), getParameterValues( ) and getParameterNames( ) methods are passed directly to the underlying servlet container or JSP engine. Please consult the servlet container or JSP engine documentation for information regarding any parameter translation functions that might be supported by the servlet container or JSP engine.
The character encoding to be used.
None.
None.
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.enableParameterTranslation("GB2312") formData.parseFormData( );
public OrdHttpUploadFile getFileParameter(String parameterName)
Returns information about an uploaded file identified by the given parameter name.
Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not you enter a valid file name into the field.
The name of the uploaded file parameter, as a String.
This method returns the uploaded file parameter, as an OrdHttpUploadFile object, or null if the parameter does not exist.
java.lang.IllegalStateException - if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); ... OrdHttpUploadFile photo = formData.getFileParameter("photo"); photo.loadImage(image); ... formData.release( );
public java.util.Enumeration getFileParameterNames( )
Returns an Enumeration of the names of all input fields of type FILE in an HTML form, or an empty Enumeration if there are no input fields of type FILE.
Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not you enter a valid file name into the field.
None.
This method returns a list of uploaded file parameter names, as an Enumeration of Strings, or an empty Enumeration if there are no input fields of type FILE.
java.lang.IllegalStateException - if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request ); formData.parseFormData( ); ... Enumeration names = formData.getFileParameterNames( );
public OrdHttpUploadFile[ ] getFileParameterValues(String parameterName)
Returns an array of OrdHttpUploadFile objects that represent all files uploaded using the specified parameter name. Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not you enter a valid file name in the field.
The name of the uploaded file parameter, as a String.
This method returns the uploaded file parameters as an array of OrdHttpUploadFile objects, or null if the parameter does not exist.
java.lang.IllegalStateException - if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request ); formData.parseFormData( ); ... OrdHttpUploadFile[ ] photo = formData.getFileParameterValues("photo")
public String getParameter(String parameterName)
Returns the value of the first query string parameter or text-based form field parameter with the specified name, or null if the parameter does not exist. The query string parameters of the request are merged with the text-based form field parameters by the parseFormData( ) method.
This method calls the getParameterName( ) method in the ServletRequest class if the request is not a multipart/form-data upload request.
The name of the parameter whose value you want to get.
This method returns the value of the specified parameter, as a String, or null if the parameter does not exist.
java.lang.IllegalStateException - if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request ); formData.parseFormData( ); ... String id = formData.getParameter("id");
public java.util.Enumeration getParameterNames( )
Returns an Enumeration of all the query string parameter names and all the text-based POST data parameter names in the request, or an empty Enumeration if there are no text-based parameters. The query string parameters of the request are merged with the text-based form field parameters by the parseFormData( ) method.
This method calls the getParameterNames( ) method in the ServletRequest class if this is not a multipart/form-data upload request.
None.
This method returns a list of text-based parameter names, as an Enumeration of String objects, or an empty Enumeration if there are no text-based parameters.
java.lang.IllegalStateException - if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request ); formData.parseFormData( ); ... Enumeration names = formData.getParameterNames( );
public String[ ] getParameterValues(String parameterName)
Returns an array of String objects containing the values of all the query string parameters and text-based POST data parameters with the specified parameter name, or null if the parameter does not exist. The query string parameters of the request are merged with the text-based form field parameters by the parseFormData( ) method.
This method calls the getParameterValues( ) method in the ServletRequest class if not a multipart/form-data upload request.
The name of the parameter.
This method returns an array of String objects containing the parameter values, or null if the parameter does not exist.
java.lang.IllegalStateException - if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); ... String[ ] ids = formData.getParameterValues("id");
public boolean isUploadRequest( )
Checks if the request was encoded using the multipart/form-data encoding format.
None.
This method returns true if the request body was encoded using the multipart/form-data encoding format; false otherwise.
java.lang.IllegalStateException - if HttpServletRequest has not been specified
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); if(formData.isUploadRequest( )){ formData.parseFormData( ); OrdHttpUploadFile uploadFile = formData.getFileParameter(...); ... } else{ String param = request.getParameter(...); ... }
public OrdHttpUploadFormData( )
Creates an OrdHttpFormData object to parse a multipart/form-data request. The application must subsequently specify the ServletRequest object with the setServletRequest( ) method.
None.
None.
None.
See setServletRequest( ) for an example of this method.
public OrdHttpUploadFormData(javax.servlet.ServletRequest request)
Creates an OrdHttpUploadFormData object using the specified ServletRequest object.
The ServletRequest object from which the multipart/form-data request will be read.
None.
None.
See getFileParameter( ) for an example of this method.
public void parseFormData( )
Parses the body of a POST request that is encoded using the multipart/form-data encoding. If the request is not an upload request, this method does nothing.
None.
None.
java.io.IOException - if an error occurs reading the request body or writing a temporary file
java.lang.IllegalStateException - if HttpServletRequest has not been specified
OrdHttpUploadException - if an error occurs parsing the multipart/form-data message
See getFileParameter( ) for an example of this method.
public void release( )
Releases all resources held by an OrdHttpUploadFormData object, including temporary files used to hold the contents of uploaded files. An application that uses temporary files must use this method.
None.
None.
None.
See getFileParameter( ) for an example of this method.
public void setMaxMemory(int maxMemory, String tempFileDir)
Specifies the maximum amount of memory that the contents of uploaded files can consume before the contents are stored in temporary files.
By default, the contents of uploaded files are held in memory until stored in a database by the application. If users upload large files, such as large video clips, then it may be desirable to limit the amount of memory consumed, and to store temporarily the contents of such files on disk, before the contents are written to a database.
Applications that use this mechanism must ensure that any temporary files are deleted when no longer required by using the release( ) method. See the release( ) method for more information.
The maximum amount of memory to be consumed by all uploaded files in a request before the contents of the uploaded files are stored in temporary files.
The directory where you will store temporary files. This parameter is optional if the java.io.tmpdir system property has been set.
None.
java.lang.IllegalArgumentException - if maxMemory is negative, or if tempFileDir was specified as null and the java.io.tmpdir system property is not present
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); try{ formData.setMaxMemory(65536,null); formData.parseFormData( ); ... OrdHttpUploadFile photo = formData.getFileParameter("photo"); photo.loadImage(image); ... } finally{ formData.release( ); }
public void setServletRequest(javax.servlet.ServletRequest request)
Specifies the ServletRequest object for the request. If you did not set the ServletRequest object in the constructor, you must set it with this method before parsing the request.
The ServletRequest object to be set.
None.
None.
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( ); ... formData.setServletRequest(request);
This section presents reference information on the methods of the OrdHttpUploadFile class.
File uploading using HTML forms encodes form data and uploaded files in POST requests using the multipart/form-data format. The OrdHttpUploadFile class is used to represent an uploaded file that has been parsed by the OrdHttpUploadFormData class (see Section 9.4 for more information on the OrdHttpUploadFormData class). The OrdHttpUploadFile class provides methods to obtain information about the uploaded file, to access the contents of the file directly, and to facilitate loading the contents into an interMedia object in a database.
Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not a user enters a valid file name into such a field. Depending on the requirements, applications can test the length of the file name, the length of the content, or both to determine if a valid file name was entered by a user and if the file was successfully uploaded by the browser. For example, if a user does not enter a file name, the length of the String returned by the getOriginalFileName( ) method will be zero. However, if a user enters an invalid file name or the name of an empty (zero-length) file, then the content length returned by the getContentLength( ) method will be zero, even though the length of the file name will not be zero.
This class extends java.lang.Object.
public int getContentLength( )
Returns the length of the uploaded media file. If you enter an invalid file name, the name of an empty file, or the name of a non-existent file, the length returned is zero.
None.
This method returns the length of the uploaded file.
None.
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); ... OrdHttpUploadFile photo = formData.getFileParameter("photo"); String mimeType = photo.getMimeType( ); int i = photo.getContentLength( ); if (i == 0){ displayUserError("The file is empty, invalid, or non-existent"); } ... photo.release( );
public java.io.InputStream getInputStream( )
Returns an InputStream object that can be used to access the contents of the uploaded file directly. Applications should close the stream with the close( ) method when finished.
None.
This method returns an InputStream object.
java.io.IOException - if an error occurs opening the temporary file
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdImage dbImage = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); OrdHttpUploadFile uploadImage = formData.getFileParameter("photo"); InputStream photoInputStream = uploadImage.getInputStream( ); try{ dbImage.loadDataFromInputStream(photoInputStream); } finally{ photoInputStream.close( ); }
public String getMimeType( )
Returns the MIME type of the file, as determined by the browser when the file is uploaded.
Some browsers return a default MIME type even if you do not supply a file name; therefore, the application should check the file name or content length to ensure the file was uploaded successfully.
None.
This method returns the MIME type of the media file as a String.
None.
See getContentLength( ) for an example of this method.
public javalang.String getOriginalFileName( )
Returns the original file name provided by the client. If no file name is provided, an empty String is returned.
None.
This method returns the file name, as a String.
None.
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); ... OrdHttpUploadFile photo = formData.getFileParameter("photo"); String originalName = photo.getOriginalFileName( ); ... formData.release( );
public String getSimpleFileName( )
Returns the simple file name (that is, the name of the file and the extension). If no file name is provided, an empty String is returned.
None.
This method returns the simple file name as a String.
None.
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); ... OrdHttpUploadFile photo = formData.getFileParameter("photo"); String name = photo.getSimpleFileName( ); ... formData.release( );
public void loadAudio(oracle.ord.im.OrdAudio audio)
Loads the media file into an OrdAudio object and sets the properties based on the audio contents. Assuming the application has already fetched an initialized OrdAudio object from the database, this method loads the contents of the audio file into the object and calls the OrdAudio.setProperties( ) method to set the audio properties. The application must then update the OrdAudio object in the database.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
This method does not use any existing format plug-in context information and does not set any comments while setting the properties.
An OrdAudio object into which the uploaded audio file will be loaded.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("soundfile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into songs (id,sound) values(?, ORDSYS.ORDAUDIO.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select sound from songs where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } OrdAudio sound = (OrdAudio)rset.getCustomDatum(1, OrdAudio.getFactory( )); uploadFile.loadAudio(sound); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update songs set sound = ? where id = ?"); stmt.setCustomDatum(1, sound); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadAudio(oracle.ord.im.OrdAudio audio, byte[ ][ ] ctx, boolean setComments)
Loads the media file into an OrdAudio object and sets the properties using an application-supplied format plug-in context. Assuming the application has already fetched an initialized OrdAudio object from the database, this method loads the contents of the audio file into the object and calls the OrdAudio.setProperties( ) method to set the audio properties. The application must then update the OrdAudio object in the database.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
The application provides the format plug-in context information and determines whether or not to set the comments in the OrdAudio object.
An OrdAudio object into which the uploaded audio file will be loaded.
The format plug-in context information.
A boolean value indicating whether or not to set the comments in the object.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("soundfile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into songs (id,sound) values(?, ORDSYS.ORDAUDIO.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select sound from songs where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } byte[ ] ctx[ ] = new byte[4000][1]; OrdAudio sound = (OrdAudio)rset.getCustomDatum(1, OrdAudio.getFactory( )); uploadFile.loadAudio(sound, ctx, true); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update songs set sound = ? where id = ?"); stmt.setCustomDatum(1, sound); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadBlob(oracle.sql.BLOB blob)
Loads the uploaded media file into a BLOB.
The BLOB into which the data will be loaded.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("docfile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into docs (id,doc_blob) values (?,EMPTY_BLOB( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select doc_blob from docs where id = ? for update" ); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } BLOB docBlob = rset.getBLOB(1); uploadFile.loadBlob(docBlob); formData.release( ); rset.close( ); stmt.close( ); conn.commit( );
public void loadDoc(oracle.ord.im.OrdDoc doc)
Loads the media file into an OrdDoc object and sets the properties based on the contents of the file. Assuming the application has already fetched an initialized OrdDoc object from the database, this method loads the contents of the file into the object and calls the OrdDoc.setProperties( ) method to set the properties. The application must then update the OrdDoc object in the database.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
This method does not use any existing format plug-in context information and does not set any comments while setting the properties.
An OrdDoc object into which the uploaded data will be loaded.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("docfile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into documents (id,doc) values(?, ORDSYS.ORDDOC.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select doc from documents where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } OrdDoc doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( )); uploadFile.loadDoc(doc); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update documents set doc = ? where id = ?"); stmt.setCustomDatum(1, doc); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadDoc(oracle.ord.im.OrdDoc doc, byte[ ][ ] ctx, boolean setComments)
Loads the media file into an OrdDoc object and sets the properties using an application-supplied format plug-in context. Assuming the application has already fetched an initialized OrdDoc object from the database, this method loads the contents of the file into the object and calls the OrdDoc.setProperties( ) method to set the properties. The application must then update the OrdDoc object in the database.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
The application provides the format plug-in context information and determines whether or not to set the comments in the OrdDoc object.
An OrdDoc object into which the uploaded file will be loaded.
The format plug-in context information.
A boolean value indicating whether or not to set the comments in the object.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("docfile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into documents (id,doc) values(?, ORDSYS.ORDDOC.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select doc from documents where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } byte[ ] ctx[ ] = new byte[4000][1]; OrdDoc doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( )); uploadFile.loadDoc(doc, ctx, true); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update documents set doc = ? where id = ?"); stmt.setCustomDatum(1, doc); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadImage(oracle.ord.im.OrdImage image)
Loads the media file into an OrdImage object and sets the properties based on the image contents. Assuming the application has already fetched an initialized OrdImage object from the database, this method loads the contents of the image file into the object and calls the OrdImage.setProperties( ) method to set the image properties. The application must then update the OrdImage object in the database.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
An OrdImage object into which the uploaded image file will be loaded.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("photofile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into photos (id,photo) values(?, ORDSYS.ORDIMAGE.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select image from photos where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } OrdImage photo = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); uploadFile.loadImage(photo); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update photos set photo = ? where id = ?"); stmt.setCustomDatum(1, photo); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadImage(oracle.ord.im.OrdImage image, String cmd)
Loads the media file into an OrdImage object and sets the properties based on the contents of the given String. Assuming the application has already fetched an initialized OrdImage object from the database, this method loads the contents of the image file into the object and calls the OrdImage.setProperties( ) method to set the image properties. The application must then update the OrdImage object in the database.
An OrdImage object into which the uploaded image file will be loaded.
A String that specifies the properties to be set.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("photofile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into photos (id,photo) values(?, ORDSYS.ORDIMAGE.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select photo from photos where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } OrdImage photo = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( )); String cmd = getImagePropertiesCommand(photo); uploadFile.loadImage(photo, cmd); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update photos set photo = ? where id = ?"); stmt.setCustomDatum(1, photo); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadVideo(oracle.ord.im.OrdVideo video)
Loads the media file into an OrdVideo object and sets the properties based on the video contents. Assuming the application has already fetched an initialized OrdVideo object from the database, this method loads the contents of the video file into the object and calls the OrdVideo.setProperties( ) method to set the video properties. The application must then update the OrdVideo object in the database.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
This method does not use any existing format plug-in context information and does not set any comments while setting the properties.
An OrdVideo object into which the uploaded video file will be loaded.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("videofile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into movies (id,video) values(?, ORDSYS.ORDVIDEO.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select video from movies where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } OrdVideo video = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( )); uploadFile.loadVideo(video); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update movies set video = ? where id = ?"); stmt.setCustomDatum(1, video); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void loadVideo(oracle.ord.im.OrdVideo video, byte[ ][ ] ctx, boolean setComments)
Loads the media file into an OrdVideo object and sets the properties using an application-supplied format plug-in context. Assuming the application has already fetched an initialized OrdVideo object from the database, this method loads the contents of the video file into the object and calls the OrdVideo.setProperties( ) method to set the video properties. The application must then update the database OrdVideo object.
If the call to the setProperties( ) method fails, this method sets the following properties automatically:
The application provides the format plug-in context information and determines whether or not to set the comments in the OrdVideo object.
An OrdVideo object into which the uploaded video file will be loaded.
The format plug-in context information.
A boolean value indicating whether or not to set the comments in the object.
None.
java.io.IOException - if an error occurs opening the temporary file
java.sql.SQLException - if an unrecognized error occurs while storing the media data
java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released
OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request); formData.parseFormData( ); String id = formData.getParameter("id"); OrdHttpUploadFile uploadFile = formData.getFileParameter("videofile"); OraclePreparedStatement stmt = (OraclePreparedStatement) conn.prepareStatement("insert into movies (id,video) values(?, ORDSYS.ORDVIDEO.INIT( ))"); stmt.setString(1, id); stmt.executeUpdate( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("select video from movies where id = ? for update"); stmt.setString(1, id); OracleResultSet rset = (OracleResultSet)stmt.executeQuery( ); if (!rset.next( )){ throw new ServletException("new row not found in table"); } byte[ ] ctx[ ] = new byte[4000][1]; OrdVideo video = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( )); uploadFile.loadVideo(video, ctx, true); formData.release( ); rset.close( ); stmt.close( ); stmt = (OraclePreparedStatement)conn.prepareStatement("update movies set video = ? where id = ?"); stmt.setCustomDatum(1, video); stmt.setString(2, id); stmt.execute( ); stmt.close( ); conn.commit( );
public void release( )
Releases all resources held by an OrdHttpUploadFile object. Specifically, this method releases the memory used to hold the contents of an uploaded file or deletes the temporary file used to hold the contents of the uploaded file. An application can optimize memory usage by calling this method to release any allocated memory, making it a candidate for garbage collection, after the application has finished processing an uploaded file.
None.
None.
None.
See getContentLength( ) for an example of this method.
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|