to the main page about the tutorial  INTERACTIVE WEB SERVICES WITH JAVA back up next

Views in JAOO

Views are generated by methods that read XML files using JDOM and stitch XML templates together. For example, the events schedule is generated by:

XML genEvents(TreeSet t) {
  XML x = templateScheduleDay;
  String hour1 = "";
  String minute1 = "";
  String hour2 = "";
  String minute2 = "";
  XML y = templateScheduleBlock;
  Iterator i = t.iterator();
  while (i.hasNext()) {
    Element e = (Element)i.next();
    String h1 = e.getChild("start").getAttributeValue("hour");
    String m1 = e.getChild("start").getAttributeValue("minute");
    String h2 = e.getChild("stop").getAttributeValue("hour");
    String m2 = e.getChild("stop").getAttributeValue("minute");
    if (!h1.equals(hour1) || !m1.equals(minute1) || !h2.equals(hour2) || !m2.equals(minute2)) {
       if (!hour1.equals(""))
         x = x<[events = templateScheduleEvents<[start=genHM(hour1,minute1),stop=genHM(hour2,minute2),block=y]];
       y = templateScheduleBlock;
       hour1 = h1; minute1 = m1; hour2 = h2; minute2 = m2;
    }
    if (e.getName().equals("talk")) 
      y=y<[event=templateScheduleTalk<[
                    track=genColor(e.getChildText("track")),
                    speakers=genEventSpeakers(e),
                    title=e.getChildText("title"),
                    extra=genExtra(e.getChildText("link"),e.getChildText("linktext")),
                    room=genRoom(e.getChildText("room"))]];
    else 
      y=y<[event=templateScheduleBreak<[title=e.getChildText("title")]];
  }
  if (!hour1.equals("")) 
    x = x<[events = templateScheduleEvents<[start=genHM(hour1,minute1),stop=genHM(hour2,minute2),block=y]];
  return x;
}

Notice that the code does not contain any mark-up tags, but only refers to template constants such as:

const XML templateScheduleEvents = [[
<tr>
<td valign="middle" align="center" width="100"><[start]> - <[stop]>&nbsp;&nbsp;</td>
<td valign="top"><[block]></td>
</tr>
<tr><td colspan="5"><hr></td></tr>
<[events]>
]]

back COPYRIGHT © 2002-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next