Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsExpatDriver.cpp File Reference
#include "nsExpatDriver.h"
#include "nsIParser.h"
#include "nsCOMPtr.h"
#include "nsParserCIID.h"
#include "CParserContext.h"
#include "nsIExpatSink.h"
#include "nsIExtendedExpatSink.h"
#include "nsIContentSink.h"
#include "nsParserMsgUtils.h"
#include "nsIURL.h"
#include "nsIUnicharInputStream.h"
#include "nsNetUtil.h"
#include "prprf.h"
#include "prmem.h"
#include "nsTextFormatter.h"
#include "nsDirectoryServiceDefs.h"
#include "nsCRT.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"

Go to the source code of this file.

Classes

struct  nsCatalogData

Defines

#define kExpatSeparatorChar   0xFFFF

Functions

 Driver_HandleXMLDeclaration (void *aUserData, const XML_Char *aVersion, const XML_Char *aEncoding, int aStandalone)
 Driver_HandleStartElement (void *aUserData, const XML_Char *aName, const XML_Char **aAtts)
 Driver_HandleEndElement (void *aUserData, const XML_Char *aName)
 Driver_HandleCharacterData (void *aUserData, const XML_Char *aData, int aLength)
 Driver_HandleComment (void *aUserData, const XML_Char *aName)
 Driver_HandleProcessingInstruction (void *aUserData, const XML_Char *aTarget, const XML_Char *aData)
 Driver_HandleDefault (void *aUserData, const XML_Char *aData, int aLength)
 Driver_HandleStartCdataSection (void *aUserData)
 Driver_HandleEndCdataSection (void *aUserData)
 Driver_HandleStartDoctypeDecl (void *aUserData, const XML_Char *aDoctypeName, const XML_Char *aSysid, const XML_Char *aPubid, int aHasInternalSubset)
 Driver_HandleEndDoctypeDecl (void *aUserData)
 Driver_HandleExternalEntityRef (void *aExternalEntityRefHandler, const XML_Char *aOpenEntityNames, const XML_Char *aBase, const XML_Char *aSystemId, const XML_Char *aPublicId)
 Driver_HandleStartNamespaceDecl (void *aUserData, const XML_Char *aPrefix, const XML_Char *aUri)
 Driver_HandleEndNamespaceDecl (void *aUserData, const XML_Char *aPrefix)
 Driver_HandleNotationDecl (void *aUserData, const XML_Char *aNotationName, const XML_Char *aBase, const XML_Char *aSysid, const XML_Char *aPubid)
 Driver_HandleUnparsedEntityDecl (void *aUserData, const XML_Char *aEntityName, const XML_Char *aBase, const XML_Char *aSysid, const XML_Char *aPubid, const XML_Char *aNotationName)
static const nsCatalogDataLookupCatalogData (const PRUnichar *aPublicID)
static PRBool IsLoadableDTD (const nsCatalogData *aCatalogData, nsIURI *aDTD, nsIURI **aResult)
 NS_IMPL_ISUPPORTS2 (nsExpatDriver, nsITokenizer, nsIDTD) nsresult NS_NewExpatDriver(nsIDTD **aResult)
static NS_METHOD ExternalDTDStreamReaderFunc (nsIUnicharInputStream *aIn, void *aClosure, const PRUnichar *aFromSegment, PRUint32 aToOffset, PRUint32 aCount, PRUint32 *aWriteCount)
static nsresult CreateErrorText (const PRUnichar *aDescription, const PRUnichar *aSourceURL, const PRInt32 aLineNumber, const PRInt32 aColNumber, nsString &aErrorString)
static nsresult CreateSourceText (const PRInt32 aColNumber, const PRUnichar *aSourceLine, nsString &aSourceString)

Variables

static const PRUnichar kUTF16 [] = { 'U', 'T', 'F', '-', '1', '6', '\0' }
static const nsCatalogData kCatalogTable []

Class Documentation

struct nsCatalogData

Definition at line 270 of file nsExpatDriver.cpp.

Class Members
const char * mAgentSheet
const char * mLocalDTD
const char * mPublicID

Define Documentation

Definition at line 58 of file nsExpatDriver.cpp.


Function Documentation

static nsresult CreateErrorText ( const PRUnichar aDescription,
const PRUnichar aSourceURL,
const PRInt32  aLineNumber,
const PRInt32  aColNumber,
nsString aErrorString 
) [static]

Definition at line 797 of file nsExpatDriver.cpp.

{
  aErrorString.Truncate();

  nsAutoString msg;
  nsresult rv =
    nsParserMsgUtils::GetLocalizedStringByName(XMLPARSER_PROPERTIES,
                                               "XMLParsingError", msg);
  NS_ENSURE_SUCCESS(rv, rv);

  // XML Parsing Error: %1$S\nLocation: %2$S\nLine Number %3$d, Column %4$d:
  PRUnichar *message = nsTextFormatter::smprintf(msg.get(), aDescription,
                                                 aSourceURL, aLineNumber,
                                                 aColNumber);
  if (!message) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  aErrorString.Assign(message);
  nsTextFormatter::smprintf_free(message);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult CreateSourceText ( const PRInt32  aColNumber,
const PRUnichar aSourceLine,
nsString aSourceString 
) [static]

Definition at line 826 of file nsExpatDriver.cpp.

{
  aSourceString.Append(aSourceLine);
  aSourceString.Append(PRUnichar('\n'));

  // Last character will be '^'.
  PRInt32 last = aColNumber - 1;
  PRInt32 i;
  PRUint32 minuses = 0;
  for (i = 0; i < last; ++i) {
    if (aSourceLine[i] == '\t') {
      // Since this uses |white-space: pre;| a tab stop equals 8 spaces.
      PRUint32 add = 8 - (minuses % 8);
      aSourceString.AppendASCII("--------", add);
      minuses += add;
    }
    else {
      aSourceString.Append(PRUnichar('-'));
      ++minuses;
    }
  }
  aSourceString.Append(PRUnichar('^'));

  return NS_OK;
}

Here is the caller graph for this function:

Driver_HandleCharacterData ( void aUserData,
const XML_Char aData,
int  aLength 
)

Definition at line 101 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    nsExpatDriver* driver = NS_STATIC_CAST(nsExpatDriver*, aUserData);
    driver->HandleCharacterData(aData, PRUint32(aLength));
  }
}

Here is the call graph for this function:

Driver_HandleComment ( void aUserData,
const XML_Char aName 
)

Definition at line 113 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if(aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->HandleComment(aName);
  }
}
Driver_HandleDefault ( void aUserData,
const XML_Char aData,
int  aLength 
)

Definition at line 135 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    nsExpatDriver* driver = NS_STATIC_CAST(nsExpatDriver*, aUserData);
    driver->HandleDefault(aData, PRUint32(aLength));
  }
}

Here is the call graph for this function:

Definition at line 156 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->HandleEndCdataSection();
  }
}

Definition at line 179 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->HandleEndDoctypeDecl();
  }
}
Driver_HandleEndElement ( void aUserData,
const XML_Char aName 
)

Definition at line 91 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->HandleEndElement(aName);
  }
}
Driver_HandleEndNamespaceDecl ( void aUserData,
const XML_Char aPrefix 
)

Definition at line 219 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->
      HandleEndNamespaceDecl(aPrefix);
  }
}
Driver_HandleExternalEntityRef ( void aExternalEntityRefHandler,
const XML_Char aOpenEntityNames,
const XML_Char aBase,
const XML_Char aSystemId,
const XML_Char aPublicId 
)

Definition at line 188 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aExternalEntityRefHandler, "expat driver should exist");
  if (!aExternalEntityRefHandler) {
    return 1;
  }

  nsExpatDriver* driver = NS_STATIC_CAST(nsExpatDriver*,
                                         aExternalEntityRefHandler);

  return driver->HandleExternalEntityRef(aOpenEntityNames, aBase, aSystemId,
                                         aPublicId);
}

Here is the call graph for this function:

Driver_HandleNotationDecl ( void aUserData,
const XML_Char aNotationName,
const XML_Char aBase,
const XML_Char aSysid,
const XML_Char aPubid 
)

Definition at line 230 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->
      HandleNotationDecl(aNotationName, aBase, aSysid, aPubid);
  }
}
Driver_HandleProcessingInstruction ( void aUserData,
const XML_Char aTarget,
const XML_Char aData 
)

Definition at line 123 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    nsExpatDriver* driver = NS_STATIC_CAST(nsExpatDriver*, aUserData);
    driver->HandleProcessingInstruction(aTarget, aData);
  }
}

Here is the call graph for this function:

Definition at line 147 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->HandleStartCdataSection();
  }
}
Driver_HandleStartDoctypeDecl ( void aUserData,
const XML_Char aDoctypeName,
const XML_Char aSysid,
const XML_Char aPubid,
int  aHasInternalSubset 
)

Definition at line 165 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->
      HandleStartDoctypeDecl(aDoctypeName, aSysid, aPubid, aHasInternalSubset);
  }
}
Driver_HandleStartElement ( void aUserData,
const XML_Char aName,
const XML_Char **  aAtts 
)

Definition at line 79 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->HandleStartElement(aName,
                                                                  aAtts);
  }
}
Driver_HandleStartNamespaceDecl ( void aUserData,
const XML_Char aPrefix,
const XML_Char aUri 
)

Definition at line 207 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->
      HandleStartNamespaceDecl(aPrefix, aUri);
  }
}
Driver_HandleUnparsedEntityDecl ( void aUserData,
const XML_Char aEntityName,
const XML_Char aBase,
const XML_Char aSysid,
const XML_Char aPubid,
const XML_Char aNotationName 
)

Definition at line 244 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    NS_STATIC_CAST(nsExpatDriver*, aUserData)->
      HandleUnparsedEntityDecl(aEntityName, aBase, aSysid, aPubid,
                               aNotationName);
  }
}
Driver_HandleXMLDeclaration ( void aUserData,
const XML_Char aVersion,
const XML_Char aEncoding,
int  aStandalone 
)

Definition at line 66 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aUserData, "expat driver should exist");
  if (aUserData) {
    nsExpatDriver* driver = NS_STATIC_CAST(nsExpatDriver*, aUserData);
    driver->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
  }
}

Here is the call graph for this function:

static NS_METHOD ExternalDTDStreamReaderFunc ( nsIUnicharInputStream aIn,
void aClosure,
const PRUnichar aFromSegment,
PRUint32  aToOffset,
PRUint32  aCount,
PRUint32 aWriteCount 
) [static]

Definition at line 679 of file nsExpatDriver.cpp.

{
  // Pass the buffer to expat for parsing. XML_Parse returns 0 for
  // fatal errors.
  if (XML_Parse((XML_Parser)aClosure, (const char *)aFromSegment,
                aCount * sizeof(PRUnichar), 0)) {
    *aWriteCount = aCount;

    return NS_OK;
  }

  *aWriteCount = 0;

  return NS_ERROR_FAILURE;
}

Here is the caller graph for this function:

static PRBool IsLoadableDTD ( const nsCatalogData aCatalogData,
nsIURI aDTD,
nsIURI **  aResult 
) [static]

Definition at line 316 of file nsExpatDriver.cpp.

{
  NS_ASSERTION(aDTD, "Null parameter.");

  nsCAutoString fileName;
  if (aCatalogData) {
    // remap the DTD to a known local DTD
    fileName.Assign(aCatalogData->mLocalDTD);
  }

  if (fileName.IsEmpty()) {
    // Try to see if the user has installed the DTD file -- we extract the
    // filename.ext of the DTD here. Hence, for any DTD for which we have
    // no predefined mapping, users just have to copy the DTD file to our
    // special DTD directory and it will be picked.
    nsCOMPtr<nsIURL> dtdURL = do_QueryInterface(aDTD);
    if (!dtdURL) {
      return PR_FALSE;
    }

    dtdURL->GetFileName(fileName);
    if (fileName.IsEmpty()) {
      return PR_FALSE;
    }
  }

  nsCOMPtr<nsIFile> dtdPath;
  NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(dtdPath));
  if (!dtdPath) {
    return PR_FALSE;
  }

  nsCOMPtr<nsILocalFile> lfile = do_QueryInterface(dtdPath);

  // append res/dtd/<fileName>
  // can't do AppendRelativeNativePath("res/dtd/" + fileName)
  // as that won't work on all platforms.
  lfile->AppendNative(NS_LITERAL_CSTRING("res"));
  lfile->AppendNative(NS_LITERAL_CSTRING("dtd"));
  lfile->AppendNative(fileName);

  PRBool exists;
  dtdPath->Exists(&exists);
  if (!exists) {
    return PR_FALSE;
  }

  // The DTD was found in the local DTD directory.
  // Set aDTD to a file: url pointing to the local DTD
  NS_NewFileURI(aResult, dtdPath);

  return *aResult != nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const nsCatalogData* LookupCatalogData ( const PRUnichar aPublicID) [static]

Definition at line 291 of file nsExpatDriver.cpp.

{
  nsDependentString publicID(aPublicID);

  // linear search for now since the number of entries is going to
  // be negligible, and the fix for bug 98413 would get rid of this
  // code anyway
  const nsCatalogData* data = kCatalogTable;
  while (data->mPublicID) {
    if (publicID.EqualsASCII(data->mPublicID)) {
      return data;
    }
    ++data;
  }

  return nsnull;
}

Here is the caller graph for this function:

Definition at line 373 of file nsExpatDriver.cpp.

{
  *aResult = new nsExpatDriver();
  if (!*aResult) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  NS_ADDREF(*aResult);

  return NS_OK;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
  { "-//W3C//DTD XHTML 1.0 Transitional//EN",    "xhtml11.dtd", nsnull },
  { "-//W3C//DTD XHTML 1.1//EN",                 "xhtml11.dtd", nsnull },
  { "-//W3C//DTD XHTML 1.0 Strict//EN",          "xhtml11.dtd", nsnull },
  { "-//W3C//DTD XHTML 1.0 Frameset//EN",        "xhtml11.dtd", nsnull },
  { "-//W3C//DTD XHTML Basic 1.0//EN",           "xhtml11.dtd", nsnull },
  { "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN", "mathml.dtd",  "resource://gre/res/mathml.css" },
  { "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN", "mathml.dtd", "resource://gre/res/mathml.css" },
  { "-//W3C//DTD MathML 2.0//EN",                "mathml.dtd",  "resource://gre/res/mathml.css" },
  { "-//WAPFORUM//DTD XHTML Mobile 1.0//EN",     "xhtml11.dtd", nsnull },
  { nsnull, nsnull, nsnull }
}

Definition at line 277 of file nsExpatDriver.cpp.

const PRUnichar kUTF16[] = { 'U', 'T', 'F', '-', '1', '6', '\0' } [static]

Definition at line 60 of file nsExpatDriver.cpp.