/*
 * $Id: XhtmlDomImpl.java,v 1.1.1.1 2002/09/30 15:08:51 smartine Exp $
 * Copyright (C) 1999-2000 David Brownell
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package xml.dom.xhtml;

import org.w3c.dom.*;
import org.w3c.dom.html.HTMLDocument;
import org.w3c.dom.html.HTMLDOMImplementation;
import xml.dom.*;


// $Id: XhtmlDomImpl.java,v 1.1.1.1 2002/09/30 15:08:51 smartine Exp $

/**
 * <p> XHTML subclass of "DomImplementation", supporting the HTML DOM
 * interfaces that make the most sense in the XHTML world.
 *
 * @author David Brownell 
 * @version $Date: 2002/09/30 15:08:51 $
 */
public class XhtmlDomImpl extends DomImpl implements HTMLDOMImplementation
{
    /**
     * Constructs a DOMImplementation object.
     */
    public XhtmlDomImpl () {}


    /**
     * This is the namespace URI for XHTML, as defined in the
     * 24-Nov-1999 working draft.  XHTML defines only one namespace; applicable
     * validity rules (defined in the DTD) are distinct from namespaces.  That
     * is, namespaces define only vocabularies, not policies for their usage
     * (such as precluding &lt;font ...&gt; tags in general, or in certain
     * contexts).
     */
    public static final String	xhtmlNamespace =
	   "http://www.w3.org/1999/xhtml";


    /**
     * <b>DOM L2</b>
     * Creates and returns a Document, populated only with a root element and
     * optionally a document type (if that was provided).
     */
    public Document createDocument (
	String namespaceURI,
	String rootName,
	DocumentType doctype
    ) {
	Document	doc = new XhtmlDomDocument (this);
	Element		root;
	
	root = doc.createElementNS (namespaceURI, rootName);
	if (namespaceURI != null)
	    root.setAttribute ("xmlns", namespaceURI);
	if (doctype != null)
	    doc.appendChild (doctype);
	doc.appendChild (root);
	return doc;
    }


    /**
     * <b>DOM L2 (HTML)</b>
     * Creates and returns an XHTML document object, populated with the
     * minimal "html", "head", "title", and "body" elements.  It also has
     * a namespace declaration so that the default namespace is the XHTML
     * namespace.
     */
    public HTMLDocument createHTMLDocument (String title)
    {
	HTMLDocument	retval;
	Element		temp1, temp2;
	
	retval = (HTMLDocument) createDocument (xhtmlNamespace, "html", null);

	temp1 = retval.createElementNS (xhtmlNamespace, "head");
	temp2 = retval.createElementNS (xhtmlNamespace, "title");
	temp2.appendChild (retval.createTextNode (title));
	temp1.appendChild (temp2);

	temp2 = retval.getDocumentElement ();
	temp2.appendChild (temp1);
	temp1 = retval.createElementNS (xhtmlNamespace, "body");
	temp2.appendChild (temp1);

	temp1.setAttribute ("xmlns", xhtmlNamespace);
	
	return retval;
    }
}
