Isis 3 Programmer Reference
IsisXMLHelper.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <string>
10 
11 #include <xercesc/util/PlatformUtils.hpp>
12 #include <xercesc/sax2/SAX2XMLReader.hpp>
13 #include <xercesc/sax2/Attributes.hpp>
14 
15 #include "IsisXMLHelper.h"
16 #include "IsisXMLChTrans.h"
17 
18 #include "IString.h"
19 
20 using namespace std;
21 
22 namespace XERCES = XERCES_CPP_NAMESPACE;
23 
24 // Constructors
25 IsisXMLHelper::IsisXMLHelper(char *PencodingName,
26  bool &PexpandNamespaces,
27  XERCES::SAX2XMLReader* &Pparser,
28  IsisHelperData *Phelper) {
29 
30  encodingName = PencodingName;
31  expandNamespaces = PexpandNamespaces;
32  parser = Pparser;
33  helper = Phelper;
34 
35  prevDocHandler = parser->getContentHandler();
36  prevErrorHandler = parser->getErrorHandler();
37 
38  parser->setContentHandler(this);
39  parser->setErrorHandler(this);
40 
41  ignoreHandler = NULL;
42  generalHandler = NULL;
43 }
44 
45 IsisXMLHelper::~IsisXMLHelper() {
46  if(ignoreHandler != NULL) delete ignoreHandler;
47  if(generalHandler != NULL) delete generalHandler;
48 }
49 
50 
51 // IsisXMLHelper: Overrides of the SAX DocumentHandler interface
52 void IsisXMLHelper::characters(const XMLCh *const chars,
53  const XMLSize_t length) {
54 }
55 
56 
57 void IsisXMLHelper::endElement(const XMLCh *const uri,
58  const XMLCh *const localname,
59  const XMLCh *const qname) {
60  parser->setContentHandler(prevDocHandler);
61  parser->setErrorHandler(prevErrorHandler);
62 }
63 
64 void IsisXMLHelper::startElement(const XMLCh *const uri,
65  const XMLCh *const localname,
66  const XMLCh *const qname,
67  const XERCES::Attributes &attributes) {
68 
69  if((string)XERCES::XMLString::transcode(localname) == (string)"brief") {
70  if(generalHandler != NULL) {
71  delete generalHandler;
72  generalHandler = NULL;
73  }
74  generalHandler = new IsisXMLHandler(encodingName, expandNamespaces,
75  parser, &helper->brief);
76  }
77  else if((string)XERCES::XMLString::transcode(localname) == (string)"description") {
78  if(generalHandler != NULL) {
79  delete generalHandler;
80  generalHandler = NULL;
81  }
82  generalHandler = new IsisXMLHandler(encodingName, expandNamespaces,
83  parser, &helper->description);
84  }
85  else if((string)XERCES::XMLString::transcode(localname) == (string)"function") {
86  if(generalHandler != NULL) {
87  delete generalHandler;
88  generalHandler = NULL;
89  }
90  generalHandler = new IsisXMLHandler(encodingName, expandNamespaces,
91  parser, &helper->function);
92  }
93  else if((string)XERCES::XMLString::transcode(localname) == (string)"icon") {
94  if(generalHandler != NULL) {
95  delete generalHandler;
96  generalHandler = NULL;
97  }
98  generalHandler = new IsisXMLHandler(encodingName, expandNamespaces,
99  parser, &helper->icon);
100  }
101  else {
102  if(ignoreHandler != NULL) {
103  delete ignoreHandler;
104  ignoreHandler = NULL;
105  }
106  ignoreHandler = new IsisXMLIgnore(encodingName, expandNamespaces, parser,
107  (string)XERCES::XMLString::transcode(localname));
108  }
109 }
IsisHelperData
Definition: IsisAmlData.h:36
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