/*
* JDynamiTe - Dynamic Template in Java
* Copyright (C) 2001 Christophe Bouleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package cb.jdynamite.analyser;
import java.util.ArrayList;
import cb.jdynamite.ITemplateDocument;
public class DefaultDynamicElement implements ITemplateElement, IDynamicElement {
private StringBuffer value;
private ArrayList templateDef;
private String name; // just for debug
public DefaultDynamicElement() {
templateDef = new ArrayList();
value = new StringBuffer();
}
public DefaultDynamicElement(String elementName) {
this();
name = elementName;
}
public String getValue(ITemplateDocument rootDocument) {
return value.toString();
}
public void setValue(String arbitraryValue) {
value.delete(0, value.length());
if (arbitraryValue != null) {
value.append(arbitraryValue);
}
}
public String getDefinition(int depth) {
StringBuffer def = new StringBuffer();
for (int indent = 0; indent < depth; indent++) {
def.append(" ");
}
def.append("DefaultDynamicElement \"" + name + "\":\n");
int elemNb = templateDef.size();
for (int i = 0; i < elemNb; i++) {
ITemplateElement elem = (ITemplateElement)templateDef.get(i);
def.append(elem.getDefinition(depth + 1));
//String elemDef = elem.getDefinition(depth + 1);
/***
elemDef = new String(elemDef.replace('\n', ' ')); // Just for presentation
if (i > 0) {
elemDef = '\n' + elemDef;
}
***/
//def.append(elemDef.replace('\n', ' ') + '\n');
}
return def.toString();
}
public void parse(ITemplateDocument rootDocument) {
int elemNb = templateDef.size();
for (int i = 0; i < elemNb; i++) {
ITemplateElement elem = (ITemplateElement)templateDef.get(i);
value.append(elem.getValue(rootDocument));
}
}
public void addElement(ITemplateElement templateElement) {
templateDef.add(templateElement);
}
}
|