ctkCmdLineModuleXslTransform.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_API
  25. *
  26. * @brief Transforms a given XML input using an XML stylesheet.
  27. *
  28. * You must call setInput(), setOutput() and setXslTransformation() before
  29. * calling transform().
  30. *
  31. * @see ctkCmdLineModuleXmlValidator
  32. */
  33. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXslTransform
  34. : public ctkCmdLineModuleXmlValidator
  35. {
  36. public:
  37. ctkCmdLineModuleXslTransform(QIODevice* input = 0, QIODevice* output = 0);
  38. virtual ~ctkCmdLineModuleXslTransform();
  39. /**
  40. * @brief Set the output device to which the transformation will be written.
  41. * @param output The output device.
  42. *
  43. * If no output device is set, a default device will be used.
  44. */
  45. void setOutput(QIODevice* output);
  46. /**
  47. * @brief Get the output device to which the transformation will be written.
  48. * @return The output device.
  49. */
  50. QIODevice* output() const;
  51. /**
  52. * @brief Set an XML schema for output validation.
  53. * @param output The XML schema against which the transformation will be validated.
  54. *
  55. * Output validation will only be done if validateOutput() returns \c true.
  56. */
  57. void setOutputSchema(QIODevice* output);
  58. /**
  59. * @brief Returns \c true if the XSL output will be formatted.
  60. * @return \c true if the ouptut will be formatted, \c false otherwise.
  61. */
  62. bool formatXmlOutput() const;
  63. /**
  64. * @brief Formats the XSL output to be human-readable.
  65. *
  66. * It is assumed that the XSL output is valid XML. The output will be
  67. * formatted with an indentation depth of four spaces. Note that setting
  68. * \c format to \c true increases compuational overhead and memory
  69. * requirements and is usually only done for testing or debugging purposes.
  70. */
  71. void setFormatXmlOutput(bool format);
  72. /**
  73. * @brief Transforms an XML input via a XSL transformation.
  74. *
  75. * This method assumes that the input set via setInput() or supplied
  76. * in the constructor is a valid, non empty XML fragment and that setOutput()
  77. * and setXslTransformation() was called with non-null arguments.
  78. *
  79. * @return
  80. */
  81. bool transform();
  82. /**
  83. * @brief Sets the XSL transformation.
  84. *
  85. * Use this method to set the XSL transformation for this instance. Trying
  86. * to transform the input without setting a transformation will result in
  87. * runtime errors.
  88. *
  89. * @param transformation The XSL transformation.
  90. */
  91. void setXslTransformation(QIODevice* transformation);
  92. /**
  93. * @brief XSL to be injected in the main XSL.
  94. *
  95. * This can be used to potentially overwrite templates.
  96. * To avoid ambiguity, specify a priority > 1 in your overwriting templates
  97. *
  98. * \param transformation Extra XSL transformation fragment.
  99. */
  100. void setXslExtraTransformation(QIODevice* transformation);
  101. void setXslExtraTransformations(const QList<QIODevice*>& transformations);
  102. /**
  103. * @brief Binds the variable name to the value so that $name can be used
  104. * from within the query to refer to the value.
  105. * In the default XslTransformation, the widget classes are variable and can
  106. * be replaced with a new binding.
  107. * @sa QXmlQuery::bindVariable()
  108. */
  109. void bindVariable(const QString& name, const QVariant& value);
  110. /**
  111. * @brief Sets the output validation mode.
  112. * @param validate If \c true, the output will be validated against the XML schema
  113. * provided via setOutputSchema(). If \c validate is \c false, no output
  114. * validation takes place.
  115. */
  116. void setValidateOutput(bool validate);
  117. /**
  118. * @brief Get the output validation mode.
  119. * @return \c true if the output will be validated, \c false otherwise.
  120. */
  121. bool validateOutput() const;
  122. /**
  123. * @brief Returns true if an error occured.
  124. *
  125. * transform() sets the error flag if an error occured when transforming the
  126. * XML file into XSL or validating the transformation.
  127. *
  128. * @sa errorString
  129. */
  130. virtual bool error() const;
  131. /**
  132. * @brief Returns the error message if any.
  133. *
  134. * transform() sets the error message if an error occured when transforming
  135. * the XML file into XSL.
  136. *
  137. * @sa error
  138. */
  139. virtual QString errorString() const;
  140. private:
  141. QScopedPointer<ctkCmdLineModuleXslTransformPrivate> d;
  142. };
  143. #endif // CTKCMDLINEMODULEXSLTRANSFORM_H