<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Snowbound Software Imaging Technology Blog &#187; Java</title>
	<atom:link href="http://blog.snowbound.com/category/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.snowbound.com</link>
	<description>Accelerating the Document Revolution</description>
	<lastBuildDate>Thu, 26 Aug 2010 14:39:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>JDBC Content Handler for VirtualViewer</title>
		<link>http://blog.snowbound.com/9/jdbc-content-handler-for-virtualviewer/</link>
		<comments>http://blog.snowbound.com/9/jdbc-content-handler-for-virtualviewer/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 20:39:27 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Content Handler]]></category>
		<category><![CDATA[Imaging Technology]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.snowbound.com/?p=9</guid>
		<description><![CDATA[One way the VirtualViewer Java servlet can be extended is by customizing the content handler on the backend of the servlet, allowing for tighter integration into content repositories or databases. PostgreSQL is an object-relational database management system licensed under the BSD license which has a strong industry backing and a number of different APIs including [...]]]></description>
			<content:encoded><![CDATA[<p>One way the VirtualViewer Java servlet can be extended is by customizing the content handler on the backend of the servlet, allowing for tighter integration into content repositories or databases. PostgreSQL is an object-relational database management system licensed under the BSD license which has a strong industry backing and a number of different APIs including C/C++, Perl, Python, PHP, and JDBC which allow for database transactions to be written in your language of choice.</p>
<p>For this setup, I used PostgreSQL v8.3.0 with the JDBC3 PostgreSQL Driver v8.3-603 and ran the VV servlet under Apache Tomcat v6.06. Instructions for installing PostgreSQL with vary depending upon your platform of choice, but there are plenty of setup guides to be found&#8211; I personally find it easer to setup and interact with databases up under Linux Since the content handler will later be built against the JDBC PostgreSQL driver, I found it helpful to build this from source for debugging.</p>
<p>The default content handler shipped with VirtualViewer can be easily extended to save binary data into a PostgreSQL database using the saveFileBytes() and getFileBytes() methods. By default, this is where the file I/O occurs for all documents and metadata in the content handler. Instead of going to disk, we use JDBC calls to access a table in our database and retrieve the appropriate content.</p>
<p><strong>Step 0:</strong> Get PostgreSQL or your DB of choice installed and all that good stuff.</p>
<p><strong>Step 1:</strong> Create new table in the database to hold our documents and metadata. I choose to associate both with the bytea data type, so I created a table like so:</p>
<p style="padding-left: 30px;">CREATE TABLE images (imgname text, img bytea);</p>
<p><strong>Step 2:</strong> Create custom content handler. I created an insertViaJDBC() method to be called from saveFileBytes() which took in a file name and byte[] array to be inserted into the database:</p>
<p style="padding-left: 30px;">DataInputStream dis = new DataInputStream(<br />
new ByteArrayInputStream( filebytes ));<br />
PreparedStatement ps =<br />
conn.prepareStatement(&#8220;INSERT INTO images VALUES (?, ?)&#8221;);<br />
ps.setString(1, filename);<br />
ps.setBinaryStream(2, dis, filebytes.length);<br />
ps.executeUpdate();</p>
<p>Likewise, I created a fetchViaJDBC() method to be called from getFileBytes() which took in a file</p>
<p style="padding-left: 30px;">PreparedStatement ps =<br />
conn.prepareStatement(&#8220;SELECT img FROM images WHERE imgname=?&#8221;);<br />
ps.setString(1, filename);<br />
ResultSet rs = ps.executeQuery();<br />
if ( rs != null ) {<br />
while( rs.next() )<br />
filebytes = rs.getBytes(1);<br />
rs.close();<br />
}</p>
<p>This all standard JDBC code adapted from the manual pages. PostgreSQL can store binary data in two ways, with either the binary bytea data type or the large object feature. I did not implement the large object feature, but depending upon your document imaging needs, you should choose accordingly.</p>
<p><strong>Step 3:</strong> Modify the servlet web.xml to point to your content handler. This is the only change to the web.xml you must make, but I also added in parameters for the database such as username, password and hostname. These parameters can then be referenced via your content handler and used in your JDBC methods. In my case, I grabbed these parameters in my content handler init() method. I also removed parameters for filePath and overPath from the web.xml since my content handler isn&#8217;t going to disk anymore for documents.</p>
<p>If you&#8217;ve implemented the content handler this far, you&#8217;ll noticed you&#8217;ve got a few problems wit annotations when you try and use it. This is because you&#8217;ll need to devise an alternative method for handling annotation layer names that doesn&#8217;t depend on file I/O. It&#8217;s fairly straightforward, basically just moving from files to String when you’re dealing with document paths. I ended up changing the method signature on both getFileBytes() and saveFileBytes() to accept a String for a file name instead of a File object&#8211; this also made for handling JDBC calls a little more logical.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.snowbound.com/9/jdbc-content-handler-for-virtualviewer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Popular Java Imaging Technology Posts from Imaging Experts</title>
		<link>http://blog.snowbound.com/8/java-imaging-technology-posts-from-imaging-experts/</link>
		<comments>http://blog.snowbound.com/8/java-imaging-technology-posts-from-imaging-experts/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 19:58:59 +0000</pubDate>
		<dc:creator>Snowbound Software</dc:creator>
				<category><![CDATA[Imaging Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://blog.snowbound.com/?p=8</guid>
		<description><![CDATA[As we work to fully integrate our blog posts and discussions on document and web imaging technology to our new Snowbound Blog, here are a select group of popular posts from Imaging Experts, which our readers may find of value. JavaScripting in Applets &#8211; Getting Out of the SandboxA discovery with regards to using JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>As we work to fully integrate our blog posts and discussions on document and web imaging technology to our new Snowbound Blog, here are a select group of popular posts from Imaging Experts, which our readers may find of value.</p>
<ul>
<li><a href="http://imagingexperts.typepad.com/imaging_experts/2006/10/javascripting_i.html" rel="nofollow" >JavaScripting in Applets &#8211; Getting Out of the Sandbox</a><br/>A discovery with regards to using JavaScript with Applets, and trying to avoid running into security problems.  There is a way to break out of the sandbox, via signing. Here is an example&#8230;</li>
<li><a href="http://imagingexperts.typepad.com/imaging_experts/2006/12/another_neat_tr.html" rel="nofollow" >Another Neat Trick with the Ant</a><br/>Even though the Ant has plenty of available tasks out of the box and a wealth of 3rd party tasks already defined, you still may wish to improve your build process by creating your own custom tasks.</li>
<li><a href="http://imagingexperts.typepad.com/imaging_experts/2006/02/using_awt_depen.html" rel="nofollow" >Using AWT Dependent Imaging Routines in SWT</a><br/>If you had code that relied heavily on its interaction with the AWT-based Java2D drawing routines, how could you port that over to a new SWT-based program?  This post illustrates one method for doing so.</li>
<li><a href="http://imagingexperts.typepad.com/imaging_experts/2006/09/serialization_a.html" rel="nofollow" >Serialization: Avoiding a NotSerializableException with the Transient Keyword</a><br/>When you are writing client-server software with Java, it&#8217;s often convenient to pass Java objects from the client to the server. Java Serialization allows classes to be converted to a string format, allowing for easy network transmission</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.snowbound.com/8/java-imaging-technology-posts-from-imaging-experts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
