19 #include <xercesc/sax2/Attributes.hpp>
20 #include <xercesc/sax2/DefaultHandler.hpp>
21 #include <xercesc/util/XMLString.hpp>
30 class ProteinIdentification;
31 class MetaInfoInterface;
36 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
38 static_assert(
sizeof(::XMLCh) ==
sizeof(char16_t),
39 "XMLCh is not sized correctly for UTF-16.");
53 if (
nullptr == item->getOwnerDocument())
67 : item_(item, doRelease_ )
83 item_.reset(item, doRelease_ );
97 return (
nullptr == item_.get());
101 template <
typename T>
111 if (
nullptr == item->getOwnerDocument())
147 std::swap(item_, other.item_);
191 return (
nullptr == item_);
220 return fromNative_(str.c_str());
232 return toNative_(str.
get());
246 return fromNative_(str).get();
252 return fromNative_(str.c_str()).get();
258 return fromNative_(str.c_str()).get();
264 return fromNative_(str);
270 return fromNative_(str.c_str());
276 return fromNative_(str.c_str());
282 return toNative_(str);
299 public xercesc::DefaultHandler
309 Exception::BaseException(file, line, function)
326 LD_COUNTS_WITHOPTIONS
358 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
360 void startElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const xercesc::Attributes & attrs)
override;
362 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
410 if (type ==
"xsd:double" || type ==
"xsd:float" || type ==
"xsd:decimal")
415 else if (type ==
"xsd:byte" ||
417 type ==
"xsd:unsignedShort" ||
418 type ==
"xsd:short" ||
419 type ==
"xsd:unsignedByte" || type ==
"xsd:unsignedInt")
424 else if (type ==
"xsd:long" || type ==
"xsd:unsignedLong" ||
425 type ==
"xsd:integer" || type ==
"xsd:negativeInteger" ||
426 type ==
"xsd:nonNegativeInteger" || type ==
"xsd:nonPositiveInteger" || type ==
"xsd:positiveInteger")
464 inline bool equal_(
const XMLCh * a,
const XMLCh * b)
const
466 return xercesc::XMLString::compareString(a, b) == 0;
502 error(LOAD,
String(
"Int conversion error of \"") + in +
"\"");
510 return xercesc::XMLString::parseInt(in);
528 error(LOAD,
String(
"UInt conversion error of \"") + in +
"\"");
543 error(LOAD,
String(
"Double conversion error of \"") + in +
"\"");
558 error(LOAD,
String(
"Float conversion error of \"") + in +
"\"");
572 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
576 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
582 error(LOAD,
String(
"Boolean conversion error of \"") + in +
"\"");
591 if (!date_string.empty())
597 date_string = date_string.
substr(0, 19);
598 date_time.
set(date_string);
602 error(LOAD,
String(
"DateTime conversion error of \"") + date_string +
"\"");
616 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
617 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
624 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
625 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
626 return xercesc::XMLString::parseInt(val);
632 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
633 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
640 String tmp(expectList_(attributeAsString_(a, name)));
641 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
647 String tmp(expectList_(attributeAsString_(a, name)));
648 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
654 String tmp(expectList_(attributeAsString_(a, name)));
655 StringList tmp_list = ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
659 for (
String& s : tmp_list)
661 s.substitute(
"\\|",
",");
674 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
690 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
693 value = xercesc::XMLString::parseInt(val);
706 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
709 value = xercesc::XMLString::parseInt(val);
722 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
738 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
741 value = attributeAsDoubleList_(a, name);
754 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
757 value = attributeAsStringList_(a, name);
770 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
773 value = attributeAsIntList_(a, name);
782 const XMLCh * val = a.getValue(name);
783 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
790 const XMLCh * val = a.getValue(name);
791 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
792 return xercesc::XMLString::parseInt(val);
798 const XMLCh * val = a.getValue(name);
799 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
800 return sm_.
convert(val).toDouble();
806 String tmp(expectList_(attributeAsString_(a, name)));
807 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
813 String tmp(expectList_(attributeAsString_(a, name)));
814 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
820 String tmp(expectList_(attributeAsString_(a, name)));
821 StringList tmp_list = ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
825 for (
String& s : tmp_list)
827 s.substitute(
"\\|",
",");
836 const XMLCh * val = a.getValue(name);
840 return !value.empty();
848 const XMLCh * val = a.getValue(name);
851 value = xercesc::XMLString::parseInt(val);
860 const XMLCh * val = a.getValue(name);
863 value = xercesc::XMLString::parseInt(val);
872 const XMLCh * val = a.getValue(name);
875 value = sm_.
convert(val).toDouble();
888 const XMLCh * val = a.getValue(name);
891 value = attributeAsDoubleList_(a, name);
904 const XMLCh * val = a.getValue(name);
907 value = attributeAsIntList_(a, name);
920 const XMLCh * val = a.getValue(name);
923 value = attributeAsStringList_(a, name);
939 fatalError(LOAD,
String(
"List argument is not a string representation of a list!"));
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:33
DateTime Class.
Definition: DateTime.h:33
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:65
Invalid conversion exception.
Definition: Exception.h:330
Parse Error exception.
Definition: Exception.h:598
Definition: XMLHandler.h:207
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:274
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:256
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:262
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:218
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:280
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:224
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:209
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:212
~StringManager()
Destructor.
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:250
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:244
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:230
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:268
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:306
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:308
Base class for XML handlers.
Definition: XMLHandler.h:300
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:811
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:457
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:846
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:752
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:460
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:493
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:834
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:818
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:804
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:704
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:570
String file_
File name.
Definition: XMLHandler.h:444
static DataValue fromXSDString(const String &type, const String &value)
Convert an XSD type (e.g. 'xsd:double') to a DataValue.
Definition: XMLHandler.h:406
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:902
String version_
Schema version.
Definition: XMLHandler.h:447
LOADDETAIL
Definition: XMLHandler.h:323
@ LD_RAWCOUNTS
Definition: XMLHandler.h:325
@ LD_ALLDATA
Definition: XMLHandler.h:324
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:464
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:514
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:614
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:918
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:652
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:481
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:317
@ LOAD
Loading a file.
Definition: XMLHandler.h:318
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:638
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:870
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:788
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:508
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:622
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:858
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:886
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:645
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:450
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:380
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:630
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:720
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:736
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:780
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:935
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:588
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:796
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:672
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:768
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:688
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:534
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:549
Definition: XMLHandler.h:47
std::shared_ptr< T > item_
Definition: XMLHandler.h:61
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:66
static void doRelease_(XMLCh *item)
bool is_released() const
Definition: XMLHandler.h:95
static void doRelease_(U *item)
Definition: XMLHandler.h:50
T * get()
Definition: XMLHandler.h:86
const T * get() const
Definition: XMLHandler.h:90
void assign(T *item)
Definition: XMLHandler.h:81
shared_xerces_ptr()=default
void reset()
Definition: XMLHandler.h:76
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:70
Definition: XMLHandler.h:103
T * item_
Definition: XMLHandler.h:118
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:151
void xerces_release()
Definition: XMLHandler.h:157
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:130
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:145
void assign(T *i)
Definition: XMLHandler.h:176
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition: XMLHandler.h:189
T * get() const
Definition: XMLHandler.h:183
unique_xerces_ptr()
Definition: XMLHandler.h:126
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:139
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:134
T * yield()
Definition: XMLHandler.h:168
static void doRelease_(U *&item)
Definition: XMLHandler.h:107
A more convenient string class.
Definition: String.h:34
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
Int64 toInt64() const
Conversion to Int64.
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.
Int32 toInt32() const
Conversion to Int32.
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:76
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:29
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22