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)
187 void fatalError(
const xercesc::SAXParseException &
exception)
override;
188 void error(
const xercesc::SAXParseException &
exception)
override;
189 void warning(
const xercesc::SAXParseException &
exception)
override;
193 void fatalError(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
195 void error(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
197 void warning(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
200 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
202 void startElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const xercesc::Attributes & attrs)
override;
204 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
207 virtual void writeTo(std::ostream & );
253 inline bool equal_(
const XMLCh * a,
const XMLCh * b)
const 255 return xercesc::XMLString::compareString(a, b) == 0;
276 OPENMS_PRECONDITION(section < cv_terms_.size(),
"cvStringToEnum_: Index overflow (section number too large)");
278 std::vector<String>::const_iterator it =
std::find(cv_terms_[section].begin(), cv_terms_[section].end(), term);
279 if (it != cv_terms_[section].end())
281 return it - cv_terms_[section].begin();
285 warning(LOAD,
String(
"Unexpected CV entry '") + message +
"'='" + term +
"'");
286 return result_on_error;
305 error(LOAD,
String(
"Int conversion error of \"") + in +
"\"");
313 return xercesc::XMLString::parseInt(in);
331 error(LOAD,
String(
"UInt conversion error of \"") + in +
"\"");
346 error(LOAD,
String(
"Double conversion error of \"") + in +
"\"");
361 error(LOAD,
String(
"Float conversion error of \"") + in +
"\"");
375 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
379 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
385 error(LOAD,
String(
"Boolean conversion error of \"") + in +
"\"");
394 if (date_string !=
"")
400 date_string = date_string.
substr(0, 19);
401 date_time.
set(date_string);
405 error(LOAD,
String(
"DateTime conversion error of \"") + date_string +
"\"");
419 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
420 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
427 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
428 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
429 return xercesc::XMLString::parseInt(val);
435 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
436 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
443 String tmp(expectList_(attributeAsString_(a, name)));
444 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
450 String tmp(expectList_(attributeAsString_(a, name)));
451 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
457 String tmp(expectList_(attributeAsString_(a, name)));
458 return ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
468 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
484 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
487 value = xercesc::XMLString::parseInt(val);
500 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
503 value = xercesc::XMLString::parseInt(val);
516 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
532 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
535 value = attributeAsDoubleList_(a, name);
548 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
551 value = attributeAsStringList_(a, name);
564 const XMLCh * val = a.getValue(sm_.
convert(name).c_str());
567 value = attributeAsIntList_(a, name);
576 const XMLCh * val = a.getValue(name);
577 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
584 const XMLCh * val = a.getValue(name);
585 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
586 return xercesc::XMLString::parseInt(val);
592 const XMLCh * val = a.getValue(name);
593 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
600 String tmp(expectList_(attributeAsString_(a, name)));
601 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
607 String tmp(expectList_(attributeAsString_(a, name)));
608 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
614 String tmp(expectList_(attributeAsString_(a, name)));
615 return ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
621 const XMLCh * val = a.getValue(name);
637 const XMLCh * val = a.getValue(name);
640 value = xercesc::XMLString::parseInt(val);
649 const XMLCh * val = a.getValue(name);
652 value = xercesc::XMLString::parseInt(val);
661 const XMLCh * val = a.getValue(name);
677 const XMLCh * val = a.getValue(name);
680 value = attributeAsDoubleList_(a, name);
693 const XMLCh * val = a.getValue(name);
696 value = attributeAsIntList_(a, name);
709 const XMLCh * val = a.getValue(name);
712 value = attributeAsStringList_(a, name);
729 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:253
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:675
std::vector< String > open_tags_
Stack of open XML tags.
Definition: XMLHandler.h:250
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:482
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:448
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:311
String version_
Schema version.
Definition: XMLHandler.h:240
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:455
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:274
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:691
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:106
String expectList_(const String &str) const
Definition: XMLHandler.h:724
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:514
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:391
UInt asUInt_(const String &in)
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:317
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:433
Definition: XMLHandler.h:68
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:582
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:530
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:425
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:219
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:562
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:659
String error_message_
Error message of the last error.
Definition: XMLHandler.h:234
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:619
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:598
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:352
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:605
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:707
bool asBool_(const String &in)
Conversion of a string to a boolean value.
Definition: XMLHandler.h:373
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:417
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:574
float toFloat() const
Conversion to float.
String file_
File name.
Definition: XMLHandler.h:237
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:337
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:243
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:647
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:296
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.
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:612
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:270
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:498
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:635
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:590
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:441
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:546
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:466
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