xslprocessor.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef XSLPROCESSOR_HPP_INCL
  15. #define XSLPROCESSOR_HPP_INCL
  16. #include "jliball.hpp"
  17. #include "xmllib.hpp"
  18. class StringBuffer;
  19. interface XMLLIB_API IIncludeHandler : public IInterface
  20. {
  21. public:
  22. virtual bool getInclude(const char* includename, MemoryBuffer& includebuf, bool& pathOnly) = 0;
  23. };
  24. interface XMLLIB_API IXslFunction : public IInterface
  25. {
  26. public:
  27. virtual const char* getName() const = 0;
  28. virtual bool isAssigned () = 0;
  29. virtual void setAssigned(bool bAssigned) = 0;
  30. };
  31. //The transform component is used to setup, and maintain any state associated with a transform
  32. //
  33. interface XMLLIB_API IXslTransform : public IInterface
  34. {
  35. public:
  36. // setXmlSource - specifies the source of the XML to process
  37. //
  38. virtual int setXmlSource(const char *pszFileName) = 0;
  39. virtual int setXmlSource(const char *pszBuffer, unsigned int nSize) = 0;
  40. // setXslSource - specifies the source of the XSLT "script" to use
  41. //
  42. virtual int setXslSource(const char *pszBuffer, unsigned int nSize, const char *cacheId, const char *rootpath) = 0;
  43. virtual int setXslNoCache(const char *pszBuffer, unsigned int nSize, const char *rootpath=NULL) = 0;
  44. virtual int loadXslFromFile(const char *pszFileName, const char *altCacheId=NULL) = 0;
  45. // setResultTarget - Specifies where the post transform data is to be placed
  46. // must be set before calling parameterless variety of transform
  47. virtual int setResultTarget(const char *pszFileName) = 0;
  48. virtual int setResultTarget(char *pszBuffer, unsigned int nSize) = 0;
  49. virtual int closeResultTarget() = 0;
  50. // setParameter - for adding value pair parameters
  51. // szExpression == "" is empty parameter
  52. // szExpression == NULL removes any existing parameter with the given name
  53. //
  54. virtual int setParameter(const char *pszName, const char *pszExpression) = 0;
  55. virtual void copyParameters(IProperties *params) = 0;
  56. virtual int setStringParameter(const char *pszName, const char* pszString) = 0;
  57. //In XalanTransformer, m_paramPairs are cleaned after each doTransform, so this function is really not necessary.
  58. //virtual int removeAllParameters () = 0;
  59. // transform - for doing it
  60. virtual int transform() = 0;
  61. virtual int transform(StringBuffer &target) = 0;
  62. virtual int transform(ISocket* targetSocket) = 0;
  63. // Set include source
  64. virtual int setIncludeHandler(IIncludeHandler* handler) = 0;
  65. // createExternalFunction - create a simple external function that processes text (a convenient way to define external functions)
  66. //
  67. virtual IXslFunction* createExternalFunction( const char* pszNameSpace, void (*fn)(StringBuffer& out, const char* pszIn, IXslTransform*)) = 0;
  68. // setExternalFunction - add an external function that can be called from within the XSLT
  69. //
  70. virtual int setExternalFunction( const char* pszNameSpace, IXslFunction*, bool set) = 0;
  71. // getLastError - returns the error, if any, in last transformation, compiling stylesheet or parsing source
  72. //
  73. virtual const char* getLastError() const = 0;
  74. // getMessages - returns the messages produced, if any, in last transformation, compiling stylesheet or parsing source
  75. // The most useful application is to fetch any <xsl:message/> as a result of transformation.
  76. // Note: in case of any errors, any cumulative messages until the error are bundled with the
  77. // message.
  78. //
  79. virtual const char* getMessages() const = 0;
  80. //Allow the caller to set necessary info that can be used to identify it.
  81. //This is typically useful in [static] external functions, which can use
  82. //this info to work with caller/context.
  83. //
  84. virtual void setUserData(void*) = 0;
  85. virtual void* getUserData() const = 0;
  86. };
  87. interface XMLLIB_API IXslProcessor : public IInterface
  88. {
  89. virtual IXslTransform *createXslTransform() = 0;
  90. // execute - runs the transformation placing the results in the specified output location
  91. //
  92. virtual int execute(IXslTransform *pITransform) = 0;
  93. virtual int setDefIncludeHandler(IIncludeHandler* handler)=0;
  94. virtual void setCacheTimeout(int timeout) = 0;
  95. virtual int getCacheTimeout() = 0;
  96. };
  97. extern "C" XMLLIB_API IXslProcessor* getXslProcessor();
  98. extern "C" XMLLIB_API IXslProcessor* getXslProcessor2();
  99. #endif