Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
txHTMLOutput Class Reference

#include <txHTMLOutput.h>

Inheritance diagram for txHTMLOutput:
Inheritance graph
[legend]
Collaboration diagram for txHTMLOutput:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 txHTMLOutput (txOutputFormat *aFormat, ostream *aOut)
 ~txHTMLOutput ()
void attribute (const nsAString &aName, const PRInt32 aNsID, const nsAString &aValue)
 Signals to receive the start of an attribute.
void characters (const nsAString &aData, PRBool aDOE)
 Signals to receive characters.
void endElement (const nsAString &aName, const PRInt32 aNsID)
 Signals to receive the end of an element.
void processingInstruction (const nsAString &aTarget, const nsAString &aData)
 Signals to receive a processing instruction.
void startDocument ()
 Signals the start of a document.
void startElement (const nsAString &aName, const PRInt32 aNsID)
 Signals to receive the start of an element.
virtual void getOutputDocument (nsIDOMDocument **aDocument)=0
 Gets the Mozilla output document.
virtual void comment (const nsAString &aData)=0
 Signals to receive data that should be treated as a comment.
virtual void endDocument (nsresult aResult)=0
 Signals the end of a document.

Static Public Member Functions

static nsresult init ()
 Init/release table with shorthands.
static void shutdown ()

Static Public Attributes

static const int DEFAULT_INDENT = 2

Protected Member Functions

void printUTF8Char (PRUnichar &ch)
void printUTF8Chars (const nsAString &aData)
void printWithXMLEntities (const nsAString &aData, MBool aAttribute=MB_FALSE)

Protected Attributes

ostream * mOut
txOutputFormat mOutputFormat
MBool mUseEmptyElementShorthand
MBool mHaveDocumentElement
MBool mStartTagOpen
MBool mAfterEndTag
MBool mInCDATASection
PRUint32 mIndentLevel
txList mAttributes
txStack mCDATASections

Private Member Functions

void closeStartTag (MBool aUseEmptyElementShorthand)
MBool isShorthandElement (const nsAString &aName)
MBool isShorthandAttribute (const nsAString &aLocalName)

Private Attributes

txStack mCurrentElements

Detailed Description

Definition at line 44 of file txHTMLOutput.h.


Constructor & Destructor Documentation

txHTMLOutput::txHTMLOutput ( txOutputFormat aFormat,
ostream *  aOut 
)

Definition at line 193 of file txHTMLOutput.cpp.

Definition at line 199 of file txHTMLOutput.cpp.

{
}

Member Function Documentation

void txHTMLOutput::attribute ( const nsAString &  aName,
const PRInt32  aNsID,
const nsAString &  aValue 
) [virtual]

Signals to receive the start of an attribute.

Parameters:
aNamethe name of the attribute
aNsIDthe namespace ID of the attribute
aValuethe value of the attribute

Implements txAXMLEventHandler.

Definition at line 203 of file txHTMLOutput.cpp.

{
    if (!mStartTagOpen)
        // XXX Signal this? (can't add attributes after element closed)
        return;

    MBool shortHand = MB_FALSE;
    if (aNsID == kNameSpaceID_None) {
        const nsAString& localPart = XMLUtils::getLocalPart(aName);
        shortHand = isShorthandAttribute(localPart);
        if (shortHand &&
            localPart.Equals(aValue, txCaseInsensitiveStringComparator())) {
            txListIterator iter(&mAttributes);
            txOutAttr* setAtt = 0;
            nsCOMPtr<nsIAtom> localName = do_GetAtom(localPart);
            txExpandedName att(aNsID, localName);
            while ((setAtt = (txOutAttr*)iter.next())) {
                 if (setAtt->mName == att) {
                     setAtt->mShorthand = MB_TRUE;
                     break;
                 }
            }
            if (!setAtt) {
                setAtt = new txOutAttr(aNsID, localName, EmptyString());
                setAtt->mShorthand = MB_TRUE;
                mAttributes.add(setAtt);
            }
        }
    }
    if (!shortHand)
        txXMLOutput::attribute(aName, aNsID, aValue);
}

Here is the call graph for this function:

void txHTMLOutput::characters ( const nsAString &  aData,
PRBool  aDOE 
) [virtual]

Signals to receive characters.

Parameters:
aDatathe characters to receive
aDOEdisable output escaping for these characters

Implements txAXMLEventHandler.

Definition at line 238 of file txHTMLOutput.cpp.

{
    if (aDOE) {
        closeStartTag(MB_FALSE);
        printUTF8Chars(aData);

        return;
    }

    // Special-case script and style
    if (!mCurrentElements.isEmpty()) {
        txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
        if (currentElement->mNamespaceID == kNameSpaceID_None &&
            (currentElement->mLocalName == txHTMLAtoms::script ||
             currentElement->mLocalName == txHTMLAtoms::style)) {
            closeStartTag(MB_FALSE);
            printUTF8Chars(aData);
            return;
        }
    }
    txXMLOutput::characters(aData, aDOE);
}

Here is the call graph for this function:

void txHTMLOutput::closeStartTag ( MBool  aUseEmptyElementShorthand) [private, virtual]

Reimplemented from txXMLOutput.

Definition at line 329 of file txHTMLOutput.cpp.

{
    txExpandedName* currentElement = mCurrentElements.isEmpty() ?
        nsnull : (txExpandedName*)mCurrentElements.peek();
    if (mStartTagOpen && currentElement &&
        (currentElement->mNamespaceID == kNameSpaceID_None) &&
        (currentElement->mLocalName == txHTMLAtoms::head)) {
        txXMLOutput::closeStartTag(MB_FALSE);
        if (mOutputFormat.mIndent == eTrue) {
            *mOut << endl;
            for (PRUint32 i = 0; i < mIndentLevel; i++)
                *mOut << ' ';
        }
        *mOut << LT << "meta http-equiv=" << QUOTE << "Content-Type" << QUOTE;
        *mOut << " content=" << QUOTE;
        printUTF8Chars(mOutputFormat.mMediaType);
        *mOut << "; charset=";
        printUTF8Chars(mOutputFormat.mEncoding);
        *mOut << QUOTE << GT;
    }
    else {
        txXMLOutput::closeStartTag(aUseEmptyElementShorthand);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void txAXMLEventHandler::comment ( const nsAString &  aData) [pure virtual, inherited]

Signals to receive data that should be treated as a comment.

Parameters:
datathe comment data to receive

Here is the caller graph for this function:

virtual void txAXMLEventHandler::endDocument ( nsresult  aResult) [pure virtual, inherited]

Signals the end of a document.

It is an error to call this method more than once.

Implemented in txRtfHandler, and txUnknownHandler.

Here is the caller graph for this function:

void txHTMLOutput::endElement ( const nsAString &  aName,
const PRInt32  aNsID 
) [virtual]

Signals to receive the end of an element.

Parameters:
aNamethe name of the element
aNsIDthe namespace ID of the element

Implements txAXMLEventHandler.

Definition at line 261 of file txHTMLOutput.cpp.

{
    const nsAString& localPart = XMLUtils::getLocalPart(aName);
    if ((aNsID == kNameSpaceID_None) && isShorthandElement(localPart) &&
        mStartTagOpen) {
        MBool newLine = (mOutputFormat.mIndent == eTrue) &&
                        mAfterEndTag;
        closeStartTag(MB_FALSE);
        if (newLine)
            *mOut << endl;
        if (mOutputFormat.mIndent == eTrue)
            mIndentLevel -= DEFAULT_INDENT;
        mAfterEndTag = MB_TRUE;
    }
    else {
        txXMLOutput::endElement(aName, aNsID);
    }
    delete (txExpandedName*)mCurrentElements.pop();
}

Here is the call graph for this function:

virtual void txAOutputXMLEventHandler::getOutputDocument ( nsIDOMDocument **  aDocument) [pure virtual, inherited]

Gets the Mozilla output document.

Parameters:
aDocumentthe Mozilla output document

Here is the caller graph for this function:

Init/release table with shorthands.

Definition at line 95 of file txHTMLOutput.cpp.

{
    if (0 == gTableRefCount++) {
        NS_ASSERTION(!gHTMLEmptyTagsTable, "pre existing array!");
        gHTMLEmptyTagsTable = new nsStaticCaseInsensitiveNameTable();
        if (!gHTMLEmptyTagsTable) {
            return NS_ERROR_OUT_OF_MEMORY;
        }

        gHTMLEmptyTagsTable->Init(kHTMLEmptyTags, EMPTY_ELEMENTS_COUNT);

        NS_ASSERTION(!gHTMLEmptyAttributesTable, "pre existing array!");
        gHTMLEmptyAttributesTable = new nsStaticCaseInsensitiveNameTable();
        if (!gHTMLEmptyAttributesTable) {
            return NS_ERROR_OUT_OF_MEMORY;
        }

        gHTMLEmptyAttributesTable->Init(kHTMLEmptyAttributes,
                                        SHORTHAND_ATTR_COUNT);

        NS_ASSERTION(!gHTMLEmptyAttributesMaps, "pre existing map!");
        gHTMLEmptyAttributesMaps = new txEmptyAttributesMaps();
        if (!gHTMLEmptyAttributesMaps) {
            return NS_ERROR_OUT_OF_MEMORY;
        }

        // checked
        gHTMLEmptyAttributesMaps->mMaps[0].AppendObject(txHTMLAtoms::input);

        // compact
        gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::dir);
        gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::dl);
        gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::menu);
        gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::ol);
        gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::ul);

        // declare
        gHTMLEmptyAttributesMaps->mMaps[2].AppendObject(txHTMLAtoms::object);

        // defer
        gHTMLEmptyAttributesMaps->mMaps[3].AppendObject(txHTMLAtoms::script);

        // disabled
        gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::button);
        gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::input);
        gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::optgroup);
        gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::option);
        gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::select);
        gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::textarea);

        // ismap
        gHTMLEmptyAttributesMaps->mMaps[5].AppendObject(txHTMLAtoms::img);
        gHTMLEmptyAttributesMaps->mMaps[5].AppendObject(txHTMLAtoms::input);

        // multiple
        gHTMLEmptyAttributesMaps->mMaps[6].AppendObject(txHTMLAtoms::select);

        // noresize
        gHTMLEmptyAttributesMaps->mMaps[7].AppendObject(txHTMLAtoms::frame);

        // noshade
        gHTMLEmptyAttributesMaps->mMaps[8].AppendObject(txHTMLAtoms::hr);

        // nowrap
        gHTMLEmptyAttributesMaps->mMaps[9].AppendObject(txHTMLAtoms::td);
        gHTMLEmptyAttributesMaps->mMaps[9].AppendObject(txHTMLAtoms::th);

        // readonly
        gHTMLEmptyAttributesMaps->mMaps[10].AppendObject(txHTMLAtoms::input);
        gHTMLEmptyAttributesMaps->mMaps[10].AppendObject(txHTMLAtoms::textarea);

        // selected
        gHTMLEmptyAttributesMaps->mMaps[11].AppendObject(txHTMLAtoms::option);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

MBool txHTMLOutput::isShorthandAttribute ( const nsAString &  aLocalName) [private]

Definition at line 360 of file txHTMLOutput.cpp.

{
    PRInt32 index = gHTMLEmptyTagsTable->Lookup(aLocalName);
    if (index == nsStaticCaseInsensitiveNameTable::NOT_FOUND) {
        return PR_FALSE;
    }

    txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
    return (gHTMLEmptyAttributesMaps->mMaps[index].IndexOf(currentElement->mLocalName) > -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

MBool txHTMLOutput::isShorthandElement ( const nsAString &  aName) [private]

Definition at line 354 of file txHTMLOutput.cpp.

{
    return (gHTMLEmptyTagsTable->Lookup(aLocalName) !=
            nsStaticCaseInsensitiveNameTable::NOT_FOUND);
}

Here is the caller graph for this function:

void txXMLOutput::printUTF8Char ( PRUnichar ch) [protected, inherited]

Definition at line 284 of file txXMLOutput.cpp.

{
    // PRUnichar is 16-bits so we only need to cover up to 0xFFFF

    // 0x0000-0x007F
    if (ch < 128) {
        *mOut << (char)ch;
    }
    // 0x0080-0x07FF
    else if (ch < 2048) {
        *mOut << (char) (192+(ch/64));        // 0xC0 + x/64
        *mOut << (char) (128+(ch%64));        // 0x80 + x%64
    }
    // 0x800-0xFFFF
    else {
        *mOut << (char) (224+(ch/4096));      // 0xE0 + x/64^2
        *mOut << (char) (128+((ch/64)%64));   // 0x80 + (x/64)%64
        *mOut << (char) (128+(ch%64));        // 0x80 + x%64
    }
}

Here is the caller graph for this function:

void txXMLOutput::printUTF8Chars ( const nsAString &  aData) [protected, inherited]

Definition at line 305 of file txXMLOutput.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void txXMLOutput::printWithXMLEntities ( const nsAString &  aData,
MBool  aAttribute = MB_FALSE 
) [protected, inherited]

Definition at line 310 of file txXMLOutput.cpp.

{
    nsAString::const_iterator iter, end;
    aData.EndReading(end);

    for (aData.BeginReading(iter); iter != end; ++iter) {
        PRUnichar currChar = *iter;
        switch (currChar) {
            case AMPERSAND:
                *mOut << AMP_ENTITY;
                break;
            case APOSTROPHE:
                if (aAttribute)
                    *mOut << APOS_ENTITY;
                else
                    printUTF8Char(currChar);
                break;
            case GT:
                *mOut << GT_ENTITY;
                break;
            case LT:
                *mOut << LT_ENTITY;
                break;
            case QUOTE:
                if (aAttribute)
                    *mOut << QUOT_ENTITY;
                else
                    printUTF8Char(currChar);
                break;
            default:
                printUTF8Char(currChar);
                break;
        }
    }
    *mOut << flush;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void txHTMLOutput::processingInstruction ( const nsAString &  aTarget,
const nsAString &  aData 
) [virtual]

Signals to receive a processing instruction.

Parameters:
aTargetthe target of the processing instruction
aDatathe data of the processing instruction

Implements txAXMLEventHandler.

Definition at line 282 of file txHTMLOutput.cpp.

Here is the call graph for this function:

Signals the start of a document.

Implements txAXMLEventHandler.

Definition at line 299 of file txHTMLOutput.cpp.

{
    // XXX Should be using mOutputFormat.getVersion
    *mOut << DOCTYPE_START << "html " << PUBLIC;
    *mOut << " \"-//W3C//DTD HTML 4.0 Transitional//EN\"";
    *mOut << " \"http://www.w3.org/TR/REC-html40/loose.dtd\"";
    *mOut << DOCTYPE_END << endl;
}
void txHTMLOutput::startElement ( const nsAString &  aName,
const PRInt32  aNsID 
) [virtual]

Signals to receive the start of an element.

Parameters:
aNamethe name of the element
aNsIDthe namespace ID of the element

Implements txAXMLEventHandler.

Definition at line 308 of file txHTMLOutput.cpp.

{
    txXMLOutput::startElement(aName, aNsID);

    nsCOMPtr<nsIAtom> localAtom;
    if (aNsID == kNameSpaceID_None) {
        nsAutoString localName;
        TX_ToLowerCase(aName, localName);
        localAtom = do_GetAtom(localName);
    }
    else {
        localAtom = do_GetAtom(aName);
    }
    NS_ASSERTION(localAtom, "Can't get atom");
    txExpandedName* currentElement = new txExpandedName(aNsID, localAtom);
    NS_ASSERTION(currentElement, "Can't create currentElement");
    if (currentElement)
        mCurrentElements.push(currentElement);
}

Here is the call graph for this function:


Member Data Documentation

const int txXMLOutput::DEFAULT_INDENT = 2 [static, inherited]

Definition at line 99 of file txXMLOutput.h.

MBool txXMLOutput::mAfterEndTag [protected, inherited]

Definition at line 116 of file txXMLOutput.h.

txList txXMLOutput::mAttributes [protected, inherited]

Definition at line 119 of file txXMLOutput.h.

txStack txXMLOutput::mCDATASections [protected, inherited]

Definition at line 120 of file txXMLOutput.h.

Definition at line 71 of file txHTMLOutput.h.

MBool txXMLOutput::mHaveDocumentElement [protected, inherited]

Definition at line 114 of file txXMLOutput.h.

MBool txXMLOutput::mInCDATASection [protected, inherited]

Definition at line 117 of file txXMLOutput.h.

PRUint32 txXMLOutput::mIndentLevel [protected, inherited]

Definition at line 118 of file txXMLOutput.h.

ostream* txXMLOutput::mOut [protected, inherited]

Definition at line 111 of file txXMLOutput.h.

Definition at line 112 of file txXMLOutput.h.

MBool txXMLOutput::mStartTagOpen [protected, inherited]

Definition at line 115 of file txXMLOutput.h.

Definition at line 113 of file txXMLOutput.h.


The documentation for this class was generated from the following files: