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

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Io/Xml/Sax/ContentHandler.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 "ContentHandler.h"
    00012 #include <xercesc/util/XMLString.hpp>
    00013 #include <xercesc/sax2/SAX2XMLReader.hpp>
    00014 #include <xercesc/sax2/Attributes.hpp>
    00015 #include <xercesc/sax/Locator.hpp>
    00016 #include <Mers/Utils/Lang/String.h>
    00017
    00019
    00020 using namespace Mers::Utils::Io::Xml::Sax;
    00021 using ::Mers::Utils::Lang::String;
    00022 using XERCES_CPP_NAMESPACE::SAX2XMLReader;
    00023 using XERCES_CPP_NAMESPACE::Locator;
    00024 using XERCES_CPP_NAMESPACE::Attributes;
    00025 using XERCES_CPP_NAMESPACE::XMLString;
    00026 using log4cplus::Logger;
    00027
    00029
    00030 Logger ContentHandler::m_Logger( Logger::getInstance(
    00031         "Mers.Utils.Io.Xml.Sax.ContentHandler" ) );
    00032
    00034
    00035 ContentHandler::ContentHandler( SAX2XMLReader * reader,
    00036         ContentHandler * parent )
    00037         : XERCES_CPP_NAMESPACE::ContentHandler(), m_Reader( reader ),
    00038           m_Parent( parent ), m_locator( NULL )
    00039 {
    00040 }
    00041
    00043
    00044 ContentHandler::~ContentHandler()
    00045 {
    00046 }
    00047
    00049
    00050 void ContentHandler::characters( const XMLCh* const chars,
    00051         const unsigned int length )
    00052 {
    00053         // Note that these are not NULL terminated.
    00054         XMLCh * mChars = new XMLCh[ length + 1 ];
    00055         XMLString::copyNString( mChars, chars, length );
    00056         char * cChars = XMLString::transcode( mChars );
    00057         LOG4CPLUS_TRACE( m_Logger, "Chars: '" << cChars << "'");
    00058         XMLString::release( &cChars );
    00059         delete[] mChars;
    00060 }
    00061
    00063
    00064 void ContentHandler::endDocument()
    00065 {
    00066         LOG4CPLUS_TRACE_STR( m_Logger, "EndDocument" );
    00067 }
    00068
    00070
    00071 void ContentHandler::endElement( const XMLCh* const uri,
    00072         const XMLCh* const localname, const XMLCh* const qname )
    00073 {
    00074         (void) uri;
    00075         (void) qname;
    00076         char * cLocalname = XMLString::transcode(localname);
    00077         LOG4CPLUS_TRACE( m_Logger, "End: " << cLocalname );
    00078         XMLString::release( &cLocalname );
    00079
    00080         // Swap our content handler.
    00081         if( m_Parent != NULL ) {
    00082                 m_Reader->setContentHandler( m_Parent );
    00083                 // We are no longer needed.
    00084                 delete this;
    00085                 return;
    00086         }
    00087 }
    00088
    00090
    00091 void ContentHandler::ignorableWhitespace( const XMLCh* const chars,
    00092         const unsigned int length )
    00093 {
    00094         (void) chars;
    00095         (void) length;
    00096 }
    00097
    00099
    00100 void ContentHandler::processingInstruction( const XMLCh* const target,
    00101         const XMLCh* const data )
    00102 {
    00103         char * cTarg = XMLString::transcode( target );
    00104         LOG4CPLUS_TRACE( m_Logger, "ProcessingInst - targ: " << cTarg << "; data: "
    00105                 << data );
    00106         XMLString::release( &cTarg );
    00107 }
    00108
    00110
    00111 void ContentHandler::setDocumentLocator( const Locator * const locator )
    00112 {
    00113         m_locator = locator;
    00114         LOG4CPLUS_TRACE_STR( m_Logger, "Locator Set" );
    00115 }
    00116
    00118
    00119 void ContentHandler::startDocument()
    00120 {
    00121         LOG4CPLUS_TRACE_STR( m_Logger, "StartDocument" );
    00122 }
    00123
    00125
    00126 void ContentHandler::startElement( const XMLCh* const uri,
    00127         const XMLCh* const localname, const XMLCh* const qname,
    00128         const Attributes& attrs )
    00129 {
    00130         (void) uri;
    00131         (void) qname;
    00132         (void) attrs;
    00133         char * cLocalname = XMLString::transcode(localname);
    00134         LOG4CPLUS_TRACE( m_Logger, "Start: " << cLocalname );
    00135         XMLString::release( &cLocalname );
    00136
    00137         // Setup a new TR object object.
    00138         ContentHandler * trch = new ContentHandler( m_Reader, this );
    00139         m_Reader->setContentHandler( trch );
    00140 }
    00141
    00143
    00144 void ContentHandler::startPrefixMapping( const XMLCh* const prefix,
    00145         const XMLCh* const uri )
    00146 {
    00147         (void) prefix;
    00148         (void) uri;
    00149 }
    00150
    00152
    00153 void ContentHandler::endPrefixMapping( const    XMLCh* const prefix )
    00154 {
    00155         (void) prefix;
    00156 }
    00157
    00159
    00160 void ContentHandler::skippedEntity( const XMLCh* const name )
    00161 {
    00162         (void) name;
    00163 }
    00164
    00166
    00167 String ContentHandler::getLineNumberString() const
    00168 {
    00169         const Locator * locator = getDocumentLocator();
    00170         if( locator == NULL )
    00171                 return String( "Unknown" );
    00172         else
    00173                 return String() + locator->getLineNumber();
    00174 }
    00175