Isis 3 Programmer Reference
IsisXMLHandler.cpp
Go to the documentation of this file.
1 
24 #include <string>
25 
26 #include <xercesc/sax2/SAX2XMLReader.hpp>
27 #include <xercesc/util/XMLException.hpp>
28 
29 #include <sstream>
30 
31 #include "IException.h"
32 
33 #include "IString.h"
34 
35 #include "IsisXMLHandler.h"
36 #include "IsisXMLChTrans.h"
37 
38 using namespace std;
39 
40 namespace XERCES = XERCES_CPP_NAMESPACE;
41 
42 
43 // Constructors
44 
45 IsisXMLHandler::IsisXMLHandler() {
46  value = NULL;
47  outputEndTag = 0;
48 }
49 
50 
51 IsisXMLHandler::IsisXMLHandler(char *PencodingName,
52  bool &PexpandNamespaces,
53  XERCES::SAX2XMLReader* &Pparser,
54  QString *Pvalue) {
55 
56  encodingName = PencodingName;
57  expandNamespaces = PexpandNamespaces;
58  parser = Pparser;
59  value = Pvalue;
60 
61  outputEndTag = 0;
62 
63  prevDocHandler = parser->getContentHandler();
64  prevErrorHandler = parser->getErrorHandler();
65 
66  parser->setContentHandler(this);
67  parser->setErrorHandler(this);
68 }
69 
70 
71 IsisXMLHandler::IsisXMLHandler(char *PencodingName,
72  bool &PexpandNamespaces,
73  XERCES::SAX2XMLReader* &Pparser) {
74 
75  value = NULL;
76  outputEndTag = 0;
77 
78  encodingName = PencodingName;
79  expandNamespaces = PexpandNamespaces;
80  parser = Pparser;
81 
82  prevDocHandler = parser->getContentHandler();
83  prevErrorHandler = parser->getErrorHandler();
84 
85  parser->setContentHandler(this);
86  parser->setErrorHandler(this);
87 }
88 
89 
90 IsisXMLHandler::~IsisXMLHandler() {}
91 
92 
93 // IsisXMLHandler: Overrides the SAX ErrorHandler
94 void IsisXMLHandler::error(const XERCES::SAXParseException &e) {
95  ostringstream os;
96  os << "Error in application XML file line: " << e.getLineNumber()
97  << " char: " << e.getColumnNumber() << ". "
98  << XERCES::XMLString::transcode(e.getMessage());
100 }
101 
102 void IsisXMLHandler::fatalError(const XERCES::SAXParseException &e) {
103  ostringstream os;
104  os << "Error in application XML file line: " << e.getLineNumber()
105  << " char: " << e.getColumnNumber() << ". "
106  << XERCES::XMLString::transcode(e.getMessage());
108 }
109 
110 void IsisXMLHandler::warning(const XERCES::SAXParseException &e) {
111  ostringstream os;
112  os << "Error in application XML file line: " << e.getLineNumber()
113  << " char: " << e.getColumnNumber() << ". "
114  << XERCES::XMLString::transcode(e.getMessage());
116 }
117 
118 
119 // IsisXMLHandler: Overrides of the SAX DocumentHandler interface
120 void IsisXMLHandler::characters(const XMLCh *const chars,
121  const XMLSize_t length) {
122 
123  if(value != NULL) {
124  QString str;
125  str = XERCES::XMLString::transcode(chars);
126  str = str.trimmed();
127  *value += str;
128  }
129 }
130 
131 
132 void IsisXMLHandler::endDocument() {
133 }
134 
135 
136 void IsisXMLHandler::endElement(const XMLCh *const uri,
137  const XMLCh *const localname,
138  const XMLCh *const qname) {
139 
140  if(outputEndTag > 0) {
141  QString str;
142  str = XERCES::XMLString::transcode(localname);
143  *value += "</" + str + ">";
144  outputEndTag--;
145  }
146  else {
147  parser->setContentHandler(prevDocHandler);
148  parser->setErrorHandler(prevErrorHandler);
149  }
150 }
151 
152 
153 void IsisXMLHandler::ignorableWhitespace(const XMLCh *const chars,
154  const unsigned int length) {
155 }
156 
157 
158 void IsisXMLHandler::processingInstruction(const XMLCh *const target,
159  const XMLCh *const data) {
160 }
161 
162 
163 void IsisXMLHandler::startDocument() {
164 }
165 
166 
167 void IsisXMLHandler::startElement(const XMLCh *const uri,
168  const XMLCh *const localname,
169  const XMLCh *const qname,
170  const XERCES::Attributes &attributes) {
171 
172  if(value != NULL) {
173  QString str;
174  str = XERCES::XMLString::transcode(localname);
175  // Note: need to build the attributes into the string too
176  *value += "<" + str + ">";
177  outputEndTag++;
178  }
179 }
Namespace for the standard library.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Isis exception class.
Definition: IException.h:107