45 #include <xercesc/util/XMLString.hpp>
46 #include <xercesc/sax2/DefaultHandler.hpp>
47 #include <xercesc/sax/Locator.hpp>
48 #include <xercesc/sax2/Attributes.hpp>
57 class ProteinIdentification;
63 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
65 static_assert(
sizeof(::XMLCh) ==
sizeof(char16_t),
66 "XMLCh is not sized correctly for UTF-16.");
80 if (
nullptr == item->getOwnerDocument())
94 : item_(item, doRelease_ )
110 item_.reset(item, doRelease_ );
124 return (
nullptr == item_.get());
128 template <
typename T>
138 if (
nullptr == item->getOwnerDocument())
174 std::swap(item_, other.item_);
218 return (
nullptr == item_);
247 return fromNative_(str.c_str());
259 return toNative_(str.
get());
273 return fromNative_(str).get();
279 return fromNative_(str.c_str()).get();
285 return fromNative_(str.c_str()).get();
291 return fromNative_(str);
297 return fromNative_(str.c_str());
303 return fromNative_(str.c_str());
309 return toNative_(str);
326 public xercesc::DefaultHandler
336 Exception::BaseException(file, line, function)
353 LD_COUNTS_WITHOPTIONS
385 void characters(
const XMLCh *
const chars,
const XMLSize_t length)
override;
387 void startElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname,
const xercesc::Attributes & attrs)
override;
389 void endElement(
const XMLCh *
const uri,
const XMLCh *
const localname,
const XMLCh *
const qname)
override;
452 inline bool equal_(
const XMLCh * a,
const XMLCh * b)
const
454 return xercesc::XMLString::compareString(a, b) == 0;
475 OPENMS_PRECONDITION(section < cv_terms_.size(),
"cvStringToEnum_: Index overflow (section number too large)");
477 std::vector<String>::const_iterator it =
std::find(cv_terms_[section].begin(), cv_terms_[section].end(), term);
478 if (it != cv_terms_[section].end())
480 return it - cv_terms_[section].begin();
484 warning(LOAD,
String(
"Unexpected CV entry '") + message +
"'='" + term +
"'");
485 return result_on_error;
504 error(LOAD,
String(
"Int conversion error of \"") + in +
"\"");
512 return xercesc::XMLString::parseInt(in);
530 error(LOAD,
String(
"UInt conversion error of \"") + in +
"\"");
545 error(LOAD,
String(
"Double conversion error of \"") + in +
"\"");
560 error(LOAD,
String(
"Float conversion error of \"") + in +
"\"");
574 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
578 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
584 error(LOAD,
String(
"Boolean conversion error of \"") + in +
"\"");
593 if (date_string !=
"")
599 date_string = date_string.
substr(0, 19);
600 date_time.
set(date_string);
604 error(LOAD,
String(
"DateTime conversion error of \"") + date_string +
"\"");
618 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
619 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
626 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
627 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
628 return xercesc::XMLString::parseInt(val);
634 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
635 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + name +
"' not present!");
642 String tmp(expectList_(attributeAsString_(a, name)));
643 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
649 String tmp(expectList_(attributeAsString_(a, name)));
650 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
656 String tmp(expectList_(attributeAsString_(a, name)));
657 return ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
667 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
683 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
686 value = xercesc::XMLString::parseInt(val);
699 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
702 value = xercesc::XMLString::parseInt(val);
715 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
731 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
734 value = attributeAsDoubleList_(a, name);
747 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
750 value = attributeAsStringList_(a, name);
763 const XMLCh * val = a.getValue(sm_.
convertPtr(name).get());
766 value = attributeAsIntList_(a, name);
775 const XMLCh * val = a.getValue(name);
776 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
783 const XMLCh * val = a.getValue(name);
784 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
785 return xercesc::XMLString::parseInt(val);
791 const XMLCh * val = a.getValue(name);
792 if (val ==
nullptr) fatalError(LOAD,
String(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
793 return sm_.
convert(val).toDouble();
799 String tmp(expectList_(attributeAsString_(a, name)));
800 return ListUtils::create<double>(tmp.
substr(1, tmp.size() - 2));
806 String tmp(expectList_(attributeAsString_(a, name)));
807 return ListUtils::create<Int>(tmp.
substr(1, tmp.size() - 2));
813 String tmp(expectList_(attributeAsString_(a, name)));
814 return ListUtils::create<String>(tmp.
substr(1, tmp.size() - 2));
820 const XMLCh * val = a.getValue(name);
824 return !value.empty();
832 const XMLCh * val = a.getValue(name);
835 value = xercesc::XMLString::parseInt(val);
844 const XMLCh * val = a.getValue(name);
847 value = xercesc::XMLString::parseInt(val);
856 const XMLCh * val = a.getValue(name);
859 value = sm_.
convert(val).toDouble();
872 const XMLCh * val = a.getValue(name);
875 value = attributeAsDoubleList_(a, name);
888 const XMLCh * val = a.getValue(name);
891 value = attributeAsIntList_(a, name);
904 const XMLCh * val = a.getValue(name);
907 value = attributeAsStringList_(a, name);
923 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:92
Invalid conversion exception.
Definition: Exception.h:356
Parse Error exception.
Definition: Exception.h:630
Definition: XMLHandler.h:234
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:301
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:283
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:289
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:245
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:307
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:251
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:236
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:239
~StringManager()
Destructor.
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:277
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:271
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:257
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:295
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:333
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:335
Base class for XML handlers.
Definition: XMLHandler.h:327
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:804
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:445
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:830
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:745
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:448
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:495
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:818
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:811
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:797
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:697
virtual void setLoadDetail(const LOADDETAIL d)
handler which support partial loading, implement this method
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:572
String file_
File name.
Definition: XMLHandler.h:432
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:886
String version_
Schema version.
Definition: XMLHandler.h:435
LOADDETAIL
Definition: XMLHandler.h:350
@ LD_RAWCOUNTS
Definition: XMLHandler.h:352
@ LD_ALLDATA
Definition: XMLHandler.h:351
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:452
String error_message_
Error message of the last error.
Definition: XMLHandler.h:429
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:516
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:616
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:902
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:654
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:469
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:344
@ LOAD
Loading a file.
Definition: XMLHandler.h:345
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:640
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:854
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:781
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:510
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:624
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:842
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:870
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:647
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:438
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:410
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:632
SignedSize cvStringToEnum_(const Size section, const String &term, const char *message, const SignedSize result_on_error=0)
Definition: XMLHandler.h:473
~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:713
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:729
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:773
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:919
void characters(const XMLCh *const chars, const XMLSize_t length) override
Parsing method for character data.
void checkUniqueIdentifiers_(const std::vector< ProteinIdentification > &prot_ids)
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:590
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:789
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:665
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:761
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:681
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:536
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:551
Definition: XMLHandler.h:74
std::shared_ptr< T > item_
Definition: XMLHandler.h:88
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:93
static void doRelease_(XMLCh *item)
bool is_released() const
Definition: XMLHandler.h:122
static void doRelease_(U *item)
Definition: XMLHandler.h:77
T * get()
Definition: XMLHandler.h:113
const T * get() const
Definition: XMLHandler.h:117
void assign(T *item)
Definition: XMLHandler.h:108
shared_xerces_ptr()=default
void reset()
Definition: XMLHandler.h:103
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:97
Definition: XMLHandler.h:130
T * item_
Definition: XMLHandler.h:145
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:178
void xerces_release()
Definition: XMLHandler.h:184
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:157
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:172
void assign(T *i)
Definition: XMLHandler.h:203
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition: XMLHandler.h:216
T * get() const
Definition: XMLHandler.h:210
unique_xerces_ptr()
Definition: XMLHandler.h:153
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:166
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:161
T * yield()
Definition: XMLHandler.h:195
static void doRelease_(U *&item)
Definition: XMLHandler.h:134
A more convenient string class.
Definition: String.h:61
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 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
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:120
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
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:886
void assign(char &c_target, AAcid const &source)
Definition: AhoCorasickAmbiguous.h:179