1 /*------------------------------------------------------------------------------
2 Name: AccessFilterQos.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Holding filter address string and protocol string
6 ------------------------------------------------------------------------------*/
7
8 /**
9 * Helper class holding filter markup from a subscribe() or get() QoS.
10 * <p />
11 * <pre>
12 * <filter type='ContentLength' version='1.0'>
13 * 800
14 * </filter>
15 * </pre>
16 * This example addresses the plugin in xmlBlaster.properties file
17 * <pre>
18 * MimeAccessPlugin[ContentLenFilter][1.0]=org.xmlBlaster.engine.mime.demo.ContentLenFilter
19 * </pre>
20 * The filter rules apply for cluster configuration as well.
21 *
22 * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/mime.plugin.accessfilter.html">MIME based access filter plugin framework</a>
23 */
24
25 #include <util/qos/AccessFilterQos.h>
26 #include <util/Global.h>
27
28 using namespace std;
29 using namespace org::xmlBlaster::util;
30 using namespace org::xmlBlaster::util::qos;
31
32 namespace org { namespace xmlBlaster { namespace util { namespace qos {
33
34
35 Dll_Export const char* ACCESSFILTER_DEFAULT_version = "1.0";
36 Dll_Export const char* ACCESSFILTER_DEFAULT_type = "";
37
38 void AccessFilterQos::copy(const AccessFilterQos& qos)
39 {
40 type_ = qos.type_;
41 version_ = qos.version_;
42 }
43
44 /**
45 */
46 AccessFilterQos::AccessFilterQos(Global& global)
47 : ME("AccessFilterQos"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")), query_(global)
48 {
49 type_ = "";
50 setVersion(global_.getProperty().getStringProperty("accessFilter.version", ACCESSFILTER_DEFAULT_version));
51 setType(global_.getProperty().getStringProperty("accessFilter.type", ACCESSFILTER_DEFAULT_type));
52 }
53
54 /**
55 * @param glob The global handle holding environment and logging objects
56 * @param type The plugin name, as used in xmlBlaster.properties e.g. "ContentLenFilter".
57 * @param version The plugin version, defaults to "1.0"
58 * @param query Your filter rule
59 */
60 AccessFilterQos::AccessFilterQos(Global& global, const string& type, const string& version, const string& query)
61 : ME("AccessFilterQos"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")), query_(global, query)
62 {
63 setType(type);
64 setVersion(version);
65 }
66
67 /**
68 * @param glob The global handle holding environment and logging objects
69 * @param type The plugin name, as used in xmlBlaster.properties e.g. "ContentLenFilter".
70 * @param version The plugin version, defaults to "1.0"
71 * @param query Your filter rule
72 */
73 AccessFilterQos::AccessFilterQos(Global& global, const string& type, const string& version, const Query& query)
74 : ME("AccessFilterQos"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")), query_(query)
75 {
76 setType(type);
77 setVersion(version);
78 }
79
80 AccessFilterQos::AccessFilterQos(const AccessFilterQos& qos)
81 : ME(qos.ME), global_(qos.global_), log_(qos.log_), query_(qos.query_)
82 {
83 copy(qos);
84 }
85
86 AccessFilterQos& AccessFilterQos::operator =(const AccessFilterQos& qos)
87 {
88 copy(qos);
89 return *this;
90 }
91
92 /**
93 * @param type The plugin name, as used in xmlBlaster.properties e.g. "ContentLenFilter".
94 */
95 void AccessFilterQos::setType(const string& type)
96 {
97 type_ = type;
98 }
99
100 /**
101 * Returns the plugins name.
102 * @return e.g. "ContentLenFilter"
103 */
104 string AccessFilterQos::getType() const
105 {
106 return type_;
107 }
108
109 /**
110 * @param version The version of the plugin, defaults to "1.0", but can anything you like.
111 */
112 void AccessFilterQos::setVersion(const string& version)
113 {
114 version_ = version;
115 }
116
117 /**
118 * Returns the plugins version.
119 * @return e.g. "1.0"
120 */
121 string AccessFilterQos::getVersion() const
122 {
123 return version_;
124 }
125
126 /**
127 * Set the filter query, it should fit to the protocol-type.
128 *
129 * @param query The filter query, e.g. "8000" for max length of a content with "ContentLenFilter" plugin
130 */
131 void AccessFilterQos::setQuery(const Query& query)
132 {
133 query_ = query;
134 }
135
136 /**
137 * Returns the query, the syntax is depending on what your plugin supports.
138 * @return e.g. "a>12 AND b<15"
139 */
140 Query AccessFilterQos::getQuery() const
141 {
142 return query_;
143 }
144
145
146 /**
147 * Dump state of this object into a XML ASCII string.
148 * <br>
149 * Only none default values are dumped for performance reasons
150 * @param extraOffset indenting of tags for nice output
151 * @return The xml representation
152 */
153 string AccessFilterQos::toXml(const string& extraOffset) const
154 {
155 string ret;
156 string offset = "\n " + extraOffset;
157
158 ret += offset + "<filter type='" + getType() + "'";
159 if (ACCESSFILTER_DEFAULT_version != getVersion())
160 ret += " version='" + getVersion() + "'";
161 ret += ">";
162 string help = getQuery().toString();
163 if (help.find("<![CDATA[") != help.npos)
164 ret += offset + " " + help;
165 else
166 ret += offset + " <![CDATA[" + help + "]]>";
167 ret += offset + "</filter>";
168
169 return ret;
170 }
171
172 }}}}
syntax highlighted by Code2HTML, v. 0.9.1