Back to index

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

#include <nsExpatDriver.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIDTD
NS_DECL_NSITOKENIZER 
nsExpatDriver ()
virtual ~nsExpatDriver ()
int HandleExternalEntityRef (const PRUnichar *aOpenEntityNames, const PRUnichar *aBase, const PRUnichar *aSystemId, const PRUnichar *aPublicId)
nsresult HandleStartElement (const PRUnichar *aName, const PRUnichar **aAtts)
nsresult HandleEndElement (const PRUnichar *aName)
nsresult HandleCharacterData (const PRUnichar *aCData, const PRUint32 aLength)
nsresult HandleComment (const PRUnichar *aName)
nsresult HandleProcessingInstruction (const PRUnichar *aTarget, const PRUnichar *aData)
nsresult HandleXMLDeclaration (const PRUnichar *aVersion, const PRUnichar *aEncoding, PRInt32 aStandalone)
nsresult HandleDefault (const PRUnichar *aData, const PRUint32 aLength)
nsresult HandleStartCdataSection ()
nsresult HandleEndCdataSection ()
nsresult HandleStartDoctypeDecl (const PRUnichar *aDoctypeName, const PRUnichar *aSysid, const PRUnichar *aPubid, PRBool aHasInternalSubset)
nsresult HandleEndDoctypeDecl ()
nsresult HandleStartNamespaceDecl (const PRUnichar *aPrefix, const PRUnichar *aUri)
nsresult HandleEndNamespaceDecl (const PRUnichar *aPrefix)
nsresult HandleNotationDecl (const PRUnichar *aNotationName, const PRUnichar *aBase, const PRUnichar *aSysid, const PRUnichar *aPubid)
nsresult HandleUnparsedEntityDecl (const PRUnichar *aEntityName, const PRUnichar *aBase, const PRUnichar *aSysid, const PRUnichar *aPubid, const PRUnichar *aNotationName)
 NS_IMETHOD_ (const nsIID &) GetMostDerivedIID(void) const =0
 NS_IMETHOD_ (eAutoDetectResult) CanParse(CParserContext &aParserContext)=0
 This method is called to determine if the given DTD can parse a document in a given source-type.
 NS_IMETHOD_ (PRBool) CanContain(PRInt32 aParent
 This method is called to determine whether or not a tag of one type can contain a tag of another type.
 NS_IMETHOD_ (PRBool) IsContainer(PRInt32 aTag) const =0
 This method gets called to determine whether a given tag is itself a container.
 NS_IMETHOD_ (void) Terminate()=0
 Use this id you want to stop the building content model --------------[ Sets DTD to STOP mode ]---------------- It's recommended to use this method in accordance with the parser's terminate() method.
 NS_IMETHOD_ (PRInt32) GetType()=0
NS_IMETHOD CreateNewInstance (nsIDTD **aInstancePtrResult)=0
 Call this method if you want the DTD to construct a clone of itself.
NS_IMETHOD WillBuildModel (const CParserContext &aParserContext, nsITokenizer *aTokenizer, nsIContentSink *aSink)=0
NS_IMETHOD DidBuildModel (nsresult anErrorCode, PRBool aNotifySink, nsIParser *aParser, nsIContentSink *aSink)=0
 Called by the parser after the parsing process has concluded gess5/18/98.
NS_IMETHOD BuildModel (nsIParser *aParser, nsITokenizer *aTokenizer, nsITokenObserver *anObserver, nsIContentSink *aSink)=0
 Called by the parser after the parsing process has concluded gess5/18/98.
NS_IMETHOD HandleToken (CToken *aToken, nsIParser *aParser)=0
 Called during model building phase of parse process.
NS_IMETHOD WillResumeParse (nsIContentSink *aSink)=0
 If the parse process gets interrupted midway, this method is called by the parser prior to resuming the process.
NS_IMETHOD WillInterruptParse (nsIContentSink *aSink)=0
 If the parse process gets interrupted, this method is called by the parser to notify the DTD that interruption will occur.
NS_IMETHOD CollectSkippedContent (PRInt32 aTag, nsAString &aContent, PRInt32 &aLineNo)=0
NS_IMETHOD WillTokenize (PRBool aIsFinalChunk, nsTokenAllocator *aTokenAllocator)=0
NS_IMETHOD ConsumeToken (nsScanner &aScanner, PRBool &aFlushTokens)=0
NS_IMETHOD DidTokenize (PRBool aIsFinalChunk)=0
 NS_IMETHOD_ (CToken *) PushTokenFront(CToken *aToken)=0
 NS_IMETHOD_ (PRInt32) GetCount(void)=0
 NS_IMETHOD_ (nsTokenAllocator *) GetTokenAllocator(void)=0
 NS_IMETHOD_ (void) PrependTokens(nsDeque &aDeque)=0
NS_IMETHOD CopyState (nsITokenizer *aTokenizer)=0

Public Attributes

PRInt32 aChild const = 0

Private Member Functions

nsresult OpenInputStreamFromExternalDTD (const PRUnichar *aFPIStr, const PRUnichar *aURLStr, const PRUnichar *aBaseURL, nsIInputStream **aStream, nsAString &aAbsURL)
nsresult ParseBuffer (const char *aBuffer, PRUint32 aLength, PRBool aIsFinal)
nsresult HandleError ()
void GetLine (const char *aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString &aLine)

Private Attributes

XML_Parser mExpatParser
nsString mLastLine
nsString mCDataText
nsString mDoctypeName
nsString mSystemID
nsString mPublicID
nsString mInternalSubset
PRPackedBool mInCData
PRPackedBool mInInternalSubset
PRPackedBool mInExternalDTD
PRInt32 mBytePosition
nsresult mInternalState
PRUint32 mBytesParsed
nsCOMPtr< nsIExpatSinkmSink
nsCOMPtr< nsIExtendedExpatSinkmExtendedSink
const nsCatalogDatamCatalogData
nsString mURISpec

Detailed Description

Definition at line 53 of file nsExpatDriver.h.


Constructor & Destructor Documentation

Definition at line 402 of file nsExpatDriver.cpp.


Member Function Documentation

NS_IMETHOD nsIDTD::BuildModel ( nsIParser aParser,
nsITokenizer aTokenizer,
nsITokenObserver anObserver,
nsIContentSink aSink 
) [pure virtual, inherited]

Called by the parser after the parsing process has concluded gess5/18/98.

Parameters:
anErrorCode- contains error code resulting from parse process
Returns:

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::CollectSkippedContent ( PRInt32  aTag,
nsAString &  aContent,
PRInt32 aLineNo 
) [pure virtual, inherited]

Here is the caller graph for this function:

NS_IMETHOD nsITokenizer::ConsumeToken ( nsScanner aScanner,
PRBool aFlushTokens 
) [pure virtual, inherited]

Here is the caller graph for this function:

NS_IMETHOD nsITokenizer::CopyState ( nsITokenizer aTokenizer) [pure virtual, inherited]

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::CreateNewInstance ( nsIDTD **  aInstancePtrResult) [pure virtual, inherited]

Call this method if you want the DTD to construct a clone of itself.

gess7/23/98

Parameters:
@return

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::DidBuildModel ( nsresult  anErrorCode,
PRBool  aNotifySink,
nsIParser aParser,
nsIContentSink aSink 
) [pure virtual, inherited]

Called by the parser after the parsing process has concluded gess5/18/98.

Parameters:
anErrorCode- contains error code resulting from parse process
Returns:

Here is the caller graph for this function:

NS_IMETHOD nsITokenizer::DidTokenize ( PRBool  aIsFinalChunk) [pure virtual, inherited]

Here is the caller graph for this function:

void nsExpatDriver::GetLine ( const char *  aSourceBuffer,
PRUint32  aLength,
PRUint32  aOffset,
nsString aLine 
) [private]

Definition at line 451 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  if (mInCData) {
    mCDataText.Append(aValue, aLength);
  }
  else if (mSink) {
    mInternalState = mSink->HandleCharacterData(aValue, aLength);
  }

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 467 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  if (mInExternalDTD) {
    // Ignore comments from external DTDs
    return NS_OK;
  }

  if (mInInternalSubset) {
    mInternalSubset.AppendLiteral("<!--");
    mInternalSubset.Append(aValue);
    mInternalSubset.AppendLiteral("-->");
  }
  else if (mSink) {
    mInternalState = mSink->HandleComment(aValue);
  }

  return NS_OK;
}

Definition at line 526 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  if (mInExternalDTD) {
    // Ignore newlines in external DTDs
    return NS_OK;
  }

  if (mInInternalSubset) {
    mInternalSubset.Append(aValue, aLength);
  }
  else if (mSink) {
    static const PRUnichar newline[] = { '\n', '\0' };
    PRUint32 i;
    for (i = 0; i < aLength && NS_SUCCEEDED(mInternalState); ++i) {
      if (aValue[i] == '\n' || aValue[i] == '\r') {
        mInternalState = mSink->HandleCharacterData(newline, 1);
      }
    }
  }

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 561 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  mInCData = PR_FALSE;
  if (mSink) {
    mInternalState = mSink->HandleCDataSection(mCDataText.get(),
                                               mCDataText.Length());
  }
  mCDataText.Truncate();

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 652 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  mInInternalSubset = PR_FALSE;

  if (mSink) {
    // let the sink know any additional knowledge that we have about the
    // document (currently, from bug 124570, we only expect to pass additional
    // agent sheets needed to layout the XML vocabulary of the document)
    nsCOMPtr<nsIURI> data;
    if (mCatalogData && mCatalogData->mAgentSheet) {
      NS_NewURI(getter_AddRefs(data), mCatalogData->mAgentSheet);
    }

    // Note: mInternalSubset already doesn't include the [] around it.
    mInternalState = mSink->HandleDoctypeDecl(mInternalSubset, mDoctypeName,
                                              mSystemID, mPublicID, data);
    
  }
  
  mInternalSubset.SetCapacity(0);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 437 of file nsExpatDriver.cpp.

Here is the call graph for this function:

Definition at line 587 of file nsExpatDriver.cpp.

{
  if (mExtendedSink) {
    mInternalState = mExtendedSink->HandleEndNamespaceDecl(aPrefix);
  }
  return NS_OK;
}

Expat can send the following: localName namespaceURI<separator>localName namespaceURI<separator>localName<separator>prefix

and we use 0xFFFF for the <separator>.

Definition at line 855 of file nsExpatDriver.cpp.

{
  PRInt32 code = XML_GetErrorCode(mExpatParser);
  NS_WARN_IF_FALSE(code > XML_ERROR_NONE, "unexpected XML error code");

  // Map Expat error code to an error string
  // XXX Deal with error returns.
  nsAutoString description;
  nsParserMsgUtils::GetLocalizedStringByID(XMLPARSER_PROPERTIES, code,
                                           description);

  if (code == XML_ERROR_TAG_MISMATCH) {
    const PRUnichar *mismatch = MOZ_XML_GetMismatchedTag(mExpatParser);
    const PRUnichar *uriEnd = nsnull;
    const PRUnichar *nameEnd = nsnull;
    const PRUnichar *pos;
    for (pos = mismatch; *pos; ++pos) {
      if (*pos == kExpatSeparatorChar) {
        if (uriEnd) {
          nameEnd = pos;
        }
        else {
          uriEnd = pos;
        }
      }
    }

    nsAutoString tagName;
    if (uriEnd && nameEnd) {
      // We have a prefix.
      tagName.Append(nameEnd + 1, pos - nameEnd - 1);
      tagName.Append(PRUnichar(':'));
    }
    const PRUnichar *nameStart = uriEnd ? uriEnd + 1 : mismatch;
    tagName.Append(nameStart, (nameEnd ? nameEnd : pos) - nameStart);
    
    nsAutoString msg;
    nsParserMsgUtils::GetLocalizedStringByName(XMLPARSER_PROPERTIES,
                                               "Expected", msg);

    // . Expected: </%S>.
    PRUnichar *message = nsTextFormatter::smprintf(msg.get(), tagName.get());
    if (!message) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    description.Append(message);

    nsTextFormatter::smprintf_free(message);
  }

  // Adjust the column number so that it is one based rather than zero based.
  PRInt32 colNumber = XML_GetCurrentColumnNumber(mExpatParser) + 1;
  PRInt32 lineNumber = XML_GetCurrentLineNumber(mExpatParser);

  nsAutoString errorText;
  CreateErrorText(description.get(), XML_GetBase(mExpatParser), lineNumber,
                  colNumber, errorText);

  nsAutoString sourceText;
  CreateSourceText(colNumber, mLastLine.get(), sourceText);

  nsCOMPtr<nsIConsoleService> cs
    (do_GetService(NS_CONSOLESERVICE_CONTRACTID));
  nsCOMPtr<nsIScriptError> serr(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
  if (serr && cs) {
    if (NS_SUCCEEDED(serr->Init(description.get(),
                                mURISpec.get(),
                                sourceText.get(),
                                lineNumber, colNumber,
                                nsIScriptError::errorFlag, "malformed-xml")))
      cs->LogMessage(serr);
  }

  NS_ASSERTION(mSink, "no sink?");
  if (mSink) {
    mSink->ReportError(errorText.get(), sourceText.get());
  }

  return NS_ERROR_HTMLPARSER_STOPPARSING;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsExpatDriver::HandleExternalEntityRef ( const PRUnichar aOpenEntityNames,
const PRUnichar aBase,
const PRUnichar aSystemId,
const PRUnichar aPublicId 
)

Definition at line 701 of file nsExpatDriver.cpp.

{
  if (mInInternalSubset && !mInExternalDTD && openEntityNames) {
    mInternalSubset.Append(PRUnichar('%'));
    mInternalSubset.Append(nsDependentString(openEntityNames));
    mInternalSubset.Append(PRUnichar(';'));
  }

  // Load the external entity into a buffer.
  nsCOMPtr<nsIInputStream> in;
  nsAutoString absURL;
  nsresult rv = OpenInputStreamFromExternalDTD(publicId, systemId, base,
                                               getter_AddRefs(in), absURL);
  NS_ENSURE_SUCCESS(rv, 1);

  nsCOMPtr<nsIUnicharInputStream> uniIn;
  rv = NS_NewUTF8ConverterStream(getter_AddRefs(uniIn), in, 1024);
  NS_ENSURE_SUCCESS(rv, 1);

  int result = 1;
  if (uniIn) {
    XML_Parser entParser = XML_ExternalEntityParserCreate(mExpatParser, 0,
                                                          kUTF16);
    if (entParser) {
      XML_SetBase(entParser, absURL.get());

      mInExternalDTD = PR_TRUE;

      PRUint32 totalRead;
      do {
        rv = uniIn->ReadSegments(ExternalDTDStreamReaderFunc, entParser,
                                 PRUint32(-1), &totalRead);
      } while (NS_SUCCEEDED(rv) && totalRead > 0);

      result = XML_Parse(entParser, nsnull, 0, 1);

      mInExternalDTD = PR_FALSE;

      XML_ParserFree(entParser);
    }
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsExpatDriver::HandleNotationDecl ( const PRUnichar aNotationName,
const PRUnichar aBase,
const PRUnichar aSysid,
const PRUnichar aPubid 
)

Definition at line 596 of file nsExpatDriver.cpp.

{
  if (mExtendedSink) {
    mInternalState = mExtendedSink->HandleNotationDecl(aNotationName,
                                                       aSysid,
                                                       aPubid);
  }
  return NS_OK;
}

Definition at line 489 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  if (mInExternalDTD) {
    // Ignore PIs in external DTDs for now.  Eventually we want to
    // pass them to the sink in a way that doesn't put them in the DOM
    return NS_OK;
  }

  if (mInInternalSubset) {
    mInternalSubset.AppendLiteral("<?");
    mInternalSubset.Append(aTarget);
    mInternalSubset.Append(' ');
    mInternalSubset.Append(aData);
    mInternalSubset.AppendLiteral("?>");
  }
  else if (mSink &&
           mSink->HandleProcessingInstruction(aTarget, aData) ==
           NS_ERROR_HTMLPARSER_BLOCK) {
    mInternalState = NS_ERROR_HTMLPARSER_BLOCK;
    MOZ_XML_StopParser(mExpatParser, XML_TRUE);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 553 of file nsExpatDriver.cpp.

{
  mInCData = PR_TRUE;

  return NS_OK;
}
nsresult nsExpatDriver::HandleStartDoctypeDecl ( const PRUnichar aDoctypeName,
const PRUnichar aSysid,
const PRUnichar aPubid,
PRBool  aHasInternalSubset 
)

Definition at line 626 of file nsExpatDriver.cpp.

{
  mDoctypeName = aDoctypeName;
  mSystemID = aSysid;
  mPublicID = aPubid;

  if (mExtendedSink) {
    mInternalState = mExtendedSink->HandleStartDTD(aDoctypeName,
                                                   aSysid, aPubid);
  }

  if (aHasInternalSubset) {
    // Consuming a huge internal subset translates to numerous
    // allocations. In an effort to avoid too many allocations
    // setting mInternalSubset's capacity to be 1K ( just a guesstimate! ).
    mInInternalSubset = PR_TRUE;
    mInternalSubset.SetCapacity(1024);
  }

  return NS_OK;
}

Definition at line 410 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(mSink, "content sink not found!");

  // Calculate the total number of elements in aAtts.
  // XML_GetSpecifiedAttributeCount will only give us the number of specified
  // attrs (twice that number, actually), so we have to check for default attrs
  // ourselves.
  PRUint32 attrArrayLength;
  for (attrArrayLength = XML_GetSpecifiedAttributeCount(mExpatParser);
       aAtts[attrArrayLength];
       attrArrayLength += 2) {
    // Just looping till we find out what the length is
  }

  if (mSink) {
    mSink->HandleStartElement(aValue, aAtts,
                              attrArrayLength,
                              XML_GetIdAttributeIndex(mExpatParser),
                              XML_GetCurrentLineNumber(mExpatParser));
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 576 of file nsExpatDriver.cpp.

{
  if (mExtendedSink) {
    mInternalState = mExtendedSink->HandleStartNamespaceDecl(aPrefix,
                                                            aUri);
  }
  return NS_OK;
}
NS_IMETHOD nsIDTD::HandleToken ( CToken aToken,
nsIParser aParser 
) [pure virtual, inherited]

Called during model building phase of parse process.

Each token created during the parse phase is stored in a deque (in the parser) and are passed to this method so that the DTD can process the token. Ultimately, the DTD will transform given token into calls onto a contentsink. gess 3/25/98

Parameters:
aToken-- token object to be put into content model
Returns:
error code (usually 0)

Here is the caller graph for this function:

nsresult nsExpatDriver::HandleUnparsedEntityDecl ( const PRUnichar aEntityName,
const PRUnichar aBase,
const PRUnichar aSysid,
const PRUnichar aPubid,
const PRUnichar aNotationName 
)

Definition at line 610 of file nsExpatDriver.cpp.

{
  if (mExtendedSink) {
    mInternalState = mExtendedSink->HandleUnparsedEntityDecl(aEntityName,
                                                             aSysid,
                                                             aPubid,
                                                             aNotationName);
  }
  return NS_OK;
}
nsresult nsExpatDriver::HandleXMLDeclaration ( const PRUnichar aVersion,
const PRUnichar aEncoding,
PRInt32  aStandalone 
)

Definition at line 518 of file nsExpatDriver.cpp.

{
  return mSink->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
}

Here is the caller graph for this function:

nsITokenizer::NS_IMETHOD_ ( CToken ) [pure virtual, inherited]
nsITokenizer::NS_IMETHOD_ ( PRInt32  ) [pure virtual, inherited]
nsITokenizer::NS_IMETHOD_ ( nsTokenAllocator ) [pure virtual, inherited]
nsITokenizer::NS_IMETHOD_ ( void  ) [pure virtual, inherited]
nsIDTD::NS_IMETHOD_ ( const nsIID ) const [pure virtual, inherited]
nsIDTD::NS_IMETHOD_ ( eAutoDetectResult  ) [pure virtual, inherited]

This method is called to determine if the given DTD can parse a document in a given source-type.

NOTE: Parsing always assumes that the end result will involve storing the result in the main content model.

Parameters:
aParserContext-- the context for this document (knows the content type, document type, parser command, etc).
Returns:
eUnknownDetect if you don't know how to parse it, eValidDetect if you do, but someone may have a better idea, ePrimaryDetect if you think you know best
nsIDTD::NS_IMETHOD_ ( PRBool  ) [inherited]

This method is called to determine whether or not a tag of one type can contain a tag of another type.

gess 3/25/98

Parameters:
aParent-- int tag of parent container
aChild-- int tag of child container
Returns:
PR_TRUE if parent can contain child
nsIDTD::NS_IMETHOD_ ( PRBool  ) const [pure virtual, inherited]

This method gets called to determine whether a given tag is itself a container.

gess 3/25/98

Parameters:
aTag-- tag to test for containership
Returns:
PR_TRUE if given tag can contain other tags
nsIDTD::NS_IMETHOD_ ( void  ) [pure virtual, inherited]

Use this id you want to stop the building content model --------------[ Sets DTD to STOP mode ]---------------- It's recommended to use this method in accordance with the parser's terminate() method.

harishd 07/22/99

Parameters:
@return
nsIDTD::NS_IMETHOD_ ( PRInt32  ) [pure virtual, inherited]
nsresult nsExpatDriver::OpenInputStreamFromExternalDTD ( const PRUnichar aFPIStr,
const PRUnichar aURLStr,
const PRUnichar aBaseURL,
nsIInputStream **  aStream,
nsAString &  aAbsURL 
) [private]

Definition at line 750 of file nsExpatDriver.cpp.

{
  nsCOMPtr<nsIURI> baseURI;
  nsresult rv = NS_NewURI(getter_AddRefs(baseURI),
                          NS_ConvertUTF16toUTF8(aBaseURL));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIURI> uri;
  rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(aURLStr), nsnull,
                 baseURI);
  NS_ENSURE_SUCCESS(rv, rv);

  // check if it is alright to load this uri
  PRBool isChrome = PR_FALSE;
  uri->SchemeIs("chrome", &isChrome);
  if (!isChrome) {
    // since the url is not a chrome url, check to see if we can map the DTD
    // to a known local DTD, or if a DTD file of the same name exists in the
    // special DTD directory
    if (aFPIStr) {
      // see if the Formal Public Identifier (FPI) maps to a catalog entry
      mCatalogData = LookupCatalogData(aFPIStr);
    }

    nsCOMPtr<nsIURI> localURI;
    if (!IsLoadableDTD(mCatalogData, uri, getter_AddRefs(localURI))) {
      return NS_ERROR_NOT_IMPLEMENTED;
    }

    localURI.swap(uri);
  }

  rv = NS_OpenURI(aStream, uri);

  nsCAutoString absURL;
  uri->GetSpec(absURL);

  CopyUTF8toUTF16(absURL, aAbsURL);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsExpatDriver::ParseBuffer ( const char *  aBuffer,
PRUint32  aLength,
PRBool  aIsFinal 
) [private]

Definition at line 947 of file nsExpatDriver.cpp.

{
  NS_ASSERTION((aBuffer && aLength != 0) || (!aBuffer && aLength == 0), "?");
  NS_ASSERTION(aLength % sizeof(PRUnichar) == 0,
               "We can have a PRUnichar spanning chunks?");
  NS_PRECONDITION(mBytesParsed % sizeof(PRUnichar) == 0,
                  "Parsed part of a PRUnichar?");
  NS_PRECONDITION(mBytePosition % sizeof(PRUnichar) == 0,
                  "Parsed part of a PRUnichar?");
  NS_PRECONDITION(XML_GetCurrentByteIndex(mExpatParser) == -1 ||
                  XML_GetCurrentByteIndex(mExpatParser) % sizeof(PRUnichar) == 0,
                  "Consumed part of a PRUnichar?");

  if (mExpatParser && mInternalState == NS_OK) {
    XML_Bool parsedAll = XML_Parse(mExpatParser, aBuffer, aLength, aIsFinal);

    PRInt32 parserBytesConsumed = XML_GetCurrentByteIndex(mExpatParser);

    NS_ASSERTION(parserBytesConsumed == -1 ||
                 parserBytesConsumed % sizeof(PRUnichar) == 0,
                 "Consumed part of a PRUnichar?");

    // Now figure out the startOffset for appending to mLastLine -- this
    // calculation is the same no matter whether we saw an error, got blocked,
    // parsed it all but didn't consume it all, or whatever else happened.
    const PRUnichar* const buffer =
      NS_REINTERPRET_CAST(const PRUnichar*, aBuffer);
    PRUint32 startOffset;
    // we assume that if expat failed to consume some bytes last time it won't
    // consume them this time without also consuming some bytes from aBuffer.
    // Note that if expat consumed everything we passed it, it will have nulled
    // out all its internal pointers to data, so parserBytesConsumed will come
    // out -1 in that case.
    if (buffer) {
      if (parserBytesConsumed < 0 ||
          (PRUint32)parserBytesConsumed >= mBytesParsed) {
        // We consumed something
        if (parserBytesConsumed < 0) {
          NS_ASSERTION(parserBytesConsumed == -1,
                       "Unexpected negative value?");
          // Consumed everything.
          startOffset = aLength / sizeof(PRUnichar);
        }
        else {
          // Consumed something, but not all
          NS_ASSERTION(parserBytesConsumed - mBytesParsed <= aLength,
                       "Too many bytes consumed?");
          startOffset = (parserBytesConsumed - mBytesParsed) /
                        sizeof(PRUnichar);
        }
        // Now startOffset points one past the last PRUnichar consumed in
        // buffer
        while (startOffset-- != 0) {
          if (buffer[startOffset] == '\n' || buffer[startOffset] == '\r') {
            mLastLine.Truncate();
            break;
          }
        }
        // Now startOffset is pointing to the last newline we consumed (or to
        // -1 if there weren't any consumed in this chunk).  Make startOffset
        // point to the first char of the first line whose end we haven't
        // consumed yet.
        ++startOffset;
      }
      else {
        // Didn't parse anything new.  So append all of aBuffer.
        startOffset = 0;
      }
    }

    if (!parsedAll) {
      if (mInternalState == NS_ERROR_HTMLPARSER_BLOCK ||
          mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING) {
        NS_ASSERTION((PRUint32)parserBytesConsumed >= mBytesParsed,
                     "How'd this happen?");
        mBytePosition = parserBytesConsumed - mBytesParsed;
        mBytesParsed = parserBytesConsumed;
        if (buffer) {
          PRUint32 endOffset = mBytePosition / sizeof(PRUnichar);
          NS_ASSERTION(startOffset <= endOffset,
                       "Something is confused about what we've consumed");
          // Only append the data we actually parsed.  The rest will come
          // through this method again.
          mLastLine.Append(Substring(buffer + startOffset,
                                     buffer + endOffset));
        }
      }
      else {
        // An error occured, look for the next newline after the last one we
        // consumed.
        PRUint32 length = aLength / sizeof(PRUnichar);
        if (buffer) {
          PRUint32 endOffset = startOffset;
          while (endOffset < length && buffer[endOffset] != '\n' &&
                 buffer[endOffset] != '\r') {
            ++endOffset;
          }
          mLastLine.Append(Substring(buffer + startOffset,
                                     buffer + endOffset));
        }
        HandleError();
        mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
      }

      return mInternalState;
    }

    if (!aIsFinal && buffer) {
      mLastLine.Append(Substring(buffer + startOffset,
                                 buffer + aLength / sizeof(PRUnichar)));
    }
    mBytesParsed += aLength;
    mBytePosition = 0;
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD nsIDTD::WillBuildModel ( const CParserContext aParserContext,
nsITokenizer aTokenizer,
nsIContentSink aSink 
) [pure virtual, inherited]

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::WillInterruptParse ( nsIContentSink aSink) [pure virtual, inherited]

If the parse process gets interrupted, this method is called by the parser to notify the DTD that interruption will occur.

gess5/18/98

Returns:
ignored

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::WillResumeParse ( nsIContentSink aSink) [pure virtual, inherited]

If the parse process gets interrupted midway, this method is called by the parser prior to resuming the process.

gess5/18/98

Returns:
ignored

Here is the caller graph for this function:

NS_IMETHOD nsITokenizer::WillTokenize ( PRBool  aIsFinalChunk,
nsTokenAllocator aTokenAllocator 
) [pure virtual, inherited]

Here is the caller graph for this function:


Member Data Documentation

PRInt32 aChild nsIDTD::const = 0 [inherited]

Definition at line 178 of file nsIDTD.h.

Definition at line 124 of file nsExpatDriver.h.

Definition at line 128 of file nsExpatDriver.h.

Definition at line 131 of file nsExpatDriver.h.

Definition at line 113 of file nsExpatDriver.h.

Definition at line 115 of file nsExpatDriver.h.

Definition at line 111 of file nsExpatDriver.h.

Definition at line 130 of file nsExpatDriver.h.

Definition at line 119 of file nsExpatDriver.h.

Definition at line 121 of file nsExpatDriver.h.

Definition at line 120 of file nsExpatDriver.h.

Definition at line 125 of file nsExpatDriver.h.

Definition at line 118 of file nsExpatDriver.h.

Definition at line 112 of file nsExpatDriver.h.

Definition at line 117 of file nsExpatDriver.h.

Definition at line 129 of file nsExpatDriver.h.

Definition at line 116 of file nsExpatDriver.h.

Definition at line 132 of file nsExpatDriver.h.


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