00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00030
00031
00032
00034
00035
00036 #include <qdom.h>
00037 #include <qstring.h>
00038 #include <qstringlist.h>
00039 #include <qvaluelist.h>
00040
00041
00042 #include <domutils.h>
00043
00044
00048
00050 void DomUtils::readNode(QDomNode* node, QString* value)
00052 {
00053 *value = node->toElement().attribute("value").stripWhiteSpace();
00054 }
00055
00057 void DomUtils::readNode(QDomNode* node, QStringList* values)
00059 {
00060
00061
00062 QDomNode childNode = node->namedItem("array");
00063 if(!childNode.isNull())
00064 *values = QStringList::split(" ",childNode.toElement().text());
00065 }
00066
00068 void DomUtils::readNode(QDomNode* node, unsigned int* value)
00070 {
00071
00072
00073 *value = node->toElement().attribute("value","0").toUShort();
00074 }
00075
00077 void DomUtils::readNode(QDomNode* node, int* value)
00079 {
00080
00081
00082 *value = node->toElement().attribute("value","0").toInt();
00083 }
00084
00086 void DomUtils::readNode(QDomNode* node, float* value)
00088 {
00089
00090
00091 *value = node->toElement().attribute("value","0.0").toFloat();
00092 }
00093
00095 void DomUtils::readNode(QDomNode* node, double* value)
00097 {
00098
00099
00100 *value = node->toElement().attribute("value","0.0").toDouble();
00101 }
00102
00104 void DomUtils::readNode(QDomNode* node, bool* value)
00106 {
00107
00108
00109 *value = node->toElement().attribute("value").stripWhiteSpace() == "true";
00110 }
00111
00113 void DomUtils::readNode(QDomNode* node, std::vector<unsigned int>* values)
00115 {
00116
00117
00118 values->clear();
00119 QDomNode childNode = node->namedItem("array");
00120 if(!childNode.isNull())
00121 {
00122 QStringList valueList = QStringList::split(" ",childNode.toElement().text());
00123 for(QStringList::Iterator it = valueList.begin(); it != valueList.end(); it++)
00124 values->push_back((*it).toUShort());
00125 }
00126 }
00127
00129 void DomUtils::readNode(QDomNode* node, std::vector<double>* values)
00131 {
00132
00133
00134 values->clear();
00135 QDomNode childNode = node->namedItem("array");
00136 if(!childNode.isNull())
00137 {
00138 QStringList valueList = QStringList::split(" ",childNode.toElement().text());
00139 for(QStringList::Iterator it = valueList.begin(); it != valueList.end(); it++)
00140 values->push_back((*it).toDouble());
00141 }
00142 }
00143
00145 void DomUtils::readNode(QDomNode* node, std::vector<bool>* values)
00147 {
00148
00149
00150 values->clear();
00151 QDomNode childNode = node->namedItem("array");
00152 if(!childNode.isNull())
00153 {
00154 QStringList valueList = QStringList::split(" ",childNode.toElement().text());
00155 for(QStringList::Iterator it = valueList.begin(); it != valueList.end(); it++)
00156 values->push_back(*it == "true");
00157 }
00158 }
00159
00161 void DomUtils::readNode(QDomNode* node, QValueList<int>* values)
00163 {
00164
00165
00166 values->clear();
00167 QDomNode childNode = node->namedItem("array");
00168 if(!childNode.isNull())
00169 {
00170 QStringList valueList = QStringList::split(" ",childNode.toElement().text());
00171 for(QStringList::Iterator it = valueList.begin(); it != valueList.end(); it++)
00172 values->push_back((*it).toInt());
00173 }
00174 }
00175
00177 void DomUtils::makeNode(QDomElement* root, const QString nodeData, const QString dictRef, const QString attributeName, const QString attributeValue)
00180 {
00181 QDomElement childNode = root->ownerDocument().createElement("parameter");
00182 if(!dictRef.isEmpty())
00183 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00185
00186
00187 if(!attributeName.isEmpty())
00188 childNode.setAttribute(attributeName, attributeValue);
00189
00190 childNode.setAttribute("value", nodeData);
00191
00192 root->appendChild(childNode);
00193 }
00194
00196 void DomUtils::makeNode(QDomElement* root, const QStringList nodeData, const QString dictRef, const QString attributeName, const QString attributeValue)
00198 {
00199 if(nodeData.size() == 0)
00200 return;
00201 QDomElement childNode = root->ownerDocument().createElement("parameter");
00202 if(!dictRef.isEmpty())
00203 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00204
00205
00206 if(!attributeName.isEmpty())
00207 childNode.setAttribute(attributeName, attributeValue);
00208
00209 QDomElement grandChildNode = root->ownerDocument().createElement("array");
00210 grandChildNode.setAttribute("size",QString::number(nodeData.size()));
00211 QDomText textNode = root->ownerDocument().createTextNode(nodeData.join(" "));
00212 grandChildNode.appendChild(textNode);
00213 childNode.appendChild(grandChildNode);
00214 root->appendChild(childNode);
00215 }
00216
00218 void DomUtils::makeNode(QDomElement* root, const unsigned int nodeData, const QString dictRef)
00220 {
00221 QDomElement childNode = root->ownerDocument().createElement("parameter");
00222 if(!dictRef.isEmpty())
00223 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00224
00225
00226
00227 childNode.setAttribute("value", nodeData);
00228
00229 root->appendChild(childNode);
00230 }
00231
00233 void DomUtils::makeNode(QDomElement* root, const int nodeData, const QString dictRef)
00235 {
00236 QDomElement childNode = root->ownerDocument().createElement("parameter");
00237 if(!dictRef.isEmpty())
00238 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00239
00240
00241
00242 childNode.setAttribute("value", nodeData);
00243
00244 root->appendChild(childNode);
00245 }
00246
00248 void DomUtils::makeNode(QDomElement* root, const float nodeData, const QString dictRef)
00250 {
00251 QDomElement childNode = root->ownerDocument().createElement("parameter");
00252 if(!dictRef.isEmpty())
00253 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00254
00255
00256
00257 childNode.setAttribute("value", nodeData);
00258
00259 root->appendChild(childNode);
00260 }
00261
00263 void DomUtils::makeNode(QDomElement* root, const bool nodeData, const QString dictRef)
00265 {
00266 QDomElement childNode = root->ownerDocument().createElement("parameter");
00267 if(!dictRef.isEmpty())
00268 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00269
00270
00271 QString text;
00272 if(nodeData)
00273 text = "true";
00274 else
00275 text = "false";
00276
00277 childNode.setAttribute("value", text);
00278
00279 root->appendChild(childNode);
00280 }
00281
00283 void DomUtils::makeNode(QDomElement* root, const std::vector<unsigned int> nodeData, const QString dictRef)
00285 {
00286 if(nodeData.size() == 0)
00287 return;
00288 QDomElement childNode = root->ownerDocument().createElement("parameter");
00289 if(!dictRef.isEmpty())
00290 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00291
00292
00293 QDomElement grandChildNode = root->ownerDocument().createElement("array");
00294 grandChildNode.setAttribute("size",QString::number(nodeData.size()));
00295 QString text;
00296 for(std::vector<unsigned int>::const_iterator it = nodeData.begin(); it < nodeData.end(); it++)
00297 text += " " + QString::number(*it);
00298 text.stripWhiteSpace();
00299 QDomText textNode = root->ownerDocument().createTextNode(text);
00300 grandChildNode.appendChild(textNode);
00301 childNode.appendChild(grandChildNode);
00302 root->appendChild(childNode);
00303 }
00304
00306 void DomUtils::makeNode(QDomElement* root, const std::vector<double> nodeData, const QString dictRef, const QString attributeName, const QString attributeValue)
00308 {
00309 if(nodeData.size() == 0)
00310 return;
00311 QDomElement childNode = root->ownerDocument().createElement("parameter");
00312 if(!dictRef.isEmpty())
00313 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00314
00315
00316 if(!attributeName.isEmpty())
00317 childNode.setAttribute(attributeName, attributeValue);
00318
00319 QDomElement grandChildNode = root->ownerDocument().createElement("array");
00320 grandChildNode.setAttribute("size",QString::number(nodeData.size()));
00321 QString text;
00322 for(std::vector<double>::const_iterator it = nodeData.begin(); it < nodeData.end(); it++)
00323 text += " " + QString::number(*it, 'f', 12);
00324 text.stripWhiteSpace();
00325 QDomText textNode = root->ownerDocument().createTextNode(text);
00326 grandChildNode.appendChild(textNode);
00327 childNode.appendChild(grandChildNode);
00328 root->appendChild(childNode);
00329 }
00330
00332 void DomUtils::makeNode(QDomElement* root, const std::vector<bool> nodeData, const QString dictRef)
00334 {
00335 if(nodeData.size() == 0)
00336 return;
00337 QDomElement childNode = root->ownerDocument().createElement("parameter");
00338 if(!dictRef.isEmpty())
00339 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00340
00341
00342
00343 QDomElement grandChildNode = root->ownerDocument().createElement("array");
00344 grandChildNode.setAttribute("size",QString::number(nodeData.size()));
00345 QString text;
00346 for(std::vector<bool>::const_iterator it = nodeData.begin(); it != nodeData.end(); it++)
00347 text += " " + *it ? "true" : "false";
00348 text.stripWhiteSpace();
00349 QDomText textNode = root->ownerDocument().createTextNode(text);
00350 grandChildNode.appendChild(textNode);
00351 childNode.appendChild(grandChildNode);
00352 root->appendChild(childNode);
00353 }
00354
00356 void DomUtils::makeNode(QDomElement* root, const QValueList<int> nodeData, const QString dictRef)
00358 {
00359 if(nodeData.size() == 0)
00360 return;
00361 QDomElement childNode = root->ownerDocument().createElement("parameter");
00362 if(!dictRef.isEmpty())
00363 childNode.setAttribute("dictRef", ns + ":" + dictRef);
00364
00365
00366 QDomElement grandChildNode = root->ownerDocument().createElement("array");
00367 grandChildNode.setAttribute("size",QString::number(nodeData.size()));
00368 QString text;
00369 for(QValueList<int>::const_iterator it = nodeData.begin(); it != nodeData.end(); it++)
00370 text += " " + QString::number(*it);
00371 text.stripWhiteSpace();
00372 QDomText textNode = root->ownerDocument().createTextNode(text);
00373 grandChildNode.appendChild(textNode);
00374 childNode.appendChild(grandChildNode);
00375 root->appendChild(childNode);
00376 }
00377
00379 bool DomUtils::dictEntry(QDomNode& node, const QString value)
00381 {
00382 return(node.isElement() && node.toElement().attribute("dictRef") == ns + ":" + value);
00383 }
00384
00388
00390 DomUtils::DomUtils()
00392 {
00393 }
00394
00396 DomUtils::~DomUtils()
00398 {
00399 }
00400
00404 const QString DomUtils::uriDict10 = "http://brabosphere.sourceforge.net/dict/1.0";
00405 const QString DomUtils::uriNSCML = "http://www.xml-cml.org/schema";
00406 const QString DomUtils::uriNSDC = "http://www.dublincore.org/dict";
00407 const QString DomUtils::uriDictCMLM = "http://www.xml-cml.org/dict/cmlMeasured";
00408 const QString DomUtils::uriDictXSD = "http://www.w3.org/2001/XMLSchema";
00409 const QString DomUtils::uriDictAtomic = "http://www.xml-cml.org/units/atomic";
00410 const QString DomUtils::uriDictSI = "http://www.xml-cml.org/units/siUnits";
00411
00412 const QString DomUtils::ns = "bs";
00413 const QString DomUtils::nsCMLM = "cmlm";
00414 const QString DomUtils::nsXSD = "xsd";
00415 const QString DomUtils::nsAtomic = "atomic";
00416 const QString DomUtils::nsSI = "siUnits";
00417 const QString DomUtils::nsDC = "dc";
00418