Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
txStylesheetCompiler Class Reference

#include <txStylesheetCompiler.h>

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

List of all members.

Public Member Functions

 txStylesheetCompiler (const nsAString &aStylesheetURI, txACompileObserver *aObserver)
 txStylesheetCompiler (const nsAString &aStylesheetURI, txStylesheet *aStylesheet, txListIterator *aInsertPosition, txACompileObserver *aObserver)
virtual nsrefcnt AddRef ()
virtual nsrefcnt Release ()
void setBaseURI (const nsString &aBaseURI)
nsresult startElement (PRInt32 aNamespaceID, nsIAtom *aLocalName, nsIAtom *aPrefix, txStylesheetAttr *aAttributes, PRInt32 aAttrCount)
nsresult startElement (const PRUnichar *aName, const PRUnichar **aAtts, PRInt32 aAttrCount, PRInt32 aIDOffset)
nsresult endElement ()
nsresult characters (const nsAString &aStr)
nsresult doneLoading ()
void cancel (nsresult aError, const PRUnichar *aErrorText=nsnull, const PRUnichar *aParam=nsnull)
txStylesheetgetStylesheet ()
nsresult loadURI (const nsAString &aUri, const nsAString &aReferrerUri, txStylesheetCompiler *aCompiler)
void onDoneCompiling (txStylesheetCompiler *aCompiler, nsresult aResult, const PRUnichar *aErrorText=nsnull, const PRUnichar *aParam=nsnull)

Private Types

enum  { eNoEmbed, eNeedEmbed, eInEmbed, eHasEmbed }

Private Member Functions

nsresult startElementInternal (PRInt32 aNamespaceID, nsIAtom *aLocalName, nsIAtom *aPrefix, txStylesheetAttr *aAttributes, PRInt32 aAttrCount, PRInt32 aIDOffset=-1)
nsresult flushCharacters ()
nsresult ensureNewElementContext ()
nsresult maybeDoneCompiling ()
nsresult init (const nsAString &aStylesheetURI, txStylesheet *aStylesheet, txListIterator *aInsertPosition)
PRBool handleEmbeddedSheet ()
void doneEmbedding ()
nsresult pushHandlerTable (txHandlerTable *aTable)
void popHandlerTable ()
nsresult pushSorter (txPushNewContext *aSorter)
void popSorter ()
nsresult pushChooseGotoList ()
void popChooseGotoList ()
nsresult pushObject (TxObject *aObject)
TxObjectpopObject ()
nsresult pushPtr (void *aPtr)
voidpopPtr ()
nsresult addToplevelItem (txToplevelItem *aItem)
nsresult openInstructionContainer (txInstructionContainer *aContainer)
void closeInstructionContainer ()
nsresult addInstruction (nsAutoPtr< txInstruction > aInstruction)
nsresult loadIncludedStylesheet (const nsAString &aURI)
nsresult loadImportedStylesheet (const nsAString &aURI, txStylesheet::ImportFrame *aFrame)
nsresult addGotoTarget (txInstruction **aTargetPointer)
nsresult addVariable (const txExpandedName &aName)
nsresult resolveNamespacePrefix (nsIAtom *aPrefix, PRInt32 &aID)
nsresult resolveFunctionCall (nsIAtom *aName, PRInt32 aID, FunctionCall *&aFunction)
PRBool caseInsensitiveNameTests ()
 Should nametests parsed in this context be case-sensitive.
PRBool fcp ()
 Should the stylesheet be parsed in forwards compatible parsing mode.
void SetErrorOffset (PRUint32 aOffset)

Private Attributes

nsAutoRefCnt mRefCnt
nsString mCharacters
nsresult mStatus
nsRefPtr< txStylesheetmStylesheet
txHandlerTablemHandlerTable
nsAutoPtr< txElementContextmElementContext
txPushNewContextmSorter
nsAutoPtr< txListmChooseGotoList
PRPackedBool mDOE
PRPackedBool mSearchingForFallback
nsRefPtr< txACompileObservermObserver
nsVoidArray mInScopeVariables
nsVoidArray mChildCompilerList
nsString mTarget
enum
txStylesheetCompilerState:: { ... }  
mEmbedStatus
nsString mStylesheetURI
PRPackedBool mIsTopCompiler
PRPackedBool mDoneWithThisStylesheet
txStack mObjectStack
txStack mOtherStack

Friends

class txStylesheetCompilerState

Detailed Description

Definition at line 198 of file txStylesheetCompiler.h.


Member Enumeration Documentation

anonymous enum [protected, inherited]
Enumerator:
eNoEmbed 
eNeedEmbed 
eInEmbed 
eHasEmbed 

Definition at line 171 of file txStylesheetCompiler.h.


Constructor & Destructor Documentation

txStylesheetCompiler::txStylesheetCompiler ( const nsAString &  aStylesheetURI,
txACompileObserver aObserver 
)

Definition at line 53 of file txStylesheetCompiler.cpp.

    : txStylesheetCompilerState(aObserver)
{
    mStatus = init(aStylesheetURI, nsnull, nsnull);
}

Here is the call graph for this function:

txStylesheetCompiler::txStylesheetCompiler ( const nsAString &  aStylesheetURI,
txStylesheet aStylesheet,
txListIterator aInsertPosition,
txACompileObserver aObserver 
)

Definition at line 60 of file txStylesheetCompiler.cpp.

    : txStylesheetCompilerState(aObserver)
{
    mStatus = init(aStylesheetURI, aStylesheet, aInsertPosition);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 838 of file txStylesheetCompiler.cpp.

{
    if (!mGotoTargetPointers.AppendElement(aTargetPointer)) {
        return NS_ERROR_OUT_OF_MEMORY;
    }
    
    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 742 of file txStylesheetCompiler.cpp.

{
    NS_PRECONDITION(mNextInstrPtr, "adding instruction outside container");

    txInstruction* newInstr = aInstruction;

    *mNextInstrPtr = aInstruction.forget();
    mNextInstrPtr = &newInstr->mNext;
    
    PRInt32 i, count = mGotoTargetPointers.Count();
    for (i = 0; i < count; ++i) {
        *NS_STATIC_CAST(txInstruction**, mGotoTargetPointers[i]) = newInstr;
    }
    mGotoTargetPointers.Clear();

    return NS_OK;
}

Here is the call graph for this function:

Implements txACompileObserver.

Definition at line 70 of file txStylesheetCompiler.cpp.

{
    return ++mRefCnt;
}

Definition at line 719 of file txStylesheetCompiler.cpp.

{
    return mToplevelIterator.addBefore(aItem);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 848 of file txStylesheetCompiler.cpp.

{
    txInScopeVariable* var = new txInScopeVariable(aName);
    NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY);

    if (!mInScopeVariables.AppendElement(var)) {
        delete var;
        return NS_ERROR_OUT_OF_MEMORY;
    }

    return NS_OK;
}

Here is the caller graph for this function:

void txStylesheetCompiler::cancel ( nsresult  aError,
const PRUnichar aErrorText = nsnull,
const PRUnichar aParam = nsnull 
)

Definition at line 421 of file txStylesheetCompiler.cpp.

{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("Compiler::cancel: %s, module: %d, code %d\n",
            NS_LossyConvertUCS2toASCII(mStylesheetURI).get(),
            NS_ERROR_GET_MODULE(aError),
            NS_ERROR_GET_CODE(aError)));
    if (NS_SUCCEEDED(mStatus)) {
        mStatus = aError;
    }

    if (mObserver) {
        mObserver->onDoneCompiling(this, mStatus, aErrorText, aParam);
        // This will ensure that we don't call onDoneCompiling twice. Also
        // ensures that we don't keep the observer alive longer then necessary.
        mObserver = nsnull;
    }
}

Here is the caller graph for this function:

Should nametests parsed in this context be case-sensitive.

Implements txIParseContext.

Definition at line 983 of file txStylesheetCompiler.cpp.

{
    return PR_FALSE;
}

Definition at line 392 of file txStylesheetCompiler.cpp.

{
    if (NS_FAILED(mStatus)) {
        // ignore content after failure
        // XXX reevaluate once expat stops on failure
        return NS_OK;
    }

    mCharacters.Append(aStr);

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 734 of file txStylesheetCompiler.cpp.

{
    NS_ASSERTION(mGotoTargetPointers.Count() == 0,
                 "GotoTargets still exists, did you forget to add txReturn?");
    mNextInstrPtr = 0;
}

Here is the caller graph for this function:

Definition at line 110 of file txStylesheetCompiler.h.

Here is the caller graph for this function:

Definition at line 406 of file txStylesheetCompiler.cpp.

{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("Compiler::doneLoading: %s\n",
            NS_LossyConvertUCS2toASCII(mStylesheetURI).get()));
    if (NS_FAILED(mStatus)) {
        return mStatus;
    }

    mDoneWithThisStylesheet = PR_TRUE;

    return maybeDoneCompiling();
}

Here is the call graph for this function:

Definition at line 350 of file txStylesheetCompiler.cpp.

{
    if (NS_FAILED(mStatus)) {
        // ignore content after failure
        // XXX reevaluate once expat stops on failure
        return NS_OK;
    }

    nsresult rv = flushCharacters();
    NS_ENSURE_SUCCESS(rv, rv);

    PRInt32 i;
    for (i = mInScopeVariables.Count() - 1; i >= 0; --i) {
        txInScopeVariable* var =
            NS_STATIC_CAST(txInScopeVariable*, mInScopeVariables[i]);
        if (!--(var->mLevel)) {
            nsAutoPtr<txInstruction> instr(new txRemoveVariable(var->mName));
            NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY);

            rv = addInstruction(instr);
            NS_ENSURE_SUCCESS(rv, rv);
            
            mInScopeVariables.RemoveElementAt(i);
            delete var;
        }
    }

    const txElementHandler* handler =
        NS_CONST_CAST(const txElementHandler*,
                      NS_STATIC_CAST(txElementHandler*, popPtr()));
    rv = (handler->mEndFunction)(*this);
    NS_ENSURE_SUCCESS(rv, rv);

    if (!--mElementContext->mDepth) {
        // this will delete the old object
        mElementContext = NS_STATIC_CAST(txElementContext*, popObject());
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 502 of file txStylesheetCompiler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool txStylesheetCompilerState::fcp ( ) [inline, inherited]

Should the stylesheet be parsed in forwards compatible parsing mode.

Definition at line 149 of file txStylesheetCompiler.h.

Here is the caller graph for this function:

Definition at line 480 of file txStylesheetCompiler.cpp.

{
    // Bail if we don't have any characters. The handler will detect
    // ignoreable whitespace
    if (mCharacters.IsEmpty()) {
        return NS_OK;
    }

    nsresult rv = NS_OK;

    do {
        rv = (mHandlerTable->mTextHandler)(mCharacters, *this);
    } while (rv == NS_XSLT_GET_NEW_HANDLER);

    NS_ENSURE_SUCCESS(rv, rv);

    mCharacters.Truncate();

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 442 of file txStylesheetCompiler.cpp.

{
    return mStylesheet;
}

Definition at line 106 of file txStylesheetCompiler.h.

    {
        return mEmbedStatus == eInEmbed;
    }

Here is the caller graph for this function:

nsresult txStylesheetCompilerState::init ( const nsAString &  aStylesheetURI,
txStylesheet aStylesheet,
txListIterator aInsertPosition 
) [inherited]

Definition at line 570 of file txStylesheetCompiler.cpp.

{
    NS_ASSERTION(!aStylesheet || aInsertPosition,
                 "must provide insertposition if loading subsheet");
    mStylesheetURI = aStylesheetURI;
    // Check for fragment identifier of an embedded stylesheet.
    PRInt32 fragment = aStylesheetURI.FindChar('#') + 1;
    if (fragment > 0) {
        PRInt32 fragmentLength = aStylesheetURI.Length() - fragment;
        if (fragmentLength > 0) {
            // This is really an embedded stylesheet, not just a
            // "url#". We may want to unescape the fragment.
            mTarget = Substring(aStylesheetURI, (PRUint32)fragment,
                                fragmentLength);
            mEmbedStatus = eNeedEmbed;
            mHandlerTable = gTxEmbedHandler;
        }
    }
    nsresult rv = NS_OK;
    if (aStylesheet) {
        mStylesheet = aStylesheet;
        mToplevelIterator = *aInsertPosition;
        mIsTopCompiler = PR_FALSE;
    }
    else {
        mStylesheet = new txStylesheet;
        NS_ENSURE_TRUE(mStylesheet, NS_ERROR_OUT_OF_MEMORY);
        
        rv = mStylesheet->init();
        NS_ENSURE_SUCCESS(rv, rv);
        
        mToplevelIterator =
            txListIterator(&mStylesheet->mRootFrame->mToplevelItems);
        mToplevelIterator.next(); // go to the end of the list
        mIsTopCompiler = PR_TRUE;
    }
   
    mElementContext = new txElementContext(aStylesheetURI);
    NS_ENSURE_TRUE(mElementContext && mElementContext->mMappings,
                   NS_ERROR_OUT_OF_MEMORY);

    // Push the "old" txElementContext
    rv = pushObject(0);
    NS_ENSURE_SUCCESS(rv, rv);
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 805 of file txStylesheetCompiler.cpp.

{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("CompilerState::loadImportedStylesheet: %s\n",
            NS_LossyConvertUCS2toASCII(aURI).get()));
    if (mStylesheetURI.Equals(aURI)) {
        return NS_ERROR_XSLT_LOAD_RECURSION;
    }
    NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED);

    txListIterator iter(&aFrame->mToplevelItems);
    iter.next(); // go to the end of the list

    txACompileObserver* observer = NS_STATIC_CAST(txStylesheetCompiler*, this);

    nsRefPtr<txStylesheetCompiler> compiler =
        new txStylesheetCompiler(aURI, mStylesheet, &iter, observer);
    NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);

    if (!mChildCompilerList.AppendElement(compiler)) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    nsresult rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
    if (NS_FAILED(rv)) {
        mChildCompilerList.RemoveElement(compiler);
    }

    return rv;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 761 of file txStylesheetCompiler.cpp.

{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("CompilerState::loadIncludedStylesheet: %s\n",
            NS_LossyConvertUCS2toASCII(aURI).get()));
    if (mStylesheetURI.Equals(aURI)) {
        return NS_ERROR_XSLT_LOAD_RECURSION;
    }
    NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED);

    nsAutoPtr<txToplevelItem> item(new txDummyItem);
    NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);

    nsresult rv = mToplevelIterator.addBefore(item);
    NS_ENSURE_SUCCESS(rv, rv);
    
    item.forget();

    // step back to the dummy-item
    mToplevelIterator.previous();
    
    txACompileObserver* observer = NS_STATIC_CAST(txStylesheetCompiler*, this);

    nsRefPtr<txStylesheetCompiler> compiler =
        new txStylesheetCompiler(aURI, mStylesheet, &mToplevelIterator,
                                 observer);
    NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);

    // step forward before calling the observer in case of syncronous loading
    mToplevelIterator.next();

    if (!mChildCompilerList.AppendElement(compiler)) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
    if (NS_FAILED(rv)) {
        mChildCompilerList.RemoveElement(compiler);
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txStylesheetCompiler::loadURI ( const nsAString &  aUri,
const nsAString &  aReferrerUri,
txStylesheetCompiler aCompiler 
) [virtual]

Implements txACompileObserver.

Definition at line 448 of file txStylesheetCompiler.cpp.

{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("Compiler::loadURI forwards %s thru %s\n",
            NS_LossyConvertUCS2toASCII(aUri).get(),
            NS_LossyConvertUCS2toASCII(mStylesheetURI).get()));
    if (mStylesheetURI.Equals(aUri)) {
        return NS_ERROR_XSLT_LOAD_RECURSION;
    }
    return mObserver ? mObserver->loadURI(aUri, aReferrerUri, aCompiler) :
                       NS_ERROR_FAILURE;
}

Definition at line 523 of file txStylesheetCompiler.cpp.

{
    if (!mDoneWithThisStylesheet || mChildCompilerList.Count()) {
        return NS_OK;
    }
    
    if (mIsTopCompiler) {
        nsresult rv = mStylesheet->doneCompiling();
        if (NS_FAILED(rv)) {
            cancel(rv);
            return rv;
        }
    }
    
    if (mObserver) {
        mObserver->onDoneCompiling(this, mStatus);
        // This will ensure that we don't call onDoneCompiling twice. Also
        // ensures that we don't keep the observer alive longer then necessary.
        mObserver = nsnull;
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void txStylesheetCompiler::onDoneCompiling ( txStylesheetCompiler aCompiler,
nsresult  aResult,
const PRUnichar aErrorText = nsnull,
const PRUnichar aParam = nsnull 
) [virtual]

Implements txACompileObserver.

Definition at line 464 of file txStylesheetCompiler.cpp.

{
    if (NS_FAILED(aResult)) {
        cancel(aResult, aErrorText, aParam);
        return;
    }

    mChildCompilerList.RemoveElement(aCompiler);

    maybeDoneCompiling();
}

Here is the call graph for this function:

Definition at line 725 of file txStylesheetCompiler.cpp.

{
    NS_PRECONDITION(!mNextInstrPtr, "can't nest instruction-containers");

    mNextInstrPtr = aContainer->mFirstInstruction.StartAssignment();
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 681 of file txStylesheetCompiler.cpp.

{
    // this will delete the old value
    mChooseGotoList = NS_STATIC_CAST(txList*, popObject());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 645 of file txStylesheetCompiler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 694 of file txStylesheetCompiler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 709 of file txStylesheetCompiler.cpp.

{
    void* value = mOtherStack.pop();
#ifdef TX_DEBUG_STACK
    PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("popPtr: %d\n", value));
#endif
    return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 662 of file txStylesheetCompiler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 668 of file txStylesheetCompiler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 634 of file txStylesheetCompiler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 688 of file txStylesheetCompiler.cpp.

{
    return mObjectStack.push(aObject);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 700 of file txStylesheetCompiler.cpp.

{
#ifdef TX_DEBUG_STACK
    PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("pushPtr: %d\n", aPtr));
#endif
    return mOtherStack.push(aPtr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 651 of file txStylesheetCompiler.cpp.

{
    nsresult rv = pushPtr(mSorter);
    NS_ENSURE_SUCCESS(rv, rv);

    mSorter = aSorter;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements txACompileObserver.

Definition at line 76 of file txStylesheetCompiler.cpp.

{
    if (--mRefCnt == 0) {
        mRefCnt = 1; //stabilize
        delete this;
        return 0;
    }
    return mRefCnt;
}
nsresult txStylesheetCompilerState::resolveFunctionCall ( nsIAtom aName,
PRInt32  aID,
FunctionCall *&  aFunction 
) [virtual, inherited]

Implements txIParseContext.

Definition at line 911 of file txStylesheetCompiler.cpp.

{
    aFunction = nsnull;

    if (aID == kNameSpaceID_None) {
        if (aName == txXSLTAtoms::document) {
            aFunction = new DocumentFunctionCall(mElementContext->mBaseURI);
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::key) {
            aFunction = new txKeyFunctionCall(mElementContext->mMappings);
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::formatNumber) {
            aFunction = new txFormatNumberFunctionCall(mStylesheet,
                                                       mElementContext->mMappings);
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::current) {
            aFunction = new CurrentFunctionCall();
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::unparsedEntityUri) {
    
            return NS_ERROR_NOT_IMPLEMENTED;
        }
        if (aName == txXSLTAtoms::generateId) {
            aFunction = new GenerateIdFunctionCall();
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::systemProperty) {
            aFunction = new SystemPropertyFunctionCall(mElementContext->mMappings);
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::elementAvailable) {
            aFunction =
                new ElementAvailableFunctionCall(mElementContext->mMappings);
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (aName == txXSLTAtoms::functionAvailable) {
            aFunction =
                new FunctionAvailableFunctionCall(mElementContext->mMappings);
            NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY);
    
            return NS_OK;
        }
        if (!fcp()) {
            return NS_ERROR_XPATH_UNKNOWN_FUNCTION;
        }
    }

    aFunction = new txErrorFunctionCall(aName, aID);

    return aFunction ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

Here is the call graph for this function:

nsresult txStylesheetCompilerState::resolveNamespacePrefix ( nsIAtom aPrefix,
PRInt32 aID 
) [virtual, inherited]

Implements txIParseContext.

Definition at line 862 of file txStylesheetCompiler.cpp.

{
    NS_ASSERTION(aPrefix && aPrefix != txXMLAtoms::_empty,
                 "caller should handle default namespace ''");
    aID = mElementContext->mMappings->lookupNamespace(aPrefix);
    return (aID != kNameSpaceID_Unknown) ? NS_OK : NS_ERROR_FAILURE;
}

Definition at line 87 of file txStylesheetCompiler.cpp.

{
    NS_ASSERTION(mObjectStack.size() == 1 && !mObjectStack.peek(),
                 "Execution already started");

    if (NS_FAILED(mStatus)) {
        return;
    }

    mElementContext->mBaseURI = aBaseURI;
}

Here is the call graph for this function:

void txStylesheetCompilerState::SetErrorOffset ( PRUint32  aOffset) [virtual, inherited]

Implements txIParseContext.

Definition at line 989 of file txStylesheetCompiler.cpp.

{
    // XXX implement me
}
nsresult txStylesheetCompiler::startElement ( PRInt32  aNamespaceID,
nsIAtom aLocalName,
nsIAtom aPrefix,
txStylesheetAttr aAttributes,
PRInt32  aAttrCount 
)

Definition at line 100 of file txStylesheetCompiler.cpp.

{
    if (NS_FAILED(mStatus)) {
        // ignore content after failure
        // XXX reevaluate once expat stops on failure
        return NS_OK;
    }

    nsresult rv = flushCharacters();
    NS_ENSURE_SUCCESS(rv, rv);

    // look for new namespace mappings
    PRBool hasOwnNamespaceMap = PR_FALSE;
    PRInt32 i;
    for (i = 0; i < aAttrCount; ++i) {
        txStylesheetAttr* attr = aAttributes + i;
        if (attr->mNamespaceID == kNameSpaceID_XMLNS) {
            rv = ensureNewElementContext();
            NS_ENSURE_SUCCESS(rv, rv);

            if (!hasOwnNamespaceMap) {
                mElementContext->mMappings =
                    new txNamespaceMap(*mElementContext->mMappings);
                NS_ENSURE_TRUE(mElementContext->mMappings,
                               NS_ERROR_OUT_OF_MEMORY);
                hasOwnNamespaceMap = PR_TRUE;
            }

            if (attr->mLocalName == txXMLAtoms::xmlns) {
                mElementContext->mMappings->mapNamespace(nsnull, attr->mValue);
            }
            else {
                mElementContext->mMappings->
                    mapNamespace(attr->mLocalName, attr->mValue);
            }
        }
    }

    return startElementInternal(aNamespaceID, aLocalName, aPrefix,
                                aAttributes, aAttrCount);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txStylesheetCompiler::startElement ( const PRUnichar aName,
const PRUnichar **  aAtts,
PRInt32  aAttrCount,
PRInt32  aIDOffset 
)

Definition at line 146 of file txStylesheetCompiler.cpp.

{
    if (NS_FAILED(mStatus)) {
        // ignore content after failure
        // XXX reevaluate once expat stops on failure
        return NS_OK;
    }

    nsresult rv = flushCharacters();
    NS_ENSURE_SUCCESS(rv, rv);

    nsAutoArrayPtr<txStylesheetAttr> atts;
    if (aAttrCount > 0) {
        atts = new txStylesheetAttr[aAttrCount];
        NS_ENSURE_TRUE(atts, NS_ERROR_OUT_OF_MEMORY);
    }

    PRBool hasOwnNamespaceMap = PR_FALSE;
    PRInt32 i;
    for (i = 0; i < aAttrCount; ++i) {
        rv = XMLUtils::splitExpatName(aAttrs[i * 2],
                                      getter_AddRefs(atts[i].mPrefix),
                                      getter_AddRefs(atts[i].mLocalName),
                                      &atts[i].mNamespaceID);
        NS_ENSURE_SUCCESS(rv, rv);
        atts[i].mValue.Append(aAttrs[i * 2 + 1]);

        nsCOMPtr<nsIAtom> prefixToBind;
        if (atts[i].mPrefix == txXMLAtoms::xmlns) {
            prefixToBind = atts[i].mLocalName;
        }
        else if (atts[i].mNamespaceID == kNameSpaceID_XMLNS) {
            prefixToBind = txXMLAtoms::_empty;
        }

        if (prefixToBind) {
            rv = ensureNewElementContext();
            NS_ENSURE_SUCCESS(rv, rv);

            if (!hasOwnNamespaceMap) {
                mElementContext->mMappings =
                    new txNamespaceMap(*mElementContext->mMappings);
                NS_ENSURE_TRUE(mElementContext->mMappings,
                               NS_ERROR_OUT_OF_MEMORY);
                hasOwnNamespaceMap = PR_TRUE;
            }

            rv = mElementContext->mMappings->
                mapNamespace(prefixToBind, atts[i].mValue);
            NS_ENSURE_SUCCESS(rv, rv);
        }
    }

    nsCOMPtr<nsIAtom> prefix, localname;
    PRInt32 namespaceID;
    rv = XMLUtils::splitExpatName(aName, getter_AddRefs(prefix),
                                  getter_AddRefs(localname), &namespaceID);
    NS_ENSURE_SUCCESS(rv, rv);

    PRInt32 idOffset = aIDOffset;
    if (idOffset > 0) {
        idOffset /= 2;
    }
    return startElementInternal(namespaceID, localname, prefix, atts,
                                aAttrCount, idOffset);
}

Here is the call graph for this function:

nsresult txStylesheetCompiler::startElementInternal ( PRInt32  aNamespaceID,
nsIAtom aLocalName,
nsIAtom aPrefix,
txStylesheetAttr aAttributes,
PRInt32  aAttrCount,
PRInt32  aIDOffset = -1 
) [private]

Definition at line 216 of file txStylesheetCompiler.cpp.

{
    nsresult rv = NS_OK;
    PRInt32 i;
    for (i = mInScopeVariables.Count() - 1; i >= 0; --i) {
        ++(NS_STATIC_CAST(txInScopeVariable*, mInScopeVariables[i]))->mLevel;
    }

    // Update the elementcontext if we have special attributes
    for (i = 0; i < aAttrCount; ++i) {
        txStylesheetAttr* attr = aAttributes + i;

        // xml:space
        if (attr->mNamespaceID == kNameSpaceID_XML &&
            attr->mLocalName == txXMLAtoms::space) {
            rv = ensureNewElementContext();
            NS_ENSURE_SUCCESS(rv, rv);

            if (TX_StringEqualsAtom(attr->mValue, txXMLAtoms::preserve)) {
                mElementContext->mPreserveWhitespace = MB_TRUE;
            }
            else if (TX_StringEqualsAtom(attr->mValue, txXMLAtoms::_default)) {
                mElementContext->mPreserveWhitespace = MB_FALSE;
            }
            else {
                return NS_ERROR_XSLT_PARSE_FAILURE;
            }
        }

        // xml:base
        if (attr->mNamespaceID == kNameSpaceID_XML &&
            attr->mLocalName == txXMLAtoms::base &&
            !attr->mValue.IsEmpty()) {
            rv = ensureNewElementContext();
            NS_ENSURE_SUCCESS(rv, rv);
            
            nsAutoString uri;
            URIUtils::resolveHref(attr->mValue, mElementContext->mBaseURI, uri);
            mElementContext->mBaseURI = uri;
        }

        // extension-element-prefixes
        if ((attr->mNamespaceID == kNameSpaceID_XSLT &&
             attr->mLocalName == txXSLTAtoms::extensionElementPrefixes &&
             aNamespaceID != kNameSpaceID_XSLT) ||
            (attr->mNamespaceID == kNameSpaceID_None &&
             attr->mLocalName == txXSLTAtoms::extensionElementPrefixes &&
             aNamespaceID == kNameSpaceID_XSLT &&
             (aLocalName == txXSLTAtoms::stylesheet ||
              aLocalName == txXSLTAtoms::transform))) {
            rv = ensureNewElementContext();
            NS_ENSURE_SUCCESS(rv, rv);

            txTokenizer tok(attr->mValue);
            while (tok.hasMoreTokens()) {
                PRInt32 namespaceID = mElementContext->mMappings->
                    lookupNamespaceWithDefault(tok.nextToken());
                
                if (namespaceID == kNameSpaceID_Unknown)
                    return NS_ERROR_XSLT_PARSE_FAILURE;

                if (!mElementContext->mInstructionNamespaces.
                        AppendElement(NS_INT32_TO_PTR(namespaceID))) {
                    return NS_ERROR_OUT_OF_MEMORY;
                }
            }
        }

        // version
        if ((attr->mNamespaceID == kNameSpaceID_XSLT &&
             attr->mLocalName == txXSLTAtoms::version &&
             aNamespaceID != kNameSpaceID_XSLT) ||
            (attr->mNamespaceID == kNameSpaceID_None &&
             attr->mLocalName == txXSLTAtoms::version &&
             aNamespaceID == kNameSpaceID_XSLT &&
             (aLocalName == txXSLTAtoms::stylesheet ||
              aLocalName == txXSLTAtoms::transform))) {
            rv = ensureNewElementContext();
            NS_ENSURE_SUCCESS(rv, rv);

            if (attr->mValue.EqualsLiteral("1.0")) {
                mElementContext->mForwardsCompatibleParsing = MB_FALSE;
            }
            else {
                mElementContext->mForwardsCompatibleParsing = MB_TRUE;
            }
        }
    }

    // Find the right elementhandler and execute it
    MBool isInstruction = MB_FALSE;
    PRInt32 count = mElementContext->mInstructionNamespaces.Count();
    for (i = 0; i < count; ++i) {
        if (NS_PTR_TO_INT32(mElementContext->mInstructionNamespaces[i]) ==
            aNamespaceID) {
            isInstruction = MB_TRUE;
            break;
        }
    }

    if (mEmbedStatus == eNeedEmbed) {
        // handle embedded stylesheets
        if (aIDOffset >= 0 && aAttributes[aIDOffset].mValue.Equals(mTarget)) {
            // We found the right ID, signal to compile the 
            // embedded stylesheet.
            mEmbedStatus = eInEmbed;
        }
    }
    const txElementHandler* handler;
    do {
        handler = isInstruction ?
                  mHandlerTable->find(aNamespaceID, aLocalName) :
                  mHandlerTable->mLREHandler;

        rv = (handler->mStartFunction)(aNamespaceID, aLocalName, aPrefix,
                                       aAttributes, aAttrCount, *this);
    } while (rv == NS_XSLT_GET_NEW_HANDLER);

    NS_ENSURE_SUCCESS(rv, rv);

    rv = pushPtr(NS_CONST_CAST(txElementHandler*, handler));
    NS_ENSURE_SUCCESS(rv, rv);

    mElementContext->mDepth++;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class txStylesheetCompilerState [friend]

Definition at line 202 of file txStylesheetCompiler.h.


Member Data Documentation

Definition at line 248 of file txStylesheetCompiler.h.

Definition at line 168 of file txStylesheetCompiler.h.

Definition at line 161 of file txStylesheetCompiler.h.

Definition at line 162 of file txStylesheetCompiler.h.

Definition at line 180 of file txStylesheetCompiler.h.

Definition at line 159 of file txStylesheetCompiler.h.

enum { ... } txStylesheetCompilerState::mEmbedStatus [protected, inherited]

Definition at line 158 of file txStylesheetCompiler.h.

Definition at line 167 of file txStylesheetCompiler.h.

Definition at line 179 of file txStylesheetCompiler.h.

Definition at line 181 of file txStylesheetCompiler.h.

Definition at line 166 of file txStylesheetCompiler.h.

Definition at line 182 of file txStylesheetCompiler.h.

Definition at line 247 of file txStylesheetCompiler.h.

Definition at line 163 of file txStylesheetCompiler.h.

Definition at line 160 of file txStylesheetCompiler.h.

Definition at line 249 of file txStylesheetCompiler.h.

Definition at line 157 of file txStylesheetCompiler.h.

Definition at line 178 of file txStylesheetCompiler.h.

Definition at line 170 of file txStylesheetCompiler.h.


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