util/key/MsgKeyFactory.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      MsgKeyFactory.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00007 #include <util/key/MsgKeyFactory.h>
00008 # include <util/Global.h>
00009 
00010 using namespace std;
00011 using namespace org::xmlBlaster::util;
00012 
00013 namespace org { namespace xmlBlaster { namespace util { namespace key {
00014 
00015 MsgKeyFactory::MsgKeyFactory(Global& global) 
00016    : XmlHandlerBase(global), ME("MsgKeyFactory"), msgKeyData_(global)
00017 {
00018    inKey_ = 0;
00019    OID                   = "oid";
00020    CONTENT_MIME          = "contentMime";
00021    CONTENT_MIME_EXTENDED = "contentMimeExtended";
00022    D_O_M_A_I_N           = "domain";
00023    clientTags_           = "";
00024 }
00025 
00026 MsgKeyFactory::~MsgKeyFactory() 
00027 {
00028    clientTags_  = "";
00029 }
00030 
00031 MsgKeyData MsgKeyFactory::readObject(const string& xmlKey)
00032 {
00033    clientTags_        = "";
00034    clientTagsOffset_  = "";
00035    clientTagsDepth_   = 0;
00036    if (xmlKey.empty()) init("<key/>");
00037    else init(xmlKey);      
00038 
00039    if (msgKeyData_.getOid().empty()) {
00040       msgKeyData_.setOid(msgKeyData_.generateOid(global_.getStrippedId()));
00041    }
00042    return msgKeyData_;
00043 }
00044 
00045 void MsgKeyFactory::startElement(const string &name, const parser::AttributeMap &attrs)
00046 {
00047    if (log_.call()) log_.call(ME, "startElement: " + getStartElementAsString(name, attrs));
00048    if (name.compare("key") == 0) {
00049       msgKeyData_ = MsgKeyData(global_);
00050       inKey_++;
00051       if (inKey_ > 1) return;
00052 
00053       if (attrs.size() > 0) {
00054          string tmp;
00055          if ( getStringAttr(attrs, OID, tmp) ) 
00056             msgKeyData_.setOid(tmp); // it is already trimmed 
00057          // if ( getStringAttr(attrs, "queryType", tmp) )
00058          //    msgKeyData_.setQueryType(tmp);
00059          if ( getStringAttr(attrs, CONTENT_MIME, tmp) )
00060             msgKeyData_.setContentMime(tmp); // it is already trimmed 
00061          if ( getStringAttr(attrs, CONTENT_MIME_EXTENDED, tmp) )
00062             msgKeyData_.setContentMimeExtended(tmp); // it is already trimmed 
00063          if ( getStringAttr(attrs, D_O_M_A_I_N, tmp) )
00064             msgKeyData_.setDomain(tmp); // it is already trimmed 
00065       }
00066       character_.erase();
00067       return;
00068    }
00069    // then it must be a part of a client tag
00070    clientTagsDepth_++;
00071    clientTagsOffset_ += "  ";
00072    clientTags_ += clientTagsOffset_ + getStartElementAsString(name, attrs) + "\n";
00073    character_.erase();
00074 }
00075 
00076 void MsgKeyFactory::endElement(const string &name)
00077 {
00078    if (name.compare("key") == 0) {
00079       inKey_--;
00080       if (clientTags_.length() > 0) msgKeyData_.setClientTags(clientTags_);
00081       if (inKey_ > 0) return; // ignore nested key tags
00082    }
00083    if (character_.length() > 0) clientTags_ += clientTagsOffset_ + "  " + character_ + "\n";
00084    clientTags_ += clientTagsOffset_ + "</" + name + ">\n";
00085    clientTagsDepth_--;
00086    for (int i=0; i <clientTagsDepth_; i++) clientTagsOffset_ = "  ";
00087    character_.erase();
00088  }
00089 
00090 
00091 }}}} // namespace
00092