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