35 #ifndef OPENMS_FORMAT_HANDLERS_XMLHANDLER_H 
   36 #define OPENMS_FORMAT_HANDLERS_XMLHANDLER_H 
   46 #include <xercesc/sax2/DefaultHandler.hpp> 
   47 #include <xercesc/sax/Locator.hpp> 
   48 #include <xercesc/sax2/Attributes.hpp> 
   71       XMLCh * convert(
const char * str) 
const;
 
   74       XMLCh * convert(
const std::string & str) 
const;
 
   77       XMLCh * convert(
const String & str) 
const;
 
   80       char * convert(
const XMLCh * str) 
const;
 
   90       public xercesc::DefaultHandler
 
   99           Exception::BaseException(file, line, function)
 
  127       void fatalError(
const xercesc::SAXParseException & 
exception);
 
  128       void error(
const xercesc::SAXParseException & 
exception);
 
  129       void warning(
const xercesc::SAXParseException & 
exception);
 
  133       void fatalError(ActionMode mode, 
const String & msg, 
UInt line = 0, 
UInt column = 0) 
const;
 
  135       void error(ActionMode mode, 
const String & msg, 
UInt line = 0, 
UInt column = 0) 
const;
 
  137       void warning(ActionMode mode, 
const String & msg, 
UInt line = 0, 
UInt column = 0) 
const;
 
  140       virtual void characters(
const XMLCh * 
const chars, 
const XMLSize_t length);
 
  142       virtual void startElement(
const XMLCh * 
const uri, 
const XMLCh * 
const localname, 
const XMLCh * 
const qname, 
const xercesc::Attributes & attrs);
 
  144       virtual void endElement(
const XMLCh * 
const uri, 
const XMLCh * 
const localname, 
const XMLCh * 
const qname);
 
  175       inline bool equal_(
const XMLCh * a, 
const XMLCh * b)
 
  177         return xercesc::XMLString::compareString(a, b) == 0;
 
  198         OPENMS_PRECONDITION(section < cv_terms_.size(), 
"cvStringToEnum_: Index overflow (section number too large)");
 
  200         std::vector<String>::const_iterator it = std::find(cv_terms_[section].begin(), cv_terms_[section].end(), term);
 
  201         if (it != cv_terms_[section].end())
 
  203           return it - cv_terms_[section].begin();
 
  207           warning(LOAD, 
String(
"Unexpected CV entry '") + message + 
"'='" + term + 
"'");
 
  208           return result_on_error;
 
  227           error(LOAD, 
String(
"Int conversion error of \"") + in + 
"\"");
 
  235         return xercesc::XMLString::parseInt(in);
 
  253           error(LOAD, 
String(
"UInt conversion error of \"") + in + 
"\"");
 
  268           error(LOAD, 
String(
"Double conversion error of \"") + in + 
"\"");
 
  283           error(LOAD, 
String(
"Float conversion error of \"") + in + 
"\"");
 
  296         if (in == 
"true" || in == 
"TRUE" || in == 
"True" || in == 
"1")
 
  300         else if (in == 
"false" || in == 
"FALSE" || in == 
"False" || in == 
"0")
 
  306           error(LOAD, 
String(
"Boolean conversion error of \"") + in + 
"\"");
 
  315         if (date_string != 
"")
 
  321             date_string = date_string.
substr(0, 19);
 
  322             date_time.
set(date_string);
 
  326             error(LOAD, 
String(
"DateTime conversion error of \"") + date_string + 
"\"");
 
  340         const XMLCh * val = a.getValue(sm_.convert(name));
 
  341         if (val == 0) fatalError(LOAD, 
String(
"Required attribute '") + name + 
"' not present!");
 
  342         return sm_.convert(val);
 
  348         const XMLCh * val = a.getValue(sm_.convert(name));
 
  349         if (val == 0) fatalError(LOAD, 
String(
"Required attribute '") + name + 
"' not present!");
 
  350         return xercesc::XMLString::parseInt(val);
 
  356         const XMLCh * val = a.getValue(sm_.convert(name));
 
  357         if (val == 0) fatalError(LOAD, 
String(
"Required attribute '") + name + 
"' not present!");
 
  358         return String(sm_.convert(val)).toDouble();
 
  364         String tmp(expectList_(attributeAsString_(a, name)));
 
  371         String tmp(expectList_(attributeAsString_(a, name)));
 
  378         String tmp(expectList_(attributeAsString_(a, name)));
 
  389         const XMLCh * val = a.getValue(sm_.convert(name));
 
  392           value = sm_.convert(val);
 
  405         const XMLCh * val = a.getValue(sm_.convert(name));
 
  408           value = xercesc::XMLString::parseInt(val);
 
  421         const XMLCh * val = a.getValue(sm_.convert(name));
 
  424           value = xercesc::XMLString::parseInt(val);
 
  437         const XMLCh * val = a.getValue(sm_.convert(name));
 
  440           value = 
String(sm_.convert(val)).toDouble();
 
  453         const XMLCh * val = a.getValue(sm_.convert(name));
 
  456           value = attributeAsDoubleList_(a, name);
 
  469         const XMLCh * val = a.getValue(sm_.convert(name));
 
  472           value = attributeAsStringList_(a, name);
 
  485         const XMLCh * val = a.getValue(sm_.convert(name));
 
  488           value = attributeAsIntList_(a, name);
 
  497         const XMLCh * val = a.getValue(name);
 
  498         if (val == 0) fatalError(LOAD, 
String(
"Required attribute '") + sm_.convert(name) + 
"' not present!");
 
  499         return sm_.convert(val);
 
  505         const XMLCh * val = a.getValue(name);
 
  506         if (val == 0) fatalError(LOAD, 
String(
"Required attribute '") + sm_.convert(name) + 
"' not present!");
 
  507         return xercesc::XMLString::parseInt(val);
 
  513         const XMLCh * val = a.getValue(name);
 
  514         if (val == 0) fatalError(LOAD, 
String(
"Required attribute '") + sm_.convert(name) + 
"' not present!");
 
  515         return String(sm_.convert(val)).toDouble();
 
  521         String tmp(expectList_(attributeAsString_(a, name)));
 
  528         String tmp(expectList_(attributeAsString_(a, name)));
 
  535         String tmp(expectList_(attributeAsString_(a, name)));
 
  542         const XMLCh * val = a.getValue(name);
 
  545           char * tmp2 = sm_.convert(val);
 
  558         const XMLCh * val = a.getValue(name);
 
  561           value = xercesc::XMLString::parseInt(val);
 
  570         const XMLCh * val = a.getValue(name);
 
  573           value = xercesc::XMLString::parseInt(val);
 
  582         const XMLCh * val = a.getValue(name);
 
  585           value = 
String(sm_.convert(val)).toDouble();
 
  598         const XMLCh * val = a.getValue(name);
 
  601           value = attributeAsDoubleList_(a, name);
 
  614         const XMLCh * val = a.getValue(name);
 
  617           value = attributeAsIntList_(a, name);
 
  630         const XMLCh * val = a.getValue(name);
 
  633           value = attributeAsStringList_(a, name);
 
  650           fatalError(LOAD, 
String(
"List argument is not a string representation of a list!"));
 
  660 #endif // OPENMS_FORMAT_HANDLERS_XMLHANDLER_H 
std::vector< String > open_tags_
Stack of open XML tags. 
Definition: XMLHandler.h:172
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const 
Converts an attribute to an IntList. 
Definition: XMLHandler.h:369
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:387
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:596
A more convenient string class. 
Definition: String.h:56
static DoubleList create(const String &list)
Returns a list that is created by splitting the given comma-separated string (String are not trimmed!...
bool optionalAttributeAsDouble_(DoubleReal &value, const xercesc::Attributes &a, const XMLCh *name) const 
Assigns the attribute content to the DoubleReal value if the attribute is present. 
Definition: XMLHandler.h:580
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:94
Int asInt_(const XMLCh *in)
Conversion of a Xerces string to an integer value. 
Definition: XMLHandler.h:233
DoubleReal toDouble() const 
Conversion to double. 
String version_
Schema version. 
Definition: XMLHandler.h:162
bool equal_(const XMLCh *a, const XMLCh *b)
Returns if two xerces strings are equal. 
Definition: XMLHandler.h:175
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const 
Converts an attribute to a IntList. 
Definition: XMLHandler.h:526
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers 
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:612
SignedSize cvStringToEnum_(const Size section, const String &term, const char *message, const SignedSize result_on_error=0)
Definition: XMLHandler.h:196
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:556
bool hasSuffix(const String &string) const 
true if String ends with string, false otherwise 
#define OPENMS_PRECONDITION(condition, message)
Precondition macro. 
Definition: Macros.h:107
unsigned int UInt
Unsigned integer type. 
Definition: Types.h:92
char * attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const 
Converts an attribute to a String. 
Definition: XMLHandler.h:495
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:403
Base class for XML handlers. 
Definition: XMLHandler.h:89
DateTime asDateTime_(String date_string)
Conversion of a xs:datetime string to a DataTime value. 
Definition: XMLHandler.h:312
UInt asUInt_(const String &in)
Conversion of a String to an unsigned integer value. 
Definition: XMLHandler.h:239
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference. 
Definition: Types.h:151
ActionMode
Action to set the current mode (for error messages) 
Definition: XMLHandler.h:106
Helper class for XML parsing that handles the memory management for conversions of Xerces strings...
Definition: XMLHandler.h:58
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const 
Converts an attribute to a Int. 
Definition: XMLHandler.h:346
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:568
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:467
String error_message_
Error message of the last error. 
Definition: XMLHandler.h:156
DoubleReal attributeAsDouble_(const xercesc::Attributes &a, const char *name) const 
Converts an attribute to a DoubleReal. 
Definition: XMLHandler.h:354
Int toInt() const 
Conversion to int. 
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:98
String expectList_(const char *str) const 
Definition: XMLHandler.h:645
std::vector< XMLCh * > xml_strings_
Definition: XMLHandler.h:82
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const 
Converts an attribute to a DoubleList. 
Definition: XMLHandler.h:362
int exception
(Used by various macros. Indicates a rough category of the exception being caught.) 
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const 
Converts an attribute to an StringList. 
Definition: XMLHandler.h:376
float asFloat_(const String &in)
Conversion of a String to a float value. 
Definition: XMLHandler.h:274
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:419
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
bool asBool_(const String &in)
Conversion of a string to a boolean value. 
Definition: XMLHandler.h:294
String file_
File name. 
Definition: XMLHandler.h:159
static StringList create(const String &list, const char splitter= ',')
Returns a list that is created by splitting the given (comma-separated) string (String are not trimme...
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const 
Converts an attribute to a DoubleList. 
Definition: XMLHandler.h:519
char * attributeAsString_(const xercesc::Attributes &a, const char *name) const 
Converts an attribute to a String. 
Definition: XMLHandler.h:338
Exception base class. 
Definition: Exception.h:90
Invalid conversion exception. 
Definition: Exception.h:363
Loading a file. 
Definition: XMLHandler.h:108
Real toFloat() const 
Conversion to float. 
double asDouble_(const String &in)
Conversion of a String to a double value. 
Definition: XMLHandler.h:259
StringManager sm_
Helper class for string conversion. 
Definition: XMLHandler.h:165
String list. 
Definition: StringList.h:56
Int asInt_(const String &in)
Conversion of a String to an integer value. 
Definition: XMLHandler.h:218
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:540
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:144
DateTime Class. 
Definition: DateTime.h:55
bool optionalAttributeAsDouble_(DoubleReal &value, const xercesc::Attributes &a, const char *name) const 
Assigns the attribute content to the DoubleReal value if the attribute is present. 
Definition: XMLHandler.h:435
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...
static IntList create(const String &list)
Returns a list that is created by splitting the given comma-separated string (String are not trimmed!...
DoubleReal attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const 
Converts an attribute to a DoubleReal. 
Definition: XMLHandler.h:511
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const 
Converts an attribute to a Int. 
Definition: XMLHandler.h:503
std::vector< std::vector< String > > cv_terms_
Array of CV term lists (one sublist denotes one term and it's children) 
Definition: XMLHandler.h:192
std::vector< char * > c_strings_
Definition: XMLHandler.h:83
int Int
Signed integer type. 
Definition: Types.h:100
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:483
virtual void writeTo(std::ostream &)
Writes the contents to a stream. 
Definition: XMLHandler.h:147
DoubleReal list. 
Definition: DoubleList.h:56
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:451
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const 
Converts an attribute to a StringList. 
Definition: XMLHandler.h:533
bool hasPrefix(const String &string) const 
true if String begins with string, false otherwise 
Parse Error exception. 
Definition: Exception.h:608
Int list. 
Definition: IntList.h:56
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:628