ctkCmdLineModuleXslTransform.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*=============================================================================
  2. Library: CTK
  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. #ifndef __ctkCmdLineModuleXslTransform_h
  16. #define __ctkCmdLineModuleXslTransform_h
  17. // CTK includes
  18. #include "ctkCommandLineModulesCoreExport.h"
  19. #include "ctkCmdLineModuleXmlValidator.h"
  20. class ctkCmdLineModuleXmlMsgHandler;
  21. // Qt includes
  22. #include <QList>
  23. #include <QString>
  24. #include <QXmlQuery>
  25. class QIODevice;
  26. /**
  27. * \ingroup CommandLineModulesCore
  28. */
  29. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXslTransform
  30. : public ctkCmdLineModuleXmlValidator
  31. {
  32. public:
  33. ctkCmdLineModuleXslTransform(QIODevice* input = 0, QIODevice* output = 0);
  34. virtual ~ctkCmdLineModuleXslTransform();
  35. void setOutput(QIODevice* output);
  36. QIODevice* output() const;
  37. void setOutputSchema(QIODevice* output);
  38. /**
  39. * @brief Transforms an XML input via a XSL transformation.
  40. *
  41. * This method assumes that the input set via setInput() or supplied
  42. * in the constructor is a valid, non empty XML fragment.
  43. *
  44. * @return
  45. */
  46. bool transform();
  47. void setXslTransformation(QIODevice* transformation);
  48. /**
  49. * @brief XSL to be injected in the main XSL.
  50. *
  51. * This can be used to potentially overwrite templates.
  52. * To avoid ambiguity, specify a priority > 1 in your overwriting templates
  53. *
  54. * @return
  55. */
  56. inline void setXslExtraTransformation(QIODevice* transformation);
  57. void setXslExtraTransformations(QList<QIODevice*> transformations);
  58. /**
  59. * @brief Binds the variable name to the value so that $name can be used
  60. * from within the query to refer to the value.
  61. * In the default XslTransformation, the widget classes are variable and can
  62. * be replaced with a new binding.
  63. * @sa QXmlQuery::bindVariable()
  64. */
  65. void bindVariable(const QString& name, const QVariant& value);
  66. void setValidateOutput(bool validate);
  67. /** @brief returns true if an error occured
  68. * transform() sets the error flag if an error occured when transforming the
  69. * XML file into XSL.
  70. * \sa errorString
  71. */
  72. virtual bool error() const;
  73. /** @brief Error message if any
  74. * transform() sets the error message if an error occured when transforming
  75. * the XML file into XSL.
  76. * \sa error
  77. */
  78. virtual QString errorString() const;
  79. private:
  80. bool validateOutput();
  81. bool Validate;
  82. QIODevice* OutputSchema;
  83. QIODevice* Transformation;
  84. QIODevice* Output;
  85. QXmlQuery XslTransform;
  86. QList<QIODevice*> ExtraTransformations;
  87. ctkCmdLineModuleXmlMsgHandler* MsgHandler;
  88. QString ErrorStr;
  89. };
  90. void ctkCmdLineModuleXslTransform::setXslExtraTransformation(QIODevice* transformation)
  91. {
  92. QList<QIODevice*> transformations;
  93. transformations<<transformation;
  94. this->setXslExtraTransformations(transformations);
  95. }
  96. #endif // CTKCMDLINEMODULEXSLTRANSFORM_H