|
1
|
|
|
<?php |
|
2
|
|
|
namespace EWW\Dpf\Services; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use EWW\Dpf\Configuration\ClientConfigurationManager; |
|
18
|
|
|
use EWW\Dpf\Domain\Repository\DocumentTypeRepository; |
|
19
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
20
|
|
|
use EWW\Dpf\Services\Transformer\DocumentTransformer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* MetsExporter |
|
24
|
|
|
*/ |
|
25
|
|
|
class MetsExporter |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* clientConfigurationManager |
|
29
|
|
|
* |
|
30
|
|
|
* @var \EWW\Dpf\Configuration\ClientConfigurationManager |
|
31
|
|
|
* @inject |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $clientConfigurationManager; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* documentTypeRepository |
|
37
|
|
|
* |
|
38
|
|
|
* @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $documentTypeRepository = null; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* formData |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $formData = array(); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* files from form |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $files = array(); |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* metsData |
|
57
|
|
|
* |
|
58
|
|
|
* @var DOMDocument |
|
|
|
|
|
|
59
|
|
|
*/ |
|
60
|
|
|
protected $metsData = ''; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* xml data |
|
64
|
|
|
* @var DOMDocument |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $xmlData = ''; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* xml header |
|
70
|
|
|
* @var string |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $xmlHeader = ''; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* xPathXMLGenerator |
|
76
|
|
|
* @var object |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $parser = null; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* ref id counter |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $counter = 0; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* namespaces as string |
|
87
|
|
|
* @var string |
|
88
|
|
|
*/ |
|
89
|
|
|
protected $namespaceString = ''; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* objId |
|
93
|
|
|
* @var string |
|
94
|
|
|
*/ |
|
95
|
|
|
protected $objId = ''; |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Constructor |
|
100
|
|
|
*/ |
|
101
|
|
|
public function __construct() |
|
102
|
|
|
{ |
|
103
|
|
|
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); |
|
104
|
|
|
$this->clientConfigurationManager = $objectManager->get(ClientConfigurationManager::class); |
|
105
|
|
|
|
|
106
|
|
|
$this->documentTypeRepository = $objectManager->get(DocumentTypeRepository::class); |
|
107
|
|
|
|
|
108
|
|
|
$namespaceConfiguration = explode(";",$this->clientConfigurationManager->getNamespaces()); |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
foreach ($namespaceConfiguration as $key => $value) { |
|
112
|
|
|
$namespace = explode("=", $value); |
|
113
|
|
|
$this->namespaceString .= ' xmlns:' . $namespace[0] . '="' . $namespace[1] . '"'; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$this->xmlHeader = '<data' . $this->namespaceString . '></data>'; |
|
117
|
|
|
|
|
118
|
|
|
$this->xmlData = new \DOMDocument(); |
|
|
|
|
|
|
119
|
|
|
$this->xmlData->loadXML($this->xmlHeader); |
|
120
|
|
|
|
|
121
|
|
|
// Parser |
|
122
|
|
|
include_once 'XPathXMLGenerator.php'; |
|
123
|
|
|
|
|
124
|
|
|
$this->parser = new XPathXMLGenerator(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* returns the mods xml string |
|
129
|
|
|
* @return string mods xml |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getXMLData() |
|
132
|
|
|
{ |
|
133
|
|
|
$xml = $this->xmlData->saveXML(); |
|
134
|
|
|
$xml = preg_replace("/eww=\"\d-\d-\d\"/", '${1}${2}${3}', $xml); |
|
135
|
|
|
|
|
136
|
|
|
return $xml; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function transformInputXML($xml) { |
|
140
|
|
|
$docTypeInput = $this->clientConfigurationManager->getTypeXpathInput(); |
|
141
|
|
|
|
|
142
|
|
|
$domDocument = new \DOMDocument(); |
|
143
|
|
|
$domDocument->loadXML($xml); |
|
144
|
|
|
|
|
145
|
|
|
$domXPath = \EWW\Dpf\Helper\XPath::create($domDocument); |
|
146
|
|
|
|
|
147
|
|
|
$domXPath->registerNamespace('mods', "http://www.loc.gov/mods/v3"); |
|
148
|
|
|
$domXPath->registerNamespace('slub', "http://slub-dresden.de/"); |
|
149
|
|
|
$domXPath->registerNamespace('foaf', "http://xmlns.com/foaf/0.1/"); |
|
150
|
|
|
$domXPath->registerNamespace('person', "http://www.w3.org/ns/person#"); |
|
151
|
|
|
$domXPath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); |
|
152
|
|
|
|
|
153
|
|
|
$documentTypeName = $domXPath->query('//' . $docTypeInput)->item(0)->nodeValue; |
|
154
|
|
|
|
|
155
|
|
|
$documentType = $this->documentTypeRepository->findOneByName($documentTypeName); |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
$transformationFile = $documentType->getTransformationFileInput()->current(); |
|
|
|
|
|
|
158
|
|
|
if ($transformationFile != NULL) { |
|
159
|
|
|
$filePath = $transformationFile->getFile()->getOriginalResource()->getIdentifier(); |
|
160
|
|
|
$documentTransformer = new DocumentTransformer(); |
|
161
|
|
|
|
|
162
|
|
|
$transformedXml = $documentTransformer->transform(PATH_site . 'fileadmin' . $filePath, $xml); |
|
163
|
|
|
} else { |
|
164
|
|
|
// return generated xml if no transformation file is present |
|
165
|
|
|
$transformedXml = $xml; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
return $transformedXml; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param $document |
|
173
|
|
|
* @return string The transformed xml |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getTransformedOutputXML($document) |
|
176
|
|
|
{ |
|
177
|
|
|
$documentType = $document->getDocumentType(); |
|
178
|
|
|
$transformationFile = $documentType->getTransformationFileOutput()->current(); |
|
179
|
|
|
if ($transformationFile != NULL) { |
|
180
|
|
|
$filePath = $transformationFile->getFile()->getOriginalResource()->getIdentifier(); |
|
181
|
|
|
$documentTransformer = new DocumentTransformer(); |
|
182
|
|
|
|
|
183
|
|
|
$transformedXml = $documentTransformer->transform(PATH_site . 'fileadmin' . $filePath, $this->getXMLData()); |
|
184
|
|
|
} else { |
|
185
|
|
|
// return generated xml if no transformation file is present |
|
186
|
|
|
$transformedXml = $this->getXMLData(); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
return $transformedXml; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* build mods from form array |
|
195
|
|
|
* @param array $array structured form data array |
|
196
|
|
|
*/ |
|
197
|
|
|
public function buildXmlFromForm($array) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->xmlData = $this->xmlData; |
|
200
|
|
|
// Build xml mods from form fields |
|
201
|
|
|
// loop each group |
|
202
|
|
|
foreach ($array['metadata'] as $key => $group) { |
|
203
|
|
|
//groups |
|
204
|
|
|
$mapping = $group['mapping']; |
|
205
|
|
|
|
|
206
|
|
|
$values = $group['values']; |
|
207
|
|
|
$attributes = $group['attributes']; |
|
208
|
|
|
|
|
209
|
|
|
$attributeXPath = ''; |
|
210
|
|
|
foreach ($attributes as $attribute) { |
|
211
|
|
|
$attributeXPath .= '[' . $attribute['mapping'] . '="' . $attribute['value'] . '"]'; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
$i = 0; |
|
215
|
|
|
// loop each object |
|
216
|
|
|
if (!empty($values)) { |
|
217
|
|
|
foreach ($values as $value) { |
|
218
|
|
|
$path = $mapping . $attributeXPath . '%/' . $value['mapping']; |
|
219
|
|
|
|
|
220
|
|
|
if ($i == 0) { |
|
221
|
|
|
$newGroupFlag = true; |
|
222
|
|
|
} else { |
|
223
|
|
|
$newGroupFlag = false; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
$xml = $this->customXPath($path, $newGroupFlag, $value['value']); |
|
|
|
|
|
|
227
|
|
|
$i++; |
|
228
|
|
|
|
|
229
|
|
|
} |
|
230
|
|
|
} else { |
|
231
|
|
|
if (!empty($attributeXPath)) { |
|
232
|
|
|
$path = $mapping . $attributeXPath; |
|
233
|
|
|
$xml = $this->customXPath($path, true, '', true); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
$this->files = $array['files']; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* get xml from xpath |
|
243
|
|
|
* @param xpath $xPath xPath expression |
|
244
|
|
|
* @return xml |
|
|
|
|
|
|
245
|
|
|
*/ |
|
246
|
|
|
public function parseXPath($xPath) |
|
247
|
|
|
{ |
|
248
|
|
|
|
|
249
|
|
|
$this->parser->generateXmlFromXPath($xPath); |
|
250
|
|
|
$xml = $this->parser->getXML(); |
|
251
|
|
|
|
|
252
|
|
|
return $xml; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
public function parseXPathWrapped($xPath) |
|
256
|
|
|
{ |
|
257
|
|
|
$this->parser->generateXmlFromXPath($xPath); |
|
258
|
|
|
$xml = $this->parser->getXML(); |
|
259
|
|
|
|
|
260
|
|
|
$xml = '<data' . $this->namespaceString . '>' . $xml . '</data>'; |
|
261
|
|
|
|
|
262
|
|
|
return $xml; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Customized xPath parser |
|
267
|
|
|
* @param xpath $xPath xpath expression |
|
268
|
|
|
* @param string $value form value |
|
269
|
|
|
* @return xml created xml |
|
270
|
|
|
*/ |
|
271
|
|
|
public function customXPath($xPath, $newGroupFlag = false, $value = '', $attributeOnly = false) |
|
272
|
|
|
{ |
|
273
|
|
|
if (!$attributeOnly) { |
|
274
|
|
|
// Explode xPath |
|
275
|
|
|
$newPath = explode('%', $xPath); |
|
276
|
|
|
|
|
277
|
|
|
$praedicateFlag = false; |
|
|
|
|
|
|
278
|
|
|
$explodedXPath = explode('[', $newPath[0]); |
|
279
|
|
|
if (count($explodedXPath) > 1) { |
|
280
|
|
|
// praedicate is given |
|
281
|
|
|
if (substr($explodedXPath[1], 0, 1) == "@") { |
|
282
|
|
|
// attribute |
|
283
|
|
|
$path = $newPath[0]; |
|
284
|
|
|
} else { |
|
285
|
|
|
// path |
|
286
|
|
|
$path = $explodedXPath[0]; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
$praedicateFlag = true; |
|
290
|
|
|
} else { |
|
291
|
|
|
$path = $newPath[0]; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
if (!empty($value)) { |
|
295
|
|
|
$newPath[1] = $newPath[1] . '="' . $value . '"'; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
$modsDataXPath = \EWW\Dpf\Helper\XPath::create($this->xmlData); |
|
299
|
|
|
|
|
300
|
|
|
if (!$newGroupFlag && $modsDataXPath->query('/data/' . $newPath[0])->length > 0) { |
|
301
|
|
|
// first xpath path exist |
|
302
|
|
|
|
|
303
|
|
|
// build xml from second xpath part |
|
304
|
|
|
$xml = $this->parseXPath($newPath[1]); |
|
305
|
|
|
|
|
306
|
|
|
// check if xpath [] are nested |
|
307
|
|
|
$search = '/(\/\w*:\w*)\[(.*)\]/'; |
|
308
|
|
|
preg_match($search, $newPath[1], $match); |
|
309
|
|
|
preg_match($search, $match[2], $secondMatch); |
|
310
|
|
|
// first part nested xpath |
|
311
|
|
|
if ($match[2] && $secondMatch[2]) { |
|
312
|
|
|
$nested = $match[2]; |
|
313
|
|
|
|
|
314
|
|
|
$nestedXml = $this->parseXPath($nested); |
|
315
|
|
|
|
|
316
|
|
|
// object xpath without nested element [] |
|
317
|
|
|
$newPath[1] = str_replace('['.$match[2].']', '', $newPath[1]); |
|
318
|
|
|
|
|
319
|
|
|
$xml = $this->parseXPath($newPath[1]); |
|
320
|
|
|
|
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
$docXML = new \DOMDocument(); |
|
324
|
|
|
$docXML->loadXML($xml); |
|
325
|
|
|
|
|
326
|
|
|
$domXPath = \EWW\Dpf\Helper\XPath::create($this->xmlData); |
|
327
|
|
|
|
|
328
|
|
|
// second part nested xpath |
|
329
|
|
|
if ($match[2] && $secondMatch[2]) { |
|
330
|
|
|
// import node from nested |
|
331
|
|
|
$docXMLNested = new \DOMDocument(); |
|
332
|
|
|
$docXMLNested->loadXML($nestedXml); |
|
|
|
|
|
|
333
|
|
|
|
|
334
|
|
|
$xPath = \EWW\Dpf\Helper\XPath::create($docXML); |
|
335
|
|
|
|
|
336
|
|
|
$nodeList = $xPath->query($match[1]); |
|
337
|
|
|
$node = $nodeList->item(0); |
|
338
|
|
|
|
|
339
|
|
|
$importNode = $docXML->importNode($docXMLNested->getElementsByTagName("mods")->item(0)->firstChild, true); |
|
|
|
|
|
|
340
|
|
|
|
|
341
|
|
|
$node->appendChild($importNode); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
$domNode = $domXPath->query('/data/' . $path); |
|
345
|
|
|
$node = $docXML->documentElement; |
|
346
|
|
|
|
|
347
|
|
|
$nodeAppendModsData = $this->xmlData->importNode($node, true); |
|
348
|
|
|
$domNode->item($domNode->length - 1)->appendChild($nodeAppendModsData); |
|
349
|
|
|
} else { |
|
350
|
|
|
// first xpath doesn't exist |
|
351
|
|
|
// parse first xpath part |
|
352
|
|
|
$xml1 = $this->parseXPathWrapped($newPath[0]); |
|
353
|
|
|
|
|
354
|
|
|
$doc1 = new \DOMDocument(); |
|
355
|
|
|
$doc1->loadXML($xml1); |
|
356
|
|
|
|
|
357
|
|
|
$domXPath = \EWW\Dpf\Helper\XPath::create($doc1); |
|
358
|
|
|
|
|
359
|
|
|
$domNode = $domXPath->query('//' . $path); |
|
360
|
|
|
|
|
361
|
|
|
// parse second xpath part |
|
362
|
|
|
$xml2 = $this->parseXPathWrapped($path . $newPath[1]); |
|
363
|
|
|
|
|
364
|
|
|
// check if xpath [] are nested |
|
365
|
|
|
$search = '/(\/\w*:?\w*)\[(.*)\]/'; |
|
366
|
|
|
preg_match($search, $newPath[1], $match); |
|
367
|
|
|
preg_match($search, $match[2], $secondMatch); |
|
368
|
|
|
|
|
369
|
|
|
// first part nested xpath |
|
370
|
|
|
if ($match[2] && $secondMatch[2]) { |
|
371
|
|
|
$nested = $match[2]; |
|
372
|
|
|
|
|
373
|
|
|
$nestedXml = $this->parseXPathWrapped($nested); |
|
374
|
|
|
|
|
375
|
|
|
// object xpath without nested element [] |
|
376
|
|
|
$newPath[1] = str_replace('['.$match[2].']', '', $newPath[1]); |
|
377
|
|
|
|
|
378
|
|
|
$xml2 = $this->parseXPathWrapped($path . $newPath[1]); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
$doc2 = new \DOMDocument(); |
|
382
|
|
|
$doc2->loadXML($xml2); |
|
383
|
|
|
|
|
384
|
|
|
$domXPath2 = \EWW\Dpf\Helper\XPath::create($doc2); |
|
385
|
|
|
|
|
386
|
|
|
// second part nested xpath |
|
387
|
|
|
if ($match[2] && $secondMatch[2]) { |
|
388
|
|
|
// import node from nested |
|
389
|
|
|
$docXMLNested = new \DOMDocument(); |
|
390
|
|
|
$docXMLNested->loadXML($nestedXml); |
|
391
|
|
|
|
|
392
|
|
|
$xPath = \EWW\Dpf\Helper\XPath::create($doc2); |
|
393
|
|
|
$nodeList = $xPath->query('//' . $path . $match[1]); |
|
394
|
|
|
$node = $nodeList->item(0); |
|
395
|
|
|
|
|
396
|
|
|
$importNode = $doc2->importNode($docXMLNested->documentElement, true); |
|
397
|
|
|
|
|
398
|
|
|
$node->appendChild($importNode); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
$domNode2 = $domXPath2->query('//' . $path)->item(0)->childNodes->item(0); |
|
402
|
|
|
|
|
403
|
|
|
// merge xml nodes |
|
404
|
|
|
$nodeToBeAppended = $doc1->importNode($domNode2, true); |
|
405
|
|
|
|
|
406
|
|
|
$domNode->item(0)->appendChild($nodeToBeAppended); |
|
407
|
|
|
|
|
408
|
|
|
// add to modsData (merge not required) |
|
409
|
|
|
// get mods tag |
|
410
|
|
|
$firstChild = $this->xmlData->firstChild; |
|
411
|
|
|
$firstItem = $doc1->documentElement->firstChild; |
|
412
|
|
|
|
|
413
|
|
|
$nodeAppendModsData = $this->xmlData->importNode($firstItem, true); |
|
414
|
|
|
$firstChild->appendChild($nodeAppendModsData); |
|
415
|
|
|
|
|
416
|
|
|
return $doc1->saveXML(); |
|
|
|
|
|
|
417
|
|
|
} |
|
418
|
|
|
} else { |
|
419
|
|
|
// attribute only |
|
420
|
|
|
$xml = $this->parseXPath($xPath); |
|
421
|
|
|
|
|
422
|
|
|
$docXML = new \DOMDocument(); |
|
423
|
|
|
$docXML->loadXML($xml); |
|
424
|
|
|
|
|
425
|
|
|
$domXPath = \EWW\Dpf\Helper\XPath::create($this->xmlData); |
|
426
|
|
|
$domNode = $domXPath->query('/data'); |
|
427
|
|
|
|
|
428
|
|
|
$node = $docXML->documentElement; |
|
429
|
|
|
|
|
430
|
|
|
$nodeAppendModsData = $this->xmlData->importNode($node, true); |
|
431
|
|
|
$domNode->item($domNode->length - 1)->appendChild($nodeAppendModsData); |
|
432
|
|
|
|
|
433
|
|
|
return $docXML->saveXML(); |
|
|
|
|
|
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
return $this->xmlData->saveXML(); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
public function setXML($value = '') { |
|
440
|
|
|
$domDocument = new \DOMDocument(); |
|
441
|
|
|
if (is_null(@$domDocument->loadXML($value))) { |
|
442
|
|
|
throw new \Exception("Couldn't load MODS data"); |
|
443
|
|
|
} |
|
444
|
|
|
$this->xmlData = $domDocument; |
|
|
|
|
|
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
/** |
|
448
|
|
|
* sets the file data and generates file xml |
|
449
|
|
|
* @param string $value |
|
450
|
|
|
*/ |
|
451
|
|
|
public function setFileData($value = '') |
|
452
|
|
|
{ |
|
453
|
|
|
$this->files = $value; |
|
|
|
|
|
|
454
|
|
|
$this->generateFileXML(); |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
/** |
|
458
|
|
|
* generates the internal xml format for files |
|
459
|
|
|
*/ |
|
460
|
|
|
public function generateFileXML() { |
|
461
|
|
|
|
|
462
|
|
|
$fileXpathConfiguration = $this->clientConfigurationManager->getFileXpath(); |
|
463
|
|
|
|
|
464
|
|
|
foreach ($this->files as $key => $fileGrp) { |
|
465
|
|
|
foreach ($fileGrp as $file) { |
|
466
|
|
|
|
|
467
|
|
|
$this->customXPath($fileXpathConfiguration . '/href', true, $file["path"]); |
|
|
|
|
|
|
468
|
|
|
$this->customXPath($fileXpathConfiguration . '%mimetype', false, $file["type"]); |
|
469
|
|
|
$this->customXPath($fileXpathConfiguration . '%title', false, $file["title"]); |
|
470
|
|
|
$this->customXPath($fileXpathConfiguration . '%download', false, $file["download"]); |
|
471
|
|
|
$this->customXPath($fileXpathConfiguration . '%archive', false, $file["archive"]); |
|
472
|
|
|
$this->customXPath($fileXpathConfiguration . '%use', false, $file["use"]); |
|
473
|
|
|
$this->customXPath($fileXpathConfiguration . '%id', false, $file["id"]); |
|
474
|
|
|
$this->customXPath($fileXpathConfiguration . '%hasFLocat', false, $file["hasFLocat"]); |
|
475
|
|
|
|
|
476
|
|
|
} |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
// public function loopFiles($array, $domElement, $domDocument) |
|
481
|
|
|
// { |
|
482
|
|
|
// $i = 0; |
|
483
|
|
|
// // set xml for uploded files |
|
484
|
|
|
// foreach ($array as $key => $value) { |
|
485
|
|
|
// $file = $domDocument->createElement('mets:file'); |
|
486
|
|
|
// $file->setAttribute('ID', $value['id']); |
|
487
|
|
|
// if ($value['use'] == 'DELETE') { |
|
488
|
|
|
// $file->setAttribute('USE', $value['use']); |
|
489
|
|
|
// $domElement->appendChild($file); |
|
490
|
|
|
// } else { |
|
491
|
|
|
// $file->setAttribute('MIMETYPE', $value['type']); |
|
492
|
|
|
// |
|
493
|
|
|
// if ($value['use']) { |
|
494
|
|
|
// $file->setAttribute('USE', $value['use']); |
|
495
|
|
|
// } |
|
496
|
|
|
// |
|
497
|
|
|
// if ($value['title']) { |
|
498
|
|
|
// $file->setAttribute('mext:LABEL', $value['title']); |
|
499
|
|
|
// } |
|
500
|
|
|
// |
|
501
|
|
|
// $domElement->appendChild($file); |
|
502
|
|
|
// $domElementFLocat = $domElement->childNodes->item($i); |
|
503
|
|
|
// |
|
504
|
|
|
// if ($value['hasFLocat']) { |
|
505
|
|
|
// $fLocat = $domDocument->createElement('mets:FLocat'); |
|
506
|
|
|
// $fLocat->setAttribute('LOCTYPE', 'URL'); |
|
507
|
|
|
// $fLocat->setAttribute('xlink:href', $value['path']); |
|
508
|
|
|
// $fLocat->setAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink"); |
|
509
|
|
|
// $domElementFLocat->appendChild($fLocat); |
|
510
|
|
|
// } |
|
511
|
|
|
// |
|
512
|
|
|
// } |
|
513
|
|
|
// |
|
514
|
|
|
// $i++; |
|
515
|
|
|
// } |
|
516
|
|
|
// } |
|
517
|
|
|
|
|
518
|
|
|
// /** |
|
519
|
|
|
// * Builds the xml fileSection part if files are uploaded |
|
520
|
|
|
// * @return xml |
|
521
|
|
|
// */ |
|
522
|
|
|
// public function buildFileSection() |
|
523
|
|
|
// { |
|
524
|
|
|
// if (empty($this->files['original']) && empty($this->files['download'])) { |
|
525
|
|
|
// return; |
|
526
|
|
|
// } |
|
527
|
|
|
// |
|
528
|
|
|
// $domDocument = new \DOMDocument(); |
|
529
|
|
|
// $domDocument->loadXML($this->metsHeader); |
|
530
|
|
|
// |
|
531
|
|
|
// $domElement = $domDocument->firstChild; |
|
532
|
|
|
// |
|
533
|
|
|
// $fileSec = $domDocument->createElement('mets:fileSec'); |
|
534
|
|
|
// $domElement->appendChild($fileSec); |
|
535
|
|
|
// |
|
536
|
|
|
// $domElement = $domElement->firstChild; |
|
537
|
|
|
// |
|
538
|
|
|
// $fileSecElement = $domElement; |
|
539
|
|
|
// |
|
540
|
|
|
// $fileGrpOriginal = $domDocument->createElement('mets:fileGrp'); |
|
541
|
|
|
// $fileGrpOriginal->setAttribute('xmlns:mext', "http://slub-dresden.de/mets"); |
|
542
|
|
|
// $fileGrpOriginal->setAttribute('USE', 'ORIGINAL'); |
|
543
|
|
|
// |
|
544
|
|
|
// // loop xml file entries |
|
545
|
|
|
// if (!empty($this->files['original'])) { |
|
546
|
|
|
// $this->loopFiles($this->files['original'], $fileGrpOriginal, $domDocument); |
|
547
|
|
|
// $domElement->appendChild($fileGrpOriginal); |
|
548
|
|
|
// } |
|
549
|
|
|
// |
|
550
|
|
|
// // switch back to filesec element |
|
551
|
|
|
// $domElement = $fileSecElement; |
|
552
|
|
|
// |
|
553
|
|
|
// $fileGrpDownload = $domDocument->createElement('mets:fileGrp'); |
|
554
|
|
|
// $fileGrpDownload->setAttribute('xmlns:mext', "http://slub-dresden.de/mets"); |
|
555
|
|
|
// $fileGrpDownload->setAttribute('USE', 'DOWNLOAD'); |
|
556
|
|
|
// |
|
557
|
|
|
// // loop xml |
|
558
|
|
|
// if (!empty($this->files['download'])) { |
|
559
|
|
|
// $this->loopFiles($this->files['download'], $fileGrpDownload, $domDocument); |
|
560
|
|
|
// $domElement->appendChild($fileGrpDownload); |
|
561
|
|
|
// } |
|
562
|
|
|
// |
|
563
|
|
|
// return $domDocument; |
|
564
|
|
|
// } |
|
565
|
|
|
|
|
566
|
|
|
// public function set_SlubInfo($value = '') |
|
567
|
|
|
// { |
|
568
|
|
|
// // build DOMDocument with slub xml |
|
569
|
|
|
// $domDocument = new \DOMDocument(); |
|
570
|
|
|
// $domDocument->loadXML($value); |
|
571
|
|
|
// $this->slubData = $domDocument; |
|
572
|
|
|
// } |
|
573
|
|
|
|
|
574
|
|
|
/** |
|
575
|
|
|
* |
|
576
|
|
|
* @param string $objId |
|
577
|
|
|
* @return void |
|
578
|
|
|
*/ |
|
579
|
|
|
public function setObjId($objId) |
|
580
|
|
|
{ |
|
581
|
|
|
$this->objId = $objId; |
|
582
|
|
|
} |
|
583
|
|
|
} |
|
584
|
|
|
|