ctkCmdLineModuleXslTransform.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 ctkCmdLineModuleXslTransformPrivate;
  21. // Qt includes
  22. class QIODevice;
  23. /**
  24. * \ingroup CommandLineModulesCore
  25. */
  26. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXslTransform
  27. : public ctkCmdLineModuleXmlValidator
  28. {
  29. public:
  30. ctkCmdLineModuleXslTransform(QIODevice* input = 0, QIODevice* output = 0);
  31. virtual ~ctkCmdLineModuleXslTransform();
  32. void setOutput(QIODevice* output);
  33. QIODevice* output() const;
  34. void setOutputSchema(QIODevice* output);
  35. /**
  36. * @brief Returns \code true if the XSL output will be formatted.
  37. * @return \code true if the ouptut will be formatted, \code false otherwise.
  38. */
  39. bool formatXmlOutput() const;
  40. /**
  41. * @brief Formats the XSL output to be human-readable.
  42. *
  43. * It is assumed that the XSL output is valid XML. The output will be
  44. * formatted with an indentation depth of four spaces. Note that setting
  45. * \e format to \code true increases compuational overhead and memory
  46. * requirements and is usually only done for testing or debugging purposes.
  47. */
  48. void setFormatXmlOutput(bool format);
  49. /**
  50. * @brief Transforms an XML input via a XSL transformation.
  51. *
  52. * This method assumes that the input set via setInput() or supplied
  53. * in the constructor is a valid, non empty XML fragment.
  54. *
  55. * @return
  56. */
  57. bool transform();
  58. void setXslTransformation(QIODevice* transformation);
  59. /**
  60. * @brief XSL to be injected in the main XSL.
  61. *
  62. * This can be used to potentially overwrite templates.
  63. * To avoid ambiguity, specify a priority > 1 in your overwriting templates
  64. *
  65. * @return
  66. */
  67. void setXslExtraTransformation(QIODevice* transformation);
  68. void setXslExtraTransformations(const QList<QIODevice*>& transformations);
  69. /**
  70. * @brief Binds the variable name to the value so that $name can be used
  71. * from within the query to refer to the value.
  72. * In the default XslTransformation, the widget classes are variable and can
  73. * be replaced with a new binding.
  74. * @sa QXmlQuery::bindVariable()
  75. */
  76. void bindVariable(const QString& name, const QVariant& value);
  77. void setValidateOutput(bool validate);
  78. /** @brief returns true if an error occured
  79. * transform() sets the error flag if an error occured when transforming the
  80. * XML file into XSL.
  81. * \sa errorString
  82. */
  83. virtual bool error() const;
  84. /** @brief Error message if any
  85. * transform() sets the error message if an error occured when transforming
  86. * the XML file into XSL.
  87. * \sa error
  88. */
  89. virtual QString errorString() const;
  90. private:
  91. QScopedPointer<ctkCmdLineModuleXslTransformPrivate> d;
  92. };
  93. #endif // CTKCMDLINEMODULEXSLTRANSFORM_H