<?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>Code Snips</title>
	<atom:link href="http://www.jordeu.net/codesnips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jordeu.net/codesnips</link>
	<description>Why is there something rather than nothing?</description>
	<lastBuildDate>Sat, 11 Dec 2010 14:34:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>How to create a XSD from Java classes annotated with JAXB</title>
		<link>http://www.jordeu.net/codesnips/2010/12/how-to-create-a-xsd-from-java-classes-annotated-with-jaxb/</link>
		<comments>http://www.jordeu.net/codesnips/2010/12/how-to-create-a-xsd-from-java-classes-annotated-with-jaxb/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 19:49:20 +0000</pubDate>
		<dc:creator>jordeu</dc:creator>
				<category><![CDATA[HowTos]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[schemagen]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://www.jordeu.net/codesnips/?p=21</guid>
		<description><![CDATA[In this howto I will show you how to create a XML Schema from an annotated JAXB class using the maven jaxb-schemagen plugin. STEP 1:  Annotate your domain classes with JAXB annotations. In our example we have a simple Contact class with name, surname, birthday and a list of mails. @XmlRootElement public class Contact { [...]]]></description>
			<content:encoded><![CDATA[<p>In this howto I will show you how to create a XML Schema from an annotated JAXB class using the maven jaxb-schemagen plugin.</p>
<p><strong>STEP 1:  Annotate your domain classes with JAXB annotations. </strong></p>
<p>In our example we have a simple Contact class with name, surname, birthday and a list of mails.</p>
<pre class="brush:java">@XmlRootElement
public class Contact {
        private String name;
        private String surname;
        private Birthday birthday;
        private List&lt;Mail&gt; mail;
       // Add getters &amp; setters
}
</pre>
<p>And the Birthday class:</p>
<pre class="brush:java">
@XmlType
public class Birthday {
        private String day;
        private String month;
        private String year;
        // Add getters &amp; setters
}
</pre>
<p>And the Mail class:</p>
<pre class="brush:java">@XmlType
public class Mail {
        public enum MailType { PERSONAL, WORK };
        private String email;
        private MailType type;
        // Add getters &amp; setters
}
</pre>
<p><strong>STEP 2: Annotate the XML namespace as a package annotation</strong></p>
<p>The package-info.java</p>
<pre class="brush:java">

@XmlSchema (
                xmlns = {},
                namespace = "http://www.jordeu.net/XSDCREATOR/1.0.0",
                elementFormDefault = XmlNsForm.UNSET,
                attributeFormDefault = XmlNsForm.UNSET
                )
package net.jordeu.codesnips.xsdcreator;

import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
</pre>
<p><strong>STEP 3: Config Maven pom.xml</strong><br />
First add this repository to the pom.xml or check that you have it in your settings.xml or proxy repository.</p>
<pre class="brush:xml">
&lt;pluginRepository&gt;
     &lt;id&gt;maven-repository.dev.java.net&lt;/id&gt;
     &lt;name&gt;Java.net Maven 2 Repository&lt;/name&gt;
     &lt;url&gt;http://download.java.net/maven/2&lt;/url&gt;
&lt;/pluginRepository&gt;
</pre>
<p>And add this plugin changing the &#8220;includes&#8221; section and &#8220;schemas&#8221; section according to your project name and layout.</p>
<pre class="brush:xml">
&lt;plugin&gt;
     &lt;groupId&gt;com.sun.tools.jxc.maven2&lt;/groupId&gt;
     &lt;artifactId&gt;maven-jaxb-schemagen-plugin&lt;/artifactId&gt;
     &lt;version&gt;1.2&lt;/version&gt;
     &lt;executions&gt;
         &lt;execution&gt;
            &lt;phase&gt;generate-resources&lt;/phase&gt;
            &lt;goals&gt;
               &lt;goal&gt;generate&lt;/goal&gt;
            &lt;/goals&gt;
         &lt;/execution&gt;
     &lt;/executions&gt;

     &lt;configuration&gt;
        &lt;project&gt;${project}&lt;/project&gt;
        &lt;destdir&gt;${project.build.directory}/schemas&lt;/destdir&gt;
        &lt;srcdir&gt;${project.build.sourceDirectory}&lt;/srcdir&gt;
        &lt;includes&gt;
             &lt;include&gt;net/jordeu/codesnips/xsdcreator/*&lt;/include&gt;
        &lt;/includes&gt;
        &lt;schemas&gt;
             &lt;schema&gt;
                 &lt;namespace&gt;http://www.jordeu.net/XSDCREATOR/1.0.0&lt;/namespace&gt;
                 &lt;file&gt;xsdcreator-v1_0_0.xsd&lt;/file&gt;
             &lt;/schema&gt;
        &lt;/schemas&gt;
        &lt;verbose&gt;true&lt;/verbose&gt;
     &lt;/configuration&gt;
     &lt;dependencies&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
             &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
             &lt;version&gt;2.2&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
             &lt;artifactId&gt;jaxb-xjc&lt;/artifactId&gt;
             &lt;version&gt;2.2&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
             &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
             &lt;version&gt;2.2&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
             &lt;artifactId&gt;jaxb-xjc&lt;/artifactId&gt;
             &lt;version&gt;2.2&lt;/version&gt;
         &lt;/dependency&gt;
     &lt;/dependencies&gt;
&lt;/plugin&gt;
</pre>
<p><strong>Checkout the sample project</strong></p>
<p>svn checkout http://jordeu-codesnips.googlecode.com/svn/trunk/codesnips-xsdcreator</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jordeu.net/codesnips/2010/12/how-to-create-a-xsd-from-java-classes-annotated-with-jaxb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to pass a XML file as an URL parameter</title>
		<link>http://www.jordeu.net/codesnips/2010/11/how-to-pass-an-xml-file-as-an-url-parameter/</link>
		<comments>http://www.jordeu.net/codesnips/2010/11/how-to-pass-an-xml-file-as-an-url-parameter/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 07:53:36 +0000</pubDate>
		<dc:creator>jordeu</dc:creator>
				<category><![CDATA[HowTos]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.jordeu.net/codesnips/?p=7</guid>
		<description><![CDATA[Some days ago I needed to pass a XML file as an URL parameter. After some googling I didn&#8217;t found anything that suited my needs and I ended coding it myself. Goals Compress a String and encode it with Base64 Decompress and decode a Base64 encoded and compressed string. Decompress method public static String decompress(String inputStr) throws [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago I needed to pass a XML file as an URL parameter. After some googling I didn&#8217;t found anything that suited my needs and I ended coding it myself.</p>
<p><strong>Goals</strong></p>
<ul>
<li>Compress a String and encode it with Base64</li>
<li>Decompress and decode a Base64 encoded and compressed string.</li>
</ul>
<p><strong>Decompress method</strong></p>
<pre class="brush:java">public static String decompress(String inputStr) throws UnsupportedEncodingException {

		// Base64 decode
		Base64 base64 = new Base64(-1, new byte[0], true);
		byte[] bytes = base64.decode(inputStr.getBytes("UTF-8"));

		// Inflater
		Inflater decompressor = new Inflater();
		decompressor.setInput(bytes);

		// Create an expandable byte array to hold the decompressed data
		ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);

		// Decompress the data
		byte[] buf = new byte[1024];
		while (!decompressor.finished()) {
			try {
				int count = decompressor.inflate(buf);
				bos.write(buf, 0, count);
			} catch (DataFormatException e) {
			}
		}
		try {
			bos.close();
		} catch (IOException e) {
		}

		// Get the decompressed data
		byte[] decompressedData = bos.toByteArray();

		return new String(decompressedData, "UTF-8");
	}</pre>
<p><strong>Compress method</strong></p>
<pre class="brush:java">	public static String compress(String inputStr) throws UnsupportedEncodingException {
		byte[] input = inputStr.getBytes("UTF-8");

		// Compressor with highest level of compression
		Deflater compressor = new Deflater();
		compressor.setLevel(Deflater.BEST_COMPRESSION);

		// Give the compressor the data to compress
		compressor.setInput(input);
		compressor.finish();

		// Create an expandable byte array to hold the compressed data.
		// It is not necessary that the compressed data will be smaller than
		// the uncompressed data.
		ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);

		// Compress the data
		byte[] buf = new byte[1024];
		while (!compressor.finished()) {
			int count = compressor.deflate(buf);
			bos.write(buf, 0, count);
		}
		try {
			bos.close();
		} catch (IOException e) {
		}

		// Get the compressed data
		byte[] compressedData = bos.toByteArray();

		// Encode Base64
		Base64 base64 = new Base64(-1, new byte[0], true);
		byte[] bytes = base64.encode(compressedData);
		return new String(bytes, "UTF-8");
	}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jordeu.net/codesnips/2010/11/how-to-pass-an-xml-file-as-an-url-parameter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

