bes  Updated for version 3.20.6
XDStr.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of asciival, software which can return an XML data
4 // representation of the data read from a DAP server.
5 
6 // Copyright (c) 2010 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 // Authors:
26 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
27 
28 // Implementation for XDStr. See XDByte.cc
29 //
30 // 3/12/98 jhrg
31 
32 #include "config.h"
33 
34 // #include <string>
35 
36 #include <InternalErr.h>
37 #include <BESDebug.h>
38 
39 #include "XDStr.h"
40 
41 using namespace libdap;
42 
43 BaseType *
44 XDStr::ptr_duplicate()
45 {
46  return new XDStr(*this);
47 }
48 
49 void XDStr::print_xml_data(XMLWriter *writer, bool show_type)
50 {
51  BESDEBUG("xd", "Entering XDStr::print_xml_data" << endl);
52 
53  Str *s = dynamic_cast<Str*>(d_redirect);
54 #if ENABLE_UNIT_TESTS
55  if (!s) s = dynamic_cast<Str *>(this);
56 #else
57  if (!s)
58  throw InternalErr(__FILE__, __LINE__, "d_redirect is null.");
59 #endif
60 
61  if (show_type) start_xml_declaration(writer);
62 
63  // Write the element for the value, then the value
64  BESDEBUG("xd", "XDStr::print_xml_data, value = '" << s->value() << "'." << endl);
65  if (xmlTextWriterWriteElement(writer->get_writer(), (const xmlChar*) "value", (const xmlChar*) s->value().c_str())
66  < 0) throw InternalErr(__FILE__, __LINE__, "Could not write value element for " + s->name());
67 
68  if (show_type) end_xml_declaration(writer);
69 }
libdap
Definition: BESDapFunctionResponseCache.h:35
XDStr
Definition: XDStr.h:39