01: package com.teamkonzept.lib;
02:
03: import java.io.*;
04: import org.w3c.dom.*;
05: import com.teamkonzept.lib.TKException;
06: import com.teamkonzept.lib.templates.*;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.xml.parsers.DocumentBuilder;
09: import javax.xml.parsers.DocumentBuilderFactory;
10:
11: /**
12: * Definition der Grundmethoden eines Templates mit DOM Daten
13: * @author $Author: alex $
14: * @version $Revision: 1.3 $
15: */
16: public class DOMTemplateData implements DOMTemplateBasic {
17: /** Das Document */
18: private Document doc;
19:
20: /** Urwurzel */
21: protected Element root;
22:
23: public DOMTemplateData() throws Exception {
24: // Create document builder factory.
25: // Hack, because otherwise wrong ImplObject is set !
26: // System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");
27: DocumentBuilderFactory factory = DocumentBuilderFactory
28: .newInstance();
29:
30: // Configure document builder factory.
31: factory.setNamespaceAware(true);
32: factory.setValidating(false);
33:
34: // Create document builder and create document.
35: doc = factory.newDocumentBuilder().newDocument();
36:
37: // Create 'root' element.
38: root = doc.createElement("root");
39: doc.appendChild(root);
40: }
41:
42: public Document getDocument() {
43: return doc;
44: }
45:
46: public Element getRoot() {
47: return root;
48: }
49:
50: public Element getContentElement(String name) {
51: return getContentElement(name, root);
52: }
53:
54: public Element getContentElement(String name, Element anchor) {
55: Element me = doc.createElement(name);
56: anchor.appendChild(me);
57: return me;
58: }
59:
60: public Element getReferenceElement(String name) {
61: return getReferenceElement(name, root);
62: }
63:
64: public Element getReferenceElement(String name, Element anchor) {
65: Element me = doc.createElement(name);
66: anchor.appendChild(me);
67: return me;
68: }
69:
70: public void set(String key, Object value) {
71: root.setAttribute(key, value.toString());
72: }
73:
74: /**
75: setzt Daten in die Root
76: */
77: public void set( TKHashtable aSubst )
78: {
79: java.util.Enumeration enum = aSubst.keys();
80: while (enum.hasMoreElements())
81: {
82: Object data = enum.nextElement();
83: root.setAttribute(data.toString(), (aSubst.get(data)).toString());
84: }
85: }
86: }
|