Isis 3 Programmer Reference
IsisXMLHelpers.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <string>
8 
9 #include <xercesc/util/PlatformUtils.hpp>
10 #include <xercesc/sax2/SAX2XMLReader.hpp>
11 #include <xercesc/sax2/Attributes.hpp>
12 
13 #include "IsisXMLHelpers.h"
14 #include "IsisXMLChTrans.h"
15 
16 using namespace std;
17 
18 namespace XERCES = XERCES_CPP_NAMESPACE;
19 
20 
21 // Constructors
22 
23 IsisXMLHelpers::IsisXMLHelpers(char *PencodingName,
24  bool &PexpandNamespaces,
25  XERCES::SAX2XMLReader* &Pparser,
26  std::vector<IsisHelperData> *Phelpers) {
27 
28  encodingName = PencodingName;
29  expandNamespaces = PexpandNamespaces;
30  parser = Pparser;
31  helpers = Phelpers;
32 
33  prevDocHandler = parser->getContentHandler();
34  prevErrorHandler = parser->getErrorHandler();
35 
36  parser->setContentHandler(this);
37  parser->setErrorHandler(this);
38 
39  helperHandler = NULL;
40  ignoreHandler = NULL;
41 }
42 
43 IsisXMLHelpers::~IsisXMLHelpers() {
44  if(helperHandler != NULL) delete helperHandler;
45  if(ignoreHandler != NULL) delete ignoreHandler;
46 }
47 
48 
49 // IsisXMLHelpers: Overrides of the SAX DocumentHandler interface
50 void IsisXMLHelpers::characters(const XMLCh *const chars,
51  const XMLSize_t length) {}
52 
53 
54 void IsisXMLHelpers::endElement(const XMLCh *const uri,
55  const XMLCh *const localname,
56  const XMLCh *const qname) {
57  parser->setContentHandler(prevDocHandler);
58  parser->setErrorHandler(prevErrorHandler);
59 }
60 
61 
62 void IsisXMLHelpers::startElement(const XMLCh *const uri,
63  const XMLCh *const localname,
64  const XMLCh *const qname,
65  const XERCES::Attributes &attributes) {
66 
67  if((string)XERCES::XMLString::transcode(localname) == (string)"helper") {
68  if(helperHandler != NULL) {
69  delete helperHandler;
70  helperHandler = NULL;
71  }
72  unsigned int index = helpers->size();
73  helpers->resize(index + 1);
74  (*helpers)[index].name = XERCES::XMLString::transcode(attributes.getValue((XMLSize_t)0));
75  helperHandler = new IsisXMLHelper(encodingName, expandNamespaces, parser,
76  &(*helpers)[index]);
77  }
78  else {
79  if(ignoreHandler != NULL) {
80  delete ignoreHandler;
81  ignoreHandler = NULL;
82  }
83  ignoreHandler = new IsisXMLIgnore(encodingName, expandNamespaces, parser,
84  (string)XERCES::XMLString::transcode(localname));
85  }
86 
87 }
IsisXMLHelper
This is free and unencumbered software released into the public domain.
Definition: IsisXMLHelper.h:19
std
Namespace for the standard library.
IsisXMLIgnore
This is free and unencumbered software released into the public domain.
Definition: IsisXMLIgnore.h:18