source: archiver/pipelines/actions/package-archive.xpl @ 5ac9ea9

Revision 5ac9ea9, 11.2 KB checked in by Eric van der Vlist <vdv@dyomedea.com>, 13 months ago (diff)

Packaging resources that have not been rewritten...

  • 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  <!-- Read the archive index -->
6  <p:processor name="oxf:pipeline">
7    <p:input name="config" href="/data-access.xpl"/>
8    <p:input name="data" transform="oxf:xslt" href="#data">
9      <config xsl:version="2.0">
10        <relpath>
11          <xsl:value-of select="/action/@directory"/>
12          <xsl:text>index.xml</xsl:text>
13        </relpath>
14        <operation>read</operation>
15        <type>document</type>
16      </config>
17    </p:input>
18    <p:input name="param">
19      <empty/>
20    </p:input>
21    <p:output name="data" id="index" debug="index"/>
22  </p:processor>
23
24  <!-- Create a WARC file -->
25  <p:processor name="oxf:file-serializer">
26    <p:input name="config">
27      <config>
28        <scope>request</scope>
29      </config>
30    </p:input>
31    <p:input name="data" transform="oxf:xslt" href="aggregate('root', #index, #data)">
32      <xsl:stylesheet version="2.0">
33        <xsl:import href="warc-lib.xsl"/>
34        <xsl:template match="/">
35          <xsl:variable name="content" as="node()*">
36            <version/>
37            <field>
38              <name>WARC-Type</name>
39              <value>warcinfo</value>
40            </field>
41            <field>
42              <name>WARC-Date</name>
43              <value>
44                <xsl:value-of select="current-dateTime()"/>
45              </value>
46            </field>
47            <field>
48              <name>WARC-Record-ID</name>
49              <value>
50                <xsl:text>&lt;urn:uuid:</xsl:text>
51                <xsl:value-of select="translate(substring(/root/action/@directory, 1, string-length(/root/action/@directory) - 1), '/', '-')"/>
52                <xsl:text>></xsl:text>
53              </value>
54            </field>
55            <field>
56              <name>Content-Type</name>
57              <value>application/warc-fields</value>
58            </field>
59            <!-- TODO: Content-Length: 381 -->
60            <CRLF/>
61            <field>
62              <name>software</name>
63              <value>Owark 0.3 http://owark.org</value>
64            </field>
65            <field>
66              <name>format</name>
67              <value>WARC file version 0.18</value>
68            </field>
69            <CRLF/>
70            <CRLF/>
71            <!--
72             
73             
74software: Heritrix 1.12.0 http://crawler.archive.org
75hostname: crawling017.archive.org
76ip: 207.241.227.234
77isPartOf: testcrawl-20050708
78description: testcrawl with WARC output
79operator: IA_Admin
80http-header-user-agent:
81 Mozilla/5.0 (compatible; heritrix/1.4.0 +http://crawler.archive.org)
82format: WARC file version 0.18
83conformsTo:
84 http://www.archive.org/documents/WarcFileFormat-0.18.html-->
85          </xsl:variable>
86          <document xsl:version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" content-type="text/plain">
87            <xsl:apply-templates select="$content" mode="warc"/>
88          </document>
89        </xsl:template>
90      </xsl:stylesheet>
91    </p:input>
92    <p:output name="data" id="warc" debug="warc"/>
93  </p:processor>
94
95  <!-- Loop over the index to retrieve the documents -->
96
97  <p:for-each href="#index" select="/archive-set/archive" id="files" root="files">
98
99    <!-- Read the document -->
100    <p:processor name="oxf:pipeline">
101      <p:input name="config" href="/data-access.xpl"/>
102      <p:input name="data" transform="oxf:xslt" href="aggregate('root', #data, current())">
103        <config xsl:version="2.0">
104          <relpath>
105            <xsl:value-of select="/root/action/@directory"/>
106            <xsl:value-of select="/root/archive/@href"/>
107          </relpath>
108          <operation>read</operation>
109          <type>document</type>
110        </config>
111      </p:input>
112      <p:input name="param">
113        <empty/>
114      </p:input>
115      <p:output name="data" id="document" debug="document"/>
116    </p:processor>
117
118    <!-- Add the request and start of response records -->
119    <p:processor name="oxf:file-serializer">
120      <p:input name="config" transform="oxf:xslt" href="#warc">
121        <config xsl:version="2.0">
122          <file>
123            <xsl:value-of select="substring-after(/url, 'file:')"/>
124          </file>
125          <make-directories>false</make-directories>
126          <append>true</append>
127        </config>
128      </p:input>
129      <p:input name="data" transform="oxf:xslt" href="#document">
130        <xsl:stylesheet version="2.0">
131          <xsl:import href="warc-lib.xsl"/>
132          <xsl:template match="/">
133            <xsl:variable name="content" as="node()*">
134              <!-- Request -->
135              <version/>
136              <field>
137                <name>WARC-Type</name>
138                <value>request</value>
139              </field>
140              <field>
141                <name>WARC-Target-URI</name>
142                <value>
143                  <xsl:value-of select="/archive/request/location"/>
144                </value>
145              </field>
146              <field>
147                <name>WARC-Date</name>
148                <value>
149                  <!-- TODO: replace that by the archive sate -->
150                  <xsl:value-of select="current-dateTime()"/>
151                </value>
152              </field>
153              <field>
154                <name>WARC-Record-ID</name>
155                <value>
156                  <xsl:text>&lt;urn:uuid:</xsl:text>
157                  <xsl:value-of select="translate(substring(/root/action/@directory, 1, string-length(/root/action/@directory) - 1), '/', '-')"/>
158                  <xsl:text>></xsl:text>
159                </value>
160              </field>
161              <field>
162                <name>Content-Type</name>
163                <value>application/http;msgtype=request</value>
164              </field>
165              <!-- TODO: Content-Length: 381 -->
166              <CRLF/>
167              <xsl:apply-templates select="/archive/request" mode="warc"/>
168              <CRLF/>
169              <CRLF/>
170              <!-- Response -->
171              <version/>
172              <field>
173                <name>WARC-Type</name>
174                <value>response</value>
175              </field>
176              <field>
177                <name>WARC-Target-URI</name>
178                <value>
179                  <xsl:value-of select="/archive/request/location"/>
180                </value>
181              </field>
182              <field>
183                <name>WARC-Date</name>
184                <value>
185                  <!-- TODO: replace that by the archive sate -->
186                  <xsl:value-of select="current-dateTime()"/>
187                </value>
188              </field>
189              <field>
190                <name>WARC-Record-ID</name>
191                <value>
192                  <xsl:text>&lt;urn:uuid:</xsl:text>
193                  <xsl:value-of select="translate(substring(/root/action/@directory, 1, string-length(/root/action/@directory) - 1), '/', '-')"/>
194                  <xsl:text>></xsl:text>
195                </value>
196              </field>
197              <field>
198                <name>Content-Type</name>
199                <value>application/http;msgtype=response</value>
200              </field>
201              <!-- TODO: Content-Length: 381 -->
202              <CRLF/>
203              <xsl:apply-templates select="/archive/response" mode="warc"/>
204              <CRLF/>
205
206            </xsl:variable>
207            <document xsl:version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" content-type="text/plain">
208              <xsl:apply-templates select="$content" mode="warc"/>
209            </document>
210          </xsl:template>
211        </xsl:stylesheet>
212      </p:input>
213    </p:processor>
214
215    <!-- Add the response document to finalize the response record -->
216    <p:processor name="oxf:file-serializer">
217      <p:input name="config" transform="oxf:xslt" href="#warc">
218        <config xsl:version="2.0">
219          <file>
220            <xsl:value-of select="substring-after(/url, 'file:')"/>
221          </file>
222          <make-directories>false</make-directories>
223          <append>true</append>
224        </config>
225      </p:input>
226      <p:input name="data" href="#document#xpointer(/archive/response/document)"/>
227    </p:processor>
228
229    <p:choose href="current()">
230      <p:when test="/archive/@href-rewritten">
231        <p:processor name="oxf:identity">
232          <p:input name="data">
233            <none/>
234          </p:input>
235          <p:output name="data" id="file" debug="file"/>
236        </p:processor>
237      </p:when>
238      <p:otherwise>
239        <!-- Store a copy of the orginal version -->
240        <p:processor name="oxf:file-serializer">
241          <p:input name="config">
242            <config>
243              <scope>request</scope>
244            </config>
245          </p:input>
246          <p:input name="data" href="#document#xpointer(/archive/response/document)"/>
247          <p:output name="data" id="file" debug="file"/>
248        </p:processor>
249      </p:otherwise>
250    </p:choose>
251
252
253
254    <p:processor name="oxf:identity">
255      <p:input name="data" href="aggregate('file', current(), #file)"/>
256      <p:output name="data" ref="files"/>
257    </p:processor>
258
259
260  </p:for-each>
261
262  <p:processor name="oxf:null-serializer">
263    <p:input name="data" href="#files" debug="files"/>
264  </p:processor>
265
266  <p:processor name="oxf:zip">
267    <p:input name="data" transform="oxf:unsafe-xslt" href="aggregate('root', #warc, #files)">
268      <files xsl:version="2.0" file-name="archive.zip">
269        <file name="archive.warc">
270          <xsl:value-of select="/root/url"/>
271        </file>
272        <xsl:for-each select="/root/files/file[url]">
273          <xsl:variable name="tokens" select="tokenize(archive/@url, '/')"/>
274          <xsl:variable name="last-token" select="$tokens[last()]"/>
275          <xsl:variable name="tokens2" select="tokenize($last-token, '\.')"/>
276          <xsl:variable name="extension" select="$tokens2[last()]"/>
277          <file name="rewritten/{saxon:string-to-hexBinary(substring(archive/@url, 1, string-length(archive/@url) - string-length($extension) - 1), 'utf-8')}.{$extension}">
278            <xsl:value-of select="url"/>
279          </file>
280        </xsl:for-each>
281      </files>
282    </p:input>
283    <p:output name="data" id="zip"/>
284  </p:processor>
285
286  <p:processor name="oxf:file-serializer">
287    <p:input name="config">
288      <config>
289        <file>/tmp/archive.zip</file>
290      </config>
291    </p:input>
292    <p:input name="data" href="#zip"/>
293
294  </p:processor>
295
296  <!--
297  <!-\- Update the queue -\->
298  <p:processor name="oxf:pipeline">
299    <p:input name="config" href="/data-access.xpl"/>
300    <p:input name="data" transform="oxf:xslt" href="#data">
301      <config xsl:version="2.0">
302        <relpath>queue.xml</relpath>
303        <operation>write</operation>
304        <type>xquery</type>
305        <parameter name="uuid" type="string">
306          <xsl:value-of select="/action/@uuid"/>
307        </parameter>
308      </config>
309    </p:input>
310    <p:input name="param">
311      <xquery><![CDATA[
312               
313for $a in /queue/action where $a/@uuid = $(uuid) return
314    update
315        delete $a
316       
317                ]]></xquery>
318    </p:input>
319    <p:output name="data" id="response4" debug="response"/>
320  </p:processor>
321  <p:processor name="oxf:null-serializer">
322    <p:input name="data" href="#response4"/>
323  </p:processor>-->
324
325
326</p:config>
Note: See TracBrowser for help on using the repository browser.