Back to index

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

Implementation of an In-Memory DOM based XML parser. More...

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

List of all members.

Public Member Functions

nsresult parse (istream &aInputStream, const nsAString &aUri)
 Parses the given input stream and returns a DOM Document.
const nsAString & getErrorString ()
void StartElement (const XML_Char *aName, const XML_Char **aAtts)
 Expat handlers.
void EndElement (const XML_Char *aName)
void CharacterData (const XML_Char *aChars, int aLength)
int ExternalEntityRef (const XML_Char *aContext, const XML_Char *aBase, const XML_Char *aSystemId, const XML_Char *aPublicId)
virtual nsrefcnt AddRef ()=0
virtual nsrefcnt Release ()=0
virtual nsresult loadURI (const nsAString &aUri, const nsAString &aReferrerUri, txStylesheetCompiler *aCompiler)=0
virtual void onDoneCompiling (txStylesheetCompiler *aCompiler, nsresult aResult, const PRUnichar *aErrorText=nsnull, const PRUnichar *aParam=nsnull)=0

Public Attributes

 TX_DECL_ACOMPILEOBSERVER
nsRefPtr< txStylesheetCompilermCompiler

Protected Member Functions

void createErrorString ()

Protected Attributes

nsString mErrorString
nsresult mRV
XML_Parser mExpatParser
nsAutoRefCnt mRefCnt

Detailed Description

Implementation of an In-Memory DOM based XML parser.

The actual XML parsing is provided by EXPAT.

Definition at line 50 of file txStandaloneStylesheetCompiler.cpp.


Member Function Documentation

virtual nsrefcnt txACompileObserver::AddRef ( ) [pure virtual, inherited]

Implemented in txStylesheetCompiler.

void txDriver::CharacterData ( const XML_Char aChars,
int  aLength 
)

Definition at line 258 of file txStandaloneStylesheetCompiler.cpp.

{
    const PRUnichar* pChars = NS_STATIC_CAST(const PRUnichar*, aChars);
    // ignore rv, as this expat handler returns void
    nsresult rv = mCompiler->characters(Substring(pChars, pChars + aLength));
    if (NS_FAILED(rv)) {
        mCompiler->cancel(rv);
    }
}

Here is the call graph for this function:

Definition at line 318 of file txStandaloneStylesheetCompiler.cpp.

{
    XML_Error errCode = XML_GetErrorCode(mExpatParser);
    mErrorString.AppendWithConversion(XML_ErrorString(errCode));
    mErrorString.AppendLiteral(" at line ");
    mErrorString.AppendInt(XML_GetCurrentLineNumber(mExpatParser));
    mErrorString.AppendLiteral(" in ");
    mErrorString.Append((const PRUnichar*)XML_GetBase(mExpatParser));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 249 of file txStandaloneStylesheetCompiler.cpp.

{
    nsresult rv = mCompiler->endElement();
    if (NS_FAILED(rv)) {
        mCompiler->cancel(rv);
    }
}
int txDriver::ExternalEntityRef ( const XML_Char aContext,
const XML_Char aBase,
const XML_Char aSystemId,
const XML_Char aPublicId 
)

Definition at line 269 of file txStandaloneStylesheetCompiler.cpp.

{
    if (aPublicId) {
        // not supported, this is "http://some.site.net/foo.dtd" stuff
        return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
    }
    nsAutoString absUrl;
    URIUtils::resolveHref(nsDependentString((PRUnichar*)aSystemId),
                          nsDependentString((PRUnichar*)aBase), absUrl);
    istream* extInput = URIUtils::getInputStream(absUrl, mErrorString);
    if (!extInput) {
        return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
    }
    XML_Parser parent = mExpatParser;
    mExpatParser = 
        XML_ExternalEntityParserCreate(mExpatParser, aContext, nsnull);
    if (!mExpatParser) {
        mExpatParser = parent;
        delete extInput;
        return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
    }
    XML_SetBase(mExpatParser, absUrl.get());

    const int bufSize = 1024;
    char buffer[bufSize];
    int result;
    PRBool done;
    do {
        extInput->read(buffer, bufSize);
        done = extInput->eof();
        if (!(result =
              XML_Parse(mExpatParser, buffer,  extInput->gcount(), done))) {
            createErrorString();
            mErrorString.Append(PRUnichar('\n'));
            done = MB_TRUE;
        }
    } while (!done);

    delete extInput;
    XML_ParserFree(mExpatParser);

    mExpatParser = parent;

    return result;
}

Here is the call graph for this function:

Definition at line 221 of file txStandaloneStylesheetCompiler.cpp.

{
    return mErrorString;
}
virtual nsresult txACompileObserver::loadURI ( const nsAString &  aUri,
const nsAString &  aReferrerUri,
txStylesheetCompiler aCompiler 
) [pure virtual, inherited]

Implemented in txStylesheetCompiler.

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

Implemented in txStylesheetCompiler.

nsresult txDriver::parse ( istream &  aInputStream,
const nsAString &  aUri 
)

Parses the given input stream and returns a DOM Document.

A NULL pointer will be returned if errors occurred

Definition at line 171 of file txStandaloneStylesheetCompiler.cpp.

{
    mErrorString.Truncate();
    if (!aInputStream) {
        mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered.");
        return NS_ERROR_FAILURE;
    }
    mExpatParser = XML_ParserCreate(nsnull);
    if (!mExpatParser) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    XML_SetUserData(mExpatParser, this);
    XML_SetElementHandler(mExpatParser, startElement, endElement);
    XML_SetCharacterDataHandler(mExpatParser, charData);
#ifdef XML_DTD
    XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS);
#endif
    XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler);
    XML_SetExternalEntityRefHandlerArg(mExpatParser, this);
    XML_SetBase(mExpatParser,
                (const XML_Char*)(PromiseFlatString(aUri).get()));

    const int bufferSize = 1024;
    char buf[bufferSize];
    PRBool done;
    int success;
    mRV = NS_OK;
    do {
        aInputStream.read(buf, bufferSize);
        done = aInputStream.eof();
        success = XML_Parse(mExpatParser, buf, aInputStream.gcount(), done);
        // mRV is set in onDoneCompiling in case of an error
        if (!success || NS_FAILED(mRV)) {
            createErrorString();
            done = MB_TRUE;
        }
    } while (!done);
    aInputStream.clear();

    // clean up
    XML_ParserFree(mExpatParser);
    mCompiler->doneLoading();
    if (!success) {
        return NS_ERROR_FAILURE;
    }
    return mRV;
}

Here is the call graph for this function:

virtual nsrefcnt txACompileObserver::Release ( ) [pure virtual, inherited]

Implemented in txStylesheetCompiler.

void txDriver::StartElement ( const XML_Char aName,
const XML_Char **  aAtts 
)

Expat handlers.

Definition at line 227 of file txStandaloneStylesheetCompiler.cpp.

{
    PRInt32 attcount = 0;
    const XML_Char** atts = aAtts;
    while (*atts) {
        ++atts;
        ++attcount;
    }
    PRInt32 idOffset = XML_GetIdAttributeIndex(mExpatParser);
    nsresult rv =
        mCompiler->startElement(NS_STATIC_CAST(const PRUnichar*, aName), 
                                NS_STATIC_CAST(const PRUnichar**, aAtts),
                                attcount/2, idOffset);
    if (NS_FAILED(rv)) {
        PR_LOG(txLog::xslt, PR_LOG_ALWAYS, 
               ("compile failed at %i with %x\n",
                XML_GetCurrentLineNumber(mExpatParser), rv));
        mCompiler->cancel(rv);
    }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 68 of file txStandaloneStylesheetCompiler.cpp.

Definition at line 71 of file txStandaloneStylesheetCompiler.cpp.

Definition at line 74 of file txStandaloneStylesheetCompiler.cpp.

Definition at line 75 of file txStandaloneStylesheetCompiler.cpp.

nsresult txDriver::mRV [protected]

Definition at line 73 of file txStandaloneStylesheetCompiler.cpp.

Definition at line 66 of file txStandaloneStylesheetCompiler.cpp.


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