01: package fr.aliacom.form.swt;
02:
03: import org.apache.log4j.Logger;
04: import org.w3c.dom.Element;
05: import org.w3c.dom.Node;
06: import org.w3c.dom.NodeList;
07:
08: import fr.aliacom.form.common.FormLoader;
09: import fr.aliacom.form.common.IFormComponent;
10:
11: /**
12: * @author tom
13: *
14: * (C) 2001, 2002 Thomas Cataldo
15: */
16: public abstract class SWTBuilder {
17:
18: protected Logger log;
19:
20: public SWTBuilder() {
21: log = Logger.getLogger(getClass());
22: }
23:
24: /**
25: * Method build.
26: * @param elem
27: * @param parent
28: * @param loader
29: * @param factory
30: * @return FormComponent
31: */
32: public abstract IFormComponent build(Element elem,
33: IFormComponent parent, FormLoader loader,
34: BuilderFactory factory);
35:
36: /**
37: * Method buildChildren.
38: * @param elem
39: * @param parent
40: * @param loader
41: * @param factory
42: */
43: protected void buildChildren(Element elem, IFormComponent parent,
44: FormLoader loader, BuilderFactory factory) {
45: NodeList list = elem.getChildNodes();
46: for (int i = 0, n = list.getLength(); i < n; i++) {
47: Node node = list.item(i);
48: if (node.getNodeType() == Node.ELEMENT_NODE) {
49: SWTBuilder builder = factory.getBuilder(node
50: .getNodeName());
51: Element elementNode = (Element) node;
52: IFormComponent ret = builder.build(elementNode, parent,
53: loader, factory);
54: if (elementNode.hasAttribute("id")) {
55: loader.getCtx().addVariable(
56: elementNode.getAttribute("id"), ret);
57: }
58: }
59: }
60: }
61:
62: private final String fullTrim(String s) {
63: return s.replace('\n', ' ').trim();
64: }
65:
66: protected String getNodeText(Element elem) {
67: return fullTrim(elem.getChildNodes().item(0).getNodeValue());
68: }
69:
70: }
|