01: /*
02: * Declaration.java February 2006
03: *
04: * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General
16: * Public License along with this library; if not, write to the
17: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18: * Boston, MA 02111-1307 USA
19: */
20:
21: package simple.page.translate;
22:
23: /**
24: * The <code>Declaration</code> object is used to parse declarations
25: * from the JSP source. Declarations are member functions and fields
26: * that will be added at the head of the generates source object.
27: * </pre>
28: *
29: * <%!
30: * declaration
31: * %>
32: *
33: * </pre>
34: * The above declaration token is parsed by this object. This will
35: * basically remove the beginning and end tags an insert the
36: * remainder, that is, the declaration, into the definition object.
37: *
38: * @author Niall Gallagher
39: */
40: class Declaration extends Token {
41:
42: /**
43: * This is used to collect the token parsed from the declaration.
44: */
45: private TokenBuffer member;
46:
47: /**
48: * Constructor for the <code>Declaration</code> token. This will
49: * create a buffer, which can be used to accumulate the data
50: * extracted from the supplied declaration token.
51: */
52: public Declaration() {
53: this .member = new TokenBuffer();
54: }
55:
56: /**
57: * Constructor for the <code>Declaration</code> token. This will
58: * create a buffer, which can be used to accumulate the data
59: * extracted from the supplied declaration token before parsing.
60: *
61: * @param token this is the declaration token to be parsed
62: */
63: public Declaration(String token) {
64: this ();
65: parse(token);
66: }
67:
68: /**
69: * This method will supply code to the document definition that
70: * will allow a declaration to be used by the page. The data
71: * inserted into the definition will generated in the class.
72: *
73: * @param source this is the source to push the code into
74: * @param builder this is the builder driving the process
75: */
76: public void process(Definition source, Builder builder) {
77: source.addDeclaration(member.text());
78: }
79:
80: /**
81: * This will clear the declaration token so that the parse can be
82: * reused by the builder. In practice this method just satisfies
83: * the contract of the token so that this object is not abstract.
84: */
85: protected void init() {
86: member.clear();
87: }
88:
89: /**
90: * This is a very simple parse method which basically extracts the
91: * begining and end values from the token. For instance this will
92: * remove "<%!" and "%>" from the token supplied.
93: */
94: protected void parse() {
95: if (skip("<%!")) {
96: member.append(buf, off, count - 5);
97: }
98: }
99: }
|