xslprocessor.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef XSLPROCESSOR_HPP_INCL
  14. #define XSLPROCESSOR_HPP_INCL
  15. #include "jliball.hpp"
  16. #include "xmllib.hpp"
  17. class StringBuffer;
  18. #define SEISINT_XSLTEXT_NAMESPACE "http://seisint.com"
  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. virtual int loadXslFromEmbedded(const char *path, const char *cacheId) = 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(IPropertyTree *cfg = nullptr) = 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