ctkXnatResourceCatalogXmlParser.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=============================================================================
  2. Library: XNAT/Core
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkXnatResourceCatalogXmlParser.h"
  16. #include <QDebug>
  17. //----------------------------------------------------------------------------
  18. class ctkXnatResourceCatalogXmlParserPrivate
  19. {
  20. public:
  21. ctkXnatResourceCatalogXmlParserPrivate()
  22. {
  23. }
  24. QList<QVariantMap> result;
  25. };
  26. ctkXnatResourceCatalogXmlParser::ctkXnatResourceCatalogXmlParser()
  27. : d_ptr (new ctkXnatResourceCatalogXmlParserPrivate())
  28. {
  29. }
  30. ctkXnatResourceCatalogXmlParser::~ctkXnatResourceCatalogXmlParser()
  31. {
  32. delete d_ptr;
  33. }
  34. bool ctkXnatResourceCatalogXmlParser::startElement(const QString &/*namespaceURI*/, const QString &localName,
  35. const QString &qName, const QXmlAttributes &atts)
  36. {
  37. Q_D(ctkXnatResourceCatalogXmlParser);
  38. if (qName == "cat:entry")
  39. {
  40. QString name("");
  41. QString md5("");
  42. QVariantMap map;
  43. for( int i=0; i<atts.count(); i++ )
  44. {
  45. // TODO ID would be better
  46. if( atts.localName(i) == "name")
  47. name = atts.value(i);
  48. if( atts.localName( i ) == "digest" )
  49. {
  50. md5 = atts.value(i);
  51. }
  52. }
  53. if (name.length() == 0 || md5.length() == 0)
  54. {
  55. qWarning()<<"Error parsing XNAT resource catalog xml!";
  56. return false;
  57. }
  58. else
  59. {
  60. map[name] = QVariant(md5);
  61. d->result.append(map);
  62. }
  63. }
  64. return true;
  65. }
  66. const QList<QVariantMap>& ctkXnatResourceCatalogXmlParser::md5Hashes()
  67. {
  68. Q_D(ctkXnatResourceCatalogXmlParser);
  69. return d->result;
  70. }