Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry5.dom;
 
 import java.util.List;
 import java.util.Map;
 
The root node of a DOM.
 
 public final class Document extends Node
 {
    
XML Namespace URI. May be bound to the "xml" but must not be bound to any other prefix.
 
     public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";

    
Namespace used exclusively for defining namespaces.
 
     public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
 
     private Element rootElement;
 
     private DTD dtd;
 
     private final MarkupModel model;
 
     private final String encoding;

    
Non-element content that comes between the DOCTYPE and the root element.
 
     private List<Nodepreamble;
 
     public Document(MarkupModel model)
     {
         this(modelnull);
     }
 
     public Document(MarkupModel modelString encoding)
     {
         super(null);
 
         assert model != null;
 
         this. = model;
         this. = encoding;
     }
 
     @Override
     public Document getDocument()
     {
         return this;
     }

    
Finds an element based on a path of element names.

Parameters:
path slash separated series of element names
Returns:
the matching element, or null if not found
See also:
Element.find(java.lang.String)
 
     public Element find(String path)
     {
         assert InternalUtils.isNonBlank(path);
 
         if ( == null)
             return null;
 
         int slashx = path.indexOf("/");
 
         String rootElementName = slashx < 0 ? path : path.substring(0, slashx);
 
         if (!.getName().equals(rootElementName))
             return null;
 
         return slashx < 0 ?  : .find(path.substring(slashx + 1));
     }

    
Builds with an instance of DefaultMarkupModel.
    public Document()
    {
        this(new DefaultMarkupModel());
    }
    public MarkupModel getMarkupModel()
    {
        return ;
    }

    
Creates the root element for this document, replacing any previous root element.
    public Element newRootElement(String name)
    {
         = new Element(thisnullname);
        return ;
    }

    
Creates a new root element within a namespace.

Parameters:
namespace URI of namespace containing the element
name name of element with namespace
Returns:
the root element
    public Element newRootElement(String namespaceString name)
    {
         = new Element(thisnamespacename);
        return ;
    }
    @Override
    public void toMarkup(Document documentPrintWriter writerMap<StringStringnamespaceURIToPrefix)
    {
        if (.isXML())
        {
            writer.print("<?xml version=\"1.0\"");
            if ( != null)
                writer.printf(" encoding=\"%s\"");
            writer.print("?>\n");
        }
        if ( != null)
        {
            .toMarkup(writer);
        }
        if ( != null)
        {
            for (Node n : )
                n.toMarkup(thiswriternamespaceURIToPrefix);
        }
        if ( == null)
            return;
        Map<StringStringinitialNamespaceMap = CollectionFactory.newMap();
        initialNamespaceMap.put("xml""http://www.w3.org/XML/1998/namespace");
        initialNamespaceMap.put("xmlns""http://www.w3.org/2000/xmlns/");
        .toMarkup(documentwriterinitialNamespaceMap);
    }
    public Element getRootElement()
    {
        return ;
    }

    
Tries to find an element in this document whose id is specified.

Parameters:
id the value of the id attribute of the element being looked for
Returns:
the element if found. null if not found.
    public Element getElementById(String id)
    {
        return .getElementById(id);
    }
    public void dtd(String nameString publicIdString systemId)
    {
         = new DTD(namepublicIdsystemId);
    }
    @Override
    protected Map<StringStringgetNamespaceURIToPrefix()
    {
        if ( == null) { return Collections.emptyMap(); }
        return .getNamespaceURIToPrefix();
    }

    
Visits the root element of the document.

Parameters:
visitor callback
Since:
5.1.0.0
    void visit(Visitor visitor)
    {
        .visit(visitor);
    }
    private <T extends Node> T newChild(T child)
    {
        if ( == null)
             = CollectionFactory.newList();
        .add(child);
        return child;
    }

    
Adds the comment and returns this document for further construction.

Since:
5.1.0.0
    public Document comment(String text)
    {
        newChild(new Comment(nulltext));
        return this;
    }

    
Adds the raw text and returns this document for further construction.

Since:
5.1.0.0
    public Document raw(String text)
    {
        newChild(new Raw(nulltext));
        return this;
    }

    
Adds and returns a new text node (the text node is returned so that Text.write(java.lang.String) or [@link Text.writef(java.lang.String,java.lang.Object[]) may be invoked.

Parameters:
text initial text for the node
Returns:
the new Text node
    public Text text(String text)
    {
        return newChild(new Text(nulltext));
    }

    
Adds and returns a new CDATA node.

Parameters:
content the content to be rendered by the node
Returns:
the newly created node
    public CData cdata(String content)
    {
        return newChild(new CData(nullcontent));
    }
New to GrepCode? Check out our FAQ X