tXmlParserNamespace::tXmlParser Class Reference

TODO: add documentation, this is just here so tXmlParser::node gets documented. More...

#include <tXmlParser.h>

Inheritance diagram for tXmlParserNamespace::tXmlParser:

Inheritance graph
[legend]
Collaboration diagram for tXmlParserNamespace::tXmlParser:

Collaboration graph
[legend]

List of all members.

Public Member Functions

node GetRoot ()
 tXmlParser ()
virtual ~tXmlParser ()
 tXmlParser (int mode)
void SetMode (int mode)
virtual bool LoadFile (const char *filename, const char *uri="")
bool LoadXmlFile (const char *filename, const char *uri="")
bool LoadWithoutParsing (const char *filename, const char *uri="")
bool LoadWithParsing (const char *filename, const char *uri="")
bool Parse ()
virtual bool ParseDom ()
bool ParseSax ()
virtual void startElement (tString &element, tAttributeList &attributes)
virtual void endElement (tString &element)
virtual void startDocument ()
virtual void endDocument ()
void cb_startDocument ()
void cb_endDocument ()
void cb_startElement (const xmlChar *name, const xmlChar **attrs)
void cb_endElement (const xmlChar *name)

Public Attributes

xmlDocPtr m_Doc
tString m_Filename

Protected Member Functions

virtual bool ValidateXml (FILE *docfd, const char *uri=NULL, const char *filepath=NULL)

Private Attributes

int m_Mode

Classes

class  node
 DOM node class; provides convienient access to libxml without dealing with its functions. More...


Detailed Description

TODO: add documentation, this is just here so tXmlParser::node gets documented.

Definition at line 52 of file tXmlParser.h.


Constructor & Destructor Documentation

tXmlParserNamespace::tXmlParser::tXmlParser (  )  [inline]

Definition at line 93 of file tXmlParser.h.

References tXmlParserNamespace::DOM, and SetMode().

00094 : m_Doc(0) { SetMode(DOM); };

Here is the call graph for this function:

tXmlParserNamespace::tXmlParser::~tXmlParser (  )  [virtual]

Definition at line 242 of file tXmlParser.cpp.

References m_Doc.

00242                         {
00243     if (m_Doc)
00244     {
00245         xmlFreeDoc(m_Doc);
00246         m_Doc=0;
00247     }
00248 }

tXmlParserNamespace::tXmlParser::tXmlParser ( int  mode  )  [inline]

Definition at line 97 of file tXmlParser.h.

References m_Doc, and SetMode().

00098 { SetMode(mode); m_Doc = 0; };

Here is the call graph for this function:


Member Function Documentation

tXmlParser::node tXmlParserNamespace::tXmlParser::GetRoot (  ) 

Definition at line 508 of file tXmlParser.cpp.

References m_Doc.

Referenced by tXmlParserNamespace::tXmlResource::GetFileContents(), and tXmlParserNamespace::tXmlResource::ValidateXml().

00508                                    {
00509     return node(xmlDocGetRootElement(m_Doc));
00510 }

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::SetMode ( int  mode  )  [inline]

Definition at line 99 of file tXmlParser.h.

References m_Mode.

Referenced by tXmlParser().

00100 { m_Mode = mode; };

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::LoadFile ( const char *  filename,
const char *  uri = "" 
) [virtual]

Reimplemented in tXmlParserNamespace::tXmlResource.

Definition at line 299 of file tXmlParser.cpp.

References LoadXmlFile().

00299                                                                {
00300     return LoadXmlFile(filename, uri);
00301 }

Here is the call graph for this function:

bool tXmlParserNamespace::tXmlParser::LoadXmlFile ( const char *  filename,
const char *  uri = "" 
)

Definition at line 303 of file tXmlParser.cpp.

References Parse(), and ValidateXml().

Referenced by LoadFile(), and tXmlParserNamespace::tXmlResource::LoadFile().

00303                                                                   {
00304     bool goOn;
00305 
00306     FILE* docfd;
00307 
00308     docfd = fopen(filename, "r");
00309 
00310     goOn = ValidateXml(docfd, uri, filename);
00311 
00312     if(goOn) {
00313         return Parse();
00314     } else {
00315         return false;
00316     }
00317 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::LoadWithoutParsing ( const char *  filename,
const char *  uri = "" 
)

Definition at line 259 of file tXmlParser.cpp.

References tResourceManager::locateResource(), m_Filename, tResourceManager::openResource(), and ValidateXml().

00259                                                                          {
00260     bool success=false;
00261     FILE* docfd;
00262 
00263     docfd = tResourceManager::openResource(filename, uri);
00264     m_Filename = tResourceManager::locateResource(filename, uri);
00265 
00266     if ( docfd )
00267     {
00268         success = ValidateXml(docfd, uri, filename);
00269         fclose(docfd);
00270     }
00271 
00272     return success;
00273 }

Here is the call graph for this function:

bool tXmlParserNamespace::tXmlParser::LoadWithParsing ( const char *  filename,
const char *  uri = "" 
)

Definition at line 275 of file tXmlParser.cpp.

References con, tResourceManager::locateResource(), m_Filename, tResourceManager::openResource(), Parse(), and ValidateXml().

00275                                                                       {
00276     bool success=false;
00277     FILE* docfd;
00278 
00279     if(!(docfd = tResourceManager::openResource(filename, uri))) {
00280         con << "Loading XML file '" << filename << "' failed!\n";
00281         return false;
00282     }
00283     m_Filename = tResourceManager::locateResource(filename, uri);
00284 
00285     success = ValidateXml(docfd, uri, filename);
00286     fclose(docfd);
00287     if(success) {
00288         return Parse();
00289     } else {
00290         return false;
00291     }
00292 }

Here is the call graph for this function:

bool tXmlParserNamespace::tXmlParser::Parse (  ) 

Definition at line 319 of file tXmlParser.cpp.

References tXmlParserNamespace::DOM, m_Mode, ParseDom(), and ParseSax().

Referenced by LoadWithParsing(), and LoadXmlFile().

00319                        {
00320     if(m_Mode == DOM) {
00321         return ParseDom();
00322     } else {
00323         return ParseSax();
00324     }
00325 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::ParseDom (  )  [virtual]

Definition at line 328 of file tXmlParser.cpp.

Referenced by Parse().

00328                           {
00329     return true;
00330 }

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::ParseSax (  ) 

Definition at line 332 of file tXmlParser.cpp.

References tXmlParserNamespace::aaSaxCallsback, and m_Filename.

Referenced by Parse().

00332                           {
00333     if (xmlSAXUserParseFile(&aaSaxCallsback, this, m_Filename) < 0) {
00334         return false;
00335     } else
00336         return true;
00337 }

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::startElement ( tString element,
tAttributeList attributes 
) [virtual]

Definition at line 238 of file tXmlParser.cpp.

Referenced by cb_startElement().

00238                                                                           {
00239     // Do nothing
00240 }

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::endElement ( tString element  )  [virtual]

Definition at line 255 of file tXmlParser.cpp.

Referenced by cb_endElement().

00255                                             {
00256     // Do nothing
00257 }

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::startDocument (  )  [virtual]

Definition at line 206 of file tXmlParser.cpp.

Referenced by cb_startDocument().

00206                                {
00207     // Do nothing
00208 }

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::endDocument (  )  [virtual]

Definition at line 214 of file tXmlParser.cpp.

Referenced by cb_endDocument().

00214                              {
00215     // Do nothing
00216 }

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::cb_startDocument (  ) 

Definition at line 202 of file tXmlParser.cpp.

References startDocument().

Referenced by tXmlParserNamespace::cb_startDocument().

00202                                   {
00203     startDocument();
00204 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::cb_endDocument (  ) 

Definition at line 210 of file tXmlParser.cpp.

References endDocument().

Referenced by tXmlParserNamespace::cb_endDocument().

00210                                 {
00211     endDocument();
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::cb_startElement ( const xmlChar *  name,
const xmlChar **  attrs 
)

Definition at line 218 of file tXmlParser.cpp.

References NULL, and startElement().

Referenced by tXmlParserNamespace::cb_startElement().

00218                                                                            {
00219     tAttributeList attributes;
00220     if (attrs != NULL) {
00221         for (int i = 0; (attrs[i] != NULL); i++) {
00222             tString attributeName( (const char*) attrs[i] );
00223             tString attributeValue;
00224             i++;
00225 
00226             if (attrs[i] != NULL) {
00227                 attributeValue = tString( (const char*)attrs[i] );
00228             } else {
00229                 attributeValue = tString();
00230             }
00231             attributes[attributeName] = attributeValue;
00232         }
00233         tString elementName((const char*)name);
00234         startElement(elementName, attributes );
00235     }
00236 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tXmlParserNamespace::tXmlParser::cb_endElement ( const xmlChar *  name  ) 

Definition at line 250 of file tXmlParser.cpp.

References endElement().

Referenced by tXmlParserNamespace::cb_endElement().

00250                                                   {
00251     tString elementName((const char*)name);
00252     endElement(elementName);
00253 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::ValidateXml ( FILE *  docfd,
const char *  uri = NULL,
const char *  filepath = NULL 
) [protected, virtual]

Reimplemented in tXmlParserNamespace::tXmlResource.

Definition at line 381 of file tXmlParser.cpp.

References m_Doc, tXmlParserNamespace::myxmlInputReadFILE(), tXmlParserNamespace::myxmlParserInputBufferCreateFilenameFunc(), NULL, tDirectories::Resource(), tXmlParserNamespace::st_ErrorFunc(), and tXmlParserNamespace::st_errorLeadIn.

Referenced by LoadWithoutParsing(), LoadWithParsing(), LoadXmlFile(), and tXmlParserNamespace::tXmlResource::ValidateXml().

00382 {
00383 #ifndef DEDICATED
00384     /* register error handler */
00385     xmlGenericErrorFunc errorFunc = &st_ErrorFunc;
00386     initGenericErrorDefaultFunc( &errorFunc );
00387     st_errorLeadIn = "XML validation error in ";
00388     st_errorLeadIn += filepath;
00389     st_errorLeadIn += ":\n\n";
00390 #endif
00391 
00392     bool validated = false;
00393 
00394     if (docfd == NULL) {
00395         printf("LoadAndValidateMapXML passed a NULL docfd (we should really trap this somewhere else!)\n");
00396         return false;
00397     }
00398 
00399 #ifndef HAVE_LIBXML2_WO_PIBCREATE
00400     //xmlSetExternalEntityLoader(myxmlResourceEntityLoader);
00401     xmlParserInputBufferCreateFilenameDefault(myxmlParserInputBufferCreateFilenameFunc);    //should be moved to some program init area
00402 #endif
00403 
00404     if (m_Doc)
00405     {
00406         xmlFreeDoc(m_Doc);
00407         m_Doc=0;
00408     }
00409 
00410     /*Validate the xml*/
00411     xmlParserCtxtPtr ctxt; /*Parser context*/
00412 
00413     ctxt = xmlNewParserCtxt();
00414 
00415     if (ctxt == 0) {
00416         fprintf(stderr, "Failed to allocate parser context\n");
00417         return false;
00418     }
00419 
00420     /* parse the file, activating the DTD validation option */
00421     m_Doc = xmlCtxtReadIO(ctxt, myxmlInputReadFILE, 0, docfd,
00422 #if HAVE_LIBXML2_WO_PIBCREATE
00423                           (const char *)tDirectories::Resource().GetReadPath("map-0.1.dtd")
00424                           // TODO: don't hardcode the file
00425 #else
00426                           uri
00427 #endif
00428                           , NULL, XML_PARSE_DTDVALID);
00429     // NOTE: Do *not* pass myxmlInputCloseFILE; we close the file *later*
00430 
00431     /* check if parsing suceeded */
00432     if (m_Doc == NULL) {
00433         fprintf(stderr, "Failed to parse \n");
00434     } else {
00435         /* check if validation suceeded */
00436         if (ctxt->valid == 0) {
00437             fprintf(stderr, "Failed to validate \n");
00438             xmlFreeDoc(m_Doc);
00439             m_Doc=NULL;
00440         }
00441         else
00442         {
00443             validated = true;
00444         }
00445     }
00446 
00447     /* free up the parser context */
00448     xmlFreeParserCtxt(ctxt);
00449 
00450 #ifndef DEDICATED
00451     /* reset error handler */
00452     initGenericErrorDefaultFunc( NULL );
00453 #endif
00454     return validated;
00455 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

xmlDocPtr tXmlParserNamespace::tXmlParser::m_Doc

Definition at line 90 of file tXmlParser.h.

Referenced by GetRoot(), tXmlParser(), ValidateXml(), and ~tXmlParser().

tString tXmlParserNamespace::tXmlParser::m_Filename

Definition at line 136 of file tXmlParser.h.

Referenced by tXmlParserNamespace::tXmlResource::LoadFile(), LoadWithoutParsing(), LoadWithParsing(), and ParseSax().

int tXmlParserNamespace::tXmlParser::m_Mode [private]

Definition at line 138 of file tXmlParser.h.

Referenced by Parse(), and SetMode().


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 00:05:24 2008 for Armagetron Advanced by  doxygen 1.5.4