<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"
>

<channel>
	<title>acidum.de</title>
	<atom:link href="http://www.acidum.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acidum.de</link>
	<description></description>
	<lastBuildDate>Sun, 08 Nov 2009 20:12:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PowerPoint template for BPMN</title>
		<link>http://www.acidum.de/2009/10/27/powerpoint-template-for-bpmn/</link>
		<comments>http://www.acidum.de/2009/10/27/powerpoint-template-for-bpmn/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 21:56:12 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[BPMN]]></category>
		<category><![CDATA[Business Process]]></category>
		<category><![CDATA[Modeling]]></category>
		<category><![CDATA[PowerPoint]]></category>
		<category><![CDATA[Template]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=236</guid>
		<description><![CDATA[Have you ever faced the challenge to model a company process? Of course you want to be the shining star and use the newest modeling notation. The Business Process Modeling Notation (BPMN) is such notation and standardized by OMG.
Additionally you want to start right now. Therefore you are not able to wait until your boss [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever faced the challenge to model a company process? Of course you want to be the shining star and use the newest modeling notation. The <a title="BPMN.org" href="http://www.bpmn.org/" target="_blank">Business Process Modeling Notation (BPMN)</a> is such notation and standardized by <a title="OMG.org" href="http://www.omg.org/" target="_blank">OMG</a>.</p>
<p>Additionally you want to start right now. Therefore you are not able to wait until your boss gives the approval for any cool BPMN app out there. For the time being you could start with your existing MS Office installation base. Either you are going to use the <a title="BPMN Visio Stencils" href="http://bpt.hpi.uni-potsdam.de/Public/BPMNCorner#Tooling">Visio Stencils</a> or start modeling your processes via Powerpoint. How knows maybe your boss likes the first drafts and introduces a cool BPMN tool afterwards.</p>
<p>For Powerpoint I created a template that contains the most useful BPMN elements. Following you will find the templates:</p>
<ul>
<li><a href="http://www.acidum.de/wp-content/uploads/2009/10/bpmn.pptx">BPMN v.1.2 Powerpoint Template (PPTX)</a></li>
<li><a href="http://www.acidum.de/wp-content/uploads/2009/10/bpmn.ppt">BPMN v.1.2 Powerpoint Template (PPT)</a></li>
</ul>
<p>Further information about BPMN is available at:</p>
<ul>
<li><a title="BPMN community" href="http://www.bpmn-community.org/" target="_blank">http://www.bpmn-community.org/</a></li>
<li><a title="BPMN Visio stencil, BPMN Poster" href="http://bpt.hpi.uni-potsdam.de/Public/BPMNCorner" target="_blank">Viso Stencils, BPMN Poster and BPMN book</a></li>
</ul>
<p>Any feedback is welcome&#8230;</p>
<p><strong>Update</strong>: Thanks to Oliver, I added a few upgrades. At first of all the first version was missing a message flow and a pool. You will find both implemented in the current version. Additionally, some annoying design issues were solved. So have fun with the update.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2009/10/27/powerpoint-template-for-bpmn/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Deploy a Grails Application into Glassfish</title>
		<link>http://www.acidum.de/2009/04/16/deploy-a-grails-application-into-glassfish/</link>
		<comments>http://www.acidum.de/2009/04/16/deploy-a-grails-application-into-glassfish/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 15:34:04 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Code Examples]]></category>
		<category><![CDATA[Glassfish]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=220</guid>
		<description><![CDATA[In most cases a Grails application uses a database to store its content. Fortunately Grails is tightly coupled with GORM to ease the use. Since Grails distinguish between different deployment environments, it uses a special configuration for development and production. Therefore you have to think of a database in production environment while you don not [...]]]></description>
			<content:encoded><![CDATA[<p>In most cases a <a title="Grails Site" href="http://www.grails.org/" target="_blank">Grails</a> application uses a database to store its content. Fortunately Grails is tightly coupled with GORM to ease the use. Since Grails distinguish between different deployment environments, it uses a special configuration for development and production. Therefore you have to think of a database in production environment while you don not in development stage.</p>
<p><a title="Glassfish Site" href="http://www.glassfish.org/" target="_blank">Glassfish</a> v2 and v3 Prelude comes with an internal database JavaDB (based on the Apache Derby) that could be used for first tests. It would be great to use the default database by default for deployments for Glassfish via JNDI. This article shows how to use the bundled database with an Grails application.</p>
<p>In preparation for the next steps you have to install <a title="Grails Installation" href="http://www.grails.org/Installation" target="_blank">Grails 1.1</a> and <a title="Glassfish v2 Installation Instructions" href="https://glassfish.dev.java.net/downloads/v2.1-b60e.html">Glassfish v2</a> or <a title="Glassfish v3 Prelude Installation Instructions" href="http://docs.sun.com/app/docs/doc/820-5968/ggssq?a=view">Glassfish v3 Prelude.</a></p>
<p>To create the demo app just run the following at command line:<br />
<code><br />
grails create-app glassfishapp<br />
cd glassfishapp<br />
grails create-domain-class Bookmark<br />
grails create-controller Bookmark<br />
</code></p>
<p>As the next step edit the domain class and the controller. E.g. open Eclipse with installed <a title="Eclipse Groovy Plugin" href="http://groovy.codehaus.org/Eclipse+Plugin" target="_blank">Groovy plugin.</a></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BookmarkController <span style="color: #009900;">&#123;</span>
    def scaffold <span style="color: #339933;">=</span> Bookmark
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Bookmark <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> constraints <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003399;">String</span> url
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now you are ready to test your app with</p>
<p><code><br />
grails run-app<br />
</code></p>
<p>To prepare the Grails application for Glassfish the data source for the production environment has to be changed. Open the <em>DataSource.groovy</em> and change</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">production <span style="color: #009900;">&#123;</span>
	dataSource <span style="color: #009900;">&#123;</span>
		dbCreate <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update&quot;</span>
		url <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:hsqldb:file:prodDb;shutdown=true&quot;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">production <span style="color: #009900;">&#123;</span>
	dataSource <span style="color: #009900;">&#123;</span>
		dbCreate <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update&quot;</span>
		<span style="color: #666666; font-style: italic;">// do not use java:/jdbc as documented</span>
		jndiName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc/__default&quot;</span>
		username <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;APP&quot;</span>
		password <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;APP&quot;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Do not use <code>jndiName = "java:jdbc/__default"</code> as <a href="http://www.grails.org/doc/1.1/guide/3.%20Configuration.html">documented</a>. Be aware that it may be dangerous to use <code>dbCreate= "update"</code> in production environments.</p>
<p>Now compile the web archive with </p>
<p><code>grails war</code></p>
<p>Start your database and the application server<br />
<code>./asadmin start-database<br />
./asadmin start-domain</code></p>
<p>Finally open the sun web interface at http://localhost:4848/ to deploy the war file</p>
<p><code>http://localhost:8080/glassfishapp-0.1/</code></p>
<p>I experienced some memory problems by using Grails with Glassfish. To fix that problem I added <code>-XX:MaxPermSize=256m</code> and <code>-Xmx1024m</code> as JVM option. JVM options can be changed via the web interface (Common Tasks -> Application Server -> JVM Settings -> JVM Options)</p>
<div id="attachment_225" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.acidum.de/wp-content/uploads/2009/04/grails_glassfish.png" rel="lightbox"><img class="size-thumbnail wp-image-225" title="Grails running in Glassfish" src="http://www.acidum.de/wp-content/uploads/2009/04/grails_glassfish-150x150.png" alt="Grails running in Glassfish" width="150" height="150" /></a><p class="wp-caption-text">Grails running in Glassfish</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2009/04/16/deploy-a-grails-application-into-glassfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Index Microsoft Office Files with Lucene</title>
		<link>http://www.acidum.de/2009/01/07/index-microsoft-office-files-with-lucene/</link>
		<comments>http://www.acidum.de/2009/01/07/index-microsoft-office-files-with-lucene/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 10:34:29 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[Search Engine]]></category>
		<category><![CDATA[Tika]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=178</guid>
		<description><![CDATA[Within my current research project I faced the challenge to index a whole bunch of files. To be platform independent the Java programming language was the first choice. Then I came along the Lucene project. 
 Lucene is an open-source project that &#8220;provides Java-based indexing and search technology&#8221;. I have to mention that Lucene is [...]]]></description>
			<content:encoded><![CDATA[<p>Within my current research project I faced the challenge to index a whole bunch of files. To be platform independent the Java programming language was the first choice. Then I came along the <a href="http://lucene.apache.org/">Lucene</a> project. </p>
<p> Lucene is an open-source project that &#8220;provides Java-based indexing and search technology&#8221;. I have to mention that Lucene is a framework library instead of an out-of-the-box application. If you think of indexing your files, you may have Microsoft Office files, Adobe pfds or OpenOffice documents in mind. None of these file format can be indexed by Lucene with the standard configuration. But Lucene provides a great API to do parsing of files by other code. </p>
<p>I looked at two projects:</p>
<ul>
<li><a href="http://lucene.apache.org/tika/">Tika</a></li>
<li><a href="http://aperture.sourceforge.net/">Aperture</a></li>
</ul>
<p>While Tika is not available as a binary download Aperture is. I decided for Tika due to Maven support and clean source code. Aperture comes along a whole bunch of dependencies which make it quite complex to figure out what is really required. Although Tika is only available via source code I&#8217;ve done the Lucene Tika integration within an half hour.</p>
<p>Just download the Tika source code via<br />
<code>svn checkout http://svn.apache.org/repos/asf/lucene/tika/trunk tika</code> and use maven to install the binary into your local maven repository. </p>
<p>The following part do the core binding between Tika and Lucene. It asks our own written ContentParser which returns a Lucene <a href="http://lucene.apache.org/java/2_4_0/api/core/org/apache/lucene/document/Document.html">Document</a>. </p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Indexing &quot;</span> <span style="color: #339933;">+</span> file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// parse the document</span>
	<span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span>contentParserAccess<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		doc <span style="color: #339933;">=</span> contentParser.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// put it into Lucene</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>doc <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		writer.<span style="color: #006633;">addDocument</span><span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cannot handle &quot;</span>
				<span style="color: #339933;">+</span> file.<span style="color: #006633;">getAbsolutePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; skipping&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cannot index &quot;</span> <span style="color: #339933;">+</span> file.<span style="color: #006633;">getAbsolutePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; skipping (&quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The ContentParser calls the TikaParser for each file and put the metadata it returns into a Lucene document. The most difficult part is determine the Mime-Type. Unfortunately Tike does not use it by default. Therefore we have to call the suitable method MimeTypes repo = config.getMimeRepository() and repo.getMimeType(bufIn). Afterward we have to reset the stream to the start. Otherwise Tika could not retrieve the data properly. </p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.acidum.indexer.tika.parser</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> ...
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
*
* This class the is the bridge between Lucene and Tika. It uses Tika to
* retrieve the file content and metadata and generates a Lucene document.
*
* @author Christoph Hartmann
*
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TikaDocumentParser <span style="color: #000000; font-weight: bold;">implements</span> ContentParser <span style="color: #009900;">&#123;</span>
&nbsp;
Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
AutoDetectParser autoDetectParser<span style="color: #339933;">;</span>
TikaConfig config<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> TikaDocumentParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// load tika config to replace the image parser with our own</span>
		<span style="color: #003399;">InputStream</span> is <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tika-config.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TikaConfig<span style="color: #009900;">&#40;</span>is<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// use tika's auto detect parser</span>
		autoDetectParser <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AutoDetectParser<span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Document</span> getDocument<span style="color: #009900;">&#40;</span><span style="color: #003399;">InputStream</span> input, MimeType mimeType<span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">throws</span> ContentParserException <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		Metadata metadata <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Metadata<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mimeType <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			metadata.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>Metadata.<span style="color: #006633;">CONTENT_TYPE</span>, mimeType.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003399;">ContentHandler</span> handler <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BodyContentHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			autoDetectParser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>input, handler, metadata<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ContentParserException<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		doc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Document</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// add the content to lucene index document</span>
		doc.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Field</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;body&quot;</span>, handler.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #003399;">Field</span>.<span style="color: #006633;">Store</span>.<span style="color: #006633;">NO</span>,
				<span style="color: #003399;">Field</span>.<span style="color: #006633;">Index</span>.<span style="color: #006633;">ANALYZED</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// add meta data</span>
		<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> names <span style="color: #339933;">=</span> metadata.<span style="color: #006633;">names</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name <span style="color: #339933;">:</span> names<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">String</span> value <span style="color: #339933;">=</span> metadata.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			doc.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Field</span><span style="color: #009900;">&#40;</span>name, value, <span style="color: #003399;">Field</span>.<span style="color: #006633;">Store</span>.<span style="color: #006633;">YES</span>,
					<span style="color: #003399;">Field</span>.<span style="color: #006633;">Index</span>.<span style="color: #006633;">ANALYZED</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			input.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ContentParserException<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> doc<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Document</span> getDocument<span style="color: #009900;">&#40;</span><span style="color: #003399;">File</span> file<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ContentParserException <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003399;">InputStream</span> input<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>input <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>
					.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not open stream from specified resource: &quot;</span>
							<span style="color: #339933;">+</span> file.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> getDocument<span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// add the file name to the meta data</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>doc <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				doc.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Field</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;filename&quot;</span>, file.<span style="color: #006633;">getCanonicalPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
						<span style="color: #003399;">Field</span>.<span style="color: #006633;">Store</span>.<span style="color: #006633;">YES</span>, <span style="color: #003399;">Field</span>.<span style="color: #006633;">Index</span>.<span style="color: #006633;">NO</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> doc<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">FileNotFoundException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ContentParserException<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Document</span> getDocument<span style="color: #009900;">&#40;</span><span style="color: #003399;">InputStream</span> input<span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">throws</span> ContentParserException <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// try to retrieve the mime type... unfortunately the Tika parser don't</span>
	<span style="color: #666666; font-style: italic;">// handle this automatically</span>
&nbsp;
	<span style="color: #003399;">BufferedInputStream</span> bufIn <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedInputStream</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	MimeType mimeType <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>bufIn.<span style="color: #006633;">markSupported</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO this may be dangerous...</span>
		bufIn.<span style="color: #006633;">mark</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2048</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		MimeTypes repo <span style="color: #339933;">=</span> config.<span style="color: #006633;">getMimeRepository</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			mimeType <span style="color: #339933;">=</span> repo.<span style="color: #006633;">getMimeType</span><span style="color: #009900;">&#40;</span>bufIn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ContentParserException<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			bufIn.<span style="color: #006633;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> getDocument<span style="color: #009900;">&#40;</span>bufIn, mimeType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> doc<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Additionally I wrote a custom TikaParser that extracts the Exif data from JPEG files. To achieve this I used the <a href="http://www.drewnoakes.com/code/exif/releases/">metadata-extractor</a>. Unfortunately the lib is not available via maven therefore we have to add the lib manually.</p>
<p><code><br />
mvn install:install-file -Dfile=metadata-extractor-2.3.1.jar -DgroupId=com.drew -DartifactId=metadata-extractor -Dversion=2.3.1 -Dpackaging=jar<br />
</code></p>
<p>A custom tika parser may looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.acidum.tika</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.ImageIO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.ImageReader</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.io.input.CloseShieldInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.tika.exception.TikaException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.tika.metadata.Metadata</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.tika.parser.Parser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.tika.sax.XHTMLContentHandler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.ContentHandler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.SAXException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.drew.imaging.jpeg.JpegMetadataReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.drew.imaging.jpeg.JpegProcessingException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.drew.metadata.Directory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.drew.metadata.MetadataException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.drew.metadata.Tag</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* This class implements a tika parser. To activate the parser we have to change
* the tika-config.xml.
*
* Compared to the default Tika Image handling we read the Jpeg Exif data and
* return these values as metadata for Lucene
*
* @author Christoph Hartmann
*
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ImageParser <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Parser</span> <span style="color: #009900;">&#123;</span>
&nbsp;
Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> parse<span style="color: #009900;">&#40;</span><span style="color: #003399;">InputStream</span> stream, <span style="color: #003399;">ContentHandler</span> handler,
		Metadata metadata<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, SAXException, TikaException <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003399;">String</span> type <span style="color: #339933;">=</span> metadata.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Metadata.<span style="color: #006633;">CONTENT_TYPE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>type <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// hey we get a jpeg lets read the exif</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>type.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/jpeg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			extractJPEGMetaData<span style="color: #009900;">&#40;</span>stream, metadata<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// if picture is unknown do the default tika handling</span>
		<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			Iterator<span style="color: #339933;">&lt;</span>ImageReader<span style="color: #339933;">&gt;</span> iterator <span style="color: #339933;">=</span> ImageIO
					.<span style="color: #006633;">getImageReadersByMIMEType</span><span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				ImageReader reader <span style="color: #339933;">=</span> iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				reader.<span style="color: #006633;">setInput</span><span style="color: #009900;">&#40;</span>ImageIO
						.<span style="color: #006633;">createImageInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CloseShieldInputStream<span style="color: #009900;">&#40;</span>
								stream<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				metadata.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;height&quot;</span>, <span style="color: #003399;">Integer</span>
						.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>reader.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				metadata.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;width&quot;</span>, <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>reader.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				reader.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	XHTMLContentHandler xhtml <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XHTMLContentHandler<span style="color: #009900;">&#40;</span>handler, metadata<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	xhtml.<span style="color: #006633;">startDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	xhtml.<span style="color: #006633;">endDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * get additional metadata for jpeg files
 *
 * @param inputStream
 * @param tikaMetaData
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> extractJPEGMetaData<span style="color: #009900;">&#40;</span><span style="color: #003399;">InputStream</span> inputStream,
		Metadata tikaMetaData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// read the exif meta data</span>
	com.<span style="color: #006633;">drew</span>.<span style="color: #006633;">metadata</span>.<span style="color: #006633;">Metadata</span> jpegMetaData<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		jpegMetaData <span style="color: #339933;">=</span> JpegMetadataReader.<span style="color: #006633;">readMetadata</span><span style="color: #009900;">&#40;</span>inputStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// iterate through metadata directories</span>
		Iterator<span style="color: #339933;">&lt;?&gt;</span> directories <span style="color: #339933;">=</span> jpegMetaData.<span style="color: #006633;">getDirectoryIterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>directories.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			Directory directory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Directory<span style="color: #009900;">&#41;</span> directories.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// iterate through tags and print to System.out</span>
			Iterator<span style="color: #339933;">&lt;?&gt;</span> tags <span style="color: #339933;">=</span> directory.<span style="color: #006633;">getTagIterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>tags.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				Tag tag <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Tag<span style="color: #009900;">&#41;</span> tags.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
					tikaMetaData.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>tag.<span style="color: #006633;">getDirectoryName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span>
							<span style="color: #339933;">+</span> tag.<span style="color: #006633;">getTagName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, tag.<span style="color: #006633;">getDescription</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span>tag.<span style="color: #006633;">getDirectoryName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span>
							<span style="color: #339933;">+</span> tag.<span style="color: #006633;">getTagName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; -&gt; &quot;</span>
							<span style="color: #339933;">+</span> tag.<span style="color: #006633;">getDescription</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>MetadataException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JpegProcessingException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can download the whole <a href='http://www.acidum.de/wp-content/uploads/2008/12/lucenetika.zip'>Lucene + Tika example</a> and try yourself.</p>
<p><a href="http://www.acidum.de/wp-content/uploads/2008/12/lucenetika.zip"><img title="download logo" src="http://www.acidum.de/wp-content/themes/acidum/images/www.gif" alt="zip" width="31" height="31" /> </a> </p>
<p><strong>UPDATE:</strong> The project uses <a href="http://maven.apache.org/">Maven 2</a> to build the jar. The official page offers <a href="http://maven.apache.org/download.html">installation instructions</a> and <a href="http://maven.apache.org/run-maven/index.html#Quick_Start">guidelines</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2009/01/07/index-microsoft-office-files-with-lucene/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>J2ME REST Client</title>
		<link>http://www.acidum.de/2008/12/29/j2me-rest-client/</link>
		<comments>http://www.acidum.de/2008/12/29/j2me-rest-client/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 16:41:00 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=203</guid>
		<description><![CDATA[Unfortunately J2ME does not provide the best basis for writing a REST Web Service. As I already mentioned in previous posts the J2ME reference implementation does not support all HTTP methods. To overcome this restriction I wrote a J2ME Rest Client that uses HTTP method emulation like Rails does. Even though I heard that some [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately J2ME does not provide the best basis for writing a REST Web Service. As I already mentioned in previous posts the J2ME reference implementation does not support all HTTP methods. To overcome this restriction I wrote a J2ME Rest Client that uses HTTP method emulation like Rails does. Even though I heard that some J2ME platforms support PUT and DELETE I decided to use the standard. Method emulation may become a challenge if you&#8217;re not talking to your own services since it require a suitable server implementation like I posted for Grails earlier.</p>
<p>The following code illustrates how the Rest Client works. It uses the <a href="http://java.sun.com/docs/books/j2mewireless/examples/src/examples/netclient/BasicAuth.java">BasicAuth</a> class from Sun. I removed the imports, because it should be obvious. In future versions of the class I plan to use one method to read the data from stream an check the status to reduce the file size. But for my first prototype it works that way.
</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * This class provided a REST implementation for J2ME.
 * @author Christoph Hartmann
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RestClient <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> userid<span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// User Agent</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> ua<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> RestClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> RestClient<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> userid, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">userid</span> <span style="color: #339933;">=</span> userid<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">password</span> <span style="color: #339933;">=</span> password<span style="color: #339933;">;</span>
		ua <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Profile/&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;microedition.profiles&quot;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; Configuration/&quot;</span>
				<span style="color: #339933;">+</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;microedition.configuration&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * prepare the HTTP connection
	 * @param conn
	 * @throws IOException
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> configureConncetion<span style="color: #009900;">&#40;</span>HttpConnection conn<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;User-Agent&quot;</span>, ua<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> locale <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;microedition.locale&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>locale <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> locale <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;en-US&quot;</span><span style="color: #339933;">;</span>	<span style="color: #009900;">&#125;</span>
		conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Accept-Language&quot;</span>, locale<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span>, <span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Accept&quot;</span>, <span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// set HTTP basic authentification</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userid <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>#038<span style="color: #339933;">;&amp;</span>#038<span style="color: #339933;">;</span> password <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Authorization&quot;</span>, <span style="color: #0000ff;">&quot;Basic &quot;</span> <span style="color: #339933;">+</span> BasicAuth.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span>userid, password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HttpConnection getConnection<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		HttpConnection conn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HttpConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		configureConncetion<span style="color: #009900;">&#40;</span>conn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> conn<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HttpConnection getConnection<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url, <span style="color: #000066; font-weight: bold;">int</span> access<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		HttpConnection conn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HttpConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>url, access<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		configureConncetion<span style="color: #009900;">&#40;</span>conn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> conn<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * READ
	 * @param url
	 * @return
	 * @throws IOException
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> get<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		HttpConnection hcon <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">DataInputStream</span> dis <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">StringBuffer</span> responseMessage <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">int</span> redirectTimes <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">boolean</span> redirect<span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">do</span> <span style="color: #009900;">&#123;</span>
				redirect <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// a standard HttpConnection with READ access</span>
				hcon <span style="color: #339933;">=</span> getConnection<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// obtain a DataInputStream from the HttpConnection</span>
				dis <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">DataInputStream</span><span style="color: #009900;">&#40;</span>hcon.<span style="color: #006633;">openInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// retrieve the response from the server</span>
				<span style="color: #000066; font-weight: bold;">int</span> ch<span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ch <span style="color: #339933;">=</span> dis.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					responseMessage.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span> ch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end while ( ( ch = dis.read() ) != -1 )</span>
				<span style="color: #666666; font-style: italic;">// check status code</span>
				<span style="color: #000066; font-weight: bold;">int</span> status <span style="color: #339933;">=</span> hcon.<span style="color: #006633;">getResponseCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_OK</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// Success!</span>
					<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_TEMP_REDIRECT</span><span style="color: #339933;">:</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_MOVED_TEMP</span><span style="color: #339933;">:</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_MOVED_PERM</span><span style="color: #339933;">:</span>
					<span style="color: #666666; font-style: italic;">// Redirect: get the new location</span>
					url <span style="color: #339933;">=</span> hcon.<span style="color: #006633;">getHeaderField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Redirect: &quot;</span> <span style="color: #339933;">+</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dis <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> dis.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hcon <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> hcon.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					hcon <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
					redirectTimes<span style="color: #339933;">++;</span>
					redirect <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
					<span style="color: #666666; font-style: italic;">// Error: throw exception</span>
					hcon.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Response status not OK:&quot;</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// max 5 redirects</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>redirect <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">&amp;</span>#038<span style="color: #339933;">;&amp;</span>#038<span style="color: #339933;">;</span> redirectTimes <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>redirectTimes <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Too much redirects&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// TODO bad style</span>
			responseMessage.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hcon <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
					hcon.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dis <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
					dis.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ioe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				ioe.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end try/catch</span>
		<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end try/catch/finally</span>
		<span style="color: #000000; font-weight: bold;">return</span> responseMessage.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end sendGetRequest( String )</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * UPDATE
	 *
	 * @param url
	 * @param data
	 *            the request body
	 * @throws IOException
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> post<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url, <span style="color: #003399;">String</span> data<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		HttpConnection hcon <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">DataInputStream</span> dis <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">DataOutputStream</span> dos <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">StringBuffer</span> responseMessage <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">int</span> redirectTimes <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">boolean</span> redirect<span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">do</span> <span style="color: #009900;">&#123;</span>
				redirect <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// an HttpConnection with both read and write access</span>
				hcon <span style="color: #339933;">=</span> getConnection<span style="color: #009900;">&#40;</span>url, Connector.<span style="color: #006633;">READ_WRITE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// set the request method to POST</span>
				hcon.<span style="color: #006633;">setRequestMethod</span><span style="color: #009900;">&#40;</span>HttpConnection.<span style="color: #006633;">POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// overwrite content type to be form based</span>
				hcon.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span>, <span style="color: #0000ff;">&quot;application/x-www-form-urlencoded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// set message length</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>data <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					hcon.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span>
							<span style="color: #339933;">+</span> data.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>data <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// obtain DataOutputStream for sending the request string</span>
					dos <span style="color: #339933;">=</span> hcon.<span style="color: #006633;">openDataOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> request_body <span style="color: #339933;">=</span> data.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">// send request string to server</span>
					<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> request_body.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						dos.<span style="color: #006633;">writeByte</span><span style="color: #009900;">&#40;</span>request_body<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end for( int i = 0; i &lt; request_body.length; i++ )</span>
					dos.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Including this line may produce</span>
					<span style="color: #666666; font-style: italic;">// undesiredresults on certain devices</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// obtain DataInputStream for receiving server response</span>
				dis <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">DataInputStream</span><span style="color: #009900;">&#40;</span>hcon.<span style="color: #006633;">openInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// retrieve the response from server</span>
				<span style="color: #000066; font-weight: bold;">int</span> ch<span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ch <span style="color: #339933;">=</span> dis.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					responseMessage.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span> ch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end while( ( ch = dis.read() ) != -1 ) {</span>
				<span style="color: #666666; font-style: italic;">// check status code</span>
				<span style="color: #000066; font-weight: bold;">int</span> status <span style="color: #339933;">=</span> hcon.<span style="color: #006633;">getResponseCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_OK</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// Success!</span>
					<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_TEMP_REDIRECT</span><span style="color: #339933;">:</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_MOVED_TEMP</span><span style="color: #339933;">:</span>
				<span style="color: #000000; font-weight: bold;">case</span> HttpConnection.<span style="color: #006633;">HTTP_MOVED_PERM</span><span style="color: #339933;">:</span>
					<span style="color: #666666; font-style: italic;">// Redirect: get the new location</span>
					url <span style="color: #339933;">=</span> hcon.<span style="color: #006633;">getHeaderField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Redirect: &quot;</span> <span style="color: #339933;">+</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dis <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> dis.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hcon <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> hcon.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					hcon <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
					redirectTimes<span style="color: #339933;">++;</span>
					redirect <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
					<span style="color: #666666; font-style: italic;">// Error: throw exception</span>
					hcon.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Response status not OK:&quot;</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// max 5 redirects</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>redirect <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">&amp;</span>#038<span style="color: #339933;">;&amp;</span>#038<span style="color: #339933;">;</span> redirectTimes <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>redirectTimes <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Too much redirects&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			responseMessage.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// free up i/o streams and http connection</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hcon <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> hcon.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dis <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> dis.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dos <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> dos.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ioe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				ioe.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end try/catch</span>
		<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// end try/catch/finally</span>
		<span style="color: #000000; font-weight: bold;">return</span> responseMessage.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * DELETE
	 * not possible on J2ME therefore we use Rails emulation on PUT and
	 * DELETE like
	 * http://localhost:8080/CandyStreamServer/airport/1?_method=delete
	 * @param url
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> delete<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		url <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot;?_method=DELETE&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> post<span style="color: #009900;">&#40;</span>url, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * CREATE not possible on J2ME therefore we use Rails emulation on PUT and
	 * DELETE
	 * @param url
	 * @param data
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> put<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url, <span style="color: #003399;">String</span> data<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		data <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot;&amp;#038;_method=PUT&quot;</span><span style="color: #339933;">;</span>
		url <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot;?&quot;</span> <span style="color: #339933;">+</span> data<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> post<span style="color: #009900;">&#40;</span>url, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/12/29/j2me-rest-client/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Groovy Swing Builder + JTabbedPane</title>
		<link>http://www.acidum.de/2008/12/13/groovy-swing-builder-jtabbedpane/</link>
		<comments>http://www.acidum.de/2008/12/13/groovy-swing-builder-jtabbedpane/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 13:48:11 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Builder]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=200</guid>
		<description><![CDATA[The groovy swing builder is one of Groovys best features. It becomes quite easy to build a gui with the builder. In some cases you may like to add a custom Java swing component to your swing builder. For such cases the swing builder is equipped with the widget() method. The following code uses the [...]]]></description>
			<content:encoded><![CDATA[<p>The groovy swing builder is one of Groovys best features. It becomes quite easy to build a gui with the builder. In some cases you may like to add a custom Java swing component to your swing builder. For such cases the swing builder is equipped with the widget() method. The following code uses the <a href="http://groovy.codehaus.org/SwingBuilder.tabbedPane">swing builder tabbed pane</a>  and add a custom component implemented in the getSearchPanel() method as tab.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.acidum.candystreams.gui</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">groovy.swing.SwingBuilder</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.SwingUtilities</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JFrame</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.BorderLayout</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JLabel</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JLabel</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JPanel</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CandystreamsClient <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Runnable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	CandystreamsClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// set system property to use mac os menu bar</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;apple.laf.useScreenMenuBar&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// set the application name for mac os</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.apple.mrj.application.apple.menu.about.name&quot;</span>, <span style="color: #0000ff;">&quot;CandyStreams&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		def swing <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SwingBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		def frame <span style="color: #339933;">=</span> swing.<span style="color: #006633;">frame</span><span style="color: #009900;">&#40;</span>title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;CandyStreams&quot;</span>,
			defaultCloseOperation<span style="color: #339933;">:</span> <span style="color: #003399;">JFrame</span>.<span style="color: #006633;">DISPOSE_ON_CLOSE</span>,
		    size<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">800</span>, <span style="color: #cc66cc;">600</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// add a simple menu bar</span>
			menuBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    menu<span style="color: #009900;">&#40;</span>text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;File&quot;</span>, mnemonic<span style="color: #339933;">:</span> <span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			      menuItem<span style="color: #009900;">&#40;</span>text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Exit&quot;</span>, mnemonic<span style="color: #339933;">:</span> <span style="color: #0000ff;">'X'</span>, actionPerformed<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
			    <span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// add a tabbed pane</span>
			tabbedPane<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				panel<span style="color: #009900;">&#40;</span>title<span style="color: #339933;">:</span><span style="color: #0000ff;">'Panel 1'</span>, tabBackground<span style="color: #339933;">:</span>java.<span style="color: #006633;">awt</span>.<span style="color: #003399;">Color</span>.<span style="color: #006633;">GREEN</span>,tabToolTip<span style="color: #339933;">:</span><span style="color: #0000ff;">'Panel1'</span><span style="color: #009900;">&#41;</span>
                                <span style="color: #666666; font-style: italic;">// add custom swing component</span>
				widget<span style="color: #009900;">&#40;</span>title<span style="color: #339933;">:</span><span style="color: #0000ff;">'Search'</span>, getSearchPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		frame.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> getSearchPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">JPanel</span> panel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">JPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		panel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">JLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Search Panel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">return</span> panel
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">SwingUtilities</span>.<span style="color: #006633;">invokeLater</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CandystreamsClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/12/13/groovy-swing-builder-jtabbedpane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>J2ME, REST and Grails</title>
		<link>http://www.acidum.de/2008/11/15/j2me-rest-and-grails/</link>
		<comments>http://www.acidum.de/2008/11/15/j2me-rest-and-grails/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 12:56:00 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=169</guid>
		<description><![CDATA[I set up an mobile application that sends data via a REST based interface to a Grails-based server. Unfortunately J2ME does not support all HTTP methods. To overcome this weakness we have to emulate the methods PUT and DELETE. Like Rails just did this by adding a &#8220;_method=PUT&#8221; parameter to the query URL, we will [...]]]></description>
			<content:encoded><![CDATA[<p>I set up an mobile application that sends data via a REST based interface to a Grails-based server. Unfortunately J2ME <a title="J2ME and &quot;missing&quot; PUT/DELETE HTTP verbs" href="http://www.burningdoor.com/steve/archives/000751.html" target="_blank">does not support all HTTP methods</a>. To overcome this weakness we have to emulate the methods PUT and DELETE. Like Rails just did this by adding a &#8220;_method=PUT&#8221; parameter to the query URL, we will do the same. Rails does the HTTP method emulation handling automatically, whilst in Grails we have do this by ourselves. By using the UrlMapping.groovy it will become quite easy to overcome this weakness. A standard REST mapping should look like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> UrlMappings <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> mappings <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// identifies a rest object like /rest/airport/1</span>
	  <span style="color: #0000ff;">&quot;/rest/$domain/$id&quot;</span><span style="color: #009900;">&#123;</span>
		  controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;rest&quot;</span>
		  action <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>GET<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;show&quot;</span>, PUT<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;create&quot;</span>, POST<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;update&quot;</span>,DELETE<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;delete&quot;</span><span style="color: #009900;">&#93;</span>
         <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The action attribute may be a simple string, a hash map or a closure. Grails calls the following method evaluateNameForValue(Object value, GrailsWebRequest webRequest) to retrieve the value. The method is located within the org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingInfo.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> evaluateNameForValue<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> value, GrailsWebRequest webRequest<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #000000; font-weight: bold;">instanceof</span> Closure<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Closure callable <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Closure<span style="color: #009900;">&#41;</span> value<span style="color: #339933;">;</span>
            <span style="color: #003399;">Object</span> result <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Closure<span style="color: #009900;">&#41;</span> callable.<span style="color: #006633;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">call</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            name <span style="color: #339933;">=</span> result <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> result.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">Map</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Map</span> httpMethods <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Map</span><span style="color: #009900;">&#41;</span> value<span style="color: #339933;">;</span>
            name <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> httpMethods.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>webRequest.<span style="color: #006633;">getCurrentRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getMethod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            name <span style="color: #339933;">=</span> value.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> name<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Due to our knowledge of the action retrieval process, we are able to implement a &#8220;_method&#8221; emulation. This could look like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> UrlMappings <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> mappings <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// identifies a rest object like /rest/airport/1</span>
	  <span style="color: #0000ff;">&quot;/rest/$domain/$id&quot;</span><span style="color: #009900;">&#123;</span>
		  controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;rest&quot;</span>
		  <span style="color: #666666; font-style: italic;">// action = [GET:&quot;show&quot;, PUT:&quot;create&quot;, POST:&quot;update&quot;,DELETE:&quot;delete&quot;]</span>
&nbsp;
	         action <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		   <span style="color: #666666; font-style: italic;">// closure will not be invoked with request, log ... therefore we have to do this manually</span>
		  GrailsWebRequest webRequest <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>GrailsWebRequest<span style="color: #009900;">&#41;</span> RequestContextHolder.<span style="color: #006633;">getRequestAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #003399;">String</span> method <span style="color: #339933;">=</span> webRequest.<span style="color: #006633;">getCurrentRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getMethod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #003399;">String</span> methodParam <span style="color: #339933;">=</span> webRequest.<span style="color: #006633;">getCurrentRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_method&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		  <span style="color: #666666; font-style: italic;">// check if we can use _method</span>
		  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>methodParam <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		    methodParam <span style="color: #339933;">=</span> methodParam.<span style="color: #006633;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
		    <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>methodParam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;PUT&quot;</span> <span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;DELETE&quot;</span> <span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;POST&quot;</span> <span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;GET&quot;</span> <span style="color: #339933;">:</span>
			  method <span style="color: #339933;">=</span> methodParam<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">break</span>
		  <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> 
&nbsp;
		<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>method.<span style="color: #006633;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;PUT&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;create&quot;</span>
			<span style="color: #000000; font-weight: bold;">break</span>
		  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;DELETE&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;delete&quot;</span>
			<span style="color: #000000; font-weight: bold;">break</span>
		  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;POST&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;update&quot;</span>
			<span style="color: #000000; font-weight: bold;">break</span>
		  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;GET&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;show&quot;</span>
			<span style="color: #000000; font-weight: bold;">break</span>
		  <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;show&quot;</span>
		        <span style="color: #000000; font-weight: bold;">break</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> method<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope that helps all Grails REST developers to enable their services for J2ME. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/11/15/j2me-rest-and-grails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Grails Spring Security</title>
		<link>http://www.acidum.de/2008/10/08/grails-spring-security/</link>
		<comments>http://www.acidum.de/2008/10/08/grails-spring-security/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 13:13:35 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Acegi Security]]></category>
		<category><![CDATA[Spring Security]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=160</guid>
		<description><![CDATA[For my current grails project I use the Spring Security Plugin (formerly Acegi Security) to secure my views and services. A tutorial at the Grails site gives a great overview how to install the grails plugin.
Right after installation I faced some issues:
Secure your Rest Services
This sounds quite easy due to a simple switch within the [...]]]></description>
			<content:encoded><![CDATA[<p>For my current grails project I use the <a title="Grails Acegi Plugin" href="http://grails.org/AcegiSecurity+Plugin" target="_blank">Spring Security Plugin (formerly Acegi Security)</a> to secure my views and services. A <a title="Acegi Installation Tutorial" href="http://www.grails.org/AcegiSecurity+Plugin+-+Basic+Tutorial" target="_blank">tutorial</a> at the Grails site gives a great overview how to install the grails plugin.</p>
<p>Right after installation I faced some issues:</p>
<p><strong>Secure your Rest Services</strong></p>
<p>This sounds quite easy due to a simple switch within the SecurityConfig.groovy. Just activate the BasicProcessingFilter. Now grails uses the Http Basic Authentification.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/** use basicProcessingFilter */</span>
basicProcessingFilter <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span></pre></div></div>

<p>At the client side the code would like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">sun.misc.BASE64Encoder</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">groovy.util.XmlSlurper</span>
&nbsp;
def userid <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;john.doe&quot;</span>
def password <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;pass&quot;</span>
&nbsp;
def url <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://localhost:8080/CandyStreamServer/rest/gps/&quot;</span>
&nbsp;
def conn <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userid <span style="color: #339933;">&amp;&amp;</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	println <span style="color: #0000ff;">&quot;set authorization&quot;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// add HTTP authentication</span>
       <span style="color: #003399;">String</span> encodedAuth <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BASE64Encoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>userid <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> password<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
&nbsp;
	conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Authorization&quot;</span>, <span style="color: #0000ff;">&quot;Basic &quot;</span> <span style="color: #339933;">+</span> encodedAuth<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
def slurper <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlSlurper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
conn.<span style="color: #006633;">requestMethod</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET&quot;</span>
conn.<span style="color: #006633;">doOutput</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>
&nbsp;
println <span style="color: #0000ff;">&quot;check connection&quot;</span>
def response
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>conn.<span style="color: #006633;">responseCode</span> <span style="color: #339933;">==</span> conn.<span style="color: #006633;">HTTP_OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	conn.<span style="color: #006633;">inputStream</span>.<span style="color: #006633;">withStream</span> <span style="color: #009900;">&#123;</span>
		response <span style="color: #339933;">=</span> slurper.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>it<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
	response <span style="color: #339933;">=</span> conn.<span style="color: #006633;">responseCod</span>
<span style="color: #009900;">&#125;</span>
println response
conn.<span style="color: #006633;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>Retrieve the Current User</strong></p>
<p>On the server side it may necessary to retrieve the current user. Spring Security offers a SecurityContextHolder. Unfortunately the  securityContext.getAuthentication().getPrincipal(); does not return the Groovy user object. Instead the Spring Security Plugin uses its own user implementation that holds the Groovy user object. This is required due to Springs dependency on a specific interface.</p>
<p>The plugin provides a org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser interface that extends the org.springframework.security.userdetails.UserDetails interface. To retrieve your Groovy user object just call getDomainClass()</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">SecurityContext securityContext <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
def springUser <span style="color: #339933;">=</span> securityContext.<span style="color: #006633;">getAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getPrincipal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> springUser.<span style="color: #006633;">getDomainClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/10/08/grails-spring-security/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Groovy Meta Programmierung</title>
		<link>http://www.acidum.de/2008/10/07/groovy-meta-programmierung/</link>
		<comments>http://www.acidum.de/2008/10/07/groovy-meta-programmierung/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 07:42:06 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Metaprogramming]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=146</guid>
		<description><![CDATA[Im Rahmen des Seminars Meta-Programmierung haben Lars Blumberg, Arvid Heise und ich eine Ausarbeitung erstellt, welche die Metaprogrammierung von Groovy untersucht.
Abstract:
Der Name der Programmiersprache ist Programm. Dass Groovy als noch junge Sprache viele neue und interessante Sprachkonzepte mitbringt, möchten wir im ersten Teil dieses Papers aufzeigen. Ein weiteres Highlight des ersten Kapitels ist vielleicht die [...]]]></description>
			<content:encoded><![CDATA[<p>Im Rahmen des Seminars Meta-Programmierung haben <a title="Lars Blumberg Homepage" href="http://www.lars-blumberg.de/" target="_blank">Lars Blumberg</a>, Arvid Heise und ich eine Ausarbeitung erstellt, welche die Metaprogrammierung von Groovy untersucht.</p>
<p><strong>Abstract:</strong></p>
<p>Der Name der Programmiersprache ist Programm. Dass Groovy als noch junge Sprache viele neue und interessante Sprachkonzepte mitbringt, möchten wir im ersten Teil dieses Papers aufzeigen. Ein weiteres Highlight des ersten Kapitels ist vielleicht die Erkenntnis über die gelungene, nahtlos Integration mit der Java-Plattform. Im folgenden Hauptteil wird insbesondere die Möglichkeit der Meta-Programmierung mit Groovy beschrieben. Es wird auf die Umsetzung des Meta-Object-Protocols eingegangen und erläutert, wie die zugehörigen Konzepte mit Hilfe der Java Virtual Machine umgesetzt werden konnten. Im dritten und letzten Teil wird dem Leser eine implementierte Beispiel-Anwendung vorgestellt. Sie ist wie dieses Paper im Rahmen der Veranstaltung &#8220;Metaprogrammierung und Reflection&#8221; entstanden und demonstriert eindrucksvoll die Meta-Programmierung in Groovy.</p>
<p><strong>Keywords:</strong></p>
<p>Groovy, Metaprogramming</p>
<p><strong><strong><a title="Microsoft Visual Programming Language: End-User Perspektive" href="http://www.acidum.de/wp-content/uploads/2008/08/microsoft-visual-programming-language-paper.pdf" target="_blank"><strong><strong></strong></strong></a></strong></strong></p>
<p><strong><strong><a href="http://www.acidum.de/wp-content/uploads/2008/10/groovy-meta-programming-paper.pdf"><img title="Pfd" src="http://www.acidum.de/wp-content/themes/acidum/images/pdf.gif" alt="Pfd" width="29" height="29" />Groovy Meta Programming Paper</a></strong></strong></p>
<p><strong><strong><a href="http://www.acidum.de/wp-content/uploads/2008/10/groovy-meta-programming-slides.pdf"><img title="Pfd" src="http://www.acidum.de/wp-content/themes/acidum/images/pdf.gif" alt="Pfd" width="29" height="29" />Groovy Meta Programming Slides</a></strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/10/07/groovy-meta-programmierung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean your Apple Wireless Keyboard</title>
		<link>http://www.acidum.de/2008/10/07/clean-your-apple-wireless-keyboard/</link>
		<comments>http://www.acidum.de/2008/10/07/clean-your-apple-wireless-keyboard/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 07:25:20 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Wireless Keyboard]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=80</guid>
		<description><![CDATA[The Apple Wireless Keyboard is a amazing slim keyboard. But how to clean? The following pictures illustrate this process. It&#8217;s quite difficult to remove the keys without breaking them. Use a small screwdriver and keep cool.  
]]></description>
			<content:encoded><![CDATA[<p>The Apple Wireless Keyboard is a amazing slim keyboard. But how to clean? The following pictures illustrate this process. It&#8217;s quite difficult to remove the keys without breaking them. Use a small screwdriver and keep cool. <img src='http://www.acidum.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p><div class="imagegallery"><a href="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/images/applekeyboard04.jpg"  title="Apple Wireless Keyboard 03" rel="lightbox[AppleWirelessKeyboard"><img class="tn" src="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/thumbnails/applekeyboard04.jpg" alt="Apple Wireless Keyboard 03" /></a><a href="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/images/applekeyboard01.jpg"  title="Apple Wireless Keyboard 01" rel="lightbox[AppleWirelessKeyboard"><img class="tn" src="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/thumbnails/applekeyboard01.jpg" alt="Apple Wireless Keyboard 01" /></a><a href="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/images/applekeyboard02.jpg"  title="Apple Wireless Keyboard 02" rel="lightbox[AppleWirelessKeyboard"><img class="tn" src="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/thumbnails/applekeyboard02.jpg" alt="Apple Wireless Keyboard 02" /></a><a href="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/images/applekeyboard03.jpg"  title="Apple Wireless Keyboard 03" rel="lightbox[AppleWirelessKeyboard"><img class="tn" src="http://www.acidum.de/wp-content/galleries/AppleWirelessKeyboard/thumbnails/applekeyboard03.jpg" alt="Apple Wireless Keyboard 03" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/10/07/clean-your-apple-wireless-keyboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy Programming Examples</title>
		<link>http://www.acidum.de/2008/09/11/groovy-programming-examples/</link>
		<comments>http://www.acidum.de/2008/09/11/groovy-programming-examples/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 13:16:03 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Code Examples]]></category>
		<category><![CDATA[Metaprogramming]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=154</guid>
		<description><![CDATA[Java Iteration Example

import java.util.Date;
&#160;
public class Foo &#123;
    public static void main&#40;String&#91;&#93; args&#41; &#123;
        int start = 1;
        int summe = 0;
&#160;
        for &#40;int i = start; i &#60;= 5; i++&#41; &#123;
 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Java Iteration Example</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> start <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> summe <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> start<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            summe <span style="color: #339933;">+=</span> i<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003399;">Date</span> now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>now.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; Die Summe ist: &quot;</span> <span style="color: #339933;">+</span> summe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Groovy Iteration Example within Groovy Shell</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
        start <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>
        summe <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i in start..5<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            summe <span style="color: #339933;">+=</span> i
        <span style="color: #009900;">&#125;</span>
&nbsp;
        now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        println <span style="color: #0000ff;">&quot;$now Die Summe ist: $summe&quot;</span></pre></div></div>

<p><strong>Groovy Map Handling with Closures</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">map <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// inline closure</span>
map.<span style="color: #006633;">each</span> <span style="color: #009900;">&#123;</span> key, value <span style="color: #339933;">-&gt;</span>
    map<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span>
<span style="color: #009900;">&#125;</span>
println map
&nbsp;
<span style="color: #666666; font-style: italic;">// extern closure</span>
doubler <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> key, value <span style="color: #339933;">-&gt;</span>
    map<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span>
<span style="color: #009900;">&#125;</span>
map.<span style="color: #006633;">each</span><span style="color: #009900;">&#40;</span>doubler<span style="color: #009900;">&#41;</span>
println map</pre></div></div>

<p><strong>Groovy Beans</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Book</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> title
&nbsp;
    <span style="color: #003399;">Book</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> theTitle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        title <span style="color: #339933;">=</span> theTitle
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003399;">Book</span> plus<span style="color: #009900;">&#40;</span><span style="color: #003399;">Book</span> anotherBook<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Book</span><span style="color: #009900;">&#40;</span>title <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;, &quot;</span> <span style="color: #339933;">+</span> anotherBook.<span style="color: #006633;">title</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">Book</span> gina <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Book</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Groovy in Action&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">// getters are generated automatically </span>
println gina.<span style="color: #006633;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
println <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>gina <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Book</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Groovy for Experts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">title</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>Groovy Duck Typing</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Dog <span style="color: #009900;">&#123;</span>
    def speak<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> println <span style="color: #0000ff;">&quot;wuff&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> Cat <span style="color: #009900;">&#123;</span>
    def speak<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> println <span style="color: #0000ff;">&quot;miau&quot;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
def saySomething<span style="color: #009900;">&#40;</span>somewhat<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    somewhat.<span style="color: #006633;">speak</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
saySomething<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Dog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
saySomething<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Cat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>Simple XML Example:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> XmlBuilder <span style="color: #009900;">&#123;</span>
   def out
   XmlBuilder<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">out</span> <span style="color: #339933;">=</span> out <span style="color: #009900;">&#125;</span>
   def invokeMethod<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       out <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000ff;">&quot;&lt;$name&gt;&quot;</span>
       <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">instanceof</span> Closure<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">delegate</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>
            args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">call</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
           out <span style="color: #339933;">&lt;&lt;</span> args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#125;</span>
       out <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000ff;">&quot;&lt;/$name&gt;&quot;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
def xml <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlBuilder<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
xml.<span style="color: #006633;">html</span> <span style="color: #009900;">&#123;</span>
    head <span style="color: #009900;">&#123;</span>
        title <span style="color: #0000ff;">&quot;Hello World&quot;</span>
    <span style="color: #009900;">&#125;</span>
    body <span style="color: #009900;">&#123;</span>
        p <span style="color: #0000ff;">&quot;Welcome!&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
println xml.<span style="color: #006633;">out</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/09/11/groovy-programming-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

