<?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>fforw.de &#187; code</title>
	<atom:link href="http://fforw.de/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://fforw.de</link>
	<description>skip the boring parts</description>
	<lastBuildDate>Fri, 10 Sep 2010 16:32:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Generating List&lt;Something&gt; from JSON with svenson</title>
		<link>http://fforw.de/post/generating-list-from-json-with-svenson/</link>
		<comments>http://fforw.de/post/generating-list-from-json-with-svenson/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 18:26:19 +0000</pubDate>
		<dc:creator>fforw</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[svenson]]></category>

		<guid isPermaLink="false">http://fforw.de/?p=217</guid>
		<description><![CDATA[Often you&#8217;ll find yourself wanting to parse a JSON into a Java collection but want the values inside the collection to be of a specific type. Nothing easier than that. import org.svenson.JSONParser; … // Getting a list containing your own type Something. // Assume json to be a String containing the JSON dataset. JSONParser parser [...]]]></description>
			<content:encoded><![CDATA[<p>Often you&#8217;ll find yourself wanting to parse a JSON into a Java collection but want the values inside the collection to be of a specific type. Nothing easier than that.</p>
<p><span style="color: #0000ff;"> </span></p>
<pre><span style="color: #0000ff;">import</span> org.svenson.JSONParser;
…
<span style="color: #008000;">// Getting a list containing your own type Something.
// Assume json to be a String containing the JSON dataset.
</span>JSONParser parser = <span style="color: #0000ff;">new</span> JSONParser();
parser.addTypeHint("[]", Something.class);
List&lt;Something&gt; someThings = parser.parse(List.class, json);
<span style="color: #008000;">// someThings will be a ArrayList instance by default. You can change
// that by changing the mappings for interfaces by calling
// org.svenson.JSONParser.setInterfaceMappings(Map&lt;Class, Class&gt;)
</span></pre>
<p>Parsing into a map is not much more complicated either</p>
<pre>JSONParser jsonParser = <span style="color: #0000ff;">new</span> JSONParser();
jsonParser.addTypeHint(new RegExPathMatcher("\\.(f1|f2)"), Something.class);
Map&lt;String,Object&gt; someThings = jsonParser.parse(Map.class, json);</pre>
<p>If we want to have our Something type for more than a single field, we need to setup a matcher. Here you see an example of a RegExPathMatcher that makes sure that both the keys &#8220;f1&#8243; and &#8220;f2&#8243; of the map we receive will be converted to Something, while all other fields are not.</p>
<p>If you want to convert all map properties to Something, the RegExPathMatcher would be like this</p>
<pre>    … new RegExPathMatcher("\\..*") …</pre>
<p>This would match every JSON path that starts with a property. If you don&#8217;t like RegularExpressions, or are on some kind of diet on them, you can also construct a more complex matcher tree from the compositable Matchers like this</p>
<pre>JSONParser jsonParser = <span style="color: #0000ff;">new</span> JSONParser();<span style="color: #000000;">
jsonParser.addTypeHint(<span style="color: #0000ff;">new</span> OrMatcher(
    <span style="color: #0000ff;">new</span> PrefixPathMatcher(".f1"),
    <span style="color: #0000ff;">new</span> PrefixPathMatcher(".f2")), Something<span style="color: #0000ff;">.class</span>);
Map&lt;String,Object&gt; someThings = jsonParser.parse(Map<span style="color: #0000ff;">.class</span>, json);
</span>
</pre>
<p><strong>Update:</strong><span style="color: #000000;"> Due to me fucking up both the Prefix-/Suffix- matchers as well as their tests, the last example will only really work with the current svenson trunk/future svenson 1.3.8</span></p>
<p><span style="color: #000000;"><br />
</span></p>
<p><span style="color: #000000;"></span></p>
]]></content:encoded>
			<wfw:commentRss>http://fforw.de/post/generating-list-from-json-with-svenson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JsServ &#8211; Serverside Javascript and DOM emulation</title>
		<link>http://fforw.de/post/jsserv-serverside-javascript-and-dom-emulation/</link>
		<comments>http://fforw.de/post/jsserv-serverside-javascript-and-dom-emulation/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 23:15:43 +0000</pubDate>
		<dc:creator>fforw</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.willie/?p=12</guid>
		<description><![CDATA[I played around with some ideas about JavaScript on the server-side and came up with this little prototype. It&#8217;s a set a spring components that allow running the scripts in a website on the server side in case a user has no support for JavaScript or has disabled it. The following diagram shows the way [...]]]></description>
			<content:encoded><![CDATA[<p>I played around with some ideas about JavaScript on the server-side and came up with this little prototype. It&#8217;s a set a spring components that allow running the scripts in a website on the server side in case a user has no support for JavaScript or has disabled it.</p>
<p>The following diagram shows the way things work:</p>
<div class="wp-caption aligncenter" style="width: 489px"><img title="jsserv architectural diagram" src="http://fforw.de/static/image/user/fforw/jsserv.png" alt="The parts of jsserv" width="479" height="297" /><p class="wp-caption-text">The parts of jsserv</p></div>
<p>The DOMInterceptor intercepts the HTML output of other controller and initializes a dom state with it. The document itself is parsed into a DOM tree and the referenced scripts are loaded and executed. Additional patch scripts can be defined to alter the behaviour of other scripts.</p>
<pre>The current version adds</pre>
<blockquote>
<pre>&lt;a class="eventHelper" href="/app/event?uuid=42"&gt;...&lt;/a&gt;</pre>
</blockquote>
<p>Links around every element for which a onclick handler is registered. The links point to a DOMEvent Controller that triggers updates in the user&#8217;s DOM State.</p>
<p>A little example scripts implements a collapsable tree that changes the style classes of nested unordered lists. With the JsServ DOM Manipulation this works with JavaScript as well as without JavaScript on the client side.</p>
<p>While this code is only a rough sketch it promises a lot in terms of vastly reducing the amount of work for sites that must use javascript to get an optimal user experience but who cannot or want not to have a java-script only site. Although the link-as-click event method is rather limited, it is good enough to make a lot of DOM manipulations possible. Expressed only once in JavaScript. Running in it&#8217;s deluxe form for people with client-side JavaScript and in a basic form for people with the help of using server-side JavaScript. All is seamlessly integratable into all kinds of Controllers.</p>
<p><strong>Links:</strong></p>
<ul>
<li><a href="/static/files/jsserv-0.12.zip">Download JsServ 0.12</a><a href="http://www.springframework.org/"><br />
</a></li>
<li><a href="http://code.google.com/p/jsserv/">code.google.com project page for jsserv</a></li>
</ul>
<p><strong>Dependencies:</strong></p>
<ul>
<li><a href="http://ejohn.org/blog/bringing-the-browser-to-the-server/">Bringing the Browser to the Server</a></li>
<li><a title="Rhino Javascript engine making Javascript run on the Java platform" href="http://www.mozilla.org/rhino/">Mozilla Rhino</a></li>
<li><a href="http://www.springframework.org/">Spring Framework</a></li>
</ul>
<p><sub><strong>Edit: </strong>code.google.com link added, update to 0.12</sub></p>
]]></content:encoded>
			<wfw:commentRss>http://fforw.de/post/jsserv-serverside-javascript-and-dom-emulation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
