libdap++ Updated for version 3.8.2
ResponseBuilder.h
Go to the documentation of this file.
00001 
00002 // -*- mode: c++; c-basic-offset:4 -*-
00003 
00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00005 // Access Protocol.
00006 
00007 // Copyright (c) 2011 OPeNDAP, Inc.
00008 // Author: James Gallagher <jgallagher@opendap.org>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00025 
00026 #ifndef _response_builder_h
00027 #define _response_builder_h
00028 
00029 #include <string>
00030 #include <set>
00031 
00032 #ifndef _das_h
00033 #include "DAS.h"
00034 #endif
00035 
00036 #ifndef _dds_h
00037 #include "DDS.h"
00038 #endif
00039 
00040 #ifndef constraint_evaluator_h
00041 #include "ConstraintEvaluator.h"
00042 #endif
00043 
00044 #ifndef _object_type_h
00045 #include "ObjectType.h"
00046 #endif
00047 
00048 #ifndef _encodingtype_h
00049 #include "EncodingType.h"
00050 #endif
00051 
00052 namespace libdap
00053 {
00054 
00060 class ResponseBuilder
00061 {
00062 public:
00063     friend class ResponseBuilderTest;
00064 
00065 protected:
00066     string d_dataset;           
00067     string d_ce;                
00068     int d_timeout;              
00069     string d_default_protocol;  
00070 
00071 #if 0   // Keyword support moved to Keywords class
00072     set<string> d_keywords;     
00073     set<string> d_known_keywords; 
00074 #endif
00075     void initialize();
00076 
00077 public:
00078 
00082     ResponseBuilder() {
00083         initialize();
00084     }
00085 
00086     virtual ~ResponseBuilder();
00087 #if 0
00088     virtual void add_keyword(const string &kw);
00089     virtual bool is_keyword(const string &kw) const;
00090     virtual list<string> get_keywords() const;
00091     // This method holds all of the keywords that this version of libdap groks
00092     virtual bool is_known_keyword(const string &w) const;
00093 #endif
00094 
00095     virtual string get_ce() const;
00096     virtual void set_ce(string _ce);
00097 
00098     virtual string get_dataset_name() const;
00099     virtual void set_dataset_name(const string _dataset);
00100 
00101     void set_timeout(int timeout = 0);
00102     int get_timeout() const;
00103 
00104     virtual void establish_timeout(ostream &stream) const;
00105 
00106     virtual void send_das(ostream &out, DAS &das,
00107                           bool with_mime_headers = true) const;
00108     virtual void send_dds(ostream &out, DDS &dds, ConstraintEvaluator &eval,
00109                           bool constrained = false,
00110                           bool with_mime_headers = true) const;
00111 
00112     virtual void dataset_constraint(ostream &out, DDS &dds, ConstraintEvaluator &eval,
00113                                     bool ce_eval = true) const;
00114     virtual void dataset_constraint_ddx(ostream &out, DDS & dds, ConstraintEvaluator & eval,
00115                                    const string &boundary, const string &start,
00116                                    bool ce_eval = true) const;
00117 
00118     virtual void send_data(ostream &data_stream, DDS &dds, ConstraintEvaluator &eval,
00119                            bool with_mime_headers = true) const;
00120 
00121     virtual void send_ddx(ostream &out, DDS &dds, ConstraintEvaluator &eval,
00122                           bool with_mime_headers = true) const;
00123 
00124     virtual void send_data_ddx(ostream &data_stream, DDS &dds, ConstraintEvaluator &eval,
00125                            const string &start, const string &boundary,
00126                            bool with_mime_headers = true) const;
00127 
00128     // These functions are used both by the methods above and by other code
00129 
00130     void set_mime_text(ostream &out, ObjectType type = unknown_type,
00131                        EncodingType enc = x_plain,
00132                        const time_t last_modified = 0,
00133                        const string &protocol = "") const;
00134 
00135     void set_mime_html(ostream &out, ObjectType type = unknown_type,
00136                        EncodingType enc = x_plain,
00137                        const time_t last_modified = 0,
00138                        const string &protocol = "") const;
00139 
00140     void set_mime_binary(ostream &out, ObjectType type = unknown_type,
00141                          EncodingType enc = x_plain,
00142                          const time_t last_modified = 0,
00143                          const string &protocol = "") const;
00144 
00145     void set_mime_multipart(ostream &out, const string &boundary,
00146         const string &start, ObjectType type = unknown_type,
00147             EncodingType enc = x_plain,
00148             const time_t last_modified = 0,
00149             const string &protocol = "") const;
00150 
00151     void set_mime_ddx_boundary(ostream &out, const string &boundary,
00152         const string &start, ObjectType type = unknown_type,
00153             EncodingType enc = x_plain) const;
00154 
00155     void set_mime_data_boundary(ostream &out, const string &boundary,
00156         const string &cid, ObjectType type = unknown_type,
00157             EncodingType enc = x_plain) const;
00158 
00159     void set_mime_error(ostream &out, int code = 404,
00160                         const string &reason = "Dataset not found",
00161                         const string &protocol = "") const;
00162 };
00163 
00164 } // namespace libdap
00165 
00166 #endif // _response_builder_h