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