Isis 3 Programmer Reference
IsisXMLHistory.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 "IsisXMLHistory.h"
14 #include "IsisXMLChTrans.h"
15 
16 using namespace std;
17 
18 namespace XERCES = XERCES_CPP_NAMESPACE;
19 
20 
21 // Constructors
22 
23 IsisXMLHistory::IsisXMLHistory(char *PencodingName,
24  bool &PexpandNamespaces,
25  XERCES::SAX2XMLReader* &Pparser,
26  std::vector<IsisChangeData> *Pchanges) {
27 
28  encodingName = PencodingName;
29  expandNamespaces = PexpandNamespaces;
30  parser = Pparser;
31  changes = Pchanges;
32 
33  prevDocHandler = parser->getContentHandler();
34  prevErrorHandler = parser->getErrorHandler();
35 
36  parser->setContentHandler(this);
37  parser->setErrorHandler(this);
38 
39  generalHandler = NULL;
40  ignoreHandler = NULL;
41 }
42 
43 IsisXMLHistory::~IsisXMLHistory() {
44  if(generalHandler != NULL) delete generalHandler;
45  if(ignoreHandler != NULL) delete ignoreHandler;
46 }
47 
48 
49 // IsisXMLHistory: Overrides of the SAX DocumentHandler interface
50 void IsisXMLHistory::characters(const XMLCh *const chars,
51  const XMLSize_t length) {}
52 
53 
54 void IsisXMLHistory::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 IsisXMLHistory::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)"change") {
68  if(generalHandler != NULL) {
69  delete generalHandler;
70  generalHandler = NULL;
71  }
72 
73  // Pull the attributes out and save them
74  unsigned int index = changes->size();
75  changes->resize(index + 1);
76 
77  // Get the name and date attributes
78  string st;
79  for(unsigned int i = 0; i < 2; i++) {
80  st = XERCES::XMLString::transcode(attributes.getQName(i));
81  if(st == "name") {
82  (*changes)[index].name = XERCES::XMLString::transcode(attributes.getValue(i));
83  }
84  else if(st == "date") {
85  (*changes)[index].date = XERCES::XMLString::transcode(attributes.getValue(i));
86  }
87  }
88 
89  generalHandler = new IsisXMLHandler(encodingName, expandNamespaces,
90  parser, &(*changes)[index].description);
91  }
92  else {
93  if(ignoreHandler != NULL) {
94  delete ignoreHandler;
95  ignoreHandler = NULL;
96  }
97  ignoreHandler = new IsisXMLIgnore(encodingName, expandNamespaces, parser,
98  (string)XERCES::XMLString::transcode(localname));
99  }
100 
101 }
IsisXMLHandler
This is free and unencumbered software released into the public domain.
Definition: IsisXMLHandler.h:18
std
Namespace for the standard library.
IsisXMLIgnore
This is free and unencumbered software released into the public domain.
Definition: IsisXMLIgnore.h:18