util/key/QueryKeyData.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      QueryKeyData.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00007 #include <util/key/QueryKeyData.h>
00008 #include <util/Constants.h>
00009 #include <util/XmlBlasterException.h>
00010 #include <util/Global.h>
00011 #include <algorithm>
00012 #include <cctype>
00013 
00014 namespace org { namespace xmlBlaster { namespace util { namespace key {
00015 
00016 using namespace std;
00017 using namespace org::xmlBlaster::util;
00018 using namespace org::xmlBlaster::util::qos;
00019 
00020 QueryKeyData::QueryKeyData(Global& global) : KeyData(global), accessFilterVector_()
00021 {
00022 }
00023 
00024 QueryKeyData::QueryKeyData(Global& global, const string& query, const string& queryType) : KeyData(global), accessFilterVector_()
00025 {
00026    this->queryType_ = checkQueryType(queryType);
00027    if (isExact()) {
00028       setOid(query);
00029    }
00030    else if (isXPath()) {
00031       this->queryString_ = query;
00032    }
00033    else if (isDomain()) {
00034       setDomain(query);
00035    }
00036    else {
00037       throw XmlBlasterException(USER_ILLEGALARGUMENT, ME + "::setQueryType",
00038                                 "Your queryType=" + queryType_ + " is invalid, use one of '" + 
00039                                 Constants::EXACT + "' , '" + Constants::XPATH + "' , '" + Constants::D_O_M_A_I_N + "'");
00040    }
00041 }
00042 
00043 QueryKeyData::QueryKeyData(const QueryKeyData& key) : KeyData(key), accessFilterVector_(key.accessFilterVector_)
00044 {
00045 }
00046 
00047 QueryKeyData& QueryKeyData::operator =(const QueryKeyData& key) 
00048 {
00049    accessFilterVector_ = key.accessFilterVector_;
00050    return *this;
00051 }
00052 
00053 string QueryKeyData::checkQueryType(const string& queryType)
00054 {
00055    string tmp = queryType;
00056    // transform (tmp.begin(), tmp.end(), tmp.begin(), ::toupper);
00057    string::iterator iter = tmp.begin();
00058    while (iter != tmp.end()) {
00059       *iter = ::toupper(*iter);
00060       iter++;
00061    }
00062 
00063    if (Constants::EXACT != tmp && Constants::XPATH !=tmp && Constants::D_O_M_A_I_N !=tmp)
00064       throw XmlBlasterException(USER_ILLEGALARGUMENT, ME + "::setQueryType",
00065                                 "Your queryType=" + queryType + " is invalid, use one of '" + 
00066                                 Constants::EXACT + "' , '" + Constants::XPATH + "' , '" + Constants::D_O_M_A_I_N + "'");
00067    return tmp;
00068 }
00069 
00070 void QueryKeyData::setQueryType(const string& queryType)
00071 {
00072    queryType_ = checkQueryType(queryType);
00073 }
00074 
00080 void QueryKeyData::setQueryString(const string& tags)
00081 {
00082    this->queryType_ = Constants::XPATH;
00083    this->queryString_ = tags;
00084 }
00085 
00086 void QueryKeyData::setOid(const string& oid)
00087 {
00088    this->queryType_ = Constants::EXACT;
00089    ">oid_ = oid;
00090 }
00091 
00092 string QueryKeyData::getQueryString() const
00093 {
00094    return queryString_;
00095 }
00096 
00103 AccessFilterVector QueryKeyData::getAccessFilterVector() const 
00104 {
00105    return accessFilterVector_;
00106 }
00107 
00108 void QueryKeyData::addFilter(const AccessFilterQos& qos) 
00109 {
00110    accessFilterVector_.insert(accessFilterVector_.end(), qos);
00111 }
00112 
00113 string QueryKeyData::toXml() const
00114 {
00115    return toXml("");
00116 }
00117 
00118 string QueryKeyData::toXml(const string& extraOffset) const
00119 {
00120    string ret;
00121    string offset = Constants::OFFSET + extraOffset;
00122 
00123    ret += offset + "<key oid='" + ">oid_ + "'";
00124    if (!getContentMime().empty())
00125       ret += " contentMime='" + getContentMime() + "'";
00126    if (!getContentMimeExtended().empty())
00127       ret += " contentMimeExtended='" + getContentMimeExtended() + "'";
00128    if (!getDomain().empty())
00129       ret += " domain='" + getDomain() + "'";
00130 
00131    if (!getQueryType().empty() && Constants::EXACT != getQueryType())
00132          ret += " queryType='" + getQueryType() + "'";
00133    ret += ">";
00134    if (!queryString_.empty()) {
00135       ret += offset + Constants::INDENT + getQueryString();
00136    }
00137 
00138    AccessFilterVector::const_iterator iter = accessFilterVector_.begin();
00139    while (iter != accessFilterVector_.end()) {
00140       ret += (*iter).toXml(extraOffset + Constants::INDENT);
00141       iter++;
00142    }
00143    ret += "</key>";
00144   return ret;
00145 }
00146 
00147 QueryKeyData* QueryKeyData::getClone() const
00148 {
00149    return new QueryKeyData(*this);
00150 }
00151 
00152 }}}} // namespace
00153