12 #include "XMLWriter.h" 15 #include "InternalErr.h" 18 #include "D4AsyncUtil.h" 19 #include "DapXmlNamespaces.h" 23 const string D4AsyncUtil::STYLESHEET_REFERENCE_KEY =
"DAP.Async.StyleSheet.Ref";
25 D4AsyncUtil::D4AsyncUtil() {}
27 D4AsyncUtil::~D4AsyncUtil() {}
47 string href =
"href='" + *stylesheet_ref +
"'";
48 if(xmlTextWriterStartPI(xml.get_writer(), (
const xmlChar*)
"xml-stylesheet") < 0)
49 throw InternalErr(__FILE__, __LINE__,
"Could not start XML Processing Instruction.");
50 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
"type='text/xsl'") < 0)
51 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
52 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
" ") < 0)
53 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
54 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) href.c_str()) < 0)
55 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
56 if(xmlTextWriterEndPI(xml.get_writer()) < 0)
57 throw InternalErr(__FILE__, __LINE__,
"Could not Close XML Processing Instruction.");
61 if (xmlTextWriterStartElementNS(xml.get_writer(),
62 (
const xmlChar*)
"dap",
63 (
const xmlChar*)
"AsynchronousResponse",
65 throw InternalErr(__FILE__, __LINE__,
"Could not write AsynchronousResponse element");
66 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"status", (
const xmlChar *)
"required") < 0)
67 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'status'");
71 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dap:expectedDelay") < 0)
72 throw InternalErr(__FILE__, __LINE__,
"Could not write expectedDelay element");
75 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"seconds", (
const xmlChar*) oss.str().c_str()) < 0)
76 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'status'");
77 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
78 throw InternalErr(__FILE__, __LINE__,
"Could not end expectedDelay element");
83 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dap:responseLifetime") < 0)
84 throw InternalErr(__FILE__, __LINE__,
"Could not write expectedDelay element");
86 oss2 << responseLifetime;
87 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"seconds", (
const xmlChar*) oss2.str().c_str()) < 0)
88 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'seconds'");
89 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
90 throw InternalErr(__FILE__, __LINE__,
"Could not end responseLifetime element");
94 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
95 throw InternalErr(__FILE__, __LINE__,
"Could not end AsynchronousResponse element");
111 string href =
"href='" + *stylesheet_ref +
"'";
112 if(xmlTextWriterStartPI(xml.get_writer(), (
const xmlChar*)
"xml-stylesheet") < 0)
113 throw InternalErr(__FILE__, __LINE__,
"Could not start XML Processing Instruction.");
114 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
"type='text/xsl'") < 0)
115 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
116 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
" ") < 0)
117 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
118 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) href.c_str()) < 0)
119 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
120 if(xmlTextWriterEndPI(xml.get_writer()) < 0)
121 throw InternalErr(__FILE__, __LINE__,
"Could not Close XML Processing Instruction.");
124 if (xmlTextWriterStartElementNS(xml.get_writer(),
125 (
const xmlChar*)
"dap",
126 (
const xmlChar*)
"AsynchronousResponse",
128 throw InternalErr(__FILE__, __LINE__,
"Could not write AsynchronousResponse element");
129 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"status", (
const xmlChar *)
"accepted") < 0)
130 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'status'");
134 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dap:expectedDelay") < 0)
135 throw InternalErr(__FILE__, __LINE__,
"Could not write expectedDelay element");
137 oss << expectedDelay;
138 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"seconds", (
const xmlChar*) oss.str().c_str()) < 0)
139 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'seconds'");
140 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
141 throw InternalErr(__FILE__, __LINE__,
"Could not end expectedDelay element");
146 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dap:responseLifetime") < 0)
147 throw InternalErr(__FILE__, __LINE__,
"Could not write expectedDelay element");
149 oss2 << responseLifetime;
150 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"seconds", (
const xmlChar*) oss2.str().c_str()) < 0)
151 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'seconds'");
152 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
153 throw InternalErr(__FILE__, __LINE__,
"Could not end responseLifetime element");
158 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dap:link") < 0)
159 throw InternalErr(__FILE__, __LINE__,
"Could not write expectedDelay element");
161 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"href", (
const xmlChar*) asyncResourceUrl.c_str()) < 0)
162 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'href'");
163 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
164 throw InternalErr(__FILE__, __LINE__,
"Could not end link element");
168 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
169 throw InternalErr(__FILE__, __LINE__,
"Could not end AsynchronousResponse element");
185 string href =
"href='" + *stylesheet_ref +
"'";
186 if(xmlTextWriterStartPI(xml.get_writer(), (
const xmlChar*)
"xml-stylesheet") < 0)
187 throw InternalErr(__FILE__, __LINE__,
"Could not start XML Processing Instruction.");
188 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
"type='text/xsl'") < 0)
189 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
190 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
" ") < 0)
191 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
192 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) href.c_str()) < 0)
193 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
194 if(xmlTextWriterEndPI(xml.get_writer()) < 0)
195 throw InternalErr(__FILE__, __LINE__,
"Could not Close XML Processing Instruction.");
198 if (xmlTextWriterStartElementNS(xml.get_writer(),
199 (
const xmlChar*)
"dap",
200 (
const xmlChar*)
"AsynchronousResponse",
202 throw InternalErr(__FILE__, __LINE__,
"Could not write AsynchronousResponse element");
203 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"status", (
const xmlChar *)
"pending") < 0)
204 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'status'");
206 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
207 throw InternalErr(__FILE__, __LINE__,
"Could not end AsynchronousResponse element");
224 string href =
"href='" + *stylesheet_ref +
"'";
225 if(xmlTextWriterStartPI(xml.get_writer(), (
const xmlChar*)
"xml-stylesheet") < 0)
226 throw InternalErr(__FILE__, __LINE__,
"Could not start XML Processing Instruction.");
227 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
"type='text/xsl'") < 0)
228 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
229 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
" ") < 0)
230 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
231 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) href.c_str()) < 0)
232 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
233 if(xmlTextWriterEndPI(xml.get_writer()) < 0)
234 throw InternalErr(__FILE__, __LINE__,
"Could not Close XML Processing Instruction.");
237 if (xmlTextWriterStartElementNS(xml.get_writer(),
238 (
const xmlChar*)
"dap",
239 (
const xmlChar*)
"AsynchronousResponse",
241 throw InternalErr(__FILE__, __LINE__,
"Could not write AsynchronousResponse element");
242 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"status", (
const xmlChar *)
"gone") < 0)
243 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'status'");
245 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
246 throw InternalErr(__FILE__, __LINE__,
"Could not end AsynchronousResponse element");
263 string href =
"href='" + *stylesheet_ref +
"'";
264 if(xmlTextWriterStartPI(xml.get_writer(), (
const xmlChar*)
"xml-stylesheet") < 0)
265 throw InternalErr(__FILE__, __LINE__,
"Could not start XML Processing Instruction.");
266 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
"type='text/xsl'") < 0)
267 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
268 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*)
" ") < 0)
269 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
270 if(xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) href.c_str()) < 0)
271 throw InternalErr(__FILE__, __LINE__,
"Could not write Processing Instruction content.");
272 if(xmlTextWriterEndPI(xml.get_writer()) < 0)
273 throw InternalErr(__FILE__, __LINE__,
"Could not Close XML Processing Instruction.");
276 if (xmlTextWriterStartElementNS(xml.get_writer(),
277 (
const xmlChar*)
"dap",
278 (
const xmlChar*)
"AsynchronousResponse",
280 throw InternalErr(__FILE__, __LINE__,
"Could not write AsynchronousResponse element");
281 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"status", (
const xmlChar *)
"rejected") < 0)
282 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'status'");
285 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dap:reason") < 0)
286 throw InternalErr(__FILE__, __LINE__,
"Could not write reason element");
287 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"code", (
const xmlChar*) getRejectReasonCodeString(code).c_str()) < 0)
288 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for 'code'");
289 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
290 throw InternalErr(__FILE__, __LINE__,
"Could not end reason element");
295 if (xmlTextWriterWriteElement(xml.get_writer(), (
const xmlChar*)
"dap:description", (
const xmlChar*) description.c_str()) < 0)
296 throw InternalErr(__FILE__, __LINE__,
"Could not write description element");
300 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
301 throw InternalErr(__FILE__, __LINE__,
"Could not end AsynchronousResponse element");
307 string D4AsyncUtil::getRejectReasonCodeString(RejectReasonCode code){
316 codeStr =
"unavailable";
320 codeStr =
"privileges";
328 throw InternalErr(__FILE__, __LINE__,
"D4AsyncUtil::getRejectReasonCodeString() - Unrecognized reject_reason_code.");
336 throw InternalErr(__FILE__, __LINE__,
"DAP2 Doesn't handle Async.");
339 void D4AsyncUtil::writeD2AsyncAccepted(
XMLWriter &,
long ,
long ,
string ) {
340 throw InternalErr(__FILE__, __LINE__,
"DAP2 Doesn't handle Async.");
344 void D4AsyncUtil::writeD2AsyncPending(
XMLWriter &) {
345 throw InternalErr(__FILE__, __LINE__,
"DAP2 Doesn't handle Async.");
348 void D4AsyncUtil::writeD2AsyncResponseGone(
XMLWriter &) {
349 throw InternalErr(__FILE__, __LINE__,
"DAP2 Doesn't handle Async.");
352 void D4AsyncUtil::writeD2AsyncResponseRejected(
XMLWriter &, RejectReasonCode ,
string ) {
353 throw InternalErr(__FILE__, __LINE__,
"DAP2 Doesn't handle Async.");
void writeD4AsyncPending(XMLWriter &xml, string *stylesheet_ref=0)
Write the DAP4 AsyncPending response. Write the DAP4 AsyncPending in XML form.
void writeD2AsyncRequired(XMLWriter &xml, long expectedDelay, long responseLifetime)
Write the DAP2 AsyncRequired response . Write the DAP2 AsyncRequired in XML form. ...
top level DAP object to house generic methods
A class for software fault reporting.
void writeD4AsyncRequired(XMLWriter &xml, long expectedDelay, long responseLifetime, string *stylesheet_ref=0)
Write the DAP4 AsyncRequired response. Print the AsyncRequired in XML form.
static std::string getDapNamespaceString(DAPVersion version)
void writeD4AsyncResponseRejected(XMLWriter &xml, RejectReasonCode code, string description, string *stylesheet_ref=0)
Write the DAP4 ResponseRejected response. Write the DAP4 AsyncRequired in XML form.
void writeD4AsyncResponseGone(XMLWriter &xml, string *stylesheet_ref=0)
Write the DAP4 AsyncResponseGone response. Write the DAP4 AsyncRequired in XML form.
void writeD4AsyncAccepted(XMLWriter &xml, long expectedDelay, long responseLifetime, string asyncResourceUrl, string *stylesheet_ref=0)
Write the DAP4 AsyncAccepted response. Write the AsyncAccepted in XML form.