45 #include <xercesc/util/XMLString.hpp> 46 #include <xercesc/sax2/DefaultHandler.hpp> 47 #include <xercesc/sax2/Attributes.hpp> 56 class ProteinIdentification;
57 class MetaInfoInterface;
62 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s) 64 static_assert(
sizeof(::XMLCh) ==
sizeof(char16_t),
65 "XMLCh is not sized correctly for UTF-16.");
79 if (
nullptr == item->getOwnerDocument())
83 static void doRelease_(
char* item);
84 static void doRelease_(XMLCh* item);
93 : item_(item, doRelease_ )
109 item_.reset(item, doRelease_ );
123 return (
nullptr == item_.get());
127 template <
typename T>
137 if (
nullptr == item->getOwnerDocument())
141 static void doRelease_(
char*& item);
142 static void doRelease_(XMLCh*& item);
173 std::swap(item_, other.item_);
217 return (
nullptr == item_);
246 return fromNative_(str.c_str());
258 return toNative_(str.
get());
272 return fromNative_(str).get();
278 return fromNative_(str.c_str()).
get();
284 return fromNative_(str.c_str()).
get();
290 return fromNative_(str);
296 return fromNative_(str.c_str());
302 return fromNative_(str.c_str());
308 return toNative_(str);
317 static void appendASCII(
const XMLCh * str,
const XMLSize_t length,
String & result);
325 public xercesc::DefaultHandler
335 Exception::BaseException(file, line, function)
352 LD_COUNTS_WITHOPTIONS
371 void fatalError(
const xercesc::SAXParseException &
exception)
override;
372 void error(
const xercesc::SAXParseException &
exception)
override;
373 void warning(
const xercesc::SAXParseException &
exception)
override;
377 void fatalError(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
379 void error(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
381 void warning(ActionMode mode,
const String & msg,
UInt line = 0,
UInt column = 0)
const;
384 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
386 void startElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const xercesc::Attributes & attrs)
override;
388 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
391 virtual void writeTo(std::ostream & );
397 virtual LOADDETAIL getLoadDetail()
const;
400 virtual void setLoadDetail(
const LOADDETAIL d);
439 if (type ==
"xsd:double" || type ==
"xsd:float" || type ==
"xsd:decimal")
444 else if (type ==
"xsd:byte" ||
446 type ==
"xsd:unsignedShort" ||
447 type ==
"xsd:short" ||
448 type ==
"xsd:unsignedByte" || type ==
"xsd:unsignedInt")
453 else if (type ==
"xsd:long" || type ==
"xsd:unsignedLong" ||
454 type ==
"xsd:integer" || type ==
"xsd:negativeInteger" ||
455 type ==
"xsd:nonNegativeInteger" || type ==
"xsd:nonPositiveInteger" || type ==
"xsd:positiveInteger")
469 void checkUniqueIdentifiers_(
const std::vector<ProteinIdentification>& prot_ids)
const;
496 inline bool equal_(
const XMLCh * a,
const XMLCh * b)
const 498 return xercesc::XMLString::compareString(a, b) == 0;
534 error(LOAD,
String(
"Int conversion error of \"") + in +
"\"");
542 return xercesc::XMLString::parseInt(in);
560 error(LOAD,
String(
"UInt conversion error of \"") + in +
"\"");
575 error(LOAD,
String(
"Double conversion error of \"") + in +
"\"");
590 error(LOAD,
String(
"Float conversion error of \"") + in +
"\"");
604 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
608 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
614 error(LOAD,
String(
"Boolean conversion error of \"") + in +
"\"");
623 if (!date_string.empty())
629 date_string = date_string.
substr(0, 19);
630 date_time.
set(date_string);
634 error(LOAD,
String(
"DateTime conversion error of \"") + date_string +
"\"");
648 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
649 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
656 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
657 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
658 return xercesc::XMLString::parseInt(val);
664 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
665 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
672 String tmp(expectList_(attributeAsString_(a, name)));
673 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
679 String tmp(expectList_(attributeAsString_(a, name)));
680 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
686 String tmp(expectList_(attributeAsString_(a, name)));
687 StringList tmp_list = ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
691 for (
String& s : tmp_list)
693 s.substitute(
"\\|",
",");
706 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
722 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
725 value = xercesc::XMLString::parseInt(val);
738 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
741 value = xercesc::XMLString::parseInt(val);
754 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
770 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
773 value = attributeAsDoubleList_(a, name);
786 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
789 value = attributeAsStringList_(a, name);
802 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
805 value = attributeAsIntList_(a, name);
814 const XMLCh * val = a.getValue(name);
815 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
822 const XMLCh * val = a.getValue(name);
823 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
824 return xercesc::XMLString::parseInt(val);
830 const XMLCh * val = a.getValue(name);
831 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
832 return sm_.
convert(val).toDouble();
838 String tmp(expectList_(attributeAsString_(a, name)));
839 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
845 String tmp(expectList_(attributeAsString_(a, name)));
846 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
852 String tmp(expectList_(attributeAsString_(a, name)));
853 StringList tmp_list = ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
857 for (
String& s : tmp_list)
859 s.substitute(
"\\|",
",");
868 const XMLCh * val = a.getValue(name);
872 return !value.empty();
880 const XMLCh * val = a.getValue(name);
883 value = xercesc::XMLString::parseInt(val);
892 const XMLCh * val = a.getValue(name);
895 value = xercesc::XMLString::parseInt(val);
904 const XMLCh * val = a.getValue(name);
907 value = sm_.
convert(val).toDouble();
920 const XMLCh * val = a.getValue(name);
923 value = attributeAsDoubleList_(a, name);
936 const XMLCh * val = a.getValue(name);
939 value = attributeAsIntList_(a, name);
952 const XMLCh * val = a.getValue(name);
955 value = attributeAsStringList_(a, name);
971 fatalError(LOAD,
String(
"List argument is not a string representation of a list!"));
void assign(T *i)
Definition: XMLHandler.h:202
void reset()
Definition: XMLHandler.h:102
bool is_released() const
Definition: XMLHandler.h:215
T * item_
Definition: XMLHandler.h:144
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:496
T * get() const
Definition: XMLHandler.h:209
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:918
std::vector< String > open_tags_
Stack of open XML tags.
Definition: XMLHandler.h:489
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:171
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:720
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:677
bool has(Byte byte) const
true if String contains the byte, false otherwise
A more convenient string class.
Definition: String.h:58
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:330
String version_
Schema version.
Definition: XMLHandler.h:479
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:684
DateTime asDateTime_(String date_string) const
Conversion of a xs:datetime string to a DateTime value.
Definition: XMLHandler.h:620
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers
static void doRelease_(U *item)
Definition: XMLHandler.h:76
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:934
void assign(T *item)
Definition: XMLHandler.h:107
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:165
static void doRelease_(U *&item)
Definition: XMLHandler.h:133
T * yield()
Definition: XMLHandler.h:194
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:282
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:96
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:752
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:256
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
Base class for XML handlers.
Definition: XMLHandler.h:324
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:342
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:662
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:250
Definition: XMLHandler.h:232
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:820
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:276
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes ...
Definition: XMLHandler.h:492
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:768
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:654
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
static String writeXMLEscape(const String &to_escape)
Escapes a string and returns the escaped string.
Definition: XMLHandler.h:409
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:800
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
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...
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:525
Int asInt_(const XMLCh *in) const
Conversion of a Xerces string to an integer value.
Definition: XMLHandler.h:540
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:902
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:238
String error_message_
Error message of the last error.
Definition: XMLHandler.h:473
~unique_xerces_ptr()
Definition: XMLHandler.h:160
void operator=(T *i)
Definition: XMLHandler.h:177
bool asBool_(const String &in) const
Conversion of a string to a boolean value.
Definition: XMLHandler.h:602
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:581
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:866
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:334
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:836
Int toInt() const
Conversion to Int.
Definition: XMLHandler.h:72
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:300
double toDouble() const
Conversion to double.
int exception
(Used by various macros. Indicates a rough category of the exception being caught.)
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:306
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:843
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:950
unique_xerces_ptr()
Definition: XMLHandler.h:152
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:646
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:812
float toFloat() const
Conversion to float.
String file_
File name.
Definition: XMLHandler.h:476
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:288
const String & expectList_(const String &str) const
Definition: XMLHandler.h:967
Exception base class.
Definition: Exception.h:89
Invalid conversion exception.
Definition: Exception.h:354
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:546
Loading a file.
Definition: XMLHandler.h:344
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
Int32 toInt32() const
Conversion to Int32.
std::shared_ptr< T > item_
Definition: XMLHandler.h:87
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:566
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:482
Definition: XMLHandler.h:350
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:890
static unique_xerces_ptr< XMLCh > convertPtr(const std::string &str)
Transcode the supplied C++ string to a xerces string pointer.
Definition: XMLHandler.h:294
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:156
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:235
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
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:92
DateTime Class.
Definition: DateTime.h:58
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
Definition: XMLHandler.h:351
Definition: XMLHandler.h:128
Int64 toInt64() const
Conversion to Int64.
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:244
static DataValue fromXSDString(const String &type, const String &value)
Convert an XSD type (e.g. 'xsd:double') to a DataValue.
Definition: XMLHandler.h:435
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:270
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:850
static double toDouble(const String &this_s)
Definition: StringUtils.h:254
void xerces_release()
Definition: XMLHandler.h:183
std::vector< std::vector< String > > cv_terms_
Array of CV term lists (one sublist denotes one term and it's children)
Definition: XMLHandler.h:513
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:736
LOADDETAIL
Definition: XMLHandler.h:348
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:878
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:828
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:670
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:784
bool is_released() const
Definition: XMLHandler.h:121
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:704