01: /*
02: * Copyright 2007 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * @author www.gerdziegler.de
13: */
14: package org.ztemplates.actions.expression;
15:
16: import org.apache.log4j.Logger;
17: import org.ztemplates.actions.util.ZFormatUtil;
18:
19: public class ZLiteral implements ZTerm {
20: private static Logger log = Logger.getLogger(ZLiteral.class);
21:
22: private StringBuffer text = new StringBuffer();
23:
24: public String getText() {
25: return text.toString();
26: }
27:
28: public String parse(String s) throws ZParserException {
29: for (int i = 0; i < s.length(); i++) {
30: char c = s.charAt(i);
31: switch (c) {
32: case '/':
33: return s.substring(i);
34: case '$':
35: return s.substring(i);
36: case '#':
37: return s.substring(i);
38: case '*':
39: return s.substring(i);
40: case '[':
41: return s.substring(i);
42: case ']':
43: return s.substring(i);
44: default:
45: text.append(c);
46: break;
47: }
48: }
49:
50: return "";
51: }
52:
53: public String toString() {
54: StringBuffer sb = new StringBuffer();
55: sb.append("<literal>");
56: sb.append(getText());
57: sb.append("</literal>");
58: return sb.toString();
59: }
60:
61: public void toXml(StringBuffer sb, int depth) {
62: ZFormatUtil.indent(sb, depth);
63: sb.append("<literal>");
64: sb.append(getText());
65: sb.append("</literal>");
66: }
67:
68: public String toDefinition() {
69: return text.toString();
70: }
71:
72: }
|