<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Software Engineering Orkus</title>
	<atom:link href="http://orkus.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://orkus.wordpress.com</link>
	<description>...encountered problems and solutions, code snippets, ideas and thoughts about Software Engineering</description>
	<lastBuildDate>Thu, 27 Oct 2011 08:51:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='orkus.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Software Engineering Orkus</title>
		<link>http://orkus.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://orkus.wordpress.com/osd.xml" title="Software Engineering Orkus" />
	<atom:link rel='hub' href='http://orkus.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Python: Getting umask without change</title>
		<link>http://orkus.wordpress.com/2011/04/17/python-getting-umask-without-change/</link>
		<comments>http://orkus.wordpress.com/2011/04/17/python-getting-umask-without-change/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 13:08:46 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[umask]]></category>
		<category><![CDATA[without]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=252</guid>
		<description><![CDATA[This article discusses how to use python to get the umask of a process without changing it during the process.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=252&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi, I recently found myself in the need of getting the umask of a process. After a few searches there seems to be no other way of getting the desired umask then using the <a href="http://docs.python.org/release/3.1.3/library/os.html?highlight=umask#os.umask">umask()</a> system call located within the python <a href="http://docs.python.org/release/3.1.3/library/os.html">os module</a>. The following code seems to be the universally accepted solution to this particular problem:</p>
<p><pre class="brush: python;">
def getUMask():
    current_umask = os.umask(0)
    os.umask(current_umask)

    return current_umask 
</pre></p>
<p>So the solution is to make a first call to umask() and get a hold of the current umask (Line 2). The argument you pass to the umask() call during the first invocation doesn&#8217;t matter since you are going to change it back to its original value. After that you make a second call to umask() (Line 3) with the umask you acquired during the first call (Line 2). So this is the point where you change the umask back to its original value. The call to umask is not atomic though, so you have to take this fact into account if you are using multiple threads, this could lead to race conditions.</p>
<p>Even though this is certainly not the holy grail of programming I thought I share this piece of code anyway…</p>
<p>If this post was useful to you, don’t forget to share it with the world…till next time&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/252/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=252&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2011/04/17/python-getting-umask-without-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>
	</item>
		<item>
		<title>Howto Install Tomcat 7 on Debian (Lenny)</title>
		<link>http://orkus.wordpress.com/2010/08/31/howto-install-tomcat-7-on-debian-lenny/</link>
		<comments>http://orkus.wordpress.com/2010/08/31/howto-install-tomcat-7-on-debian-lenny/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 17:35:12 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[tomcat 7]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=151</guid>
		<description><![CDATA[This Article describes how to install Apache Tomcat 7 on a Debian (Lenny) OS in 8 easy steps. For this HowTo to work smoothly you must already have Java installed on your machine. In case you haven&#8217;t Java installed on your machine, there is anoter HowTo for this Task on my Blog. Follow the instructions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=151&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This Article describes how to install <a href="http://tomcat.apache.org/download-70.cgi">Apache Tomcat 7</a> on a Debian (Lenny) OS in 8 easy steps.<br />
For this HowTo to work smoothly you must already have Java installed on your machine. In case you haven&#8217;t Java installed on your machine, there is anoter HowTo for this Task on my Blog. Follow the instructions in this <a href="http://orkus.wordpress.com/2010/07/06/howto-install-suns-java-6-on-debain-lenny/">Post</a> and come back when Java is up and running.</p>
<h1><strong>1. Download it!</strong></h1>
<p>The first step is to aquire Tomcat 7 by downloading it from the Homepage. This is really easy, I used <em><strong>wget</strong></em> to download the &#8220;<a href="http://apache.prosite.de/tomcat/tomcat-7/v7.0.2-beta/bin/apache-tomcat-7.0.2.tar.gz">apache-tomcat-7.0.2.tar.gz</a>&#8221; archive into my /temp Directory. This should look something like this:</p>
<p><pre class="brush: plain;">
cd /tmp
wget http://apache.prosite.de/tomcat/tomcat-7/v7.0.2-beta/bin/apache-tomcat-7.0.2.tar.gz
</pre></p>
<h1><strong>2. Unzip &amp; Move</strong></h1>
<p>Move the package to it&#8217;s permanant location and unzip the package into its own folder.</p>
<p><pre class="brush: plain;">
mv apache-tomcat-7.0.2/ /usr/local/tomcat
tar -zxvf apache-tomcat-7.0.0.tar.gz
</pre></p>
<h1><strong>3. Create &#8220;tomcat&#8221; Group &amp; User</strong></h1>
<p>Next you need to add a new group and a new user to your system. This will be the user and the group under which the Tomcat server runs.</p>
<p>1. To add a group called &#8220;tomcat&#8221; you simply type:<br />
<pre class="brush: plain;">
groupadd tomcat
</pre></p>
<p>2. Now you have to create a new user called &#8220;tomcat&#8221; (useradd tomcat) who belongs to the group &#8220;tomcat&#8221; (-g tomcat). You also should set the home directory of that user to the directory where you moved the Tomcat server in the previous step. In this case that would be &#8220;/usr/local/tomcat&#8221; (-d /usr/local/tomcat). So you should end up with a statement that looks something like this:<br />
<pre class="brush: plain;">
useradd -g tomcat -d /usr/local/tomcat tomcat
</pre></p>
<p>3. Now you should also add the user to the &#8220;www-data&#8221; group. This group should already exist. You do that by executing the following command:<br />
<pre class="brush: plain;">
usermod -G www-data tomcat
</pre></p>
<h1><strong>4. Create INIT File for Tomcat</strong></h1>
<p>Now you should create an INIT-File that makes it possible to start, stop and restart your Tomcat Server. This file must be located in your &#8220;/etc/init.d/&#8221; directory. You can use the following command to create a file called &#8220;tomcat&#8221; and open up that file in an editor (I used nano).</p>
<p><pre class="brush: plain;">
nano /etc/init.d/tomcat
</pre></p>
<p>Now you should add the following lines into the file an save it:</p>
<p><pre class="brush: bash;">

#Tomcat auto-start
#description: Auto-starts tomcat
#processname: tomcat
#pidfile: /var/run/tomcat.pid

#this path should point to your JAVA_HOME Directory
export JAVA_HOME=/usr/lib/jvm/java-6-sun
case $1 in

start)
  sh /usr/local/tomcat/bin/startup.sh
  ;;

stop)  
  sh /usr/local/tomcat/bin/shutdown.sh
  ;;

restart)
  sh /usr/local/tomcat/bin/shutdown.sh
  sh /usr/local/tomcat/bin/startup.sh
  ;;
esac
   
exit 0
</pre></p>
<p>Make sure you set the right paths for the startup.sh and shutdown.sh scripts. They reside in the /bin directory of your tomcat path (use the path to which you moved the tomcat files in step 2).  </p>
<h1><strong>5. Adjust Permissions of INIT File</strong></h1>
<p>Since you have to execute the tomcat file, you have to assign the correct rights for the file to be executable.<br />
This line should do the trick:</p>
<p><pre class="brush: plain;">
chmod 755 /etc/init.d/tomcat
</pre></p>
<h1><strong>6. Make Tomcat auto-start on boot (optional)</strong></h1>
<p>If you want the Tomcat Server to start every time the system boots up you can use the &#8220;update-rc.d&#8221; command to set a symbolic link at the correct runlevel. For the &#8220;tomcat fle&#8221; this looks like this:</p>
<p><pre class="brush: plain;">
update-rc.d tomcat defaults
</pre></p>
<p>Now the Tomcat Server starts automatically at system bootup. This step is optional you can always start your Tomcat Server manually like this:</p>
<p><pre class="brush: plain;">
/etc/init.d/tomcat start
</pre></p>
<h1><strong>7. Modify Tomcat Users File</strong></h1>
<p>We are almost there! In this step we need to add a user in the tomcat-users.xml. This user is used to gain access to the Tomcat Manager Interface in the next step. So open up the &#8220;tomcat-users.xml&#8221; file with any editor you like (i used nano):</p>
<p><pre class="brush: plain;">
nano /usr/local/tomcat/conf/tomcat-users.xml
</pre></p>
<p>There is a &lt;tomcat-users&gt; section within that file. After the installation this section should only contain comments and look something like this:</p>
<p><pre class="brush: xml;">
&lt;tomcat-users&gt;
&lt;!--
  NOTE:  By default, no user is included in the &quot;manager-gui&quot; role required
  to operate the &quot;/manager/html&quot; web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
--&gt;
&lt;!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  &lt;!.. ..&gt; that surrounds them.
--&gt;
&lt;!--
  &lt;role rolename=&quot;tomcat&quot;/&gt;
  &lt;role rolename=&quot;role1&quot;/&gt;
  &lt;user username=&quot;tomcat&quot; password=&quot;tomcat&quot; roles=&quot;tomcat&quot;/&gt;
  &lt;user username=&quot;both&quot; password=&quot;tomcat&quot; roles=&quot;tomcat,role1&quot;/&gt;
  &lt;user username=&quot;role1&quot; password=&quot;tomcat&quot; roles=&quot;role1&quot;/&gt;
--&gt;
&lt;/tomcat-users&gt;
</pre></p>
<p>Now all we need to do is add a new user by adding some new lines here. After insertion the section should look like this:</p>
<p><pre class="brush: xml;">
&lt;tomcat-users&gt;
&lt;!--
  NOTE:  By default, no user is included in the &quot;manager-gui&quot; role required
  to operate the &quot;/manager/html&quot; web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
--&gt;
&lt;!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  &lt;!.. ..&gt; that surrounds them.
--&gt;
&lt;!--
  &lt;role rolename=&quot;tomcat&quot;/&gt;
  &lt;role rolename=&quot;role1&quot;/&gt;
  &lt;user username=&quot;tomcat&quot; password=&quot;tomcat&quot; roles=&quot;tomcat&quot;/&gt;
  &lt;user username=&quot;both&quot; password=&quot;tomcat&quot; roles=&quot;tomcat,role1&quot;/&gt;
  &lt;user username=&quot;role1&quot; password=&quot;tomcat&quot; roles=&quot;role1&quot;/&gt;
--&gt;
  &lt;role rolename=&quot;manager&quot;/&gt;
  &lt;role rolename=&quot;manager-gui&quot;/&gt;
  &lt;role rolename=&quot;admin&quot;/&gt;
  &lt;user username=&quot;admin&quot; password=&quot;tomcat&quot; roles=&quot;admin,manager,manager-gui&quot;/&gt;
&lt;/tomcat-users&gt;
</pre></p>
<p>In lines 19-22 I added three roles with the names &#8220;manager&#8221;, &#8220;manager-gui&#8221; and &#8220;admin&#8221;. In line 22 I created a user with the username &#8220;admin&#8221;, the password &#8220;tomcat&#8221; and the roles I created before. This user will be used to access the Tomcat Manager Interface in the next step.</p>
<p>All there is left to do is to restart the Tomcat Server to make him recognize that the &#8220;tomcat-users.xml&#8221; file has changed and that there is a new user with the name &#8220;admin&#8221; and the password &#8220;tomcat&#8221;. This is how you restart your Tomcat Server: </p>
<p><pre class="brush: plain;">
/etc/init.d/tomcat restart
</pre></p>
<h1><strong>8. Test Tomcat Manager Interface</strong></h1>
<p>Finally we can check if everything went right. If your Tomcat Server runs on your local machine your can access it via the following adress:</p>
<p><em><strong>http://localhost:8080/</strong></em></p>
<p>otherwise you have to replace the &#8220;localhost&#8221; part with the IP adress or name of your server. This could look like this:</p>
<p><em><strong>http://192.168.6.15:8080/</strong></em></p>
<p>If all went right you should see the following site in your browser:</p>
<div id="attachment_223" class="wp-caption aligncenter" style="width: 490px"><a href="http://orkus.files.wordpress.com/2010/08/unbenannt-1.png"><img src="http://orkus.files.wordpress.com/2010/08/unbenannt-1.png?w=480&#038;h=305" alt="This is the Tomcat Startup Site" title="Tomcat Site" width="480" height="305" class="size-full wp-image-223" /></a><p class="wp-caption-text">Tomcat Site</p></div>
<p>Now you know that your Tomcat Server is running. Next we will log in to the Tomcat Manager Interface. For that you should click on the link that says &#8220;Tomcat Manager&#8221; in the upper left part of the webpage (This link is actually highlighted in the picture above.). Now you will be prompted for your username and password. Type in the username and the password you set in the &#8220;tomcat-users.xml&#8221; file (in this case that would be &#8220;admin&#8221; and &#8220;tomcat&#8221;)</p>
<div id="attachment_226" class="wp-caption aligncenter" style="width: 510px"><a href="http://orkus.files.wordpress.com/2010/08/prompt.png"><img src="http://orkus.files.wordpress.com/2010/08/prompt.png?w=500&#038;h=115" alt="Tomcat Manager Username and Password Prompt" title="Prompt" width="500" height="115" class="size-full wp-image-226" /></a><p class="wp-caption-text">Tomcat Manager Prompt</p></div>
<p>After that you should see the site of the Tomcat Manager.</p>
<div id="attachment_228" class="wp-caption aligncenter" style="width: 490px"><a href="http://orkus.files.wordpress.com/2010/08/tomcat_manager.png"><img src="http://orkus.files.wordpress.com/2010/08/tomcat_manager.png?w=480&#038;h=313" alt="The Tomcat Manager Interface" title="Tomcat Manager Interface" width="480" height="313" class="size-full wp-image-228" /></a><p class="wp-caption-text">Tomcat Manager Interface</p></div>
<p>Congratulations you just installed your very own Tomcat Server.</p>
<p>Let me know what you think about my article. Perhaps there are some sections where i need to be a little bit more elaborate. Just drop me a line&#8230;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=151&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2010/08/31/howto-install-tomcat-7-on-debian-lenny/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>

		<media:content url="http://orkus.files.wordpress.com/2010/08/unbenannt-1.png" medium="image">
			<media:title type="html">Tomcat Site</media:title>
		</media:content>

		<media:content url="http://orkus.files.wordpress.com/2010/08/prompt.png" medium="image">
			<media:title type="html">Prompt</media:title>
		</media:content>

		<media:content url="http://orkus.files.wordpress.com/2010/08/tomcat_manager.png" medium="image">
			<media:title type="html">Tomcat Manager Interface</media:title>
		</media:content>
	</item>
		<item>
		<title>Howto Install Sun&#8217;s Java 6 on Debain (Lenny)</title>
		<link>http://orkus.wordpress.com/2010/07/06/howto-install-suns-java-6-on-debain-lenny/</link>
		<comments>http://orkus.wordpress.com/2010/07/06/howto-install-suns-java-6-on-debain-lenny/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 11:49:03 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[sun]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=153</guid>
		<description><![CDATA[This article is a short Tutorial on how to install Java 6 on a Machine running Debian (Lenny) OS. I will try to keep the Installation process as simple as possible so let&#8217;s get started&#8230; Step 1: Add &#8220;non-free&#8221; parameter If you haven&#8217;t already done so, you have to add the &#8220;non-free&#8221; parameter to your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=153&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article is a short Tutorial on how to install Java 6 on a Machine running Debian (Lenny) OS. I will try to keep the Installation process as simple as possible so let&#8217;s get started&#8230;</p>
<h2><strong>Step 1: Add &#8220;non-free&#8221; parameter</strong></h2>
<p>
If you haven&#8217;t already done so, you have to add the &#8220;non-free&#8221; parameter to your apt &#8220;sources.list&#8221;. So open up your sources.list normallly located in /etc/apt/sources.list like so</p>
<p><pre class="brush: plain;">
nano /etc/apt/sources.list
</pre></p>
<p>&#8230;if you did not modify your &#8220;sources.list&#8221; up to now it might look something like this&#8230;</p>
<p><pre class="brush: plain;">
# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main
# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main

deb http://ftp.de.debian.org/debian/ lenny main
deb-src http://ftp.de.debian.org/debian/ lenny main

deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main
</pre></p>
<p>&#8230;now you have to add the &#8220;non-free&#8221; parameter to the end of  the deb and deb-src lines. After that your &#8220;sources.list&#8221; should look like:</p>
<p><pre class="brush: plain;">
# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main
# deb cdrom:[Debian GNU/Linux 5.0.4 _Lenny_ - Official i386 NETINST Binary-1 20100201-16:45]/ lenny main

deb http://ftp.de.debian.org/debian/ lenny main non-free
deb-src http://ftp.de.debian.org/debian/ lenny main  non-free

deb http://security.debian.org/ lenny/updates main non-free
deb-src http://security.debian.org/ lenny/updates main non-free
</pre></p>
<p>&#8230;save your modified &#8220;sources.list&#8221; file.</p>
<h2><strong>Step 2: Install Java</strong></h2>
<p>
Before you can install the sun-java packages you have to update your package repository&#8230;</p>
<p><pre class="brush: plain;">
apt-get update
</pre></p>
<p>now you can install the java packages&#8230;</p>
<p><pre class="brush: plain;">
apt-get install sun-java6-jdk sun-java6-jre libtcnative-1
</pre></p>
<h2><strong>Step 3: Set JAVA_HOME</strong></h2>
<p>
Before we do anything else we set the JAVA_HOME environment variable so that other application can find your java distribution. To to that you have to edit your &#8220;.bashrc&#8221; file located in your home directory. So open up your &#8220;.bashrc&#8221; file:</p>
<p><pre class="brush: plain;">
nano ~/.bashrc
</pre></p>
<p>&#8230;and add the following line to the end of your file</p>
<p><pre class="brush: plain;">
export JAVA_HOME=/usr/lib/jvm/java-6-sun
</pre></p>
<p>at this point I&#8217;m assuming that your distribution installed java in /usr/lib/jvm/java-6-sun which is the default behaviour. If that is not the case you have to replace the path with your installation path. Now you could try to log out and log in again to check if the JAVA_HOME is correctly set. After logging in again you just type&#8230;</p>
<p><pre class="brush: plain;">
echo $JAVA_HOME
</pre></p>
<p>if everything went right you should see the path that you set in your &#8220;.bashrc&#8221; earlier.</p>
<p><pre class="brush: plain;">
/usr/lib/jvm/java-6-sun
</pre></p>
<h2><strong>Step 4: Check your Java Installation</strong></h2>
<p></p>
<p>If everything went right the command </p>
<p><pre class="brush: plain;">
java -version
</pre></p>
<p>&#8230;should yield the following output:</p>
<p><pre class="brush: plain;">
java version &quot;1.6.0_20&quot;
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
</pre></p>
<p>&#8230; so that&#8217;s that&#8230;hope it helps&#8230;cya</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=153&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2010/07/06/howto-install-suns-java-6-on-debain-lenny/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>
	</item>
		<item>
		<title>Variable LIMIT statement in MySQL</title>
		<link>http://orkus.wordpress.com/2010/06/29/variable-limit-statement-in-mysql/</link>
		<comments>http://orkus.wordpress.com/2010/06/29/variable-limit-statement-in-mysql/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 21:37:23 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[between statement]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[prepared statement]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=67</guid>
		<description><![CDATA[Question: Is there a way to use variables in conjunction with the SQL LIMIT clause? (e.g. SELECT * FROM movies LIMIT @foo)? Answer: No not directly&#8230;at the time of writing this is still a big issue of MySQL Development. Nonetheless there exist various workarounds. I will discuss a few of them in this article. Description: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=67&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><strong>Question:</strong></h2>
<p>Is there a way to use variables in conjunction with the SQL <span style="color:darkmagenta;"><strong>LIMIT</strong></span> clause?<br />
(e.g. <span style="color:darkmagenta;"><strong>SELECT</strong></span> * <span style="color:darkmagenta;"><strong>FROM</strong></span> movies <span style="color:darkmagenta;"><strong>LIMIT</strong></span> @foo)?</p>
<h2><strong>Answer:</strong></h2>
<p>No not directly&#8230;at the time of writing this is still a big issue of MySQL Development. Nonetheless there exist various workarounds. I will discuss a few of them in this article.</p>
<h2><strong>Description:</strong></h2>
<p>The main issue is that you want to construct an SQL query that hands a variable as a parameter to the LIMIT clause. That could look something like this:</p>
<p><pre class="brush: sql;">
SET @foo = 5;
SELECT * FROM movies LIMIT @foo;</pre></p>
<p>This immediately results in the following error message.</p>
<p><strong>Error Code: 1064</strong><br />
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#8216;@&#8217; at line 1)</p>
<p>So to all appearances SELECT queries using the LIMIT clause do not work when a SQL variable (e.g. @foo) is used as a parameter in the LIMIT clause.</p>
<h2><strong>Solutions:</strong></h2>
<p>In the following I present a few workarounds to resolve this little handicap:</p>
<p><strong>1. Make use of Prepared Statements</strong></p>
<p><pre class="brush: sql;">
SET @foo=5;
PREPARE STMT FROM 'SELECT * FROM table LIMIT ?';
EXECUTE STMT USING @foo;</pre></p>
<p>You could also concatenate your entire SELECT Statement and convert this to a Prepared Statement. In the following example the parameter &#8220;sParameter&#8221; is the used variable.</p>
<p><pre class="brush: sql;">
SET @myQuery = CONCAT('SELECT * FROM test ORDER BY ', sParameter);
PREPARE stmt FROM @myQuery;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;</pre></p>
<p>If you use queries like these a lot, it might make sense to wrap the whole thing up in a stored procedure:</p>
<p><pre class="brush: sql;">
DELIMITER $$

CREATE PROCEDURE `get_movie_range`(
IN _FROM INTEGER,
IN _TO INTEGER
)
BEGIN
PREPARE STMT FROM &quot;SELECT * FROM movies LIMIT ?,? &quot;;
SET @FROM = _FROM;
SET @TO = _TO;
EXECUTE STMT USING @FROM, @TO; 
END$$
</pre></p>
<p>With the stored procedure in place you can make calls like:</p>
<p><pre class="brush: sql;">
CALL get_movie_range(7,(SELECT COUNT(*) FROM movies));</pre></p>
<p><strong>2. Make use of variables and the BETWEEN Statement</strong></p>
<p>This statement selects all rows beginning with 12 and ending at 20.<br />
<pre class="brush: sql;">
set @i=0;
select * from movies where (@i:=@i+1) between 12 and 20;</pre></p>
<p>So that&#8217;s it&#8230;hope it helps&#8230;:)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=67&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2010/06/29/variable-limit-statement-in-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>
	</item>
		<item>
		<title>SELECT TOP in MySQL</title>
		<link>http://orkus.wordpress.com/2010/06/29/select-top-in-mysql/</link>
		<comments>http://orkus.wordpress.com/2010/06/29/select-top-in-mysql/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 12:41:36 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[emulate]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[imitate]]></category>
		<category><![CDATA[mimic]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[select top]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=69</guid>
		<description><![CDATA[This article contains a brief discussion on how to emulate the behavior of the SELECT TOP statement in MySQL.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=69&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Question:</strong> Is there a way to emulate the behavior of <span style="color:darkmagenta;"><strong>SELECT TOP</strong></span> [Integer] &#8230; in MySQL?</p>
<p><strong>Answer:</strong> Yes there is&#8230;you have to make use of the <span style="color:darkmagenta;"><strong>LIMIT</strong></span> clause.</p>
<p><strong>Example:</strong></p>
<p>The query&#8230;</p>
<p><span style="color:darkmagenta;"><strong>SELECT TOP</strong></span> 5 * <span style="color:darkmagenta;"><strong>FROM</strong></span> movies;</p>
<p><strong>Output:</strong></p>
<table border="1">
<tr>
<th>titleID</th>
<th>title</th>
<th>url</th>
</tr>
<tr>
<td>0012349</td>
<td>The Kid</td>
<td>http://www.imdb.com/title/tt0012349/</td>
</tr>
<tr>
<td>0015864</td>
<td>The Gold Rush</td>
<td>http://www.imdb.com/title/tt0015864/</td>
</tr>
<tr>
<td>0017136</td>
<td>Metropolis</td>
<td>http://www.imdb.com/title/tt0017136/</td>
</tr>
<tr>
<td>0017925</td>
<td>The General</td>
<td>http://www.imdb.com/title/tt0017925/</td>
</tr>
<tr>
<td>0018455</td>
<td>Sunrise: A Song of Two Humans</td>
<td>http://www.imdb.com/title/tt0018455/</td>
</tr>
</table>
<p>&#8230;will look like this in MySQL&#8230;</p>
<p><span style="color:darkmagenta;"><strong>SELECT</strong></span> * <span style="color:darkmagenta;"><strong>FROM</strong></span> movies <span style="color:darkmagenta;"><strong>LIMIT</strong></span> 5;</p>
<p><strong>Output:</strong></p>
<table border="1">
<tr>
<th>titleID</th>
<th>title</th>
<th>url</th>
</tr>
<tr>
<td>0012349</td>
<td>The Kid</td>
<td>http://www.imdb.com/title/tt0012349/</td>
</tr>
<tr>
<td>0015864</td>
<td>The Gold Rush</td>
<td>http://www.imdb.com/title/tt0015864/</td>
</tr>
<tr>
<td>0017136</td>
<td>Metropolis</td>
<td>http://www.imdb.com/title/tt0017136/</td>
</tr>
<tr>
<td>0017925</td>
<td>The General</td>
<td>http://www.imdb.com/title/tt0017925/</td>
</tr>
<tr>
<td>0018455</td>
<td>Sunrise: A Song of Two Humans</td>
<td>http://www.imdb.com/title/tt0018455/</td>
</tr>
</table>
<p>You can find more information about selections with <span style="color:darkmagenta;"><strong>LIMIT</strong></span> <a title="MySQL 5.0 Reference Manual the SELECT Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/select.html" target="_blank">here.</a></p>
<p>Hope this helps&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=69&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2010/06/29/select-top-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding XML namespaces via Dom4j</title>
		<link>http://orkus.wordpress.com/2008/07/18/adding-xml-namespaces-via-dom4j/</link>
		<comments>http://orkus.wordpress.com/2008/07/18/adding-xml-namespaces-via-dom4j/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 17:14:03 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[Dom4j]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlns]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=5</guid>
		<description><![CDATA[Hello everyone, today&#8217;s article is about adding namespaces to your XML document using Java and Dom4j, so let&#8217;s get started&#8230; First of all we need an instance of the Dom4j factory, here is how we do it&#8230; &#8230;next we create an element which is going to serve as the root element as well as a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=5&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#000000;">Hello everyone,</span></p>
<p>today&#8217;s article is about adding namespaces to your XML document using Java and Dom4j, so let&#8217;s get started&#8230;</p>
<p>First of all we need an instance of the Dom4j factory, here is how we do it&#8230;</p>
<p><pre class="brush: java;">//Get an instance of the dom4j document factory
DocumentFactory factory = DocumentFactory.getInstance();</pre></p>
<p>&#8230;next we create an element which is going to serve as the root element as well as a new xml document using the factory object.</p>
<p><pre class="brush: java;">//use the factory to create a root element
Element rootElement = factory.createElement(&quot;RootElement&quot;);
//use the factory to create a new document with the previously created root element
Document doc = factory.createDocument(rootElement);</pre></p>
<p>Now we are ready to create our namespaces.</p>
<p><pre class="brush: java;">//create some dom4j namespaces that we like to add to our new document
Namespace namespace1 = new Namespace(&quot;xsd&quot;,&quot;http://www.w3.org/2001/XMLSchema#&quot;);
Namespace namespace2 = new Namespace(&quot;rdfs&quot;,&quot;http://www.w3.org/2000/01/rdf-schema#&quot;);
Namespace namespace3 = new Namespace(&quot;rdf&quot;,&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;);
Namespace namespace4 = new Namespace(&quot;owl&quot;,&quot;http://www.w3.org/2002/07/owl#&quot;);
Namespace namespace5 = new Namespace(&quot;some&quot;,&quot;http://some/other/namespace:-)#&quot;);</pre></p>
<p>The last step we have to take is to add all the namespaces to the XML document.</p>
<p><pre class="brush: java;">//add the created namespaces to the document&lt;/span&gt;
doc.getRootElement().add(namespace1);
doc.getRootElement().add(namespace2);
doc.getRootElement().add(namespace3);
doc.getRootElement().add(namespace4);
doc.getRootElement().add(namespace5);</pre></p>
<p>Finished! To check if everything worked as intended we&#8217;re going to write the document to an XML file&#8230;</p>
<p><pre class="brush: java;">try{
  //write the created document to an arbitrary file
  FileOutputStream fos = new FileOutputStream( &quot;files/output.xml&quot; );

  OutputFormat outformat = OutputFormat.createPrettyPrint();
  XMLWriter writer = new XMLWriter(fos, outformat);
  writer.write(doc);
  writer.flush();

}catch(FileNotFoundException e) {
  // catch exception
  e.printStackTrace();
}catch(UnsupportedEncodingException e) {
  // catch exception
  e.printStackTrace();
}catch (IOException e) {
  // catch exception
  e.printStackTrace();
}</pre></p>
<p>&#8230;if everything went fine we should end up with an XML file that looks like this:</p>
<p><pre class="brush: xml;">&lt;xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;&gt;

&lt;RootElement xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema#&quot;
xmlns:rdfs=&quot;http://www.w3.org/2000/01/rdf-schema#&quot;
xmlns:rdf=&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;
xmlns:owl=&quot;http://www.w3.org/2002/07/owl#&quot;
xmlns:some=&quot;http://some/other/namespace:-)#&quot;&gt;

&lt;/RootElement&gt;</pre></p>
<p>So this is how you add namespaces to your xml document via Dom4j&#8230;have a nice day and stay tuned for more face-melting articles <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8230;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/orkus.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/orkus.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=5&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2008/07/18/adding-xml-namespaces-via-dom4j/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>
	</item>
		<item>
		<title>XPath Expressions Dom4j vs XMLSpy</title>
		<link>http://orkus.wordpress.com/2008/07/07/xpath-expressions-dom4j-vs-xmlspy/</link>
		<comments>http://orkus.wordpress.com/2008/07/07/xpath-expressions-dom4j-vs-xmlspy/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 13:15:33 +0000</pubDate>
		<dc:creator>evermean</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Dom4j]]></category>
		<category><![CDATA[Expression]]></category>
		<category><![CDATA[Problem]]></category>
		<category><![CDATA[XMLSpy]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://orkus.wordpress.com/?p=3</guid>
		<description><![CDATA[Hello, this is my first real article so I hope I get things right&#8230; This article is about a &#8220;Problem&#8221; I recently encountered while using XPath expressions in Dom4j and XMLSpy. The main objective was to select certain nodes in an XML File. Just to give you a better understanding of what I wanted to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=3&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello,</p>
<p>this is my first real article so I hope I get things right&#8230;</p>
<p>This article is about a &#8220;Problem&#8221; I recently encountered while using XPath expressions in Dom4j and XMLSpy. The main objective was to select certain nodes in an XML File. Just to give you a better understanding of what I wanted to select, here the related snippet of the XML File:</p>
<p><pre class="brush: xml;">
   &lt;!-- Individual:http://www.co-ode.org/ontologies/pizza/pizza.owl#Germany --&gt;
   &lt;owl:Thing rdf:about=&quot;#Germany&quot;&gt;
       &lt;rdf:type rdf:resource=&quot;#Country&quot;/&gt;
   &lt;/owl:Thing&gt;

   &lt;!-- Individual: http://www.co-ode.org/ontologies/pizza/pizza.owl#Italy --&gt;
   &lt;owl:Thing rdf:about=&quot;#Italy&quot;&gt;
      &lt;rdf:type rdf:resource=&quot;#Country&quot;/&gt;
   &lt;/owl:Thing&gt;

   &lt;owl:Thing rdf:about=&quot;#AmeriCunt&quot;&gt;
       &lt;rdf:type rdf:resource=&quot;#American&quot;/&gt;
   &lt;/owl:Thing&gt;

   &lt;American rdf:ID=&quot;Lappland&quot;/&gt;

   &lt;AmericanHot rdf:ID=&quot;Toska&quot;&gt;&lt;/AmericanHot&gt;

   &lt;AnchoviesTopping rdf:ID=&quot;Lappland&quot;/&gt;;

   &lt;ArtichokeTopping rdf:ID=&quot;Lappland&quot;/&gt;&lt;/span&gt;

   &lt;AsparagusTopping rdf:ID=&quot;Lappland&quot;/&gt;</pre></pre>
<p>I wanted to select the elements in the lines 17 - 25 via XPath expressions. So I tried to select the first Element with the expression "//American". In XMLSpy and everything worked just fine. Therefore I took my java code and tried to run the same XPath expression with Dom4j (see code below):</p>
<p><pre class="brush: java;">
Document doc = null;
try {
      doc = new SAXReader(  ).read(
              new FileInputStream(&quot;files/pizza.owl&quot;));

      XPath xpathSelector =
      DocumentHelper.createXPath(&quot;//American&quot;);

      List&lt;Element&gt; elements = xpathSelector.selectNodes(doc);
      for(Element e: elements){
          System.out.println(&quot;Found&quot;);
      }

} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (DocumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}</pre></p>
<p>That didn't work so well and I ended up with an empty result set. After hours I finally came up with a solution to this problem (even though I am not quite sure that the explanation why the problem occurred with Dom4j and not with XMLSpy is accurate or not.....so it's just a guess ).</p>
<p>I figured out that the elements I tried to select don't belong to any namespace (in fact they do, they belong to the standard namespace of the XML file, if defined). The elements which I wanted to select existed one level below the actual root element of the XML file.</p>
<p>My guess is that XMLSpy figures out the namespaces of given document on its own and therefore can select elements based on an expression like "//American". Dom4j on the other hand doesn't figure out namespaces on its own an therefore is incapable of correctly evaluating the expression. That is why I ended up with an empty result set on my first try.</p>
<p>What I did is I took the namespace (line 1 in the XML file below) which all elements belong to if they have no prefix assigned to them and made it known to Dom4j:</p>
<p><pre class="brush: xml;">
&lt;rdf:RDF xmlns=&quot;http://www.co-ode.org/ontologies/pizza/pizza.owl#&quot;
     xml:base=&quot;http://www.co-ode.org/ontologies/pizza/pizza.owl&quot;
     xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema#&quot;
     xmlns:rdfs=&quot;http://www.w3.org/2000/01/rdf-schema#&quot;
     xmlns:rdf=&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;
     xmlns:owl=&quot;http://www.w3.org/2002/07/owl#&quot;&gt;</pre></p>
<p>Java Code (the relevant changes are lokated in lines 4,5 and 8):</p>
<p><pre class="brush: java;">
           try {
               doc = new SAXReader(  ).read(new FileInputStream(&quot;files/pizza.owl&quot;));

               Map map = new HashMap();
               map.put(&quot;standard&quot;, &quot;http://www.co-ode.org/ontologies/pizza/pizza.owl#&quot;);

               XPath xpathSelector  = DocumentHelper.createXPath(&quot;//standard:American&quot;);
               xpathSelector.setNamespaceContext(new SimpleNamespaceContext(map));

                List&lt;Element&gt; elements = xpathSelector.selectNodes(doc);
                for(Element e: elements){
                    System.out.println(&quot;Found&quot;);
                }

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (DocumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
</pre><br />
Now everything was working fine and I got my desired elements...</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/orkus.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/orkus.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/orkus.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/orkus.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/orkus.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/orkus.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/orkus.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/orkus.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/orkus.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/orkus.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=orkus.wordpress.com&amp;blog=1553644&amp;post=3&amp;subd=orkus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://orkus.wordpress.com/2008/07/07/xpath-expressions-dom4j-vs-xmlspy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28600c109b25da6693f6999c7e5166c3?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">evermean</media:title>
		</media:content>
	</item>
	</channel>
</rss>
