Back to index

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

#include <nsSAXXMLReader.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIEXPATSINK
NS_DECL_NSIEXTENDEDEXPATSINK
NS_DECL_NSISAXXMLREADER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER 
nsSAXXMLReader ()
NS_IMETHOD WillBuildModel ()
 This method gets called when the parser begins the process of building the content model via the content sink.
NS_IMETHOD DidBuildModel ()
 This method gets called when the parser concludes the process of building the content model via the content sink.
NS_IMETHOD SetParser (nsIParser *aParser)
 This method gets called by the parser so that the content sink can retain a reference to the parser.
NS_IMETHOD WillInterrupt ()
 This method gets called when the parser gets i/o blocked, and wants to notify the sink that it may be a while before more data is available.
NS_IMETHOD WillResume ()
 This method gets called when the parser i/o gets unblocked, and we're about to start dumping content again to the sink.
virtual void FlushPendingNotifications (mozFlushType aType)
 Flush content so that the content model is in sync with the state of the sink.
NS_IMETHOD SetDocumentCharset (nsACString &aCharset)
 Set the document character set.
virtual nsISupports * GetTarget ()
 Returns the target object (often a document object) into which the content built by this content sink is being added, if any (IOW, may return null).
void setFeature (in AString name, in boolean value)
 Set the value of a feature flag.
boolean getFeature (in AString name)
 Look up the value of a feature flag.
void setProperty (in AString name, in nsISupports value)
 Set the value of a property.
boolean getProperty (in AString name)
 Look up the value of a property.
void parseFromString (in AString str, in string contentType)
void parseFromStream (in nsIInputStream stream, in string charset, in string contentType)
void parseAsync (in nsIRequestObserver observer)
 Begin an asynchronous parse.
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.
void handleStartDTD (in wstring aDoctypeName, in wstring aSysid, in wstring aPubid)
 Called at the beginning of the DTD, before any entity or notation events.
void handleStartNamespaceDecl (in wstring aPrefix, in wstring aUri)
 Called when a prefix mapping starts to be in-scope, before any startElement events.
void handleEndNamespaceDecl (in wstring aPrefix)
 Called when a prefix mapping is no longer in-scope, after any endElement events.
void handleNotationDecl (in wstring aNotationName, in wstring aSysid, in wstring aPubid)
 This is called for a declaration of notation.
void handleUnparsedEntityDecl (in wstring aName, in wstring aSysid, in wstring aPubid, in wstring aNotationName)
 This is called for a declaration of an unparsed (NDATA) entity.
void HandleStartElement (in wstring aName,[array, size_is(aAttsCount)] in wstring aAtts, in unsigned long aAttsCount, in long aIndex, in unsigned long aLineNumber)
 Called to handle the opening tag of an element.
void HandleEndElement (in wstring aName)
 Called to handle the closing tag of an element.
void HandleComment (in wstring aCommentText)
 Called to handle a comment.
void HandleCDataSection ([size_is(aLength)] in wstring aData, in unsigned long aLength)
 Called to handle a CDATA section.
void HandleDoctypeDecl (in AString aSubset, in AString aName, in AString aSystemId, in AString aPublicId, in nsISupports aCatalogData)
 Called to handle the doctype declaration.
void HandleCharacterData ([size_is(aLength)] in wstring aData, in unsigned long aLength)
 Called to handle character data.
void HandleProcessingInstruction (in wstring aTarget, in wstring aData)
 Called to handle a processing instruction.
void HandleXMLDeclaration (in wstring aVersion, in wstring aEncoding, in long aStandalone)
 Handle the XML Declaration.
void ReportError (in wstring aErrorText, in wstring aSourceText)

Public Attributes

attribute nsIURI baseURI
 The base URI.
attribute nsISAXContentHandler contentHandler
 If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.
attribute nsISAXDTDHandler dtdHandler
 If the application does not register a DTD handler, all DTD events reported by the SAX parser will be silently ignored.
attribute nsISAXErrorHandler errorHandler
 If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue.
attribute nsISAXLexicalHandler lexicalHandler
 If the application does not register a lexical handler, all lexical events (e.g.

Private Member Functions

nsresult EnsureBaseURI ()
nsresult InitParser (nsIRequestObserver *aListener, nsIChannel *aChannel)
nsresult SplitExpatName (const PRUnichar *aExpatName, nsString &aURI, nsString &aLocalName, nsString &aQName)

Static Private Member Functions

static PRBool TryChannelCharset (nsIChannel *aChannel, PRInt32 &aCharsetSource, nsACString &aCharset)

Private Attributes

nsCOMPtr< nsISAXContentHandlermContentHandler
nsCOMPtr< nsISAXDTDHandlermDTDHandler
nsCOMPtr< nsISAXErrorHandlermErrorHandler
nsCOMPtr< nsISAXLexicalHandlermLexicalHandler
nsCOMPtr< nsIURImBaseURI
nsCOMPtr< nsIStreamListenermListener
nsCOMPtr< nsIRequestObservermParserObserver
PRBool mIsAsyncParse

Detailed Description

Definition at line 58 of file nsSAXXMLReader.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIEXPATSINK NS_DECL_NSIEXTENDEDEXPATSINK NS_DECL_NSISAXXMLREADER NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER nsSAXXMLReader::nsSAXXMLReader ( )

Member Function Documentation

This method gets called when the parser concludes the process of building the content model via the content sink.

5/7/98 gess

Implements nsIContentSink.

Definition at line 73 of file nsSAXXMLReader.cpp.

{
  if (mContentHandler)
    return mContentHandler->EndDocument();

  return NS_OK;
}

Definition at line 609 of file nsSAXXMLReader.cpp.

{
  if (mBaseURI) 
    return NS_OK;

  return NS_NewURI(getter_AddRefs(mBaseURI), "about:blank");
}

Here is the call graph for this function:

virtual void nsSAXXMLReader::FlushPendingNotifications ( mozFlushType  aType) [inline, virtual]

Flush content so that the content model is in sync with the state of the sink.

Parameters:
aTypethe type of flush to perform

Implements nsIContentSink.

Definition at line 87 of file nsSAXXMLReader.h.

  {
  }
boolean nsISAXXMLReader::getFeature ( in AString  name) [inherited]

Look up the value of a feature flag.

NOT CURRENTLY IMPLEMENTED.

The feature name is any fully-qualified URI. It is possible for an XMLReader to recognize a feature name but temporarily be unable to return its value. Some feature values may be available only in specific contexts, such as before, during, or after a parse.

All XMLReaders are required to recognize the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes feature names.

Parameters:
nameString flag for a parser feature.
boolean nsISAXXMLReader::getProperty ( in AString  name) [inherited]

Look up the value of a property.

NOT CURRENTLY IMPLEMENTED.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but temporarily be unable to return its value. Some property values may be available only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize any specific property names, though an initial core set is documented for SAX2.

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.

Parameters:
nameThe property name, which is a fully-qualified URI.
Returns:
The current value of the property.
virtual nsISupports* nsSAXXMLReader::GetTarget ( ) [inline, virtual]

Returns the target object (often a document object) into which the content built by this content sink is being added, if any (IOW, may return null).

Implements nsIContentSink.

Definition at line 96 of file nsSAXXMLReader.h.

  {
    return nsnull;
  }
void nsIExpatSink::HandleCDataSection ( [size_is(aLength)] in wstring  aData,
in unsigned long  aLength 
) [inherited]

Called to handle a CDATA section.

Parameters:
aDatathe text in the CDATA section. This is null-terminated.
aLengththe length of the aData string
void nsIExpatSink::HandleCharacterData ( [size_is(aLength)] in wstring  aData,
in unsigned long  aLength 
) [inherited]

Called to handle character data.

Note that this does NOT get called for the contents of CDATA sections.

Parameters:
aDatathe data to handle. aData is NOT NULL-TERMINATED.
aLengththe length of the aData string
void nsIExpatSink::HandleComment ( in wstring  aCommentText) [inherited]

Called to handle a comment.

Parameters:
aCommentTextthe text of the comment (not including the "<!--" and "-->")
void nsIExpatSink::HandleDoctypeDecl ( in AString  aSubset,
in AString  aName,
in AString  aSystemId,
in AString  aPublicId,
in nsISupports  aCatalogData 
) [inherited]

Called to handle the doctype declaration.

void nsIExpatSink::HandleEndElement ( in wstring  aName) [inherited]

Called to handle the closing tag of an element.

Parameters:
aNamethe fully qualified tagname of the element
void nsIExtendedExpatSink::handleEndNamespaceDecl ( in wstring  aPrefix) [inherited]

Called when a prefix mapping is no longer in-scope, after any endElement events.

Parameters:
aPrefixThe prefix that was being mapped. This is the empty string when a default mapping scope ends.
void nsIExtendedExpatSink::handleNotationDecl ( in wstring  aNotationName,
in wstring  aSysid,
in wstring  aPubid 
) [inherited]

This is called for a declaration of notation.

The base argument is whatever was set by XML_SetBase. aNotationName will never be null. The other arguments can be.

Parameters:
aNotationNameThe notation name.
aSysIdThe notation's system identifier, or null if none was given.
aPubIdThe notation's pubilc identifier, or null if none was given.
void nsIExpatSink::HandleProcessingInstruction ( in wstring  aTarget,
in wstring  aData 
) [inherited]

Called to handle a processing instruction.

Parameters:
aTargetthe PI target (e.g. xml-stylesheet)
aDataall the rest of the data in the PI
void nsIExtendedExpatSink::handleStartDTD ( in wstring  aDoctypeName,
in wstring  aSysid,
in wstring  aPubid 
) [inherited]

Called at the beginning of the DTD, before any entity or notation events.

Parameters:
aDoctypeNameThe document type name.
aSysidThe declared system identifier for the external DTD subset, or null if none was declared.
aPubidThe declared public identifier for the external DTD subset, or null if none was declared.
void nsIExpatSink::HandleStartElement ( in wstring  aName,
[array, size_is(aAttsCount)] in wstring  aAtts,
in unsigned long  aAttsCount,
in long  aIndex,
in unsigned long  aLineNumber 
) [inherited]

Called to handle the opening tag of an element.

Parameters:
aNamethe fully qualified tagname of the element
aAttsthe array of attribute names and values. There are aAttsCount/2 names and aAttsCount/2 values, so the total number of elements in the array is aAttsCount. The names and values alternate. Thus, if we number attributes starting with 0, aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is the value of that attribute Both explicitly specified attributes and attributes that are defined to have default values in a DTD are present in aAtts.
aAttsCountthe number of elements in aAtts.
aIndexIf the element has an attribute of type ID, then aAtts[aIndex] is the name of that attribute. Otherwise, aIndex is -1
aLineNumberthe line number of the start tag in the data stream.
void nsIExtendedExpatSink::handleStartNamespaceDecl ( in wstring  aPrefix,
in wstring  aUri 
) [inherited]

Called when a prefix mapping starts to be in-scope, before any startElement events.

Parameters:
aPrefixThe Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix.
aUriThe Namespace URI the prefix is mapped to.
void nsIExtendedExpatSink::handleUnparsedEntityDecl ( in wstring  aName,
in wstring  aSysid,
in wstring  aPubid,
in wstring  aNotationName 
) [inherited]

This is called for a declaration of an unparsed (NDATA) entity.

aName, aSysid and aNotationName arguments will never be null. The other arguments may be.

Parameters:
aNameThe unparsed entity's name.
aSysIdThe notation's system identifier.
aPubIdThe notation's pubilc identifier, or null if none was given.
aNotationNameThe name of the associated notation.
void nsIExpatSink::HandleXMLDeclaration ( in wstring  aVersion,
in wstring  aEncoding,
in long  aStandalone 
) [inherited]

Handle the XML Declaration.

Parameters:
aVersionThe version string, can be null if not specified.
aEncodingThe encoding string, can be null if not specified.
aStandalone-1, 0, or 1 indicating respectively that there was no standalone parameter in the declaration, that it was given as no, or that it was given as yes.
nsresult nsSAXXMLReader::InitParser ( nsIRequestObserver aListener,
nsIChannel aChannel 
) [private]

Definition at line 551 of file nsSAXXMLReader.cpp.

{
  nsresult rv;

  // setup the parser
  nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  parser->SetContentSink(this);

  PRInt32 charsetSource = kCharsetFromDocTypeDefault;
  nsCAutoString charset(NS_LITERAL_CSTRING("UTF-8"));
  TryChannelCharset(aChannel, charsetSource, charset);
  parser->SetDocumentCharset(charset, charsetSource);

#ifdef MOZILLA_1_8_BRANCH
  rv = parser->Parse(mBaseURI, aObserver, PR_FALSE);
#else
  rv = parser->Parse(mBaseURI, aObserver);
#endif
  NS_ENSURE_SUCCESS(rv, rv);

  mListener = do_QueryInterface(parser, &rv);

  return rv;
}

Here is the call graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

Begin an asynchronous parse.

This method initializes the parser, and must be called before any nsIStreamListener methods. It is then the caller's duty to call nsIStreamListener methods to drive the parser. Once this method is called, the caller must not call one of the other parse methods.

Parameters:
observerThe nsIRequestObserver to notify upon start or stop. Can be NULL.
void nsISAXXMLReader::parseFromStream ( in nsIInputStream  stream,
in string  charset,
in string  contentType 
) [inherited]
Parameters:
streamThe byte stream whose contents are parsed
charsetThe character set that was used to encode the byte stream. NULL if not specified.
contentTypeThe content type of the string - either text/xml, application/xml, or application/xhtml+xml. Must not be NULL.
void nsISAXXMLReader::parseFromString ( in AString  str,
in string  contentType 
) [inherited]
Parameters:
strThe UTF16 string to be parsed
contentTypeThe content type of the string (see parseFromStream)
void nsIExpatSink::ReportError ( in wstring  aErrorText,
in wstring  aSourceText 
) [inherited]
NS_IMETHOD nsSAXXMLReader::SetDocumentCharset ( nsACString &  aCharset) [inline, virtual]

Set the document character set.

This should be passed on to the document itself.

Implements nsIContentSink.

Definition at line 91 of file nsSAXXMLReader.h.

  {
    return NS_OK;
  }
void nsISAXXMLReader::setFeature ( in AString  name,
in boolean  value 
) [inherited]

Set the value of a feature flag.

NOT CURRENTLY IMPLEMENTED.

The feature name is any fully-qualified URI. It is possible for an XMLReader to expose a feature value but to be unable to change the current value. Some feature values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

All XMLReaders are required to support setting http://xml.org/sax/features/namespaces to true and http://xml.org/sax/features/namespace-prefixes to false.

Parameters:
nameString flag for a parser feature.
valueTurn the feature on/off.

This method gets called by the parser so that the content sink can retain a reference to the parser.

The expectation is that the content sink will drop the reference when it gets the DidBuildModel notification i.e. when parsing is done.

Implements nsIContentSink.

Definition at line 82 of file nsSAXXMLReader.cpp.

{
  return NS_OK;
}
void nsISAXXMLReader::setProperty ( in AString  name,
in nsISupports  value 
) [inherited]

Set the value of a property.

NOT CURRENTLY IMPLEMENTED.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but to be unable to change the current value. Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize setting any specific property names, though a core set is defined by SAX2.

This method is also the standard mechanism for setting extended handlers.

Parameters:
nameString flag for a parser feature
valueTurn the feature on/off.
nsresult nsSAXXMLReader::SplitExpatName ( const PRUnichar aExpatName,
nsString aURI,
nsString aLocalName,
nsString aQName 
) [private]

Adapted from RDFContentSinkImpl

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

and we use 0xFFFF for the <separator>.

Definition at line 618 of file nsSAXXMLReader.cpp.

{
  NS_ASSERTION(aExpatName, "null passed to handler");
  nsDependentString expatStr(aExpatName);
  PRInt32 break1, break2 = kNotFound;
  break1 = expatStr.FindChar(PRUnichar(0xFFFF));

  if (break1 == kNotFound) {
    aLocalName = expatStr; // no namespace
    aURI.Truncate();
    aQName = expatStr;
  } else {
    aURI = StringHead(expatStr, break1);
    break2 = expatStr.FindChar(PRUnichar(0xFFFF), break1 + 1);
    if (break2 == kNotFound) { // namespace, but no prefix
      aLocalName = Substring(expatStr, break1 + 1);
      aQName = aLocalName;
    } else { // namespace with prefix
      aLocalName = Substring(expatStr, break1 + 1, break2 - break1 - 1);
      aQName = Substring(expatStr, break2 + 1) +
        NS_LITERAL_STRING(":") + aLocalName;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

PRBool nsSAXXMLReader::TryChannelCharset ( nsIChannel aChannel,
PRInt32 aCharsetSource,
nsACString &  aCharset 
) [static, private]

Definition at line 580 of file nsSAXXMLReader.cpp.

{
  if (aCharsetSource >= kCharsetFromChannel)
    return PR_TRUE;
  
  if (aChannel) {
    nsCAutoString charsetVal;
    nsresult rv = aChannel->GetContentCharset(charsetVal);
    if (NS_SUCCEEDED(rv)) {
      nsCOMPtr<nsICharsetAlias>
        calias(do_GetService(NS_CHARSETALIAS_CONTRACTID));
      if (calias) {
        nsCAutoString preferred;
        rv = calias->GetPreferred(charsetVal, preferred);
        if (NS_SUCCEEDED(rv)) {
          aCharset = preferred;
          aCharsetSource = kCharsetFromChannel;
          return PR_TRUE;
        }
      }
    }
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This method gets called when the parser begins the process of building the content model via the content sink.

5/7/98 gess

Implements nsIContentSink.

Definition at line 64 of file nsSAXXMLReader.cpp.

{
  if (mContentHandler)
    return mContentHandler->StartDocument();

  return NS_OK;
}

This method gets called when the parser gets i/o blocked, and wants to notify the sink that it may be a while before more data is available.

5/7/98 gess

Implements nsIContentSink.

Definition at line 77 of file nsSAXXMLReader.h.

  {
    return NS_OK;
  }
NS_IMETHOD nsSAXXMLReader::WillResume ( ) [inline, virtual]

This method gets called when the parser i/o gets unblocked, and we're about to start dumping content again to the sink.

5/7/98 gess

Implements nsIContentSink.

Definition at line 82 of file nsSAXXMLReader.h.

  {
    return NS_OK;
  }

Member Data Documentation

The base URI.

Definition at line 65 of file nsISAXXMLReader.idl.

If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Definition at line 76 of file nsISAXXMLReader.idl.

If the application does not register a DTD handler, all DTD events reported by the SAX parser will be silently ignored.

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Definition at line 86 of file nsISAXXMLReader.idl.

If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue.

It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Definition at line 100 of file nsISAXXMLReader.idl.

If the application does not register a lexical handler, all lexical events (e.g.

startDTD) reported by the SAX parser will be silently ignored.

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Definition at line 111 of file nsISAXXMLReader.idl.

Definition at line 106 of file nsSAXXMLReader.h.

Definition at line 102 of file nsSAXXMLReader.h.

Definition at line 103 of file nsSAXXMLReader.h.

Definition at line 104 of file nsSAXXMLReader.h.

Definition at line 109 of file nsSAXXMLReader.h.

Definition at line 105 of file nsSAXXMLReader.h.

Definition at line 107 of file nsSAXXMLReader.h.

Definition at line 108 of file nsSAXXMLReader.h.


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