Back to index

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

#include <nsXULContentUtils.h>

Collaboration diagram for nsXULContentUtils:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XUL_RESOURCE (NC_child, NC_NAMESPACE_URI"child")
 XUL_RESOURCE (NC_Folder, NC_NAMESPACE_URI"Folder")
 XUL_RESOURCE (NC_open, NC_NAMESPACE_URI"open")
 XUL_LITERAL (true_,"true")

Static Public Member Functions

static nsresult Init ()
static nsresult Finish ()
static nsresult FindChildByTag (nsIContent *aElement, PRInt32 aNameSpaceID, nsIAtom *aTag, nsIContent **aResult)
static nsresult FindChildByResource (nsIContent *aElement, nsIRDFResource *aResource, nsIContent **aResult)
static nsresult GetElementResource (nsIContent *aElement, nsIRDFResource **aResult)
static nsresult GetElementRefResource (nsIContent *aElement, nsIRDFResource **aResult)
static nsresult GetTextForNode (nsIRDFNode *aNode, nsAString &aResult)
static nsresult MakeElementURI (nsIDocument *aDocument, const nsAString &aElementID, nsCString &aURI)
 Construct a URI from the element ID given.
static nsresult MakeElementResource (nsIDocument *aDocument, const nsAString &aElementID, nsIRDFResource **aResult)
static nsresult MakeElementID (nsIDocument *aDocument, const nsACString &aURI, nsAString &aElementID)
 Extract the element ID from aURI.
static nsresult GetResource (PRInt32 aNameSpaceID, nsIAtom *aAttribute, nsIRDFResource **aResult)
static nsresult GetResource (PRInt32 aNameSpaceID, const nsAString &aAttribute, nsIRDFResource **aResult)
static nsresult SetCommandUpdater (nsIDocument *aDocument, nsIContent *aElement)
static nsIRDFServiceRDFService ()

Static Protected Member Functions

static int PR_CALLBACK DisableXULCacheChangedCallback (const char *aPrefName, void *aClosure)

Static Protected Attributes

static nsrefcnt gRefCnt
static nsIRDFServicegRDF
static nsIDateTimeFormatgFormat
static PRBool gDisableXULCache

Detailed Description

Definition at line 63 of file nsXULContentUtils.h.


Member Function Documentation

static int PR_CALLBACK nsXULContentUtils::DisableXULCacheChangedCallback ( const char *  aPrefName,
void aClosure 
) [static, protected]
static nsresult nsXULContentUtils::FindChildByResource ( nsIContent aElement,
nsIRDFResource aResource,
nsIContent **  aResult 
) [static]
nsresult nsXULContentUtils::FindChildByTag ( nsIContent aElement,
PRInt32  aNameSpaceID,
nsIAtom aTag,
nsIContent **  aResult 
) [static]

Definition at line 168 of file nsXULContentUtils.cpp.

{
    PRUint32 count = aElement->GetChildCount();

    for (PRUint32 i = 0; i < count; ++i) {
        nsIContent *kid = aElement->GetChildAt(i);

        if (kid->GetNameSpaceID() != aNameSpaceID)
            continue; // wrong namespace

        nsINodeInfo *ni = kid->GetNodeInfo();

        if (!ni || !ni->Equals(aTag))
            continue;

        *aResult = kid;
        NS_ADDREF(*aResult);
        return NS_OK;
    }

    *aResult = nsnull;
    return NS_RDF_NO_VALUE; // not found
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 146 of file nsXULContentUtils.cpp.

{
    if (--gRefCnt == 0) {
        NS_IF_RELEASE(gRDF);

#define XUL_RESOURCE(ident, uri) NS_IF_RELEASE(ident)
#define XUL_LITERAL(ident, val) NS_IF_RELEASE(ident)
#include "nsXULResourceList.h"
#undef XUL_RESOURCE
#undef XUL_LITERAL

        NS_IF_RELEASE(gFormat);
    }

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 228 of file nsXULContentUtils.cpp.

{
    *aResult = nsnull;
    // Perform a reverse mapping from an element in the content model
    // to an RDF resource. Check for a "ref" attribute first, then
    // fallback on an "id" attribute.
    nsresult rv;
    PRUnichar buf[128];
    nsFixedString uri(buf, NS_ARRAY_LENGTH(buf), 0);

    rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::ref, uri);
    NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving attribute");
    if (NS_FAILED(rv)) return rv;

    if (rv != NS_CONTENT_ATTR_HAS_VALUE) {
        rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::id, uri);
    }

    if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
        // We'll use rdf_MakeAbsolute() to translate this to a URL.
        nsCOMPtr<nsIDocument> doc = aElement->GetOwnerDoc();

        nsIURI *url = doc->GetDocumentURI();
        NS_ASSERTION(url != nsnull, "document has no uri");
        if (! url)
            return NS_ERROR_UNEXPECTED;

        // N.B. that if this fails (e.g., because necko doesn't grok
        // the protocol), uriStr will be untouched.
        NS_MakeAbsoluteURI(uri, uri, url);

        rv = gRDF->GetUnicodeResource(uri, aResult);
    }
    else {
        nsCOMPtr<nsIDOMXULElement> xulElem(do_QueryInterface(aElement, &rv));
        if (xulElem) {
            rv = xulElem->GetResource(aResult);
        }
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsXULContentUtils::GetElementResource ( nsIContent aElement,
nsIRDFResource **  aResult 
) [static]

Definition at line 197 of file nsXULContentUtils.cpp.

{
    // Perform a reverse mapping from an element in the content model
    // to an RDF resource.
    nsresult rv;

    PRUnichar buf[128];
    nsFixedString id(buf, NS_ARRAY_LENGTH(buf), 0);

    rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::id, id);
    NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving attribute");
    if (NS_FAILED(rv)) return rv;

    if (rv != NS_CONTENT_ATTR_HAS_VALUE)
        return NS_ERROR_FAILURE;

    // Since the element will store its ID attribute as a document-relative value,
    // we may need to qualify it first...
    nsCOMPtr<nsIDocument> doc = aElement->GetDocument();
    NS_ASSERTION(doc, "element is not in any document");
    if (! doc)
        return NS_ERROR_FAILURE;

    rv = nsXULContentUtils::MakeElementResource(doc, id, aResult);
    if (NS_FAILED(rv)) return rv;

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsXULContentUtils::GetResource ( PRInt32  aNameSpaceID,
nsIAtom aAttribute,
nsIRDFResource **  aResult 
) [static]

Definition at line 413 of file nsXULContentUtils.cpp.

{
    // construct a fully-qualified URI from the namespace/tag pair.
    NS_PRECONDITION(aAttribute != nsnull, "null ptr");
    if (! aAttribute)
        return NS_ERROR_NULL_POINTER;

    nsresult rv;

    nsAutoString attr;
    rv = aAttribute->ToString(attr);
    if (NS_FAILED(rv)) return rv;

    return GetResource(aNameSpaceID, attr, aResult);
}

Here is the caller graph for this function:

nsresult nsXULContentUtils::GetResource ( PRInt32  aNameSpaceID,
const nsAString &  aAttribute,
nsIRDFResource **  aResult 
) [static]

Definition at line 431 of file nsXULContentUtils.cpp.

{
    // construct a fully-qualified URI from the namespace/tag pair.

    // XXX should we allow nodes with no namespace???
    //NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "no namespace");
    //if (aNameSpaceID == kNameSpaceID_Unknown)
    //    return NS_ERROR_UNEXPECTED;

    nsresult rv;

    PRUnichar buf[256];
    nsFixedString uri(buf, NS_ARRAY_LENGTH(buf), 0);
    if (aNameSpaceID != kNameSpaceID_Unknown && aNameSpaceID != kNameSpaceID_None) {
        rv = nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceURI(aNameSpaceID, uri);
        // XXX ignore failure; treat as "no namespace"
    }

    // XXX check to see if we need to insert a '/' or a '#'. Oy.
    if (!uri.IsEmpty()  && uri.Last() != '#' && uri.Last() != '/' && aAttribute.First() != '#')
        uri.Append(PRUnichar('#'));

    uri.Append(aAttribute);

    rv = gRDF->GetUnicodeResource(uri, aResult);
    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
    if (NS_FAILED(rv)) return rv;

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsXULContentUtils::GetTextForNode ( nsIRDFNode aNode,
nsAString &  aResult 
) [static]

Definition at line 278 of file nsXULContentUtils.cpp.

{
    if (! aNode) {
        aResult.Truncate();
        return NS_OK;
    }

    nsresult rv;

    // Literals are the most common, so try these first.
    nsCOMPtr<nsIRDFLiteral> literal = do_QueryInterface(aNode);
    if (literal) {
        const PRUnichar* p;
        rv = literal->GetValueConst(&p);
        if (NS_FAILED(rv)) return rv;

        aResult = p;
        return NS_OK;
    }

    nsCOMPtr<nsIRDFDate> dateLiteral = do_QueryInterface(aNode);
    if (dateLiteral) {
        PRInt64      value;
        rv = dateLiteral->GetValue(&value);
        if (NS_FAILED(rv)) return rv;

        nsAutoString str;
        rv = gFormat->FormatPRTime(nsnull /* nsILocale* locale */,
                                  kDateFormatShort,
                                  kTimeFormatSeconds,
                                  PRTime(value),
                                  str);
        aResult.Assign(str);

        if (NS_FAILED(rv)) return rv;

        return NS_OK;
    }

    nsCOMPtr<nsIRDFInt> intLiteral = do_QueryInterface(aNode);
    if (intLiteral) {
        PRInt32      value;
        rv = intLiteral->GetValue(&value);
        if (NS_FAILED(rv)) return rv;

        aResult.Truncate();
        nsAutoString intStr;
        intStr.AppendInt(value, 10);
        aResult.Append(intStr);
        return NS_OK;
    }


    nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(aNode);
    if (resource) {
        const char* p;
        rv = resource->GetValueConst(&p);
        if (NS_FAILED(rv)) return rv;
        CopyUTF8toUTF16(p, aResult);
        return NS_OK;
    }

    NS_ERROR("not a resource or a literal");
    return NS_ERROR_UNEXPECTED;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file nsXULContentUtils.cpp.

{
    if (gRefCnt++ == 0) {
        nsresult rv = CallGetService(kRDFServiceCID, &gRDF);
        if (NS_FAILED(rv)) {
            return rv;
        }

#define XUL_RESOURCE(ident, uri)                              \
  PR_BEGIN_MACRO                                              \
   rv = gRDF->GetResource(NS_LITERAL_CSTRING(uri), &(ident)); \
   if (NS_FAILED(rv)) return rv;                              \
  PR_END_MACRO

#define XUL_LITERAL(ident, val)                                   \
  PR_BEGIN_MACRO                                                  \
   rv = gRDF->GetLiteral(NS_LITERAL_STRING(val).get(), &(ident)); \
   if (NS_FAILED(rv)) return rv;                                  \
  PR_END_MACRO

#include "nsXULResourceList.h"
#undef XUL_RESOURCE
#undef XUL_LITERAL

        rv = CallCreateInstance(kDateTimeFormatCID, &gFormat);
        if (NS_FAILED(rv)) {
            return rv;
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsXULContentUtils::MakeElementID ( nsIDocument aDocument,
const nsACString &  aURI,
nsAString &  aElementID 
) [static]

Extract the element ID from aURI.

Note that aURI must be an absolute URI string in UTF8; the element ID is the ref from the URI. If the scheme does not support refs, then the ID will be empty.

Definition at line 389 of file nsXULContentUtils.cpp.

{
    // Convert a URI into an element ID that can be accessed from the
    // DOM APIs.
    nsCOMPtr<nsIURI> uri;
    nsresult rv = NS_NewURI(getter_AddRefs(uri), aURI,
                            aDocument->GetDocumentCharacterSet().get());
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
    if (url) {
        nsCAutoString ref;
        url->GetRef(ref);
        CopyUTF8toUTF16(ref, aElementID);
    } else {
        aElementID.Truncate();
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsXULContentUtils::MakeElementResource ( nsIDocument aDocument,
const nsAString &  aElementID,
nsIRDFResource **  aResult 
) [static]

Definition at line 370 of file nsXULContentUtils.cpp.

{
    nsresult rv;

    char buf[256];
    nsFixedCString uri(buf, sizeof(buf), 0);
    rv = MakeElementURI(aDocument, aID, uri);
    if (NS_FAILED(rv)) return rv;

    rv = gRDF->GetResource(uri, aResult);
    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create resource");
    if (NS_FAILED(rv)) return rv;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsXULContentUtils::MakeElementURI ( nsIDocument aDocument,
const nsAString &  aElementID,
nsCString aURI 
) [static]

Construct a URI from the element ID given.

This uses aElement as the ref and aDocument's document URI as the base. If aDocument's document URI does not support refs, this will throw NS_ERROR_NOT_AVAILABLE.

Definition at line 345 of file nsXULContentUtils.cpp.

{
    // Convert an element's ID to a URI that can be used to refer to
    // the element in the XUL graph.

    nsIURI *docURL = aDocument->GetDocumentURI();
    NS_ENSURE_TRUE(docURL, NS_ERROR_UNEXPECTED);

    nsCOMPtr<nsIURI> docURIClone;
    nsresult rv = docURL->Clone(getter_AddRefs(docURIClone));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIURL> mutableURL(do_QueryInterface(docURIClone));
    NS_ENSURE_TRUE(mutableURL, NS_ERROR_NOT_AVAILABLE);

    rv = mutableURL->SetRef(NS_ConvertUTF16toUTF8(aElementID));
    NS_ENSURE_SUCCESS(rv, rv);

    return mutableURL->GetSpec(aURI);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIRDFService* nsXULContentUtils::RDFService ( ) [inline, static]

Definition at line 131 of file nsXULContentUtils.h.

    {
        return gRDF;
    }
nsresult nsXULContentUtils::SetCommandUpdater ( nsIDocument aDocument,
nsIContent aElement 
) [static]

Definition at line 464 of file nsXULContentUtils.cpp.

{
    // Deal with setting up a 'commandupdater'. Pulls the 'events' and
    // 'targets' attributes off of aElement, and adds it to the
    // document's command dispatcher.
    NS_PRECONDITION(aDocument != nsnull, "null ptr");
    if (! aDocument)
        return NS_ERROR_NULL_POINTER;

    NS_PRECONDITION(aElement != nsnull, "null ptr");
    if (! aElement)
        return NS_ERROR_NULL_POINTER;

    nsresult rv;

    nsCOMPtr<nsIDOMXULDocument> xuldoc = do_QueryInterface(aDocument);
    NS_ASSERTION(xuldoc != nsnull, "not a xul document");
    if (! xuldoc)
        return NS_ERROR_UNEXPECTED;

    nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher;
    rv = xuldoc->GetCommandDispatcher(getter_AddRefs(dispatcher));
    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get dispatcher");
    if (NS_FAILED(rv)) return rv;

    NS_ASSERTION(dispatcher != nsnull, "no dispatcher");
    if (! dispatcher)
        return NS_ERROR_UNEXPECTED;

    nsAutoString events;
    rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::events, events);

    if (rv != NS_CONTENT_ATTR_HAS_VALUE)
        events.AssignLiteral("*");

    nsAutoString targets;
    rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::targets, targets);

    if (rv != NS_CONTENT_ATTR_HAS_VALUE)
        targets.AssignLiteral("*");

    nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(aElement);
    NS_ASSERTION(domelement != nsnull, "not a DOM element");
    if (! domelement)
        return NS_ERROR_UNEXPECTED;

    rv = dispatcher->AddCommandUpdater(domelement, events, targets);
    if (NS_FAILED(rv)) return rv;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsXULContentUtils::XUL_LITERAL ( true_  ,
"true"   
)
nsXULContentUtils::XUL_RESOURCE ( NC_child  ,
NC_NAMESPACE_URI"child"   
)
nsXULContentUtils::XUL_RESOURCE ( NC_Folder  ,
NC_NAMESPACE_URI"Folder"   
)

Member Data Documentation

Definition at line 70 of file nsXULContentUtils.h.

Definition at line 68 of file nsXULContentUtils.h.

nsIRDFService * nsXULContentUtils::gRDF [static, protected]

Definition at line 67 of file nsXULContentUtils.h.

nsrefcnt nsXULContentUtils::gRefCnt [static, protected]

Definition at line 66 of file nsXULContentUtils.h.


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