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

<channel>
	<title>REVERT TO CONSOLE &#187; CodeSnippets</title>
	<atom:link href="http://www.reverttoconsole.com/blog/category/codesnippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reverttoconsole.com</link>
	<description>for f in *;do echo &#124; sed 'i\rtc' &#62;&#62; $f;done;</description>
	<lastBuildDate>Sat, 10 Jul 2010 12:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Quick command line spell check of a single word or sentence</title>
		<link>http://www.reverttoconsole.com/blog/nix/quick-command-line-spell-check-of-a-single-word-or-sentence/</link>
		<comments>http://www.reverttoconsole.com/blog/nix/quick-command-line-spell-check-of-a-single-word-or-sentence/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:43:53 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[*NIX]]></category>
		<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Cygwin]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=413</guid>
		<description><![CDATA[Here&#8217;s a short bash script, using aspell, to spell check a word or several words from the command line. It&#8217;s simple but effective. If anyone else knows a cleaner or even simpler way, please let us know. #!/bin/bash WORD=$1 TEMPFILE=temp.spell echo $WORD > $TEMPFILE aspell -c $TEMPFILE cat $TEMPFILE rm -f $TEMPFILE rm -f $TEMPFILE.bak [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a short bash script, using aspell, to spell check a word or several words from the command line.  It&#8217;s simple but effective.  If anyone else knows a cleaner or even simpler way, please let us know.</p>
<p><code><br />
#!/bin/bash</p>
<p>WORD=$1<br />
TEMPFILE=temp.spell</p>
<p>echo $WORD > $TEMPFILE<br />
aspell -c $TEMPFILE<br />
cat $TEMPFILE<br />
rm -f $TEMPFILE<br />
rm -f $TEMPFILE.bak<br />
</code></p>
<p>I named this script &#8220;spell&#8221;.  Simply use it like so:<br />
<code><br />
$ spell reccomend<br />
</code></p>
<p>Aspell will run and you can make your changes.<br />
<code><br />
reccomend</p>
<p>1) recommends                           6) commend<br />
2) recommend                            7) recommenced<br />
3) reckoned                             <img src='http://www.reverttoconsole.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> recommended<br />
4) regiment                             9) Redmond<br />
5) recombined                           0) rejoined<br />
i) Ignore                               I) Ignore all<br />
r) Replace                              R) Replace all<br />
a) Add                                  l) Add Lower<br />
b) Abort                                x) Exit<br />
</code></p>
<p>In this case, if I type &#8220;2&#8243;, the correction will be made, aspell will exit and the spelling I chose gets printed out.</p>
<p>Here&#8217;s an example of how to use it with a sentence.<br />
<code><br />
$ spell "I go to the storede and buy beakh clotes"<br />
</code></p>
<p>Now aspell will take you through each misspelled word.  After you finish the corrections it will exit and print out the corrected sentence or series of words.<br />
<code><br />
I go to the store and buy beach clothes<br />
</code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fnix%2Fquick-command-line-spell-check-of-a-single-word-or-sentence%2F&amp;title=Quick+command+line+spell+check+of+a+single+word+or+sentence" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/nix/quick-command-line-spell-check-of-a-single-word-or-sentence/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dirt Simple EXTJS Grid on Grails</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/dirt-simple-extjs-grid-on-grails/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/dirt-simple-extjs-grid-on-grails/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 21:37:53 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=223</guid>
		<description><![CDATA[At my current contract, I&#8217;ve been using the popular EXTJS javascript library. In order to get up to speed faster, I&#8217;ve started a small project to assist my learning. I thought about using a number of back ends to support my project, but decided on Grails after reading about the built-in JSON converters. Getting started [...]]]></description>
			<content:encoded><![CDATA[<p>At my current contract, I&#8217;ve been using the popular <a href="http://extjs.com/">EXTJS </a>javascript library. In order to get up to speed faster, I&#8217;ve started a small project to assist my learning.</p>
<p>I thought about using a number of back ends to support my project, but decided on Grails after reading about the built-in JSON converters.</p>
<p><strong>Getting started note</strong>: Since this is a dirt simple example, I copied extjs into the web-app/js directory. <a href="http://jlorenzen.blogspot.com/2008/08/getting-started-with-grails-and-extjs.html">James Lorenzen looks like he has a better way</a>, and there <a href="http://grails.org/Ext+Plugin">might be a plugin some day</a>.</p>
<p>I started with a simple GORM object, Media, which looks like this:</p>
<pre class="brush: java">
class Media {

	static constraints = {
		releaseDate(nullable: true)
	}

	String title
	Date releaseDate
	Date dateCreated
	Date lastUpdated
}
</pre>
<p>Next I added some startup data by adding it to to Bootstrap.groovy class:</p>
<pre class="brush: java">
     	def m = new Media(releaseDate:null, title: &#039;Test&#039;)
     	m.save()
</pre>
<p>And added a controller:</p>
<pre class="brush: java">
import grails.converters.*

class MediaController {

    def view = {

    }

    def list = {
   	def listResult = [ total: Media.count(), items: Media.list(params)]
        render listResult as JSON
    }
}
</pre>
<p>And I now have a Grails back end that will deliver JSON to extjs! Off to the front end!</p>
<p>First I modified my layout, main.gsp, to add the extjs js and css files:</p>
<pre class="brush: html">
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;g:layoutTitle default=&quot;Grails&quot; /&gt;&lt;/title&gt;

		&lt;link rel=&quot;stylesheet&quot; href=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/resources/css/ext-all.css&#039;)}&quot;&gt;&lt;/link&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/resources/css/theme-aero.css&#039;)}&quot;&gt;&lt;/link&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/adapter/ext/ext-base.js&#039;)}&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/ext-all-debug.js&#039;)}&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
			Ext.BLANK_IMAGE_URL = &quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;ext-2.2/resources/images/default/s.gif&#039;)}&quot;;
		&lt;/script&gt;
		&lt;g:layoutHead /&gt;

	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;container&quot;&gt;
			&lt;div id=&quot;content&quot;&gt;
				&lt;div id=&quot;include&quot;&gt;
					&lt;g:layoutBody /&gt;
				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>and added my view.gsp:</p>
<pre class="brush: html">
&lt;html&gt;
	&lt;head&gt;
		&lt;meta name=&quot;layout&quot; content=&quot;main&quot; /&gt;
		&lt;title&gt;Decorated&lt;/title&gt;
		&lt;script type=&quot;text/javascript&quot; src=&quot;${createLinkTo(dir:&#039;js&#039;,file:&#039;oscar.js&#039;)}&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id=&quot;center-div&quot;&gt;&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>and lastly, my js file, taken nearly verbatim from an extjs example:</p>
<pre class="brush: javascript">
/*
 * Ext JS Library 2.0 Beta 1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 */

Ext.onReady(function(){

    // create the Data Store
    var ds = new Ext.data.Store({
       autoLoad: true,
       proxy: new Ext.data.HttpProxy({
       url: &#039;http://localhost:8080/oscar/media/list&#039;}),
       reader: new Ext.data.JsonReader({
       	results: &#039;total&#039;,
       	root:&#039;items&#039;,
       	id:&#039;id&#039;
       },
       [
               {name: &#039;title&#039;},
               {name: &#039;dateCreated&#039;},
               {name: &#039;lastUpdated&#039;},
               {name: &#039;releaseDate&#039;}
          ]
       )
    });

    var cm = new Ext.grid.ColumnModel([
	    {header: &quot;Title&quot;, width: 120, dataIndex: &#039;title&#039;},
		{header: &quot;Created Date&quot;, width: 180, dataIndex: &#039;dateCreated&#039;},
		{header: &quot;Last Updated&quot;, width: 115, dataIndex: &#039;lastUpdated&#039;},
		{header: &quot;releaseDate&quot;, width: 100, dataIndex: &#039;releaseDate&#039;}
	]);
    cm.defaultSortable = true;

    // create the grid
    var grid = new Ext.grid.GridPanel({
        ds: ds,
        cm: cm,
        renderTo:&#039;center-div&#039;,
        width:540,
        height:200
    });
});
</pre>
<p><a href="http://svn.reverttoconsole.com/rtc/oscar/">My code is checked in here</a>.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fdirt-simple-extjs-grid-on-grails%2F&amp;title=Dirt+Simple+EXTJS+Grid+on+Grails" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/dirt-simple-extjs-grid-on-grails/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>SVN Log History By User to HTML</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/svn-log-history-by-user-to-html/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/svn-log-history-by-user-to-html/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 16:25:51 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=218</guid>
		<description><![CDATA[Most SVN users who use the command line client understand how to create a log in XML format: svn log --xml -v svn://some/url &#62; svnlog.xml But this dumps the whole log, and I really just want to see a specific user. Plus, I hate XML and definitely do not want to read it. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Most SVN users who <a href="http://reverttoconsole.com/wiki/index.php?title=Command_Line_Cheatsheet">use the command line client</a> understand how to create a log in XML format:</p>
<pre class="brush: java">
svn log --xml -v svn://some/url &gt; svnlog.xml
</pre>
<p>But this dumps the whole log, and I really just want to see a specific user. Plus, I hate XML and definitely do not want to read it.</p>
<p>Here is a handy stylesheet:</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot;
xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;

&lt;xsl:template match=&quot;/&quot;&gt;
&lt;html&gt;
&lt;body&gt;
        &lt;h2&gt;Header&lt;/h2&gt;
        &lt;table border=&quot;1&quot;&gt;
                &lt;xsl:for-each select=&quot;log/logentry&quot;&gt;
                        &lt;xsl:if test=&quot;author=&#039;YOUR_NAME_HERE&#039;&quot;&gt;
                                &lt;tr&gt;
                                        &lt;td&gt;&lt;xsl:value-of
select=&quot;@revision&quot;/&gt;&lt;/td&gt;
                                        &lt;td&gt;&lt;xsl:value-of
select=&quot;author&quot;/&gt;&lt;/td&gt;
                                        &lt;td&gt;&lt;xsl:value-of
select=&quot;date&quot;/&gt;&lt;/td&gt;
                                        &lt;td&gt;&lt;xsl:value-of
select=&quot;msg&quot;/&gt;&lt;/td&gt;
                                &lt;/tr&gt;
                                &lt;xsl:for-each select=&quot;paths/path&quot;&gt;
                                        &lt;tr&gt;
                                                &lt;td&gt;&lt;/td&gt;
                                                &lt;td&gt;&lt;xsl:value-of
select=&quot;@action&quot;/&gt;&lt;/td&gt;
                                                &lt;td&gt;&lt;xsl:value-of
select=&quot;.&quot;/&gt;&lt;/td&gt;
                                        &lt;/tr&gt;
                                &lt;/xsl:for-each&gt;
                        &lt;/xsl:if&gt;
                &lt;/xsl:for-each&gt;
        &lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
<p>Simply add a header line to your output log, like this:</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;mystylesheet.xsl&quot;?&gt;
&lt;log&gt;
&lt;logentry
   revision=&quot;6610&quot;&gt;
</pre>
<p>Add the username you wish to filter on in the stylesheet (in place of <em>YOUR_NAME_HERE</em>), and open the log file in the browser.</p>
<p>Hat tip to:<br />
<a href="http://svn.haxx.se/users/archive-2008-04/0703.shtml">Subversion Users mailing list</a><br />
<a href="http://www.w3schools.com/xsl/xsl_transformation.asp">w3schools how to use xslt</a></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsvn-log-history-by-user-to-html%2F&amp;title=SVN+Log+History+By+User+to+HTML" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/svn-log-history-by-user-to-html/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A simple java.util.Date to java.sql.Date converter</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/a-simple-javautildate-to-javasqldate-converter/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/a-simple-javautildate-to-javasqldate-converter/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 15:26:39 +0000</pubDate>
		<dc:creator>Priyatam</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=206</guid>
		<description><![CDATA[If you&#8217;re using JSF and need a converter for converting UI elements (typically java.util.Date) to your domain object&#8217;s date field (typically java.sql.Date), here&#8217;s the code snippet, public class DateConverter implements Converter, Serializable { public Object getAsObject(FacesContext context, UIComponent component, String value) { java.sql.Date sqlDate = null; Calendar cal = null; if (value != null &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using JSF and need a converter for converting UI elements (typically java.util.Date) to  your domain object&#8217;s date field (typically java.sql.Date), here&#8217;s the code snippet,</p>
<pre class="brush: java">
public class DateConverter implements Converter, Serializable {
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
	    java.sql.Date sqlDate = null;
	    Calendar cal = null;

	    if (value != null &amp;&amp; value.length() &gt; 0) {
	      DateFormat df = new SimpleDateFormat(&quot;dd-MMM-yy&quot;);

	      try {
	    	  Date utilDate = df.parse(value);
	          cal = new GregorianCalendar();
	          cal.setTime(utilDate);
	    	  sqlDate = new java.sql.Date(utilDate.getTime());
	      }
	      catch (ParseException e) {
	        throw new ConverterException(e);
	      }
	    }
	    return sqlDate;
	  }

	  public String getAsString(FacesContext context, UIComponent component, Object value) {
	    String dateString = null;
	    if (value != null) {
	      if (value instanceof String) {
	        dateString = (String) value;
	      }
	      else {
	        DateFormat df = new SimpleDateFormat(&quot;dd-MMM-yy&quot;);
	        if (value instanceof java.sql.Date) {
	        	Date date = new Date(((java.sql.Date)value).getTime());
	 	        dateString = df.format(date);
	        }
	      }
	    }
	     return dateString;
	  }
}
</pre>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fa-simple-javautildate-to-javasqldate-converter%2F&amp;title=A+simple+java.util.Date+to+java.sql.Date+converter" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/a-simple-javautildate-to-javasqldate-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending Hibernate Validator for BigDecimal Range validation</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/extending-hibernate-validator-for-bigdecimal-range-validation/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/extending-hibernate-validator-for-bigdecimal-range-validation/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 14:22:59 +0000</pubDate>
		<dc:creator>Priyatam</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/189</guid>
		<description><![CDATA[Hibernate Validator is a very precise framework written in the hibernate umbrella of frameworks. Using the inbuilt validators should solve most of your column constraints. However, if you have Decimal types (Float, Double of BigDecimal), there is no inbuilt validator to validate both the precision and scale. Also, I&#8217;ve stopped using Doubles and Floats in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.hibernate.org/hib_docs/validator/reference/en/html_single/">Hibernate Validator</a> is a very precise framework written in the hibernate umbrella of frameworks. Using the inbuilt validators should solve most of your column constraints. However, if you have Decimal types (Float, Double of BigDecimal), there is no inbuilt validator to validate both the precision and scale. Also, I&#8217;ve stopped using Doubles and Floats in bargain with BigDecimal as:-<br />
1) BigDecimal has better control over math functions<br />
2) It generates the correct column type, is Number(precison, scale) in most databases when used with hbm2ddl Tool</p>
<p>I&#8217;ve written two classes for validating the range (minimum and maximum) of BigDecimal types, extending HibernateValidator. It&#8217;s as good as annotating like this, for your property</p>
<pre class="brush: java">
 @BigDecimalRange(minPrecision=0, maxPrecision=13, scale=2)
 	public BigDecimal getFoo() {
 		return this.foo;
 }</pre>
<p><strong>BigDecimalRange</strong></p>
<pre class="brush: java">
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import org.hibernate.validator.ValidatorClass;

/**
 * The annotated element has to be in the appropriate range. Apply on BigDecimal values.
 */
@Documented
@ValidatorClass(BigDecimalRangeValidator.class)
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface BigDecimalRange {
	long minPrecision() default Long.MIN_VALUE;
	long maxPrecision() default Long.MAX_VALUE;
	int scale() default 0;

	String message() default &quot;precision must be in the range of {minPrecision} to {maxPrecision} with scale&amp;lt;= {scale}&quot;;
}</pre>
<p><strong>BigDecimalRangeValidator</strong></p>
<pre class="brush: java">
import java.io.Serializable;
import java.math.BigDecimal;
import org.hibernate.validator.Validator;

/**
 * The value has to be in a defined range with precision &amp;amp; scale
 */
public class BigDecimalRangeValidator implements Validator&lt;bigdecimalrange&gt;, Serializable {;

	private long minPrecision;
	private long maxPrecision;
	private int scale;

	public void initialize(BigDecimalRange parameters) {
		minPrecision = parameters.minPrecision();
		maxPrecision = parameters.maxPrecision();
		scale = parameters.scale();
	}

	public boolean isValid(Object value) {
		if ( value == null ) return true;
		else if ( value instanceof BigDecimal ) {
			int _precision = ((BigDecimal)value).precision();
			int _scale = ((BigDecimal)value).scale();
			return (_precision &gt;= minPrecision &amp;&amp; _precision &lt;= maxPrecision &amp;&amp; _scale &lt;= scale);
		}
		else {
			return false;
		}
	}
}
</pre>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fextending-hibernate-validator-for-bigdecimal-range-validation%2F&amp;title=Extending+Hibernate+Validator+for+BigDecimal+Range+validation" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/extending-hibernate-validator-for-bigdecimal-range-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Commons StringUtils Is Your Friend</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/commons-stringutils-is-your-friend/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/commons-stringutils-is-your-friend/#comments</comments>
		<pubDate>Wed, 14 May 2008 14:34:08 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[UnitTest]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/181</guid>
		<description><![CDATA[I have just completed a test for a method that parses a forward-slash delimited String: private static final String PROJECTID_STR_1 = &#34;&#34;; private static final String PROJECTID_STR_2 = &#34;101/103/102/104/105/106/107&#34;; private static final String PROJECTID_STR_3 = &#34;///103/104&#34;; private static final String PROJECTID_STR_4 = &#34;a/b/102/104/105/106/107&#34;; @Test public void testParseProjectIds1() { List&#60;integer&#62; projectIdList1 = getViewBillingReportController().parseProjectIds(PROJECTID_STR_1); assertTrue(projectIdList1.size() == 0); [...]]]></description>
			<content:encoded><![CDATA[<p>I have just completed a test for a method that parses a forward-slash delimited String:</p>
<pre class="brush: java">
	private static final String PROJECTID_STR_1 = &quot;&quot;;
	private static final String PROJECTID_STR_2 = &quot;101/103/102/104/105/106/107&quot;;
	private static final String PROJECTID_STR_3 = &quot;///103/104&quot;;
	private static final String PROJECTID_STR_4 = &quot;a/b/102/104/105/106/107&quot;;

	@Test
	public void testParseProjectIds1() {
		List&lt;integer&gt; projectIdList1 =
			getViewBillingReportController().parseProjectIds(PROJECTID_STR_1);
		assertTrue(projectIdList1.size() == 0);
	}

	@Test
	public void testParseProjectIds2() {
		List&lt;integer&gt; projectIdList2 =
			getViewBillingReportController().parseProjectIds(PROJECTID_STR_2);
		assertTrue(projectIdList2.size() == 7);
	}

	@Test
	public void testParseProjectIds3() {
		List&lt;integer&gt; projectIdList3 =
			getViewBillingReportController().parseProjectIds(PROJECTID_STR_3);
		assertTrue(projectIdList3.size() == 2);
	}

	@Test
	public void testParseProjectIds4() {
		List&lt;integer&gt; projectIdList4 =
			getViewBillingReportController().parseProjectIds(PROJECTID_STR_4);
		assertTrue(projectIdList4.size() == 5);
	}
</pre>
<p>This test initially failed all but one of the assertions (it passed the happy path).</p>
<p>The initial method looked like this:</p>
<pre class="brush: java">
    public List&lt;integer&gt; parseProjectIds(String projectIdsStr) {
    	ArrayList&lt;integer&gt; result = new ArrayList&lt;integer&gt;();
    	int lastDelimiterLoc = -1;
    	boolean done = false;
    	while (!done) {
    		int delimiterLoc = projectIdsStr.indexOf(&#039;/&#039;, lastDelimiterLoc + 1);
    		if (delimiterLoc &gt;= 0) {
    			String idStr = projectIdsStr.substring(lastDelimiterLoc + 1, delimiterLoc);
    			Integer id = new Integer(idStr);
   			result.add(id);
    			lastDelimiterLoc = delimiterLoc;
    		} else {
    			delimiterLoc = projectIdsStr.length();
    			String idStr = projectIdsStr.substring(lastDelimiterLoc + 1, delimiterLoc);
    			Integer id = new Integer(idStr);
    			result.add(id);
    			done = true;
    		}
        }
    	return result;
    }
</pre>
<p>I don&#8217;t know why the developer on this would have done it this way, since we already had <a href="http://commons.apache.org/lang/">Commons Lang</a> available in the classpath. But after a quick refactoring I came up with this:</p>
<pre class="brush: java">
public List&lt;integer&gt; parseProjectIds(String projectIdsStr) {
    	ArrayList&lt;integer&gt; result = new ArrayList&lt;integer&gt;();
    	if(StringUtils.isNotBlank(projectIdsStr)) {
    		String[] parsedList = StringUtils.split(projectIdsStr, &quot;/&quot;);
    		for( int i =0; i &lt; parsedList.length; i++) {
    			if( StringUtils.isNotEmpty(parsedList[i])){
    				if( StringUtils.isNumeric(parsedList[i])) {
    					result.add(new Integer(parsedList[i]));
    				}
    			}
    		}
    	}
    	return result;
    }
</pre>
<p>This passed all my tests, and seems much more readable. This is how <a href="http://commons.apache.org/lang/api/org/apache/commons/lang/StringUtils.html">StringUtils</a> rocks!</p>
<p>PS- StringUtils.isNotBlank also handles null values.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fcommons-stringutils-is-your-friend%2F&amp;title=Commons+StringUtils+Is+Your+Friend" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/commons-stringutils-is-your-friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Step by Step Tutorials &#8211; DWR with Spring, Ajax &#8211; Dynamic drop down lists</title>
		<link>http://www.reverttoconsole.com/blog/ajax/step-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists/</link>
		<comments>http://www.reverttoconsole.com/blog/ajax/step-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 21:53:49 +0000</pubDate>
		<dc:creator>Priyatam</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Con-(in)sulting]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/146</guid>
		<description><![CDATA[Scenario: A simple jsp page with a standard drop down box. A Selection criteria (could be another drop down box and a couple of check boxes) to change the values in these drop down box dynamically, without submitting the page. What you will learn: Configure dwr.xml with spring beans Configure application contexts for dwr beans [...]]]></description>
			<content:encoded><![CDATA[<p><b>Scenario:</b> A simple jsp page with a standard drop down box. A Selection criteria (could be another drop down box and a couple of check boxes) to change the values in these drop down box dynamically, without submitting the page.</p>
<p>What you will learn:</p>
<ol>
<li>Configure dwr.xml with spring beans</li>
<li>Configure application contexts for dwr beans
<li>The basic structure of the jsp for dwr</li>
<li>The necessary js that executes the ajax call along with the code for rendering the new drop down values</li>
<li>Finally, the facade (ajax handler) in Java, for the action</li>
</ol>
<p><strong>1. Configure dwr.xml with spring beans</strong></p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;dwr&gt;
&lt;allow&gt;
	&lt;create creator=&quot;spring&quot; javascript=&quot;ListOptionsAjaxFacade&quot;&gt;
		&lt;param name=&quot;beanName&quot; value=&quot;listOptionsAjaxFacade&quot; /&gt;
	&lt;/create&gt;
	&lt;convert converter=&quot;bean&quot; match=&quot;com.reverttoconsole.domain.*&quot; /&gt;
&lt;/allow&gt;
&lt;/dwr&gt;
</pre>
<p>listOptionsAjaxFacade is the bean name you would want configure in Spring&#8217;s application context. The advantage of using beans and  creator=&#8221;spring&#8221; here is that all your dependencies can be autowired by default with your existing Spring container. So if you have two dao dependencies in listOptionsAjaxFacade, you can now use your existing application context to resolve dependencies. Simply add autowire=&#8221;byType&#8221;. The converter=&#8221;bean&#8221; above ensures that all Types are converted to your domain object types. I assume a package structure for domain which are the only return types of my ajax handlers.</p>
<p><strong>2.Configure application contexts for dwr beans</strong></p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot;&gt;
	&lt;description&gt;
		This file defines DWR Ajax Facade Beans.
	&lt;/description&gt;
	&lt;bean id=&quot;listOptionsAjaxFacade&quot; class=&quot;com.reverttoconsole.domain.ListOptionsAjaxFacade&quot; autowire=&quot;byType&quot;/&gt;
&lt;/beans&gt;
</pre>
<p>I assume, you already have an application context(s) for all your controller, dao, services beans etc</p>
<p><strong>3.The basic structure of the jsp for dwr</strong></p>
<pre class="brush: xml">
&lt;html&gt;
&lt;head&gt;
&lt;!-- dwr ajax scripts--&gt;
&lt;script src=&quot;\&#039;dwr/interface/ListOptionsAjaxFacade.js\&#039;&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;\&#039;dwr/engine.js\&#039;&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;\&#039;dwr/util.js\&#039;&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
// contents of your jsp

&lt;select name=&quot;listOptions&quot; id=&quot;listOptions&quot;&gt;
    &lt;c:forEach items=&quot;${listOptions}&quot; var=&quot;item&quot;&gt;
        &lt;option value=&quot;${item.id}&quot;&gt;${item.description}&lt;/option&gt;
    &lt;/c:forEach&gt;
&lt;/select&gt;

&lt;select name=&quot;groupBy&quot; id=&quot;groupBy&quot;&gt;
       &lt;option value=&quot;name&quot;&gt;first name&lt;/option&gt;
       &lt;option value=&quot;name&quot;&gt;last name&lt;/option&gt;
       &lt;option value=&quot;name&quot;&gt;age&lt;/option&gt;
       &lt;option value=&quot;name&quot;&gt;city&lt;/option&gt;
&lt;/select&gt;
&lt;input type=&quot;checkbox&quot; name=&quot;isAscending&quot;&gt; Ascending
&lt;input type=&quot;button&quot; value=&quot;Refresh&quot; onclick=&quot;processListOptions()&quot;/&gt;

// other parts of jsp
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>As you see, include 3 js files on the top of your jsp. The js ListOptionsAjaxFacade.js is actually the name of the handler that you<br />
will see in a moment. The button &#8216;refresh&#8217; has a js handler processListOptions.</p>
<p><strong>4.The necessary js that executes the ajax call along with the code for rendering the new drop down values</strong><br />
Add the following js in the jsp</p>
<pre class="brush: javascript">
&lt;script&gt;
     function processListOptions(){
     	// get sortBy, isAscending values from current jsp elements
	    ListOptionsAjaxFacade.processListOptions(sortBy, isAscending,function(data){
		dwr.util.removeAllOptions(&quot;listOptions&quot;);
		DWRUtil.addOptions(&quot;listOptions&quot;,data,&quot;id&quot;,&quot;description&quot;);});
     }
&lt;/script&gt;
</pre>
<p>It retrieves the values of groupBy and ascendingorder fields from the current jsp and calls the ajax method processListOptions. Once retrieved, it uses the handy dwr.util method to replace all the list options with the new values. Note the callback function(date) used for this. Dwr replaces the return call from processListOptions and puts them in data (The complete java object collection)</p>
<p><strong>5.Finally, the facade (ajax handler) in Java, for the action </strong></p>
<pre class="brush: java">
public class ListOptionsAjaxFacade {
      private PersonDao personDao;

      public List processListOptions(String sortBy, boolean isAscending) {
       	return personDao.getAll(sortBy, isAscending);
      }

      //setters &amp; getters
}
</pre>
<p>Ofcourse, this is a happy-day-flow with no exception handling either in client side or server side, but you can add that later. Read the docs for DWR.<br />
Thats it. You should now be able to retrieve the lists dynamically</p>
<p><strong>Essential Reading:</strong><br />
Read more on <a href="http://getahead.org/dwr/browser/util">dwr.util</a> package. Just like drop down lists, you can pretty<br />
much create any other dynamic form element. The basic structure remains the same as above. Try using <a href="http://script.aculo.us/">scriptaculous </a>for fancy js effects in combination with the above code. For instance, on click of Refresh, you can fade in fade out the dropdown box.<br />
(and charge the customer an additional 8 hours for implementing the same)</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fajax%2Fstep-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists%2F&amp;title=Step+by+Step+Tutorials+%26%238211%3B+DWR+with+Spring%2C+Ajax+%26%238211%3B+Dynamic+drop+down+lists" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/ajax/step-by-step-tutorials-dwr-ajax-with-spring-dynamic-drop-down-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Example code, sending emails using Spring SimpleMailMessage, MimeMessagePreparator and Velocity Templates</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/sending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/sending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 18:57:53 +0000</pubDate>
		<dc:creator>Priyatam</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/143</guid>
		<description><![CDATA[When I first wrote my custom Email utlity 4 years back using JavaMail, it spread well over hundred lines of code. Looking at Spring&#8217;s out of the box functionality for sending Emails with attachements &#38; velocity templates makes you wanna feel sorry for your old code. The reference doc by Spring for Email is quite [...]]]></description>
			<content:encoded><![CDATA[<p>When I first wrote my custom Email utlity 4 years back using JavaMail, it spread well over hundred lines of code. Looking at Spring&#8217;s out of the box functionality for sending Emails with attachements &amp; velocity templates makes you wanna feel sorry for your old code. The <a href="http://static.springframework.org/spring/docs/2.0.x/reference/mail.html">reference doc </a>by Spring for Email is quite comprehensive, however if you want even simpler Email handler with custom to/from/template with spring config,  here is the code. I assume a generic object called &#8216;DomainObject&#8217; in your application. (All domain objects should extend this. If you use annotations, this is the way to go for domain driven development). The email utility would accept a domain object, use it&#8217;s properties like name, lastUpdatedBy, createdBy to complete the email body, the rest of which is in a velocity template. All the other beans and To/From/Host properties are set in a context file called applicationContext-mail.xml. (Another good practice, have seperate context files in your web-app).</p>
<p><strong>EmailService</strong></p>
<pre class="brush: java">
package com.reverttoconsole.mail;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import javax.mail.internet.MimeMessage;

import org.apache.log4j.Logger;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.ui.velocity.VelocityEngineUtils;

import com.reverttoconsole.common.DomainObject;

public class EmailService {
	private static final Logger logger = Logger.getLogger(EmailService.class);

	private VelocityEngine velocityEngine;
	private String velocityTemplate;
	private JavaMailSender mailSender;
	private SimpleMailMessage templateMessage;
	private Boolean isEnabled;

	public void sendMail(final DomainObject object, final String subject) throws Exception{
    	if (!isEnabled.booleanValue()) {
    		logger.warn(&quot;Mail is not enabled. Check your applicationContext-mail.xml isEnabled Settings&quot;);
    		return;
    	}

    	MimeMessagePreparator preparator = new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
               MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
               message.setTo(templateMessage.getTo());
               message.setFrom(templateMessage.getFrom());
               message.setSubject(subject);
               Map model = new HashMap();
               model.put(&quot;object&quot;, object);
               String text = VelocityEngineUtils.mergeTemplateIntoString(
                  velocityEngine, velocityTemplate, model);
               message.setText(text, true); //true means enable html email
            }
         };
         this.mailSender.send(preparator);
    }

	public JavaMailSender getMailSender() {
		return mailSender;
	}
	public void setMailSender(JavaMailSender mailSender) {
		this.mailSender = mailSender;
	}
	public SimpleMailMessage getTemplateMessage() {
		return templateMessage;
	}
	public void setTemplateMessage(SimpleMailMessage templateMessage) {
		this.templateMessage = templateMessage;
	}
	public VelocityEngine getVelocityEngine() {
		return velocityEngine;
	}
	public void setVelocityEngine(VelocityEngine velocityEngine) {
		this.velocityEngine = velocityEngine;
	}
	public String getVelocityTemplate() {
		return velocityTemplate;
	}
	public void setVelocityTemplate(String velocityTemplate) {
		this.velocityTemplate = velocityTemplate;
	}
	public Boolean getIsEnabled() {
		return isEnabled;
	}
	public void setIsEnabled(Boolean isEnabled) {
		this.isEnabled = isEnabled;
	}
        public String getFrom() {
               return getTemplateMessage().getFrom();
        }
        public String[] getTo() {
                 return getTemplateMessage().getTo();
        }
}
</pre>
<p><strong>applicationContext-mail.xml</strong></p>
<pre class="brush: xml">
&lt;!--l version=&quot;1.0&quot; encoding=&quot;utf-8--&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;&gt;&lt;/beans&gt;	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot;&amp;gt;
	&lt;description&gt;&lt;/description&gt;
		This file defines Email beans and their dependencies .
    &lt;bean autowire=&quot;byName&quot; id=&quot;emailManager&quot; class=&quot;com.reverttoconsole.EmailService&quot;&gt;&lt;/bean&gt;
       &lt;!-- set to true for enabling email --&gt;
&lt;property name=&quot;isEnabled&quot; value=&quot;true&quot;&gt;&lt;/property&gt;
	&lt;bean id=&quot;mailSender&quot; class=&quot;org.springframework.mail.javamail.JavaMailSenderImpl&quot;&gt;&lt;/bean&gt;
&lt;property name=&quot;host&quot; value=&quot;fe1psb1.i.fmedr.com&quot;&gt;&lt;/property&gt;
	&lt;bean id=&quot;templateMessage&quot; class=&quot;org.springframework.mail.SimpleMailMessage&quot;&gt;&lt;/bean&gt;
&lt;property name=&quot;from&quot; value=&quot;youremail@mail.com&quot;&gt;&lt;/property&gt;
&lt;property name=&quot;to&quot; value=&quot;youremail@mail.com&quot;&gt;&lt;/property&gt;
&lt;property name=&quot;subject&quot; value=&quot;Confirmation: &quot;&gt;&lt;/property&gt;
	&lt;bean id=&quot;velocityEngine&quot; class=&quot;org.springframework.ui.velocity.VelocityEngineFactoryBean&quot;&gt;&lt;/bean&gt;
&lt;property name=&quot;velocityProperties&quot;&gt;
         &lt;value&gt;&lt;/value&gt;
            resource.loader=class           class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
      &lt;/property&gt;&lt;/pre&gt;
&lt;strong&gt;Velocity Template&lt;/strong&gt;
</pre>
<p>Make sure you place this file (.vm) in the same location as the EmailService. Stick to convention. It&#8217;s easier</p>
<pre>
Hello,

The <em>${object.shortName}</em> is created by ${object.createdBy} on ${object.createdDate}.

This is a system-generated notification. Please do not reply to this email.

Please contact <a href="mailto:youremail.mail.com">Support</a> with any questions.

Thank you.</pre>
<p>That&#8217;s it. Set your email parameters, call EmailService.sendMail(..) from your controller or application code and you&#8217;re all done!</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fsending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates%2F&amp;title=Example+code%2C+sending+emails+using+Spring+SimpleMailMessage%2C+MimeMessagePreparator+and+Velocity+Templates" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/sending-emails-using-springs-simplemailmessage-mimemessagepreparator-velocity-templates/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Groovy CLIBuilder In Practice</title>
		<link>http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/</link>
		<comments>http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 15:44:25 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CodeSnippets]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/130</guid>
		<description><![CDATA[Ok, it doesn&#8217;t get much easier than this to build a CLI: class ContentUpdaterMain { static void main(args) { def cli = new CliBuilder(usage: &#039;java -jar contentupdater.jar -su[dh] &#34;update name&#34;&#039;) cli.h(longOpt: &#039;help&#039;, &#039;usage information&#039;) cli.u(longOpt: &#039;update&#039;, &#039;update the provided table&#039;, args: 1) cli.s(longOpt: &#039;stage&#039;, &#039;stage the provided table&#039;, args: 1) cli.d(longOpt: &#039;debug&#039;, &#039;run the process [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, it doesn&#8217;t get much easier than this to build a CLI:</p>
<pre class="brush: java">
class ContentUpdaterMain {

static void main(args) {

def cli = new CliBuilder(usage: &#039;java -jar contentupdater.jar -su[dh] &quot;update name&quot;&#039;)
cli.h(longOpt: &#039;help&#039;, &#039;usage information&#039;)
cli.u(longOpt: &#039;update&#039;, &#039;update the provided table&#039;, args: 1)
cli.s(longOpt: &#039;stage&#039;, &#039;stage the provided table&#039;, args: 1)
cli.d(longOpt: &#039;debug&#039;, &#039;run the process with debugging enabled&#039;)
def opt = cli.parse(args)
if(!opt) return

if(opt.h) cli.usage()

if( opt.d ) {
//turn on debug
}

if(opt.u) {
//do updates
}

if( opt.s ) {
// run against staging db
}
}
}
</pre>
<p>This produces the following usage output:</p>
<pre>usage: java -jar contentupdater.jar -su[dh] "update name"
-d,--debug run the process with debugging enabled
-h,--help usage information
-s,--stage stage the provided table
-u,--update update the provided table</pre>
<p>And all that remains is to validate the input and invoke the processes!</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcodesnippets%2Fgroovy-clibuilder-in-practice%2F&amp;title=Groovy+CLIBuilder+In+Practice" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
