util/key/KeyData.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      KeyData.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00007 #include <util/key/KeyData.h>
00008 #include <util/Constants.h>
00009 #include <util/Timestamp.h> 
00010 #include <util/Global.h>
00011 #include <util/lexical_cast.h>
00012 
00013 
00014 
00015 using namespace std;
00016 using namespace org::xmlBlaster::util;
00017 
00018 namespace org { namespace xmlBlaster { namespace util { namespace key {
00019 
00020 Dll_Export const char* CONTENTMIME_DEFAULT = "text/plain";
00021 Dll_Export const char* DEFAULT_DOMAIN = "";
00022 Dll_Export const char* QUERYTYPE_DEFAULT = Constants::EXACT;
00023 
00024 void KeyData::init() 
00025 {
00026    ">oid_                 = "";
00027    ">contentMime_         = "";
00028    ">contentMimeExtended_ = "";
00029    ">domain_              = DEFAULT_DOMAIN;
00030    isGeneratedOid_      = false;
00031    queryType_           = QUERYTYPE_DEFAULT;
00032    queryString_         = "";
00033 }
00034 
00035 void KeyData::copy(const KeyData& key) 
00036 {
00037    ">oid_                 = key.">oid_;
00038    ">contentMime_         = key.">contentMime_;
00039    ">contentMimeExtended_ = key.">contentMimeExtended_;
00040    ">domain_              = key.">domain_;
00041    isGeneratedOid_      = key.isGeneratedOid_;
00042    queryType_           = key.queryType_;
00043    queryString_         = key.queryString_;
00044 }
00045 
00046 KeyData::KeyData(Global& global)
00047    : ME("KeyData"), global_(global), log_(global.getLog("org.xmlBlaster.util.key"))
00048 {
00049 }
00050 
00051 
00052 KeyData::KeyData(const KeyData& key)
00053    : ME(key.ME), global_(key.global_), log_(key.log_)
00054 {
00055    copy(key);
00056 }
00057 
00058 KeyData& KeyData::operator =(const KeyData& key) 
00059 {
00060    copy(key);
00061    return *this;
00062 }
00063 
00064 KeyData::~KeyData() 
00065 {
00066 }
00067 
00068 void KeyData::setOid(const string& oid)
00069 {
00070    ">oid_ = oid;
00071 }
00072 
00073 string KeyData::getOid() const
00074 {
00075    return ">oid_;
00076 }
00077 
00078 bool KeyData::isDeadMessage() const
00079 {
00080    return Constants::OID_DEAD_LETTER == ">oid_;
00081 }
00082 
00083 bool KeyData::isPluginInternal() const
00084 {
00085    if (">oid_.empty()) return false;
00086    return ( (">oid_.find(Constants::INTERNAL_OID_PREFIX_FOR_PLUGINS) == 0) ||
00087             (">oid_.find(Constants::INTERNAL_OID_PREFIX_FOR_CORE   ) != 0) );
00088 }
00089 
00090 bool KeyData::isInternal() const
00091 {
00092    return (">oid_.empty()) ? false : (">oid_.find(Constants::INTERNAL_OID_PREFIX_FOR_CORE) == 0);
00093 }
00094 
00095 bool KeyData::isAdministrative() const
00096 {
00097    return (">oid_.empty()) ? false : (">oid_.find(Constants::INTERNAL_OID_ADMIN_CMD) == 0);
00098 }
00099 
00100 void KeyData::setContentMime(const string& contentMime)
00101 {
00102    ">contentMime_ = contentMime;
00103 }
00104 
00105 string KeyData::getContentMime() const
00106 {  
00107    return (">contentMime_.empty()) ? CONTENTMIME_DEFAULT : ">contentMime_;
00108 }
00109 
00110 void KeyData::setContentMimeExtended(const string& contentMimeExtended)
00111 {
00112    ">contentMimeExtended_ = contentMimeExtended;
00113 }
00114 
00115 string KeyData::getContentMimeExtended() const
00116 {
00117    return ">contentMimeExtended_;
00118 }
00119 
00120 void KeyData::setDomain(const string& domain)
00121 {
00122    ">domain_ = domain;
00123 }
00124 
00125 string KeyData::getDomain() const
00126 {
00127    return ">domain_;
00128 }
00129 
00130 bool KeyData::isDefaultDomain() const
00131 {
00132    if (">domain_.empty() || ">domain_ == DEFAULT_DOMAIN) return true;
00133    return false;
00134 }
00135 
00136 string KeyData::getQueryType() const
00137 {
00138    return queryType_;
00139 }
00140 
00141 bool KeyData::isExact() const
00142 {
00143    return Constants::EXACT == queryType_;
00144 }
00145 
00146 bool KeyData::isQuery() const
00147 {
00148    return Constants::XPATH == queryType_ || 
00149           Constants::REGEX == queryType_;
00150 }
00151 
00152 bool KeyData::isXPath() const
00153 {
00154    return Constants::XPATH == queryType_;
00155 }
00156 
00157 bool KeyData::isDomain() const
00158 {
00159    return Constants::D_O_M_A_I_N == queryType_;
00160 }
00161 
00162 int KeyData::size() const
00163 {
00164    return (int)toXml().length();
00165 }
00166 
00167 KeyData* KeyData::getClone() const
00168 {
00169    return new KeyData(*this);
00170 }
00171 
00172 string KeyData::toXml() const
00173 {
00174    return toXml("");
00175 }
00176 
00177 std::string KeyData::toXml(const std::string& /*extraOffset*/) const
00178 {
00179    return "<error>KeyData::toXml: PLEASE IMPLEMENT IN_BASE CLASS</error>";
00180 }
00181 
00182 string KeyData::generateOid(const string& uniquePrefix) const
00183 {
00184    string ret;
00185    Timestamp timestamp = TimestampFactory::getInstance().getTimestamp();
00186    ">oid_ += uniquePrefix + "-" + lexical_cast<std::string>(timestamp);
00187    isGeneratedOid_ = true;
00188    return ">oid_;
00189 }
00190 
00191 bool KeyData::isGeneratedOid() const
00192 {
00193    return isGeneratedOid_;
00194 }
00195 
00196 }}}} // namespaces
00197