<?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>Marcus Schiesser</title>
	<atom:link href="http://www.marcusschiesser.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcusschiesser.de</link>
	<description>Discovering User Interface Technologies</description>
	<lastBuildDate>Fri, 02 Dec 2011 17:40:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using Google App Engine as Backend for Android</title>
		<link>http://www.marcusschiesser.de/2011/12/using-google-app-engine-as-backend-for-android/</link>
		<comments>http://www.marcusschiesser.de/2011/12/using-google-app-engine-as-backend-for-android/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 17:40:57 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[jersey]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=436</guid>
		<description><![CDATA[If you&#8217;re looking for a way to create a backend for your Android application, Google App Engine looks like the perfect choice: You can use Java as you can do for Android and you don&#8217;t need to think too much about hosting, as it is all stored in the cloud. Another benefit is that you [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking for a way to create a backend for your Android application, Google App Engine looks like the perfect choice: You can use Java as you can do for Android and you don&#8217;t need to think too much about hosting, as it is all stored in the cloud. </p>
<p>Another benefit is that you can reuse your <a href="http://java.sun.com/blueprints/patterns/TransferObject.html">transfer objects</a> on the client and on server side. But as it is often there are some problems doing this in practice. So you don&#8217;t have the same ones I had, I am glad to share my experiences with you.</p>
<p>So first question is what libraries are to use for the client/server communication. At start I tried <a href="http://www.restlet.org">Restlet 2.0</a>. Looked like a great choice as there are special editions for App Engine and for Android available. In practice it is not very useful as the libraries are to big for Android and I also very much disliked that fully serialized java objects are transfered.</p>
<p>Best approach I found so far is to use <a href="http://jersey.java.net/">Jersey 1.6</a>: It is easy to use and implements the JAX-RS (JSR 311) standard. To set it up on the App Engine, please consult these blog posts from me: <a href="/2011/12/using-real-pojos-without-jaxb-annotations-as-transfer-objects-with-jax-rs/" title="Using real POJOs (without JAXB Annotations) as transfer objects with JAX-RS">Using real POJOs (without JAXB Annotations) as transfer objects with JAX-RS</a> and <a href="/2011/12/storing-large-images-restful-in-the-cloud-using-google-app-engine/" title="Storing large images RESTful in the cloud using Google App Engine">Storing large images RESTful in the cloud using Google App Engine</a>.</p>
<p>Ok, so far about the server side. To keep things small and simple on the Android side, I mainly created the following wrapper class for the <code>HttpClient</code> to handle the HTTP requests:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.codehaus.jackson.map.ObjectMapper</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HttpUtils <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> SERVER_PORT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SERVER_IP <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;myapp.appspot.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// use 10.0.2.2 for emulator</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> HttpUtils instance <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpUtils<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> DefaultHttpClient client<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> ResponseHandler<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> responseHandler<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> ObjectMapper mapper<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> HttpUtils<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultHttpClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpConnectionParams.<span style="color: #006633;">setConnectionTimeout</span><span style="color: #009900;">&#40;</span>client.<span style="color: #006633;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">30000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                responseHandler <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BasicResponseHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                mapper <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// can reuse, share globally</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> HttpUtils getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> instance<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doGet<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> doGet<span style="color: #009900;">&#40;</span>path, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doGet<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path, <span style="color: #003399;">String</span> query<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                        URI uri<span style="color: #339933;">;</span>
                        uri <span style="color: #339933;">=</span> createURI<span style="color: #009900;">&#40;</span>path, query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        HttpGet get <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpGet<span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        HttpResponse response <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>get<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">int</span> statusCode <span style="color: #339933;">=</span> response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>statusCode <span style="color: #339933;">==</span> HttpStatus.<span style="color: #006633;">SC_OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #000000; font-weight: bold;">return</span> responseHandler.<span style="color: #006633;">handleResponse</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wrong http status: &quot;</span> <span style="color: #339933;">+</span> statusCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;uri syntax error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ClientProtocolException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;protocol error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> 
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> URI createURI<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path, <span style="color: #003399;">String</span> query<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> URISyntaxException <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> URIUtils.<span style="color: #006633;">createURI</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http&quot;</span>, SERVER_IP, SERVER_PORT, <span style="color: #0000ff;">&quot;rest/&quot;</span> <span style="color: #339933;">+</span> path, query, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> doPut<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path, <span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #003399;">String</span> json <span style="color: #339933;">=</span> mapper.<span style="color: #006633;">writeValueAsString</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        URI uri <span style="color: #339933;">=</span> createURI<span style="color: #009900;">&#40;</span>path, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        HttpPut put <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpPut<span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        put.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Accept&quot;</span>, <span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        put.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span>, <span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        StringEntity entity <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringEntity<span style="color: #009900;">&#40;</span>json, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        entity.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        put.<span style="color: #006633;">setEntity</span><span style="color: #009900;">&#40;</span>entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        HttpResponse response <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>put<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">int</span> statusCode <span style="color: #339933;">=</span> response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">return</span> statusCode <span style="color: #339933;">==</span> HttpStatus.<span style="color: #006633;">SC_OK</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;uri syntax error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ClientProtocolException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;protocol error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doPutFile<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> path, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">File</span> file<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> URISyntaxException, HttpException,
                        <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
                URI uri <span style="color: #339933;">=</span> createURI<span style="color: #009900;">&#40;</span>path, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpPut put <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpPut<span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">String</span> mimeType <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;binary/octet-stream&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.*<span style="color: #000099; font-weight: bold;">\\</span>.(jpeg|jpg)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        mimeType <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;image/jpeg&quot;</span><span style="color: #339933;">;</span>
                FileEntity reqEntity <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FileEntity<span style="color: #009900;">&#40;</span>file, mimeType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                put.<span style="color: #006633;">setEntity</span><span style="color: #009900;">&#40;</span>reqEntity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpResponse response <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>put<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">int</span> statusCode <span style="color: #339933;">=</span> response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>statusCode <span style="color: #339933;">==</span> HttpStatus.<span style="color: #006633;">SC_OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">return</span> responseHandler.<span style="color: #006633;">handleResponse</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wrong http status: &quot;</span> <span style="color: #339933;">+</span> statusCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doPost<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> path, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> POSTText<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> URISyntaxException, HttpException,
                        <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
                URI uri <span style="color: #339933;">=</span> createURI<span style="color: #009900;">&#40;</span>path, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpPost httpPost <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpPost<span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                StringEntity entity <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringEntity<span style="color: #009900;">&#40;</span>POSTText, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                BasicHeader basicHeader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BasicHeader<span style="color: #009900;">&#40;</span>HTTP.<span style="color: #006633;">CONTENT_TYPE</span>, <span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                httpPost.<span style="color: #006633;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setBooleanParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http.protocol.expect-continue&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                entity.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span>basicHeader<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                httpPost.<span style="color: #006633;">setEntity</span><span style="color: #009900;">&#40;</span>entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpResponse response <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>httpPost<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">int</span> statusCode <span style="color: #339933;">=</span> response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>statusCode <span style="color: #339933;">==</span> HttpStatus.<span style="color: #006633;">SC_OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">return</span> responseHandler.<span style="color: #006633;">handleResponse</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wrong http status: &quot;</span> <span style="color: #339933;">+</span> statusCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> doDelete<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> path<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> HttpException, <span style="color: #003399;">IOException</span>, URISyntaxException <span style="color: #009900;">&#123;</span>
                URI uri <span style="color: #339933;">=</span> createURI<span style="color: #009900;">&#40;</span>path, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpDelete httpDelete <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpDelete<span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                httpDelete.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Accept&quot;</span>, <span style="color: #0000ff;">&quot;text/html, image/jpeg, *; q=.2, */*; q=.2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                HttpResponse response <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>httpDelete<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">int</span> statusCode <span style="color: #339933;">=</span> response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">return</span> statusCode <span style="color: #339933;">==</span> HttpStatus.<span style="color: #006633;">SC_OK</span> <span style="color: #339933;">?</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This implementation is far from perfect, especially exception handling and passing parameters need to be improved, but it works so far <img src='http://www.marcusschiesser.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Using this class it is easy to store a file using the <code>FileServerResource</code> from my former blog post. Just call:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">File</span> imageFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #009900;">&#40;</span>myimgage.<span style="color: #006633;">getImageURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> url <span style="color: #339933;">=</span> HttpUtils.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doPutFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file/store&quot;</span>, imageFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also it is easy to store a transfer object using the <code>doPut</code> method. Note that is is using the <code>ObjectMapper</code> class from <a href="http://jackson.codehaus.org/">Jackson</a>, the same JSON processor that is also used by Jersey.<br />
Jackson is therefore the only additional library that you need on the Android side which keeps the executable small. If you use the same version of Jackson on the client side as on the server side you&#8217;re also ensured that the (un-)marshalling process of your transfer objects works flawlessly on both sides.</p>
<p>Hope you liked this approach &#8211; feel free to discuss here further ideas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/12/using-google-app-engine-as-backend-for-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing large images RESTful in the cloud using Google App Engine</title>
		<link>http://www.marcusschiesser.de/2011/12/storing-large-images-restful-in-the-cloud-using-google-app-engine/</link>
		<comments>http://www.marcusschiesser.de/2011/12/storing-large-images-restful-in-the-cloud-using-google-app-engine/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 17:27:36 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=431</guid>
		<description><![CDATA[In my last article I showed how to store files in the cloud using Google app engine. Problem there was that the maximum size of the files was 1MB. Not that much for images. To improve the situation, we just shrink the images with this very simple algorithm by factor 0.9 until the size is [...]]]></description>
			<content:encoded><![CDATA[<p>In my last article I showed <a href="/2011/12/storing-files-restful-in-the-cloud-using-google-app-engine/">how to store files in the cloud using Google app engine</a>.<br />
Problem there was that the maximum size of the files was 1MB. Not that much for images.</p>
<p>To improve the situation, we just shrink the images with this very simple algorithm by factor 0.9 until the size is less than 1MB:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FileTransformer <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger log <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>FileTransformer.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> JPEG_QUALITY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MAX_FILE_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1024</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> transform<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ba, <span style="color: #003399;">String</span> mediaType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mediaType.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/jpeg&quot;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">||</span> mediaType.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> imageTransform<span style="color: #009900;">&#40;</span>ba<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unsupported media type: &quot;</span> <span style="color: #339933;">+</span> mediaType <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; for this transformer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> imageTransform<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ba<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> result <span style="color: #339933;">=</span> ba<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">length</span><span style="color: #339933;">&gt;</span>MAX_FILE_SIZE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Image</span> origImage <span style="color: #339933;">=</span> ImagesServiceFactory.<span style="color: #006633;">makeImage</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Image</span> newImage <span style="color: #339933;">=</span> shrinkImage<span style="color: #009900;">&#40;</span>origImage, 0.9f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			result <span style="color: #339933;">=</span> newImage.<span style="color: #006633;">getImageData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Image</span> shrinkImage<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Image</span> origImage, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">float</span> percent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">final</span> ImagesService imagesService <span style="color: #339933;">=</span> ImagesServiceFactory.<span style="color: #006633;">getImagesService</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		log.<span style="color: #006633;">fine</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;orig dimensions is &quot;</span> <span style="color: #339933;">+</span> origImage.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; X &quot;</span> <span style="color: #339933;">+</span> origImage.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">final</span> OutputSettings settings <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OutputSettings<span style="color: #009900;">&#40;</span>OutputEncoding.<span style="color: #006633;">JPEG</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		settings.<span style="color: #006633;">setQuality</span><span style="color: #009900;">&#40;</span>JPEG_QUALITY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">final</span> Transform resize <span style="color: #339933;">=</span> ImagesServiceFactory.<span style="color: #006633;">makeResize</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">round</span><span style="color: #009900;">&#40;</span>origImage.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>percent<span style="color: #009900;">&#41;</span>, <span style="color: #003399;">Math</span>.<span style="color: #006633;">round</span><span style="color: #009900;">&#40;</span>origImage.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>percent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Image</span> newImage <span style="color: #339933;">=</span> imagesService.<span style="color: #006633;">applyTransform</span><span style="color: #009900;">&#40;</span>resize, origImage, settings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> newImage<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This <code>FileTransformer</code> class is then just called in the <code>storeFile</code> method of the <code>FileServerResource</code> in the case the file size is large than 1MB:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ba.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ba <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FileTransformer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">transform</span><span style="color: #009900;">&#40;</span>ba, mediaType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Remark: So far this only works with JPEG media types, otherwise an exception is raised. Feel free to add different compression cases for other media types (e.g. using GZIP on texts). As I said, it is a good idea to store<br />
the media type <img src='http://www.marcusschiesser.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/12/storing-large-images-restful-in-the-cloud-using-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing files RESTful in the cloud using Google App Engine</title>
		<link>http://www.marcusschiesser.de/2011/12/storing-files-restful-in-the-cloud-using-google-app-engine/</link>
		<comments>http://www.marcusschiesser.de/2011/12/storing-files-restful-in-the-cloud-using-google-app-engine/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 17:09:27 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=420</guid>
		<description><![CDATA[Do you want to store files RESTful in the cloud? Why not use the Google App Engine for it? Firstly you will need a entity class that is storing the file in the data store: @Entity public class FileEntity &#123; @Id @GeneratedValue&#40;strategy = GenerationType.IDENTITY&#41; private Long key; &#160; private Blob content; private String mediaType; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to store files RESTful in the cloud? Why not use the Google App Engine for it?</p>
<p>Firstly you will need a entity class that is storing the file in the data store:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FileEntity <span style="color: #009900;">&#123;</span>
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> key<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Blob</span> content<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> mediaType<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getKey<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> key<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Blob</span> getContent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> content<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setContent<span style="color: #009900;">&#40;</span><span style="color: #003399;">Blob</span> content<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">content</span> <span style="color: #339933;">=</span> content<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMediaType<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> mediaType<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMediaType<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> mediaType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mediaType</span> <span style="color: #339933;">=</span> mediaType<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Beside the actual content of the file, this entity also stores the media type (you never know, it might be good to know&#8230;).<br />
As I just like standards, you also might mention that I used JPA as much as possible (<code>Blob</code> is a Google specific thing, as unfortunately <code>byte[]</code> can not store large amounts. BTW: <code>Blob</code> is also limited by 1MB, so you can not store larger files than 1MB using this approach).</p>
<p>Secondly you will need a JAX-RS resource class that is handling the GET and PUT requests from clients:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/file&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FileServerResource <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger log <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>FileServerResource.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	@<span style="color: #003399;">Context</span>
	UriInfo uriInfo<span style="color: #339933;">;</span>
	@<span style="color: #003399;">Context</span>
	HttpHeaders headers<span style="color: #339933;">;</span>
	@<span style="color: #003399;">Context</span>
	HttpServletResponse response<span style="color: #339933;">;</span>
&nbsp;
	@PUT
	@Path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/store&quot;</span><span style="color: #009900;">&#41;</span>
	@Consumes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> MediaType.<span style="color: #006633;">TEXT_PLAIN</span>, <span style="color: #0000ff;">&quot;image/jpeg&quot;</span>, <span style="color: #0000ff;">&quot;image/png&quot;</span>, <span style="color: #0000ff;">&quot;image/gif&quot;</span>, <span style="color: #0000ff;">&quot;application/zip&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	@Produces<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> MediaType.<span style="color: #006633;">TEXT_PLAIN</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> storeFile<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		FileEntity file <span style="color: #339933;">=</span> EMF.<span style="color: #006633;">doTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> EMF.<span style="color: #006633;">Closure</span><span style="color: #339933;">&lt;</span>FileEntity<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">public</span> FileEntity doit<span style="color: #009900;">&#40;</span>EntityManager em<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ba <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span>
				<span style="color: #003399;">String</span> mediaType <span style="color: #339933;">=</span> headers.<span style="color: #006633;">getMediaType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				FileEntity file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FileEntity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				file.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Blob</span><span style="color: #009900;">&#40;</span>ba<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				file.<span style="color: #006633;">setMediaType</span><span style="color: #009900;">&#40;</span>mediaType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				em.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">return</span> file<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		UriBuilder ub <span style="color: #339933;">=</span> uriInfo.<span style="color: #006633;">getBaseUriBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		URI link <span style="color: #339933;">=</span> ub.<span style="color: #006633;">path</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/file/get/&quot;</span> <span style="color: #339933;">+</span> file.<span style="color: #006633;">getKey</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> link.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@GET
	@Path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/get/{id}&quot;</span><span style="color: #009900;">&#41;</span>
	@Produces<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*/*&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> Response getFile<span style="color: #009900;">&#40;</span>@PathParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> EMF.<span style="color: #006633;">doTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> EMF.<span style="color: #006633;">Closure</span><span style="color: #339933;">&lt;</span>Response<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">public</span> Response doit<span style="color: #009900;">&#40;</span>EntityManager em<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				FileEntity entity <span style="color: #339933;">=</span> em.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>FileEntity.<span style="color: #000000; font-weight: bold;">class</span>, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>entity <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
					<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> WebApplicationException<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">404</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">return</span> Response.<span style="color: #006633;">ok</span><span style="color: #009900;">&#40;</span>entity.<span style="color: #006633;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, entity.<span style="color: #006633;">getMediaType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At last you just need a small helper class (<a href='/wp-content/uploads/2011/12/EMF.java' >EMF.java</a>) that is handling the transactions and of course an JAX-RS implementation (I used <a href="http://jersey.java.net/">Jersey 1.6</a> &#8211; works perfectly with App Engine).</p>
<p>To test the file store, just call:<br />
<code>curl --upload-file mypic.jpg -H "Content-Type: image/jpeg" http://localhost:8888/rest/file/store</code></p>
<p>This request returns the URL of the file that is stored. Just request this URL to retrieve your file back from the storage.</p>
<p>Have fun and let me know, if you are using this code for some of your projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/12/storing-files-restful-in-the-cloud-using-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using real POJOs (without JAXB Annotations) as transfer objects with JAX-RS</title>
		<link>http://www.marcusschiesser.de/2011/12/using-real-pojos-without-jaxb-annotations-as-transfer-objects-with-jax-rs/</link>
		<comments>http://www.marcusschiesser.de/2011/12/using-real-pojos-without-jaxb-annotations-as-transfer-objects-with-jax-rs/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 16:06:30 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[jax-rs]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[marshall]]></category>
		<category><![CDATA[pojo]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=413</guid>
		<description><![CDATA[Are you annoyed that you have to annotate your POJOs with @XmlRootElement, so they can be used with JAX-RS? If your using Jersey as JAX-RS implementation your lucky: Just add to the &#60;servlet&#62; tag in your web.xml the following snippet: &#60;init-param&#62; &#60;param-name&#62;com.sun.jersey.api.json.POJOMappingFeature&#60;/param-name&#62; &#60;param-value&#62;true&#60;/param-value&#62; &#60;/init-param&#62; After restarting your servlet, your POJOs are marshalled to JSON as [...]]]></description>
			<content:encoded><![CDATA[<p>Are you annoyed that you have to annotate your POJOs with <code>@XmlRootElement</code>, so they can be used with JAX-RS? If your using Jersey as JAX-RS implementation your lucky: Just add to the <code>&lt;servlet&gt;</code> tag in your <code>web.xml</code> the following snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.api.json.POJOMappingFeature<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After restarting your servlet, your POJOs are marshalled to JSON as a charme. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/12/using-real-pojos-without-jaxb-annotations-as-transfer-objects-with-jax-rs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBoss-Migration: Von 4 über 5 nach 7</title>
		<link>http://www.marcusschiesser.de/2011/11/jboss-migration/</link>
		<comments>http://www.marcusschiesser.de/2011/11/jboss-migration/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 15:29:22 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[4]]></category>
		<category><![CDATA[5]]></category>
		<category><![CDATA[7]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[migration]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=405</guid>
		<description><![CDATA[Die Migration einer Java Enterprise-Anwendung auf eine höhere JBoss-Version ist nicht an einem Nachmittag erledigt. Auf welche Probleme man stoßen kann, beschreibe ich in meinem Erfahrungsbericht: Von 4 über 5 nach 7, erschienen im JavaMagazin 10/2011. Behandelt wird die Migration einer J2EE-1.4-Anwendung von JBoss 4 bis 7. Vielen Dank an den Verlag (Software &#038; Support [...]]]></description>
			<content:encoded><![CDATA[<p>Die Migration einer Java Enterprise-Anwendung auf eine höhere JBoss-Version ist nicht an einem Nachmittag erledigt. Auf welche Probleme man stoßen kann, beschreibe ich in meinem Erfahrungsbericht: <a href='/wp-content/uploads/2011/11/JM_10_11_Schiesser_JBoss-Migration.pdf'>Von 4 über 5 nach 7</a>, erschienen im <a href="http://it-republik.de/jaxenter/java-magazin-ausgaben/Ride-the-Lightning-000466.html">JavaMagazin 10/2011</a>. </p>
<p>Behandelt wird die Migration einer J2EE-1.4-Anwendung von JBoss 4 bis 7. </p>
<p>Vielen Dank an den Verlag (Software &#038; Support Media GmbH), dass ich das PDF in meinem Blog nun zur Verfügung stellen darf.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/11/jboss-migration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let the user change the column order in Java/Swing</title>
		<link>http://www.marcusschiesser.de/2011/11/let-the-user-change-the-column-order-in-javaswing/</link>
		<comments>http://www.marcusschiesser.de/2011/11/let-the-user-change-the-column-order-in-javaswing/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 14:36:15 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[swing]]></category>
		<category><![CDATA[tablecolumnmodel]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=390</guid>
		<description><![CDATA[Do you have the requirement to let the user of your application change the order of his columns and your app is based on Swing? Then you should read further. Below you find a TableColumnModel that has two states: STANDARD and USERDEFINED. In the STANDARD state the user may not change the order of the [...]]]></description>
			<content:encoded><![CDATA[<p>Do you have the requirement to let the user of your application change the order<br />
of his columns and your app is based on Swing?</p>
<p>Then you should read further. Below you find a <code><a href="http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/table/TableColumnModel.html">TableColumnModel</a></code> that has<br />
two states: <code>STANDARD</code> and <code>USERDEFINED</code>.<br />
In the <code>STANDARD</code> state the user may not change the order of the columns by drag&#8217;n'drop,<br />
in <code>USERDEFINED</code> he may. The good thing: If you toogle the state the column order is restored. </p>
<p>Just a hint: If you want to store the column order, first get it by calling <code>getColumnMap()</code>.</p>
<p>Before you ask you to use it. Try <code>setModel</code> of your <code>JTable</code><a href="http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JTable.html"></a> class <img src='http://www.marcusschiesser.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Have fun!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StatefulTableColumnModel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">DefaultTableColumnModel</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">enum</span> Mode <span style="color: #009900;">&#123;</span>
        STANDARD, USERDEFINED<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> columnMap<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Mode mode <span style="color: #339933;">=</span> Mode.<span style="color: #006633;">STANDARD</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> StatefulTableColumnModel<span style="color: #009900;">&#40;</span>Mode mode, <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> columnMap<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">columnMap</span> <span style="color: #339933;">=</span> columnMap<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mode<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> 
            setMode<span style="color: #009900;">&#40;</span>mode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
            setMode<span style="color: #009900;">&#40;</span>Mode.<span style="color: #006633;">STANDARD</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMode<span style="color: #009900;">&#40;</span>Mode mode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mode</span> <span style="color: #339933;">=</span> mode<span style="color: #339933;">;</span>
        refresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Mode getMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mode</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getColumnMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> columnMap<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* (non-Javadoc)
     * @see javax.swing.table.DefaultTableColumnModel#fireColumnMoved(javax.swing.event.TableColumnModelEvent)
     */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> fireColumnMoved<span style="color: #009900;">&#40;</span><span style="color: #003399;">TableColumnModelEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>mode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">case</span> USERDEFINED<span style="color: #339933;">:</span>
            <span style="color: #666666; font-style: italic;">// if columns have been moved there might have been Drag'n'Drop operations,</span>
            <span style="color: #666666; font-style: italic;">// so update the state </span>
            columnMap <span style="color: #339933;">=</span> getColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> STANDARD<span style="color: #339933;">:</span>
            <span style="color: #666666; font-style: italic;">// in standard mode drag'n'drop operations are not permitted, so reset the order</span>
            resetColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">fireColumnMoved</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * re-order table columns depending on their model index (this resets the original order), don't update view
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> resetColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Collections</span>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>tableColumns, <span style="color: #000000; font-weight: bold;">new</span> Comparator<span style="color: #339933;">&lt;</span>TableColumn<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #003399;">TableColumn</span> o1, <span style="color: #003399;">TableColumn</span> o2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span>o1.<span style="color: #006633;">getModelIndex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>o2.<span style="color: #006633;">getModelIndex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * set the visible column positions (independent of state), don't update view
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> setColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> columnMap<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        resetColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>columnMap<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Vector<span style="color: #339933;">&lt;</span>TableColumn<span style="color: #339933;">&gt;</span> newOrder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Vector<span style="color: #339933;">&lt;</span>TableColumn<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>tableColumns.<span style="color: #006633;">capacity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            newOrder.<span style="color: #006633;">setSize</span><span style="color: #009900;">&#40;</span>tableColumns.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TableColumn</span> column<span style="color: #339933;">:</span> tableColumns<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// lookup new position in newOrder</span>
                <span style="color: #000066; font-weight: bold;">int</span> newPos <span style="color: #339933;">=</span> columnMap<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                newOrder.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>newPos, column<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            tableColumns <span style="color: #339933;">=</span> newOrder<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the visible column positions (independent of state)
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> result<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span>tableColumns.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TableColumn</span> column<span style="color: #339933;">:</span> tableColumns<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> modelIndex <span style="color: #339933;">=</span> column.<span style="color: #006633;">getModelIndex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            result<span style="color: #009900;">&#91;</span>modelIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * 
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> refresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>mode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">case</span> STANDARD<span style="color: #339933;">:</span>
            <span style="color: #666666; font-style: italic;">// reset position</span>
            resetColumnPositions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> USERDEFINED<span style="color: #339933;">:</span>
            setColumnPositions<span style="color: #009900;">&#40;</span>columnMap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>        
        <span style="color: #666666; font-style: italic;">// inform view that column order has changed (seems to be sufficient to just tell 0 has moved to 1)</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">fireColumnMoved</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">TableColumnModelEvent</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/11/let-the-user-change-the-column-order-in-javaswing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Openbahn-API – Bahn-Webseite als Webservice</title>
		<link>http://www.marcusschiesser.de/2011/06/openbahn-api-%e2%80%93-bahn-webseite-als-webservice/</link>
		<comments>http://www.marcusschiesser.de/2011/06/openbahn-api-%e2%80%93-bahn-webseite-als-webservice/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 20:13:17 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Idea]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[bahn]]></category>
		<category><![CDATA[booking]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[ticket]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=386</guid>
		<description><![CDATA[As this is only of interest for German users &#8211; this article is in German only. It&#8217;s about a new project of mine. Sorry folks. Ich bin gerade dabei eine Android-App zu entwickeln, mit der es möglich ist Fahrkarten für Bahn-Pendler einfacher zu buchen. Bei der Entwicklung ist mir aufgefallen, dass die Bahn leider keine [...]]]></description>
			<content:encoded><![CDATA[<p>As this is only of interest for German users &#8211; this article is in German only. It&#8217;s about a new project of mine. Sorry folks.</p>
<p>Ich bin gerade dabei eine Android-App zu entwickeln, mit der es möglich ist Fahrkarten für Bahn-Pendler einfacher zu buchen.<br />
Bei der Entwicklung ist mir aufgefallen, dass die Bahn leider keine Webservices nach außen zur Verfügung stellt – die Webseite <a href="http://www.bahn.de">www.bahn.de</a> ist zusammen mit der mobilen Variante <a href="http://m.bahn.de">m.bahn.de</a> die einzige Schnittstelle.</p>
<p>Daher habe ich das Projekt <a href="http://code.google.com/p/openbahn-api">Openbahn-API</a> ins Leben gerufen: Es handelt sich um eine API, die Funktionalitäten der Bahn-Webseite als Webservices zur Verfügung stellt. Über diese Services können eigene Programme die verfügbaren Bahnhöfe oder Zugverbindungen inkl. Zeiten und Preise abrufen. Des Weiteren ist es über die Schnittstelle möglich, Zugtickets zu buchen oder Sitzplätze zu reservieren.</p>
<p>Die Dokumentation und URLs zu den einzelnen Services finden sich auf der Projektseite unter <a href="http://code.google.com/p/openbahn-api">http://code.google.com/p/openbahn-api</a>. Diese werden über HTTP-GET aufgerufen und liefern JSON Objekte zurück. So gibt der Aufruf von <a href="http://openbahnapi.appspot.com/rest/stations/list?contains=karlsr">http://openbahnapi.appspot.com/rest/stations/list?contains=karlsr</a> eine Liste von JSON-Objekten zurück, die alle Bahnhöfe enthalten, die im Namen „karlsr“ enthalten. Im Beispiel sind dies die gesamten Bahnhöfe im Stadtgebiet von Karlsruhe.</p>
<p>Die API kann verwendet werden, um eigene Anwendungen zu entwickeln, die Bahndaten benötigen.</p>
<p>Um die Qualität des Parsers zu sichern, wird der Code komplett als GPL auf Google Code unter <a href="http://code.google.com/p/openbahn-api">http://code.google.com/p/openbahn-api</a> zur Verfügung gestellt – jeder Entwickler ist herzlich dazu eingeladen Verbesserungen und Erweiterungen vorzunehmen. Das Hosting erfolgt über die Google AppEngine. Die Ergebnisse der Anfragen werden über einen Cache zwischengespeichert, so dass die Kommunikation mit der Bahn-Webseite minimiert wird und für vorhandene Ergebnisse auch funktioniert, wenn diese offline ist.</p>
<p>Ich bin gespannt auf eure Meinung und wünsche euch viel Spaß mit der neuen API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2011/06/openbahn-api-%e2%80%93-bahn-webseite-als-webservice/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to detect whether an element is in a scrollable parent</title>
		<link>http://www.marcusschiesser.de/2009/11/how-to-detect-whether-an-element-is-in-a-scrollable-parent/</link>
		<comments>http://www.marcusschiesser.de/2009/11/how-to-detect-whether-an-element-is-in-a-scrollable-parent/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 20:54:28 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[hidden]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[scrollable]]></category>
		<category><![CDATA[visible]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=352</guid>
		<description><![CDATA[Just think of having an element in a scrollable parent (the CSS property overflow is set to scroll) and you want to test whether the element is visible or not. Using this little function you can do the trick: function isInView&#40;node&#41;&#123; var offsetParent = node.offsetParent; var top = offsetParent.scrollTop; var height = offsetParent.offsetHeight; var y [...]]]></description>
			<content:encoded><![CDATA[<p>Just think of having an element in a scrollable parent (the CSS property <code>overflow</code> is set to <code>scroll</code>) and you want to test whether the element is visible or not.</p>
<p>Using this little function you can do the trick:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> isInView<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> offsetParent <span style="color: #339933;">=</span> node.<span style="color: #660066;">offsetParent</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> top <span style="color: #339933;">=</span> offsetParent.<span style="color: #660066;">scrollTop</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> height <span style="color: #339933;">=</span> offsetParent.<span style="color: #660066;">offsetHeight</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> node.<span style="color: #660066;">offsetTop</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span> y <span style="color: #339933;">&gt;=</span> top <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&lt;=</span> <span style="color: #009900;">&#40;</span>top <span style="color: #339933;">+</span> height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And here&#8217;s a small use case &#8211; this one scrolls the element into the visible region, if it is not already in the view:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isInView<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            element.<span style="color: #660066;">scrollIntoView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2009/11/how-to-detect-whether-an-element-is-in-a-scrollable-parent/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Let the user select an item in a modal dialog</title>
		<link>http://www.marcusschiesser.de/2009/08/selecting-an-item-in-javascript/</link>
		<comments>http://www.marcusschiesser.de/2009/08/selecting-an-item-in-javascript/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 13:31:29 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[choose]]></category>
		<category><![CDATA[item]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[yui3]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=328</guid>
		<description><![CDATA[After having used the shiny new YUI3 library for a project, it&#8217;s about time to share my YUI3 experiences with you. For the project I built an item selector: A modal dialog is openend and the user has to select an item. After selection the dialog is closed and the selected item is passed to [...]]]></description>
			<content:encoded><![CDATA[<p><script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js">
</script>After having used the shiny new <a href="http://developer.yahoo.com/yui/3/">YUI3</a> library for a project, it&#8217;s about time to share my YUI3 experiences with you.<br />
For the project I built an item selector: A modal dialog is openend and the user has to select an item. After selection the dialog is closed and the selected item is passed to a callback function.</p>
<p>Here you can find the <a href="http://www.marcusschiesser.de/wp-content/uploads/2009/08/ItemSelector.js">full source</a> for the item selector. An example to use the selector can be as simple as this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">ms.<span style="color: #660066;">ItemSelector</span>.<span style="color: #660066;">selectItem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'Bart'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Lisa'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Homer'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Marge'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Maggie'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Ned'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Barney'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Bob'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' is your favorite character.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just click on the following button, to start the example. Enjoy and let me know your comments.</p>
<style type="text/css">			a.item-selector-clickme {
				background-color: red;
				padding: 4px;
				color: white;
				text-decoration: none;
			}	a.item-selector-clickme:hover {
				color: yellow;
			}  .item-selector-header {
                font-weight: bold;
                padding: 10px;
            } .item-selector {
                overflow: auto;
                height: 150px;
            }.item-selector li a:hover {
                color: red;
            }.item-selector li {
                list-style: none;
            } .item-selector li a {
                text-decoration: none;
                color: #333;
            }  .yui-overlay-content {
                padding: 3px; font-size: 16px;  font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
				width: 200px;
				height: 210px;
                border: 2px solid #000;
                background-color: #fff;
            }
        </style>
<p>        <script type="text/javascript" src="http://www.marcusschiesser.de/wp-content/uploads/2009/08/ItemSelector.js">
        </script><br />
        <script type="text/javascript" src="http://www.marcusschiesser.de/wp-content/uploads/2009/08/itemselector.js">
        </script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2009/08/selecting-an-item-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quince: UX Pattern Explorer</title>
		<link>http://www.marcusschiesser.de/2009/06/quince-ux-pattern-explorer/</link>
		<comments>http://www.marcusschiesser.de/2009/06/quince-ux-pattern-explorer/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 20:14:17 +0000</pubDate>
		<dc:creator>Marcus Schiesser</dc:creator>
				<category><![CDATA[UX]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://www.marcusschiesser.de/?p=319</guid>
		<description><![CDATA[Just in case you don&#8217;t already know it: Quince &#8211; calls itself an UX Patterns Explorer and that&#8217;s just what it is. You want to improve the user experience of your applications? Just take a look at this marble. It contains a large number of design patterns for creating great user interfaces. Even the exploration [...]]]></description>
			<content:encoded><![CDATA[<p>Just in case you don&#8217;t already know it: <a href="http://quince.infragistics.com/">Quince</a> &#8211; calls itself an UX Patterns Explorer and that&#8217;s just what it is.</p>
<p>You want to improve the user experience of your applications? Just take a look at this marble. It contains a large number of <a href="http://en.wikipedia.org/wiki/Design_patterns">design patterns</a> for creating great user interfaces.</p>
<p>Even the exploration part of this tool is innovative: The patterns are not only ordered alphabetically by name but can be found by the tasks the user wants to accomplish.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusschiesser.de/2009/06/quince-ux-pattern-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

