<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>thegioraproject.com &#187; grails</title>
	<link>http://thegioraproject.com</link>
	<description></description>
	<pubDate>Mon, 02 Jun 2008 04:20:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Custom implicit variables in GSP&#8217;s</title>
		<link>http://thegioraproject.com/2008/06/01/custom-implicit-variables-in-gsps/</link>
		<comments>http://thegioraproject.com/2008/06/01/custom-implicit-variables-in-gsps/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 20:46:39 +0000</pubDate>
		<dc:creator>Kevin Burke</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://thegioraproject.com/2008/06/01/custom-implicit-variables-in-gsps/</guid>
		<description><![CDATA[I really should start every post with &#8220;groovy is a really swell language&#8221;.  You can do some pretty cool things with it.
Anyway,  I had a desire to have an variable implicitly available in all of my GSP&#8217;s so that I didn&#8217;t have to wrap certain blocks in a tag that made the variable [...]]]></description>
			<content:encoded><![CDATA[<p>I really should start every post with &#8220;groovy is a really swell language&#8221;.  You can do some pretty cool things with it.</p>
<p>Anyway,  I had a desire to have an variable implicitly available in all of my GSP&#8217;s so that I didn&#8217;t have to wrap certain blocks in a tag that made the variable available.  There were a couple of reasons for this. The first is that if an exception was thrown in the block of code, the stack trace would indicate that it was coming from my custom tag.  More importantly however it was a real pain in the tuckus to have to litter my GSP&#8217;s with a tag that simply introduced a variable into the scope.  After several attempts to hijack the page scope before the page was rendered I settled on the following:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">GroovyPage.<span class="me1">metaClass</span>.<span class="me1">getCurrentUser</span> <span class="sy0">=</span> <span class="br0">&#123;</span>-<span class="sy0">&gt;</span> ctx.<span class="me1">authenzedManager</span>.<span class="me1">currentUser</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>As it turns out every page extends GroovyPage which is just a groovy script.  So you can add methods using it&#8217;s metaClass to add all kinds of functionality.  This might be a good way for plugins to add sort of helper methods, since, unlike tags, it will actually return a value and not write it to out.  Anyway, by adding getCurrenUser I can now call ${currentUser.whatever} from my GSP.  It makes me happy.</p>
<p>Rock over London. Rock on Chicago.</p>
]]></content:encoded>
			<wfw:commentRss>http://thegioraproject.com/2008/06/01/custom-implicit-variables-in-gsps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Image attachments in grails using ImageMagick</title>
		<link>http://thegioraproject.com/2008/03/26/image-attachments-in-grails-using-imagemagick/</link>
		<comments>http://thegioraproject.com/2008/03/26/image-attachments-in-grails-using-imagemagick/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 05:38:43 +0000</pubDate>
		<dc:creator>Kevin Burke</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://thegioraproject.com/2008/03/26/image-attachments-in-grails-using-imagemagick/</guid>
		<description><![CDATA[I&#8217;ll admit it, I used ImageMagick for my image manipulation instead of Java and I&#8217;ll show you how I did it.
I tried using the image tools plugin.  It&#8217;s terrific.  It is easy to install and simple to use.  I couldn&#8217;t ask for anything more.  The only problem is that the default [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll admit it, I used <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a> for my image manipulation instead of Java and I&#8217;ll show you how I did it.</p>
<p>I tried using the <a href="http://grails.org/ImageTools+plugin">image tools plugin</a>.  It&#8217;s terrific.  It is easy to install and simple to use.  I couldn&#8217;t ask for anything more.  The only problem is that the default interpolation algorithm (nearest neighbor) doesn&#8217;t create the greatest images when scaling.  This is a JAI problem.  So I did some trial and error and found that bicubic interpolation is much better; not great, but better.  It was slow.  This is a JAI problem.  It got even slower when I tried a multi pass approach to scaling the image.  It was just too slow for the image quality that it was producing.  It seemed I had a problem with JAI.</p>
<p>On a past RoR project I used a plugin that facilitated file uploads on models.  It had a built-in thumbnailing feature that used ImageMagick for image processing.  I had a decent experience with it, so I decided to give it a shot.</p>
<p><strong>Pros:</strong> It is noticeably faster , the image quality is superb, and it supports modifying and saving gifs straight up.  You can even scale a jpeg and save it as a gif if you so desired.  Note that I wasn&#8217;t using mediaLib which speeds up processing, though quality is actually the biggest sticking point.</p>
<p><strong>Con:</strong> I&#8217;m interfacing ImageMagick using Groovy&#8217;s String.execute() method (a wrapper for ProcessBuilder).  Not that this is an ImageMagick problem, as there is a JMagick library that uses JNI to interop.  However, judging from some reports on the intartubes, there haven&#8217;t been too many success stories.</p>
<p>If your still interested here&#8217;s how it went down:</p>
<h3>1. Installed ImageMagick</h3>
<p><a href="http://www.imagemagick.org/script/binary-releases.php">Downloaded and installed ImageMagick</a><br />
</p>
<h3>2. Installed Hibernate Events Plugin</h3>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">grails install-plugin http:<span class="sy0">//</span>thegioraproject.com<span class="sy0">/</span>files<span class="sy0">/</span>grails<span class="sy0">/</span>plugins<span class="sy0">/</span>grails-hibernate-events<span class="nu0">-0.2</span>.<span class="kw2">zip</span></div>
</li>
</ol>
</div>
<p></p>
<h3>3. Created a generic Attachment Domain class</h3>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">import grails.util.GrailsUtil</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.springframework.web.multipart.MultipartFile</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.codehaus.groovy.grails.commons.ConfigurationHolder</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">class</span> Attachment <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Allows us to have spring bind the file automatically. &lt;input name=&quot;attachment.file&quot; type=&quot;file&quot; /&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; MultipartFile file</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Save file metadata to the database</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> contentType</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> fileName</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ALong+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Long</span></a> size &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Don&#8217;t try to save the MultipartFile. &nbsp;Hibernate will barf all over you.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">static</span> transients = <span class="br0">&#91;</span><span class="st0">&quot;file&quot;</span><span class="br0">&#93;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Location for saving files i.e. /home/me/app_files/attachments/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def baseDir = <span class="br0">&#123;</span> ConfigurationHolder.<span class="me1">config</span>.<span class="me1">paperclip</span>.<span class="me1">files</span>.<span class="me1">dir</span><span class="br0">&#91;</span>GrailsUtil.<span class="me1">environment</span><span class="br0">&#93;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Use Hibernate Events Plugin to save the file after it&#8217;s metadata has been saved.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; def afterInsert = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; writeFile<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Create a unique directory to store the file based on the saved id. Produces a two deep</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//directory to stave off the 32000 hard link limit on ext3 filesystem. &nbsp;So the path might look</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//like 0000/0001/filename.extension</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//see: http://thegioraproject.com/2008/03/02/workaround-for-subdirectory-limit-on-ext3-filesystem/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def directory = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; def stringId = id.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; def fullId = stringId.<span class="me1">padLeft</span><span class="br0">&#40;</span><span class="nu0">8</span>, <span class="st0">&quot;0&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>fullId<span class="br0">&#91;</span><span class="nu0">0</span>..<span class="nu0">3</span><span class="br0">&#93;</span>, fullId<span class="br0">&#91;</span><span class="nu0">4</span>..<span class="nu0">7</span><span class="br0">&#93;</span><span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;/&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Joins the directory and filename to create a path. &nbsp;Useful for creating links on views: can call</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//attachment.path() to produce href.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def path = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>directory<span class="br0">&#40;</span><span class="br0">&#41;</span>, fileName<span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;/&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//Location on disk to write the file to.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def absolutePath = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>baseDir<span class="br0">&#40;</span><span class="br0">&#41;</span>, path<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;/&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//Writes the file to the disk making sure all parent directories are present</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw4">void</span> writeFile<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; def destination = <span class="kw2">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">File</span></a><span class="br0">&#40;</span>absolutePath<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; destination.<span class="me1">mkdirs</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; file.<span class="me1">transferTo</span><span class="br0">&#40;</span>destination<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//When Spring binds the file to the object we set the metadata for the file on the object.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Eliminates some setter code.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setFile<span class="br0">&#40;</span>MultipartFile upload<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; file = upload</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; contentType = upload.<span class="me1">contentType</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; fileName = upload.<span class="me1">originalFilename</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; size = upload.<span class="me1">size</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p></p>
<h3>4. Created an Image Domain class</h3>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">import grails.util.GrailsUtil</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import org.codehaus.groovy.grails.commons.ConfigurationHolder</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AImage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Image</span></a> <span class="kw2">extends</span> Attachment <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//Root directory of the ImageMagick install determined by the environment. &nbsp;So if we&#8217;re using</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//development it will get the config variable paperclip.magick.dir.development from Config.groovy</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def magickDir = <span class="br0">&#123;</span> ConfigurationHolder.<span class="me1">config</span>.<span class="me1">paperclip</span>.<span class="me1">magick</span>.<span class="me1">dir</span><span class="br0">&#91;</span>GrailsUtil.<span class="me1">environment</span><span class="br0">&#93;</span> <span class="br0">&#125;</span> &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//After saving make sure we save the original by calling writeFile() on Attachment,</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//then create the thumbnails</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def afterInsert = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; writeFile<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; createThumbnails<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Location on disk to write the thumbnail to</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def absoluteThumbnail = <span class="br0">&#123;</span>type -<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>baseDir<span class="br0">&#40;</span><span class="br0">&#41;</span>, thumbnail<span class="br0">&#40;</span>type<span class="br0">&#41;</span><span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;/&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Kind of like path on Attachment. &nbsp;Allows us to call attachment.thumbnail(&quot;300&quot;) on the view to</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//produce an img src.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def thumbnail = <span class="br0">&#123;</span>type -<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; def tokens = fileName.<span class="me1">tokenize</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; def name = <span class="br0">&#91;</span>tokens<span class="br0">&#91;</span><span class="nu0">0</span>..<span class="nu0">-2</span><span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="br0">&#41;</span>, type, tokens<span class="br0">&#91;</span><span class="nu0">-1</span><span class="br0">&#93;</span><span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>directory<span class="br0">&#40;</span><span class="br0">&#41;</span>, name<span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&quot;/&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//The meat of it all. &nbsp;It gets a little lost because there isn&#8217;t a lot of code. &nbsp;So we loop over</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//an array to produce two thumbnails. &nbsp;One will be 100&#215;100, the other will be 300&#215;300. &nbsp;However</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//ImageMagick will keep the images aspect ratio using the geometry we supplied. &nbsp;This method will</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//create a string like &quot;/ImageMagick/convert /path/image.jpg -thumbnail 100&#215;100 /path/image.100.jpg&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//and then execute it as if you were on the command line. &nbsp;The ImageMagick command will resize and</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//save the image to the supplied dir. &nbsp;The execute() call returns a process object which we call</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">//waitFor on to make sure the processing finishes before we move on. &nbsp;We can also get the exit code</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//from the process to handle exceptions.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//More info ongeometry flags and resizing here: http://www.imagemagick.org/Usage/resize/#resize.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//It is very flexible.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw4">void</span> createThumbnails<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="nu0">300</span>, <span class="nu0">100</span><span class="br0">&#93;</span>.<span class="me1">each</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def process = <span class="st0">&quot;${magickDir()}/convert ${absolutePath()} -thumbnail ${it}x${it} ${absoluteThumbnail(it)}&quot;</span>.<span class="me1">execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; process.<span class="me1">waitFor</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>
Hopefully the comments explain how everything works together.  If you have questions, comments or criticism, please let me know.  And yes, I feel a little dirty calling another program in a process, but when it works this well, getting a little dirty feels pretty good.</p>
<p>Image comparison (my youngest, Ariana):</p>
<p>ImageMagick<br />
<img src="http://thegioraproject.com/wp-content/uploads/2008/03/arianamagick100.JPG" alt="ImageMagick 100px Thumb" /></p>
<p>ImageTool (JAI)<br />
<img src="http://thegioraproject.com/wp-content/uploads/2008/03/arianaimagetool100.jpg" alt="ImageTool(JAI) 100px Thumb" /></p>
<p>ImageMagick<br />
<img src="http://thegioraproject.com/wp-content/uploads/2008/03/arianamagick300.JPG" alt="arianamagick300.JPG" /></p>
<p>ImageTool (JAI)<br />
<img src="http://thegioraproject.com/wp-content/uploads/2008/03/arianaimagetool300.jpg" alt="arianaimagetool300.jpg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://thegioraproject.com/2008/03/26/image-attachments-in-grails-using-imagemagick/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hibernate events plugin v0.2</title>
		<link>http://thegioraproject.com/2008/03/24/hibernate-events-plugin-v02/</link>
		<comments>http://thegioraproject.com/2008/03/24/hibernate-events-plugin-v02/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 15:41:06 +0000</pubDate>
		<dc:creator>Kevin Burke</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://thegioraproject.com/2008/03/24/hibernate-events-plugin-v02/</guid>
		<description><![CDATA[What, another release already?  Yep, we&#8217;re releasing another version of the grails hibernate events plugin.  Well, obviously I wasn&#8217;t paying attention in grails/hibernate class and it turns out that while it requires a hibernate.cfg.xml to participate in the creation of the SessionFactory, you can still programmatically add event listeners to the SessionFactory after its [...]]]></description>
			<content:encoded><![CDATA[<p>What, another release already?  Yep, we&#8217;re releasing another version of the <a href="http://thegioraproject.com/2008/03/22/hibernate-events-plugin/">grails hibernate events plugin</a>.  Well, obviously I wasn&#8217;t paying attention in grails/hibernate class and it turns out that while it requires a hibernate.cfg.xml to participate in the creation of the SessionFactory, you can still programmatically add event listeners to the SessionFactory after its been created.  Big ups to Burt Beckwith  for the tip (who, judging by the grails mailing list alone, has every api under the sun memorized!).  So here is the hibernate events plugin sans hibernate.cfg.xml:</p>
<p><a href="http://thegioraproject.com/files/grails/plugins/grails-hibernate-events-0.2.zip">http://thegioraproject.com/files/grails/plugins/grails-hibernate-events-0.2.zip</a></p>
<p>And again, any feedback is much appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://thegioraproject.com/2008/03/24/hibernate-events-plugin-v02/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hibernate events plugin</title>
		<link>http://thegioraproject.com/2008/03/22/hibernate-events-plugin/</link>
		<comments>http://thegioraproject.com/2008/03/22/hibernate-events-plugin/#comments</comments>
		<pubDate>Sat, 22 Mar 2008 18:52:29 +0000</pubDate>
		<dc:creator>Kevin Burke</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://thegioraproject.com/2008/03/22/hibernate-events-plugin/</guid>
		<description><![CDATA[On a current grails project I had a need to act on my domain classes using hibernate&#8217;s persistence lifecycle.  However, it turns out that grails only provides three lifecycle methods: beforeInsert, beforeUpdate, beforeDelete.  Four if you count onLoad.  I was really interested in having an afterInsert method so that I could save [...]]]></description>
			<content:encoded><![CDATA[<p>On a current grails project I had a need to act on my domain classes using hibernate&#8217;s persistence lifecycle.  However, it turns out that grails only provides three lifecycle methods: beforeInsert, beforeUpdate, beforeDelete.  Four if you count onLoad.  I was really interested in having an afterInsert method so that I could save a file to the filesystem after it&#8217;s metadata had been saved to the database.  So I used the <a href="http://www.hibernate.org/hib_docs/reference/en/html/events.html">hibernate event system</a> to round out the lifecycle methods with seven more hooks:</p>
<ul>
<li>afterInsert</li>
<li>afterUpdate</li>
<li>afterDelete</li>
<li>beforeLoad</li>
<li>afterLoad</li>
<li>beforeSave</li>
<li>afterSave</li>
</ul>
<p>So if a domain model contains a closure with any of these names they will be called during their turn in the lifecycle.  I think they are mostly self explanatory except for before/afterSave.  The purpose for these methods is to be called when the persistence call is either an insert or an update.  So if you don&#8217;t care if the object is being saved for the first time or being updated you can use this method.</p>
<p>Unfortunately the plugin uses a hibernate.cfg.xml, because it is the only way you can participate in the creation of the SessionFactory.</p>
<p>I haven&#8217;t decided if I will release the plugin yet.  Maybe if there is interest.</p>
<p><strong>Update: </strong>Ok, so some interest was expressed.  Here it is: <a href="http://thegioraproject.com/files/grails/plugins/grails-hibernate-events-0.1.zip">http://thegioraproject.com/files/grails/plugins/grails-hibernate-events-0.1.zip</a>.  Feedback is always welcome.</p>
<p><strong>Update 2</strong>: I&#8217;ve added a doc page to the grails wiki.  Not really much is needed, but it could clear things up a bit.  <a href="http://docs.codehaus.org/display/GRAILS/Hibernate+Events+Plugin">http://docs.codehaus.org/display/GRAILS/Hibernate+Events+Plugin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://thegioraproject.com/2008/03/22/hibernate-events-plugin/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dead simple dependencies with grails + ivy</title>
		<link>http://thegioraproject.com/2008/02/26/dead-simple-dependencies-with-grails-ivy/</link>
		<comments>http://thegioraproject.com/2008/02/26/dead-simple-dependencies-with-grails-ivy/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 19:30:34 +0000</pubDate>
		<dc:creator>Kevin Burke</dc:creator>
		
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://thegioraproject.com/2008/02/26/dead-simple-dependencies-with-grails-ivy/</guid>
		<description><![CDATA[It is unbelievably easy to integrate Ivy as a dependency manager for your grails application.  Just a couple of steps really (Note: this is for grails &#62;= 1.0 as &#60; 1.0 had ivy integrated):

           Install the Ivy plugin:



grails install-plugin ivy



This will create an ivy.xml [...]]]></description>
			<content:encoded><![CDATA[<p>It is unbelievably easy to integrate Ivy as a dependency manager for your grails application.  Just a couple of steps really (Note: this is for grails &gt;= 1.0 as &lt; 1.0 had ivy integrated):</p>
<ol>
<li>           Install the Ivy plugin:
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">grails install-plugin ivy</div>
</li>
</ol>
</div>
<p>This will create an ivy.xml and an ivyconf.xml, and place them in the project root.  I modified my ivy.xml thusly:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;ivy-module</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;info</span> <span class="re0">organisation</span>=<span class="st0">&quot;codehaus&quot;</span> <span class="re0">module</span>=<span class="st0">&quot;grails&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;dependencies<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;dependency</span> <span class="re0">org</span>=<span class="st0">&quot;mysql&quot;</span> <span class="re0">name</span>=<span class="st0">&quot;mysql-connector-java&quot;</span> <span class="re0">rev</span>=<span class="st0">&quot;5.0.5&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/dependencies<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/ivy-module<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
</li>
<li>          You can then run the following command and ivy will place your dependencies in the lib folder of your project root:
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">grails get-dependencies</div>
</li>
</ol>
</div>
</li>
</ol>
<p>That&#8217;s it!  Now I just need to figure out why they don&#8217;t really use this as a selling point for grails.  The only thing I can figure is that there are so many great features it would get lost in the list anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://thegioraproject.com/2008/02/26/dead-simple-dependencies-with-grails-ivy/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
