DOMTemplateData.java :  » Content-Management-System » webman » com » teamkonzept » lib » Java Open Source

Java Open Source » Content Management System » webman 
webman » com » teamkonzept » lib » DOMTemplateData.java
package com.teamkonzept.lib;

import java.io.*;
import org.w3c.dom.*;
import com.teamkonzept.lib.TKException;
import com.teamkonzept.lib.templates.*;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

/**
 * Definition der Grundmethoden eines Templates mit DOM Daten
 * @author  $Author: alex $
 * @version $Revision: 1.3 $
 */
public class DOMTemplateData implements DOMTemplateBasic
{
  /** Das Document */
  private Document doc;
  
  /** Urwurzel */
  protected Element root;
    
    
    public DOMTemplateData() throws Exception
    {
    // Create document builder factory.
    // Hack, because otherwise wrong ImplObject is set !
    // System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    // Configure document builder factory.
    factory.setNamespaceAware(true);
    factory.setValidating(false);

    // Create document builder and create document.
        doc = factory.newDocumentBuilder().newDocument();

        // Create 'root' element.
        root = doc.createElement("root");
        doc.appendChild(root);
    }
    
  public Document getDocument()
  {
    return doc;
  }
  
  public Element getRoot()
  {
    return root;
  }
  
  public Element getContentElement(String name)
  {
    return getContentElement(name, root);
  }
  
  public Element getContentElement(String name, Element anchor)
  {
    Element me = doc.createElement(name);
    anchor.appendChild(me);    
    return me;
  }
  
  public Element getReferenceElement(String name)
  {
    return getReferenceElement(name, root);
  }
    
  public Element getReferenceElement(String name, Element anchor)
  {
    Element me = doc.createElement(name);
    anchor.appendChild(me);
    return me;
  }
 
  public void set(String key, Object value)
  {
    root.setAttribute(key, value.toString());
  }
  
  /**
    setzt Daten in die Root
  */
  public void set( TKHashtable aSubst )
  {
    java.util.Enumeration enum = aSubst.keys();
    while (enum.hasMoreElements())
    {
      Object data = enum.nextElement();
      root.setAttribute(data.toString(), (aSubst.get(data)).toString());
    }
  }
}


java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.