2012-04-12 09:19:46 +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="data" type="input"/>
|
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- Look if the resource has already been archived for that set -->
|
2012-04-12 09:19:46 +00:00
|
|
|
<p:processor name="oxf:pipeline">
|
2012-04-13 09:16:40 +00:00
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>
|
|
|
|
<xsl:value-of select="/action/@directory"/>
|
2012-04-13 11:05:25 +00:00
|
|
|
<xsl:text>index.xml</xsl:text>
|
2012-04-12 09:19:46 +00:00
|
|
|
</relpath>
|
2012-04-13 11:05:25 +00:00
|
|
|
<operation>read</operation>
|
|
|
|
<type>xquery</type>
|
|
|
|
<parameter name="url" type="string">
|
|
|
|
<xsl:value-of select="/action/@url"/>
|
|
|
|
</parameter>
|
2012-04-12 09:19:46 +00:00
|
|
|
</config>
|
|
|
|
</p:input>
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:input name="param">
|
|
|
|
<xquery><![CDATA[
|
|
|
|
|
|
|
|
boolean(//archive[@url = $(url)])
|
|
|
|
|
|
|
|
]]></xquery>
|
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="duplicate" debug="duplicate"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
</p:processor>
|
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:choose href="#duplicate">
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:when test="/*/* = 'true'">
|
|
|
|
<!-- Already archived, nothing to do -->
|
|
|
|
<!-- Update the queue -->
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>queue.xml</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>xquery</type>
|
|
|
|
<parameter name="uuid" type="string">
|
|
|
|
<xsl:value-of select="/action/@uuid"/>
|
|
|
|
</parameter>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="param">
|
|
|
|
<xquery><![CDATA[
|
|
|
|
|
|
|
|
for $a in /queue/action where $a/@uuid = $(uuid) return
|
|
|
|
update
|
|
|
|
delete $a
|
|
|
|
|
|
|
|
]]></xquery>
|
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="response4" debug="response"/>
|
|
|
|
</p:processor>
|
|
|
|
<p:processor name="oxf:null-serializer">
|
|
|
|
<p:input name="data" href="#response4"/>
|
|
|
|
</p:processor>
|
|
|
|
</p:when>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:otherwise>
|
|
|
|
<!-- Otherwise, archive the resource... -->
|
|
|
|
<!-- Fetch the resource -->
|
2012-04-12 09:19:46 +00:00
|
|
|
<p:processor name="oxf:url-generator">
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:input name="config" transform="oxf:xslt" href="#data">
|
2012-04-12 09:19:46 +00:00
|
|
|
<config xsl:version="2.0">
|
|
|
|
<url>
|
2012-04-13 11:05:25 +00:00
|
|
|
<xsl:value-of select="/action/@url"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
</url>
|
2012-04-13 11:05:25 +00:00
|
|
|
<header>
|
|
|
|
<name>User-Agent</name>
|
|
|
|
<value>
|
|
|
|
<xsl:value-of select="doc('oxf:/config.xml')/config/user-agent"/>
|
|
|
|
</value>
|
|
|
|
</header>
|
|
|
|
<mode>archive</mode>
|
2012-04-12 09:19:46 +00:00
|
|
|
</config>
|
|
|
|
</p:input>
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:output name="data" id="archive" debug="archive"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- Store the archive in the database -->
|
2012-04-12 09:19:46 +00:00
|
|
|
<p:processor name="oxf:pipeline">
|
2012-04-13 09:16:40 +00:00
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>
|
|
|
|
<xsl:value-of select="/action/@directory"/>
|
|
|
|
<xsl:value-of select="/action/@filename"/>
|
|
|
|
</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>document</type>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:input name="param" href="#archive"/>
|
|
|
|
<p:output name="data" id="response2"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
</p:processor>
|
2012-04-13 11:05:25 +00:00
|
|
|
|
2012-04-12 09:19:46 +00:00
|
|
|
<p:processor name="oxf:null-serializer">
|
2012-04-13 11:05:25 +00:00
|
|
|
<p:input name="data" href="#response2"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- Test the type of document to see if it needs to be rewritten -->
|
|
|
|
<p:choose href="#archive">
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- HTML document : need to update the links... -->
|
|
|
|
<p:when test="/archive/response/document/@content-type=('text/html', 'text/css')">
|
|
|
|
|
|
|
|
<!-- Call the corresponding pipeline to extract the links and rewrite them -->
|
|
|
|
<p:processor name="oxf:url-generator">
|
|
|
|
<p:input name="config" transform="oxf:xslt" href="#archive">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<url>
|
|
|
|
<xsl:text>oxf:/actions/mediatypes/</xsl:text>
|
|
|
|
<xsl:value-of select="substring-after(/archive/response/document/@content-type, '/')"/>
|
|
|
|
<xsl:text>.xpl</xsl:text>
|
|
|
|
</url>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="pipeline"/>
|
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="#pipeline"/>
|
|
|
|
<p:input name="archive" href="#archive"/>
|
|
|
|
<p:output name="rewritten" id="rewritten"/>
|
|
|
|
<p:output name="links" id="links"/>
|
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Store the rewritten document in the database -->
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>
|
|
|
|
<xsl:value-of select="/action/@directory"/>
|
|
|
|
<xsl:text>rewritten-</xsl:text>
|
|
|
|
<xsl:value-of select="/action/@filename"/>
|
|
|
|
</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>document</type>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="param" href="#rewritten"/>
|
|
|
|
<p:output name="data" id="response3"/>
|
|
|
|
</p:processor>
|
|
|
|
<p:processor name="oxf:null-serializer">
|
|
|
|
<p:input name="data" href="#response3"/>
|
|
|
|
</p:processor>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Update the archive index -->
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>
|
|
|
|
<xsl:value-of select="/action/@directory"/>
|
|
|
|
<xsl:text>index.xml</xsl:text>
|
|
|
|
</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>xquery</type>
|
|
|
|
<parameter name="url" type="string">
|
|
|
|
<xsl:value-of select="/action/@url"/>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="filename" type="string">
|
|
|
|
<xsl:value-of select="/action/@filename"/>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="filename-rewritten" type="string">
|
|
|
|
<xsl:text>rewritten-</xsl:text>
|
|
|
|
<xsl:value-of select="/action/@filename"/>
|
|
|
|
</parameter>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="param">
|
|
|
|
<xquery><![CDATA[
|
2012-04-12 09:19:46 +00:00
|
|
|
for $as in /archive-set
|
|
|
|
return
|
|
|
|
update
|
2012-04-12 10:42:55 +00:00
|
|
|
insert <archive url=$(url) href=$(filename) href-rewritten=$(filename-rewritten) dateTime="{current-dateTime()}"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
into $as
|
|
|
|
]]></xquery>
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="response1"/>
|
|
|
|
</p:processor>
|
|
|
|
<p:processor name="oxf:null-serializer">
|
|
|
|
<p:input name="data" href="#response1"/>
|
|
|
|
</p:processor>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- Update the queue -->
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
|
|
|
<p:input name="data" transform="oxf:xslt" href="aggregate('root', #data, #links)">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>queue.xml</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>xquery</type>
|
|
|
|
<parameter name="directory" type="string">
|
|
|
|
<xsl:value-of select="/root/action/@directory"/>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="uuid" type="string">
|
|
|
|
<xsl:value-of select="/root/action/@uuid"/>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="priority" type="string">
|
|
|
|
<xsl:value-of select="/root/action/@priority"/>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="links" type="node-set">
|
|
|
|
<xsl:copy-of select="/root/links"/>
|
|
|
|
</parameter>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="param">
|
|
|
|
<xquery><![CDATA[
|
2012-04-12 09:19:46 +00:00
|
|
|
declare namespace util = "http://exist-db.org/xquery/util";
|
|
|
|
declare variable $links := $(links);
|
|
|
|
|
2012-04-13 09:58:38 +00:00
|
|
|
for $q in /queue[$links/link/@abs-href]
|
|
|
|
return
|
2012-04-12 09:19:46 +00:00
|
|
|
update
|
|
|
|
insert
|
|
|
|
for $href in distinct-values($links/link/@abs-href)
|
|
|
|
let $link := $links/link[@abs-href = $href][1]
|
2012-04-12 12:06:23 +00:00
|
|
|
return <action priority=$(priority) uuid="{util:uuid()}" type="archive-resource" url="{$link/@abs-href}" directory=$(directory) filename="{$link/@filename}"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
into $q,
|
|
|
|
|
|
|
|
for $a in /queue/action where $a/@uuid = $(uuid) return
|
|
|
|
update
|
|
|
|
delete $a
|
|
|
|
|
|
|
|
]]></xquery>
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="response4" debug="response"/>
|
|
|
|
</p:processor>
|
|
|
|
<p:processor name="oxf:null-serializer">
|
|
|
|
<p:input name="data" href="#response4"/>
|
|
|
|
</p:processor>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:when>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- Otherwise: no need to rewrite -->
|
|
|
|
<p:otherwise>
|
|
|
|
<!-- Update the archive index -->
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>
|
|
|
|
<xsl:value-of select="/action/@directory"/>
|
|
|
|
<xsl:text>index.xml</xsl:text>
|
|
|
|
</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>xquery</type>
|
|
|
|
<parameter name="url" type="string">
|
|
|
|
<xsl:value-of select="/action/@url"/>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="filename" type="string">
|
|
|
|
<xsl:value-of select="/action/@filename"/>
|
|
|
|
</parameter>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="param">
|
|
|
|
<xquery><![CDATA[
|
2012-04-12 09:19:46 +00:00
|
|
|
for $as in /archive-set
|
|
|
|
return
|
|
|
|
update
|
2012-04-12 10:42:55 +00:00
|
|
|
insert <archive url=$(url) href=$(filename) dateTime="{current-dateTime()}"/>
|
2012-04-12 09:19:46 +00:00
|
|
|
into $as
|
|
|
|
]]></xquery>
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="response1"/>
|
|
|
|
</p:processor>
|
|
|
|
<p:processor name="oxf:null-serializer">
|
|
|
|
<p:input name="data" href="#response1"/>
|
|
|
|
</p:processor>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
<!-- Update the queue -->
|
|
|
|
<p:processor name="oxf:pipeline">
|
|
|
|
<p:input name="config" href="/data-access.xpl"/>
|
|
|
|
<p:input name="data" transform="oxf:xslt" href="#data">
|
|
|
|
<config xsl:version="2.0">
|
|
|
|
<relpath>queue.xml</relpath>
|
|
|
|
<operation>write</operation>
|
|
|
|
<type>xquery</type>
|
|
|
|
<parameter name="uuid" type="string">
|
|
|
|
<xsl:value-of select="/action/@uuid"/>
|
|
|
|
</parameter>
|
|
|
|
</config>
|
|
|
|
</p:input>
|
|
|
|
<p:input name="param">
|
|
|
|
<xquery><![CDATA[
|
|
|
|
|
2012-04-12 09:19:46 +00:00
|
|
|
for $a in /queue/action where $a/@uuid = $(uuid) return
|
|
|
|
update
|
|
|
|
delete $a
|
|
|
|
|
|
|
|
]]></xquery>
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:input>
|
|
|
|
<p:output name="data" id="response4" debug="response"/>
|
|
|
|
</p:processor>
|
|
|
|
<p:processor name="oxf:null-serializer">
|
|
|
|
<p:input name="data" href="#response4"/>
|
|
|
|
</p:processor>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:otherwise>
|
2012-04-12 09:19:46 +00:00
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
</p:choose>
|
|
|
|
</p:otherwise>
|
2012-04-12 09:19:46 +00:00
|
|
|
</p:choose>
|
|
|
|
|
2012-04-13 11:05:25 +00:00
|
|
|
|
|
|
|
|
2012-04-12 09:19:46 +00:00
|
|
|
</p:config>
|