source: archiver/pipelines/actions/archive-resource.xpl @ 16cc943

Revision 16cc943, 8.7 KB checked in by Eric van der Vlist <vdv@dyomedea.com>, 13 months ago (diff)

Refactoring before supporting CSS

  • Property mode set to 100644
Line 
1<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/">
2
3  <p:param name="data" type="input"/>
4
5  <!-- Fetch the resource -->
6  <p:processor name="oxf:url-generator">
7    <p:input name="config" transform="oxf:xslt" href="#data">
8      <config xsl:version="2.0">
9        <url>
10          <xsl:value-of select="/action/@url"/>
11        </url>
12        <header>
13          <name>User-Agent</name>
14          <value>
15            <xsl:value-of select="doc('oxf:/config.xml')/config/user-agent"/>
16          </value>
17        </header>
18        <mode>archive</mode>
19      </config>
20    </p:input>
21    <p:output name="data" id="archive" debug="archive"/>
22  </p:processor>
23
24
25  <!-- Store the archive in the database -->
26  <p:processor name="oxf:pipeline">
27    <p:input name="config" href="/data-access.xpl"/>
28    <p:input name="data" transform="oxf:xslt" href="#data">
29      <config xsl:version="2.0">
30        <relpath>
31          <xsl:value-of select="/action/@directory"/>
32          <xsl:value-of select="/action/@filename"/>
33        </relpath>
34        <operation>write</operation>
35        <type>document</type>
36      </config>
37    </p:input>
38    <p:input name="param" href="#archive"/>
39    <p:output name="data" id="response2"/>
40  </p:processor>
41
42  <p:processor name="oxf:null-serializer">
43    <p:input name="data" href="#response2"/>
44  </p:processor>
45
46
47  <!-- Test the type of document to see if it needs to be rewritten -->
48  <p:choose href="#archive">
49
50    <!-- HTML document : need to update the links... -->
51    <p:when test="/archive/response/document/@content-type=('text/html')">
52
53      <!-- Call the corresponding pipeline to extract the links and rewrite them -->
54      <p:processor name="oxf:url-generator">
55        <p:input name="config" transform="oxf:xslt" href="#archive">
56          <config xsl:version="2.0">
57            <url>
58              <xsl:text>oxf:/actions/mediatypes/</xsl:text>
59              <xsl:value-of select="substring-after(/archive/response/document/@content-type, '/')"/>
60              <xsl:text>.xpl</xsl:text>
61            </url>
62          </config>
63        </p:input>
64        <p:output name="data" id="pipeline"/>
65      </p:processor>
66
67      <p:processor name="oxf:pipeline">
68        <p:input name="config" href="#pipeline"/>
69        <p:input name="archive" href="#archive"/>
70        <p:output name="rewritten" id="rewritten"/>
71        <p:output name="links" id="links"/>
72      </p:processor>
73
74
75      <!-- Store the rewritten document in the database -->
76      <p:processor name="oxf:pipeline">
77        <p:input name="config" href="/data-access.xpl"/>
78        <p:input name="data" transform="oxf:xslt" href="#data">
79          <config xsl:version="2.0">
80            <relpath>
81              <xsl:value-of select="/action/@directory"/>
82              <xsl:text>rewritten-</xsl:text>
83              <xsl:value-of select="/action/@filename"/>
84            </relpath>
85            <operation>write</operation>
86            <type>document</type>
87          </config>
88        </p:input>
89        <p:input name="param" href="#rewritten"/>
90        <p:output name="data" id="response3"/>
91      </p:processor>
92      <p:processor name="oxf:null-serializer">
93        <p:input name="data" href="#response3"/>
94      </p:processor>
95
96
97
98      <!-- Update the archive index -->
99      <p:processor name="oxf:pipeline">
100        <p:input name="config" href="/data-access.xpl"/>
101        <p:input name="data" transform="oxf:xslt" href="#data">
102          <config xsl:version="2.0">
103            <relpath>
104              <xsl:value-of select="/action/@directory"/>
105              <xsl:text>index.xml</xsl:text>
106            </relpath>
107            <operation>write</operation>
108            <type>xquery</type>
109            <parameter name="url" type="string">
110              <xsl:value-of select="/action/@url"/>
111            </parameter>
112            <parameter name="filename" type="string">
113              <xsl:value-of select="/action/@filename"/>
114            </parameter>
115            <parameter name="filename-rewritten" type="string">
116              <xsl:text>rewritten-</xsl:text>
117              <xsl:value-of select="/action/@filename"/>
118            </parameter>
119          </config>
120        </p:input>
121        <p:input name="param">
122          <xquery><![CDATA[
123for $as in /archive-set
124    return
125      update
126        insert <archive url=$(url) href=$(filename) href-rewritten=$(filename-rewritten) dateTime="{current-dateTime()}"/>
127        into $as               
128                ]]></xquery>
129        </p:input>
130        <p:output name="data" id="response1"/>
131      </p:processor>
132      <p:processor name="oxf:null-serializer">
133        <p:input name="data" href="#response1"/>
134      </p:processor>
135
136      <!-- Update the queue -->
137      <p:processor name="oxf:pipeline">
138        <p:input name="config" href="/data-access.xpl"/>
139        <p:input name="data" transform="oxf:xslt" href="aggregate('root', #data, #links)">
140          <config xsl:version="2.0">
141            <relpath>queue.xml</relpath>
142            <operation>write</operation>
143            <type>xquery</type>
144            <parameter name="directory" type="string">
145              <xsl:value-of select="/root/action/@directory"/>
146            </parameter>
147            <parameter name="uuid" type="string">
148              <xsl:value-of select="/root/action/@uuid"/>
149            </parameter>
150            <parameter name="priority" type="string">
151              <xsl:value-of select="/root/action/@priority"/>
152            </parameter>
153            <parameter name="links" type="node-set">
154              <xsl:copy-of select="/root/links"/>
155            </parameter>
156          </config>
157        </p:input>
158        <p:input name="param">
159          <xquery><![CDATA[
160declare namespace util = "http://exist-db.org/xquery/util";
161declare variable $links := $(links);
162
163for $q in /queue return
164    update
165        insert
166          for $href in distinct-values($links/link/@abs-href)
167            let $link := $links/link[@abs-href = $href][1]
168            return <action priority=$(priority) uuid="{util:uuid()}" type="archive-resource" url="{$link/@abs-href}" directory=$(directory) filename="{$link/@filename}"/>
169        into $q,
170       
171for $a in /queue/action where $a/@uuid = $(uuid) return
172    update
173        delete $a
174       
175                ]]></xquery>
176        </p:input>
177        <p:output name="data" id="response4" debug="response"/>
178      </p:processor>
179      <p:processor name="oxf:null-serializer">
180        <p:input name="data" href="#response4"/>
181      </p:processor>
182
183
184    </p:when>
185
186    <!-- Otherwise: no need to rewrite -->
187    <p:otherwise>
188      <!-- Update the archive index -->
189      <p:processor name="oxf:pipeline">
190        <p:input name="config" href="/data-access.xpl"/>
191        <p:input name="data" transform="oxf:xslt" href="#data">
192          <config xsl:version="2.0">
193            <relpath>
194              <xsl:value-of select="/action/@directory"/>
195              <xsl:text>index.xml</xsl:text>
196            </relpath>
197            <operation>write</operation>
198            <type>xquery</type>
199            <parameter name="url" type="string">
200              <xsl:value-of select="/action/@url"/>
201            </parameter>
202            <parameter name="filename" type="string">
203              <xsl:value-of select="/action/@filename"/>
204            </parameter>
205          </config>
206        </p:input>
207        <p:input name="param">
208          <xquery><![CDATA[
209for $as in /archive-set
210    return
211      update
212        insert <archive url=$(url) href=$(filename) dateTime="{current-dateTime()}"/>
213        into $as               
214                ]]></xquery>
215        </p:input>
216        <p:output name="data" id="response1"/>
217      </p:processor>
218      <p:processor name="oxf:null-serializer">
219        <p:input name="data" href="#response1"/>
220      </p:processor>
221
222      <!-- Update the queue -->
223      <p:processor name="oxf:pipeline">
224        <p:input name="config" href="/data-access.xpl"/>
225        <p:input name="data" transform="oxf:xslt" href="#data">
226          <config xsl:version="2.0">
227            <relpath>queue.xml</relpath>
228            <operation>write</operation>
229            <type>xquery</type>
230            <parameter name="uuid" type="string">
231              <xsl:value-of select="/action/@uuid"/>
232            </parameter>
233          </config>
234        </p:input>
235        <p:input name="param">
236          <xquery><![CDATA[
237
238for $a in /queue/action where $a/@uuid = $(uuid) return
239    update
240        delete $a
241       
242                ]]></xquery>
243        </p:input>
244        <p:output name="data" id="response4" debug="response"/>
245      </p:processor>
246      <p:processor name="oxf:null-serializer">
247        <p:input name="data" href="#response4"/>
248      </p:processor>
249
250    </p:otherwise>
251
252  </p:choose>
253
254</p:config>
Note: See TracBrowser for help on using the repository browser.