1 /*------------------------------------------------------------------------------
 2 Name:      MsgKeyFactory.cpp
 3 Project:   xmlBlaster.org
 4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
 5 ------------------------------------------------------------------------------*/
 6 
 7 #include <util/key/MsgKeyFactory.h>
 8 # include <util/Global.h>
 9 
10 using namespace std;
11 using namespace org::xmlBlaster::util;
12 
13 namespace org { namespace xmlBlaster { namespace util { namespace key {
14 
15 MsgKeyFactory::MsgKeyFactory(Global& global) 
16    : XmlHandlerBase(global), ME("MsgKeyFactory"), msgKeyData_(global)
17 {
18    inKey_ = 0;
19    OID                   = "oid";
20    CONTENT_MIME          = "contentMime";
21    CONTENT_MIME_EXTENDED = "contentMimeExtended";
22    D_O_M_A_I_N           = "domain";
23    clientTags_           = "";
24 }
25 
26 MsgKeyFactory::~MsgKeyFactory() 
27 {
28    clientTags_  = "";
29 }
30 
31 MsgKeyData MsgKeyFactory::readObject(const string& xmlKey)
32 {
33    clientTags_        = "";
34    clientTagsOffset_  = "";
35    clientTagsDepth_   = 0;
36    if (xmlKey.empty()) init("<key/>");
37    else init(xmlKey);      
38 
39    if (msgKeyData_.getOid().empty()) {
40       msgKeyData_.setOid(msgKeyData_.generateOid(global_.getStrippedId()));
41    }
42    return msgKeyData_;
43 }
44 
45 void MsgKeyFactory::startElement(const string &name, const parser::AttributeMap &attrs)
46 {
47    if (log_.call()) log_.call(ME, "startElement: " + getStartElementAsString(name, attrs));
48    if (name.compare("key") == 0) {
49       msgKeyData_ = MsgKeyData(global_);
50       inKey_++;
51       if (inKey_ > 1) return;
52 
53       if (attrs.size() > 0) {
54          string tmp;
55          if ( getStringAttr(attrs, OID, tmp) ) 
56             msgKeyData_.setOid(tmp); // it is already trimmed 
57          // if ( getStringAttr(attrs, "queryType", tmp) )
58          //    msgKeyData_.setQueryType(tmp);
59          if ( getStringAttr(attrs, CONTENT_MIME, tmp) )
60             msgKeyData_.setContentMime(tmp); // it is already trimmed 
61          if ( getStringAttr(attrs, CONTENT_MIME_EXTENDED, tmp) )
62             msgKeyData_.setContentMimeExtended(tmp); // it is already trimmed 
63          if ( getStringAttr(attrs, D_O_M_A_I_N, tmp) )
64             msgKeyData_.setDomain(tmp); // it is already trimmed 
65       }
66       character_.erase();
67       return;
68    }
69    // then it must be a part of a client tag
70    clientTagsDepth_++;
71    clientTagsOffset_ += "  ";
72    clientTags_ += clientTagsOffset_ + getStartElementAsString(name, attrs) + "\n";
73    character_.erase();
74 }
75 
76 void MsgKeyFactory::endElement(const string &name)
77 {
78    if (name.compare("key") == 0) {
79       inKey_--;
80       if (clientTags_.length() > 0) msgKeyData_.setClientTags(clientTags_);
81       if (inKey_ > 0) return; // ignore nested key tags
82    }
83    if (character_.length() > 0) clientTags_ += clientTagsOffset_ + "  " + character_ + "\n";
84    clientTags_ += clientTagsOffset_ + "</" + name + ">\n";
85    clientTagsDepth_--;
86    for (int i=0; i <clientTagsDepth_; i++) clientTagsOffset_ = "  ";
87    character_.erase();
88  }
89 
90 
91 }}}} // namespace


syntax highlighted by Code2HTML, v. 0.9.1