33#include "AISResources.h"
34#include "AISDatabaseParser.h"
49 if (r.d_rule != Resource::overwrite) {
51 (r.d_rule == Resource::fallback) ? os <<
"fallback\"" : os <<
"replace\"";
53 os <<
" url=\"" << r.d_url <<
"\"/>";
64 os <<
"<?xml version=\"1.0\" encoding=\"US-ASCII\" standalone=\"yes\"?>"
66 os <<
"<!DOCTYPE ais SYSTEM \"http://xml.opendap.org/ais/ais_database.dtd\">" << endl;
67 os <<
"<ais xmlns=\"http://xml.opendap.org/ais\">" << endl;
69 for (AISResources::ResourceRegexpsCIter pos = ais_res.d_re.begin();
70 pos != ais_res.d_re.end(); ++pos) {
71 os <<
"<entry>" << endl;
73 os <<
"<primary regexp=\"" << pos->first <<
"\"/>" << endl;
75 for (ResourceVectorCIter i = pos->second.begin();
76 i != pos->second.end(); ++i) {
79 os <<
"</entry>" << endl;
85 for (AISResources::ResourceMapCIter pos2 = ais_res.d_db.begin();
86 pos2 != ais_res.d_db.end(); ++pos2) {
87 os <<
"<entry>" << endl;
89 os <<
"<primary url=\"" << pos2->first <<
"\"/>" << endl;
91 for (ResourceVectorCIter i = pos2->second.begin();
92 i != pos2->second.end(); ++i) {
95 os <<
"</entry>" << endl;
98 os <<
"</ais>" << endl;
107 read_database(database);
130 ResourceMapIter pos = d_db.find(url);
131 if (pos == d_db.end()) {
132 d_db.insert(std::make_pair(url, rv));
136 for (ResourceVectorCIter i = rv.begin(); i != rv.end(); ++i)
137 pos->second.push_back(*i);
160 ResourceRegexpsIter pos = find_if(d_re.begin(), d_re.end(),
161 [re](
const RVPair &p){ return re == p.first; });
162 if (pos == d_re.end()) {
163 d_re.push_back(std::make_pair(re, rv));
167 for (ResourceVectorCIter i = rv.begin(); i != rv.end(); ++i)
168 pos->second.push_back(*i);
188 return ((d_db.find(primary) != d_db.end())
189 || (find_if(d_re.begin(), d_re.end(),
190 [primary] (
const RVPair &p) {
191 Regex r(p.first.c_str());
192 return r.match(p.first) != -1; } )
219 const ResourceMapIter &i = d_db.find(primary);
226 const ResourceRegexpsIter &j = find_if(d_re.begin(), d_re.end(),
227 [primary] (
const RVPair &p) {
228 Regex r(p.first.c_str());
229 return r.match(p.first) != -1; } );
231 copy(j->second.begin(), j->second.end(), inserter(rv, rv.begin()));
251 parser.
intern(database,
this);
266 fos.open(filename.c_str());
271 fos << *
this << endl;
void intern(const string &database, AISResources *ais)
virtual void write_database(const string &filename)
virtual ResourceVector get_resource(const string &primary)
virtual bool has_resource(const string &primary) const
virtual void read_database(const string &database)
virtual void add_regexp_resource(const string ®exp, const Resource &ancillary)
virtual void add_url_resource(const string &url, const Resource &ancillary)
Associate a rule with an ancillary resource.
top level DAP object to house generic methods
ostream & operator<<(ostream &os, const Resource &r)