FileDocCategorySizeDatePackage
HTMLDocument.javaAPI DocAndroid 1.5 API5376Wed May 06 22:41:16 BST 2009com.vladium.emma.report.html.doc

HTMLDocument

public final class HTMLDocument extends IElement.Factory.ElementImpl
author
Vlad Roubtsov, (C) 2003

Fields Summary
private final String
m_title
private final IElement
m_head
private final IElement
m_body
private IContent
m_header
private IContent
m_footer
Constructors Summary
public HTMLDocument()

        this (null, null);
    
public HTMLDocument(String title, String encoding)

        super (Tag.HTML, AttributeSet.create ());
        
        super.add (m_head = IElement.Factory.create (Tag.HEAD));
        super.add (m_body = IElement.Factory.create (Tag.BODY));

        // specify encoding META before anything else:
        if ((encoding != null) && (encoding.length () != 0))
        {
            final ISimpleElement meta = ISimpleElement.Factory.create (Tag.META);
            
            meta.getAttributes ()
            .set (Attribute.HTTP_EQUIV, "Content-Type")
            .set (Attribute.CONTENT, "text/html; charset=" + encoding);
            
            m_head.add (meta);
        }
        
        if (title != null)
        {
            // TODO: escape
            //getAttributes ().set (Attribute.TITLE, title);
            
            final IElement titleElement = IElement.Factory.create (Tag.TITLE).setText (title, false);
            m_head.add (titleElement);            
        }
        
        m_title = title;
    
Methods Summary
public IElementListadd(IContent content)
Overridden to add to the doc body.

        m_body.add (content);
        
        return this;
    
public voidaddEmptyP()

        add (IElement.Factory.create (Tag.P));
    
public voidaddH(int level, java.lang.String text, java.lang.String classID)

        final Tag Hl = Tag.Hs [level];
        
        final IElement h = IElement.Factory.create (Hl);
        h.setText (text, true);
        h.setClass (classID);
         
        add (h);
    
public voidaddH(int level, IContent text, java.lang.String classID)

        final Tag Hl = Tag.Hs [level];
        
        final IElement h = IElement.Factory.create (Hl);
        h.add (text);
        h.setClass (classID);
         
        add (h);
    
public voidaddHR(int size)

        final IElement hr = IElement.Factory.create (Tag.HR);
        hr.getAttributes ().set (Attribute.SIZE, size);
        
        add (hr);
    
public voidaddLINK(java.lang.String type, java.lang.String href)
Adds a <LINK> to the head.

        final ISimpleElement link = ISimpleElement.Factory.create (Tag.LINK);
        
        // TODO: add REL="STYLESHEET"
        
        link.getAttributes ().set (Attribute.TYPE, type); // TODO: escape
        link.getAttributes ().set (Attribute.HREF, href); // TODO: escape
        link.getAttributes ().set (Attribute.SRC, href); // TODO: escape
        
        m_head.add (link);
    
public voidaddStyle(java.lang.String css)

        if (css != null)
        {
            final IElement style = IElement.Factory.create (Tag.STYLE);
            style.getAttributes ().set (Attribute.TYPE, "text/css");
            
            final StringBuffer def = new StringBuffer ("<!--");
            def.append (IConstants.EOL);
            
            style.setText (css, false);
            
            def.append (IConstants.EOL);
            def.append ("-->");
            
            m_head.add (style);
        }
    
public voidemit(HTMLWriter out)
Overridden to ensure header/footer appear first/last in the body.

        if (m_header != null) m_body.add (0, m_header);
        if (m_footer != null) m_body.add (m_body.size (), m_footer);
            
        super.emit(out);
    
public IElementgetBody()

        return m_body;
    
public IContentgetFooter()

        return m_footer;
    
public IElementgetHead()

        return m_head; 
    
public IContentgetHeader()

        return m_header;
    
public java.lang.StringgetTitle()

        return m_title;
    
public voidsetFooter(IContent footer)

        if (footer != null) m_footer = footer;
    
public voidsetHeader(IContent header)

        if (header != null) m_header = header;