next
 
Multimedia and Geospatial Data

By Joseph Mauro

Work with rich data in J2EE applications using Oracle9i Database, Oracle9iAS, and interMedia.

With colorful animations and maps springing to life nowadays on everything from ATM machines to automobiles, it's clear that applications that can take advantage of multimedia and geospatial data are increasingly in demand. Application developers eager to gain a foothold in the use of this type of rich visual data face several technical hurdles. These include how to get large media objects from data stores; how to process, render, and visualize such data; and how to make the solutions portable and scalable. The Java 2 Platform, Enterprise Edition (J2EE), offers several application server technologies that simplify the development and deployment of this kind of application. These technologies include Java Classes for Servlets and JavaServer Pages (JSP), JSP Tag Libraries, JSP Data Tag Libraries for Java integrated development environments (IDEs), Image Adaptation Servlets based on Sun's Java Advanced Imaging (JAI) API, Map Visualization Servlets, and Java Database Connectivity (JDBC) to media and geospatial content. All of these J2EE technologies and components are available in Oracle9i Application Server (Oracle9iAS), Oracle Database, and development tools.

Challenges of Multimedia and Spatial Data

The first challenge middle-tier logic faces is how to address and get such data, associated metadata, and related business information from content stores such as databases. This problem is compounded by the fact that the associated business information and the media are often stored separately, meaning applications must have specialized code that understands the relationship between the media and the affiliated business information and the different techniques for accessing them.

Another problem is that of accessing a specific metadata format. This data is often bound up in the media interchange format. With a bewildering array of media formats such as BMP, JPG, WAV, and MPG, applications are faced with the task of knowing how to parse each to extract the metadata they need. As the number and type of formats grow, so do the problems the application faces. In addition to getting raw data from the content store, the application faces the problem of knowing how to manipulate such data. Handling each of the formats separately is not a viable solution. Instead, the content must be typed and bound to middle-tier objects that understand the semantics of the data.

Since multimedia and spatial datatypes are visual in nature, the application is also faced with rendering the data. Rendering is the process of preparing or formatting the data for display purposes. Rendering is almost always required, because the size, color depth, and resolution of the data rarely match the characteristics of the output display device. And although rendering multimedia can be challenging, it is somewhat more straightforward than rendering spatial data.

Much multimedia data consists of raster graphics images, or bitmaps, which are data files or structures made up of a generally rectangular array of pixels, or points of color. Spatial data is mainly made up of vector graphics that use computational geometry to represent shapes and images and visualize them on a computer monitor and other output devices. Whether the images are raster- or vector-based, the rendering problem is a particular challenge in the emerging wireless space, with its various device-specific formats, sizes, and resolutions.

Oracle interMedia

In the past, rich media was stored in flat files, because traditional databases were not equipped to easily deal with these more-complex datatypes. Databases have evolved to handle complex data, and Oracle9i meets these new rich media and Java language requirements via Oracle interMedia, an array of services for developing and deploying traditional, Web, and wireless applications that include rich media.

Through the use of media datatypes, Oracle interMedia adds support that enables Oracle9i to manage and deliver image, audio, video, and geographical location data in an integrated fashion with other enterprise information. interMedia provides the means for adding audio, image, and video columns or objects to existing database tables, inserting and retrieving multimedia data, performing image processing on a number of popular image formats, and doing limited conversion between image formats. interMedia does this by storing media metadata in the database under Oracle interMedia control. Whether media data is stored within or outside the database, interMedia manages metadata for all the media types and can automatically extract it for audio, image, and video. interMedia makes use of object types, which are similar to Java or C++ classes, to describe multimedia data. The OrdAudio, OrdImage, and OrdVideo object types have attributes and methods associated with them and can carry Multipurpose Internet Mail Extensions (MIME)-type information (such as text, images, audio, video, and other application-specific data), making them invaluable in downstream processing and rendering.

JDBC Data Access

In supporting multimedia and geospatial content, the JDBC standard for communication between a Java application and a relational database goes beyond simply providing connectivity to the database. JDBC is able to support the return of result sets that contain media and spatial data along with metadata and traditional relational business data. JDBC also has the ability to bind these datatypes to specialized middle-tier Java classes, since it is these classes that must contain much of the media-specific logic for rendering.

Oracle interMedia provides a set of Java classes (OrdImage, OrdAudio, OrdVideo) that allow applications to access and manipulate multimedia data stored in an Oracle9i database. These Java classes allow JDBC result sets to include both traditional relational data and interMedia objects so that applications can easily select and operate on a result set containing interMedia columns and other relational data. Through the use of interMedia Java classes, applications can access object attributes and invoke object methods. After a connection to the database is established, the application can query a table and get a result set of one or more rows that have media columns. Here is some code to show how to establish a JDBC connection:


public class ImageDemo
{
private String connectString =
"jdbc:oracle:oci8:@";
private String username = "scott";
private String password = "tiger";
private Connection conn = null;
...
private void getConnection() throws
SQLException
{
DriverManager.registerDriver(
new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(
connectString,username,password);
}

The following code begins by querying the database and getting a result set back. The call to the getCustomDatum method retrieves the OrdImage database object from the result set and loads it into the OrdImage Java object for processing by the application.


OracleResultSet rs = (OracleResultSet)stmt1
.executeQuery("SELECT image1
FROM imgdemo
WHERE id = 1 FOR UPDATE");
if (rs.next())
{
OrdImage imageObj = (OrdImage)rs
.getCustomDatum(1, OrdImage.getFactory());

 	

Upload and Download

The flexibility of the J2EE platform gives you several options when developing J2EE media applications. For those who wish to develop in Java, Java Classes for Servlets and JSP provide media upload and retrieval support. For those wanting to develop in HTML using JSP, there are JSP Data Tag Libraries designed for specific IDEs, generic JSP Tag Libraries, and Java Classes for Servlets and JSP that offer a number of alternatives requiring differing levels of customization and coding.

Java Classes for Servlets and JSP. Oracle interMedia includes a Java component, called the Oracle interMedia Java Classes for Java Servlets and JavaServer Pages, that facilitates the uploading and retrieval of multimedia data in a Web-based environment.

The OrdHttpResponseHandler class facilitates the retrieval of media 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 JSP.

The following example shows how to use the OrdHttpResponseHandler class to retrieve an image object from a database and deliver it to a browser:


OraclePreparedStatement stmt = (OraclePreparedStatement)
conn.prepareStatement("select media from photos where id = ?");
stmt.setString(1,
request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)
stmt.executeQuery( );
if (rset.next( ))
{
OrdImage media = (OrdImage)rset
.getCustomDatum(1, OrdImage.getFactory( ));
OrdHttpResponseHandler handler = new OrdHttpResponseHandler (request, response);
handler.sendImage(media);
return;
}
else{
response.setStatus(
response.SC_NOT_FOUND);
}

Similarly, audio clip objects can be retrieved and sent to a browser by using the OrdAudio.getFactory and the sendAudio methods, and video clip objects can be retrieved and sent to a browser by using the OrdVideo.getFactory and the sendVideo methods. Related methods exist for getting and sending image, audio, and video data to the browser from database BLOBs and BFILEs (operating system files).

The OrdHttpJspResponseHandler class facilitates the retrieval of media data from an Oracle database and its delivery to a browser or another HTTP client from a JSP. Listing 1 shows the use of the OrdHttpJspResponseHandler within a JSP.

The same code can handle audio or video by substituting the sendAudio method or the sendVideo method for the sendImage method. Likewise, methods exist to deliver media content from BLOBs and BFILEs.

Uploading a file using an HTML form is done by encoding both the form data and the uploaded file in a POST request, using a specific 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 a JSP. 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 similar methods, namely getFileParameter( ), getFileParameterValues( ), and getFileParameterNames( ). The OrdHttpUploadFile objects returned by the getFileParameter( ) and getFileParameterValues( ) methods provide access to the MIME type, length, and contents of each uploaded file.

Listing 2 shows how to use the OrdHttpUploadFormData class. Again, similar methods exist for both audio and video.

JSP Tag Libraries. The purpose of the JSP Tag Library is to simplify the creation of JSP Web applications that support the upload and retrieval of multimedia data stored using the interMedia object types. These tags greatly simplify the process of writing multimedia JSP Web applications. Application developers no longer have to write code to construct multimedia HTML tags or write runtime components that deliver the multimedia data. Access to data in HTML file upload forms is also greatly simplified.

To illustrate how the interMedia tag library works, the following code extract illustrates the generation of an HTML <IMG> tag. The code is entirely Java, rather than HTML, with expression elements to obtain the height and width attributes. This allows it to handle the situation where the image's height and width attributes are not known.


<%
out.print(
"<IMG SRC=\"PhotoAlbumMediaViewer.jsp" +
"?media=image&id=" +
album.getId() + "\"" );
if ( album.getImage().getHeight() > 0
&& album.getImage().getWidth() > 0 )
{
out.print( "height=\"" +
album.getImage().getHeight() + "\"" );
out.print( "width=\"" +
album.getImage().getWidth() + "\"" );
}
out.print( "BORDER=\"1\">" );
%>

Using the interMedia tag library, this portion of the JSP page would look like the following:


<ord:embedImage connCache = album.getConnectionCache()
table = "PHOTOS" column = "IMAGE"
key = "<%= album.getId() %>"
image = "<%= album.getImage() %>" border="1" />

JSP Data Tag Libraries for IDEs. Because hand-coding servlets or JSP can be tedious and error-prone, many developers are turning to the use of IDEs. Oracle9i JDeveloper is a visual component-based J2EE development environment tightly integrated with Oracle9i Database and Oracle9iAS. With Oracle9i JDeveloper, it is easy to create thick and thin Java clients, servlets, JSP, EJB, and Java Beans.

A distinguishing feature of JDeveloper is Oracle Business Components for Java (BC4J), an application component framework that gives developers a set of intelligent software building blocks to manage common facilities.

The BC4J framework automatically recognizes the interMedia object types and integrates seamlessly with interMedia at different levels, thus providing developers great flexibility in creating new applications. For example, developers can choose to create JSP applications with prepackaged database manipulation components using the Business Components JSP Application Wizard. To create more-customized JSP applications, developers can use the BC4J JSP Data Tag Library.

The Business Components JSP Application Wizard allows users to generate, without programming, a JSP application that is capable of querying, inserting, updating, and deleting data from the database. The wizard automatically integrates interMedia data objects with standard relational data using BC4J JSP Data Tags for data accessing and content rendering. Users of the JSP application are able to view, insert, update, and delete multimedia content just like other textual data. Developers can debug or run the JSP application from inside JDeveloper. When the development work is done, the developers can deploy the JSP application to an application server in the form of a Web Archive (WAR) or Enterprise Archive (EAR) file from JDeveloper.

Developers can use the BC4J Data Tag Library to create JSP applications with highly customized user interfaces and application-specific database access functionality. The BC4J Data Tag library includes a set of BC4J interMedia Data Tags that make it easier to write JSP code to upload, retrieve, or render media—for example, uploading a video clip to the database or displaying an image taken from a database table. The BC4J Data Tag Library allows developers to create database-bound, multimedia-intensive JSP applications with little effort. BC4J has the following tags:

  • AnchorMedia. Inserts an HTML Anchor tag for an interMedia object to a page
  • EmbedAudio. Inserts an HTML OBJECT tag for an interMedia ORDAudio object to a page
  • EmbedImage. Inserts an HTML IMAGE tag for an interMedia ORDImage object to a page
  • EmbedVideo. Inserts an HTML OBJECT tag for an interMedia ORDVideo object to a page
  • FileUploadForm. Inserts an HTML FORM tag for file upload
  • MediaURL. Inserts a URL string for an interMedia object to a page

Each tag takes a list of parameters, so for example, here's how you would use EmbedImage in a JSP application, and the resulting output:


<jbo:EmbedImage
datasource="datasourceInstanceName"
mediaattr="mediaAttributeName"
[[ rowkey="rowKeyString" ] |
[ whereclause="whereClause" ]]
[ retrievepath="customRetrievePath" ]
[ width="imageWidth" ]
[ height="imageHeight" ]
[ border="borderPixel" ]
[ align="alignOption" ]
[[ alt="alternateText" ] |
[ altattr="alternateAttributeName" ]]
[ longdesc="longDescription" ]
/>

Example 1:


<jbo:EmbedImage datasource="ds"
mediaattr="Pic" whereclause="id = 2" alt="family reunion picture" />
 
next
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy