xpathprocessor.hpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 XPATH_MANAGER_HPP_
  14. #define XPATH_MANAGER_HPP_
  15. #include "xmllib.hpp"
  16. #include "jliball.hpp"
  17. interface XMLLIB_API ICompiledXpath : public IInterface
  18. {
  19. virtual const char * getXpath() = 0;
  20. virtual void extractReferences(StringArray &functions, StringArray &variables) = 0;
  21. };
  22. interface IXpathContextIterator;
  23. interface XMLLIB_API IXpathContext : public IInterface
  24. {
  25. virtual bool setXmlDoc(const char * xmldoc) = 0;
  26. virtual void setUserData(void *) = 0;
  27. virtual void *getUserData() = 0;
  28. virtual void registerFunction(const char *xmlns, const char * name, void *f) = 0;
  29. virtual void registerNamespace(const char *prefix, const char *uri) = 0;
  30. virtual const char *queryNamespace(const char *prefix) = 0;
  31. virtual void beginScope(const char *name) = 0;
  32. virtual void endScope() = 0;
  33. virtual bool addVariable(const char * name, const char * val) = 0;
  34. virtual bool addXpathVariable(const char * name, const char * xpath) = 0;
  35. virtual bool addCompiledVariable(const char * name, ICompiledXpath * compiled) = 0;
  36. virtual const char * getVariable(const char * name, StringBuffer & variable) = 0;
  37. virtual bool addInputXpath(const char * name, const char * xpath) = 0; //values should be declared as parameters before use, "strict parameter mode" requires it
  38. virtual bool addInputValue(const char * name, const char * value) = 0; //values should be declared as parameters before use, "strict parameter mode" requires it
  39. virtual bool declareParameter(const char * name, const char *value) = 0;
  40. virtual bool declareCompiledParameter(const char * name, ICompiledXpath * compiled) = 0;
  41. virtual void declareRemainingInputs() = 0;
  42. virtual void pushLocation() = 0;
  43. virtual void popLocation() = 0;
  44. virtual bool setLocation(const char *xpath, bool required) = 0;
  45. virtual bool setLocation(ICompiledXpath * compiledXpath, bool required) = 0;
  46. virtual bool ensureLocation(const char *xpath, bool required) = 0;
  47. virtual void addElementToLocation(const char *name) = 0;
  48. virtual void setLocationNamespace(const char *prefix, const char *uri, bool current) = 0;
  49. virtual void ensureSetValue(const char *xpath, const char *value, bool required) = 0;
  50. virtual void ensureAddValue(const char *xpath, const char *value, bool required) = 0;
  51. virtual void ensureAppendToValue(const char *xpath, const char *value, bool required) = 0;
  52. virtual void rename(const char *xpath, const char *name, bool all) = 0;
  53. virtual void remove(const char *xpath, bool all) = 0;
  54. virtual void copyFromPrimaryContext(ICompiledXpath *select, const char *newname) = 0;
  55. virtual bool evaluateAsBoolean(const char * xpath) = 0;
  56. virtual bool evaluateAsString(const char * xpath, StringBuffer & evaluated) = 0;
  57. virtual bool evaluateAsBoolean(ICompiledXpath * compiledXpath) = 0;
  58. virtual const char * evaluateAsString(ICompiledXpath * compiledXpath, StringBuffer & evaluated) = 0;
  59. virtual double evaluateAsNumber(ICompiledXpath * compiledXpath) = 0;
  60. virtual IXpathContextIterator *evaluateAsNodeSet(ICompiledXpath * compiledXpath) = 0;
  61. virtual StringBuffer &toXml(const char *xpath, StringBuffer & xml) = 0;
  62. virtual void addXmlContent(const char *xml) = 0;
  63. };
  64. interface IXpathContextIterator : extends IIteratorOf<IXpathContext> { };
  65. class CXpathContextScope : CInterface
  66. {
  67. private:
  68. Linked<IXpathContext> context;
  69. Linked<IProperties> namespaces;
  70. public:
  71. IMPLEMENT_IINTERFACE;
  72. CXpathContextScope(IXpathContext *ctx, const char *name, IProperties *ns=nullptr) : context(ctx), namespaces(ns)
  73. {
  74. context->beginScope(name);
  75. }
  76. virtual ~CXpathContextScope()
  77. {
  78. if (namespaces)
  79. {
  80. Owned<IPropertyIterator> ns = namespaces->getIterator();
  81. ForEach(*ns)
  82. {
  83. const char *prefix = ns->getPropKey();
  84. const char *uri = namespaces->queryProp(prefix);
  85. context->registerNamespace(prefix, isEmptyString(uri) ? nullptr : uri);
  86. }
  87. }
  88. context->endScope();
  89. }
  90. };
  91. class CXpathContextLocation : CInterface
  92. {
  93. private:
  94. Linked<IXpathContext> context;
  95. public:
  96. IMPLEMENT_IINTERFACE;
  97. CXpathContextLocation(IXpathContext *ctx) : context(ctx)
  98. {
  99. if (context)
  100. context->pushLocation();
  101. }
  102. virtual ~CXpathContextLocation()
  103. {
  104. if (context)
  105. context->popLocation();
  106. }
  107. };
  108. extern "C" XMLLIB_API ICompiledXpath* compileXpath(const char * xpath);
  109. extern "C" XMLLIB_API IXpathContext* getXpathContext(const char * xmldoc, bool strictParameterDeclaration, bool removeDocNamespaces);
  110. #define ESDLScriptCtxSection_Store "store"
  111. #define ESDLScriptCtxSection_Logging "logging"
  112. #define ESDLScriptCtxSection_LogData "logdata"
  113. #define ESDLScriptCtxSection_TargetConfig "target"
  114. #define ESDLScriptCtxSection_BindingConfig "config"
  115. #define ESDLScriptCtxSection_ESDLInfo "esdl"
  116. #define ESDLScriptCtxSection_ESDLRequest "esdl_request"
  117. #define ESDLScriptCtxSection_FinalRequest "final_request"
  118. #define ESDLScriptCtxSection_InitialResponse "initial_response"
  119. #define ESDLScriptCtxSection_PreESDLResponse "pre_esdl_response"
  120. interface IEsdlScriptContext : extends IInterface
  121. {
  122. virtual IXpathContext* createXpathContext(IXpathContext *parent, const char *section, bool strictParameterDeclaration) = 0;
  123. virtual IXpathContext *getCopiedSectionXpathContext(IXpathContext *parent, const char *tgtSection, const char *srcSection, bool strictParameterDeclaration) = 0;
  124. virtual void *queryEspContext() = 0;
  125. virtual void setContent(const char *section, const char *xml) = 0;
  126. virtual void appendContent(const char *section, const char *name, const char *xml) = 0;
  127. virtual void setContent(const char *section, IPropertyTree *tree) = 0;
  128. virtual bool tokenize(const char *str, const char *delimeters, StringBuffer &resultPath) = 0;
  129. virtual void setAttribute(const char *section, const char *name, const char *value) = 0;
  130. virtual const char *queryAttribute(const char *section, const char *name) = 0;
  131. virtual const char *getAttribute(const char *section, const char *name, StringBuffer &s) = 0;
  132. virtual const char *getXPathString(const char *xpath, StringBuffer &s) const = 0;
  133. virtual __int64 getXPathInt64(const char *xpath, __int64 dft=0) const = 0;
  134. virtual bool getXPathBool(const char *xpath, bool dft=false) const = 0;
  135. virtual void toXML(StringBuffer &xml, const char *section, bool includeParentNode=false) = 0;
  136. virtual void toXML(StringBuffer &xml) = 0;
  137. virtual IPropertyTree *createPTreeFromSection(const char *section) = 0;
  138. virtual void cleanupBetweenScripts() = 0;
  139. };
  140. extern "C" XMLLIB_API IEsdlScriptContext *createEsdlScriptContext(void * espContext);
  141. #endif /* XPATH_MANAGER_HPP_ */