bes  Updated for version 3.20.6
DMRpp.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of the BES
4 
5 // Copyright (c) 2016 OPeNDAP, Inc.
6 // Author: James Gallagher <jgallagher@opendap.org>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 
24 #include "config.h"
25 
26 #include <XMLWriter.h>
27 #include <D4Group.h>
28 #include <D4BaseTypeFactory.h>
29 #include <InternalErr.h>
30 
31 #include "DMRpp.h"
32 #include "DmrppCommon.h"
33 #include "DmrppTypeFactory.h"
34 
35 using namespace libdap;
36 
37 namespace dmrpp {
38 
39 DMRpp::DMRpp(DmrppTypeFactory *factory, const std::string &name) : DMR(factory, name)
40 {
41 }
42 
70 void DMRpp::print_dmrpp(XMLWriter &xml, const string &href, bool constrained, bool print_chunks)
71 {
72  bool pc_initial_value = DmrppCommon::d_print_chunks;
73  DmrppCommon::d_print_chunks = print_chunks;
74 
75  try {
76  if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar*) "Dataset") < 0)
77  throw InternalErr(__FILE__, __LINE__, "Could not write Dataset element");
78 
79  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "xmlns",
80  (const xmlChar*) get_namespace().c_str()) < 0)
81  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for xmlns");
82 
83  // The dmrpp namespace
84  if (DmrppCommon::d_print_chunks)
85  if (xmlTextWriterWriteAttribute(xml.get_writer(),
86  (const xmlChar*)string("xmlns:").append(DmrppCommon::d_ns_prefix).c_str(),
87  (const xmlChar*)DmrppCommon::d_dmrpp_ns.c_str()) < 0)
88  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for xmlns:dmrpp");
89 
90  if (!request_xml_base().empty()) {
91  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "xml:base",
92  (const xmlChar*) request_xml_base().c_str()) < 0)
93  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for xml:base");
94  }
95 
96  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "dapVersion",
97  (const xmlChar*) dap_version().c_str()) < 0)
98  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for dapVersion");
99 
100  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "dmrVersion",
101  (const xmlChar*) dmr_version().c_str()) < 0)
102  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for dapVersion");
103 
104  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "name", (const xmlChar*) name().c_str()) < 0)
105  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
106 
107  // cerr << "DMRpp::" <<__func__ << "() href: "<< href << endl;
108  if (!href.empty())
109  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*)string(DmrppCommon::d_ns_prefix).append(":href").c_str(),
110  (const xmlChar*) href.c_str()) < 0)
111  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for href");
112 
113 
114  root()->print_dap4(xml, constrained);
115 
116  if (xmlTextWriterEndElement(xml.get_writer()) < 0)
117  throw InternalErr(__FILE__, __LINE__, "Could not end the top-level Group element");
118  }
119  catch (...) {
120  DmrppCommon::d_print_chunks = pc_initial_value;
121  throw;
122  }
123 
124  DmrppCommon::d_print_chunks = pc_initial_value;
125 }
126 
133 void
134 DMRpp::print_dap4(XMLWriter &xml, bool constrained /* false */)
135 {
136  print_dmrpp(xml, get_href(), constrained, get_print_chunks());
137 }
138 
139 } /* namespace dmrpp */
libdap
Definition: BESDapFunctionResponseCache.h:35