OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
WWWOutput.cc
Go to the documentation of this file.
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 
34 static 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 <BaseType.h>
49 #include <Grid.h>
50 #include <DDS.h>
51 
52 #include <debug.h>
53 #include <mime_util.h> // remove if write_html_headers() not needed
54 #include <util.h>
55 
56 #include "WWWOutput.h"
57 
58 using namespace std;
59 
60 #ifdef WIN32
61 #define getpid _getpid
62 #define access _access
63 #define X_OK 00 // Simple existence
64 #endif
65 
66 WWWOutput::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?
72 void
74 {
75 #if 1
76  set_mime_html(*d_strm, unknown_type, dap_version(), x_plain);
77 #endif
78 }
79 
80 void 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 
93  // Add new netcdf_button call here jhrg 2/9/09
94  if (netcdf3_file_response)
95  *d_strm << "<input type=\"button\" value=\"Get as NetCDF 3\" onclick=\"binary_button('nc')\">\n";
96  // Add new new netcdf4 button. jhrg 9/23/13
97  if (netcdf4_file_response)
98  *d_strm << "<input type=\"button\" value=\"Get as NetCDF 4\" onclick=\"binary_button('nc4')\">\n";
99 
100  *d_strm <<
101 "<input type=\"button\" value=\"Binary (DAP2) Object\" onclick=\"binary_button('dods')\">\n\
102 <input type=\"button\" value=\"Show Help\" onclick=\"help_button()\">\n\
103 \n\
104 <tr>\n\
105 <td align=\"right\"><h3><a href=\"opendap_form_help.html#data_url\" target=\"help\">Data URL:</a>\n\
106 </h3>\n\
107 <td><input name=\"url\" type=\"text\" size=\"" << d_attr_cols << "\" value=\"" << url << "\">\n" ;
108 }
109 
110 void WWWOutput::write_attributes(AttrTable *attr, const string prefix)
111 {
112  if (attr) {
113  for (AttrTable::Attr_iter a = attr->attr_begin(); a
114  != attr->attr_end(); ++a) {
115  if (attr->is_container(a))
116  write_attributes(attr->get_attr_table(a),
117  (prefix == "") ? attr->get_name(a) : prefix + string(
118  ".") + attr->get_name(a));
119  else {
120  if (prefix != "")
121  *d_strm << prefix << "." << attr->get_name(a) << ": ";
122  else
123  *d_strm << attr->get_name(a) << ": ";
124 
125  int num_attr = attr->get_attr_num(a) - 1;
126  for (int i = 0; i < num_attr; ++i)
127  {
128  *d_strm << attr->get_attr(a, i) << ", ";
129  }
130  *d_strm << attr->get_attr(a, num_attr) << "\n";
131  }
132  }
133  }
134 }
135 
142 {
143  *d_strm << "<tr>\n\
144 <td align=\"right\" valign=\"top\"><h3>\n\
145 <a href=\"opendap_form_help.html#global_attr\" target=\"help\">Global Attributes:</a></h3>\n\
146 <td><textarea name=\"global_attr\" rows=\"" << d_attr_rows << "\" cols=\"" << d_attr_cols << "\">\n" ;
147 
148  write_attributes(&attr);
149 
150  *d_strm << "</textarea><p>\n\n";
151 }
152 
154 {
155  // This writes the text `Variables:' and then sets up the table so that
156  // the first variable's section is written into column two.
157  *d_strm << "<tr>\n\
158 <td align=\"right\" valign=\"top\">\n\
159 <h3><a href=\"opendap_form_help.html#dataset_variables\" target=\"help\">Variables:</a></h3>\n\
160 <td>";
161 
162  for (DDS::Vars_iter p = dds.var_begin(); p != dds.var_end(); ++p) {
163  (*p)->print_val(*d_strm);
164 
166 #if 0
167  (*p)->print_attributes(*d_strm, d_attr_rows, d_attr_cols);
168 #endif
169  *d_strm << "\n<p><p>\n\n"; // End the current var's section
170  *d_strm << "<tr><td><td>\n\n"; // Start the next var in column two
171  }
172 }
173 
181 {
182  switch (btp->type()) {
183  case dods_byte_c:
184  case dods_int16_c:
185  case dods_uint16_c:
186  case dods_int32_c:
187  case dods_uint32_c:
188  case dods_float32_c:
189  case dods_float64_c:
190  case dods_str_c:
191  case dods_url_c:
192  case dods_array_c: {
193  AttrTable &attr = btp->get_attr_table();
194 
195  // Don't write anything if there are no attributes.
196  if (attr.get_size() == 0) {
197  DBG(cerr << "No Attributes for " << btp->name() << endl);
198  return;
199  }
200 
201  *d_strm << "<textarea name=\"" << btp->name() << "_attr\" rows=\"" << d_attr_rows << "\" cols=\""
202  << d_attr_cols << "\">\n";
203  write_attributes(&attr);
204  *d_strm << "</textarea>\n\n";
205  break;
206  }
207 
208  case dods_structure_c:
209  case dods_sequence_c: {
210  AttrTable &attr = btp->get_attr_table();
211 
212  // Don't write anything if there are no attributes.
213  if (attr.get_size() == 0) {
214  DBG(cerr << "No Attributes for " << btp->name() << endl);
215  return;
216  }
217 
218  *d_strm << "<textarea name=\"" << btp->name() << "_attr\" rows=\"" << d_attr_rows << "\" cols=\""
219  << d_attr_cols << "\">\n";
220  write_attributes(&attr);
221  *d_strm << "</textarea>\n\n";
222  break;
223  }
224 
225  case dods_grid_c: {
226  Grid &g = dynamic_cast<Grid&>(*btp);
227 #if 0
228  // Don't write anything if there are no attributes.
229  if (attr.get_size() == 0 && array_attr.get_size() == 0) {
230  DBG(cerr << "No Attributes for " << btp->name() << endl);
231  return;
232  }
233 #endif
234  *d_strm << "<textarea name=\"" << btp->name() << "_attr\" rows=\"" << d_attr_rows << "\" cols=\""
235  << d_attr_cols << "\">\n";
236  write_attributes(&g.get_attr_table());
237  write_attributes(&g.get_array()->get_attr_table(), g.name());
238  for (Grid::Map_iter m = g.map_begin(); m != g.map_end(); ++m) {
239  Array &map = dynamic_cast<Array&>(**m);
240  write_attributes(&map.get_attr_table(), map.name());
241  }
242  *d_strm << "</textarea>\n\n";
243  break;
244  }
245 
246  default:
247  break;
248  }
249 }
250 
void write_global_attributes(AttrTable &attr)
Given the global attribute table, write the HTML which contains all the global attributes for this da...
Definition: WWWOutput.cc:141
#define not_used
Definition: config.h:315
int d_attr_rows
Definition: WWWOutput.h:63
STL namespace.
void write_variable_entries(DDS &dds)
Definition: WWWOutput.cc:153
WWWOutput(ostream &strm, int rows=5, int cols=70)
Create a WWWOutput.
Definition: WWWOutput.cc:66
int d_attr_cols
Definition: WWWOutput.h:64
void write_disposition(string url, bool netcdf3_file_response, bool netcdf4_file_response)
Write the disposition section of the HTML page.
Definition: WWWOutput.cc:80
void write_variable_attributes(BaseType *btp)
Write a variable's attribute information.
Definition: WWWOutput.cc:180
void write_html_header()
Write out the header for the HTML document.
Definition: WWWOutput.cc:73
void write_attributes(AttrTable *attr, const string prefix="")
Definition: WWWOutput.cc:110
ostream * d_strm
Definition: WWWOutput.h:62