<?xml version="1.0" encoding="UTF-8" ?><rss xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Sindri's internet adventures</title>
    <link>http://sindri.info</link>
    <description>Everything you ever wanted to know about Sindri but never dared to ask</description>
    <copyright />
    <dc:rights />
    <item>
      <title>Using Gravatars in Unify</title>
      <link>http://sindri.info:80/blog/post/item4969</link>
      <description>&lt;p&gt;&lt;em&gt;Republished because of my weird fixation on everything having to last forever&lt;/em&gt;&lt;/p&gt;&#xD;
&lt;h2&gt;Dealing with complex data types in XSL&lt;/h2&gt;&#xD;
&lt;p&gt;My motivation for creating this article comes from wanting to implement Gravatars on a blog/comment feature on a Unify site. To create a link to a Gravatar you need to generate a URL that contains an MD5 hash of an email adress in HEX formatting and XSL simply doesn't help much with that sort of thing. In Java code however generating an MD5 hash from an email address is a trivial task.&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;VYRE Unify uses XSL a lot to generate HTML from the XML data stored in it's content repository. This can often lead to issues for users trying to produce output with anything more complicated than plain text with simple HTML tags and URLs. For example reformating dates is a nightmare to do with just plain XSL and XPath.&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;This is where XSL Java extensions come in to save the day. Using XSL Java extensions you can effectively call any Java method available from an XSL script. VYRE Unify fully supports XSL Java extensions.&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;To explain what XSL Java extensions are, here is a simple example that prints the cosinus of a number in the XML source.&lt;/p&gt;&#xD;
&lt;p&gt;&lt;span style="font-family: 'Courier New';"&gt;&lt;xsl:value-of xmlns:math="xalan://java.lang.Math" select="math:cos( content/item/angle )" /&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p&gt;To explain what's going on here, I have defined a new namespace “math” to be a &lt;em&gt;Java class format namespace&lt;/em&gt;. I can then call static methods on that class in XPath by using the namespace. Note the parameter is a XPath that resolves to a tag containing a number and is automatically cast to a javatype &lt;strong&gt;double&lt;/strong&gt;.&lt;/p&gt;&#xD;
&lt;p&gt;A slightly more complicated example would be printing the current date:&lt;/p&gt;&#xD;
&lt;p&gt;&#xD;
&lt;xmp&gt;&#xD;
&lt;xsl:template name="currentDate" xmlns:date="xalan://java.util.Date"&gt;&#xD;
  &lt;xsl:variable name="current-date" select="date:new()" /&gt;&#xD;
  &lt;xsl:value-of select="date:toString( $current-date )" /&gt;&#xD;
&lt;/xsl:template&gt;&#xD;
&lt;/xmp&gt;&lt;/p&gt;&#xD;
&lt;p&gt;This is the equivalent of the Java code:&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;&lt;xmp&gt;&#xD;
public String getCurrentDate() { &#xD;
    java.util.Date currentDate = new java.util.Date();&#xD;
    return currentDate.toString(); &#xD;
}&#xD;
&lt;/xmp&gt;&lt;/p&gt;&#xD;
&lt;p&gt;You might notice that the method calls in the XPath look a bit backward compared to the Java syntax. The rule is a methods declaring class is the first parameter of the method and the following parameters are the Java methods parameters. Calling constructors is the same syntax as calling a static method with the name "new".&lt;/p&gt;&#xD;
&lt;p&gt;Both the examples above use so called Class format namespace, there is also package format namespace and Java format namespace that you can read about in the &lt;a href="http://xml.apache.org/xalan-j/extensions.html#ext-func-calls" title="Xalan documentation"&gt;Xalan documentation&lt;/a&gt;.&lt;/p&gt;&#xD;
&lt;h2&gt;Using gravatars&lt;br /&gt;&lt;/h2&gt;&#xD;
&lt;p&gt;Now finally I'll show how I managed to create gravatar links in an item list XSL in Unify. The first place to look was the &lt;a href="http://en.gravatar.com/site/implement/" title="Gravatar implementor's guide"&gt;Gravatar implementor's guide&lt;/a&gt; &lt;a href="http://en.gravatar.com/site/implement/java" title="Java"&gt;Java&lt;/a&gt; section. Where they show a class that can generate the MD5 hash with a simple static method call. What I actually did was cheat, because I knew there was a class in Unify that does exactly the same thing, so I did:&lt;/p&gt;&#xD;
&lt;p&gt;&lt;xmp&gt;&#xD;
&lt;div xmlns:hasher="xalan://vyre.realms.PasswordService"&gt;&#xD;
  &lt;xsl:variable name="hasher" select="hasher:getInstance('MD5', 'hex')"/&gt; &#xD;
  &lt;img&gt; &lt;br /&gt;    &lt;xsl:attribute name="src"&gt;&lt;br /&gt;&#xD;
      http://www.gravatar.com/avatar/&lt;xsl:value-of select="hasher:encrypt($hasher, ./creator/email)"/&gt;.jpg&#xD;
    &lt;/xsl:attribute&gt;&#xD;
  &lt;/img&gt; &#xD;
&lt;/div&gt;&#xD;
&lt;/xmp&gt;&lt;/p&gt;&#xD;
&lt;p&gt;But for non Unify developers it is trivial to compile the class given on the Gravatar site, put it on your Unify servers classpath and calling it like so:&lt;/p&gt;&#xD;
&lt;p&gt;&lt;xmp&gt;&#xD;
&lt;div xmlns:md5="xalan://MD5Util"&gt;&#xD;
  &lt;img&gt;&#xD;
    &lt;x</description>
      <pubDate>Mon, 16 Nov 2009 16:28:53 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4969</guid>
      <dc:date>2009-11-16T16:28:53Z</dc:date>
    </item>
    <item>
      <title>Das Kapital</title>
      <link>http://sindri.info:80/blog/post/item4906</link>
      <description>&lt;blockquote&gt;“Owners of capital will stimulate the working class to buy more and more of expensive goods, houses and technology, pushing them to take more and more expensive credits, until their debt becomes unbearable. The unpaid debt will lead to bankruptcy of banks, which will have to be nationalised, …”&lt;/blockquote&gt;&#xD;
-- Karl Marx in &lt;em&gt;&lt;a href="http://en.wikipedia.org/wiki/Das_Kapital"&gt;Das Kapital&lt;/a&gt;&lt;/em&gt; published 1867 &lt;small&gt;&lt;a href="http://husmodirivesturbaenum.eyjan.is/2009/05/07/hann-sa-thetta-allt-fyrir/"&gt;source&lt;/a&gt;&lt;/small&gt;</description>
      <pubDate>Thu, 07 May 2009 15:03:04 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4906</guid>
      <dc:date>2009-05-07T15:03:04Z</dc:date>
    </item>
    <item>
      <title>Pro blogger</title>
      <link>http://sindri.info:80/blog/post/item4763</link>
      <description>I've finally, after this minimal amount of training, gone pro in my blogging career. My first attempt at pro blogging is this &lt;a href="http://www.vyre.com/company/staff-room-blog/detail/item36359/"&gt;quick overview of my trip to Belgium last year&lt;/a&gt;. Expect more to come soonish, so &lt;a href="http://www.vyre.com/company/staff-room-blog/"&gt;watch this space&lt;/a&gt;!</description>
      <pubDate>Thu, 12 Feb 2009 22:11:00 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4763</guid>
      <dc:date>2009-02-12T22:11:00Z</dc:date>
    </item>
    <item>
      <title>Generic and special laws of laptop relativity</title>
      <link>http://sindri.info:80/blog/post/item4757</link>
      <description>This item was uploaded 06-Feb-2009 13:29:57</description>
      <pubDate>Fri, 06 Feb 2009 13:30:31 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4757</guid>
      <dc:date>2009-02-06T13:30:31Z</dc:date>
    </item>
    <item>
      <title>DataMarket</title>
      <link>http://sindri.info:80/blog/post/item4748</link>
      <description>This item was uploaded 03-Feb-2009 18:31:10</description>
      <pubDate>Tue, 03 Feb 2009 18:31:10 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4748</guid>
      <dc:date>2009-02-03T18:31:10Z</dc:date>
    </item>
    <item>
      <title>Wiki wiki!</title>
      <link>http://sindri.info:80/blog/post/item4616</link>
      <description>This item was uploaded 07-Nov-2008 14:28:39</description>
      <pubDate>Fri, 07 Nov 2008 14:28:39 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4616</guid>
      <dc:date>2008-11-07T14:28:39Z</dc:date>
    </item>
    <item>
      <title>Financial expert</title>
      <link>http://sindri.info:80/blog/post/item4539</link>
      <description>This item was uploaded 09-Oct-2008 11:58:06</description>
      <pubDate>Thu, 09 Oct 2008 15:46:30 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4539</guid>
      <dc:date>2008-10-09T15:46:30Z</dc:date>
    </item>
    <item>
      <title>Javascript brainfuck interpreter</title>
      <link>http://sindri.info:80/blog/post/item4528</link>
      <description>This item was uploaded 01-Oct-2008 18:01:17</description>
      <pubDate>Wed, 01 Oct 2008 17:06:56 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4528</guid>
      <dc:date>2008-10-01T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Google Chrome crash window</title>
      <link>http://sindri.info:80/blog/post/item4515</link>
      <description>This item was uploaded 04-Sep-2008 14:26:19</description>
      <pubDate>Wed, 01 Oct 2008 16:38:20 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item4515</guid>
      <dc:date>2008-10-01T16:38:20Z</dc:date>
    </item>
    <item>
      <title>My pet peeve</title>
      <link>http://sindri.info:80/blog/post/item2494</link>
      <description>This item was uploaded 28-Nov-2007 14:07:31</description>
      <pubDate>Wed, 28 Nov 2007 14:07:31 GMT</pubDate>
      <guid>http://sindri.info:80/blog/post/item2494</guid>
      <dc:date>2007-11-28T14:07:31Z</dc:date>
    </item>
  </channel>
</rss>


