01: /*
02: * Created on Jan 30, 2005
03: *
04: */
05: package net.sf.thingamablog.generator;
06:
07: import java.util.Hashtable;
08:
09: /**
10: * @author Owner
11: */
12: public abstract class ListContainer implements TemplateContainer {
13: private String name;
14: /** Sort order attrib */
15: public static final String SORT_ORDER = "sort_order";
16: /** Glue attrib */
17: public static final String GLUE = "glue";
18:
19: public static final String ASC = "ascend";
20: public static final String DESC = "descend";
21:
22: protected Hashtable defaults = new Hashtable();
23:
24: private int curIndex = 0;
25: private String glue = "";
26:
27: public ListContainer(String name) {
28: this .name = name;
29: defaults.put(SORT_ORDER, ASC);
30: defaults.put(GLUE, "");
31: }
32:
33: /* (non-Javadoc)
34: * @see net.sf.thingamablog.tmpltest.TemplateContainer#init(java.util.Hashtable)
35: */
36: public void initialize(Hashtable attribs) {
37: curIndex = 0;
38: glue = attribs.get(GLUE).toString();
39: Object order = attribs.get(SORT_ORDER);
40: initListData(order != null
41: && order.toString().equalsIgnoreCase(ASC), attribs);
42: }
43:
44: public abstract void initListData(boolean asc, Hashtable attribs);
45:
46: public abstract int getListDataSize();
47:
48: public abstract Object getValueForTag(TemplateTag t, int index);
49:
50: public Object getValueForTag(TemplateTag t) {
51: return getValueForTag(t, curIndex);
52: }
53:
54: public int currentIndex() {
55: return curIndex;
56: }
57:
58: /* (non-Javadoc)
59: * @see net.sf.thingamablog.tmpltest.TemplateContainer#processAgain()
60: */
61: public boolean processAgain() {
62: curIndex++;
63: return curIndex < getListDataSize();
64: }
65:
66: /* (non-Javadoc)
67: * @see net.sf.thingamablog.tmpltest.TemplateContainer#prefix()
68: */
69: public String prefix() {
70: return null;
71: }
72:
73: /* (non-Javadoc)
74: * @see net.sf.thingamablog.tmpltest.TemplateContainer#postfix()
75: */
76: public String postfix() {
77: if (curIndex < getListDataSize() - 1)
78: return glue;
79: return null;
80: }
81:
82: /* (non-Javadoc)
83: * @see net.sf.thingamablog.tmpltest.TemplateElement#getName()
84: */
85: public String getName() {
86: return name;
87: }
88:
89: /* (non-Javadoc)
90: * @see net.sf.thingamablog.tmpltest.TemplateElement#getDefaultAttributes()
91: */
92: public Hashtable getDefaultAttributes() {
93: return defaults;
94: }
95: }
|