Isis 3 Programmer Reference
IsisXMLHelpers.cpp
Go to the documentation of this file.
1 
24 #include <string>
25 
26 #include <xercesc/util/PlatformUtils.hpp>
27 #include <xercesc/sax2/SAX2XMLReader.hpp>
28 #include <xercesc/sax2/Attributes.hpp>
29 
30 #include "IsisXMLHelpers.h"
31 #include "IsisXMLChTrans.h"
32 
33 using namespace std;
34 
35 namespace XERCES = XERCES_CPP_NAMESPACE;
36 
37 
38 // Constructors
39 
40 IsisXMLHelpers::IsisXMLHelpers(char *PencodingName,
41  bool &PexpandNamespaces,
42  XERCES::SAX2XMLReader* &Pparser,
43  std::vector<IsisHelperData> *Phelpers) {
44 
45  encodingName = PencodingName;
46  expandNamespaces = PexpandNamespaces;
47  parser = Pparser;
48  helpers = Phelpers;
49 
50  prevDocHandler = parser->getContentHandler();
51  prevErrorHandler = parser->getErrorHandler();
52 
53  parser->setContentHandler(this);
54  parser->setErrorHandler(this);
55 
56  helperHandler = NULL;
57  ignoreHandler = NULL;
58 }
59 
60 IsisXMLHelpers::~IsisXMLHelpers() {
61  if(helperHandler != NULL) delete helperHandler;
62  if(ignoreHandler != NULL) delete ignoreHandler;
63 }
64 
65 
66 // IsisXMLHelpers: Overrides of the SAX DocumentHandler interface
67 void IsisXMLHelpers::characters(const XMLCh *const chars,
68  const XMLSize_t length) {}
69 
70 
71 void IsisXMLHelpers::endElement(const XMLCh *const uri,
72  const XMLCh *const localname,
73  const XMLCh *const qname) {
74  parser->setContentHandler(prevDocHandler);
75  parser->setErrorHandler(prevErrorHandler);
76 }
77 
78 
79 void IsisXMLHelpers::startElement(const XMLCh *const uri,
80  const XMLCh *const localname,
81  const XMLCh *const qname,
82  const XERCES::Attributes &attributes) {
83 
84  if((string)XERCES::XMLString::transcode(localname) == (string)"helper") {
85  if(helperHandler != NULL) {
86  delete helperHandler;
87  helperHandler = NULL;
88  }
89  unsigned int index = helpers->size();
90  helpers->resize(index + 1);
91  (*helpers)[index].name = XERCES::XMLString::transcode(attributes.getValue((XMLSize_t)0));
92  helperHandler = new IsisXMLHelper(encodingName, expandNamespaces, parser,
93  &(*helpers)[index]);
94  }
95  else {
96  if(ignoreHandler != NULL) {
97  delete ignoreHandler;
98  ignoreHandler = NULL;
99  }
100  ignoreHandler = new IsisXMLIgnore(encodingName, expandNamespaces, parser,
101  (string)XERCES::XMLString::transcode(localname));
102  }
103 
104 }
Namespace for the standard library.