- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Io/Xml/Sax/XMLLoader.cpp

    00001
    00002 //
    00003 // Copyright (c) 2005           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #include "XMLLoader.h"
    00012 #include <xercesc/util/PlatformUtils.hpp>
    00013 #include <cassert>
    00014
    00016
    00017 using namespace Mers::Utils::Io::Xml::Sax;
    00018 using Mers::Utils::Lang::String;
    00019 using XERCES_CPP_NAMESPACE::XMLPlatformUtils;
    00020 using XERCES_CPP_NAMESPACE::SAX2XMLReader;
    00021 using XERCES_CPP_NAMESPACE::XMLException;
    00022 using XERCES_CPP_NAMESPACE::XMLString;
    00023 using log4cplus::Logger;
    00024 using std::exception;
    00025
    00027
    00028 #define ASSERT(x) assert(x)
    00029
    00031
    00032 Logger XMLLoader::m_Logger(
    00033         Logger::getInstance( "Mers.Utils.Io.Xml.Sax.XMLLoader" ) );
    00034
    00036
    00037 void XMLLoader::initialize()
    00038 {
    00039                 XMLPlatformUtils::Initialize();
    00040 }
    00041
    00043
    00044 int XMLLoader::loadContent( SAX2XMLReader * reader, const String &fileName,
    00045         ContentHandler * cHandler )
    00046 {
    00047         int ret = 0;
    00048         ASSERT( reader != NULL );
    00049
    00050         // Let the reader know who is reading for now.
    00051         reader->setContentHandler( cHandler );
    00052
    00053         try {
    00054                 // Parse the content.
    00055                 reader->parse( fileName.c_str() );
    00056
    00057         } catch( const XMLException &exc ) {
    00058                 // We caught a parse exception.
    00059                 char * msg = XMLString::transcode( exc.getMessage() );
    00060                 LOG4CPLUS_ERROR( m_Logger, "XML Exception: " << msg );
    00061                 XMLString::release(&msg);
    00062
    00063                 ret = 1;
    00064         } catch( const exception &exc ) {
    00065                 // We caught an exception, probably from our code.  The data had
    00066                 // some error.
    00067                 LOG4CPLUS_ERROR( m_Logger, "Exception: " << exc.what() );
    00068
    00069                 ret = 2;
    00070         }
    00071
    00072         // Delete our content handler.
    00073         XERCES_CPP_NAMESPACE::ContentHandler * ch = reader->getContentHandler();
    00074         if( ch != NULL )
    00075                 delete ch;
    00076
    00077         // Delete our reader.
    00078         delete reader;
    00079
    00080         // Return everything ok.
    00081         return ret;
    00082 }
    00083