KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > theme > render > impl > TableRegionRenderer


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9
10 package org.jboss.portal.core.theme.render.impl;
11
12 import org.apache.log4j.Logger;
13 import org.jboss.portal.server.output.FragmentResult;
14 import org.jboss.portal.server.theme.Item;
15 import org.jboss.portal.server.theme.Region;
16 import org.jboss.portal.server.theme.RegionOrientation;
17 import org.jboss.portal.server.theme.render.RegionRenderer;
18 import org.jboss.portal.server.theme.render.RenderContext;
19 import org.jboss.portal.server.theme.render.RenderException;
20
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * Implementation of a Region renderer, based on a table tag.
25  *
26  * @author <a HREF="mailto:mholzner@novell.com>Martin Holzner</a>
27  * @version $LastChangedRevision$, $LastChangedDate$
28  * @see RegionRenderer
29  */

30 public class TableRegionRenderer
31    implements RegionRenderer
32 {
33    private static Logger log = Logger.getLogger(TableRegionRenderer.class);
34
35    public TableRegionRenderer()
36    {
37    }
38
39    /**
40     * @see org.jboss.portal.server.theme.render.Renderer#renderStart
41     */

42    public void renderStart(RenderContext ctx)
43    {
44       log.debug(ctx.getRegionOrientation().toString());
45
46       if (ctx.getRegionOrientation() == RegionOrientation.HORIZONTAL)
47       {
48          // do td's
49
ctx.getMarkupFragment().append("<table class='horizontalRegion'><tr>");
50       }
51       else
52       {
53          // do tr's
54
ctx.getMarkupFragment().append("<table class='verticalRegion'>");
55       }
56    }
57
58    /**
59     * @see RegionRenderer#render
60     */

61    public void render(RenderContext ctx, Region region) throws RenderException
62    {
63       log.debug("starting with: " + ctx.getMarkupFragment());
64
65       if (region.isEmpty())
66       {
67          log.debug("region is empty: nothing to render!");
68          return;
69       }
70
71       renderStart(ctx);
72
73       for (Iterator JavaDoc i = region.items(); i.hasNext();)
74       {
75          Item item = (Item)i.next();
76          FragmentResult fragment = item.getFragment();
77
78          if (ctx.getRegionOrientation() == RegionOrientation.HORIZONTAL)
79          {
80             // do td's
81
ctx.getMarkupFragment().append("<td class='horizontalRegionElement'>");
82             ctx.getWindowRenderer().render(ctx, fragment);
83             ctx.getMarkupFragment().append("</td>");
84          }
85          else
86          {
87             // do tr's
88
ctx.getMarkupFragment().append("<tr><td class='verticalRegionElement'>");
89             ctx.getWindowRenderer().render(ctx, fragment);
90             ctx.getMarkupFragment().append("</td></tr>");
91          }
92       }
93
94       renderEnd(ctx);
95
96       log.debug("ending with: " + ctx.getMarkupFragment());
97    }
98
99    /**
100     * @see org.jboss.portal.server.theme.render.Renderer#renderEnd
101     */

102    public void renderEnd(RenderContext ctx)
103    {
104       if (ctx.getRegionOrientation() == RegionOrientation.HORIZONTAL)
105       {
106          // do td's
107
ctx.getMarkupFragment().append("</tr></table>");
108       }
109       else
110       {
111          // do tr's
112
ctx.getMarkupFragment().append("</table>");
113       }
114    }
115 }
116
Popular Tags