1 /*------------------------------------------------------------------------------
  2 Name:      KeyData.cpp
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 
  7 #include <util/key/KeyData.h>
  8 #include <util/Constants.h>
  9 #include <util/Timestamp.h> 
 10 #include <util/Global.h>
 11 #include <util/lexical_cast.h>
 12 
 13 
 14 
 15 using namespace std;
 16 using namespace org::xmlBlaster::util;
 17 
 18 namespace org { namespace xmlBlaster { namespace util { namespace key {
 19 
 20 Dll_Export const char* CONTENTMIME_DEFAULT = "text/plain";
 21 Dll_Export const char* DEFAULT_DOMAIN = "";
 22 Dll_Export const char* QUERYTYPE_DEFAULT = Constants::EXACT;
 23 
 24 void KeyData::init() 
 25 {
 26    oid_                 = "";
 27    contentMime_         = "";
 28    contentMimeExtended_ = "";
 29    domain_              = DEFAULT_DOMAIN;
 30    isGeneratedOid_      = false;
 31    queryType_           = QUERYTYPE_DEFAULT;
 32    queryString_         = "";
 33 }
 34 
 35 void KeyData::copy(const KeyData& key) 
 36 {
 37    oid_                 = key.oid_;
 38    contentMime_         = key.contentMime_;
 39    contentMimeExtended_ = key.contentMimeExtended_;
 40    domain_              = key.domain_;
 41    isGeneratedOid_      = key.isGeneratedOid_;
 42    queryType_           = key.queryType_;
 43    queryString_         = key.queryString_;
 44 }
 45 
 46 KeyData::KeyData(Global& global)
 47    : ME("KeyData"), global_(global), log_(global.getLog("org.xmlBlaster.util.key"))
 48 {
 49 }
 50 
 51 
 52 KeyData::KeyData(const KeyData& key)
 53    : ME(key.ME), global_(key.global_), log_(key.log_)
 54 {
 55    copy(key);
 56 }
 57 
 58 KeyData& KeyData::operator =(const KeyData& key) 
 59 {
 60    copy(key);
 61    return *this;
 62 }
 63 
 64 KeyData::~KeyData() 
 65 {
 66 }
 67 
 68 void KeyData::setOid(const string& oid)
 69 {
 70    oid_ = oid;
 71 }
 72 
 73 string KeyData::getOid() const
 74 {
 75    return oid_;
 76 }
 77 
 78 bool KeyData::isDeadMessage() const
 79 {
 80    return Constants::OID_DEAD_LETTER == oid_;
 81 }
 82 
 83 bool KeyData::isPluginInternal() const
 84 {
 85    if (oid_.empty()) return false;
 86    return ( (oid_.find(Constants::INTERNAL_OID_PREFIX_FOR_PLUGINS) == 0) ||
 87             (oid_.find(Constants::INTERNAL_OID_PREFIX_FOR_CORE   ) != 0) );
 88 }
 89 
 90 bool KeyData::isInternal() const
 91 {
 92    return (oid_.empty()) ? false : (oid_.find(Constants::INTERNAL_OID_PREFIX_FOR_CORE) == 0);
 93 }
 94 
 95 bool KeyData::isAdministrative() const
 96 {
 97    return (oid_.empty()) ? false : (oid_.find(Constants::INTERNAL_OID_ADMIN_CMD) == 0);
 98 }
 99 
100 void KeyData::setContentMime(const string& contentMime)
101 {
102    contentMime_ = contentMime;
103 }
104 
105 string KeyData::getContentMime() const
106 {  
107    return (contentMime_.empty()) ? CONTENTMIME_DEFAULT : contentMime_;
108 }
109 
110 void KeyData::setContentMimeExtended(const string& contentMimeExtended)
111 {
112    contentMimeExtended_ = contentMimeExtended;
113 }
114 
115 string KeyData::getContentMimeExtended() const
116 {
117    return contentMimeExtended_;
118 }
119 
120 void KeyData::setDomain(const string& domain)
121 {
122    domain_ = domain;
123 }
124 
125 string KeyData::getDomain() const
126 {
127    return domain_;
128 }
129 
130 bool KeyData::isDefaultDomain() const
131 {
132    if (domain_.empty() || domain_ == DEFAULT_DOMAIN) return true;
133    return false;
134 }
135 
136 string KeyData::getQueryType() const
137 {
138    return queryType_;
139 }
140 
141 bool KeyData::isExact() const
142 {
143    return Constants::EXACT == queryType_;
144 }
145 
146 bool KeyData::isQuery() const
147 {
148    return Constants::XPATH == queryType_ || 
149           Constants::REGEX == queryType_;
150 }
151 
152 bool KeyData::isXPath() const
153 {
154    return Constants::XPATH == queryType_;
155 }
156 
157 bool KeyData::isDomain() const
158 {
159    return Constants::D_O_M_A_I_N == queryType_;
160 }
161 
162 int KeyData::size() const
163 {
164    return (int)toXml().length();
165 }
166 
167 KeyData* KeyData::getClone() const
168 {
169    return new KeyData(*this);
170 }
171 
172 string KeyData::toXml() const
173 {
174    return toXml("");
175 }
176 
177 std::string KeyData::toXml(const std::string& /*extraOffset*/) const
178 {
179    return "<error>KeyData::toXml: PLEASE IMPLEMENT IN_BASE CLASS</error>";
180 }
181 
182 string KeyData::generateOid(const string& uniquePrefix) const
183 {
184    string ret;
185    Timestamp timestamp = TimestampFactory::getInstance().getTimestamp();
186    oid_ += uniquePrefix + "-" + lexical_cast<std::string>(timestamp);
187    isGeneratedOid_ = true;
188    return oid_;
189 }
190 
191 bool KeyData::isGeneratedOid() const
192 {
193    return isGeneratedOid_;
194 }
195 
196 }}}} // namespaces


syntax highlighted by Code2HTML, v. 0.9.1