01: /*
02: * JDynamiTe - Dynamic Template in Java
03: * Copyright (C) 2001 Christophe Bouleau
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
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 GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package cb.jdynamite.analyser;
21:
22: import java.util.ArrayList;
23: import cb.jdynamite.ITemplateDocument;
24:
25: public class DefaultDynamicElement implements ITemplateElement,
26: IDynamicElement {
27: private StringBuffer value;
28: private ArrayList templateDef;
29: private String name; // just for debug
30:
31: public DefaultDynamicElement() {
32: templateDef = new ArrayList();
33: value = new StringBuffer();
34: }
35:
36: public DefaultDynamicElement(String elementName) {
37: this ();
38: name = elementName;
39: }
40:
41: public String getValue(ITemplateDocument rootDocument) {
42: return value.toString();
43: }
44:
45: public void setValue(String arbitraryValue) {
46: value.delete(0, value.length());
47: if (arbitraryValue != null) {
48: value.append(arbitraryValue);
49: }
50: }
51:
52: public String getDefinition(int depth) {
53: StringBuffer def = new StringBuffer();
54: for (int indent = 0; indent < depth; indent++) {
55: def.append(" ");
56: }
57: def.append("DefaultDynamicElement \"" + name + "\":\n");
58: int elemNb = templateDef.size();
59: for (int i = 0; i < elemNb; i++) {
60: ITemplateElement elem = (ITemplateElement) templateDef
61: .get(i);
62: def.append(elem.getDefinition(depth + 1));
63: //String elemDef = elem.getDefinition(depth + 1);
64: /***
65: elemDef = new String(elemDef.replace('\n', ' ')); // Just for presentation
66: if (i > 0) {
67: elemDef = '\n' + elemDef;
68: }
69: ***/
70: //def.append(elemDef.replace('\n', ' ') + '\n');
71: }
72: return def.toString();
73: }
74:
75: public void parse(ITemplateDocument rootDocument) {
76: int elemNb = templateDef.size();
77: for (int i = 0; i < elemNb; i++) {
78: ITemplateElement elem = (ITemplateElement) templateDef
79: .get(i);
80: value.append(elem.getValue(rootDocument));
81: }
82: }
83:
84: public void addElement(ITemplateElement templateElement) {
85: templateDef.add(templateElement);
86: }
87: }
|