OpenMS
XMLHandler.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Marc Sturm, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/CONCEPT/Types.h>
12 #include <OpenMS/CONCEPT/Macros.h>
13 
14 #include <OpenMS/DATASTRUCTURES/ListUtils.h> // StringList
18 
19 #include <xercesc/sax2/Attributes.hpp>
20 #include <xercesc/sax2/DefaultHandler.hpp>
21 #include <xercesc/util/XMLString.hpp>
22 
23 #include <iosfwd>
24 #include <string>
25 #include <memory>
26 
27 
28 namespace OpenMS
29 {
30  class ProteinIdentification;
31  class MetaInfoInterface;
32 
33  namespace Internal
34  {
35 
36  #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
37 
38  static_assert(sizeof(::XMLCh) == sizeof(char16_t),
39  "XMLCh is not sized correctly for UTF-16.");
40 
41  //Adapted from https://www.codeproject.com/articles/99551/redux-raii-adapter-for-xerces
42  //Copyright 2010 Orjan Westin
43  //Under BSD license
44  //========================================================================================================
45  template<typename T>
46  class OPENMS_DLLAPI shared_xerces_ptr
47  {
48  // Function to release Xerces data type with a release member function
49  template<typename U>
50  static void doRelease_(U* item)
51  {
52  // Only release this if it has no owner
53  if (nullptr == item->getOwnerDocument())
54  item->release();
55  }
56 
57  static void doRelease_(char* item);
58  static void doRelease_(XMLCh* item);
59 
60  // The actual data we're holding
61  std::shared_ptr<T> item_;
62  public:
63  // Default constructor
64  shared_xerces_ptr() = default;
65  // Assignment constructor
67  : item_(item, doRelease_ )
68  {}
69  // Assignment of data to guard
71  {
72  assign(item);
73  return *this;
74  }
75  // Give up hold on data
76  void reset()
77  {
78  item_.reset();
79  }
80  // Release currently held data, if any, to hold another
81  void assign(T* item)
82  {
83  item_.reset(item, doRelease_ );
84  }
85  // Get pointer to the currently held data, if any
86  T* get()
87  {
88  return item_.get();
89  }
90  const T* get() const
91  {
92  return item_.get();
93  }
94  // Return true if no data is held
95  bool is_released() const
96  {
97  return (nullptr == item_.get());
98  }
99  };
100 
101  template <typename T>
102  class OPENMS_DLLAPI unique_xerces_ptr
103  {
104  private:
105 
106  template<typename U>
107  static void doRelease_(U*& item)
108  {
109  // Only release this if it has no parent (otherwise
110  // parent will release it)
111  if (nullptr == item->getOwnerDocument())
112  item->release();
113  }
114 
115  static void doRelease_(char*& item);
116  static void doRelease_(XMLCh*& item);
117 
118  T* item_;
119 
120  public:
121 
122  // Hide copy constructor and assignment operator
125 
127  : item_(nullptr)
128  {}
129 
130  explicit unique_xerces_ptr(T* i)
131  : item_(i)
132  {}
133 
135  {
136  xerces_release();
137  }
138 
140  : item_(nullptr)
141  {
142  this->swap(other);
143  }
144 
145  void swap(unique_xerces_ptr<T>& other) noexcept
146  {
147  std::swap(item_, other.item_);
148  }
149 
150  // Assignment of data to guard (not chainable)
151  void operator=(T* i)
152  {
153  reassign(i);
154  }
155 
156  // Release held data (i.e. delete/free it)
158  {
159  if (!is_released())
160  {
161  // Use type-specific release mechanism
162  doRelease_(item_);
163  item_ = nullptr;
164  }
165  }
166 
167  // Give up held data (i.e. return data without releasing)
168  T* yield()
169  {
170  T* tempItem = item_;
171  item_ = nullptr;
172  return tempItem;
173  }
174 
175  // Release currently held data, if any, to hold another
176  void assign(T* i)
177  {
178  xerces_release();
179  item_ = i;
180  }
181 
182  // Get pointer to the currently held data, if any
183  T* get() const
184  {
185  return item_;
186  }
187 
188  // Return true if no data is held
189  bool is_released() const
190  {
191  return (nullptr == item_);
192  }
193  };
194 
195  //========================================================================================================
196 
197  /*
198  * @brief Helper class for XML parsing that handles the conversions of Xerces strings
199  *
200  * It provides the convert() function which internally calls
201  * XMLString::transcode and ensures that the memory is released properly
202  * through XMLString::release internally. It returns a std::string or
203  * std::basic_string<XMLCh> to the caller who takes ownership of the data.
204  *
205  */
206  class OPENMS_DLLAPI StringManager
207  {
208 
209  typedef std::basic_string<XMLCh> XercesString;
210 
211  // Converts from a narrow-character string to a wide-character string.
212  inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
213  {
214  return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
215  }
216 
217  // Converts from a narrow-character string to a wide-character string.
218  inline static unique_xerces_ptr<XMLCh> fromNative_(const String& str)
219  {
220  return fromNative_(str.c_str());
221  }
222 
223  // Converts from a wide-character string to a narrow-character string.
224  inline static String toNative_(const XMLCh* str)
225  {
226  return String(unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
227  }
228 
229  // Converts from a wide-character string to a narrow-character string.
230  inline static String toNative_(const unique_xerces_ptr<XMLCh>& str)
231  {
232  return toNative_(str.get());
233  }
234 
235 
236 public:
239 
242 
244  inline static XercesString convert(const char * str)
245  {
246  return fromNative_(str).get();
247  }
248 
250  inline static XercesString convert(const std::string & str)
251  {
252  return fromNative_(str.c_str()).get();
253  }
254 
256  inline static XercesString convert(const String & str)
257  {
258  return fromNative_(str.c_str()).get();
259  }
260 
262  inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
263  {
264  return fromNative_(str);
265  }
266 
268  inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
269  {
270  return fromNative_(str.c_str());
271  }
272 
274  inline static unique_xerces_ptr<XMLCh> convertPtr(const String & str)
275  {
276  return fromNative_(str.c_str());
277  }
278 
280  inline static String convert(const XMLCh * str)
281  {
282  return toNative_(str);
283  }
284 
291  static void appendASCII(const XMLCh * str, const XMLSize_t length, String & result);
292 
293  };
294 
298  class OPENMS_DLLAPI XMLHandler :
299  public xercesc::DefaultHandler
300  {
301 public:
302 
304  class OPENMS_DLLAPI EndParsingSoftly :
306  {
307  public:
308  EndParsingSoftly(const char * file, int line, const char * function) :
309  Exception::BaseException(file, line, function)
310  {
311  }
312 
313  };
314 
317  {
319  STORE
320  };
321 
323  {
324  LD_ALLDATA, // default; load all data
325  LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
326  LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
327  };
328 
329 
331  XMLHandler(const String & filename, const String & version);
333  ~XMLHandler() override;
334 
336  void reset();
337 
338 
345  void fatalError(const xercesc::SAXParseException & exception) override;
346  void error(const xercesc::SAXParseException & exception) override;
347  void warning(const xercesc::SAXParseException & exception) override;
349 
351  void fatalError(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
353  void error(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
355  void warning(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
356 
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;
363 
365  virtual void writeTo(std::ostream & /*os*/);
366 
368  virtual LOADDETAIL getLoadDetail() const;
369 
371  virtual void setLoadDetail(const LOADDETAIL d);
372 
380  static String writeXMLEscape(const String& to_escape)
381  {
382  String _copy = to_escape;
383  // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
384  if (_copy.has('&')) _copy.substitute("&","&amp;");
385  if (_copy.has('>')) _copy.substitute(">","&gt;");
386  if (_copy.has('"')) _copy.substitute("\"","&quot;");
387  if (_copy.has('<')) _copy.substitute("<","&lt;");
388  if (_copy.has('\'')) _copy.substitute("'","&apos;");
389 
390  return _copy;
391  }
392 
406  static DataValue fromXSDString(const String& type, const String& value)
407  {
408  DataValue data_value;
409  // float type
410  if (type == "xsd:double" || type == "xsd:float" || type == "xsd:decimal")
411  {
412  data_value = DataValue(value.toDouble());
413  }
414  // <=32 bit integer types
415  else if (type == "xsd:byte" || // 8bit signed
416  type == "xsd:int" || // 32bit signed
417  type == "xsd:unsignedShort" || // 16bit unsigned
418  type == "xsd:short" || // 16bit signed
419  type == "xsd:unsignedByte" || type == "xsd:unsignedInt")
420  {
421  data_value = DataValue(value.toInt32());
422  }
423  // 64 bit integer types
424  else if (type == "xsd:long" || type == "xsd:unsignedLong" || // 64bit signed or unsigned respectively
425  type == "xsd:integer" || type == "xsd:negativeInteger" || // any 'integer' has arbitrary size... but we have to cope with 64bit for now.
426  type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger")
427  {
428  data_value = DataValue(value.toInt64()); // internally a signed 64-bit integer. So if someone uses 2^64-1 as value, toInt64() will raise an exception...
429  }
430  // everything else is treated as a string
431  else
432  {
433  data_value = DataValue(value);
434  }
435  return data_value;
436  }
437 
440  void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
441 
442 protected:
445 
448 
451 
457  std::vector<String> open_tags_;
458 
461 
462 
464  inline bool equal_(const XMLCh * a, const XMLCh * b) const
465  {
466  return xercesc::XMLString::compareString(a, b) == 0;
467  }
468 
470 
471 
473  void writeUserParam_(const String & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
474 
476 
478 
479 
481  std::vector<std::vector<String> > cv_terms_;
482 
485  SignedSize cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error = 0);
486 
488 
490 
491 
493  inline Int asInt_(const String & in) const
494  {
495  Int res = 0;
496  try
497  {
498  res = in.toInt();
499  }
501  {
502  error(LOAD, String("Int conversion error of \"") + in + "\"");
503  }
504  return res;
505  }
506 
508  inline Int asInt_(const XMLCh * in) const
509  {
510  return xercesc::XMLString::parseInt(in);
511  }
512 
514  inline UInt asUInt_(const String & in) const
515  {
516  UInt res = 0;
517  try
518  {
519  Int tmp = in.toInt();
520  if (tmp < 0)
521  {
522  throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
523  }
524  res = UInt(tmp);
525  }
527  {
528  error(LOAD, String("UInt conversion error of \"") + in + "\"");
529  }
530  return res;
531  }
532 
534  inline double asDouble_(const String & in) const
535  {
536  double res = 0.0;
537  try
538  {
539  res = in.toDouble();
540  }
542  {
543  error(LOAD, String("Double conversion error of \"") + in + "\"");
544  }
545  return res;
546  }
547 
549  inline float asFloat_(const String & in) const
550  {
551  float res = 0.0;
552  try
553  {
554  res = in.toFloat();
555  }
557  {
558  error(LOAD, String("Float conversion error of \"") + in + "\"");
559  }
560  return res;
561  }
562 
570  inline bool asBool_(const String & in) const
571  {
572  if (in == "true" || in == "TRUE" || in == "True" || in == "1")
573  {
574  return true;
575  }
576  else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
577  {
578  return false;
579  }
580  else
581  {
582  error(LOAD, String("Boolean conversion error of \"") + in + "\"");
583  }
584  return false;
585  }
586 
588  inline DateTime asDateTime_(String date_string) const
589  {
590  DateTime date_time;
591  if (!date_string.empty())
592  {
593  try
594  {
595  //strip away milliseconds
596  date_string.trim();
597  date_string = date_string.substr(0, 19);
598  date_time.set(date_string);
599  }
600  catch (Exception::ParseError& /*err*/ )
601  {
602  error(LOAD, String("DateTime conversion error of \"") + date_string + "\"");
603  }
604  }
605  return date_time;
606  }
607 
609 
611 
612 
614  inline String attributeAsString_(const xercesc::Attributes & a, const char * name) const
615  {
616  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
617  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
618  return sm_.convert(val);
619  }
620 
622  inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
623  {
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);
627  }
628 
630  inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
631  {
632  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
633  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
634  return String(sm_.convert(val)).toDouble();
635  }
636 
638  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
639  {
640  String tmp(expectList_(attributeAsString_(a, name)));
641  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
642  }
643 
645  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
646  {
647  String tmp(expectList_(attributeAsString_(a, name)));
648  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
649  }
650 
652  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
653  {
654  String tmp(expectList_(attributeAsString_(a, name)));
655  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
656 
657  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
658  {
659  for (String& s : tmp_list)
660  {
661  s.substitute("\\|", ",");
662  }
663  }
664  return tmp_list;
665  }
666 
672  inline bool optionalAttributeAsString_(String & value, const xercesc::Attributes & a, const char * name) const
673  {
674  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
675  if (val != nullptr)
676  {
677  value = sm_.convert(val);
678  return true;
679  }
680  return false;
681  }
682 
688  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
689  {
690  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
691  if (val != nullptr)
692  {
693  value = xercesc::XMLString::parseInt(val);
694  return true;
695  }
696  return false;
697  }
698 
704  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
705  {
706  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
707  if (val != nullptr)
708  {
709  value = xercesc::XMLString::parseInt(val);
710  return true;
711  }
712  return false;
713  }
714 
720  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
721  {
722  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
723  if (val != nullptr)
724  {
725  value = String(sm_.convert(val)).toDouble();
726  return true;
727  }
728  return false;
729  }
730 
736  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
737  {
738  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
739  if (val != nullptr)
740  {
741  value = attributeAsDoubleList_(a, name);
742  return true;
743  }
744  return false;
745  }
746 
752  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
753  {
754  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
755  if (val != nullptr)
756  {
757  value = attributeAsStringList_(a, name);
758  return true;
759  }
760  return false;
761  }
762 
768  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
769  {
770  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
771  if (val != nullptr)
772  {
773  value = attributeAsIntList_(a, name);
774  return true;
775  }
776  return false;
777  }
778 
780  inline String attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
781  {
782  const XMLCh * val = a.getValue(name);
783  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
784  return sm_.convert(val);
785  }
786 
788  inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
789  {
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);
793  }
794 
796  inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
797  {
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();
801  }
802 
804  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
805  {
806  String tmp(expectList_(attributeAsString_(a, name)));
807  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
808  }
809 
811  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
812  {
813  String tmp(expectList_(attributeAsString_(a, name)));
814  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
815  }
816 
818  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
819  {
820  String tmp(expectList_(attributeAsString_(a, name)));
821  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
822 
823  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
824  {
825  for (String& s : tmp_list)
826  {
827  s.substitute("\\|", ",");
828  }
829  }
830  return tmp_list;
831  }
832 
834  inline bool optionalAttributeAsString_(String& value, const xercesc::Attributes & a, const XMLCh * name) const
835  {
836  const XMLCh * val = a.getValue(name);
837  if (val != nullptr)
838  {
839  value = sm_.convert(val);
840  return !value.empty();
841  }
842  return false;
843  }
844 
846  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
847  {
848  const XMLCh * val = a.getValue(name);
849  if (val != nullptr)
850  {
851  value = xercesc::XMLString::parseInt(val);
852  return true;
853  }
854  return false;
855  }
856 
858  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
859  {
860  const XMLCh * val = a.getValue(name);
861  if (val != nullptr)
862  {
863  value = xercesc::XMLString::parseInt(val);
864  return true;
865  }
866  return false;
867  }
868 
870  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
871  {
872  const XMLCh * val = a.getValue(name);
873  if (val != nullptr)
874  {
875  value = sm_.convert(val).toDouble();
876  return true;
877  }
878  return false;
879  }
880 
886  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
887  {
888  const XMLCh * val = a.getValue(name);
889  if (val != nullptr)
890  {
891  value = attributeAsDoubleList_(a, name);
892  return true;
893  }
894  return false;
895  }
896 
902  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
903  {
904  const XMLCh * val = a.getValue(name);
905  if (val != nullptr)
906  {
907  value = attributeAsIntList_(a, name);
908  return true;
909  }
910  return false;
911  }
912 
918  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
919  {
920  const XMLCh * val = a.getValue(name);
921  if (val != nullptr)
922  {
923  value = attributeAsStringList_(a, name);
924  return true;
925  }
926  return false;
927  }
928 
930 
931 private:
934 
935  inline const String& expectList_(const String& str) const
936  {
937  if (!(str.hasPrefix('[') && str.hasSuffix(']')))
938  {
939  fatalError(LOAD, String("List argument is not a string representation of a list!"));
940  }
941  return str;
942  }
943 
944  };
945 
946  } // namespace Internal
947 } // namespace OpenMS
948 
949 
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
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
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
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
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:35
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