01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.template;
14:
15: import org.wings.SComponent;
16: import org.wings.STemplateLayout;
17: import org.wings.io.Device;
18: import org.wings.template.parser.ParseContext;
19: import org.wings.template.parser.SpecialTagHandler;
20:
21: import java.io.InputStream;
22: import java.util.Iterator;
23: import java.util.Map;
24:
25: /**
26: * A TemplateTagHandler
27: *
28: * @author <A href="mailto:zeller@think.de">Henner Zeller</A>
29: */
30: abstract class TemplateTagHandler implements SpecialTagHandler {
31: long startPos;
32: long endPos;
33: Map properties;
34: String name;
35:
36: /**
37: * Get start position of the area in the sourcefile this
38: * handler processes.
39: */
40: public long getTagStart() {
41: return startPos;
42: }
43:
44: /**
45: * Get the length of the area in the sourcefile.
46: * The area this handler processes is skipped in the inputfile.
47: */
48: /*
49: * Since we just have a single tag, this is just the area
50: * this tag spans:
51: */
52: public long getTagLength() {
53: return endPos - startPos;
54: }
55:
56: /**
57: * actually perform the action associated with this tag.
58: *
59: * @throws Exception anything can happen .. and throw an Exception
60: * which is caught in PageParser
61: */
62: public void executeTag(ParseContext context, InputStream input)
63: throws Exception {
64: TemplateParseContext tcontext = (TemplateParseContext) context;
65: Device sink = tcontext.getDevice();
66:
67: /*
68: * get the component that is associtated with this name. This has
69: * been set as Layout Manager Constraint.
70: */
71: SComponent c = tcontext.getComponent(name);
72: if (c == null) {
73: sink.print("<!-- Template: '" + name
74: + "' Component not given -->");
75: } else {
76: // set properties; the STemplateLayout knows how
77: if (properties.size() > 0) {
78: PropertyManager propManager = STemplateLayout
79: .getPropertyManager(c.getClass());
80:
81: if (propManager != null) {
82: Iterator iter = properties.keySet().iterator();
83: while (iter.hasNext()) {
84: String key = (String) iter.next();
85: String value = (String) properties.get(key);
86: // System.out.println("set Property " + key + "=" +value + " for " + name);
87: propManager.setProperty(c, key, value);
88: }
89: }
90: }
91: c.write(sink);
92: }
93: input.skip(getTagLength());
94: }
95: }
|