bes  Updated for version 3.20.6
WWWArray.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
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 // Implementation for WWWArray. See WWWByte.cc
33 //
34 // 4/7/99 jhrg
35 
36 #include "config.h"
37 
38 static char rcsid[] not_used =
39  { "$Id$" };
40 
41 #include <iostream>
42 #include <sstream>
43 #include <string>
44 
45 #include "InternalErr.h"
46 #include "escaping.h"
47 
48 #include "WWWArray.h"
49 #include "WWWOutput.h"
50 #include "get_html_form.h"
51 
52 using namespace dap_html_form;
53 
54 BaseType *WWWArray::ptr_duplicate()
55 {
56  return new WWWArray(*this);
57 }
58 
59 WWWArray::WWWArray(const string & n, BaseType * v): Array(n, v), _redirect(0)
60 {
61 }
62 
63 WWWArray::WWWArray(Array * bt) : Array( bt->name(), 0), _redirect(bt)
64 {
65  BaseType *abt = basetype_to_wwwtype(bt->var());
66  abt->set_attr_table(bt->get_attr_table());
67  add_var(abt);
68  // add_var makes a copy of the base type passed to it, so delete it here
69  delete abt;
70 
71  // Copy the dimensions
72  Dim_iter p = bt->dim_begin();
73  while ( p != bt->dim_end() ) {
74  append_dim(bt->dimension_size(p, true), bt->dimension_name(p));
75  ++p;
76  }
77 }
78 
79 WWWArray::~WWWArray()
80 {
81 }
82 
83 void
84 WWWArray::do_print_val( ostream &ss )
85 {
86  const string fqn = get_fqn(this);
87  ss << "<script type=\"text/javascript\">\n"
88  << "<!--\n"
89  << name_for_js_code(fqn) << " = new dods_var(\""
90  << id2www_ce(fqn)
91  << "\", \"" << name_for_js_code(fqn) << "\", 1);\n"
92  << "DODS_URL.add_dods_var(" << name_for_js_code(fqn) << ");\n"
93  << "// -->\n" << "</script>\n";
94 
95  // Slight formatting change: The typename is no longer bold. 10/28/08
96  ss << "<b>"
97  << "<input type=\"checkbox\" name=\"get_" <<
98  name_for_js_code(fqn)
99  << "\"\n" << "onclick=\"" << name_for_js_code(fqn)
100  << ".handle_projection_change(get_"
101  << name_for_js_code(fqn) << ") \" onfocus=\"describe_projection()\">\n"
102  << "<font size=\"+1\">" << name() << "</font></b>"
103  << ": " << fancy_typename(this) << "<br>\n\n";
104 
105  Dim_iter p = dim_begin();
106  for (int i = 0; p != dim_end(); ++i, ++p) {
107  int size = dimension_size(p, true);
108  string n = dimension_name(p);
109  if (n != "")
110  ss << n << ":";
111  ss << "<input type=\"text\" name=\"" << name_for_js_code(fqn)
112  << "_" << i
113  << "\" size=8 onfocus=\"describe_index()\""
114  << " onChange=\"DODS_URL.update_url()\">\n";
115  ss << "<script type=\"text/javascript\">\n"
116  << "<!--\n"
117  << name_for_js_code(fqn) << ".add_dim(" << size << ");\n"
118  << "// -->\n" << "</script>\n";
119  }
120 
121  ss << "<br>\n\n";
122 }
123 
124 void
125 WWWArray::print_val(FILE * os, string, bool /*print_decl_p */ )
126 {
127  ostringstream ss ;
128  do_print_val( ss ) ;
129  fprintf(os, "%s", ss.str().c_str());
130 }
131 
132 void
133 WWWArray::print_val(ostream &strm, string, bool /*print_decl_p */ )
134 {
135  ostringstream ss ;
136  do_print_val( strm ) ;
137 }
138 
WWWArray
Definition: WWWArray.h:43
WWWArray::print_val
virtual void print_val(FILE *os, string space="", bool print_decl_p=true)
Overload of BaseType mfunc. This prints arrays using commas and CRs.
Definition: WWWArray.cc:125