Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

SAX2Handler.cxx

Go to the documentation of this file.
00001 
00002 // $Id: SAX2Handler.cxx,v 1.1 2007/02/09 04:44:14 fmwk Exp $
00003 //
00005 //
00006 // messier@indiana.edu
00008 #include "XMLInterface/SAX2Handler.h"
00009 #include <iostream>
00010 #include "XMLInterface/Parser.h"
00011 #include "XMLInterface/Builder.h"
00012 #include "XMLInterface/BuilderFac.h"
00013 
00014 xmli::SAX2Handler::SAX2Handler() : 
00015   fUri       (""),
00016   fLocalName (""),
00017   fQname     (""),
00018   fCharacters(""),
00019   fCount     (0 )
00020 { }
00021 
00022 //......................................................................
00023 
00024 xmli::SAX2Handler::~SAX2Handler() 
00025 {
00026   // Check that the begin and end tag counts match
00027   if (fCount>0) {
00028     std::cerr << "xmli::SAX2Handler::" << __LINE__ 
00029               << " Tag '" << fLocalName << "' not closed "
00030               << " in " << xmli::Parser::GetCurrentSource()
00031               << " (count = " << fCount << ")" 
00032               << std::endl;
00033     abort();
00034   }
00035   if (fCount<0) {
00036     std::cerr << "xmli::SAX2Handler::" << __LINE__ 
00037               << " Tag '" << fLocalName << "' closed but not openned"
00038               << " in " << xmli::Parser::GetCurrentSource()
00039               << " (count = " << fCount << ")" 
00040               << std::endl;
00041     abort();
00042   }
00043 }
00044 
00045 //......................................................................
00046 
00047 void xmli::SAX2Handler::StartElement(const std::string& uri,
00048                                    const std::string& localname,
00049                                    const std::string& qname,
00050                                    const xmli::AttributeList& attrs) 
00051 {
00052 //======================================================================
00053 // Called at start of tag element
00054 //======================================================================
00055   fUri        = uri;
00056   fLocalName  = localname;
00057   fQname      = qname;
00058   fAttributes = attrs;
00059   fCharacters = "";
00060 
00061   ++fCount;
00062 
00063   // std::cerr 
00064   // << "[StartElement]" 
00065   // << " [ uri=" << uri << "]"
00066   // << " [ localname=" << localname << "]"
00067   // << " [ qname=" << qname << "]"
00068   // << std::endl;
00069 }
00070 
00071 //......................................................................
00072 
00073 void xmli::SAX2Handler::Characters(const std::string& chars) 
00074 {
00075 //======================================================================
00076 // Spool the characters inside the element to the local buffer
00077 //======================================================================
00078   // std::cerr << "[Charaters] " << chars << std::endl;
00079   fCharacters += chars;
00080 }
00081 
00082 //......................................................................
00083 
00084 void xmli::SAX2Handler::EndElement(const std::string& uri,
00085                                  const std::string& localname,
00086                                  const std::string& qname) 
00087 {
00088 //======================================================================
00089 // Handle the end tag
00090 //======================================================================
00091 
00092   // These better match what we saw in the StartElement or we're in
00093   // big trouble
00094   if (uri       != fUri)       abort();
00095   if (localname != fLocalName) abort();
00096   if (qname     != fQname)     abort();
00097   --fCount;
00098 
00099   // Check if there is a builder defined for this tag. If yes, pass
00100   // the accumulated data off to the builder
00101   xmli::Builder* b = xmli::BuilderFac::Instance().Get(localname);
00102   if (b) b->Build(fAttributes, fCharacters);
00103   else {
00104     std::cerr << "xmli::SAX2Handler:" << __LINE__ 
00105               << " No no handler for tag '"
00106               << localname << "' from file "
00107               << xmli::Parser::GetCurrentSource()
00108               << std::endl;
00109     abort();
00110   }
00111   // std::cerr 
00112   // << "[EndElement]" 
00113   // << " [ uri=" << uri << "]"
00114   // << " [ localname=" << localname << "]"
00115   // << " [ qname=" << qname << "]"
00116   // << " [ builder=" << b << "]"
00117   // << std::endl;
00118 }
00119 

Generated on Thu Sep 4 02:05:28 2008 for NOvA Offline by doxygen 1.3.5