file_cache.xsl 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:exslt="http://exslt.org/common"
  5. xmlns:dyn="http://saxon.sf.net/"
  6. xmlns:uuid="java:java.util.UUID"
  7. xmlns:http="http://expath.org/ns/http-client"
  8. exclude-result-prefixes="xs exslt dyn uuid http"
  9. version="2.0">
  10. <!-- @2017-02 bindera to powinno byc zamienione na korzystanie z API zamiennie z ant i dociaganie danych -->
  11. <!-- authBasicHeader - base64 for basic auth
  12. example:
  13. bash: echo -n "$username:$passwd" | base64
  14. php: echo base64_encode("{$username}:{$password}");
  15. -->
  16. <xsl:param name="authBasicHeader" select="'xxxx'"/>
  17. <xsl:template name="file_cache">
  18. <!-- Template zczytujacy dane z URLa i zapisujacy je pod FILE_URL - w razie potrzeby czyta z cache a w innym przypadku odswieza
  19. importowany np. przez import_resource_table_xml_from_api.xsl
  20. -->
  21. <xsl:param name="cache"/> <!-- read | refresh -->
  22. <xsl:param name="URL"/>
  23. <xsl:param name="FILE_URL" select="concat('../default_db.instance.xml/',$URL)"/>
  24. <xsl:param name="INSERT_OBJ"/> <!-- xml z zawartoscia obiektu do wgrania np. @system_cache__appinfo:ID, @system_cache__appinfo:PARENT_ID, @system_cache__appinfo:VALUE , @system_cache__appinfo:REMOTE_ID -->
  25. <xsl:param name="xpath"/> <!-- to filter results in xpath - optional -->
  26. <xsl:param name="uuid"/>
  27. <xsl:message>Bede dzialac z URL:<xsl:value-of select="$URL"/> authHeader:<xsl:value-of select="$authBasicHeader"/></xsl:message>
  28. <xsl:choose>
  29. <!-- @2015-11-19 opcja wylaczona z uwagi na niepoprawne dzialanie expath, dla testowania innych funkcji na silniku SAXON EE-->
  30. <!--<xsl:when test="$cache='refresh' or ( not(unparsed-text-available($FILE_URL)))">
  31. <xsl:message>Laduje swieze dane z API:<xsl:value-of select="$URL"/>; do pliku <xsl:value-of select="$FILE_URL"/></xsl:message>
  32. <xsl:variable name="req" as="element()">
  33. <http:request href="{concat($URL,'/items?handle=',$uuid)}" method="put">
  34. <http:header name="Authorization" value="Basic { $authBasicHeader }" />
  35. </http:request>
  36. </xsl:variable>
  37. <xsl:variable name="resp" select="http:send-request($req)"/>
  38. <xsl:result-document href="{$FILE_URL}">
  39. <xsl:copy-of select="$resp[2]" copy-namespaces="no"/>
  40. </xsl:result-document>
  41. <xsl:choose>
  42. <xsl:when test="$xpath">
  43. <xsl:message terminate="yes">dyn:evaluate option are disabled - do not use them!!!</xsl:message>
  44. <!-\-<xsl:copy-of select="$SCHEMA/dyn:evaluate($xpath)"/>-\->
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <xsl:copy-of select="$resp[2]" copy-namespaces="no"/>
  48. </xsl:otherwise>
  49. </xsl:choose>
  50. </xsl:when>
  51. <xsl:when test="$cache='write'">
  52. <xsl:message>57: Zapisuje XML do bazy danych <xsl:value-of select="concat($URL,'/newitem?handle=',$uuid)"/></xsl:message>
  53. <xsl:message> authBasicHeader aktualny:<xsl:value-of select="$authBasicHeader"/></xsl:message>
  54. <xsl:variable name="req" as="element()">
  55. <http:request href="{concat($URL,'/newitem?handle=',$uuid)}" method="put">
  56. <http:header name="Authorization" value="Basic { $authBasicHeader }" />
  57. <http:body media-type="application/xml" method="xml" omit-xml-declaration="yes">
  58. <xsl:copy-of select="$INSERT_OBJ" copy-namespaces="no" exclude-result-prefixes="http"/>
  59. </http:body>
  60. </http:request>
  61. </xsl:variable>
  62. <xsl:variable name="resp" select="http:send-request($req)"/>
  63. <xsl:message>63: response body : <xsl:copy-of select="$resp"/></xsl:message>
  64. <xsl:copy-of select="$resp[2]" copy-namespaces="no"/>
  65. </xsl:when>-->
  66. <xsl:when test="1=2"/>
  67. <xsl:otherwise>
  68. <xsl:choose>
  69. <xsl:when test="$xpath">
  70. <xsl:message terminate="yes"> Opcja xpath w przygotowaniu dla xpath <xsl:value-of select="concat($FILE_URL,$xpath)"/></xsl:message>
  71. <xsl:message>Laduje istniejacy plik schematow z <xsl:value-of select="concat($FILE_URL,$xpath)"/> z xpath <xsl:value-of select="$xpath"/></xsl:message>
  72. <!--<xsl:copy-of select="document($FILE_URL)/dyn:evaluate($xpath)"/>-->
  73. </xsl:when>
  74. <xsl:otherwise>
  75. <xsl:message>Laduje istniejacy plik <xsl:value-of select="$FILE_URL"/></xsl:message>
  76. <xsl:copy-of select="document($FILE_URL)"/>
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:otherwise>
  80. </xsl:choose>
  81. </xsl:template>
  82. </xsl:stylesheet>