Archives / 2004 / September
  • [Java] Things I learn while I dig into JSR 168

    The portlet API spec (JSR 168) is a piece of good work, but once you want to do something out of the ordinary with a portlet, it feels a Perhaps it depends on what portal engine you're using, but I'd like to share some stuff I've noticed with session variables.

    A portlet sitting in one page needs to know on what portal page it is used - it needs to know the name of the portal page or the name of the navigation item / menu item the user clicked so that the portlet may show dynamic content based on that. If this is possible, I could use the same portlet instance on several portal pages.

    I know, maybe portlets shouldn't be aware of where they are used, be it a mobile phone, digital TV-box or in a java portal, but I sure would like to get some more information out of the portal context.

    My first thought was - the session object. I can extend the portal navigation or the portal frame (which is just a JSP page) and add code to it that sets the name of the current page or the menu item the user clicked in a session variable. Problem is that it seems impossible for a JSR 168 portlet to get to the Session object of the portal. Since the portal and the portlet are two separate web applications, this is maybe as it should be, but even so...

    Then I had a quick look at the portal context object to see if I could add a property to the context from the portal framework, then read it from the portlet, but it seems impossible without changing some of the portal code that I'm not sure I want to (or can) do.

    So, final option seems to be to store the name of the selected portal page in the database, using the username as key, then read it from the database in the portlet. Not the most effective solution, but I can't find any other way to do this.

  • ASP.ASP - good at generating a dynamic RSS feed

    I did a few tests some weeks ago and coded some base classes and an HttpHander that generates an RSS feed depending on the URI of the get request. I ended up with an RssHandler that does:

    1) listens on get requests for *.rss
    2) parses the URI to see what kind of feed the requester wants to have (news.rss, 123.rss, whatever.rss)
    3) gets the requested data from different data sources and builds up a rss object generated with the XSD Object Generator
    4) Serializes the RSS object back to the user on the Response-stream.

    Using .NET to do this is really a walk in the park. Some of the code looks like this:

    public class RssHandler : IHttpHandler


               public void ProcessRequest(HttpContext context)


                          HttpRequest Request = context.Request;

                          HttpResponse Response = context.Response;


                          //Gets som info about the requested data

                          string newsType = GetNewsType(Request);


                          //Build up the RSS object – consider caching

                          rss rssData = GetRss(newsType);


                          //set response content type to text/xml

                          Response.ContentType = "text/xml";


                          //Add namespace for my extension to the RSS

                          XmlSerializerNamespaces ns =

                              new XmlSerializerNamespaces();

                          ns.Add("ext", "");


                          //serialize via response stream back to browser

                          XmlSerializer serializer =

                                     new XmlSerializer(typeof(rss));

                          serializer.Serialize(Response.OutputStream, rssData, ns);



               private static rss GetRss(String newsType)


                          rss rssData = new rss();

                          rssData.version = "2.0";


                          //Add other stuff to rss object here

                          //things like author, all the items etc...


                          return rssData;



    The rss object is automatically created from a sample rss XML file and a schema, therefore it is serialized into correct RSS XML. I modified the generated RSS types to support a few extensions I wanted to have, with their own namespace. To do this, add a Namespace="someNamespace" to the XmlElement attribute for each element that should have it.

  • XSD Object Generator

    Found this tool on MS Downloads some time back, used to generate sample C# & VB classes from a XSD schema.

    The Sample Code Generator (XSDObjectGen) tool takes an XSD schema as input and generates sample code showing how to mark up C# and VB.Net classes so that when serialized with the XML serializer, the resulting XML will be valid according to the original schema.

    If Visual Studio .NET is present, will also install a new XSD project type in the C# and VB.NET project types.

    XSD Object Generator

     It seems to work a bit better than the XSD tool that ships with VS.NET.

  • Anyone looked at the OWL standard from W3C?

    I'm having a taxonomy/ontology discussion in the project I'm involved with. I was suggesting we build our own XML structure and someone suggested to have a look at OWL.

    To me it looks like OWL has extended RDF into something very complex, and it would probably take quite a while just to define all the OWL "classes" we would need. I'd like to know if anyone has had a look at OWL to see if it's useful. What we need to describe are primarily things like organisation, location and similar items.