cstlcompiler.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
  3. Distributed under MIT license, or public domain if desired and
  4. recognized in your jurisdiction.
  5. See file LICENSE for detail.
  6. */
  7. #ifndef CSTLCOMPILER_H
  8. #define CSTLCOMPILER_H
  9. #include <QMap>
  10. #include <QFile>
  11. #include <QString>
  12. #include <QXmlStreamReader>
  13. #include <QXmlStreamWriter>
  14. #include <QStringList>
  15. #include <QMetaObject>
  16. #include <QMetaMethod>
  17. #include "properties.h"
  18. #include "qlistobject.h"
  19. #include "cppwebframework_global.h"
  20. CWF_BEGIN_NAMESPACE
  21. /**
  22. * @brief This class compiles view pages with CSTL (C++ Server Pages Standard Tags Library).
  23. */
  24. class CPPWEBFRAMEWORKSHARED_EXPORT CSTLCompiler
  25. {
  26. QByteArray str;
  27. QString path;
  28. QMap<QString, QObject *> &objects;
  29. bool isStrFileName;
  30. bool isView = true;
  31. /**
  32. * @brief Try to open the view page, if it fails, it will return an error QByteArray, else, it will return an empty QByteArray.
  33. * @param QXmlStreamReader &xml : The opened xml.
  34. * @return QByteArray : Return an error QByteArray, else, it will return an empty QByteArray.
  35. */
  36. QByteArray openFile(QXmlStreamReader &xml);
  37. /**
  38. * @brief Process XML file to find special tags and expressions.
  39. * @param QXmlStreamReader &xml : The opened xml.
  40. * @return QByteArray : Returns the processed QByteArray or an error.
  41. */
  42. QByteArray processXml(QXmlStreamReader &xml);
  43. /**
  44. * @brief Process out tag from CSTL
  45. * @param QXmlStreamReader &xml : The opened xml.
  46. * @return QByteArray : Returns the processed QByteArray or an error.
  47. */
  48. QByteArray processOutTag(QMap<QString, QString> &attr);
  49. /**
  50. * @brief Process for tag from CSTL
  51. * @param QXmlStreamReader &xml : The opened xml.
  52. * @return QByteArray : Returns the processed QByteArray or an error.
  53. */
  54. QByteArray processForTag(QXmlStreamReader &xml);
  55. /**
  56. * @brief Process if tag from CSTL
  57. * @param QXmlStreamReader &xml : The opened xml.
  58. * @return QByteArray : Returns the processed QByteArray or an error.
  59. */
  60. QByteArray processIfTag(QXmlStreamReader &xml);
  61. /**
  62. * @brief Extract a tag body.
  63. * @param QXmlStreamReader &xml : The opened xml.
  64. * @param const QString &tagName : Tag name to extract body.
  65. * @return QByteArray : Tag body.
  66. */
  67. QByteArray getBody(QXmlStreamReader &xml, const QString &tagName);
  68. void processText(QString &text);
  69. public:
  70. /**
  71. * @brief Initialize the str, objects and isStrFileName properties.
  72. * @param const QByteArray &str : If isStrFileName is true, it should be a file name, else, it should be the file content.
  73. * @param QMap<QString, QObject *> &objects : Container objects that can be compiled into the view page.
  74. * @param bool isStrFileName : It indicates whether str is the name of a file or its contents.
  75. */
  76. CSTLCompiler(const QByteArray &str, QString path, QMap<QString, QObject *> &objects, bool isStrFileName = true);
  77. /**
  78. * @brief Returns the compiled view page.
  79. * @return QByteArray : Compiled page.
  80. */
  81. QByteArray output();
  82. };
  83. CWF_END_NAMESPACE
  84. #endif // CSTLCOMPILER_H