xslprocessor.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #define SEISINT_XSLTEXT_NAMESPACE "http://seisint.com"
  20. interface XMLLIB_API IIncludeHandler : public IInterface
  21. {
  22. public:
  23. virtual bool getInclude(const char* includename, MemoryBuffer& includebuf, bool& pathOnly) = 0;
  24. };
  25. interface XMLLIB_API IXslFunction : public IInterface
  26. {
  27. public:
  28. virtual const char* getName() const = 0;
  29. virtual bool isAssigned () = 0;
  30. virtual void setAssigned(bool bAssigned) = 0;
  31. };
  32. //The transform component is used to setup, and maintain any state associated with a transform
  33. //
  34. interface XMLLIB_API IXslTransform : public IInterface
  35. {
  36. public:
  37. // setXmlSource - specifies the source of the XML to process
  38. //
  39. virtual int setXmlSource(const char *pszFileName) = 0;
  40. virtual int setXmlSource(const char *pszBuffer, unsigned int nSize) = 0;
  41. // setXslSource - specifies the source of the XSLT "script" to use
  42. //
  43. virtual int setXslSource(const char *pszBuffer, unsigned int nSize, const char *cacheId, const char *rootpath) = 0;
  44. virtual int setXslNoCache(const char *pszBuffer, unsigned int nSize, const char *rootpath=NULL) = 0;
  45. virtual int loadXslFromFile(const char *pszFileName, const char *altCacheId=NULL) = 0;
  46. // setResultTarget - Specifies where the post transform data is to be placed
  47. // must be set before calling parameterless variety of transform
  48. virtual int setResultTarget(const char *pszFileName) = 0;
  49. virtual int setResultTarget(char *pszBuffer, unsigned int nSize) = 0;
  50. virtual int closeResultTarget() = 0;
  51. // setParameter - for adding value pair parameters
  52. // szExpression == "" is empty parameter
  53. // szExpression == NULL removes any existing parameter with the given name
  54. //
  55. virtual int setParameter(const char *pszName, const char *pszExpression) = 0;
  56. virtual void copyParameters(IProperties *params) = 0;
  57. virtual int setStringParameter(const char *pszName, const char* pszString) = 0;
  58. //In XalanTransformer, m_paramPairs are cleaned after each doTransform, so this function is really not necessary.
  59. //virtual int removeAllParameters () = 0;
  60. // transform - for doing it
  61. virtual int transform() = 0;
  62. virtual int transform(StringBuffer &target) = 0;
  63. virtual int transform(ISocket* targetSocket) = 0;
  64. // Set include source
  65. virtual int setIncludeHandler(IIncludeHandler* handler) = 0;
  66. // createExternalFunction - create a simple external function that processes text (a convenient way to define external functions)
  67. //
  68. virtual IXslFunction* createExternalFunction( const char* pszNameSpace, void (*fn)(StringBuffer& out, const char* pszIn, IXslTransform*)) = 0;
  69. // setExternalFunction - add an external function that can be called from within the XSLT
  70. //
  71. virtual int setExternalFunction( const char* pszNameSpace, IXslFunction*, bool set) = 0;
  72. // getLastError - returns the error, if any, in last transformation, compiling stylesheet or parsing source
  73. //
  74. virtual const char* getLastError() const = 0;
  75. // getMessages - returns the messages produced, if any, in last transformation, compiling stylesheet or parsing source
  76. // The most useful application is to fetch any <xsl:message/> as a result of transformation.
  77. // Note: in case of any errors, any cumulative messages until the error are bundled with the
  78. // message.
  79. //
  80. virtual const char* getMessages() const = 0;
  81. //Allow the caller to set necessary info that can be used to identify it.
  82. //This is typically useful in [static] external functions, which can use
  83. //this info to work with caller/context.
  84. //
  85. virtual void setUserData(void*) = 0;
  86. virtual void* getUserData() const = 0;
  87. };
  88. interface XMLLIB_API IXslProcessor : public IInterface
  89. {
  90. virtual IXslTransform *createXslTransform() = 0;
  91. // execute - runs the transformation placing the results in the specified output location
  92. //
  93. virtual int execute(IXslTransform *pITransform) = 0;
  94. virtual int setDefIncludeHandler(IIncludeHandler* handler)=0;
  95. virtual void setCacheTimeout(int timeout) = 0;
  96. virtual int getCacheTimeout() = 0;
  97. };
  98. extern "C" XMLLIB_API IXslProcessor* getXslProcessor();
  99. #endif