36#include <libdap/DataDDS.h>
37#include <libdap/escaping.h>
39#include "get_html_form.h"
41#include "WWWOutputFactory.h"
48#include "WWWFloat32.h"
49#include "WWWFloat64.h"
53#include "WWWStructure.h"
54#include "WWWSequence.h"
57namespace dap_html_form {
59#include "javascript.h"
70BaseType *basetype_to_wwwtype(BaseType * bt)
74 return new WWWByte(
dynamic_cast < Byte *
>(bt));
76 return new WWWInt16(
dynamic_cast < Int16 *
>(bt));
78 return new WWWUInt16(
dynamic_cast < UInt16 *
>(bt));
80 return new WWWInt32(
dynamic_cast < Int32 *
>(bt));
82 return new WWWUInt32(
dynamic_cast < UInt32 *
>(bt));
84 return new WWWFloat32(
dynamic_cast < Float32 *
>(bt));
86 return new WWWFloat64(
dynamic_cast < Float64 *
>(bt));
88 return new WWWStr(
dynamic_cast < Str *
>(bt));
90 return new WWWUrl(
dynamic_cast < Url *
>(bt));
92 return new WWWArray(
dynamic_cast < Array *
>(bt));
93 case dods_structure_c:
94 return new WWWStructure(
dynamic_cast < Structure *
>(bt));
96 return new WWWSequence(
dynamic_cast < Sequence *
>(bt));
98 return new WWWGrid(
dynamic_cast < Grid *
>(bt));
100 throw InternalErr(__FILE__, __LINE__,
"Unknown type.");
110DDS *dds_to_www_dds(DDS * dds)
116 WWWOutputFactory wwwfactory;
117 dds->set_factory(&wwwfactory);
121 DDS *wwwdds =
new DDS(*dds);
125 wwwdds->del_var(wwwdds->var_begin(), wwwdds->var_end());
129 DDS::Vars_iter i = dds->var_begin();
130 while (i != dds->var_end()) {
131 BaseType *abt = basetype_to_wwwtype(*i);
132 abt->set_attr_table((*i)->get_attr_table());
134 cerr <<
"dds attr: "; (*i)->get_attr_table().print(cerr); cerr << endl;
135 cerr <<
"abt attr: "; abt->get_attr_table().print(cerr); cerr << endl;
137 wwwdds->add_var(abt);
147 DDS *wwwdds =
new DDS(dds->get_factory(), dds->get_dataset_name());
149 wwwdds->set_attr_table(dds->get_attr_table);
151 DDS::Vars_iter i = dds->var_begin();
152 while (i != dds->var_end()) {
153 BaseType *abt = basetype_to_wwwtype(*i);
154 wwwdds->add_var(abt);
188void write_html_form_interface(FILE * dest, DDS * dds,
189 const string & url,
bool html_header,
190 const string & admin_name,
191 const string & help_location)
193 wo =
new WWWOutput(dest);
196 wo->write_html_header();
200 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"
201 <<
"\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n" <<
202 "<html><head><title>OPeNDAP Server Dataset Query Form</title>\n"
203 <<
"<base href=\"" << help_location <<
"\">\n" <<
204 "<script type=\"text/javascript\">\n"
207 <<
"DODS_URL = new dods_url(\"" << url <<
"\");\n"
210 <<
"<style id=\"antiClickjack\">body{display:none !important;}</style>\n"
211 <<
"<script type=\"text/javascript\">\n"
212 <<
" if (self === top) {\n"
213 <<
" var antiClickjack = document.getElementById(\"antiClickjack\");\n"
214 <<
" antiClickjack.parentNode.removeChild(antiClickjack);\n"
216 <<
" top.location = self.location;\n"
223 "<p><h2 align='center'>OPeNDAP Server Dataset Access Form</h2>\n"
224 <<
"<hr>\n" <<
"<form action=\"\">\n" <<
"<table>\n";
225 fprintf(dest,
"%s", oss.str().c_str());
227 wo->write_disposition(url);
229 fprintf(dest,
"<tr><td><td><hr>\n\n");
231 wo->write_global_attributes(dds->get_attr_table());
233 fprintf(dest,
"<tr><td><td><hr>\n\n");
235 wo->write_variable_entries(*dds);
238 oss <<
"</table></form>\n\n" <<
"<hr>\n\n";
239 oss <<
"<address>Send questions or comments to: <a href=\"mailto:"
240 << admin_name <<
"\">" << admin_name <<
"</a></address>" <<
"<p>\n\
241 <a href=\"http://validator.w3.org/check?uri=referer\"><img\n\
242 src=\"http://www.w3.org/Icons/valid-html40\"\n\
243 alt=\"Valid HTML 4.0 Transitional\" height=\"31\" width=\"88\">\n\
244 </a></p>\n" <<
"</body></html>\n";
246 fprintf(dest,
"%s", oss.str().c_str());
269void write_html_form_interface(ostream &strm, DDS * dds,
const string & url,
bool html_header,
270 bool netcdf3_file_response,
bool netcdf4_file_response,
const string & admin_name,
271 const string & help_location)
273 wo =
new WWWOutput(strm);
276 wo->write_html_header();
279 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"
280 <<
"\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n" <<
281 "<html><head><title>OPeNDAP Server Dataset Query Form</title>\n"
282 <<
"<base href=\"" << help_location <<
"\">\n" <<
283 "<script type=\"text/javascript\">\n"
286 <<
"DODS_URL = new dods_url(\"" << url <<
"\");\n"
289 <<
"<style id=\"antiClickjack\">body{display:none !important;}</style>\n"
290 <<
"<script type=\"text/javascript\">\n"
291 <<
" if (self === top) {\n"
292 <<
" var antiClickjack = document.getElementById(\"antiClickjack\");\n"
293 <<
" antiClickjack.parentNode.removeChild(antiClickjack);\n"
295 <<
" top.location = self.location;\n"
302 "<p><h2 align='center'>OPeNDAP Server Dataset Access Form</h2>\n"
303 <<
"<hr>\n" <<
"<form action=\"\">\n" <<
"<table>\n";
305 wo->write_disposition(url, netcdf3_file_response, netcdf4_file_response);
307 strm <<
"<tr><td><td><hr>\n\n" ;
309 wo->write_global_attributes(dds->get_attr_table());
311 strm <<
"<tr><td><td><hr>\n\n" ;
313 wo->write_variable_entries(*dds);
315 strm <<
"</table></form>\n\n" <<
"<hr>\n\n";
316 strm <<
"<address>Send questions or comments to: <a href=\"mailto:"
317 << admin_name <<
"\">" << admin_name <<
"</a></address>" <<
"<p>\n\
318 <a href=\"http://validator.w3.org/check?uri=referer\"><img\n\
319 src=\"http://www.w3.org/Icons/valid-html40\"\n\
320 alt=\"Valid HTML 4.0 Transitional\" height=\"31\" width=\"88\">\n\
321 </a></p>\n" <<
"</body></html>\n";
324const string allowable =
325 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
334string name_for_js_code(
const string & dods_name)
336 return string(
"org_opendap_") +
337 esc2underscore(id2www(dods_name, allowable));
346get_fqn(BaseType *var)
351 static const string dot =
".";
359 else if (!var->get_parent())
362 return get_fqn(var->get_parent()) + dot + var->name();
365string fancy_typename(BaseType * v)
371 return "16 bit Integer";
373 return "16 bit Unsigned integer";
375 return "32 bit Integer";
377 return "32 bit Unsigned integer";
379 return "32 bit Real";
381 return "64 bit Real";
388 Array *a = (Array *) v;
389 type <<
"Array of " << fancy_typename(a->var()) <<
"s ";
390 for (Array::Dim_iter p = a->dim_begin(); p != a->dim_end();
392 type <<
"[" << a->dimension_name(p) <<
" = 0.." << a->
393 dimension_size(p,
false) - 1 <<
"]";
396 case dods_structure_c:
398 case dods_sequence_c:
402 Grid &g =
dynamic_cast<Grid&
>(*v);
403 type <<
"Grid of " << fancy_typename(g.get_array());
406 for (Grid::Map_iter p = g.map_begin(); p != g.map_end(); ++p) {
407 Array &a =
dynamic_cast<Array&
>(**p);
408 type <<
"[" << a.dimension_name(a.dim_begin()) <<
" = 0.." \
409 << a.dimension_size(a.dim_begin(),
false) - 1 <<
"]";
429write_simple_variable(FILE * os, BaseType *var)
433 write_simple_variable( ss, var);
436 fprintf(os,
"%s", ss.str().c_str());
446write_simple_variable(ostream &strm, BaseType *var)
449 const string fqn = get_fqn(var);
451 strm <<
"<script type=\"text/javascript\">\n"
452 << name_for_js_code(fqn) <<
" = new dods_var(\""
454 <<
"\", \"" << name_for_js_code(fqn) <<
"\", 0);\n" <<
455 "DODS_URL.add_dods_var(" << name_for_js_code(fqn) <<
");\n"
459 <<
"<input type=\"checkbox\" name=\"get_" << name_for_js_code(fqn)
460 <<
"\"\n" <<
"onclick=\"" << name_for_js_code(fqn)
461 <<
".handle_projection_change(get_" << name_for_js_code(fqn)
462 <<
") \" onfocus=\"describe_projection()\">\n" <<
"<font size=\"+1\">"
463 << var->name() <<
"</font>" <<
": "
464 << fancy_typename(var) <<
"</b><br>\n\n";
466 strm << var->name() <<
" <select name=\"" << name_for_js_code(fqn)
467 <<
"_operator\"" <<
" onfocus=\"describe_operator()\""
468 <<
" onchange=\"DODS_URL.update_url()\">\n"
469 <<
"<option value=\"=\" selected>=\n"
470 <<
"<option value=\"!=\">!=\n" <<
"<option value=\"<\"><\n"
471 <<
"<option value=\"<=\"><=\n" <<
"<option value=\">\">>\n"
472 <<
"<option value=\">=\">>=\n" <<
"<option value=\"-\">--\n"
475 strm <<
"<input type=\"text\" name=\"" << name_for_js_code(fqn)
477 <<
"\" size=12 onFocus=\"describe_selection()\" "
478 <<
"onChange=\"DODS_URL.update_url()\">\n";
484write_simple_var_attributes(FILE * os, BaseType *var)
487 write_simple_var_attributes(ss, var);
490 fprintf(os,
"%s", ss.str().c_str());
494write_simple_var_attributes(ostream &os,
int rows,
int cols, BaseType *btp)
496 AttrTable &attr = btp->get_attr_table();
499 if (attr.get_size() == 0) {
503 os <<
"<textarea name=\"" << btp->name()
504 <<
"_attr\" rows=\"" << rows
505 <<
"\" cols=\"" << cols <<
"\">\n" ;
506 write_attributes(os, attr,
"");
507 os <<
"</textarea>\n\n" ;
511write_attributes(ostream &os, AttrTable &attr,
const string &prefix)
513 for (AttrTable::Attr_iter a = attr.attr_begin(); a != attr.attr_end(); ++a) {
514 if (attr.is_container(a))
515 write_attributes(os, attr.get_attr_table(a), (prefix ==
"") ? attr.get_name(a) : prefix +
string(
".") + attr.get_name(a));
518 os << prefix <<
"." << attr.get_name(a) <<
": ";
520 os << attr.get_name(a) <<
": ";
522 int num_attr = attr.get_attr_num(a) - 1;
523 for (
int i = 0; i < num_attr; ++i) {
524 os << attr.get_attr(a, i) <<
", ";
526 os << attr.get_attr(a, num_attr) <<
"\n";