<?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 &#187; Groovy</title>
	<atom:link href="http://www.acidum.de/tag/groovy/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>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>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>
		<item>
		<title>10 Steps to Integrate OpenID into Grails</title>
		<link>http://www.acidum.de/2008/08/11/10-steps-to-integrate-openid-into-grails/</link>
		<comments>http://www.acidum.de/2008/08/11/10-steps-to-integrate-openid-into-grails/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 12:32:24 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[OpenID]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=123</guid>
		<description><![CDATA[Check out how easy the integration of OpenID into Grails is:
1. Create a new grails application: grails create-app openID
2. Change into directory: cd openID
3. Install Plugin: grails install-plugin openid
4. Create a new controller: grails create-controller User
5. Create logon.gsp at grails-app/views/user
6. Add the following lines of code
 &#60;openid:css /&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&#62;
&#60;meta name="layout" content="main" /&#62;
&#60;title&#62;Login&#60;/title&#62;
&#60;openid:css /&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;h1&#62;Login&#60;/h1&#62;
&#60;openid:hasLoginError&#62;
&#60;div [...]]]></description>
			<content:encoded><![CDATA[<p>Check out how easy the integration of <a title="OpenID" href="http://openid.net/" target="_blank">OpenID</a> into Grails is:</p>
<p>1. Create a new grails application: grails create-app openID</p>
<p>2. Change into directory: cd openID</p>
<p>3. Install Plugin: grails install-plugin openid</p>
<p>4. Create a new controller: grails create-controller User</p>
<p>5. Create logon.gsp at grails-app/views/user</p>
<p>6. Add the following lines of code</p>
<p><code> &lt;openid:css /&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;<br />
&lt;meta name="layout" content="main" /&gt;<br />
&lt;title&gt;Login&lt;/title&gt;<br />
&lt;openid:css /&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;Login&lt;/h1&gt;<br />
&lt;openid:hasLoginError&gt;<br />
&lt;div class="errors"&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;openid:renderLoginError /&gt;&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;/div&gt;<br />
&lt;/openid:hasLoginError&gt;<br />
&lt;openid:form success="[action:'loggedin']"&gt;<br />
&lt;openid:input size="30" value="http://" /&gt; (e.g. http://username.myopenid.com)<br />
&lt;br/&gt;<br />
&lt;g:submitButton name="login" value="Login" /&gt;<br />
&lt;/openid:form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p>7. Edit UserController and add</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UserController <span style="color: #009900;">&#123;</span>
def login <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
def loggedin <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> redirect<span style="color: #009900;">&#40;</span>uri<span style="color: #339933;">:</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>8. Call grails run-app</p>
<p>9. Open your web browser at http://localhost:8080/openID/User/login.gsp</p>
<p>10. Use your OpenID account to log on like <a title="Yahoo OpenID" href="http://openid.yahoo.com/" target="_blank">Yahoo OpenID</a>.</p>
<p>Check out <a title="Grails OpenID Integration" href="http://docs.codehaus.org/display/GRAILS/OpenID+Plugin" target="_blank">http://docs.codehaus.org/display/GRAILS/OpenID+Plugin</a> for further information about the Grails openID plugin</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/08/11/10-steps-to-integrate-openid-into-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use Groovy XML Parser with namespaces</title>
		<link>http://www.acidum.de/2008/04/01/how-to-use-groovy-xml-parser-with-namespaces/</link>
		<comments>http://www.acidum.de/2008/04/01/how-to-use-groovy-xml-parser-with-namespaces/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 09:10:31 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=75</guid>
		<description><![CDATA[The Groovy documentation gives the first hints about how to use the Groovy XML Parser. This post describes how to read an XML file into a groovy class instance. To check for a valid input document advanced XML programs require XSDs for a formal description. Of course the XML processing task becomes more difficult with [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="Groovy XML Processing" href="http://groovy.codehaus.org/Processing+XML">Groovy documentation</a> gives the first hints about how to use the Groovy XML Parser. This post describes how to read an XML file into a groovy class instance. To check for a valid input document advanced XML programs require XSDs for a formal description. Of course the XML processing task becomes more difficult with XML namespaces but the following expample shows how easy XML processing is with Groovy.</p>
<p>This demo illustrates how to read an XML file into Groovy objects. As the background I used the student lecture management. It stores students, assigned lectures with results and specific details about the lecture itself. The students are stored within a <strong>studenten</strong> node which itself contains a node for every student. A student may have a name, birthday and its assignments.</p>
<p>The second major node is the <strong>lehrveranstaltungen</strong> node that contains details about the lectures. The student assignments and the lectures are linked via identifier.</p>
<p>The following XML file is used as xml input:<br />
<code><br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;studentenverwaltung<br />
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
xsi:schemaLocation="studentenverwaltung.xsd"<br />
xmlns="http://www.hpi.uni-potsdam.de/studentenverwaltung"&gt;<br />
&lt;studenten&gt;<br />
&lt;student geburtstag="19821221" matrikelnummer="123456"&gt;<br />
&lt;vorname&gt;John&lt;/vorname&gt;<br />
&lt;nachname&gt;Doe&lt;/nachname&gt;<br />
&lt;belegungen&gt;<br />
&lt;belegung lehrveranstaltung="_12" note="1.0"/&gt;<br />
&lt;/belegungen&gt;<br />
&lt;/student&gt;<br />
&lt;student geburtstag="19821221" matrikelnummer="654321"&gt;<br />
&lt;vorname&gt;Alice&lt;/vorname&gt;<br />
&lt;nachname&gt;Doe&lt;/nachname&gt;<br />
&lt;belegungen&gt;<br />
&lt;belegung lehrveranstaltung="_12" note="1.0"/&gt;<br />
&lt;/belegungen&gt;<br />
&lt;/student&gt;<br />
&lt;/studenten&gt;<br />
&lt;lehrveranstaltungen&gt;<br />
&lt;lehrveranstaltung id="_12" belegungspunkte="6"&gt;<br />
&lt;titel&gt;Datenorientiertes XML&lt;/titel&gt;<br />
&lt;dozent&gt;Martin von Löwis&lt;/dozent&gt;<br />
&lt;beschreibung&gt;<br />
Das ist eine ganz nützliche Veranstaltung.<br />
&lt;/beschreibung&gt;<br />
&lt;/lehrveranstaltung&gt;<br />
&lt;/lehrveranstaltungen&gt;<br />
&lt;/studentenverwaltung&gt;<br />
</code></p>
<p>This whole document with two students will be read into 3 classes:</p>
<ul>
<li>Student,</li>
<li>Belegung and</li>
<li>Lehrveranstaltung</li>
</ul>
<p>These classes are quite small compared to Java classes:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Student<span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">String</span> geburtstag
      <span style="color: #003399;">String</span> matrikelnummer
      <span style="color: #003399;">String</span> vorname
      <span style="color: #003399;">String</span> nachname
      def belegungen <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
&nbsp;
      <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #0000ff;">&quot;Student: $vorname $nachname nMartrikelnummer: $matrikelnummer) nBelegungen: $belegungen&quot;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Belegung <span style="color: #009900;">&#123;</span>
	  Lehrveranstaltung lehrveranstaltung
	  <span style="color: #003399;">String</span> note
&nbsp;
	  <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		  <span style="color: #0000ff;">&quot;nLehrveranstaltung: $lehrveranstaltung  Note: $note&quot;</span>
&nbsp;
	  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Lehrveranstaltung <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">String</span>  id
      <span style="color: #000066; font-weight: bold;">int</span>     belegungspunkte
      <span style="color: #003399;">String</span>  titel
      <span style="color: #003399;">String</span>  dozent
      <span style="color: #003399;">String</span>  beschreibung
&nbsp;
      <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    	  <span style="color: #0000ff;">&quot;$titel ($dozent)&quot;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now the XML processing starts. At first we have to initialize the Namespace and load the XML file into a variable.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// create namespace</span>
def ns <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> groovy.<span style="color: #006633;">xml</span>.<span style="color: #006633;">Namespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.hpi.uni-potsdam.de/studentenverwaltung&quot;</span>, <span style="color: #0000ff;">'ns'</span><span style="color: #009900;">&#41;</span>
def root <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'studies.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>After parsing the xml document it&#8217;s easy to iterate over the nodes with Groovy. A syntax like</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">root<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">studenten</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">student</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">each</span> <span style="color: #009900;">&#123;</span> xmlstudent <span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>reads all <strong>Stutent</strong> nodes within the <strong>Studenten</strong> node. The called each method iterates over the result list and provide the <em>xmlstudent</em> variable to access the current student within the following code block. With the help of this code block it is easy to read the student vales into a new object.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// read core data</span>
	student <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Student<span style="color: #009900;">&#40;</span>
		vorname<span style="color: #339933;">:</span>             xmlstudent<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">vorname</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
		nachname<span style="color: #339933;">:</span>           xmlstudent<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">nachname</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
		matrikelnummer<span style="color: #339933;">:</span>  xmlstudent.<span style="color: #0000ff;">'@matrikelnummer'</span>,
		geburtstag<span style="color: #339933;">:</span>          xmlstudent.<span style="color: #0000ff;">'@geburtstag'</span>
	<span style="color: #009900;">&#41;</span></pre></div></div>

<p>The constructor behavior is special compared to Java. Groovy allows to initialize class members via the constructor. Additionally the instruction xmlstudent.&#8217;@matrikelnummer&#8217; reads the xml attribute <strong>matrikelnummer</strong> from the xml <strong>student</strong> node.</p>
<p>The second task is to read in all lecture assignments for the student. This task is more complex because the lectures are stored within it&#8217;s own node. For that reason we have to iterate over all assignments stored within the <strong>belegung</strong> nodes and use the assigned lecture link to find the right lecture.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// read belegungen</span>
xmlstudent<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">belegungen</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">belegung</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">each</span> <span style="color: #009900;">&#123;</span> belegung <span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To include the content of the lecture node we have to search for this lecture node now. The required lecture link is taken from the <strong>lehrveranstaltung</strong> attribute of the current assignment. This lecture lookup is written like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// read lecture</span>
xmlLehr <span style="color: #339933;">=</span> root<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">lehrveranstaltungen</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">lehrveranstaltung</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">find</span><span style="color: #009900;">&#123;</span>
	it.<span style="color: #0000ff;">'@id'</span> <span style="color: #339933;">==</span> belegung.<span style="color: #0000ff;">'@lehrveranstaltung'</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>With this lecture node it is possible to fill the student class with the student&#8217;s assignments.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// read assignment</span>
student.<span style="color: #006633;">belegungen</span> <span style="color: #339933;">+=</span> <span style="color: #000000; font-weight: bold;">new</span> Belegung<span style="color: #009900;">&#40;</span>
	note <span style="color: #339933;">:</span> belegung.<span style="color: #0000ff;">'@note'</span>,
	lehrveranstaltung <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> Lehrveranstaltung<span style="color: #009900;">&#40;</span>
		id					<span style="color: #339933;">:</span>xmlLehr.<span style="color: #0000ff;">'@id'</span>,
		belegungspunkte		<span style="color: #339933;">:</span>xmlLehr.<span style="color: #0000ff;">'@belegungspunkte'</span>,
		titel				<span style="color: #339933;">:</span>xmlLehr<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">titel</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
		dozent				<span style="color: #339933;">:</span>xmlLehr<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">dozent</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
		beschreibung		<span style="color: #339933;">:</span>xmlLehr<span style="color: #009900;">&#91;</span>ns.<span style="color: #006633;">beschreibung</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>These few lines of code are enough to read a namespace xml into Groovy. The iteration over all nodes and the simple attributes access is useful to keep the amount of code low. If you are interested to try out the whole example you are welcome to download the <a href="http://www.acidum.de/wp-content/uploads/2008/03/groovyxml.zip">attached zip file </a> that contains the Eclipse project with all required files.</p>
<p>Download:<br />
<a href="http://www.acidum.de/wp-content/uploads/2008/03/groovyxml.zip"><br />
<img src="http://www.acidum.de/wp-content/themes/acidum/images/www.gif" alt="Download" /><br />
Code Sample<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/04/01/how-to-use-groovy-xml-parser-with-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install the Groovy Eclipse Plugin</title>
		<link>http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/</link>
		<comments>http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 13:10:40 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=66</guid>
		<description><![CDATA[Acording to the official Groovy web site Groovy is “an agile dynamic language for the Java Platform with many features that are inspired by languages like Python, Ruby and Smalltalk, making them available to Java developers using a Java-like syntax.”
Besides all marketing I used Groovy for quite some time and I think it&#8217;s a great [...]]]></description>
			<content:encoded><![CDATA[<p>Acording to the official <a title="Offical Groovy Page" href="http://groovy.codehaus.org/" target="_blank">Groovy</a> web site Groovy is “an agile dynamic language for the Java Platform with many features that are inspired by languages like Python, Ruby and Smalltalk, making them available to Java developers using a Java-like syntax.”</p>
<p>Besides all marketing I used Groovy for quite some time and I think it&#8217;s a great scripting language for Java. If you are new to Groovy you should read the book: <a title="Groovy in Action" href="http://www.manning.com/koenig/" target="_blank">&#8220;Dierk Koenig: Groovy in Action&#8221;</a>. After 2 days of working with Groovy you will become a real Groovy developer. And the best about Groovy is that your old Java code can be reused.</p>
<p><strong>Get the stuff workig</strong></p>
<p>Although Groovy is available as a separate package <a title="Groovy Download Page" href="http://groovy.codehaus.org/Download" target="_blank">here</a>, I would recommend to use Groovy in combination with Eclipse. This works easily on Mac and Windows and fits to Java programmers most due to the familiar Eclipse environment. Compared to Eclipse the Groovy scripting console shipped with the Groovy libraries called &#8220;Groovy Console&#8221; is only useful to write simple Code snippets. If your project becomes bigger the Eclipse environment is more powerful.</p>
<p>After a properly set up of <a title="Eclipse Home" href="http://www.eclipse.org/" target="_blank">Eclipse</a>, open it and go to <strong>Help -&gt; Software Updates -&gt; Find and Install -&gt; Search For New Features</strong>. Now add a <strong>New Remote Site&#8230;</strong> and insert &#8220;Grovvy Plugin&#8221; and &#8220;http://dist.codehaus.org/groovy/distributions/update/&#8221; as URL. Confirm the data with <strong>OK.</strong> Now check the newly added Site and press <strong>Finish</strong>.</p>
<p>The following screen will ask you to <strong>Select the Features to Install</strong>. Just select the Groovy check box and press <strong>Next. </strong>Finally accept the license agreement and press <strong>Next. </strong>Confirm the default location with<strong> Finish</strong>. Now the plugin download starts.<strong><br />
</strong></p>

<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-01/' title='groovy-eclipse-01'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-01-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-01" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-02/' title='groovy-eclipse-02'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-02-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-02" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-03/' title='groovy-eclipse-03'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-03-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-03" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-project-01/' title='groovy-eclipse-project-01'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-project-01-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-project-01" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-project-02/' title='groovy-eclipse-project-02'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-project-02-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-project-02" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-project-03/' title='groovy-eclipse-project-03'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-project-03-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-project-03" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-project-04/' title='groovy-eclipse-project-04'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-project-04-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-project-04" /></a>
<a href='http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/groovy-eclipse-project-05/' title='groovy-eclipse-project-05'><img width="150" height="150" src="http://www.acidum.de/wp-content/uploads/2008/03/groovy-eclipse-project-05-150x150.jpg" class="attachment-thumbnail" alt="" title="groovy-eclipse-project-05" /></a>

<p>After the Groovy plugin installation, it&#8217;s easy to start with Groovy. At first you create a <strong>new Java project</strong> and add a new <strong>Groovy class</strong>.  Afterwards Eclipse asks you to add the Groovy runtime to the Java project and confirm this question with Yes. Within this project you can use Java and Groovy classes interchangeable. This is the best thing about Groovy runtime because it is a simple Java jar file.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> HelloWorld <span style="color: #009900;">&#123;</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>args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Add <em>println &#8220;Hello World&#8221;</em> and open the <strong>Run Dialog</strong>. Currently the dialog does not find Groovy main classes. Therefore you have to add it manually. After a click on <strong>Run</strong> the Console outputs: <em> Hello World </em></p>
<p>To sum up: it&#8217;s so simple to run Groovy code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2008/03/31/install-the-groovy-eclipse-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 3.239 seconds -->
