KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > template > TemplateTagHandler


1 /*
2  * $Id: TemplateTagHandler.java,v 1.3 2004/12/01 07:54:28 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.template;
15
16 import org.wings.SComponent;
17 import org.wings.STemplateLayout;
18 import org.wings.io.Device;
19 import org.wings.template.parser.ParseContext;
20 import org.wings.template.parser.SpecialTagHandler;
21
22 import java.io.InputStream JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * A TemplateTagHandler
28  *
29  * @author <A HREF="mailto:zeller@think.de">Henner Zeller</A>
30  * @version $Revision: 1.3 $
31  */

32 abstract class TemplateTagHandler implements SpecialTagHandler {
33     long startPos;
34     long endPos;
35     Map JavaDoc properties;
36     String JavaDoc name;
37
38     /**
39      * Get start position of the area in the sourcefile this
40      * handler processes.
41      */

42     public long getTagStart() {
43         return startPos;
44     }
45
46     /**
47      * Get the length of the area in the sourcefile.
48      * The area this handler processes is skipped in the inputfile.
49      */

50     /*
51      * Since we just have a single tag, this is just the area
52      * this tag spans:
53      */

54     public long getTagLength() {
55         return endPos - startPos;
56     }
57
58     /**
59      * actually perform the action associated with this tag.
60      *
61      * @throws Exception anything can happen .. and throw an Exception
62      * which is caught in PageParser
63      */

64     public void executeTag(ParseContext context, InputStream JavaDoc input)
65             throws Exception JavaDoc {
66         TemplateParseContext tcontext = (TemplateParseContext) context;
67         Device sink = tcontext.getDevice();
68
69         /*
70          * get the component that is associtated with this name. This has
71          * been set as Layout Manager Constraint.
72          */

73         SComponent c = tcontext.getComponent(name);
74         if (c == null) {
75             sink.print("<!-- Template: '" + name + "' Component not given -->");
76         } else {
77             // set properties; the STemplateLayout knows how
78
if (properties.size() > 0) {
79                 PropertyManager propManager =
80                         STemplateLayout.getPropertyManager(c.getClass());
81
82                 if (propManager != null) {
83                     Iterator JavaDoc iter = properties.keySet().iterator();
84                     while (iter.hasNext()) {
85                         String JavaDoc key = (String JavaDoc) iter.next();
86                         String JavaDoc value = (String JavaDoc) properties.get(key);
87                         // System.out.println("set Property " + key + "=" +value + " for " + name);
88
propManager.setProperty(c, key, value);
89                     }
90                 }
91             }
92             c.write(sink);
93         }
94         input.skip(getTagLength());
95     }
96 }
97
98
99
Popular Tags