2012-04-13 09:58:38 +00:00
|
|
|
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">
|
|
|
|
|
|
|
|
<p:param name="archive" type="input"/>
|
|
|
|
<p:param name="rewritten" type="output"/>
|
|
|
|
<p:param name="links" type="output"/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Store the document -->
|
|
|
|
<p:processor name="oxf:file-serializer">
|
|
|
|
<p:input name="config">
|
|
|
|
<config>
|
|
|
|
<scope>session</scope>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="data" href="#archive#xpointer(/archive/response/document)"/>
|
|
|
|
<p:output name="data" id="url-written"/>
|
|
|
|
</p:processor>
|
|
|
|
|
2012-04-13 10:27:04 +00:00
|
|
|
<!-- And read it as CSS -->
|
2012-04-13 09:58:38 +00:00
|
|
|
<p:processor name="oxf:url-generator">
|
|
|
|
<p:input name="config" transform="oxf:xslt" href="#url-written">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<url>
|
|
|
|
<xsl:value-of select="/*"/>
|
|
|
|
</url>
|
2012-04-13 17:08:04 +00:00
|
|
|
<content-type>text/css</content-type>
|
2012-04-13 09:58:38 +00:00
|
|
|
<mode>text</mode>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="css" debug="css"/>
|
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
<!-- Get a list of links to update -->
|
|
|
|
<!-- TODO: support links in inline CSS -->
|
|
|
|
<!-- TODO: support iframes and objects -->
|
|
|
|
<p:processor name="oxf:unsafe-xslt">
|
|
|
|
<p:input name="data" href="#css"/>
|
|
|
|
<p:input name="request" href="#archive#xpointer(/archive/request)"/>
|
|
|
|
<p:input name="config">
|
|
|
|
<xsl:stylesheet version="2.0">
|
|
|
|
<xsl:variable name="base" select="doc('input:request')/request/location"/>
|
|
|
|
<xsl:template match="/">
|
|
|
|
<links>
|
|
|
|
<xsl:variable name="links" as="node()*">
|
2012-04-13 10:27:04 +00:00
|
|
|
<xsl:analyze-string select="document" regex="url\(["']?([^)'"]+)["']?\)" flags="">
|
|
|
|
<xsl:matching-substring>
|
|
|
|
<link href="{regex-group(1)}"/>
|
|
|
|
</xsl:matching-substring>
|
|
|
|
</xsl:analyze-string>
|
2012-04-13 09:58:38 +00:00
|
|
|
</xsl:variable>
|
|
|
|
<xsl:for-each-group select="$links" group-by="@href">
|
|
|
|
<xsl:variable name="abs-href" select="resolve-uri(@href, $base)"/>
|
|
|
|
<xsl:variable name="tokens" select="tokenize($abs-href, '/')"/>
|
|
|
|
<xsl:variable name="last-token" select="$tokens[last()]"/>
|
|
|
|
<xsl:variable name="tokens2" select="tokenize($last-token, '\.')"/>
|
|
|
|
<xsl:variable name="extension" select="$tokens2[last()]"/>
|
|
|
|
<link abs-href="{$abs-href}" new-href="{saxon:string-to-hexBinary(substring($abs-href, 1, string-length($abs-href) - string-length($extension) - 1), 'utf-8')}.{$extension}"
|
|
|
|
filename="{saxon:string-to-hexBinary($abs-href, 'utf-8')}.xml">
|
|
|
|
<xsl:copy-of select="@*"/>
|
|
|
|
</link>
|
|
|
|
</xsl:for-each-group>
|
|
|
|
</links>
|
|
|
|
</xsl:template>
|
|
|
|
</xsl:stylesheet>
|
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="links-local" debug="links"/>
|
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
<p:processor name="oxf:identity">
|
|
|
|
<p:input name="data" href="#links-local"/>
|
|
|
|
<p:output name="data" ref="links"/>
|
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
<!-- Update the links -->
|
|
|
|
<p:processor name="oxf:unsafe-xslt">
|
|
|
|
<p:input name="data" href="#css"/>
|
|
|
|
<p:input name="request" href="#archive#xpointer(/archive/request)"/>
|
|
|
|
<p:input name="links" href="#links-local"/>
|
|
|
|
<p:input name="config">
|
|
|
|
<xsl:stylesheet version="2.0">
|
|
|
|
<xsl:variable name="links" select="doc('input:links')/links"/>
|
|
|
|
<xsl:variable name="base" select="doc('input:request')/request/location"/>
|
|
|
|
<xsl:key name="link" match="link" use="@href"/>
|
2012-04-13 10:27:04 +00:00
|
|
|
<xsl:template match="/document">
|
2012-04-13 09:58:38 +00:00
|
|
|
<xsl:copy>
|
2012-04-13 10:27:04 +00:00
|
|
|
<xsl:copy-of select="@*"/>
|
|
|
|
<xsl:analyze-string select="." regex="url\(["']?([^)'"]+)["']?\)" flags="">
|
|
|
|
<xsl:matching-substring>
|
|
|
|
<xsl:text>url(</xsl:text>
|
|
|
|
<xsl:value-of select="$links/key('link', regex-group(1))/@new-href"/>
|
|
|
|
<xsl:text>)</xsl:text>
|
|
|
|
</xsl:matching-substring>
|
|
|
|
<xsl:non-matching-substring>
|
|
|
|
<xsl:copy-of select="."/>
|
|
|
|
</xsl:non-matching-substring>
|
|
|
|
</xsl:analyze-string>
|
2012-04-13 09:58:38 +00:00
|
|
|
</xsl:copy>
|
|
|
|
</xsl:template>
|
|
|
|
</xsl:stylesheet>
|
|
|
|
</p:input>
|
2012-04-13 17:08:04 +00:00
|
|
|
<p:output name="data" ref="rewritten" debug="rewritten"/>
|
2012-04-13 09:58:38 +00:00
|
|
|
</p:processor>
|
|
|
|
|
2012-04-13 17:08:04 +00:00
|
|
|
|
2012-04-13 09:58:38 +00:00
|
|
|
|
|
|
|
</p:config>
|