bes Updated for version 3.20.10
WWWOutput.cc
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of www_int, software which returns an HTML form which
5// can be used to build a URL to access data from a DAP data server.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// (c) COPYRIGHT URI/MIT 1999,2000
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32#include "config.h"
33
34static char rcsid[] not_used =
35 { "$Id$" };
36
37#include <string>
38#include <iostream>
39#include <sstream>
40
41#ifndef WIN32
42#include <unistd.h>
43#else
44#include <process.h>
45#include <io.h>
46#endif
47
48#include <libdap/BaseType.h>
49#include <libdap/Grid.h>
50#include <libdap/DDS.h>
51
52#include <libdap/debug.h>
53#include <libdap/mime_util.h> // remove if write_html_headers() not needed
54#include <libdap/util.h>
55
56#include "WWWOutput.h"
57
58using namespace std;
59
60#ifdef WIN32
61#define getpid _getpid
62#define access _access
63#define X_OK 00 // Simple existence
64#endif
65
66WWWOutput::WWWOutput(ostream &strm, int rows, int cols)
67 : d_strm(&strm), d_attr_rows(rows), d_attr_cols(cols)
68{
69}
70
71// TODO: Can this be removed?
72void
74{
75#if 1
76 set_mime_html(*d_strm, unknown_type, dap_version(), x_plain);
77#endif
78}
79
80void WWWOutput::write_disposition(string url, bool netcdf3_file_response, bool netcdf4_file_response)
81{
82 // To get the size to be a function of the image window size, you need to
83 // use some JavaScript code to generate the HTML. C++ --> JS --> HTML.
84 // 4/8/99 jhrg
85
86 *d_strm << "<tr>\n\
87<td align=\"right\">\n\
88<h3>\n\
89<a href=\"opendap_form_help.html#disposition\" target=\"help\">Action:</a></h3>\n\
90<td>\n\
91<input type=\"button\" value=\"Get ASCII\" onclick=\"ascii_button()\">\n\
92<input type=\"button\" value=\"Get as CoverageJSON\" onclick=\"binary_button('covjson')\">\n";
93
94 // Add new netcdf_button call here jhrg 2/9/09
95 if (netcdf3_file_response)
96 *d_strm << "<input type=\"button\" value=\"Get as NetCDF 3\" onclick=\"binary_button('nc')\">\n";
97 // Add new new netcdf4 button. jhrg 9/23/13
98 if (netcdf4_file_response)
99 *d_strm << "<input type=\"button\" value=\"Get as NetCDF 4\" onclick=\"binary_button('nc4')\">\n";
100
101 *d_strm <<
102"<input type=\"button\" value=\"Binary (DAP2) Object\" onclick=\"binary_button('dods')\">\n\
103<input type=\"button\" value=\"Show Help\" onclick=\"help_button()\">\n\
104\n\
105<tr>\n\
106<td align=\"right\"><h3><a href=\"opendap_form_help.html#data_url\" target=\"help\">Data URL:</a>\n\
107</h3>\n\
108<td><input name=\"url\" type=\"text\" size=\"" << d_attr_cols << "\" value=\"" << url << "\">\n" ;
109}
110
111void WWWOutput::write_attributes(AttrTable *attr, const string prefix)
112{
113 if (attr) {
114 for (AttrTable::Attr_iter a = attr->attr_begin(); a
115 != attr->attr_end(); ++a) {
116 if (attr->is_container(a))
117 write_attributes(attr->get_attr_table(a),
118 (prefix == "") ? attr->get_name(a) : prefix + string(
119 ".") + attr->get_name(a));
120 else {
121 if (prefix != "")
122 *d_strm << prefix << "." << attr->get_name(a) << ": ";
123 else
124 *d_strm << attr->get_name(a) << ": ";
125
126 int num_attr = attr->get_attr_num(a) - 1;
127 for (int i = 0; i < num_attr; ++i)
128 {
129 *d_strm << attr->get_attr(a, i) << ", ";
130 }
131 *d_strm << attr->get_attr(a, num_attr) << "\n";
132 }
133 }
134 }
135}
136
143{
144 *d_strm << "<tr>\n\
145<td align=\"right\" valign=\"top\"><h3>\n\
146<a href=\"opendap_form_help.html#global_attr\" target=\"help\">Global Attributes:</a></h3>\n\
147<td><textarea name=\"global_attr\" rows=\"" << d_attr_rows << "\" cols=\"" << d_attr_cols << "\">\n" ;
148
149 write_attributes(&attr);
150
151 *d_strm << "</textarea><p>\n\n";
152}
153
154void WWWOutput::write_variable_entries(DDS &dds)
155{
156 // This writes the text `Variables:' and then sets up the table so that
157 // the first variable's section is written into column two.
158 *d_strm << "<tr>\n\
159<td align=\"right\" valign=\"top\">\n\
160<h3><a href=\"opendap_form_help.html#dataset_variables\" target=\"help\">Variables:</a></h3>\n\
161<td>";
162
163 for (DDS::Vars_iter p = dds.var_begin(); p != dds.var_end(); ++p) {
164 (*p)->print_val(*d_strm);
165
167#if 0
168 (*p)->print_attributes(*d_strm, d_attr_rows, d_attr_cols);
169#endif
170 *d_strm << "\n<p><p>\n\n"; // End the current var's section
171 *d_strm << "<tr><td><td>\n\n"; // Start the next var in column two
172 }
173}
174
182{
183 switch (btp->type()) {
184 case dods_byte_c:
185 case dods_int16_c:
186 case dods_uint16_c:
187 case dods_int32_c:
188 case dods_uint32_c:
189 case dods_float32_c:
190 case dods_float64_c:
191 case dods_str_c:
192 case dods_url_c:
193 case dods_array_c: {
194 AttrTable &attr = btp->get_attr_table();
195
196 // Don't write anything if there are no attributes.
197 if (attr.get_size() == 0) {
198 DBG(cerr << "No Attributes for " << btp->name() << endl);
199 return;
200 }
201
202 *d_strm << "<textarea name=\"" << btp->name() << "_attr\" rows=\"" << d_attr_rows << "\" cols=\""
203 << d_attr_cols << "\">\n";
204 write_attributes(&attr);
205 *d_strm << "</textarea>\n\n";
206 break;
207 }
208
209 case dods_structure_c:
210 case dods_sequence_c: {
211 AttrTable &attr = btp->get_attr_table();
212
213 // Don't write anything if there are no attributes.
214 if (attr.get_size() == 0) {
215 DBG(cerr << "No Attributes for " << btp->name() << endl);
216 return;
217 }
218
219 *d_strm << "<textarea name=\"" << btp->name() << "_attr\" rows=\"" << d_attr_rows << "\" cols=\""
220 << d_attr_cols << "\">\n";
221 write_attributes(&attr);
222 *d_strm << "</textarea>\n\n";
223 break;
224 }
225
226 case dods_grid_c: {
227 Grid &g = dynamic_cast<Grid&>(*btp);
228#if 0
229 // Don't write anything if there are no attributes.
230 if (attr.get_size() == 0 && array_attr.get_size() == 0) {
231 DBG(cerr << "No Attributes for " << btp->name() << endl);
232 return;
233 }
234#endif
235 *d_strm << "<textarea name=\"" << btp->name() << "_attr\" rows=\"" << d_attr_rows << "\" cols=\""
236 << d_attr_cols << "\">\n";
237 write_attributes(&g.get_attr_table());
238 write_attributes(&g.get_array()->get_attr_table(), g.name());
239 for (Grid::Map_iter m = g.map_begin(); m != g.map_end(); ++m) {
240 Array &map = dynamic_cast<Array&>(**m);
241 write_attributes(&map.get_attr_table(), map.name());
242 }
243 *d_strm << "</textarea>\n\n";
244 break;
245 }
246
247 default:
248 break;
249 }
250}
void write_variable_attributes(BaseType *btp)
Definition: WWWOutput.cc:181
WWWOutput(ostream &strm, int rows=5, int cols=70)
Definition: WWWOutput.cc:66
void write_disposition(string url, bool netcdf3_file_response, bool netcdf4_file_response)
Definition: WWWOutput.cc:80
void write_html_header()
Definition: WWWOutput.cc:73
void write_global_attributes(AttrTable &attr)
Definition: WWWOutput.cc:142