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

<channel>
	<title>Kurtis Chiappone</title>
	<atom:link href="http://kurtischiappone.com/feed" rel="self" type="application/rss+xml" />
	<link>http://kurtischiappone.com</link>
	<description>Programmer, Web Developer, Blogger</description>
	<lastBuildDate>Thu, 17 May 2012 23:23:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<!-- podcast_generator="Blubrry PowerPress/4.0" -->
	<itunes:summary>Programmer, Web Developer, Blogger</itunes:summary>
	<itunes:author>Kurtis Chiappone</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://kurtischiappone.com/wp-content/plugins/powerpress/itunes_default.jpg" />
	<itunes:subtitle>Programmer, Web Developer, Blogger</itunes:subtitle>
	<image>
		<title>Kurtis Chiappone</title>
		<url>http://kurtischiappone.com/wp-content/plugins/powerpress/rss_default.jpg</url>
		<link>http://kurtischiappone.com</link>
	</image>
		<item>
		<title>Android Chord Transposer</title>
		<link>http://kurtischiappone.com/programming/android-chord-transposer</link>
		<comments>http://kurtischiappone.com/programming/android-chord-transposer#comments</comments>
		<pubDate>Mon, 02 Jan 2012 05:30:01 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[chord]]></category>
		<category><![CDATA[transposer]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=905</guid>
		<description><![CDATA[I wrote my first Android app &#8212; a chord transposer. Usually when I&#8217;m writing a song I take out a pad and write down the chords I&#8217;m using, then try out the same progression in different keys according to what&#8217;s suitable for my voice. Since I do this so often I figured it&#8217;d be easier [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote my first Android app &#8212; a chord transposer. Usually when I&#8217;m writing a song I take out a pad and write down the chords I&#8217;m using, then try out the same progression in different keys according to what&#8217;s suitable for my voice. Since I do this so often I figured it&#8217;d be easier to create an app to do it for me. It&#8217;s simple, but it gets the job done! And faster than I can do it on paper.</p>
<p>Check it out on the <a href="https://market.android.com/details?id=net.chiappone.android.transposer">Android market</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/android-chord-transposer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Observable ArrayList</title>
		<link>http://kurtischiappone.com/programming/java/observable-arraylist</link>
		<comments>http://kurtischiappone.com/programming/java/observable-arraylist#comments</comments>
		<pubDate>Sat, 07 May 2011 03:07:37 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[arraylist]]></category>
		<category><![CDATA[observable]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=782</guid>
		<description><![CDATA[If you&#8217;ve ever needed or wanted to observe an ArrayList for changes, it&#8217;s easy to extend it so that it follows the observable pattern. The Observer First we&#8217;ll make an interface for our observer, which defines all of the methods that we want to observe. Since ArrayList is parameterized, we&#8217;ll add a generic parameterization to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever needed or wanted to observe an ArrayList for changes, it&#8217;s easy to extend it so that it follows the observable pattern.</p>
<p><span id="more-782"></span></p>
<h3>The Observer</h3>
<p>First we&#8217;ll make an interface for our observer, which defines all of the methods that we want to observe.  Since ArrayList is parameterized, we&#8217;ll add a generic parameterization to our observer as well.  I&#8217;ve added most, if not all, of the methods that modify the list.  In your case, you might not need to observe all of these methods, so you can limit the number of methods in your interface to only the ones you need (or extend an abstract class like I do below).</p>
<pre class="brush: java; title: ; notranslate">
import java.util.Collection;

public interface ArrayListObserver&lt;E&gt; {

	public void onAdd( E element );

	public void onAdd( int index, E element );

	public void onAddAll( Collection&lt;? extends E&gt; elements );

	public void onAddAll( int index, Collection&lt;? extends E&gt; elements );

	public void onClear();

	public void onRemove( int index );

	public void onRemove( Object obj );

	public void onRemoveAll( Collection&lt;?&gt; c );

	public void onRetainAll( Collection&lt;?&gt; c );

	public void onSet( int index, E element );

	public void onSubList( int fromIndex, int toIndex );

}
</pre>
<h3>The Observable</h3>
<p>Next we&#8217;ll extend ArrayList by making our very own ObservableArrayList.  We&#8217;ll override all of the methods we want to observe, let the super class do its work, and we&#8217;ll notify the observers which method was called.</p>
<pre class="brush: java; title: ; notranslate">
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ObservableArrayList&lt;E&gt; extends ArrayList&lt;E&gt; {

	private List&lt;ArrayListObserver&lt;E&gt;&gt; observers = null;
	private static final long serialVersionUID = 1L;

	public ObservableArrayList( ArrayListObserver&lt;E&gt; observer ) {

		registerObserver( observer );

	}

	@Override
	public boolean add( E e ) {

		boolean result = super.add( e );

		if ( result ) {

			for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

				o.onAdd( e );

			}

		}

		return result;

	}

	@Override
	public void add( int index, E element ) {

		super.add( index, element );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onAdd( index, element );

		}

	}

	@Override
	public boolean addAll( Collection&lt;? extends E&gt; c ) {

		boolean result = super.addAll( c );

		if ( result ) {

			for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

				o.onAddAll( c );

			}

		}

		return result;

	}

	@Override
	public boolean addAll( int index, Collection&lt;? extends E&gt; c ) {

		boolean result = super.addAll( index, c );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onAddAll( index, c );

		}

		return result;

	}

	@Override
	public void clear() {

		super.clear();

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onClear();

		}

	}

	public List&lt;ArrayListObserver&lt;E&gt;&gt; getObservers() {

		if ( observers == null ) {

			observers = new ArrayList&lt;ArrayListObserver&lt;E&gt;&gt;();

		}

		return observers;

	}

	public void registerObserver( ArrayListObserver&lt;E&gt; observer ) {

		getObservers().add( observer );

	}

	@Override
	public E remove( int index ) {

		E toRet = super.remove( index );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onRemove( index );

		}

		return toRet;

	}

	@Override
	public boolean remove( Object obj ) {

		boolean result = super.remove( obj );

		if ( result ) {

			for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

				o.onRemove( obj );

			}

		}

		return result;

	}

	@Override
	public boolean removeAll( Collection&lt;?&gt; c ) {

		boolean result = super.removeAll( c );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onRemoveAll( c );

		}

		return result;

	}

	@Override
	public boolean retainAll( Collection&lt;?&gt; c ) {

		boolean result = super.retainAll( c );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onRetainAll( c );

		}

		return result;

	}

	@Override
	public E set( int index, E element ) {

		E toRet = super.set( index, element );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onSet( index, element );

		}

		return toRet;

	}

	@Override
	public List&lt;E&gt; subList( int fromIndex, int toIndex ) {

		List&lt;E&gt; toRet = super.subList( fromIndex, toIndex );

		for ( ArrayListObserver&lt;E&gt; o : getObservers() ) {

			o.onSubList( fromIndex, toIndex );

		}

		return toRet;

	}

	public void unregisterObserver( ArrayListObserver&lt;E&gt; observer ) {

		getObservers().remove( observer );

	}

}
</pre>
<h3>Abstract Observer</h3>
<p>At the moment, for the purpose of this article, I don&#8217;t want to observe every method that I specified in my interface.  I also don&#8217;t want to remove those methods from my interface because in the future I might need them.  To get around having to implement each method specified in the interface, I&#8217;ll make an abstract observer which, by default, does nothing in each method.  Then, I&#8217;ll write an implementation extending the abstract class which overrides only the methods I want to observe.</p>
<pre class="brush: java; title: ; notranslate">
import java.util.Collection;

public abstract class AbstractArrayListObserver&lt;E&gt; implements ArrayListObserver&lt;E&gt; {

	@Override
	public void onAdd( E element ) {

	}

	@Override
	public void onAdd( int index, E element ) {

	}

	@Override
	public void onAddAll( Collection&lt;? extends E&gt; elements ) {

	}

	@Override
	public void onAddAll( int index, Collection&lt;? extends E&gt; elements ) {

	}

	@Override
	public void onClear() {

	}

	@Override
	public void onRemove( int index ) {

	}

	@Override
	public void onRemove( Object obj ) {

	}

	@Override
	public void onRemoveAll( Collection&lt;?&gt; c ) {

	}

	@Override
	public void onRetainAll( Collection&lt;?&gt; c ) {

	}

	@Override
	public void onSet( int index, E element ) {

	}

	@Override
	public void onSubList( int fromIndex, int toIndex ) {

	}

}
</pre>
<h3>Observer Implementation</h3>
<p>Here, I just want to observe the add(), remove(), and clear() methods of the ArrayList, so I&#8217;ll only override these corresponding methods.  For testing purposes, I&#8217;m just going to print a message to the console whenever the methods I&#8217;m observing are called.</p>
<pre class="brush: java; title: ; notranslate">
public class MyArrayListObserver&lt;E&gt; extends AbstractArrayListObserver&lt;E&gt; {

	@Override
	public void onAdd( E element ) {

		System.out.println( &quot;Added element: &quot; + element );
		// Do something useful...

	}

	@Override
	public void onClear() {

		System.out.println( &quot;Cleared list!&quot; );
		// Do something useful...

	}

	@Override
	public void onRemove( Object obj ) {

		System.out.println( &quot;Removed object: &quot; + obj );
		// Do something useful...

	}

}
</pre>
<h3>Example Usage</h3>
<p>In my main class, I&#8217;ll create an ObservableArrayList, register an observer, call some methods on my list and see what the output is.</p>
<pre class="brush: java; title: ; notranslate">
public class ArrayListObserverTest {

	public static void main( String[] args ) {

		ArrayListObserver&lt;String&gt; observer = new MyArrayListObserver&lt;String&gt;();
		List&lt;String&gt; myList = new ObservableArrayList&lt;String&gt;( observer );
		myList.add( &quot;Test1&quot; );
		myList.remove( &quot;Test1&quot; );
		myList.add( &quot;Test2&quot; );
		myList.clear();

	}

}
</pre>
<h3>Output</h3>
<p>You can see in the output that the observer was appropriately notified when each of the observed methods were called.</p>
<pre>
Added element: Test1
Removed object: Test1
Added element: Test2
Cleared list!
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/java/observable-arraylist/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Property Class Generator</title>
		<link>http://kurtischiappone.com/programming/java/property-class-generator</link>
		<comments>http://kurtischiappone.com/programming/java/property-class-generator#comments</comments>
		<pubDate>Tue, 26 Apr 2011 01:13:18 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[properties]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=771</guid>
		<description><![CDATA[Following my article on Dynamic and Parsable Properties, I decided to write a utility class that would parse a properties file and generate the class for it. This way, if you have a particularly large properties file, you don&#8217;t have to spend too much time on the class to read the properties. Usage Assuming you [...]]]></description>
			<content:encoded><![CDATA[<p>Following my article on <a href="http://kurtischiappone.com/programming/java/dynamic-properties">Dynamic and Parsable Properties</a>, I decided to write a utility class that would parse a properties file and generate the class for it.  This way, if you have a particularly large properties file, you don&#8217;t have to spend too much time on the class to read the properties.</p>
<p><span id="more-771"></span></p>
<h3>Usage</h3>
<p>Assuming you have some properties file called <strong>test.properties</strong>, this will generate the class for it.  Since it works in conjunction with my ParsableProperties, this will &#8220;guess&#8221; at the data type and create appropriate getters.  Currently it only supports Boolean, Integer, Double, String, Date, and URL. Below, I just pass in the properties file and the output path where the generated class should be saved. I also specify the class name, package name, and in this case (for demonstration purposes) I&#8217;ve overridden the default list delimiter to use a comma rather than a tilde. (In my ParsableProperties, the default list delimiter is a tilde because you might use commas in number data types).</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.properties.generator.test;

import java.io.File;

import net.chiappone.properties.generator.PropertyClassGenerator;

public class TestPropertyClassGenerator {

	public static void main( String[] args ) throws Exception {

		File propertyFile = new File( &quot;test.properties&quot; );
		File outputPath = new File( &quot;src/net/chiappone/properties/generator/test/generated&quot; );

		PropertyClassGenerator generator = new PropertyClassGenerator( propertyFile, outputPath );
		generator.setPackageName( &quot;net.chiappone.properties.generator.test.generated&quot; );
		generator.setClassName( &quot;TestProperties&quot; );
		generator.setListDelimiter( &quot;,&quot; );
		generator.run();

	}

}
</pre>
<div class="download">
<ul>
<li><a href="http://kurtischiappone.com/wp-content/uploads/2011/04/net.chiappone.properties.generator.zip">JAR files</a> &#8211; for using in your project (49.7 KB)</li>
<li><a href="http://kurtischiappone.com/wp-content/uploads/2011/04/net.chiappone.properties.generator.src.zip">Source Code</a> &#8211; includes source, JAR, and tests (74.3 KB)</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/java/property-class-generator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic and Parsable Properties</title>
		<link>http://kurtischiappone.com/programming/java/dynamic-properties</link>
		<comments>http://kurtischiappone.com/programming/java/dynamic-properties#comments</comments>
		<pubDate>Sat, 23 Apr 2011 20:48:37 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[parsable]]></category>
		<category><![CDATA[properties]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=741</guid>
		<description><![CDATA[The Properties class allows you to store and retrieve static String property types from files. I wrote two classes that makes Properties &#8220;dynamic&#8221; (so that you can reference the values of other keys) and parsable (so that instead of returning all String types, you can parse other supported types). Dynamic Properties Sometimes you may have [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://download.oracle.com/javase/6/docs/api/java/util/Properties.html">Properties</a> class allows you to store and retrieve static String property types from files. I wrote two classes that makes Properties &#8220;dynamic&#8221; (so that you can reference the values of other keys) and parsable (so that instead of returning all String types, you can parse other supported types).</p>
<p><span id="more-741"></span></p>
<h3>Dynamic Properties</h3>
<p>Sometimes you may have a properties file with various keys that have the same value, but for flexibility purposes, you don&#8217;t want to share the same key because the value can change sometime in the future. At the same time, it can be cumbersome to duplicate larger values. Here&#8217;s a simple example:</p>
<pre class="brush: xml; title: ; notranslate">
backend.timeout: 5000
webservice.timeout: 5000
http.timeout: 30000
other.timeout: 30000
</pre>
<p>Here, you can see that two values are duplicated across four keys.  With my <strong>DynamicProperties</strong> class, you can reference duplicate values like this:</p>
<pre class="brush: xml; title: ; notranslate">
default.short.timeout: 5000
default.long.timeout: 30000

backend.timeout: ${default.short.timeout}
webservice.timeout: ${default.short.timeout}
http.timeout: ${default.long.timeout}
other.timeout: ${default.long.timeout}
</pre>
<h3>Parsable Properties</h3>
<p>Every object returned from a properties file is a String type.  If you represent other types of data in your properties file, chances are that you manually convert those values into other types.  My <strong>ParsableProperties</strong> class extends <strong>DynamicProperties</strong> by adding support to automatically parse different types and lists.  Using the above properties file, I can do this:</p>
<pre class="brush: java; title: ; notranslate">
int backendTimeout = properties.getInteger(&quot;backend.timeout&quot;);
</pre>
<p>As opposed to the &#8220;old&#8221; way:</p>
<pre class="brush: java; title: ; notranslate">
String backendTimeout = properties.getProperty(&quot;backend.timeout&quot;);
int converted = 0;
try {
    converted = Integer.parseInt( backendTimeout );
} catch ( NumberFormatException e ) {
    // Handle error
}
</pre>
<p>If you&#8217;re worried about losing the ability to handle the error, you can always provide a default value in the event that the value wasn&#8217;t parsable:</p>
<pre class="brush: java; title: ; notranslate">
// Use a default value of 30000 ms if this property can't be found or parsed
int backendTimeout = properties.getInteger(&quot;backend.timeout&quot;, 30000);
</pre>
<h4>Supported Types</h4>
<p>The API supports all of the primitive wrappers (Boolean, Character, Double, Float, Integer, Long, Short), in addition to URI, URL, File, and Date. This class will also parse lists for all of the above types, so long as they are delimited by some token (the default token is the `~` char since a comma could potentially be used in number values).</p>
<div class="download">
<ul>
<li><a href="http://kurtischiappone.com/wp-content/uploads/2011/04/net.chiappone.properties.zip">JAR files</a> &#8211; for using in your project (41.8 KB)</li>
<li><a href="http://kurtischiappone.com/wp-content/uploads/2011/04/net.chiappone.properties.src.zip">Source Code</a> &#8211; includes source, JAR, and unit tests (106 KB)</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/java/dynamic-properties/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java Crypter, Hasher, Masker, Truncater</title>
		<link>http://kurtischiappone.com/programming/projects/java-crypter</link>
		<comments>http://kurtischiappone.com/programming/projects/java-crypter#comments</comments>
		<pubDate>Sat, 08 Jan 2011 05:33:47 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[crypt]]></category>
		<category><![CDATA[decryption]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[truncate]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=700</guid>
		<description><![CDATA[I wrote a set of classes that make encrypting, decrypting, hashing, masking, and truncating data a little easier. I chose a generic design so that the API can be extended to include other, complex objects. To use it, you can include the JAR in your project (download the JAR and source here). It includes several [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a set of classes that make encrypting, decrypting, hashing, masking, and truncating data a little easier.  I chose a generic design so that the API can be extended to include other, complex objects.  To use it, you can include the JAR in your project (download the JAR and source <a href="http://kurtischiappone.com/wp-content/uploads/2011/01/Crypter.zip" title="Crypter">here</a>). It includes several test classes in the <strong>net.chiappone.crypt.test</strong> package for example usage.  In this article I&#8217;ll show some of these examples with their corresponding output.</p>
<p><span id="more-700"></span></p>
<h2>Contents</h2>
<ul>
<li><a href="#encryption">Encryption / Decryption</a>
<ul>
<li><a href="#encryptString">Encrypting / Decrypting a String</a></li>
<li><a href="#encryptXml">Encrypting / Decrypting XML</a></li>
<li><a href="#encryptObjects">Encrypting / Decrypting Other Objects</a></li>
</ul>
</li>
<li><a href="#hashing">Hashing</a>
<ul>
<li><a href="#hashString">Hashing a String</a></li>
<li><a href="#hashXml">Hashing XML</a></li>
</ul>
</li>
<li><a href="#masking">Masking</a>
<ul>
<li><a href="#maskPassword">Password Masking</a></li>
<li><a href="#maskXml">Masking XML</a></li>
</ul>
</li>
<li><a href="#truncating">Truncating</a>
<ul>
<li><a href="#truncateString">Truncating a String</a></li>
<li><a href="#truncateXml">Truncating XML</a></li>
</ul>
</li>
</ul>
<p><a id="encryption"></a></p>
<h2>Encryption / Decryption</h2>
<p><a id="encryptString"></a></p>
<h3>Encrypting / Decrypting a String</h3>
<p>Here&#8217;s an example on encrypting/decrypting a String with AES:</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.encrypt;

import net.chiappone.crypt.algorithms.Algorithm;
import net.chiappone.crypt.algorithms.KeyHolder;
import net.chiappone.crypt.crypters.StringCrypter;

public class EncryptStringAES {

	/**
	 * @param args
	 */
	public static void main( String[] args ) throws Exception {

		String data = &quot;1234-5678-9012-3456-7890&quot;;

		// Generate a secret key for AES-128

		KeyHolder key = new KeyHolder( Algorithm.AES128 );

		// Encrypt and decrypt using the key

		StringCrypter crypter = new StringCrypter();
		String encrypted = crypter.encrypt( data, key );
		String decrypted = crypter.decrypt( encrypted, key );

		System.out.println( &quot;Original Data = &quot; + data );
		System.out.println( &quot;AES-128 Encrypted = &quot; + encrypted );
		System.out.println( &quot;AES-128 Decrypted = &quot; + decrypted );

	}
}
</pre>
<h4>Output</h4>
<pre>
Original Data = 1234-5678-9012-3456-7890
AES-128 Encrypted = 800b46e3522335977aa7be783859ac39d69347213b55e1ff30553c20bfcc60d4
AES-128 Decrypted = 1234-5678-9012-3456-7890
</pre>
<p><a id="encryptXml"></a></p>
<h3>Encrypting / Decrypting XML</h3>
<p>Though it&#8217;s probably better to encrypt fields before putting into XML, I added support for finding and encrypting/decrypting nodes based on tag.</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.encrypt;

import java.util.ArrayList;
import java.util.List;

import net.chiappone.crypt.algorithms.Algorithm;
import net.chiappone.crypt.algorithms.KeyHolder;
import net.chiappone.crypt.crypters.XmlCrypter;

public class EncryptXmlMultipleAES {

	/**
	 * @param args
	 */
	public static void main( String[] args ) throws Exception {

		String xml = &quot;&lt;customers&gt;\n&quot; + &quot;\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;123-45-6789&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;\n&quot; + &quot;\t\t\t&lt;password&gt;abcdefg&lt;/password&gt;\n&quot;
				+ &quot;\t&lt;/customer&gt;\n&quot; + &quot;\t\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;987-65-4321&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;\n&quot; + &quot;\t\t\t&lt;password&gt;hijklmnop&lt;/password&gt;\n&quot;
				+ &quot;\t\t&lt;/customer&gt;\n&quot; + &quot;&lt;/customers&gt;&quot;;

		// Generate a secret key for AES-128

		KeyHolder key = new KeyHolder( Algorithm.AES128 );

		// Indicate the tags that should be encrypted

		List&lt;String&gt; tags = new ArrayList&lt;String&gt;();
		tags.add( &quot;ssn&quot; );
		tags.add( &quot;cc&quot; );
		tags.add( &quot;password&quot; );

		// Encrypt and decrypt using the key

		XmlCrypter crypter = new XmlCrypter();
		String encrypted = crypter.encrypt( xml, key, tags );
		String decrypted = crypter.decrypt( encrypted, key, tags );

		System.out.println( &quot;Original Data = &quot; + xml );
		System.out.println( &quot;AES-128 Encrypted = &quot; + encrypted );
		System.out.println( &quot;AES-128 Decrypted = &quot; + decrypted );

	}
}
</pre>
<h4>Output</h4>
<pre>
Original Data =
&lt;customers&gt;
    &lt;customer&gt;
        &lt;ssn&gt;123-45-6789&lt;/ssn&gt;
	&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;
	&lt;password&gt;abcdefg&lt;/password&gt;
    &lt;/customer&gt;
    &lt;customer&gt;
        &lt;ssn&gt;987-65-4321&lt;/ssn&gt;
	&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;
	&lt;password&gt;hijklmnop&lt;/password&gt;
    &lt;/customer&gt;
&lt;/customers&gt;

AES-128 Encrypted =
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;customers&gt;
    &lt;customer&gt;
        &lt;ssn&gt;3b72baec243dcf8f2446bdbc2d3fe60e&lt;/ssn&gt;
	&lt;cc&gt;b1fdd12b26e930eef02a5a4afa90472948b800c1c0986436d19db153bf3ef653&lt;/cc&gt;
	&lt;password&gt;9b97a02e0e8ae3f9a7fd7cc0d7b91351&lt;/password&gt;
    &lt;/customer&gt;
    &lt;customer&gt;
        &lt;ssn&gt;c16d031b0133b4d1b63ea7dbf79f1849&lt;/ssn&gt;
	&lt;cc&gt;8aea6326da7ece55a1be424355f3518fa329c3055096485947e4007ccf0c9d77&lt;/cc&gt;
	&lt;password&gt;21ee817069bbd599001d38eb3f93fb60&lt;/password&gt;
    &lt;/customer&gt;
&lt;/customers&gt;

AES-128 Decrypted =
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;customers&gt;
    &lt;customer&gt;
        &lt;ssn&gt;123-45-6789&lt;/ssn&gt;
	&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;
	&lt;password&gt;abcdefg&lt;/password&gt;
    &lt;/customer&gt;
    &lt;customer&gt;
        &lt;ssn&gt;987-65-4321&lt;/ssn&gt;
	&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;
	&lt;password&gt;hijklmnop&lt;/password&gt;
    &lt;/customer&gt;
&lt;/customers&gt;
</pre>
<p><a id="encryptObjects"></a></p>
<h3>Encrypting / Decrypting Other Objects</h3>
<p>Suppose you had some other object, <strong>DataObject</strong>, which contains certain fields that you want to encrypt/decrypt (credit card, social security, password, etc.).  It&#8217;s easy to write a crypter that would handle the encryption/decryption for it:</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.crypters;

import net.chiappone.crypt.algorithms.KeyHolder;
import net.chiappone.crypt.serializable.DataObject;

public class DataObjectCrypter implements Crypter&lt;DataObject&gt; {

	public DataObject decrypt( DataObject data, KeyHolder key ) {

		if ( data != null ) {

			// Decrypt the CC, SSN, and Password

			StringCrypter crypter = new StringCrypter();
			data.setCreditCard( crypter.decrypt( data.getCreditCard(), key ) );
			data.setSocialSecurity( crypter.decrypt( data.getSocialSecurity(), key ) );
			data.setPassword( crypter.decrypt( data.getPassword(), key ) );

		}

		return data;

	}

	public DataObject encrypt( DataObject data, KeyHolder key ) {

		if ( data != null ) {

			// Encrypt the CC, SSN, and Password

			StringCrypter crypter = new StringCrypter();
			data.setCreditCard( crypter.encrypt( data.getCreditCard(), key ) );
			data.setSocialSecurity( crypter.encrypt( data.getSocialSecurity(), key ) );
			data.setPassword( crypter.encrypt( data.getPassword(), key ) );

		}

		return data;

	}

}
</pre>
<p><a id="hashing"></a></p>
<h2>Hashing</h2>
<p>If you don&#8217;t need to get back the original data, you can hash the data (very useful for storing passwords).</p>
<p><a id="hashString"></a></p>
<h3>Hashing a String</h3>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.hash;

import net.chiappone.crypt.algorithms.Algorithm;
import net.chiappone.crypt.hashers.Hasher;
import net.chiappone.crypt.hashers.StringHasher;

public class HashString {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {

		String data = &quot;1234-5678-9012-3456-7890&quot;;
		Hasher&lt;String&gt; hasher = new StringHasher();
		System.out.println( &quot;Original Data = &quot; + data );

		// MD5
		String hashed = hasher.hash( Algorithm.MD5, data );
		System.out.println( &quot;MD5 Hashed = &quot; + hashed );

		// SHA-1
		hashed = hasher.hash( Algorithm.SHA1, data );
		System.out.println( &quot;SHA-1 Hashed = &quot; + hashed );

		// SHA-256
		hashed = hasher.hash( Algorithm.SHA256, data );
		System.out.println( &quot;SHA-256 Hashed = &quot; + hashed );

		// SHA-384
		hashed = hasher.hash( Algorithm.SHA384, data );
		System.out.println( &quot;SHA-384 Hashed = &quot; + hashed );

		// SHA-512
		hashed = hasher.hash( Algorithm.SHA512, data );
		System.out.println( &quot;SHA-512 Hashed = &quot; + hashed );
	}

}
</pre>
<h4>Output</h4>
<pre>
Original Data = 1234-5678-9012-3456-7890
MD5 Hashed = 173ec737e7c3b96f8e5deb86293b2482
SHA-1 Hashed = e8b1b706f089372a7e36af6ca1c09b29f8a17e3c
SHA-256 Hashed = 8dbfce16a02065d83a33c02ed059fec7da394ed2a7fa57a8cfd070656dc5b8ab
SHA-384 Hashed = 8f1ce3278edfdf1fc44bedd02f75cb64447fdddf345cbb26492da3caa8dd8bb983b401bc5b4720cf5443f8f7024ed483
SHA-512 Hashed = b47c33d66bc8d4e86c070bb0117110275bab3b0b25e45f5dea478078b9500ae1506fb6c79d3a688691e4d1dfb5c15970aa791aec6567b7c31c58bddf6b0ae690
</pre>
<p><a id="hashXml"></a></p>
<h3>Hashing XML</h3>
<p>Hashing XML nodes is similar to the above example for encrypting XML:</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.hash;

import java.util.ArrayList;
import java.util.List;

import net.chiappone.crypt.algorithms.Algorithm;
import net.chiappone.crypt.hashers.XmlHasher;

public class HashXmlMultipleTags {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {

		String xml = &quot;&lt;customers&gt;\n&quot; + &quot;\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;123-45-6789&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;\n&quot;
				+ &quot;\t\t\t&lt;password&gt;abcdefg&lt;/password&gt;\n&quot; + &quot;\t&lt;/customer&gt;\n&quot;
				+ &quot;\t\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;987-65-4321&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;\n&quot;
				+ &quot;\t\t\t&lt;password&gt;hijklmnop&lt;/password&gt;\n&quot; + &quot;\t\t&lt;/customer&gt;\n&quot;
				+ &quot;&lt;/customers&gt;&quot;;

		List&lt;String&gt; tags = new ArrayList&lt;String&gt;();
		tags.add( &quot;ssn&quot; );
		tags.add( &quot;cc&quot; );
		tags.add( &quot;password&quot; );

		String hashed = new XmlHasher().hash( Algorithm.SHA256, xml, tags );

		System.out.println( &quot;Original Data = &quot; + xml );
		System.out.println( &quot;Hashed = &quot; + hashed )

	}

}
</pre>
<h4>Output</h4>
<pre>
Original Data =
&lt;customers&gt;
	&lt;customer&gt;
		&lt;ssn&gt;123-45-6789&lt;/ssn&gt;
		&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;
		&lt;password&gt;abcdefg&lt;/password&gt;
	&lt;/customer&gt;
	&lt;customer&gt;
		&lt;ssn&gt;987-65-4321&lt;/ssn&gt;
		&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;
		&lt;password&gt;hijklmnop&lt;/password&gt;
	&lt;/customer&gt;
&lt;/customers&gt;

Hashed =
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;customers&gt;
	&lt;customer&gt;
		&lt;ssn&gt;01a54629efb952287e554eb23ef69c52097a75aecc0e3a93ca0855ab6d7a31a0&lt;/ssn&gt;
		&lt;cc&gt;5d444387a5d39f5deb5b24a82a9b990d4ada981515d84469cda488f605799c10&lt;/cc&gt;
		&lt;password&gt;7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a&lt;/password&gt;
	&lt;/customer&gt;
	&lt;customer&gt;
		&lt;ssn&gt;ecdbc061a36dd6495e016ba4696dedbc4c0b822b4d6ec55b4fb57d17f1df5695&lt;/ssn&gt;
		&lt;cc&gt;05e819efb49067336a6105c7d4de554b4b3496d6c468b901f0679e51683e9bab&lt;/cc&gt;
		&lt;password&gt;5fa0f12f10e1e16191a8671a42ed6b5245ce97006757070abd92003d771bb56a&lt;/password&gt;
	&lt;/customer&gt;
&lt;/customers&gt;
</pre>
<p><a id="masking"></a></p>
<h2>Masking</h2>
<p>Sometimes you just need to mask certain sensitive data, like a password:</p>
<p><a id="maskPassword"></a></p>
<h3>Password Masking</h3>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.mask;

import net.chiappone.crypt.maskers.PasswordMasker;

public class MaskPassword {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {

		String data = &quot;mypassword&quot;;
		String masked = new PasswordMasker().mask( data );

		System.out.println( &quot;Original Data = &quot; + data );
		System.out.println( &quot;Masked = &quot; + masked );

	}

}
</pre>
<h4>Output</h4>
<pre>
Original Data = mypassword
Masked = **********
</pre>
<p><a id="maskXml"></a></p>
<h3>Masking XML</h3>
<p>Something a little more complicated, masking certain XML nodes with different element data and different ways to mask them.</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.mask;

import java.util.HashMap;
import java.util.Map;

import net.chiappone.crypt.maskers.CreditCardMasker;
import net.chiappone.crypt.maskers.Masker;
import net.chiappone.crypt.maskers.PasswordMasker;
import net.chiappone.crypt.maskers.SocialSecurityMasker;
import net.chiappone.crypt.maskers.XmlMasker;

public class MaskXmlMultipleTags {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {

		String xml = &quot;&lt;customers&gt;\n&quot; + &quot;\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;123-45-6789&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;\n&quot;
				+ &quot;\t\t\t&lt;password&gt;abcdefg&lt;/password&gt;\n&quot; + &quot;\t&lt;/customer&gt;\n&quot;
				+ &quot;\t\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;987-65-4321&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;\n&quot;
				+ &quot;\t\t\t&lt;password&gt;hijklmnop&lt;/password&gt;\n&quot; + &quot;\t\t&lt;/customer&gt;\n&quot;
				+ &quot;&lt;/customers&gt;&quot;;

		Map&lt;String, Masker&lt;String&gt;&gt; map = new HashMap&lt;String, Masker&lt;String&gt;&gt;();
		map.put( &quot;ssn&quot;, new SocialSecurityMasker() );
		map.put( &quot;cc&quot;, new CreditCardMasker() );
		map.put( &quot;password&quot;, new PasswordMasker() );

		String masked = new XmlMasker().mask( map, xml );

		System.out.println( &quot;Original Data = &quot; + xml );
		System.out.println( &quot;Masked = &quot; + masked );

	}
}
</pre>
<h4>Output</h4>
<pre>
Original Data =
&lt;customers&gt;
    &lt;customer&gt;
	    &lt;ssn&gt;123-45-6789&lt;/ssn&gt;
		&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;
		&lt;password&gt;abcdefg&lt;/password&gt;
    &lt;/customer&gt;
    &lt;customer&gt;
	    &lt;ssn&gt;987-65-4321&lt;/ssn&gt;
		&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;
		&lt;password&gt;hijklmnop&lt;/password&gt;
	&lt;/customer&gt;
&lt;/customers&gt;

Masked =
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;customers&gt;
    &lt;customer&gt;
	    &lt;ssn&gt;xxx-xx-6789&lt;/ssn&gt;
		&lt;cc&gt;xxxx-xxxx-xxxx-3456&lt;/cc&gt;
		&lt;password&gt;*******&lt;/password&gt;
	&lt;/customer&gt;
	&lt;customer&gt;
		&lt;ssn&gt;xxx-xx-4321&lt;/ssn&gt;
		&lt;cc&gt;xxxx-xxxx-xxxx-7654&lt;/cc&gt;
		&lt;password&gt;*********&lt;/password&gt;
	&lt;/customer&gt;
&lt;/customers&gt;
</pre>
<p><a id="truncating"></a></p>
<h2>Truncating</h2>
<p>Slightly different than masking, truncating is when you just need a certain portion of the data.  E.g., sometimes your social security number is truncated to show the last four digits only.</p>
<p><a id="truncateString"></a></p>
<h3>Truncating a String</h3>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.truncate;

import net.chiappone.crypt.truncaters.SocialSecurityTruncater;

public class TruncateSocialSecurity {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {

		String data = &quot;123-45-6789&quot;;
		String truncated = new SocialSecurityTruncater().truncate( data );

		System.out.println( &quot;Original Data = &quot; + data );
		System.out.println( &quot;Truncated = &quot; + truncated );

	}

}
</pre>
<h4>Output</h4>
<pre>
Original Data = 123-45-6789
Truncated = 6789
</pre>
<p><a id="truncateXml"></a></p>
<h3>Truncating XML</h3>
<p>You can do the same for XML nodes:</p>
<pre class="brush: java; title: ; notranslate">
package net.chiappone.crypt.test.truncate;

import java.util.HashMap;
import java.util.Map;

import net.chiappone.crypt.truncaters.CreditCardTruncater;
import net.chiappone.crypt.truncaters.SocialSecurityTruncater;
import net.chiappone.crypt.truncaters.Truncater;
import net.chiappone.crypt.truncaters.XmlTruncater;

public class TruncateXmlMultipleTags {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {

		String xml = &quot;&lt;customers&gt;\n&quot; + &quot;\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;123-45-6789&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;\n&quot; + &quot;\t\t\t&lt;password&gt;abcdefg&lt;/password&gt;\n&quot;
				+ &quot;\t&lt;/customer&gt;\n&quot; + &quot;\t\t&lt;customer&gt;\n&quot; + &quot;\t\t\t&lt;ssn&gt;987-65-4321&lt;/ssn&gt;\n&quot;
				+ &quot;\t\t\t&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;\n&quot; + &quot;\t\t\t&lt;password&gt;hijklmnop&lt;/password&gt;\n&quot;
				+ &quot;\t\t&lt;/customer&gt;\n&quot; + &quot;&lt;/customers&gt;&quot;;

		Map&lt;String, Truncater&lt;String&gt;&gt; map = new HashMap&lt;String, Truncater&lt;String&gt;&gt;();
		map.put( &quot;ssn&quot;, new SocialSecurityTruncater() );
		map.put( &quot;cc&quot;, new CreditCardTruncater() );

		String truncated = new XmlTruncater().truncate( map, xml );

		System.out.println( &quot;Original Data = &quot; + xml );
		System.out.println( &quot;Truncated = &quot; + truncated );

	}

}
</pre>
<h4>Output</h4>
<pre>
Original Data =
&lt;customers&gt;
	&lt;customer&gt;
		&lt;ssn&gt;123-45-6789&lt;/ssn&gt;
		&lt;cc&gt;1234-5678-9012-3456&lt;/cc&gt;
		&lt;password&gt;abcdefg&lt;/password&gt;
	&lt;/customer&gt;
	&lt;customer&gt;
		&lt;ssn&gt;987-65-4321&lt;/ssn&gt;
		&lt;cc&gt;9876-5432-1098-7654&lt;/cc&gt;
		&lt;password&gt;hijklmnop&lt;/password&gt;
	&lt;/customer&gt;
&lt;/customers&gt;

Truncated =
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;customers&gt;
	&lt;customer&gt;
		&lt;ssn&gt;6789&lt;/ssn&gt;
		&lt;cc&gt;3456&lt;/cc&gt;
		&lt;password&gt;abcdefg&lt;/password&gt;
&lt;/customer&gt;
	&lt;customer&gt;
		&lt;ssn&gt;4321&lt;/ssn&gt;
		&lt;cc&gt;7654&lt;/cc&gt;
		&lt;password&gt;hijklmnop&lt;/password&gt;
	&lt;/customer&gt;
&lt;/customers&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/projects/java-crypter/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extract text from a PDF file</title>
		<link>http://kurtischiappone.com/programming/java/parse-pdf</link>
		<comments>http://kurtischiappone.com/programming/java/parse-pdf#comments</comments>
		<pubDate>Fri, 31 Dec 2010 20:03:17 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=683</guid>
		<description><![CDATA[This example shows you how to parse the text from a PDF file using Apache POI. The Code]]></description>
			<content:encoded><![CDATA[<p>This example shows you how to parse the text from a PDF file using <a href="http://poi.apache.org/" title="Apache POI">Apache POI</a>.</p>
<p><span id="more-683"></span></p>
<h3>The Code</h3>
<pre class="brush: java; title: ; notranslate">
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;

public class ParsePdfFile {

	/**
	 * @param args
	 */
	public static void main( String[] args ) throws Exception {

		File myFile = new File( &quot;doc/mypdf.pdf&quot; );
		List&lt;String&gt; lines = new ArrayList&lt;String&gt;();

		FileInputStream inputStream = new FileInputStream( myFile );
		PDDocument pdfDoc = PDDocument.load( inputStream );
		StringWriter writer = new StringWriter();
		PDFTextStripper stripper = new PDFTextStripper();
		stripper.writeText( pdfDoc, writer );
		pdfDoc.close();

		StringBuffer buffer = writer.getBuffer();
		String line = buffer.toString();
		line = line.replaceAll( stripper.getLineSeparator(), &quot;\n&quot; );

		BufferedReader br = new BufferedReader( new StringReader( line ) );

		String currentLine;

		while ( ( currentLine = br.readLine() ) != null ) {

			if ( !currentLine.trim().isEmpty() ) {

				lines.add( currentLine.trim() );

			}

		}

	}

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/java/parse-pdf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extract Text from a .DOC File</title>
		<link>http://kurtischiappone.com/programming/java/parse-doc</link>
		<comments>http://kurtischiappone.com/programming/java/parse-doc#comments</comments>
		<pubDate>Fri, 31 Dec 2010 19:55:21 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[doc]]></category>
		<category><![CDATA[microsoft word]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=679</guid>
		<description><![CDATA[This example shows you how to parse the text from a Microsoft Word file (prior to the 2007 version) using Apache POI. If you want to parse a .docx file instead, click here. The Code Using Apache POI, it&#8217;s pretty simple. Just include the library in your classpath and use the following code:]]></description>
			<content:encoded><![CDATA[<p>This example shows you how to parse the text from a Microsoft Word file (prior to the 2007 version) using <a href="http://poi.apache.org/" title="Apache POI">Apache POI</a>. If you want to parse a <strong>.docx</strong> file instead, click <a href="http://kurtischiappone.com/programming/java/parse-docx" title="Parse a Microsoft 2007 docx file">here</a>.</p>
<p><span id="more-679"></span></p>
<h3>The Code</h3>
<p>Using <a href="http://poi.apache.org/" title="Apache POI">Apache POI</a>, it&#8217;s pretty simple. Just include the library in your classpath and use the following code:</p>
<pre class="brush: java; title: ; notranslate">
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ParseWodDocFile {

	/**
	 * @param args
	 */
	public static void main( String[] args ) throws Exception {

		File myFile = new File( &quot;doc/myfile.doc&quot; );
		List&lt;String&gt; lines = new ArrayList&lt;String&gt;();

		FileInputStream inputStream = new FileInputStream( myFile );
		POIFSFileSystem fs = new POIFSFileSystem( inputStream );
		HWPFDocument doc = new HWPFDocument( fs );
		WordExtractor we = new WordExtractor( doc );

		String[] paragraphs = we.getParagraphText();

		for ( String line : paragraphs ) {

			if ( line != null &amp;&amp; !line.trim().isEmpty() ) {

				lines.add( line.trim() );

			}

		}

	}

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/java/parse-doc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Klondike</title>
		<link>http://kurtischiappone.com/programming/projects/klondike</link>
		<comments>http://kurtischiappone.com/programming/projects/klondike#comments</comments>
		<pubDate>Thu, 30 Dec 2010 21:52:37 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[klondike]]></category>
		<category><![CDATA[solitaire]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=656</guid>
		<description><![CDATA[Following my Minewsweeper game, I thought I&#8217;d work on another classic computer game &#8212; Klondike (better known as Solitaire). Complete source code is available here. The Challenge Though it&#8217;s a simple game, it was much more complex than Minesweeper. There&#8217;s a lot of rules, there&#8217;s a deck of cards involved, and there&#8217;s specific scoring. From [...]]]></description>
			<content:encoded><![CDATA[<p>Following my <a href="http://kurtischiappone.com/programming/projects/minewsweeper" title="Minesweeper">Minewsweeper</a> game, I thought I&#8217;d work on another classic computer game &#8212; Klondike (better known as Solitaire).  Complete source code is available <a href="http://kurtischiappone.com/wp-content/uploads/2010/12/Klondike.zip" title="Klondike">here</a>.</p>
<p><span id="more-656"></span></p>
<h3>The Challenge</h3>
<p>Though it&#8217;s a simple game, it was much more complex than Minesweeper.  There&#8217;s a lot of rules, there&#8217;s a deck of cards involved, and there&#8217;s specific scoring.  From a GUI perspective, cards have to be drag-and-droppable to different areas of the screen and you should be able to drag-and-drop single AND multiple cards at once.</p>
<h3>Cards</h3>
<p>The first thing I did was work on a package for the deck of cards.  I made a <strong>Card</strong> class which contained a <strong>Rank</strong>, <strong>Suit</strong>, and <strong>State</strong> (face up or down).  Then I made a <strong>Deck</strong> which holds a <strong>CardSet</strong> (52 unique cards) and includes methods for adding, removing, shuffling, etc.</p>
<h3>Banks</h3>
<p>Once that was done I worked on the different &#8220;banks&#8221; where cards can be placed.  These are generally known as the <strong>Stock</strong> and <strong>Waste</strong> (where the cards are dealt from), <strong>Foundation</strong> (where the cards are built, Aces downward), and the <strong>Table</strong> (made up of 7 columns where the cards are initially dealt to).</p>
<h3>Game Engine</h3>
<p>Then I worked on the game <strong>Engine</strong>.  It&#8217;s completely separate from any GUI so that it can be reused and reimplemented in various ways.  I won&#8217;t go into too much detail, other than that it contains all of the game logic such that you could actually use the engine to play a whole Klondike game without any interface at all &#8212; but it would be very difficult to do so <img src='http://kurtischiappone.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>GUI</h3>
<p>Once I felt like the engine was solid, I worked on the GUI.  Some of the basic elements (e.g. the <strong>Card</strong>) I worked on before were extended so that they could include images and (x,y,z) coordinates on the screen.  I also made a <strong>DesktopEngine</strong> that interacted with the core game engine.  The reason I did this was to implement the drag-and-drop logic and all the other GUI elements and logic.</p>
<h3>Future Improvements</h3>
<p>I didn&#8217;t implement a timer, finished game animation or high scores.  If anyone is interested, please feel free!</p>
<div align="center">
<img src="http://kurtischiappone.com/wp-content/uploads/2010/12/Klondike.jpg" alt="Klondike" width="590" height="560" />
</div>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/projects/klondike/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Minesweeper</title>
		<link>http://kurtischiappone.com/programming/projects/minesweeper</link>
		<comments>http://kurtischiappone.com/programming/projects/minesweeper#comments</comments>
		<pubDate>Thu, 30 Dec 2010 21:25:13 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[minesweeper]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=660</guid>
		<description><![CDATA[I wrote this simple Minesweeper game when offering the challenge to a friend who was trying to get back into programming. It turned out to be a fun little project so I figured I&#8217;d share the code here for those who are interested. The game itself is made up of a board which contains cells/points. [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this simple Minesweeper game when offering the challenge to a friend who was trying to get back into programming. It turned out to be a fun little project so I figured I&#8217;d share <a href="http://kurtischiappone.com/wp-content/uploads/2010/12/MSW.zip" title="Minesweeper">the code</a> here for those who are interested.</p>
<p><span id="more-660"></span></p>
<p><img src="http://kurtischiappone.com/wp-content/uploads/2010/12/Minewsweeper.jpg" alt="Minewsweeper" height="270" width="230" border="0" class="rightnoborder" /></p>
<p>The game itself is made up of a board which contains cells/points. According to the game rules, cells (which may or may not contain mines) may be clicked or flagged. The objective is to flag all the cells containing mines and to click all of the &#8220;safe&#8221; cells.  Once all of the safe cells are checked and all of the cells with mines are flagged, the game is won. If a cell with a mine is clicked, the game is lost.</p>
<p>I kept the game engine (<strong>msw.game.Engine</strong>) separate from the GUI, so the engine itself can be reused and plugged into any GUI aside from the one I included in the project.  The main class is <strong>msw.game.Main</strong>.  If you find any bugs or see any room for improvement, please feel free to share.  (One feature I didn&#8217;t yet add was a timer and proper handling when the game finishes [e.g. high scores]).</p>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/programming/projects/minesweeper/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated my site</title>
		<link>http://kurtischiappone.com/announcements/updated-my-site</link>
		<comments>http://kurtischiappone.com/announcements/updated-my-site#comments</comments>
		<pubDate>Thu, 30 Dec 2010 16:18:58 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://kurtischiappone.com/?p=3</guid>
		<description><![CDATA[Wow, it&#8217;s been a while but I&#8217;ve updated my site. In doing so, I&#8217;ve retired my old website (ComputerCranium) and integrated it with my personal website (where you are now). This way I&#8217;ll be able to have all my postings in one location but under separate categories. I hardly used the other site anymore, so [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, it&#8217;s been a while but I&#8217;ve updated my site. In doing so, I&#8217;ve retired my old website (ComputerCranium) and integrated it with my personal website (where you are now). This way I&#8217;ll be able to have all my postings in one location but under separate categories. I hardly used the other site anymore, so this will give me the opportunity to update just the one site on a more regular basis.</p>
]]></content:encoded>
			<wfw:commentRss>http://kurtischiappone.com/announcements/updated-my-site/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

