KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: RangeTagHandler.java,v 1.5 2005/03/14 13:33:28 neurolabs 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.io.Device;
17 import org.wings.template.parser.ParseContext;
18 import org.wings.template.parser.PositionReader;
19 import org.wings.template.parser.SGMLTag;
20
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23
24 /**
25  * A TemplateTagHandler
26  *
27  * @author <A HREF="mailto:zeller@think.de">Henner Zeller</A>
28  * @version $Revision: 1.5 $
29  */

30 public class RangeTagHandler extends TemplateTagHandler {
31     boolean close_is_missing = false;
32
33     /**
34      * Parse special tag.
35      *
36      * @param context The ParseContext
37      * @param input The PositionReader, located after the Name token of the Tag
38      * @param startPosition The Position parsing of this token began
39      * @param startTag the SGMLTag found in the file.
40      */

41     public SGMLTag parseTag(ParseContext context,
42                             PositionReader input,
43                             long startPosition,
44                             SGMLTag startTag)
45             throws IOException JavaDoc {
46         final String JavaDoc startTagName = startTag.getName();
47         final String JavaDoc endTagName = "/" + startTagName;
48
49         /*
50          * parse the full tag to get all parameters
51          * (i.e. an optional 'format'-parameter)
52          * and to place the Reader at the position
53          * after the closing '>'
54          */

55         startTag.parse(input);
56
57         /*
58          * The Offset is the space the reader skipped
59          * before it reached the opening '<'
60          * <!-- a comment --> some garbage <DATE>
61          * ^----- offset --------------------^
62          */

63         startPos = startPosition + startTag.getOffset();
64
65         /*
66          * get properties
67          */

68         properties = startTag.getAttributes();
69
70         name = startTag.value("NAME", null);
71         if (name == null)
72             return null;
73
74         endPos = input.getPosition(); // in case </component> is missing
75

76         while (!startTag.finished()) {
77             startTag = new SGMLTag(input, true);
78             if (startTag.isNamed(endTagName) || startTag.isNamed(startTagName))
79                 break;
80         }
81
82         // Either EOF or newly opened COMPONENT (unexpectedly)
83
if (startTag.finished() || startTag.isNamed(startTagName)) {
84             close_is_missing = true;
85         } else {
86             // The current Position is after the closing '>'
87
endPos = input.getPosition();
88         }
89
90         // remove properties, which are not necessary for the PropertyManager
91
properties.remove("NAME");
92         properties.remove("TYPE");
93
94         return startTag;
95     }
96
97     /**
98      * actually perform the action associated with this tag.
99      *
100      * @throws Exception anything can happen .. and throw an Exception
101      * which is caught in PageParser
102      */

103     public void executeTag(ParseContext context, InputStream JavaDoc input)
104             throws Exception JavaDoc {
105         super.executeTag(context, input);
106
107         // warn, if the closing tag was not found ..
108
if (close_is_missing) {
109             TemplateParseContext tcontext = (TemplateParseContext) context;
110             Device sink = tcontext.getDevice();
111             sink.print("<table bgcolor='#FFAA55'><tr><td>");
112             sink.print("&nbsp;<blink><b>");
113             sink.print("closing tag missing");
114             sink.print(" for '<em>" + name + "</em>'");
115             sink.print("</b></blink>&nbsp;");
116             sink.print("</td></tr></table>");
117         }
118     }
119 }
120
121
122
Popular Tags