Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
txXPathNodeUtils Class Reference

#include <txXPathTreeWalker.h>

List of all members.

Static Public Member Functions

static PRBool getAttr (const txXPathNode &aNode, nsIAtom *aLocalName, PRInt32 aNSID, nsAString &aValue)
static already_AddRefed< nsIAtomgetLocalName (const txXPathNode &aNode)
static void getLocalName (const txXPathNode &aNode, nsAString &aLocalName)
static void getNodeName (const txXPathNode &aNode, nsAString &aName)
static PRInt32 getNamespaceID (const txXPathNode &aNode)
static void getNamespaceURI (const txXPathNode &aNode, nsAString &aURI)
static PRUint16 getNodeType (const txXPathNode &aNode)
static void appendNodeValue (const txXPathNode &aNode, nsAString &aResult)
static PRBool isWhitespace (const txXPathNode &aNode)
static txXPathNodegetDocument (const txXPathNode &aNode)
static txXPathNodegetOwnerDocument (const txXPathNode &aNode)
static PRInt32 getUniqueIdentifier (const txXPathNode &aNode)
static nsresult getXSLTId (const txXPathNode &aNode, nsAString &aResult)
static void release (txXPathNode *aNode)
static void getBaseURI (const txXPathNode &aNode, nsAString &aURI)
static PRIntn comparePosition (const txXPathNode &aNode, const txXPathNode &aOtherNode)
static PRBool localNameEquals (const txXPathNode &aNode, nsIAtom *aLocalName)
static PRBool isRoot (const txXPathNode &aNode)
static PRBool isElement (const txXPathNode &aNode)
static PRBool isAttribute (const txXPathNode &aNode)
static PRBool isProcessingInstruction (const txXPathNode &aNode)
static PRBool isComment (const txXPathNode &aNode)
static PRBool isText (const txXPathNode &aNode)

Detailed Description

Definition at line 111 of file txXPathTreeWalker.h.


Member Function Documentation

void txXPathNodeUtils::appendNodeValue ( const txXPathNode aNode,
nsAString &  aResult 
) [static]

Definition at line 575 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isAttribute()) {
        nsCOMPtr<nsIAtom> name, prefix;
        PRInt32 namespaceID;
        aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID,
                                      getter_AddRefs(name),
                                      getter_AddRefs(prefix));

        nsAutoString result;
        aNode.mContent->GetAttr(namespaceID, name, result);
        aResult.Append(result);

        return;
    }

    if (aNode.isDocument()) {
        nsIContent* content = aNode.mDocument->GetRootContent();
        if (content) {
            appendTextContent(content, aResult);
        }

        return;
    }

    if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) {
        appendTextContent(aNode.mContent, aResult);

        return;
    }

    if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) {
        nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode.mContent);

        nsAutoString result;
        node->GetNodeValue(result);
        aResult.Append(result);

        return;
    }

    nsCOMPtr<nsITextContent> textContent = do_QueryInterface(aNode.mContent);
    if (!textContent) {
        NS_ERROR("Unexpected nodetype.");

        return;
    }

    textContent->AppendTextTo(aResult);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRIntn txXPathNodeUtils::comparePosition ( const txXPathNode aNode,
const txXPathNode aOtherNode 
) [static]

Definition at line 729 of file txMozillaXPathTreeWalker.cpp.

{
    // First check for equal nodes or attribute-nodes on the same element.
    if (aNode.mContent == aOtherNode.mContent) {
        if (aNode.mIndex == aOtherNode.mIndex) {
            return 0;
        }

        if (aNode.isContent() || (!aOtherNode.isContent() &&
                                  aNode.mIndex < aOtherNode.mIndex)) {
            return -1;
        }

        return 1;
    }

    // Get document for both nodes.
    nsIDocument* document = aNode.isDocument() ?
                            aNode.mDocument :
                            aNode.mContent->GetDocument();

    nsIDocument* otherDocument = aOtherNode.isDocument() ?
                                 aOtherNode.mDocument :
                                 aOtherNode.mContent->GetDocument();

    // If the nodes have different ownerdocuments, compare the document
    // pointers.
    if (document && otherDocument && document != otherDocument) {
        return document > otherDocument ? 1 : -1;
    }

    // Every node comes after its ownerdocument.
    if (aNode.isDocument()) {
        return -1;
    }

    if (aOtherNode.isDocument()) {
        return 1;
    }

    // Get parents up the tree.
    nsAutoVoidArray parents, otherParents;
    nsIContent* content = aNode.mContent;
    nsIContent* otherContent = aOtherNode.mContent;
    nsIContent* parent, *otherParent;
    PRInt32 index, otherIndex;
    while (content && otherContent) {
        parent = content->GetParent();
        otherParent = otherContent->GetParent();

        // Hopefully this is a common case.
        if (parent == otherParent) {
            if (parent) {
                index = (PRUint32)parent->IndexOf(content);
                otherIndex = (PRUint32)parent->IndexOf(otherContent);
            }
            else {
                if (!document) {
                    if (!otherDocument) {
                        // Neither aNode nor aOtherNode are not in a document,
                        // compare their top ancestors.
                        return content > otherContent ? 1 : -1;
                    }

                    // aNode is not in the tree, compare its top ancestor with
                    // aOtherNode's document.
                    return (void*)content > (void*)otherDocument ? 1 : -1;
                }
                else if (!otherDocument) {
                    // aOtherNode is not in a document, compare its top
                    // ancestor with aNode's document.
                    return (void*)document > (void*)otherContent ? 1 : -1;
                }

                // Both nodes are in the same document.
                index = (PRUint32)document->IndexOf(content);
                otherIndex = (PRUint32)document->IndexOf(otherContent);
            }

            return index < otherIndex ? -1 : 1;
        }

        parents.AppendElement(content);
        otherParents.AppendElement(otherContent);
        content = parent;
        otherContent = otherParent;
    }

    while (content) {
        parents.AppendElement(content);
        content = content->GetParent();
    }
    while (otherContent) {
        otherParents.AppendElement(otherContent);
        otherContent = otherContent->GetParent();
    }

    if (!document) {
        if (!otherDocument) {
            // Neither aNode nor aOtherNode are not in a document, compare
            // their top ancestors.
            return parents.ElementAt(parents.Count() - 1) >
                   otherParents.ElementAt(otherParents.Count() - 1) ? 1 : -1;
        }

        // aNode is not in the tree, compare its top ancestor with aOtherNode's
        // document.
        return parents.ElementAt(parents.Count() - 1) > otherDocument ? 1 : -1;
    }
    else if (!otherDocument) {
        // aOtherNode is not in a document, compare its top
        // ancestor with aNode's document.
        return document >
               otherParents.ElementAt(otherParents.Count() - 1) ? 1 : -1;
    }

    // Walk back down along the parent-chains until we find where they split.
    PRInt32 total = parents.Count() - 1;
    PRInt32 otherTotal = otherParents.Count() - 1;
    NS_ASSERTION(total != otherTotal, "Can't have same number of parents");

    PRInt32 lastIndex = PR_MIN(total, otherTotal);
    PRInt32 i;
    parent = nsnull;
    for (i = 0; i <= lastIndex; ++i) {
        content = NS_STATIC_CAST(nsIContent*, parents.ElementAt(total - i));
        otherContent = NS_STATIC_CAST(nsIContent*,
                                      otherParents.ElementAt(otherTotal - i));
        if (content != otherContent) {
            if (parent) {
                index = (PRUint32)parent->IndexOf(content);
                otherIndex = (PRUint32)parent->IndexOf(otherContent);
            }
            else {
                index = (PRUint32)document->IndexOf(content);
                otherIndex = (PRUint32)document->IndexOf(otherContent);
            }
            NS_ASSERTION(index != otherIndex && index >= 0 && otherIndex >= 0,
                         "invalid index in compareTreePosition");
            return index < otherIndex ? -1 : 1;
        }

        parent = content;
    }

    // One node is a descendant of the other. The one with the shortest
    // parent-chain is first in the document.
    return total < otherTotal ? -1 : 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool txXPathNodeUtils::getAttr ( const txXPathNode aNode,
nsIAtom aLocalName,
PRInt32  aNSID,
nsAString &  aValue 
) [static]

Definition at line 348 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument() || aNode.isAttribute()) {
        return PR_FALSE;
    }

    nsresult rv = aNode.mContent->GetAttr(aNSID, aLocalName, aValue);
    return NS_SUCCEEDED(rv) && rv != NS_CONTENT_ATTR_NOT_THERE;
}

Here is the call graph for this function:

void txXPathNodeUtils::getBaseURI ( const txXPathNode aNode,
nsAString &  aURI 
) [static]

Definition at line 709 of file txMozillaXPathTreeWalker.cpp.

{
    nsCOMPtr<nsIDOM3Node> node;
    if (aNode.isDocument()) {
        node = do_QueryInterface(aNode.mDocument);
    }
    else {
        node = do_QueryInterface(aNode.mContent);
    }

    if (node) {
        node->GetBaseURI(aURI);
    }
    else {
        aURI.Truncate();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 641 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        return new txXPathNode(aNode);
    }

    nsIDocument* document = aNode.mContent->GetDocument();
    return document ? new txXPathNode(document) : nsnull;
}

Here is the call graph for this function:

Definition at line 361 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        return nsnull;
    }

    if (aNode.isContent()) {
        if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) {
            nsIAtom* localName = aNode.mContent->Tag();
            NS_ADDREF(localName);

            return localName;
        }

        if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) {
            nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode.mContent);
            nsAutoString target;
            node->GetNodeName(target);

            return NS_NewAtom(target);
        }

        return nsnull;
    }

    nsIAtom* localName;
    nsCOMPtr<nsIAtom> prefix;
    PRInt32 namespaceID;
    aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, &localName,
                                  getter_AddRefs(prefix));

    return localName;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void txXPathNodeUtils::getLocalName ( const txXPathNode aNode,
nsAString &  aLocalName 
) [static]

Definition at line 397 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        aLocalName.Truncate();

        return;
    }

    if (aNode.isContent()) {
        nsINodeInfo* nodeInfo = aNode.mContent->GetNodeInfo();
        if (nodeInfo) {
            nodeInfo->GetLocalName(aLocalName);

            // Check for html
            if (nodeInfo->NamespaceEquals(kNameSpaceID_None) &&
                aNode.mContent->IsContentOfType(nsIContent::eHTML)) {
                ToUpperCase(aLocalName);
            }

            return;
        }

        if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) {
            // PIs don't have a nodeinfo but do have a name
            nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode.mContent);
            node->GetNodeName(aLocalName);

            return;
        }

        aLocalName.Truncate();

        return;
    }

    nsCOMPtr<nsIAtom> prefix, localName;
    PRInt32 namespaceID;
    aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID,
                                  getter_AddRefs(localName),
                                  getter_AddRefs(prefix));
    localName->ToString(aLocalName);

    // Check for html
    if (aNode.mContent->GetNodeInfo()->NamespaceEquals(kNameSpaceID_None) &&
        aNode.mContent->IsContentOfType(nsIContent::eHTML)) {
        ToUpperCase(aLocalName);
    }
}

Here is the call graph for this function:

Definition at line 511 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        return kNameSpaceID_None;
    }

    if (aNode.isContent()) {
        nsINodeInfo* ni = aNode.mContent->GetNodeInfo();

        return ni ? ni->NamespaceID() : kNameSpaceID_None;
    }

    nsCOMPtr<nsIAtom> name, prefix;
    PRInt32 namespaceID;
    aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID,
                                  getter_AddRefs(name),
                                  getter_AddRefs(prefix));
    return namespaceID;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void txXPathNodeUtils::getNamespaceURI ( const txXPathNode aNode,
nsAString &  aURI 
) [static]

Definition at line 533 of file txMozillaXPathTreeWalker.cpp.

Here is the call graph for this function:

void txXPathNodeUtils::getNodeName ( const txXPathNode aNode,
nsAString &  aName 
) [static]

Definition at line 448 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        aName.Truncate();

        return;
    }

    if (aNode.isContent()) {
        nsINodeInfo* nodeInfo = aNode.mContent->GetNodeInfo();
        if (nodeInfo) {
            nodeInfo->GetQualifiedName(aName);

            // Check for html
            if (nodeInfo->NamespaceEquals(kNameSpaceID_None) &&
                aNode.mContent->IsContentOfType(nsIContent::eHTML)) {
                ToUpperCase(aName);
            }

            return;
        }

        if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) {
            // PIs don't have a nodeinfo but do have a name
            nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode.mContent);
            node->GetNodeName(aName);

            return;
        }

        aName.Truncate();

        return;
    }

    nsCOMPtr<nsIAtom> name, prefix;
    PRInt32 namespaceID;
    aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID,
                                  getter_AddRefs(name),
                                  getter_AddRefs(prefix));


    if (prefix) {
        prefix->ToString(aName);
        aName.Append(PRUnichar(':'));
    }
    else {
        aName.Truncate();
    }

    const char* attrName;
    name->GetUTF8String(&attrName);
    AppendUTF8toUTF16(attrName, aName);

    // Check for html
    if (aNode.mContent->GetNodeInfo()->NamespaceEquals(kNameSpaceID_None) &&
        aNode.mContent->IsContentOfType(nsIContent::eHTML)) {
        ToUpperCase(aName);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 540 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        return txXPathNodeType::DOCUMENT_NODE;
    }

    if (aNode.isContent()) {
        PRUint16 type;
        nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode.mContent);
        node->GetNodeType(&type);

        return type;
    }

    return txXPathNodeType::ATTRIBUTE_NODE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 653 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        return new txXPathNode(aNode);
    }

    nsIDocument* document = aNode.mContent->GetDocument();
    if (!document) {
        nsINodeInfo* ni = aNode.mContent->GetNodeInfo();
        if (ni) {
          document = ni->GetDocument();
        }
    }

    return document ? new txXPathNode(document) : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 233 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return NS_PTR_TO_INT32(aNode.mInner);
#else
    NS_PRECONDITION(aNode.mIndex == txXPathNode::eDocument,
                    "Only implemented for documents.");
    return NS_PTR_TO_INT32(aNode.mDocument);
#endif
}

Here is the caller graph for this function:

nsresult txXPathNodeUtils::getXSLTId ( const txXPathNode aNode,
nsAString &  aResult 
) [static]

Definition at line 684 of file txMozillaXPathTreeWalker.cpp.

{
    if (aNode.isDocument()) {
        CopyASCIItoUTF16(nsPrintfCString(kFmtSize, gPrintfFmt,
                                         aNode.mDocument), aResult);

        return NS_OK;
    }

    if (aNode.isContent()) {
        CopyASCIItoUTF16(nsPrintfCString(kFmtSize, gPrintfFmt, aNode.mContent),
                         aResult);

        return NS_OK;
    }

    CopyASCIItoUTF16(nsPrintfCString(kFmtSizeAttr, gPrintfFmtAttr, aNode.mContent,
                                     aNode.mIndex), aResult);

    return NS_OK;
}

Here is the call graph for this function:

PRBool txXPathNodeUtils::isAttribute ( const txXPathNode aNode) [inline, static]

Definition at line 305 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return aNode.mInner->getNodeType() == Node::ATTRIBUTE_NODE;
#else
    return aNode.isAttribute();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool txXPathNodeUtils::isComment ( const txXPathNode aNode) [inline, static]

Definition at line 328 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return aNode.mInner->getNodeType() == Node::COMMENT_NODE;
#else
    return aNode.isContent() &&
           aNode.mContent->IsContentOfType(nsIContent::eCOMMENT);
#endif
}

Here is the call graph for this function:

PRBool txXPathNodeUtils::isElement ( const txXPathNode aNode) [inline, static]

Definition at line 292 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return aNode.mInner->getNodeType() == Node::ELEMENT_NODE;
#else
    return aNode.isContent() &&
           aNode.mContent->IsContentOfType(nsIContent::eELEMENT);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 316 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return aNode.mInner->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE;
#else
    return aNode.isContent() &&
           aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION);
#endif
}

Here is the call graph for this function:

PRBool txXPathNodeUtils::isRoot ( const txXPathNode aNode) [inline, static]

Definition at line 281 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return aNode.mInner->getNodeType() == Node::DOCUMENT_NODE;
#else
    return aNode.isDocument();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool txXPathNodeUtils::isText ( const txXPathNode aNode) [inline, static]

Definition at line 340 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    return aNode.mInner->getNodeType() == Node::TEXT_NODE;
#else
    return aNode.isContent() &&
           aNode.mContent->IsContentOfType(nsIContent::eTEXT);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 628 of file txMozillaXPathTreeWalker.cpp.

{
    NS_ASSERTION(aNode.isContent(), "Wrong type!");

    nsCOMPtr<nsITextContent> textCont = do_QueryInterface(aNode.mContent);
    if (!textCont) {
        return PR_TRUE;
    }
    return textCont->IsOnlyWhitespace();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool txXPathNodeUtils::localNameEquals ( const txXPathNode aNode,
nsIAtom aLocalName 
) [inline, static]

Definition at line 257 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    nsCOMPtr<nsIAtom> localName;
    aNode.mInner->getLocalName(getter_AddRefs(localName));

    return localName == aLocalName;
#else
    if (aNode.isContent()) {
        nsINodeInfo *ni = aNode.mContent->GetNodeInfo();
        if (ni) {
            return ni->Equals(aLocalName);
        }
    }

    nsCOMPtr<nsIAtom> localName = txXPathNodeUtils::getLocalName(aNode);

    return localName == aLocalName;
#endif
}

Here is the call graph for this function:

void txXPathNodeUtils::release ( txXPathNode aNode) [inline, static]

Definition at line 246 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    delete aNode->mInner;
#else
    NS_RELEASE(aNode->mDocument);
#endif
}

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