| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:exslt="http://exslt.org/common"
- xmlns:dyn="http://saxon.sf.net/"
- xmlns:uuid="java:java.util.UUID"
- xmlns:http="http://expath.org/ns/http-client"
- exclude-result-prefixes="xs exslt dyn uuid http"
- version="2.0">
-
- <!-- @2017-02 bindera to powinno byc zamienione na korzystanie z API zamiennie z ant i dociaganie danych -->
- <!-- authBasicHeader - base64 for basic auth
- example:
- bash: echo -n "$username:$passwd" | base64
- php: echo base64_encode("{$username}:{$password}");
- -->
- <xsl:param name="authBasicHeader" select="'xxxx'"/>
- <xsl:template name="file_cache">
- <!-- Template zczytujacy dane z URLa i zapisujacy je pod FILE_URL - w razie potrzeby czyta z cache a w innym przypadku odswieza
- importowany np. przez import_resource_table_xml_from_api.xsl
- -->
- <xsl:param name="cache"/> <!-- read | refresh -->
- <xsl:param name="URL"/>
- <xsl:param name="FILE_URL" select="concat('../default_db.instance.xml/',$URL)"/>
- <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 -->
- <xsl:param name="xpath"/> <!-- to filter results in xpath - optional -->
- <xsl:param name="uuid"/>
- <xsl:message>Bede dzialac z URL:<xsl:value-of select="$URL"/> authHeader:<xsl:value-of select="$authBasicHeader"/></xsl:message>
- <xsl:choose>
- <!-- @2015-11-19 opcja wylaczona z uwagi na niepoprawne dzialanie expath, dla testowania innych funkcji na silniku SAXON EE-->
- <!--<xsl:when test="$cache='refresh' or ( not(unparsed-text-available($FILE_URL)))">
- <xsl:message>Laduje swieze dane z API:<xsl:value-of select="$URL"/>; do pliku <xsl:value-of select="$FILE_URL"/></xsl:message>
- <xsl:variable name="req" as="element()">
- <http:request href="{concat($URL,'/items?handle=',$uuid)}" method="put">
- <http:header name="Authorization" value="Basic { $authBasicHeader }" />
- </http:request>
- </xsl:variable>
- <xsl:variable name="resp" select="http:send-request($req)"/>
- <xsl:result-document href="{$FILE_URL}">
- <xsl:copy-of select="$resp[2]" copy-namespaces="no"/>
- </xsl:result-document>
- <xsl:choose>
- <xsl:when test="$xpath">
- <xsl:message terminate="yes">dyn:evaluate option are disabled - do not use them!!!</xsl:message>
- <!-\-<xsl:copy-of select="$SCHEMA/dyn:evaluate($xpath)"/>-\->
- </xsl:when>
- <xsl:otherwise>
- <xsl:copy-of select="$resp[2]" copy-namespaces="no"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$cache='write'">
-
- <xsl:message>57: Zapisuje XML do bazy danych <xsl:value-of select="concat($URL,'/newitem?handle=',$uuid)"/></xsl:message>
- <xsl:message> authBasicHeader aktualny:<xsl:value-of select="$authBasicHeader"/></xsl:message>
- <xsl:variable name="req" as="element()">
- <http:request href="{concat($URL,'/newitem?handle=',$uuid)}" method="put">
- <http:header name="Authorization" value="Basic { $authBasicHeader }" />
- <http:body media-type="application/xml" method="xml" omit-xml-declaration="yes">
- <xsl:copy-of select="$INSERT_OBJ" copy-namespaces="no" exclude-result-prefixes="http"/>
- </http:body>
- </http:request>
- </xsl:variable>
-
- <xsl:variable name="resp" select="http:send-request($req)"/>
-
- <xsl:message>63: response body : <xsl:copy-of select="$resp"/></xsl:message>
-
- <xsl:copy-of select="$resp[2]" copy-namespaces="no"/>
-
- </xsl:when>-->
- <xsl:when test="1=2"/>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="$xpath">
- <xsl:message terminate="yes"> Opcja xpath w przygotowaniu dla xpath <xsl:value-of select="concat($FILE_URL,$xpath)"/></xsl:message>
- <xsl:message>Laduje istniejacy plik schematow z <xsl:value-of select="concat($FILE_URL,$xpath)"/> z xpath <xsl:value-of select="$xpath"/></xsl:message>
- <!--<xsl:copy-of select="document($FILE_URL)/dyn:evaluate($xpath)"/>-->
- </xsl:when>
- <xsl:otherwise>
- <xsl:message>Laduje istniejacy plik <xsl:value-of select="$FILE_URL"/></xsl:message>
- <xsl:copy-of select="document($FILE_URL)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- </xsl:stylesheet>
|