<?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>ADM Blog &#187; Java</title> <atom:link href="http://blog.another-d-mention.ro/category/programming/java/feed/" rel="self" type="application/rss+xml" /><link>http://blog.another-d-mention.ro</link> <description>No matter how you see things, reality changes when you reach understanding</description> <lastBuildDate>Fri, 22 Jul 2011 06:56:49 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1</generator> <item><title>Static files locked by Jetty in Eclipse</title><link>http://blog.another-d-mention.ro/programming/java/static-files-locked-by-jetty-in-eclipse/</link> <comments>http://blog.another-d-mention.ro/programming/java/static-files-locked-by-jetty-in-eclipse/#comments</comments> <pubDate>Mon, 25 Jan 2010 12:26:11 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[eclipse]]></category> <category><![CDATA[files]]></category> <category><![CDATA[jetty]]></category> <category><![CDATA[locked]]></category> <category><![CDATA[static]]></category> <category><![CDATA[windows]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=795</guid> <description><![CDATA[If you use Jetty you might notice that once it's running you can't edit any static files because it says they are already in use and locked. Why ? Because Jetty buffers static content for webapps such as html files, css files, images etc and uses memory mapped files to do this if the NIO [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/misc/view-hidden-files-with-a-keyboard-shortcut/' rel='bookmark' title='Permanent Link: View hidden files with a keyboard shortcut'>View hidden files with a keyboard shortcut</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/' rel='bookmark' title='Permanent Link: How to run python code in Windows batch (bat) files'>How to run python code in Windows batch (bat) files</a></li></ol>]]></description> <content:encoded><![CDATA[<p><img
class="alignleft size-full wp-image-798" title="jetty_logo" src="http://cache.another-d-mention.ro/images/wp-content/uploads/2010/01/jetty_logo2.png" alt="jetty logo2 Static files locked by Jetty in Eclipse" hspace="10" vspace="10" width="142" height="40" /> If you use Jetty you might notice that once it's running you can't edit any static files because it says they are already in use and locked.<br
/> Why ? Because Jetty buffers static content for webapps such as html files, css files, images etc and uses memory mapped files to do this if the NIO connectors are being used. The problem is that on Windows, memory mapping a file causes the file to be locked, so that the file cannot be updated or replaced. This means that effectively you have to stop Jetty in order to update a file.</p><p><strong>In case this happens follow these steps:</strong></p><p>1. Extract the runjettyrun_1.0.1.jar in the eclipse plugin directory<br
/> 2. Extract the jetty-6.1.6.jar in the lib directory of the previous jar.<br
/> 3. Edit the file org\mortbay\jetty\webapp\webdefault.xml and change the "useFileMappedBuffer" to false. It should look like the following:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init</span> -param<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> -name<span style="color: #000000; font-weight: bold;">&gt;</span></span>useFileMappedBuffer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/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</span> -value<span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div><p>4. Pack everything back up and overwrite the runjettyrun jar in the plugin directory.<br
/> 5. If you still get the error after step 4 start eclipse.exe with -clean and then recreate the Jetty configuration. (It just need to replace whatever jar's it copies in your workspace .plugins dir)</p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/misc/view-hidden-files-with-a-keyboard-shortcut/' rel='bookmark' title='Permanent Link: View hidden files with a keyboard shortcut'>View hidden files with a keyboard shortcut</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/' rel='bookmark' title='Permanent Link: How to run python code in Windows batch (bat) files'>How to run python code in Windows batch (bat) files</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java/static-files-locked-by-jetty-in-eclipse/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>The simplest way to parse XML in Java</title><link>http://blog.another-d-mention.ro/programming/the-simplest-way-to-parse-xml-in-java/</link> <comments>http://blog.another-d-mention.ro/programming/the-simplest-way-to-parse-xml-in-java/#comments</comments> <pubDate>Thu, 24 Sep 2009 10:54:06 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[class]]></category> <category><![CDATA[parser]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=569</guid> <description><![CDATA[You can do a lot with XML, but often all you want to do is to read a simple file with some basic data in it. The options for doing this, SAX, DOM and JAXB are all relatively verbose and often off-putting. So here is a class that will make all this much much more [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/misc/eee-pc/reset-system-password-for-eeepc/' rel='bookmark' title='Permanent Link: Reset system password for EeePC'>Reset system password for EeePC</a></li><li><a
href='http://blog.another-d-mention.ro/misc/alfresco-cifs-shared-drive-authentication-problem/' rel='bookmark' title='Permanent Link: Alfresco CIFS shared drive authentication problem'>Alfresco CIFS shared drive authentication problem</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol>]]></description> <content:encoded><![CDATA[<p>You can do a lot with XML, but often all you want to do is to read a simple file with some basic data in it. The options for doing this, SAX, DOM and JAXB are all relatively verbose and often off-putting. So here is a class that will make all this much much more simple.</p><p>Parsing a file such as:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version</span> <span style="color: #000066;">major</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">minor</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;roles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;admin&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/roles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;users<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;joe&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;pass&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;admin&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;harry&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;secret&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/users<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div><p>Can be achieved with the following code:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td
class="code"><pre class="java" style="font-family:monospace;">Xml config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Xml<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;config.xml&quot;</span>,<span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title: &quot;</span><span style="color: #339933;">+</span>config.<span style="color: #006633;">child</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">content</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;
Xml version <span style="color: #339933;">=</span> config.<span style="color: #006633;">child</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;version&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;version: &quot;</span><span style="color: #339933;">+</span>version.<span style="color: #006633;">integer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;major&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">+</span>version.<span style="color: #006633;">integer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;minor&quot;</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;">for</span><span style="color: #009900;">&#40;</span>Xml role<span style="color: #339933;">:</span>config.<span style="color: #006633;">child</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;roles&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">children</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;role&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;role: name: &quot;</span><span style="color: #339933;">+</span>role.<span style="color: #006633;">string</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</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;">for</span><span style="color: #009900;">&#40;</span>Xml user<span style="color: #339933;">:</span>config.<span style="color: #006633;">child</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;users&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">children</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;user: name: &quot;</span><span style="color: #339933;">+</span>user.<span style="color: #006633;">string</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>
		<span style="color: #0000ff;">&quot;, password: &quot;</span><span style="color: #339933;">+</span>user.<span style="color: #006633;">string</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>
		<span style="color: #0000ff;">&quot;, role: &quot;</span><span style="color: #339933;">+</span>user.<span style="color: #006633;">string</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;role&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>As you can see, it's nice and simple and allows you to get to the information quickly and without any hassle. The API uses the DOM parser underneath, but attempts to make the data more easily available. All you need is the following [<a
href="http://cache.another-d-mention.ro/stuff/Xml.java">Click to download</a>] class, which you can of course customise however you like.</p><p><strong>Update</strong>:<br
/> I've just added another nice method to this class. Is called e4xEval, that is actualy a xpath eval but i made it use the flex e4x syntax. So, if you want to get all the role name you can do:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="java" style="font-family:monospace;">&nbsp;
Xml config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Xml<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;config.xml&quot;</span>,<span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> list <span style="color: #339933;">=</span> config.<span style="color: #006633;">e4xEval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;config.roles.role.@name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// @ is attribute</span></pre></td></tr></table></div><p></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/misc/eee-pc/reset-system-password-for-eeepc/' rel='bookmark' title='Permanent Link: Reset system password for EeePC'>Reset system password for EeePC</a></li><li><a
href='http://blog.another-d-mention.ro/misc/alfresco-cifs-shared-drive-authentication-problem/' rel='bookmark' title='Permanent Link: Alfresco CIFS shared drive authentication problem'>Alfresco CIFS shared drive authentication problem</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/the-simplest-way-to-parse-xml-in-java/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
