44 #include <xercesc/util/XMLString.hpp>
45 #include <xercesc/sax2/DefaultHandler.hpp>
46 #include <xercesc/sax2/Attributes.hpp>
55 class ProteinIdentification;
56 class MetaInfoInterface;
61 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
63 static_assert(
sizeof(::XMLCh) ==
sizeof(char16_t),
64 "XMLCh is not sized correctly for UTF-16.");
78 if (
nullptr == item->getOwnerDocument())
92 : item_(item, doRelease_ )
108 item_.reset(item, doRelease_ );
122 return (
nullptr == item_.get());
126 template <
typename T>
136 if (
nullptr == item->getOwnerDocument())
172 std::swap(item_, other.item_);
216 return (
nullptr == item_);
245 return fromNative_(str.c_str());
257 return toNative_(str.
get());
271 return fromNative_(str).get();
277 return fromNative_(str.c_str()).get();
283 return fromNative_(str.c_str()).get();
289 return fromNative_(str);
295 return fromNative_(str.c_str());
301 return fromNative_(str.c_str());
307 return toNative_(str);
324 public xercesc::DefaultHandler
334 Exception::BaseException(file, line, function)
351 LD_COUNTS_WITHOPTIONS
383 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
385 void startElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const xercesc::Attributes & attrs)
override;
387 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
450 inline bool equal_(
const XMLCh * a,
const XMLCh * b)
const
452 return xercesc::XMLString::compareString(a, b) == 0;
488 error(LOAD,
String(
"Int conversion error of \"") + in +
"\"");
496 return xercesc::XMLString::parseInt(in);
514 error(LOAD,
String(
"UInt conversion error of \"") + in +
"\"");
529 error(LOAD,
String(
"Double conversion error of \"") + in +
"\"");
544 error(LOAD,
String(
"Float conversion error of \"") + in +
"\"");
558 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
562 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
568 error(LOAD,
String(
"Boolean conversion error of \"") + in +
"\"");
577 if (!date_string.empty())
583 date_string = date_string.
substr(0, 19);
584 date_time.
set(date_string);
588 error(LOAD,
String(
"DateTime conversion error of \"") + date_string +
"\"");
602 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
603 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
610 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
611 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
612 return xercesc::XMLString::parseInt(val);
618 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
619 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
626 String tmp(expectList_(attributeAsString_(a, name)));
627 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
633 String tmp(expectList_(attributeAsString_(a, name)));
634 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
640 String tmp(expectList_(attributeAsString_(a, name)));
641 StringList tmp_list = ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
645 for (
String& s : tmp_list)
647 s.substitute(
"\\|",
",");
660 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
676 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
679 value = xercesc::XMLString::parseInt(val);
692 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
695 value = xercesc::XMLString::parseInt(val);
708 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
724 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
727 value = attributeAsDoubleList_(a, name);
740 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
743 value = attributeAsStringList_(a, name);
756 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
759 value = attributeAsIntList_(a, name);
768 const XMLCh * val = a.getValue(name);
769 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
776 const XMLCh * val = a.getValue(name);
777 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
778 return xercesc::XMLString::parseInt(val);
784 const XMLCh * val = a.getValue(name);
785 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
786 return sm_.
convert(val).toDouble();
792 String tmp(expectList_(attributeAsString_(a, name)));
793 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
799 String tmp(expectList_(attributeAsString_(a, name)));
800 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
806 String tmp(expectList_(attributeAsString_(a, name)));
807 StringList tmp_list = ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
811 for (
String& s : tmp_list)
813 s.substitute(
"\\|",
",");
822 const XMLCh * val = a.getValue(name);
826 return !value.empty();
834 const XMLCh * val = a.getValue(name);
837 value = xercesc::XMLString::parseInt(val);
846 const XMLCh * val = a.getValue(name);
849 value = xercesc::XMLString::parseInt(val);
858 const XMLCh * val = a.getValue(name);
861 value = sm_.
convert(val).toDouble();
874 const XMLCh * val = a.getValue(name);
877 value = attributeAsDoubleList_(a, name);
890 const XMLCh * val = a.getValue(name);
893 value = attributeAsIntList_(a, name);
906 const XMLCh * val = a.getValue(name);
909 value = attributeAsStringList_(a, name);
925 fatalError(LOAD,
String(
"List argument is not a string representation of a list!"));
DateTime Class.
Definition: DateTime.h:55
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers
Exception base class.
Definition: Exception.h:91
Invalid conversion exception.
Definition: Exception.h:356
Parse Error exception.
Definition: Exception.h:624
Definition: XMLHandler.h:232
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:299
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:281
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:287
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:243
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:305
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:249
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:234
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:237
~StringManager()
Destructor.
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:275
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:269
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:255
StringManager()
Constructor.
static void appendASCII(const XMLCh *str, const XMLSize_t length, String &result)
Transcodes the supplied XMLCh* and appends it to the OpenMS String.
static unique_xerces_ptr< XMLCh > convertPtr(const std::string &str)
Transcode the supplied C++ string to a xerces string pointer.
Definition: XMLHandler.h:293
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:331
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:333
Base class for XML handlers.
Definition: XMLHandler.h:325
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:797
String errorString()
Returns the last error description.
virtual LOADDETAIL getLoadDetail() const
handler which support partial loading, implement this method
std::vector< String > open_tags_
Stack of open XML tags.
Definition: XMLHandler.h:443
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const xercesc::Attributes &attrs) override
Parsing method for opening tags.
void warning(const xercesc::SAXParseException &exception) override
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:832
XMLHandler(const String &filename, const String &version)
Default constructor.
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:738
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:446
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:479
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:820
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:804
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:790
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:690
virtual void setLoadDetail(const LOADDETAIL d)
handler which support partial loading, implement this method
void checkUniqueIdentifiers_(const std::vector< ProteinIdentification > &prot_ids) const
XMLHandler()
Not implemented.
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
Parsing method for closing tags.
bool asBool_(const String &in) const
Conversion of a string to a boolean value.
Definition: XMLHandler.h:556
String file_
File name.
Definition: XMLHandler.h:430
void fatalError(ActionMode mode, const String &msg, UInt line=0, UInt column=0) const
Fatal error handler. Throws a ParseError exception.
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:888
String version_
Schema version.
Definition: XMLHandler.h:433
LOADDETAIL
Definition: XMLHandler.h:348
@ LD_RAWCOUNTS
Definition: XMLHandler.h:350
@ LD_ALLDATA
Definition: XMLHandler.h:349
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:450
String error_message_
Error message of the last error.
Definition: XMLHandler.h:427
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:500
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:600
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:904
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:638
void warning(ActionMode mode, const String &msg, UInt line=0, UInt column=0) const
Warning handler.
std::vector< std::vector< String > > cv_terms_
Array of CV term lists (one sublist denotes one term and it's children)
Definition: XMLHandler.h:467
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:342
@ LOAD
Loading a file.
Definition: XMLHandler.h:343
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:624
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:856
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:774
void writeUserParam_(const String &tag_name, std::ostream &os, const MetaInfoInterface &meta, UInt indent) const
Writes the content of MetaInfoInterface to the file.
Int asInt_(const XMLCh *in) const
Conversion of a Xerces string to an integer value.
Definition: XMLHandler.h:494
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:608
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:844
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:872
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:631
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:436
void fatalError(const xercesc::SAXParseException &exception) override
static String writeXMLEscape(const String &to_escape)
Escapes a string and returns the escaped string.
Definition: XMLHandler.h:408
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:616
SignedSize cvStringToEnum_(const Size section, const String &term, const char *message, const SignedSize result_on_error=0)
~XMLHandler() override
Destructor.
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:706
virtual void writeTo(std::ostream &)
Writes the contents to a stream.
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:722
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:766
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:921
void characters(const XMLCh *const chars, const XMLSize_t length) override
Parsing method for character data.
void error(ActionMode mode, const String &msg, UInt line=0, UInt column=0) const
Error handler for recoverable errors.
DateTime asDateTime_(String date_string) const
Conversion of a xs:datetime string to a DateTime value.
Definition: XMLHandler.h:574
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:782
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:658
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:754
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:674
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:520
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:535
Definition: XMLHandler.h:72
std::shared_ptr< T > item_
Definition: XMLHandler.h:86
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:91
static void doRelease_(XMLCh *item)
bool is_released() const
Definition: XMLHandler.h:120
static void doRelease_(U *item)
Definition: XMLHandler.h:75
T * get()
Definition: XMLHandler.h:111
const T * get() const
Definition: XMLHandler.h:115
void assign(T *item)
Definition: XMLHandler.h:106
shared_xerces_ptr()=default
void reset()
Definition: XMLHandler.h:101
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:95
Definition: XMLHandler.h:128
T * item_
Definition: XMLHandler.h:143
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:176
void xerces_release()
Definition: XMLHandler.h:182
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:155
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:170
void assign(T *i)
Definition: XMLHandler.h:201
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition: XMLHandler.h:214
T * get() const
Definition: XMLHandler.h:208
unique_xerces_ptr()
Definition: XMLHandler.h:151
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:164
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:159
T * yield()
Definition: XMLHandler.h:193
static void doRelease_(U *&item)
Definition: XMLHandler.h:132
A more convenient string class.
Definition: String.h:60
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 hasPrefix(const String &string) const
true if String begins with string, false otherwise
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
bool has(Byte byte) const
true if String contains the byte, false otherwise
Int toInt() const
Conversion to int.
double toDouble() const
Conversion to double.
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
float toFloat() const
Conversion to float.
int Int
Signed integer type.
Definition: Types.h:102
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47