<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;AkcASHkzfSp7ImA9WhRUEEk.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395</id><updated>2012-01-20T09:27:29.785+01:00</updated><category term="Internet" /><category term=".NET and VS2005" /><category term="SQL" /><category term="Java" /><category term="Javascript" /><category term="Ant" /><category term="Linux" /><category term="Eclipse" /><category term="ZK" /><title>XMedekO's blog</title><subtitle type="html">Blog of Ondrej Medek, alias Ondra, aka XMedekO, or MeDon.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://xmedeko.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>33</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/XmedekosBlog" /><feedburner:info uri="xmedekosblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;AkcASHkyeip7ImA9WhRUEEk.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-1610455629090755962</id><published>2012-01-20T09:27:00.000+01:00</published><updated>2012-01-20T09:27:29.792+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-20T09:27:29.792+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse" /><title>Eclipse: Manual and Automatic Code Formatting</title><content type="html">I like automatic code formatting in the &lt;a href="http://www.eclipse.org/"&gt;Eclipse IDE&lt;/a&gt;. For Java see the settings in &lt;code&gt;Window -&amp;gt; Preferences -&amp;gt; Java -&amp;gt; Code Style -&amp;gt; Formatter&lt;/code&gt;. I Just hit &lt;code&gt;CTRL+SHIFT+F&lt;/code&gt; time from time and let the IDE do the boring job for me. &lt;br /&gt;
&lt;br /&gt;
Occasionally, I want the different result then the Eclipse Formatter produce. Especially when a method has many parameters. Sometimes I like to have all of them on one line, sometimes I like to break them into multiple times. Of course, the Eclipse  automatic formatter cannot be configured to meet wishes.&lt;br /&gt;
&lt;br /&gt;
The Eclipse formatter has a nice option &lt;code&gt;On/Off Tags&lt;/code&gt;:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;@formatter:off&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@formatter:on&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;But it's tedious and ugly to write these tags into the code. (Even Code templates does not simply usage of On/Off Tags very much). Much more simpler solution is to append the Java comment &lt;code&gt;//&lt;/code&gt; ant the and of line, which you want to break. For example, I have configured the Eclipse formatter to have all method parameters on a single line. But when I write&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;this.someMethod(param1, //
    param2, //
    param3, //
    param4, //
    param5);
&lt;/pre&gt;Then the &lt;code&gt;CTRL+SHIFT+F&lt;/code&gt; reformatting let this piece of the code as is.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-1610455629090755962?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/WEIL5FRQzug" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/1610455629090755962/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=1610455629090755962" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/1610455629090755962?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/1610455629090755962?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/WEIL5FRQzug/eclipse-manual-and-automatic-code.html" title="Eclipse: Manual and Automatic Code Formatting" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2012/01/eclipse-manual-and-automatic-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEGQH8-fCp7ImA9WhdUGU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-4506653009750963519</id><published>2011-10-06T14:24:00.002+02:00</published><updated>2011-10-06T14:37:01.154+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-06T14:37:01.154+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Javascript" /><title>Simple Javascript SCORM 2004 API</title><content type="html">Just a very very simple implementation of SCORM 2004 API for LMS (RTS) developers. It implements just basic SCORM 2004 features. Hope, someone else may find it useful, see &lt;a href="http://sites.google.com/site/xmedeko/code/misc/simple-javascript-scorm-2004-api"&gt;http://sites.google.com/site/xmedeko/code/misc/simple-javascript-scorm-2004-api&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-4506653009750963519?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/sadqDo-VVBw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/4506653009750963519/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=4506653009750963519" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4506653009750963519?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4506653009750963519?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/sadqDo-VVBw/simple-javascript-scorm-2004-api.html" title="Simple Javascript SCORM 2004 API" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2011/10/simple-javascript-scorm-2004-api.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04DRHg5fCp7ImA9WhZVGEk.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-7056534406367848175</id><published>2011-05-31T09:51:00.001+02:00</published><updated>2011-05-31T13:39:35.624+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-31T13:39:35.624+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Java zsync</title><content type="html">The very first implementation of &lt;a href="http://zsync.moria.org.uk/"&gt;zsync&lt;/a&gt; in Java: &lt;a href="http://sourceforge.net/projects/jazsync/"&gt;http://sourceforge.net/projects/jazsync/&lt;/a&gt;. It has no release yet, check out the source code from SVN.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-7056534406367848175?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/OGj7mpCakfU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/7056534406367848175/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=7056534406367848175" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/7056534406367848175?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/7056534406367848175?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/OGj7mpCakfU/java-zsync.html" title="Java zsync" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2011/05/java-zsync.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYNQ3o_cSp7ImA9WhZWEU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-4877160163397004413</id><published>2011-05-11T10:56:00.000+02:00</published><updated>2011-05-11T10:56:32.449+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-11T10:56:32.449+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK-DL Released!</title><content type="html">&lt;a href="http://zk.datalite.cz/zk-dl"&gt;ZK-DL&lt;/a&gt;, an extension to the &lt;a href="http://www.zkoss.org/"&gt;ZKoss framework&lt;/a&gt; (ZK 5), has been released under LGPL just a few weeks ago!. ZK_DL provides especially:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Integration with Spring.&lt;/li&gt;
&lt;li&gt;Flexible listbox, combobox and lovbox (a kind of combobox) components with automatic sorting and searching build upon the Hibernate Criteria API.&lt;/li&gt;
&lt;li&gt;And much more, see &lt;a href="http://zk.datalite.cz/zk-dl"&gt;http://zk.datalite.cz/zk-dl&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
The documentation is at &lt;a href="http://zk.datalite.cz/zk-dl"&gt;http://zk.datalite.cz/zk-dl&lt;/a&gt; and the source code can be found at &lt;a href="http://code.google.com/p/zk-dl/"&gt;http://code.google.com/p/zk-dl/&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;I have used DL-ZK with EJB3 on JBoss 5.1 successfully.&lt;/b&gt; So I had not taken the advantage of ZK-DL Spring integration (IMHO better than original ZK Spring integration). Anyway the ZK-DL listobox, combobox and lovbox components has greatly simplified our development and provided a rich yet simple interface to our users. &lt;br /&gt;
&lt;br /&gt;
Many thanks to Jiří Bubník and Karel Čemus for their valuable help and cooperation. I wish DL-ZK long life and have many users!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-4877160163397004413?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/F70BB8qAU_k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/4877160163397004413/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=4877160163397004413" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4877160163397004413?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4877160163397004413?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/F70BB8qAU_k/zk-dl-released.html" title="ZK-DL Released!" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2011/05/zk-dl-released.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEMRX46eyp7ImA9WhdQFU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-6342751996174989330</id><published>2011-03-10T16:38:00.010+01:00</published><updated>2011-08-16T16:24:44.013+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-16T16:24:44.013+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>JPA Queries - A Few Methods to Simplify the Life with JPA/JPQL</title><content type="html">The JPA &lt;a href="http://download.oracle.com/javaee/6/api/javax/persistence/Query.html#getSingleResult%28%29"&gt;&lt;code&gt;Query.getSingleResult()&lt;/code&gt;&lt;/a&gt; method is usable only when the JPQL has exactly one result. Yeah, you can catch &lt;code&gt;NoResultException&lt;/code&gt; or &lt;code&gt;NonUniqueResultException&lt;/code&gt; exceptions, but the try ... catch block make the code less readable. So I have coded three static method to overcome this JPA deficiency:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class Queries {
    /**
     * @param query
     * @return {@code true}, the query has one or more results, otherwise returns {@code false}.
     */
    public static boolean hasAnyResult(Query query) {
        query.setMaxResults(1);
        final List&amp;lt;?&amp;gt; list = query.getResultList();
        return list.size() &amp;gt; 0;
    }

    /**
     * @param query
     * @return The only one result or {@code null}, when the query has no result.
     * @throws NonUniqueResultException
     *             when the query has more than one result.
     */
    public static Object singleResultOrNull(Query query) {
        query.setMaxResults(2);
        final List&amp;lt;?&amp;gt; list = query.getResultList();
        final int size = list.size();
        if (size &amp;lt;= 0) {
            return null;
        }
        if (size &amp;gt; 1) {
            throw new NonUniqueResultException(&amp;quot;result returns more than one element&amp;quot;);
        }

        // return first element from the list
        return list.get(0);
    }

    /**
     * @param query
     * @return The first result or {@code null}, when the query has no result.
     */
    public static Object firstResultOrNull(Query query) {
        query.setMaxResults(1);
        final List&amp;lt;?&amp;gt; list = query.getResultList();
        final int size = list.size();
        if (size &amp;lt;= 0) {
            return null;
        }
        if (size &amp;gt; 1) { // should not happened, Hibernate bug?
            Logger.getLogger(Queries.class).error(&amp;quot;firstResultOrNull more rows returned. setMaxResults(1) does not work?&amp;quot;);
        }

        return list.get(0);
    }

    /**
     * Constructor. No instances.
     */
    private Queries() {
    }
}
&lt;/pre&gt;The &lt;b&gt;&lt;code&gt;hasAnyResult&lt;/code&gt;&lt;/b&gt; is the &lt;i&gt;boolean&lt;/i&gt; query method - you may test if something exists in database. The best is to use it with some JPQL query returning only id of an entity, e.g.:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;Queries.hasAnyResult(em.createQuery(&amp;quot;SELECT id FROM Person WHERE ...&amp;quot;));&lt;/pre&gt;I think the usage of the &lt;b&gt;&lt;code&gt;singleResultOrNull&lt;/code&gt;&lt;/b&gt; is obvious. Use it, when you are sure the result returns one or no result. The exception &lt;code&gt;NonUniqueResultException&lt;/code&gt; should warn you that something is wrong, wither the query or the data.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;&lt;code&gt;firstResultOrNull&lt;/code&gt;&lt;/b&gt; returns just the first result of the query. Typically, use it with queries with "ORDER BY" statement, like "get the Person with lowest/highest salary."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-6342751996174989330?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/txCdKsxoKpk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/6342751996174989330/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=6342751996174989330" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/6342751996174989330?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/6342751996174989330?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/txCdKsxoKpk/jpa-queries-few-methods-to-simplify.html" title="JPA Queries - A Few Methods to Simplify the Life with JPA/JPQL" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2011/03/jpa-queries-few-methods-to-simplify.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08FR3o5fyp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-1166732407029538805</id><published>2011-02-15T15:17:00.003+01:00</published><updated>2011-05-20T13:43:36.427+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:43:36.427+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Oracle Like Decode in JasperReports</title><content type="html">Oracle SQL has a nice function &lt;a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions040.htm"&gt;DECODE&lt;/a&gt;. I am using Java Beans data source for &lt;a href="http://jasperforge.org/projects/jasperreports"&gt;JasperReports&lt;/a&gt; and sometimes I have missed such a function in JasperReports expressions. One can achieve the same functionality by a &lt;a href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/operators.html"&gt;ternary operator &lt;code&gt;? :&lt;code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/a&gt;. But it is not nice for more complicated conditions. So I have created my own Java decode:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public static Object decode(Object value, Object... arg) {
  if (arg == null) {
    return value;
  }
  int n = arg.length;
  for (int i = 0; i &amp;lt; n; i+=2) {
    int j = i + 1;
    if (j &amp;gt;= n) {
      // only the default remains
      return arg[i];
    }
    if (equal(value, arg[i])) {
      return arg[j];
    }
  }
  // no match found, no default is specified
  return value;
}
&lt;/pre&gt;Then import it into JasperReports &lt;code&gt;*.jrxml&lt;/code&gt; report by:&lt;br /&gt;
&lt;pre class="prettyprint lang-xml"&gt;&amp;lt;import value="static com.mypackage.MyClass.decode"/&amp;gt;
&lt;/pre&gt;And use it in the report like:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;"" + decode(count, 0, "no one", 1, "one", 2, "two", "too many: " + count);
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-1166732407029538805?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/fH0RqVwDJtc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/1166732407029538805/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=1166732407029538805" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/1166732407029538805?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/1166732407029538805?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/fH0RqVwDJtc/oracle-like-decode-in-jasperreports.html" title="Oracle Like Decode in JasperReports" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2011/02/oracle-like-decode-in-jasperreports.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUEMQX45eCp7ImA9Wx9WGUU.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-4728352107375014100</id><published>2011-01-25T20:28:00.000+01:00</published><updated>2011-01-25T20:28:00.020+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-25T20:28:00.020+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK and Converting to a Negative Number</title><content type="html">When I was working with &lt;a href="http://www.zkoss.org/"&gt;ZK Web Framework&lt;/a&gt;, I have needed to convert some number to the negatives for the databinding. I have created a new type converter &lt;b&gt;&lt;code&gt;NumberNegativeConverter&lt;/code&gt;&lt;/b&gt;. Hope, someone else may find it useful, see &lt;a href="http://sites.google.com/site/xmedeko/code/zk-web-framework/numbernegativeconverter"&gt;http://sites.google.com/site/xmedeko/code/zk-web-framework/numbernegativeconverter&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-4728352107375014100?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/VxaeoaYmvWk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/4728352107375014100/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=4728352107375014100" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4728352107375014100?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4728352107375014100?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/VxaeoaYmvWk/zk-and-converting-to-negative-number.html" title="ZK and Converting to a Negative Number" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2011/01/zk-and-converting-to-negative-number.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08DQng8eyp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-4321369758907234459</id><published>2010-12-03T15:29:00.005+01:00</published><updated>2011-05-20T13:44:33.673+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:44:33.673+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Java: A Simple Assert Class for Design By Contract Checks</title><content type="html">Very often, the programmer are lazy to include design by contract checks into the code. That means argument checking in the beginning of the method, checking of a wrong state in the method body, etc. The Java &lt;a href="http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html"&gt;assert&lt;/a&gt; construct cannot be used for this purpose, since it is switched off by default (one has tu run &lt;code&gt;java -ea&lt;/code&gt; to switch on the Java asserts). To simplify the design by contract checks, I have made three simple static methods:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;/**
 * A static class for simple run-time checks. The methods from this class may (and should) be used to check arguments
 * and code for design-by-contract.
 * &amp;lt;p&amp;gt;
 * These are the methods for lazy programmers. If you like to write more complicated messages (and God bless you for
 * that), use the classic {@code if (...) throw ... } way.
 * &amp;lt;p&amp;gt;
 * It is not possible to switch off these checks, do not use them for any memory or CPU consuming operations.
 * 
 * @author xmedeko
 * 
 */
public class Assert {

 /**
  * Check, that the condition is {@code true}.
  * &amp;lt;p&amp;gt;
  * Usage:
  * 
  * &amp;lt;pre&amp;gt;
  * Assert.state(i &amp;amp;lt;= maxIter, &amp;amp;quot;iteration number exceeded&amp;amp;quot;);
  * &amp;lt;/pre&amp;gt;
  * 
  * @param check
  * @param message
  *            An error message.
  */
 public static void state(boolean check, String message) {
  if (check)
   return;
  throw new IllegalStateException(message);
 }

 /**
  * Check, that the object is not null. 
  * &amp;lt;p&amp;gt;
  * Usage:
  * 
  * &amp;lt;pre&amp;gt;
  * Assert.notNull(entity, &amp;amp;quot;entity&amp;amp;quot;);
  * &amp;lt;/pre&amp;gt;
  * 
  * 
  * @param o
  * @param message
  *            An error message.
  */
 public static void notNull(Object o, String message) {
  if (o != null)
   return;
  throw new NullPointerException(message);
 }

 /**
  * Check, that the argument fullfills the given condition.
  * &amp;lt;p&amp;gt;
  * Usage:
  * 
  * &amp;lt;pre&amp;gt;
  * Assert.argument(from &amp;amp;gt; 0, &amp;amp;quot;from has to be greater then zero&amp;amp;quot;);
  * &amp;lt;/pre&amp;gt;
  * 
  * @param check
  * @param message
  *            An error message.
  */
 public static void argument(boolean check, String message) {
  if (check)
   return;
  throw new IllegalArgumentException(message);
 }

 /** No instances. */
 private Assert() {
  throw new UnsupportedOperationException();
 }

}
&lt;/pre&gt;&lt;br /&gt;
Note, to check argument for not &lt;code&gt;null&lt;/code&gt; value, do not use &lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;Assert.argument(obj != null, "obj is null");
&lt;/pre&gt;but use instead:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;Assert.argument(obj != null, "obj");
&lt;/pre&gt;&lt;br /&gt;
Also, do not put any String concatenation or other operation into the &lt;code&gt;argument&lt;/code&gt;. These are the methods for lazy programmers. If you like to write more complicated messages (and God bless you for that), use the classic &lt;code&gt;if (...) throw ...&lt;/code&gt; way.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update 29.3.2011:&lt;/b&gt; I have just found out that Spring frameworks has &lt;a href="http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/util/Assert.html"&gt;org.springframework.util.Assert&lt;/a&gt; class, too.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-4321369758907234459?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/w27gNY-opec" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/4321369758907234459/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=4321369758907234459" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4321369758907234459?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4321369758907234459?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/w27gNY-opec/java-simple-assert-class-for-design-by.html" title="Java: A Simple Assert Class for Design By Contract Checks" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/12/java-simple-assert-class-for-design-by.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08NSH05cSp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-91841026369532651</id><published>2010-12-02T15:05:00.003+01:00</published><updated>2011-05-20T13:44:59.329+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:44:59.329+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK Calendar Colors</title><content type="html">Unfortunately, colours for the &lt;a href="http://code.google.com/p/zkcalendar/"&gt;ZK Calendar&lt;/a&gt; has to be specified in the Java. They cannot be set in a CSS file. Because writing hexadecimal colour codes directly in the code is error prone, I have created a simple enum constant with a set of ZK Calendar colors:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public enum ZkCalendarsColor  {
 GREY("#B4BAB7", "#72706F"),
 GREEN("#4CB052", "#0D7813"),
 KHAKI("#BFBF4D", "#88880E"),
 PURPLE("#B373B3", "#7A367A"),
 RED("#D96666", "#A32929"),
 BLUE("#668CD9", "#3467CE");
 
 private String contentColor;
 private String headerColor;
 
 private ZkCalendarsColor(String contentColor, String headerColor) {
  this.contentColor = contentColor;
  this.headerColor = headerColor;
 }

 public String getContentColor() {
  return contentColor;
 }

 public String getHeaderColor() {
  return headerColor;
 }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-91841026369532651?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/xQ_N3JHC310" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/91841026369532651/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=91841026369532651" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/91841026369532651?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/91841026369532651?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/xQ_N3JHC310/zk-calendar-colors.html" title="ZK Calendar Colors" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/12/zk-calendar-colors.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYBQngycCp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-5076309392433218943</id><published>2010-10-14T10:24:00.004+02:00</published><updated>2011-05-20T13:49:13.698+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:49:13.698+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Linux" /><title>Fixing Line Terminators for Cygwin CVS</title><content type="html">I have to use a Windows operating system (unfortunately :-)) and CVS in my current job. Thanks to the &lt;a href="http://www.cygwin.com/"&gt;Cygwin&lt;/a&gt;, I can work with Windows almost as effectively as in Linux. The CVS (CVSNT) installation in Windows and other CVS tools installed in on my Windows box (TortoiseCVS, Eclipse) stores the CVS files with CRLF line terminators (EOLs). The Cygwin CVS client requires the classic UNIX LT terminator. Fortunatelly, the Windows CVS clients can read the UNIX-way text files, too. So, I have creates a simple bash script to forx this problem:&lt;br /&gt;
&lt;pre class="prettyprint lang-sh"&gt;#!/bin/sh
find . -type f -path '*/CVS/*' -print0 | xargs -0 dos2unix 
&lt;/pre&gt;Hope, someone may find it useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-5076309392433218943?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/BEsP2nwYH6U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/5076309392433218943/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=5076309392433218943" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5076309392433218943?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5076309392433218943?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/BEsP2nwYH6U/cygwin-and-cvs.html" title="Fixing Line Terminators for Cygwin CVS" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/10/cygwin-and-cvs.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8FRns7fSp7ImA9Wx5QFU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-3667913374368191251</id><published>2010-08-31T11:22:00.001+02:00</published><updated>2010-09-03T10:50:17.505+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-03T10:50:17.505+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>JasperReports PDF Font Mapping</title><content type="html">Are your font &lt;b&gt;bold&lt;/b&gt; and &lt;i&gt;italic&lt;/i&gt; font properties lost when you export your JasperReports report into the PDF? Do you wander, why PDF preview in the iReport has all fonts right? Check this link out, mate: &lt;a href="http://sites.google.com/site/xmedeko/code/misc/jasperreports-pdf-font-mapping"&gt;http://sites.google.com/site/xmedeko/code/misc/jasperreports-pdf-font-mapping&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-3667913374368191251?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/xHqjXVMH8V4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/3667913374368191251/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=3667913374368191251" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3667913374368191251?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3667913374368191251?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/xHqjXVMH8V4/jasperreports-pdf-font-mapping.html" title="JasperReports PDF Font Mapping" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/08/jasperreports-pdf-font-mapping.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8HSXk7cSp7ImA9Wx5QFU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-302070515207552357</id><published>2010-08-05T08:13:00.004+02:00</published><updated>2010-09-03T10:50:38.709+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-03T10:50:38.709+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>JBoss and HSQLDB 2.0.0</title><content type="html">&lt;a href="http://hsqldb.org/"&gt;HSQLBD 2.0 GA&lt;/a&gt; has been released on 7 June 2010 with &lt;a href="http://hsqldb.org/web/features200.html"&gt;a lot of new cool features&lt;/a&gt;. I have needed some of them for my JBoss 5.1.0GA, so I have just replaced the library &lt;code&gt;common/lib/hsqldb.jar&lt;/code&gt; and voilà, it runs almost without any problem (Hibernate/JPA usage) as before. I have made just one small change, see bellow. Even the HSQLDB Database Manager starts from JMX console. My personal feeling is that the version 2.0 is a little bit faster than 1.8.0, but I have not made any benchmarks.&lt;br /&gt;
&lt;br /&gt;
The HSQLDB 2.0 upgrade notes:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;In my &lt;code&gt;import.sql&lt;/code&gt; I had to change all timestamp formats from &lt;code&gt;'2010-08-06 8:00:00'&lt;/code&gt; to &lt;code&gt;'2010-08-06 08:00:00'&lt;/code&gt;, i.e. I had to zero pad the hours into two decimal places.&lt;/li&gt;
&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-302070515207552357?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/j5J3mB51bK8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/302070515207552357/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=302070515207552357" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/302070515207552357?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/302070515207552357?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/j5J3mB51bK8/jboss-and-hsqldb-200.html" title="JBoss and HSQLDB 2.0.0" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/08/jboss-and-hsqldb-200.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MHQnY8eCp7ImA9Wx5XFUg.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-3815494561457835535</id><published>2010-07-21T13:59:00.003+02:00</published><updated>2010-09-15T14:57:13.870+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-15T14:57:13.870+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK 3.6 CSRF Protection</title><content type="html">Unfortunately, &lt;a href="http://www.zkoss.org/"&gt;ZK Web Framework&lt;/a&gt; version 3.6 and earlier lack any &lt;a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery"&gt;CSRF&lt;/a&gt; protection. i have created a very basic event filter to tackle this issue. Hope, someone else may find it useful, see &lt;a href="http://sites.google.com/site/xmedeko/code/zk-web-framework/zk-3-6-csrf-protection"&gt;http://sites.google.com/site/xmedeko/code/zk-web-framework/zk-3-6-csrf-protection&lt;/a&gt;. It is just a very first version, leave me a comment, if you have some suggestion.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Update 15th Sep 2010:&lt;/i&gt; Improved protection and logging.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-3815494561457835535?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/_TxOPbb0yx4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/3815494561457835535/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=3815494561457835535" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3815494561457835535?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3815494561457835535?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/_TxOPbb0yx4/zk-36-csrf-protection.html" title="ZK 3.6 CSRF Protection" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/07/zk-36-csrf-protection.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEANSXo_fyp7ImA9WxFaEUw.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-2402261003998714907</id><published>2010-07-14T16:11:00.002+02:00</published><updated>2010-07-14T16:13:18.447+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-14T16:13:18.447+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK - Converting Null Values</title><content type="html">A common problem in database programming is to display some meaningful labels instead of &lt;code&gt;NULL&lt;/code&gt; values in the list of database rows. Fortunately, &lt;a href="http://www.zkoss.org/"&gt;ZK Web Framework&lt;/a&gt;, offers a comfortable &lt;code&gt;TypeConverter&lt;/code&gt; class to address this issue. I have created a general type converter &lt;b&gt;&lt;code&gt;NullToLabelConverter&lt;/code&gt;&lt;/b&gt; to convert NULL values into any localised text. Hope, someone else may find it useful, see &lt;a href="http://sites.google.com/site/xmedeko/code/zk-web-framework/nulltolabelconverter"&gt;http://sites.google.com/site/xmedeko/code/zk-web-framework/nulltolabelconverter&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-2402261003998714907?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/v9WgBG1EjL8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/2402261003998714907/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=2402261003998714907" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/2402261003998714907?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/2402261003998714907?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/v9WgBG1EjL8/zk-converting-null-values.html" title="ZK - Converting Null Values" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/07/zk-converting-null-values.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8DRnw5eyp7ImA9Wx5QFU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-3808909642527449363</id><published>2010-05-19T12:57:00.003+02:00</published><updated>2010-09-03T10:51:17.223+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-03T10:51:17.223+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK Logging in ZUL zscript Code</title><content type="html">I have created a very simple class to simplify getting Java logger for the ZUL file (see &lt;a href="http://www.zkoss.org/"&gt;ZK Web Framework&lt;/a&gt;). It is targeted especially for the JBoss logging org.jboss.logging.Logger, but can be easily changed for &lt;a href="http://java.sun.com/javase/6/docs/api/java/util/logging/package-summary.html"&gt;&lt;code&gt;java.util.logging&lt;/code&gt;&lt;/a&gt; or any other logging library. Hope, someone else may find it useful, see &lt;a href="http://sites.google.com/site/xmedeko/code/zk-web-framework/zul-logging"&gt;http://sites.google.com/site/xmedeko/code/zk-web-framework/zul-logging&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-3808909642527449363?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/w2IGkH2zGQs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/3808909642527449363/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=3808909642527449363" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3808909642527449363?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3808909642527449363?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/w2IGkH2zGQs/zk-logging-in-zul-zscript-code.html" title="ZK Logging in ZUL zscript Code" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/05/zk-logging-in-zul-zscript-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8HQ3oyfSp7ImA9WxFaEUw.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-5793993347279541878</id><published>2010-04-07T17:10:00.004+02:00</published><updated>2010-07-14T16:13:52.495+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-14T16:13:52.495+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ZK" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>ZK and Very Long Strings</title><content type="html">When I was working with &lt;a href="http://www.zkoss.org/"&gt;ZK Web Framework&lt;/a&gt;, I have needed to display just a beginning of a very long &lt;code&gt;String&lt;/code&gt; in a &lt;code&gt;listbox&lt;/code&gt;. I have created a new type converter &lt;b&gt;&lt;code&gt;StringTrimConverter&lt;/code&gt;&lt;/b&gt;, which trims a string to the specified length. Hope, someone else may find it useful, see &lt;a href="http://sites.google.com/site/xmedeko/code/zk-web-framework/stringtrimconverter"&gt;http://sites.google.com/site/xmedeko/code/zk-web-framework/stringtrimconverter&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-5793993347279541878?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/0BFC38v5Wj4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/5793993347279541878/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=5793993347279541878" title="Počet komentářů: 3" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5793993347279541878?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5793993347279541878?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/0BFC38v5Wj4/zk-and-very-large-strings.html" title="ZK and Very Long Strings" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/04/zk-and-very-large-strings.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYGR3o8eip7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-3745068372369053704</id><published>2010-03-11T10:54:00.006+01:00</published><updated>2011-05-20T13:48:46.472+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:48:46.472+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>JPA: Mapping from Enum to Char(1)</title><content type="html">Very often, enumerations are stored in SQL databases as &lt;code&gt;char(1)&lt;/code&gt; columns. However, &lt;a href="http://en.wikipedia.org/wiki/Java_Persistence_API"&gt;JPA&lt;/a&gt; annotation &lt;a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Enumerated.html"&gt;Enumerated&lt;/a&gt; allows mapping from Java &lt;a href="http://java.sun.com/javase/6/docs/api/java/lang/Enum.html"&gt;Enum type&lt;/a&gt; into &lt;code&gt;javax.persistence.EnumType.STRING&lt;/code&gt; (i.e. SQL type &lt;code&gt;VARCHAR&lt;/code&gt;) or &lt;code&gt;javax.persistence.EnumType.ORDINAL&lt;/code&gt; (i.e. SQL type &lt;code&gt;INTERGER&lt;/code&gt;) only. &lt;br /&gt;
&lt;br /&gt;
I have read a few rather complicated advices, how to make a mapping from general Java Enum type into SQL &lt;code&gt;char(1)&lt;/code&gt; in &lt;a href="https://www.hibernate.org/"&gt;Hibernate&lt;/a&gt;. After a while, I have found out, that when all constant names in the Enum have length just character, one can make an easy JPA mapping:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;@Basic(optional = false)
@Enumerated(EnumType.STRING)
@Column(nullable = false, columnDefinition = "char(1) default 'A'")
private FruitType fruit_type = FruitType.A;
&lt;/pre&gt;So, the &lt;code&gt;FruitType&lt;/code&gt; may be:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public enum FruitType {
  /** Apples */
  A,
  /** Apricots */
  B,
  /** Cherries */
  C,
  /** Pears */
  P;
}
&lt;/pre&gt;&lt;br /&gt;
Well, it has a disadvantage, that "apricots" are represented by &lt;code&gt;FruitType.B&lt;/code&gt;. But all modern IDE (like Eclipse) shows Javadoc when the developer types the code. Beside the simplicity, the other great advantage is, that the application developer &lt;b&gt;knows&lt;/b&gt; that the "apricots" are represented by 'B' in the database. So, it is easier for the developer to write JPQL/HQL/SQL queries. When you a complicated JPA/Hibernate mapping from some type &lt;code&gt;FruitTypeLong.APPRICOT&lt;/code&gt; to the 'B' in database, then it will be just confusing after some time to write JPQL/HQL/SQL queries.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-3745068372369053704?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/g_medzY_N-E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/3745068372369053704/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=3745068372369053704" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3745068372369053704?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3745068372369053704?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/g_medzY_N-E/jpa-mapping-enum-to-char1.html" title="JPA: Mapping from Enum to Char(1)" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/03/jpa-mapping-enum-to-char1.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU4BQH87fSp7ImA9Wx5QFU0.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-5888846764837591457</id><published>2010-02-11T09:06:00.007+01:00</published><updated>2010-09-03T10:52:31.105+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-03T10:52:31.105+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Java Web Container: Hunting Redeploy Memory Leaks</title><content type="html">&lt;p&gt;Using a &lt;a href="http://java.sun.com/javase/6/docs/api/java/lang/ThreadLocal.html"&gt;ThreadLocal&lt;/a&gt; in a web application (WAR) may simplify the development, but one must have a very deep understanding of the web container (e.g. &lt;a href="http://tomcat.apache.org/"&gt;Tomcat&lt;/a&gt;) internals and Java class loading to avoid memory leaks when WAR is redeployed. See&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Problem with static ThreadLocal: &lt;a href="http://blog.arendsen.net/index.php/2005/02/22/threadlocals-and-memory-leaks-revisited/"&gt;http://blog.arendsen.net/index.php/2005/02/22/threadlocals-and-memory-leaks-revisited/&lt;/a&gt; and once more at &lt;a href="http://www.jroller.com/tackline/entry/fixing_threadlocal"&gt;http://www.jroller.com/tackline/entry/fixing_threadlocal&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Problem with inner classes and ThreadLocal: &lt;a href="http://crazybob.org/2006/02/threadlocal-memory-leak.html"&gt;http://crazybob.org/2006/02/threadlocal-memory-leak.html&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;br /&gt;
The problem might be hidden deep in any library used by the application. To check, if the redeploy memory leak occurs is simple with &lt;a href="http://www.eclipse.org/mat/"&gt;Eclipse Memory Analyzer (MAT)&lt;/a&gt;. Just redeploy the WAR several times, make a heap dump (e.g. by &lt;code&gt;jmap&lt;/code&gt; or &lt;code&gt;jconsole&lt;/code&gt;). Then open the heap dump in MAT and click the link Duplicate Classes: List classes loaded by more than one class loader. If there are some duplicated classes, then you have a memory leak.&lt;/p&gt;&lt;p&gt;Tip: how to clean ThreadLocals in a servlet: &lt;a href="http://www.dewavrin.info/?p=196"&gt;http://www.dewavrin.info/?p=196&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-5888846764837591457?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/JG_hF7-i4Qw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/5888846764837591457/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=5888846764837591457" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5888846764837591457?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5888846764837591457?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/JG_hF7-i4Qw/java-web-container-hunting-redeploy.html" title="Java Web Container: Hunting Redeploy Memory Leaks" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/02/java-web-container-hunting-redeploy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUBQ3o-fSp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-6768840594228310612</id><published>2010-01-20T09:33:00.005+01:00</published><updated>2011-05-20T13:50:52.455+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:50:52.455+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse" /><title>Eclipse: An error occurred while collecting items to be installed</title><content type="html">I have tried to update my Eclipse 3.5 Galileo plugins, and all what I have seen was:&lt;br /&gt;
&lt;pre class="preplain"&gt;An error occurred while collecting items to be installed
No repository found containing: org.eclipse.net4j.jms.api/osgi.bundle/1.0.0.v200806180305&lt;/pre&gt;I could not find the solution for a couple of hours. Finally, BINGO!, reinstalling EclipseLink packages solved it.&lt;br /&gt;
&lt;br /&gt;
Just go to &lt;code&gt;Help -&amp;gt; Install New Software -&amp;gt;&lt;/code&gt;, choose Galile update site &lt;code&gt;Galileo - http://download.eclipse.org/releases/galileo&lt;/code&gt; and search for all installed EclipseLink packages. (You must uncheck &lt;code&gt;Hide items that are already installed&lt;/code&gt; also.) The installed packages have grey icon. Just check them, press &lt;code&gt;Next&lt;/code&gt;, and then &lt;code&gt;Finish&lt;/code&gt;. Restart the Eclipse and then try to update plugins again.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-6768840594228310612?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/l74sv-xCUbU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/6768840594228310612/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=6768840594228310612" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/6768840594228310612?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/6768840594228310612?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/l74sv-xCUbU/eclipse-error-occurred-while-collecting.html" title="Eclipse: An error occurred while collecting items to be installed" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2010/01/eclipse-error-occurred-while-collecting.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04FQHwyeip7ImA9WxNWF00.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-3834332041318841747</id><published>2009-10-16T15:39:00.002+02:00</published><updated>2009-10-16T17:11:51.292+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-16T17:11:51.292+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse" /><title>Eclipse: Java Decompiler - Really Nice Plugin</title><content type="html">Why the method throws an exception? What happens when I pass a &lt;code&gt;null&lt;/code&gt; parameter? Hot the hell is the class designed? These question I have often asked when I had was working with a library without sources. But now I have found a really nice Eclipse plugin &lt;a href="http://java.decompiler.free.fr/jd-eclipse"&gt;http://java.decompiler.free.fr/jd-eclipse/&lt;/a&gt;. The update site is &lt;code&gt;http://java.decompiler.free.fr/jd-eclipse/update&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;Now I may press F3 button and see the decompiled source immediately. I just miss a possibility to debug the code without source.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-3834332041318841747?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/IIfCaTIYxvE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/3834332041318841747/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=3834332041318841747" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3834332041318841747?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/3834332041318841747?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/IIfCaTIYxvE/eclipse-java-decompiler-really-nice.html" title="Eclipse: Java Decompiler - Really Nice Plugin" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2009/10/eclipse-java-decompiler-really-nice.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMFQH8-eyp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-5388927999270738549</id><published>2009-09-16T16:21:00.011+02:00</published><updated>2011-05-20T13:53:31.153+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:53:31.153+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Linux" /><title>Linux: How to Convert Binary File into Byte Array</title><content type="html">Sometimes, a programmer needs to embed a content of a binary file into a program, usually as an array of bytes. For instance, I needed to embed an icon into a Java code, to be really sure the icon is always available for the program. So I have saved an icon in a GIF format and then used the &lt;a href="http://linux.die.net/man/1/od"&gt;&lt;code&gt;od&lt;/code&gt; command&lt;/a&gt;. But the result was an unusable list of octal numbers. After a minute with playing, I have found a feasible solution&lt;br /&gt;
&lt;pre class="prettyprint lang-sh"&gt;od -A n -v -t d1 image.gif &amp;#124; sed -e 's/^ *//g' -e 's/  */,/g' -e 's/$/,/g'&lt;/pre&gt;I have copied a result into my Java code as&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;private static final byte[] MISSING_ICON_BYTES = new byte[] { /* copy result here */ };
public static final ImageIcon MISSING_ICON = new ImageIcon(MISSING_ICON_BYTES);
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-5388927999270738549?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/NQ8Q6iOgd_c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/5388927999270738549/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=5388927999270738549" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5388927999270738549?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/5388927999270738549?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/NQ8Q6iOgd_c/linux-how-to-convert-binary-file-into.html" title="Linux: How to Convert Binary File into Byte Array" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2009/09/linux-how-to-convert-binary-file-into.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEADSXc6eip7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-2772251299733545447</id><published>2009-09-15T11:40:00.015+02:00</published><updated>2011-05-20T13:59:38.912+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:59:38.912+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ant" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Ant: Removing a File from ZIP or JAR</title><content type="html">I was facing a common problem with building a Java project by &lt;a href="http://ant.apache.org/"&gt;Ant&lt;/a&gt;: how to remove one file, and how to replace another file in a JAR (or ZIP) file. Many folks on the web, e.g. &lt;a href="http://www.blogger.com/%20http://frank.neatstep.com/node/29"&gt;here&lt;/a&gt; and &lt;a href="http://janmaterne.wordpress.com/2008/10/14/ant-deleting-files-from-zip/"&gt;here&lt;/a&gt;, advice to unzip the JAR, delete and replace what's needed, and then create JAR again. But I have found out a simpler solution using a &lt;a href="http://ant.apache.org/manual/CoreTypes/zipfileset.html"&gt;&lt;code&gt;&amp;lt;zipfileset&amp;gt;&lt;/code&gt;&lt;/a&gt; resource pattern:&lt;br /&gt;
&lt;pre class="prettyprint lang-xml"&gt;&amp;lt;delete file="new.jar"&amp;gt;
&amp;lt;zip file="new.jar"&amp;gt;
  &amp;lt;zipfileset src="old.jar"&amp;gt;
    &amp;lt;exclude name="META-INF/replace.properties"/&amp;gt;
    &amp;lt;exclude name="META-INF/remove.properties"/&amp;gt;
  &amp;lt;/zipfileset&amp;gt;
  &amp;lt;zipfileset file="file-to-replace.properties" fullpath="source-file-to-be-replaced.properties"/&amp;gt;
&amp;lt;/zip&amp;gt;
&lt;/pre&gt;You can use any of Ant &lt;a href="http://ant.apache.org/manual/CoreTypes/resources.html"&gt;resources&lt;/a&gt;. I personally like &lt;code&gt;zipfileset&lt;/code&gt;, because it allows to specify the &lt;code&gt;fullpath&lt;/code&gt; attribute, which is the simple way how to change a name of a source file. The &lt;code&gt;&amp;lt;exclude&amp;gt;&lt;/code&gt; element is like "delete file" command in this example.&lt;br /&gt;
&lt;br /&gt;
The Ant &lt;code&gt;jar&lt;/code&gt; task can be used instead of the &lt;code&gt;zip&lt;/code&gt; task, too. But then it has to be specified the &lt;code&gt;META-INF/MANIFEST.MF&lt;/code&gt; also, otherwise the &lt;code&gt;jar&lt;/code&gt; task creates a new one.&lt;br /&gt;
&lt;br /&gt;
The zip task has one unpleasant "feature". It does not create the file &lt;code&gt;new.jar&lt;/code&gt;, if it is newer (has greater timestamp) than the file &lt;code&gt;old.jar&lt;/code&gt;. So, I recommend to delete the &lt;code&gt;new.jar&lt;/code&gt; file first.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-2772251299733545447?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/MofH86ta2J8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/2772251299733545447/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=2772251299733545447" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/2772251299733545447?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/2772251299733545447?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/MofH86ta2J8/ant-removing-file-from-zip-or-jar.html" title="Ant: Removing a File from ZIP or JAR" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2009/09/ant-removing-file-from-zip-or-jar.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEENQHo4fCp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-2138157957970807946</id><published>2009-08-27T10:00:00.009+02:00</published><updated>2011-05-20T13:58:11.434+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:58:11.434+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Java Swing: Flexible Message Dialog</title><content type="html">&lt;a href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html"&gt;&lt;code&gt;JOptionPane&lt;/code&gt;&lt;/a&gt; makes life of a developer much easier when one need to show simple message or input dialogs. However, when a huge String or a String with many line breaks is passed to it's &lt;code&gt;showMessageDialog()&lt;/code&gt; method, then the message dialog may the screen. For the user, it's better, when the very large messages are wrapped in an &lt;a href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html"&gt;&lt;code&gt;JScrollPane&lt;/code&gt;&lt;/a&gt;. It is possible to pass &lt;code&gt;JScrollPane&lt;/code&gt; as an message parameter into to &lt;code&gt;JOptionPane&lt;/code&gt;, so far so good. Unfotunatelly, it's not possible to limit the maximum size of the dialog. Finally, I have finished with this solution:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;JTextArea textArea = new JTextArea();
textArea.setEditable(false);
// better to keep it true, so the user is able to copy the message to the clipboard
//textArea.setFocusable(false);
textArea.setOpaque(false);
textArea.setText(message);
textArea.setCaretPosition(0); // jump to the beginning
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(null); // no border, please
Dimension scrollPaneSize = scrollPane.getPreferredSize();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
scrollPaneSize.width = Math.min(scrollPaneSize.width, Math.max(screen.width / 2, 260));
scrollPaneSize.height = Math.min(scrollPaneSize.height, Math.max(screen.height / 2, 125));
scrollPane.setPreferredSize(scrollPaneSize);
JOptionPane jOptionPane = new JOptionPane(scrollPane, JOptionPane.ERROR_MESSAGE);
JDialog dialog = jOptionPane.createDialog(parent, &amp;quot;Error&amp;quot;);
// it could be nice to let the user resize the dialog, but then the scrollPane always shows the scroll bar
//dialog.setResizable(true);
dialog.setVisible(true);
dialog.dispose();
&lt;/pre&gt;The size of the &lt;code&gt;scrollPane&lt;/code&gt; grows or shrinks. It's maximum is screen size divided by two, or (260, 125) points (just in case the screen is too small :-)). I have found out, that (260, 125) is roughly the size of the empty massage dialog.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-2138157957970807946?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/ZIlT_tlWEGg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/2138157957970807946/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=2138157957970807946" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/2138157957970807946?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/2138157957970807946?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/ZIlT_tlWEGg/java-swing-flexible-message-dialog.html" title="Java Swing: Flexible Message Dialog" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2009/08/java-swing-flexible-message-dialog.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEECRXw6eyp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-4527065130176661558</id><published>2009-06-26T10:12:00.014+02:00</published><updated>2011-05-20T13:57:44.213+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T13:57:44.213+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse" /><title>Eclipse: WTP Plugin and Name of Deployment</title><content type="html">I have a WTP project in Eclipse called in like &lt;code&gt;myproject_war&lt;/code&gt;. When I have deployed it into the JBoss server, then the deployment name was &lt;code&gt;myproject_war.war&lt;/code&gt;. I wanted to deploy it as &lt;code&gt;myproject.war&lt;/code&gt; only. I could not find any property in the "Properties" dialogue to change the deploument name, so I have searched my filesystem for &lt;code&gt;"myproject_war"&lt;/code&gt; string. So, I have discovered the file&lt;br /&gt;
&lt;code&gt;.settings/org.eclipse.wst.common.component&lt;/code&gt; in the project directory. I have changed the attribute &lt;code&gt;name&lt;/code&gt; of the &lt;code&gt;wb-module&lt;/code&gt; module there, from&lt;br /&gt;
&lt;pre class="prettyprint lang-xml"&gt;&amp;lt;wb-module name=&amp;quot;myproject_war&amp;quot;&amp;gt;
&lt;/pre&gt;to&lt;br /&gt;
&lt;pre class="prettyprint lang-xml"&gt;&amp;lt;wb-module name=&amp;quot;myproject&amp;quot;&amp;gt;&lt;/pre&gt;Now, the project is deployed as &lt;code&gt;myproject.war&lt;/code&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-4527065130176661558?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/1ynxAklFw18" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/4527065130176661558/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=4527065130176661558" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4527065130176661558?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/4527065130176661558?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/1ynxAklFw18/eclipse-wtp-plugin-and-name-of.html" title="Eclipse: WTP Plugin and Name of Deployment" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2009/06/eclipse-wtp-plugin-and-name-of.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUcBR3s8cSp7ImA9WhZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-665270312096612395.post-268567603877205275</id><published>2009-06-19T09:10:00.015+02:00</published><updated>2011-05-20T14:04:16.579+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-20T14:04:16.579+02:00</app:edited><title>Java: Standalone Pattern and Lazy Initialization with Concurrent Access</title><content type="html">Whats wrong with this piece of code?&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class MyClass {
  private static MyClass instance = null;
  public static MyClass getInstance() {
    if (instance == null) instance = new MyClass();
    return instance;
  }
}
&lt;/pre&gt;&lt;br /&gt;
Nothing, if you have single thread application only. Otherwise add a magic word synchronized:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class MyClass {
  private static MyClass instance = null;
  public static &lt;b&gt;synchronized&lt;/b&gt; MyClass getInstance() {
    if (instance == null) instance = new MyClass();
    return instance;
  }
}
&lt;/pre&gt;&lt;br /&gt;
Now, it's more safe, but a little bit slower. I was thinking about speeding it up by double check locking:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class MyClass {
  private static MyClass instance = null;
  public static MyClass getInstance() {
    if (instance != null) return instance;
    &lt;b&gt;synchronized&lt;/b&gt; (MyClass.class) {
      // yes, one more check in synchronized block
      if (instance == null) instance = new MyClass();
    }
    return instance;
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;font color="red"&gt;Danger!&lt;/font&gt; There's hidden snag in this code. Fortunately, I have stumbled upon the See Bill Pugh's page &lt;a href="http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html"&gt;http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html&lt;/a&gt; explaining what's wrong with this piece of the code. Briefly, the construction of the object &lt;code&gt;instance = new MyClass()&lt;/code&gt; is not an atomic operation. So a thread can get the instance variable while some other thread is still processing the constructor of the same instance object. You can find some old web pages advising to use double check locking in a wrong way, e.g. &lt;a href="http://www.javaworld.com/javaworld/javatips/jw-javatip67.html"&gt;http://www.javaworld.com/javaworld/javatips/jw-javatip67.html&lt;/a&gt;. Bill Pugh's research has changed the memory model in Java 1.5, so there is a new keyword &lt;a href="http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html#28330"&gt;&lt;code&gt;&lt;b&gt;volatile&lt;/b&gt;&lt;/code&gt;&lt;/a&gt; which solves the hidden snag:&lt;br /&gt;
&lt;pre class="prettyprint lang-java"&gt;public class MyClass {
  private static &lt;b&gt;volatile&lt;/b&gt; MyClass instance = null;
  public static MyClass getInstance() {
    if (instance != null) return instance;
    &lt;b&gt;synchronized&lt;/b&gt; (MyClass.class) {
      // yes, one more check in synchronized block
      if (instance == null) instance = new MyClass();
    }
    return instance;
  }
}
&lt;/pre&gt;&lt;br /&gt;
Java has some nice semantic and syntactic sugar for multi-threaded programming. But this simple example shows, that one should not venture into the Java multi-threaded programming without deeper study of the Java internals and common concurrent programming principles.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/665270312096612395-268567603877205275?l=xmedeko.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/XmedekosBlog/~4/Hk1FrtNXMwA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://xmedeko.blogspot.com/feeds/268567603877205275/comments/default" title="Komentáře k příspěvku" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=665270312096612395&amp;postID=268567603877205275" title="Počet komentářů: 0" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/268567603877205275?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/665270312096612395/posts/default/268567603877205275?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/XmedekosBlog/~3/Hk1FrtNXMwA/java-standalone-pattern-and-lazy.html" title="Java: Standalone Pattern and Lazy Initialization with Concurrent Access" /><author><name>Ondrej Medek</name><uri>http://www.blogger.com/profile/02465917905307330831</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://xmedeko.blogspot.com/2009/06/java-standalone-pattern-and-lazy.html</feedburner:origLink></entry></feed>

