<?xml version="1.0" encoding="UTF-8"?>

<feed xmlns="http://www.w3.org/2005/Atom">
	<title>Jérôme Nègre&apos;s piece of web</title>
	<icon>http://www.jnegre.org/favicon.ico</icon>
	<link href="http://www.jnegre.org/" />
	<link rel="self" type="application/atom+xml" href="http://www.jnegre.org/news/atom.xml" />

	<updated>2023-12-26T11:38:25+01:00</updated>
	<author>
		<name>Jérôme Nègre</name>
	</author>
	<id>http://www.jnegre.org/</id>

	
		<entry>
			<title>Site Update</title>
			<link href="http://www.jnegre.org/news/2023/09/17/site_update.html"/>
			<id>http://www.jnegre.org/news/2023/09/17/site_update.html</id>
			<updated>2023-09-17T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p><em>Long time no see!</em></p>

<p>Took a bit of time to update</p>
<ul>
  <li>my social networks: goodbye Google+, Twitter and Bitbucket; hello Mastodon and LinkedIn</li>
  <li>my resume: I’m not working as a developer anymore</li>
  <li>the CSS: because I’m still a developer at heart 😉</li>
</ul>


				</div>
			</content>
		</entry>
	
		<entry>
			<title>S2 Geometry Library</title>
			<link href="http://www.jnegre.org/news/2015/08/02/S2_Geometry_Library.html"/>
			<id>http://www.jnegre.org/news/2015/08/02/S2_Geometry_Library.html</id>
			<updated>2015-08-02T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>The S2 Geometry Library is a spherical geometry library originally made by Google,
released under the Apache License (Version 2.0),
which is very useful for manipulating regions on the sphere (commonly on Earth) and indexing geographic data.
I use it in several of my personal toy projects, both on desktop and on Android.</p>

<p><img style="float:right; margin-left:5px;" src="/news/assets/2015-08-02-S2_Geometry_Library.jpg" width="500" height="281" alt="Use the Fork, Luke" /></p>

<p>Sadly, it is/was hosted on <a href="https://code.google.com/p/s2-geometry-library-java">Google Code</a>,
but <a href="http://google-opensource.blogspot.fr/2015/03/farewell-to-google-code.html">Google Code is closing</a>.
The project has had no activity since 2011 and looks abandoned, so I had little hope to see it migrate
somewhere else. Too bad for such a useful project!</p>

<p>But the beauty of Free and Open Source Software is that anyone is free to fork the code to fit his needs.
And that’s what I did.</p>

<p>I’ve put the sources on <a href="https://github.com/jnegre/s2-geometry-library-java">Github</a>, who hopefully won’t close in the near future.
I have changed the build system to use Gradle instead of Ant, but the core of the library hasn’t changed.</p>

<p>The continuous integration is provided by <a href="https://travis-ci.org/jnegre/s2-geometry-library-java">Travis CI</a>.</p>

<p>The binaries are published on <a href="https://bintray.com/jnegre/maven/org.jnegre.google%3As2-geometry/view">Bintray</a>,
so using them in your Gradle or Maven build is dead easy.</p>

<p>For Gradle, add the following repository in your <code class="language-plaintext highlighter-rouge">build.gradle</code>:</p>

<figure class="highlight"><pre><code class="language-groovy" data-lang="groovy"><span class="n">repositories</span> <span class="o">{</span>
  <span class="n">maven</span> <span class="o">{</span>
    <span class="n">url</span> <span class="s2">"http://dl.bintray.com/jnegre/maven"</span>
  <span class="o">}</span>
<span class="o">}</span></code></pre></figure>

<p>Then reference the artifact you need:</p>

<figure class="highlight"><pre><code class="language-groovy" data-lang="groovy"><span class="n">dependencies</span> <span class="o">{</span>
  <span class="n">compile</span> <span class="s1">'org.jnegre.google:s2-geometry:1.2'</span>
<span class="o">}</span></code></pre></figure>

<p>If you’re using Maven, add the repository in your <code class="language-plaintext highlighter-rouge">settings.xml</code>:</p>

<figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="cp">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>
<span class="nt">&lt;settings</span> <span class="na">xsi:schemaLocation=</span><span class="s">'http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'</span>
<span class="na">xmlns=</span><span class="s">'http://maven.apache.org/SETTINGS/1.0.0'</span> <span class="na">xmlns:xsi=</span><span class="s">'http://www.w3.org/2001/XMLSchema-instance'</span><span class="nt">&gt;</span>
  <span class="nt">&lt;profiles&gt;</span>
    <span class="nt">&lt;profile&gt;</span>
      <span class="nt">&lt;repositories&gt;</span>
        <span class="nt">&lt;repository&gt;</span>
          <span class="nt">&lt;snapshots&gt;</span>
            <span class="nt">&lt;enabled&gt;</span>false<span class="nt">&lt;/enabled&gt;</span>
          <span class="nt">&lt;/snapshots&gt;</span>
          <span class="nt">&lt;id&gt;</span>bintray-jnegre-maven<span class="nt">&lt;/id&gt;</span>
          <span class="nt">&lt;name&gt;</span>bintray<span class="nt">&lt;/name&gt;</span>
          <span class="nt">&lt;url&gt;</span>http://dl.bintray.com/jnegre/maven<span class="nt">&lt;/url&gt;</span>
        <span class="nt">&lt;/repository&gt;</span>
      <span class="nt">&lt;/repositories&gt;</span>
      <span class="nt">&lt;id&gt;</span>bintray<span class="nt">&lt;/id&gt;</span>
    <span class="nt">&lt;/profile&gt;</span>
  <span class="nt">&lt;/profiles&gt;</span>
  <span class="nt">&lt;activeProfiles&gt;</span>
    <span class="nt">&lt;activeProfile&gt;</span>bintray<span class="nt">&lt;/activeProfile&gt;</span>
  <span class="nt">&lt;/activeProfiles&gt;</span>
<span class="nt">&lt;/settings&gt;</span></code></pre></figure>

<p>Then add the dependency in your <code class="language-plaintext highlighter-rouge">pom.xml</code>:</p>

<figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;dependency&gt;</span>
  <span class="nt">&lt;groupId&gt;</span>org.jnegre.google<span class="nt">&lt;/groupId&gt;</span>
  <span class="nt">&lt;artifactId&gt;</span>s2-geometry<span class="nt">&lt;/artifactId&gt;</span>
  <span class="nt">&lt;version&gt;</span>1.2<span class="nt">&lt;/version&gt;</span>
  <span class="nt">&lt;type&gt;</span>jar<span class="nt">&lt;/type&gt;</span>
<span class="nt">&lt;/dependency&gt;</span></code></pre></figure>

<p>(I suspect the Maven developers are paid by the hard disk manufacturers to have such verbose file formats.)</p>

<p>Did I mention the fact that this library works perfectly well on Android? Because it does.</p>

<p>Gosh, I love Open Source!</p>


				</div>
			</content>
		</entry>
	
		<entry>
			<title>Dr. Jekyll and Mr. XSLT</title>
			<link href="http://www.jnegre.org/news/2015/04/18/dr_jekyll_and_mr_xslt.html"/>
			<id>http://www.jnegre.org/news/2015/04/18/dr_jekyll_and_mr_xslt.html</id>
			<updated>2015-04-18T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>I’ve always been a big fan of static websites, for mainly two reasons: simplicity and security.
Simplicity, because why have a complex software on the server when the content is updated at most
once or twice a month? Security, because the most secure lines of code are the ones that have never been written.</p>

<p>In 2002, nothing was really existing to easily generate a static website, so I wrote an Eclipse plugin,
<a href="/styloplume/index.html">Stylo Plume</a>, to help me accomplish this.
And since the year was 2002, and I was working a lot with XML and XSL, I used XSLT.</p>

<figure>
	<img src="/news/assets/2015-04-18-jnegre_org_in_2002.png" alt="This site in 2002" />
	<figcaption>This very web site in 2002. In Technicolor, baby!</figcaption>
</figure>

<p>Fast forward 13 years later. I still think a static website is what I need,
but I’m getting tired of XSLT, and I really don’t feel like testing and
potentially fixing my plugin with Java 8 and the Eclipse 4 branch.
So I started looking at some static site generators, and I stumbled upon
<a href="http://tom.preston-werner.com/2008/11/17/blogging-like-a-hacker.html">a post from Tom Preston-Werner</a>
that sums up nicely my feelings:</p>

<blockquote>
  <p>I already knew a lot about what I <strong>didn’t</strong> want. I was tired of complicated blogging engines like WordPress and Mephisto. I wanted to write great posts, not style a zillion template pages, moderate comments all day long, and constantly lag behind the latest software release. Something like Posterous looked attractive, but I wanted to style my blog, and it needed to be hosted at the domain of my choosing. For the same reason, other hosted sites (wordpress.com, blogger.com) were disqualified.</p>
</blockquote>

<p>Tom Preston-Werner is the creator of <a href="http://jekyllrb.com/">Jekyll</a>,
and after 2 weeks to migrate the source of my site, I can say that I’m now a happy user.</p>

				</div>
			</content>
		</entry>
	
		<entry>
			<title>Feeling hungry?</title>
			<link href="http://www.jnegre.org/news/2015/03/30/feeling_hungry.html"/>
			<id>http://www.jnegre.org/news/2015/03/30/feeling_hungry.html</id>
			<updated>2015-03-30T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>Do you feel hungry? Do you speak French?</p>

<p>If the answer to both questions is “yes”, I’ve added a bunch of recipes:
<a href="/ego/coin_cuisine/tarte_a_la_tomate.html">Tarte à la tomate</a>,
<a href="/ego/coin_cuisine/egg_in_the_basket.html">Egg in the basket</a>
and <a href="/ego/coin_cuisine/encornets_a_ma_facon.html">Encornets à ma façon</a>.</p>

<p><em>Bon appétit !</em></p>

				</div>
			</content>
		</entry>
	
		<entry>
			<title>OpenStreetMap and Android</title>
			<link href="http://www.jnegre.org/news/2012/08/31/openstreetmap_and_android.html"/>
			<id>http://www.jnegre.org/news/2012/08/31/openstreetmap_and_android.html</id>
			<updated>2012-08-31T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p><img style="float:right; margin-left:5px;" src="/news/assets/2012-08-31-osm_logo.png" width="200" height="200" alt="OSM logo" /></p>

<p>This summer, I went on vacation to a place that was not covered by <a href="http://www.openstreetmap.org/">OpenStreetMap</a>,
so I became a small OpenStreetMap contributer and mapped the surroundings.
Here’s the list of software that I used on my Android devices.</p>

<p>To gather GPS data, I used <a href="https://code.google.com/p/osmtracker-android/">OSM Tracker for Android</a>, available both in
<a href="https://play.google.com/store/apps/details?id=me.guillaumin.android.osmtracker">Google Play</a> and via 
<a href="http://f-droid.org/repository/browse/?fdid=me.guillaumin.android.osmtracker">F-Droid</a>.
It’s a nice GPS tracker with fast Points of Interest (POI) placement shortcuts.
It should be able to upload traces directly to OSM, but this functionality always crashed with me;
uploading the generated traces (.gpx) with the website worked once I renamed the files to remove
non-ASCII characters.</p>

<p>To edit the map, I used <a href="http://code.google.com/p/osmeditor4android/">Vespucci</a>, which is also available both in
<a href="https://play.google.com/store/apps/details?id=de.blau.android">Google Play</a> and via 
<a href="http://f-droid.org/repository/browse/?fdid=de.blau.android">F-Droid</a>.
It’s fine for relative small edits, but for larger one you’d better use the Flash-based
<a href="http://wiki.openstreetmap.org/wiki/Potlatch_2">Potlatch 2</a>.
Another useful application to edit details such as the name of roads or POIs is
<a href="http://osmaptuner.salzburgresearch.at/">OSMapTuner</a> <em>(see update)</em>, available in
<a href="https://play.google.com/store/apps/details?id=at.srfg.osmaptuner">Google Play</a>.</p>

<p><a href="http://openfixmap.bmaron.net/">OpenFixMap</a> (in
<a href="https://play.google.com/store/apps/details?id=net.bmaron.openfixmap">Google Play</a>) was very helpful to
flag errors on the map. You’ll have to use an editor to fix them.</p>

<p>A more comprehensive list can be found on OpenStreetMap’s wiki:
<a href="http://wiki.openstreetmap.org/wiki/Android#Android_software_supporting_OpenStreetMap">Android software supporting OpenStreetMap</a>.
Happy <del>hacking</del> mapping!</p>

<p><em>Update:</em> I’ve just found another editor for POIs,
<a href="https://play.google.com/store/apps/details?id=com.mapzen">Mapzen POI Collector</a>. It can add POIs and has a much nicer
user interface. However, it is limited to the most common types of POI, so if you have very special needs, it’s not for you.</p>


				</div>
			</content>
		</entry>
	
		<entry>
			<title>Deploying to a maven repository via SCP with Gradle</title>
			<link href="http://www.jnegre.org/news/2011/12/23/deploy_to_maven_repository_via_scp_with_gradle.html"/>
			<id>http://www.jnegre.org/news/2011/12/23/deploy_to_maven_repository_via_scp_with_gradle.html</id>
			<updated>2011-12-23T00:00:00+01:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>Deploying your artifacts to a remote Maven repository with Gradle is possible, but the official documentation is rather thin at the time of this writing. Worse, it tells you to use a version of wagon-ssh that ignores the provided password and prompt for it at the command line (use gradle -i to see its message).</p>

<p>So, without further ado, here is a build.gradle that uploads its artifact via scp with a password. It has been tested with Gradle 1.0-milestone-6.</p>

<figure class="highlight"><pre><code class="language-groovy" data-lang="groovy"><span class="n">apply</span> <span class="nl">plugin:</span> <span class="s1">'java'</span>
<span class="n">apply</span> <span class="nl">plugin:</span> <span class="s1">'maven'</span>

<span class="n">configurations</span> <span class="o">{</span>
    <span class="n">deployerJars</span>
<span class="o">}</span>

<span class="n">repositories</span> <span class="o">{</span>
    <span class="n">mavenLocal</span><span class="o">()</span>
    <span class="n">mavenCentral</span><span class="o">()</span>
<span class="o">}</span>

<span class="n">dependencies</span> <span class="o">{</span>
    <span class="c1">//the one and only version that works</span>
    <span class="n">deployerJars</span> <span class="s1">'org.apache.maven.wagon:wagon-ssh:1.0-alpha-3'</span>
<span class="o">}</span>

<span class="n">uploadArchives</span> <span class="o">{</span>
    <span class="n">repositories</span><span class="o">.</span><span class="na">mavenDeployer</span> <span class="o">{</span>
        <span class="n">configuration</span> <span class="o">=</span> <span class="n">configurations</span><span class="o">.</span><span class="na">deployerJars</span>
        <span class="n">uniqueVersion</span> <span class="o">=</span> <span class="kc">false</span>
        <span class="n">String</span> <span class="n">username</span> <span class="o">=</span> <span class="s1">'me'</span>
        <span class="n">String</span> <span class="n">password</span> <span class="o">=</span> <span class="s1">'secret'</span>
        <span class="n">repository</span><span class="o">(</span><span class="nl">url:</span> <span class="s1">'scp://repos.mycompany.com/releases'</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">authentication</span><span class="o">(</span><span class="nl">userName:</span> <span class="n">username</span><span class="o">,</span> <span class="nl">password:</span> <span class="n">password</span><span class="o">)</span>
        <span class="o">}</span>
        <span class="n">snapshotRepository</span><span class="o">(</span><span class="nl">url:</span> <span class="s1">'scp://repos.mycompany.com/snapshots'</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">authentication</span><span class="o">(</span><span class="nl">userName:</span> <span class="n">username</span><span class="o">,</span> <span class="nl">password:</span> <span class="n">password</span><span class="o">)</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span></code></pre></figure>

<p>Of course, in a real world scenario, it would be wiser to get the username and password from your gradle.properties or any other non-public file.</p>

				</div>
			</content>
		</entry>
	
		<entry>
			<title>Book review: &quot;Building and Testing with Gradle&quot;</title>
			<link href="http://www.jnegre.org/news/2011/09/21/book_review_building_and_testing_with_gradle.html"/>
			<id>http://www.jnegre.org/news/2011/09/21/book_review_building_and_testing_with_gradle.html</id>
			<updated>2011-09-21T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>Gradle is a very flexible and powerful build tool, allowing an extremely concise build file for conventional
projects and letting you do whatever crazy thing your project requires using a Groovy DSL.
I’ve been following its development for the last two years, and I introduced it to replace a legacy Ant based
build system at my work about a year ago.</p>

<p><img style="float:left; margin-right:5px;" src="/news/assets/2011-09-21-building_testing_gradle_cover.png" width="250" height="328" alt="Cover" /></p>

<p>As far as I know, <i>Building and Testing with Gradle</i>, written by Tim Berglund and Matthew McCullough
and published by O’Reilly, is the first book published on this topic.</p>

<p>The first chapter will guide you through the installation process and the use of the Gradle from the command line.
I’m not sure someone willing to use Gradle needs that kind of information.
It will also show you the shorter build file possible for a Java project, containing only 18 non-whitespace characters:
compare this with Maven…</p>

<p>The second chapter is were the serious stuff begins.
It presents the basic unit of Gradle build files: tasks.
The two lifecycle phases, configuration and execution, are explained.
You’ll also learn how to use their rich API and how to simply write your own tasks.
If you’re used to the complexity of Maven, be prepared for a shock as this is dead simple and way conciser.</p>

<p>The third chapter shows how Gradle can leverage your existing Ant files and custom tasks.
This particularity of Gradle allows a step-by-step migration from Ant.</p>

<p>The fourth chapter compares Maven and Gradle.
Gradle takes the best ideas from Maven (and others): convention over configuration, consistently named artifacts
and a solid dependency management with the same central repositories.
It drops what makes Maven so painful to use: tons of XML, a rigid lifecycle and more generally its lack of flexibility.</p>

<p>The fifth chapter is about testing. The integration of JUnit, TestNG, Spock, Geb and EasyB will be rapidly shown.</p>

<p>The sixth and last chapter is focused on multiproject (or multimodule) builds.
Once again, the tremendous flexibility of Gradle makes it bend to your needs rather than imposing its standards on you.</p>

<p>This is a short book with fewer than a hundred pages, read in a couple of hours, and full of code samples.
It is an introduction to Gradle, not a complete  reference guide: it will show you the power and the simplicity of Gradle,
and - I hope - will convince you to give Gradle a try.</p>

				</div>
			</content>
		</entry>
	
		<entry>
			<title>Using the Brother HL-2250DN laser printer on Ubuntu Linux</title>
			<link href="http://www.jnegre.org/news/2011/07/31/brother_HL_2250DN_ubuntu_linux.html"/>
			<id>http://www.jnegre.org/news/2011/07/31/brother_HL_2250DN_ubuntu_linux.html</id>
			<updated>2011-07-31T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>The Brother HL-2250DN is a laser printer with both a USB and an Ethernet interface.
It understands PCL6, so I knew I could use it with my Ubuntu 10.10 box without too much troubles.</p>

<p>Here’s how to configure your computer to enjoy the Ethernet interface.
One doesn’t buy a network printer to use USB, right?</p>

<p>First, one need to get the IP address of the printer. You could get it from your router, or you
may just ask the printer. To print the settings of your printer, do the following:</p>

<ol>
  <li>Switch on the printer;</li>
  <li>Wait till the printer is ready;</li>
  <li>Press “Go” three times in less than 2 seconds.</li>
</ol>

<p>The IP address will be on the third page.</p>

<p>Now, on your Ubuntu box:</p>

<ol>
  <li>Go to System / Administration / Printing;</li>
  <li>Click on the “Add” button;</li>
  <li>Select “LPD/LPR Host or Printer” on the left;</li>
  <li>On the right, enter the printer’s IP address;</li>
  <li>The name of the queue is “PCL_P1”;</li>
  <li>When asked for a driver, pick “Generic PCL 6/PCL XL Printer - CUPS+Gutenprint v5.2.6 Simplified”.</li>
</ol>

<p>And voilà!</p>

				</div>
			</content>
		</entry>
	
		<entry>
			<title>Beware of javax.xml.xpath</title>
			<link href="http://www.jnegre.org/news/2011/06/26/beware_of_javax_xml_xpath.html.html"/>
			<id>http://www.jnegre.org/news/2011/06/26/beware_of_javax_xml_xpath.html.html</id>
			<updated>2011-06-26T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>I had to parse in Java an rather big XML document that was looking something like that:</p>

<figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;root&gt;</span>
	<span class="nt">&lt;child1&gt;</span>
		<span class="nt">&lt;a&gt;</span>I need this element<span class="nt">&lt;/a&gt;</span>
		<span class="nt">&lt;b&gt;</span>but not this one<span class="nt">&lt;/b&gt;</span>
		<span class="nt">&lt;c&gt;</span>this one is also irrelevant<span class="nt">&lt;/c&gt;</span>
	<span class="nt">&lt;/child1&gt;</span>
	<span class="nt">&lt;child2&gt;</span>
		<span class="nt">&lt;a&gt;&lt;/a&gt;</span>
		<span class="nt">&lt;b&gt;&lt;/b&gt;</span>
		<span class="nt">&lt;c&gt;&lt;/c&gt;</span>
	<span class="nt">&lt;/child2&gt;</span>
	<span class="c">&lt;!-- and so on to fill more than 4 Mo --&gt;</span>
<span class="nt">&lt;/root&gt;</span></code></pre></figure>

<p>There are hundreds of first level child nodes, but each one only has a few children.</p>

<p>Given any child node, I had to get one of its own children by its name. I had two options:</p>

<ul>
  <li>iterate over the list of children, and check each one to see if it’s the one I am looking for (5 lines of code);</li>
  <li>or be lazy and use a very simple XPath expression (1 line of code).</li>
</ul>

<p>Being lazy, and since the context nodes were having only a few child nodes, I decided to go with XPath.
I knew there would be some overhead, but it shouldn’t be very big, right?</p>

<p>Wrong.</p>

<p>My code wasn’t doing anything fancy, but it took 40 seconds to complete.
Being curious about the overhead introduced by XPath, I replaced it by a bunch of node.getChildNodes().
The total time dropped to 0.1 second.</p>

<p>I wrote a small benchmark to illustrate this problem.
It boils down to these two methods:</p>

<figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="cm">/**
 * Returns the direct child of parent with the given name using XPath
 */</span>
<span class="kd">private</span> <span class="kd">static</span> <span class="nc">Node</span> <span class="nf">getChildXPath</span><span class="o">(</span><span class="nc">Node</span> <span class="n">parent</span><span class="o">,</span> <span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="kd">throws</span> <span class="nc">Exception</span> <span class="o">{</span>
	<span class="k">return</span> <span class="o">(</span><span class="nc">Node</span><span class="o">)</span><span class="n">xpath</span><span class="o">.</span><span class="na">evaluate</span><span class="o">(</span><span class="n">name</span><span class="o">,</span> <span class="n">parent</span><span class="o">,</span> <span class="nc">XPathConstants</span><span class="o">.</span><span class="na">NODE</span><span class="o">);</span>
<span class="o">}</span>

<span class="cm">/**
 * Returns the direct child of parent with the given name using getChildNodes()
 */</span>
<span class="kd">private</span> <span class="kd">static</span> <span class="nc">Node</span> <span class="nf">getChildDom</span><span class="o">(</span><span class="nc">Node</span> <span class="n">parent</span><span class="o">,</span> <span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="kd">throws</span> <span class="nc">Exception</span> <span class="o">{</span>
	<span class="nc">NodeList</span> <span class="n">list</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="na">getChildNodes</span><span class="o">();</span>
	<span class="k">for</span><span class="o">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="o">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">list</span><span class="o">.</span><span class="na">getLength</span><span class="o">();</span> <span class="n">i</span><span class="o">++)</span> <span class="o">{</span>
		<span class="nc">Node</span> <span class="n">child</span> <span class="o">=</span> <span class="n">list</span><span class="o">.</span><span class="na">item</span><span class="o">(</span><span class="n">i</span><span class="o">);</span>
		<span class="k">if</span><span class="o">(</span><span class="n">child</span><span class="o">.</span><span class="na">getNodeType</span><span class="o">()</span> <span class="o">==</span> <span class="nc">Node</span><span class="o">.</span><span class="na">ELEMENT_NODE</span> <span class="o">&amp;&amp;</span> <span class="n">name</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">child</span><span class="o">.</span><span class="na">getNodeName</span><span class="o">()))</span> <span class="o">{</span>
			<span class="k">return</span> <span class="n">child</span><span class="o">;</span>
		<span class="o">}</span>
	<span class="o">}</span>
	<span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span></code></pre></figure>

<p>The full code is available on <a href="https://gist.github.com/1046969">github</a>.</p>

<p>On my linux box with OpenJDK 1.6.0_20, I got the following results:</p>

<figure class="highlight"><pre><code class="language-plaintext" data-lang="plaintext">Children were found using DOM in 2 ms
Children were found using XPath in 4016 ms</code></pre></figure>

<p>Lesson learned: javax.xml.xpath is slow as hell, even for very simple expressions.</p>


				</div>
			</content>
		</entry>
	
		<entry>
			<title>Stylo Plume 0.2.0</title>
			<link href="http://www.jnegre.org/news/2011/06/19/styloplume_0_2_0.html"/>
			<id>http://www.jnegre.org/news/2011/06/19/styloplume_0_2_0.html</id>
			<updated>2011-06-19T00:00:00+02:00</updated>
			<content type="xhtml" xml:lang="en">
				<div xmlns="http://www.w3.org/1999/xhtml">
					<p>This web site is still built with XSL using my good old Eclipse plugin 
<a href="/styloplume/index.html">Stylo Plume</a>. Everything was OK for the past years, but
a few weeks ago I wanted to redesign the news section on the home page, to add individual links to each announcement.
I wanted something a bit like a blog, but without comments and fully in static html (no server-side PHP/Java/whatever).</p>

<p>In order to do so, I needed to add a new functionality to <a href="/styloplume/index.html">Stylo Plume</a>,
namely to enhance the dir:// protocol to be able to list sub-directories recursively.
So 8 years after the last release, I searched in a bunch of old hard drives to recover my
ancient CVS server and put the code in Mercurial.
A public repository is now available on <a href="https://bitbucket.org/jnegre/styloplume">Bitbucket</a>.</p>

<p>Release 0.2.0 is out today, it includes the modification to the dir:// protocol and the replacement of Xalan by the
XML stack included in the JVM.</p>

<p>Oh, and there’s even an <a href="/news/atom.xml">Atom feed</a> for the news, now!</p>

				</div>
			</content>
		</entry>
	
</feed>

