45 #include <xercesc/util/XMLString.hpp> 46 #include <xercesc/sax2/DefaultHandler.hpp> 47 #include <xercesc/sax/Locator.hpp> 48 #include <xercesc/sax2/Attributes.hpp> 76 XMLCh* ptr(xercesc::XMLString::transcode(str));
78 xercesc::XMLString::release(&ptr);
85 return fromNative_(str.c_str());
91 char* ptr(xercesc::XMLString::transcode(str));
93 xercesc::XMLString::release(&ptr);
100 return toNative_(str.c_str());
114 return fromNative_(str);
120 return fromNative_(str.c_str());
126 return fromNative_(str.c_str());
132 return toNative_(str);
141 static void appendASCII(
const XMLCh * str,
const XMLSize_t length,
String & result);
149 public xercesc::DefaultHandler
159 Exception::BaseException(file, line, function)
176 LD_COUNTS_WITHOPTIONS
195 void fatalError(
const xercesc::SAXParseException &
exception)
override;
196 void error(
const xercesc::SAXParseException &
exception)
override;
197 void warning(
const xercesc::SAXParseException &
exception)
override;
201 void fatalError(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
203 void error(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
205 void warning(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
208 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
210 void startElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const xercesc::Attributes & attrs)
override;
212 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
215 virtual void writeTo(std::ostream & );
221 virtual LOADDETAIL getLoadDetail()
const;
224 virtual void setLoadDetail(
const LOADDETAIL d);
271 inline bool equal_(
const XMLCh * a,
const XMLCh * b)
const 273 return xercesc::XMLString::compareString(a, b) == 0;
294 OPENMS_PRECONDITION(section < cv_terms_.size(),
"cvStringToEnum_: Index overflow (section number too large)");
296 std::vector<String>::const_iterator it =
std::find(cv_terms_[section].begin(), cv_terms_[section].end(), term);
297 if (it != cv_terms_[section].end())
299 return it - cv_terms_[section].begin();
303 warning(LOAD,
String(
"Unexpected CV entry '") + message +
"'='" + term +
"'");
304 return result_on_error;
323 error(LOAD,
String(
"Int conversion error of \"") + in +
"\"");
331 return xercesc::XMLString::parseInt(in);
349 error(LOAD,
String(
"UInt conversion error of \"") + in +
"\"");
364 error(LOAD,
String(
"Double conversion error of \"") + in +
"\"");
379 error(LOAD,
String(
"Float conversion error of \"") + in +
"\"");
393 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
397 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
403 error(LOAD,
String(
"Boolean conversion error of \"") + in +
"\"");
412 if (date_string !=
"")
418 date_string = date_string.
substr(0, 19);
419 date_time.
set(date_string);
423 error(LOAD,
String(
"DateTime conversion error of \"") + date_string +
"\"");
437 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
438 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
445 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
446 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
447 return xercesc::XMLString::parseInt(val);
453 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
454 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
461 String tmp(expectList_(attributeAsString_(a, name)));
462 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
468 String tmp(expectList_(attributeAsString_(a, name)));
469 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
475 String tmp(expectList_(attributeAsString_(a, name)));
476 return ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
486 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
502 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
505 value = xercesc::XMLString::parseInt(val);
518 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
521 value = xercesc::XMLString::parseInt(val);
534 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
550 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
553 value = attributeAsDoubleList_(a, name);
566 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
569 value = attributeAsStringList_(a, name);
582 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
585 value = attributeAsIntList_(a, name);
594 const XMLCh * val = a.getValue(name);
595 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
602 const XMLCh * val = a.getValue(name);
603 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
604 return xercesc::XMLString::parseInt(val);
610 const XMLCh * val = a.getValue(name);
611 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
618 String tmp(expectList_(attributeAsString_(a, name)));
619 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
625 String tmp(expectList_(attributeAsString_(a, name)));
626 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
632 String tmp(expectList_(attributeAsString_(a, name)));
633 return ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
639 const XMLCh * val = a.getValue(name);
655 const XMLCh * val = a.getValue(name);
658 value = xercesc::XMLString::parseInt(val);
667 const XMLCh * val = a.getValue(name);
670 value = xercesc::XMLString::parseInt(val);
679 const XMLCh * val = a.getValue(name);
695 const XMLCh * val = a.getValue(name);
698 value = attributeAsDoubleList_(a, name);
711 const XMLCh * val = a.getValue(name);
714 value = attributeAsIntList_(a, name);
727 const XMLCh * val = a.getValue(name);
730 value = attributeAsStringList_(a, name);
747 fatalError(LOAD,
String(
"List argument is not a string representation of a list!"));
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:271
bool optionalAttributeAsDoubleList_(DoubleList &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the DoubleList value if the attribute is present.
Definition: XMLHandler.h:693
std::vector< String > open_tags_
Stack of open XML tags.
Definition: XMLHandler.h:264
bool optionalAttributeAsInt_(Int &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the Int value if the attribute is present.
Definition: XMLHandler.h:500
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:466
bool has(Byte byte) const
true if String contains the byte, false otherwise
A more convenient string class.
Definition: String.h:57
Exception that is thrown if the parsing is ended by some event (e.g. if only a prefix of the XML file...
Definition: XMLHandler.h:154
Int asInt_(const XMLCh *in)
Conversion of a Xerces string to an integer value.
Definition: XMLHandler.h:329
String version_
Schema version.
Definition: XMLHandler.h:254
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:65
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:473
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers
SignedSize cvStringToEnum_(const Size section, const String &term, const char *message, const SignedSize result_on_error=0)
Definition: XMLHandler.h:292
bool optionalAttributeAsIntList_(IntList &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the IntList value if the attribute is present.
Definition: XMLHandler.h:709
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:106
String expectList_(const String &str) const
Definition: XMLHandler.h:742
XercesString fromNative_(const String &str) const
Definition: XMLHandler.h:83
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
bool optionalAttributeAsDouble_(double &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the double value if the attribute is present.
Definition: XMLHandler.h:532
String toNative_(const XMLCh *str) const
Definition: XMLHandler.h:89
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:58
Base class for XML handlers.
Definition: XMLHandler.h:148
DateTime asDateTime_(String date_string)
Conversion of a xs:datetime string to a DateTime value.
Definition: XMLHandler.h:409
UInt asUInt_(const String &in)
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:335
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:166
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:451
Definition: XMLHandler.h:68
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:600
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes ...
Definition: XMLHandler.h:267
bool optionalAttributeAsDoubleList_(DoubleList &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the DoubleList value if the attribute is present.
Definition: XMLHandler.h:548
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:443
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
static String writeXMLEscape(const String &to_escape)
Escapes a string and returns the escaped string.
Definition: XMLHandler.h:233
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
bool optionalAttributeAsIntList_(IntList &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the IntList value if the attribute is present.
Definition: XMLHandler.h:580
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
bool optionalAttributeAsDouble_(double &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the double value if the attribute is present.
Definition: XMLHandler.h:677
String error_message_
Error message of the last error.
Definition: XMLHandler.h:248
bool optionalAttributeAsString_(String &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the String value if the attribute is present.
Definition: XMLHandler.h:637
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:158
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:616
Int toInt() const
Conversion to int.
String convert(const XMLCh *str) const
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:130
double toDouble() const
Conversion to double.
int exception
(Used by various macros. Indicates a rough category of the exception being caught.)
float asFloat_(const String &in)
Conversion of a String to a float value.
Definition: XMLHandler.h:370
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:623
XercesString fromNative_(const char *str) const
Definition: XMLHandler.h:74
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
bool optionalAttributeAsStringList_(StringList &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the StringList value if the attribute is present.
Definition: XMLHandler.h:725
bool asBool_(const String &in)
Conversion of a string to a boolean value.
Definition: XMLHandler.h:391
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:435
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:592
float toFloat() const
Conversion to float.
String file_
File name.
Definition: XMLHandler.h:251
XercesString convert(const std::string &str) const
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:118
Exception base class.
Definition: Exception.h:89
Invalid conversion exception.
Definition: Exception.h:362
Loading a file.
Definition: XMLHandler.h:168
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
double asDouble_(const String &in)
Conversion of a String to a double value.
Definition: XMLHandler.h:355
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:257
Definition: XMLHandler.h:174
bool optionalAttributeAsUInt_(UInt &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the UInt value if the attribute is present.
Definition: XMLHandler.h:665
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:71
Int asInt_(const String &in)
Conversion of a String to an integer value.
Definition: XMLHandler.h:314
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
DateTime Class.
Definition: DateTime.h:54
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
Definition: XMLHandler.h:175
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:630
XercesString convert(const String &str) const
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:124
std::vector< std::vector< String > > cv_terms_
Array of CV term lists (one sublist denotes one term and it's children)
Definition: XMLHandler.h:288
bool optionalAttributeAsUInt_(UInt &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the UInt value if the attribute is present.
Definition: XMLHandler.h:516
LOADDETAIL
Definition: XMLHandler.h:172
int Int
Signed integer type.
Definition: Types.h:102
bool optionalAttributeAsInt_(Int &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the Int value if the attribute is present.
Definition: XMLHandler.h:653
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:608
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:459
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
bool optionalAttributeAsStringList_(StringList &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the StringList value if the attribute is present.
Definition: XMLHandler.h:564
Parse Error exception.
Definition: Exception.h:622
bool optionalAttributeAsString_(String &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the String value if the attribute is present.
Definition: XMLHandler.h:484
String toNative_(const XercesString &str) const
Definition: XMLHandler.h:98
XercesString convert(const char *str) const
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:112