Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
txMozillaTextOutput Class Reference

#include <txMozillaTextOutput.h>

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

List of all members.

Public Member Functions

 txMozillaTextOutput (nsIDOMDocument *aSourceDocument, nsIDOMDocument *aResultDocument, nsITransformObserver *aObserver)
 txMozillaTextOutput (nsIDOMDocumentFragment *aDest)
virtual ~txMozillaTextOutput ()
virtual void getOutputDocument (nsIDOMDocument **aDocument)=0
 Gets the Mozilla output document.
virtual void attribute (const nsAString &aName, const PRInt32 aNsID, const nsAString &aValue)=0
 Signals to receive the start of an attribute.
virtual void characters (const nsAString &aData, PRBool aDOE)=0
 Signals to receive characters.
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.
virtual void endElement (const nsAString &aName, const PRInt32 aNsID)=0
 Signals to receive the end of an element.
virtual void processingInstruction (const nsAString &aTarget, const nsAString &aData)=0
 Signals to receive a processing instruction.
virtual void startDocument ()=0
 Signals the start of a document.
virtual void startElement (const nsAString &aName, const PRInt32 aNsID)=0
 Signals to receive the start of an element.

Private Member Functions

void createResultDocument (nsIDOMDocument *aSourceDocument, nsIDOMDocument *aResultDocument)

Private Attributes

nsCOMPtr< nsIDOMCharacterDatamTextNode
nsWeakPtr mObserver
nsCOMPtr< nsIDOMDocumentmDocument
txOutputFormat mOutputFormat

Detailed Description

Definition at line 52 of file txMozillaTextOutput.h.


Constructor & Destructor Documentation

txMozillaTextOutput::txMozillaTextOutput ( nsIDOMDocument aSourceDocument,
nsIDOMDocument aResultDocument,
nsITransformObserver aObserver 
)

Definition at line 57 of file txMozillaTextOutput.cpp.

{
    mObserver = do_GetWeakReference(aObserver);
    createResultDocument(aSourceDocument, aResultDocument);
}

Here is the call graph for this function:

Definition at line 65 of file txMozillaTextOutput.cpp.

{
    nsCOMPtr<nsIDOMDocument> doc;
    aDest->GetOwnerDocument(getter_AddRefs(doc));
    NS_ASSERTION(doc, "unable to get ownerdocument");
    nsCOMPtr<nsIDOMText> textNode;
    nsresult rv = doc->CreateTextNode(EmptyString(),
                                      getter_AddRefs(textNode));
    if (NS_FAILED(rv)) {
        return;
    }
    nsCOMPtr<nsIDOMNode> dummy;
    rv = aDest->AppendChild(textNode, getter_AddRefs(dummy));
    if (NS_FAILED(rv)) {
        return;
    }

    mTextNode = textNode;
    return;
}

Here is the call graph for this function:

Definition at line 86 of file txMozillaTextOutput.cpp.

{
}

Member Function Documentation

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

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

Implemented in txHTMLOutput, and txUnknownHandler.

Here is the caller graph for this function:

virtual void txAXMLEventHandler::characters ( const nsAString &  aData,
PRBool  aDOE 
) [pure virtual, inherited]

Signals to receive characters.

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

Implemented in txHTMLOutput.

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:

void txMozillaTextOutput::createResultDocument ( nsIDOMDocument aSourceDocument,
nsIDOMDocument aResultDocument 
) [private]

Definition at line 130 of file txMozillaTextOutput.cpp.

{
    nsresult rv = NS_OK;
    
    /*
     * Create an XHTML document to hold the text.
     *
     * <html>
     *   <head />
     *   <body>
     *     <pre> * The text comes here * </pre>
     *   <body>
     * </html>
     *
     * Except if we are transforming into a non-displayed document we create
     * the following DOM
     *
     * <transformiix:result> * The text comes here * </transformiix:result>
     */
     
    nsCOMPtr<nsIDocument> doc;
    if (!aResultDocument) {
        // Create the document
        doc = do_CreateInstance(kXMLDocumentCID, &rv);
        NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create document");
        nsCOMPtr<nsIDocument_MOZILLA_1_8_BRANCH3> source =
          do_QueryInterface(aSourceDocument);
        if (!source) {
          return;
        }
        PRBool hasHadScriptObject = PR_FALSE;
        nsIScriptGlobalObject* sgo =
          source->GetScriptHandlingObject(hasHadScriptObject);
        if (!sgo && hasHadScriptObject) {
          return;
        }
        nsCOMPtr<nsIDocument_MOZILLA_1_8_BRANCH3> doc18 =
          do_QueryInterface(doc);
        if (!doc18) {
          return;
        }
        doc18->SetScriptHandlingObject(sgo);
        mDocument = do_QueryInterface(doc);
    }
    else {
        mDocument = aResultDocument;
        doc = do_QueryInterface(aResultDocument);
        NS_ASSERTION(doc, "Couldn't QI to nsIDocument");
    }

    if (!doc) {
        return;
    }

    NS_ASSERTION(mDocument, "Need document");

    nsCOMPtr<nsIDOMNSDocument> nsDoc = do_QueryInterface(mDocument);
    if (nsDoc) {
        nsDoc->SetTitle(EmptyString());
    }

    // Reset and set up document
    nsCOMPtr<nsIDocument> sourceDoc = do_QueryInterface(aSourceDocument);
    nsIPrincipal* sourcePrincipal = sourceDoc->GetPrincipal();
    if (!sourcePrincipal) {
        return;
    }

    nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();
    nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel();
    if (!channel) {
        // Need to synthesize one
        if (NS_FAILED(NS_NewChannel(getter_AddRefs(channel),
                                    sourceDoc->GetDocumentURI(),
                                    nsnull,
                                    loadGroup))) {
            return;
        }
        channel->SetOwner(sourcePrincipal);
    }
    // Copy the channel and loadgroup from the source document.
    doc->Reset(channel, loadGroup);
    doc->SetPrincipal(sourcePrincipal);
    doc->SetBaseURI(sourceDoc->GetBaseURI());

    // Set the charset
    if (!mOutputFormat.mEncoding.IsEmpty()) {
        NS_LossyConvertUTF16toASCII charset(mOutputFormat.mEncoding);
        nsCAutoString canonicalCharset;
        nsCOMPtr<nsICharsetAlias> calias =
            do_GetService("@mozilla.org/intl/charsetalias;1");

        if (calias &&
            NS_SUCCEEDED(calias->GetPreferred(charset, canonicalCharset))) {
            doc->SetDocumentCharacterSet(canonicalCharset);
            doc->SetDocumentCharacterSetSource(kCharsetFromOtherComponent);
        }
    }
    else {
        doc->SetDocumentCharacterSet(sourceDoc->GetDocumentCharacterSet());
        doc->SetDocumentCharacterSetSource(
            sourceDoc->GetDocumentCharacterSetSource());
    }

    // Notify the contentsink that the document is created
    nsCOMPtr<nsITransformObserver> observer = do_QueryReferent(mObserver);
    if (observer) {
        observer->OnDocumentCreated(mDocument);
    }

    // Create the content

    // When transforming into a non-displayed document (i.e. when there is no
    // observer) we only create a transformiix:result root element.
    // Don't do this when called through nsIXSLTProcessorObsolete (i.e. when
    // aResultDocument is set) for compability reasons
    nsCOMPtr<nsIDOMNode> textContainer;
    if (!aResultDocument && !observer) {
        nsCOMPtr<nsIDOMElement> docElement;
        mDocument->CreateElementNS(NS_LITERAL_STRING(kTXNameSpaceURI),
                                   NS_LITERAL_STRING(kTXWrapper),
                                   getter_AddRefs(docElement));
        NS_ASSERTION(docElement, "Failed to create wrapper element");
        if (!docElement) {
            return;
        }

        rv = mDocument->AppendChild(docElement, getter_AddRefs(textContainer));
        NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the wrapper element");
        if (NS_FAILED(rv)) {
            return;
        }
    }
    else {
        nsCOMPtr<nsIDOMElement> element, docElement;
        nsCOMPtr<nsIDOMNode> parent, pre;

        NS_NAMED_LITERAL_STRING(XHTML_NSURI, "http://www.w3.org/1999/xhtml");

        mDocument->CreateElementNS(XHTML_NSURI,
                                   NS_LITERAL_STRING("html"),
                                   getter_AddRefs(docElement));
        nsCOMPtr<nsIContent> rootContent = do_QueryInterface(docElement);
        NS_ASSERTION(rootContent, "Need root element");
        if (!rootContent) {
            return;
        }

        // XXXbz what to do on failure here?
        rv = doc->SetRootContent(rootContent);
        if (NS_FAILED(rv)) {
            NS_ERROR("Failed to set root content");
            return;
        }
            

        mDocument->CreateElementNS(XHTML_NSURI,
                                   NS_LITERAL_STRING("head"),
                                   getter_AddRefs(element));
        NS_ASSERTION(element, "Failed to create head element");
        if (!element) {
            return;
        }

        rv = docElement->AppendChild(element, getter_AddRefs(parent));
        NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the head element");
        if (NS_FAILED(rv)) {
            return;
        }

        mDocument->CreateElementNS(XHTML_NSURI,
                                   NS_LITERAL_STRING("body"),
                                   getter_AddRefs(element));
        NS_ASSERTION(element, "Failed to create body element");
        if (!element) {
            return;
        }

        rv = docElement->AppendChild(element, getter_AddRefs(parent));
        NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the body element");
        if (NS_FAILED(rv)) {
            return;
        }

        mDocument->CreateElementNS(XHTML_NSURI,
                                   NS_LITERAL_STRING("pre"),
                                   getter_AddRefs(element));
        NS_ASSERTION(element, "Failed to create pre element");
        if (!element) {
            return;
        }

        rv = parent->AppendChild(element, getter_AddRefs(pre));
        NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the pre element");
        if (NS_FAILED(rv)) {
            return;
        }

        nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(pre);
        htmlElement->SetId(NS_LITERAL_STRING("transformiixResult"));
        NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the id");
        
        textContainer = pre;
    }

    nsCOMPtr<nsIDOMText> textNode;
    mDocument->CreateTextNode(EmptyString(),
                              getter_AddRefs(textNode));
    NS_ASSERTION(textNode, "Failed to create the text node");
    if (!textNode) {
        return;
    }

    nsCOMPtr<nsIDOMNode> dummy;
    rv = textContainer->AppendChild(textNode, getter_AddRefs(dummy));
    NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the text node");
    if (NS_FAILED(rv)) {
        return;
    }

    mTextNode = textNode;
}

Here is the call graph for this function:

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:

virtual void txAXMLEventHandler::endElement ( const nsAString &  aName,
const PRInt32  aNsID 
) [pure virtual, inherited]

Signals to receive the end of an element.

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

Implemented in txHTMLOutput.

Here is the caller 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:

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

Signals to receive a processing instruction.

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

Implemented in txHTMLOutput.

Here is the caller graph for this function:

virtual void txAXMLEventHandler::startDocument ( ) [pure virtual, inherited]

Signals the start of a document.

Implemented in txRtfHandler, and txHTMLOutput.

Here is the caller graph for this function:

virtual void txAXMLEventHandler::startElement ( const nsAString &  aName,
const PRInt32  aNsID 
) [pure virtual, inherited]

Signals to receive the start of an element.

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

Implemented in txHTMLOutput, and txUnknownHandler.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 70 of file txMozillaTextOutput.h.

Definition at line 69 of file txMozillaTextOutput.h.

Definition at line 71 of file txMozillaTextOutput.h.

Definition at line 68 of file txMozillaTextOutput.h.


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