ctkCmdLineModuleXslTransform.h 4.0 KB

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