Open Journal Systems  3.3.0
RepresentationNativeXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
23  function __construct($filterGroup) {
24  $this->setDisplayName('Native XML representation export');
25  parent::__construct($filterGroup);
26  }
27 
28 
29  //
30  // Implement template methods from PersistableFilter
31  //
35  function getClassName() {
36  return 'lib.pkp.plugins.importexport.native.filter.RepresentationNativeXmlFilter';
37  }
38 
39 
40  //
41  // Implement template methods from Filter
42  //
48  function &process(&$representation) {
49  // Create the XML document
50  $doc = new DOMDocument('1.0');
51  $doc->preserveWhiteSpace = false;
52  $doc->formatOutput = true;
53  $deployment = $this->getDeployment();
54  $rootNode = $this->createRepresentationNode($doc, $representation);
55  $doc->appendChild($rootNode);
56  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
57  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
58 
59  return $doc;
60  }
61 
62  //
63  // Representation conversion functions
64  //
71  function createRepresentationNode($doc, $representation) {
72  $deployment = $this->getDeployment();
73  $context = $deployment->getContext();
74 
75  // Create the representation node
76  $representationNode = $doc->createElementNS($deployment->getNamespace(), $deployment->getRepresentationNodeName());
77 
78  $representationNode->setAttribute('locale', $representation->getData('locale'));
79 
80  $this->addIdentifiers($doc, $representationNode, $representation);
81 
82  // Add metadata
83  $this->createLocalizedNodes($doc, $representationNode, 'name', $representation->getName(null));
84  $sequenceNode = $doc->createElementNS($deployment->getNamespace(), 'seq');
85  $sequenceNode->appendChild($doc->createTextNode((int) $representation->getSequence()));
86  $representationNode->appendChild($sequenceNode);
87 
88  $urlRemote = $representation->getData('urlRemote');
89  if ($urlRemote) {
90  $remoteNode = $doc->createElementNS($deployment->getNamespace(), 'remote');
91  $remoteNode->setAttribute('src', $urlRemote);
92  $representationNode->appendChild($remoteNode);
93  } else {
94  // Add files
95  foreach ($this->getFiles($representation) as $submissionFile) {
96  $fileRefNode = $doc->createElementNS($deployment->getNamespace(), 'submission_file_ref');
97  $fileRefNode->setAttribute('id', $submissionFile->getFileId());
98  $fileRefNode->setAttribute('revision', $submissionFile->getRevision());
99  $representationNode->appendChild($fileRefNode);
100  }
101  }
102 
103  return $representationNode;
104  }
105 
112  function addIdentifiers($doc, $representationNode, $representation) {
113  $deployment = $this->getDeployment();
114 
115  // Add internal ID
116  $representationNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'id', $representation->getId()));
117  $node->setAttribute('type', 'internal');
118  $node->setAttribute('advice', 'ignore');
119 
120  // Add public ID
121  if ($pubId = $representation->getStoredPubId('publisher-id')) {
122  $representationNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'id', htmlspecialchars($pubId, ENT_COMPAT, 'UTF-8')));
123  $node->setAttribute('type', 'public');
124  $node->setAttribute('advice', 'update');
125  }
126 
127  // Add pub IDs by plugin
128  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $deployment->getContext()->getId());
129  foreach ($pubIdPlugins as $pubIdPlugin) {
130  $this->addPubIdentifier($doc, $representationNode, $representation, $pubIdPlugin);
131  }
132  }
133 
142  function addPubIdentifier($doc, $representationNode, $representation, $pubIdPlugin) {
143  $pubId = $representation->getStoredPubId($pubIdPlugin->getPubIdType());
144  if ($pubId) {
145  $deployment = $this->getDeployment();
146  $representationNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'id', htmlspecialchars($pubId, ENT_COMPAT, 'UTF-8')));
147  $node->setAttribute('type', $pubIdPlugin->getPubIdType());
148  $node->setAttribute('advice', 'update');
149  return $node;
150  }
151  return null;
152  }
153 
154  //
155  // Abstract methods to be implemented by subclasses
156  //
162  function getFiles($representation) {
163  assert(false); // To be overridden by subclasses
164  }
165 }
166 
167 
RepresentationNativeXmlFilter\getClassName
getClassName()
Definition: RepresentationNativeXmlFilter.inc.php:35
RepresentationNativeXmlFilter\process
& process(&$representation)
Definition: RepresentationNativeXmlFilter.inc.php:48
RepresentationNativeXmlFilter
Base class that converts a representation to a Native XML document.
Definition: RepresentationNativeXmlFilter.inc.php:18
RepresentationNativeXmlFilter\addIdentifiers
addIdentifiers($doc, $representationNode, $representation)
Definition: RepresentationNativeXmlFilter.inc.php:112
NativeImportExportFilter\getDeployment
getDeployment()
Definition: NativeImportExportFilter.inc.php:49
NativeExportFilter\createLocalizedNodes
createLocalizedNodes($doc, $parentNode, $name, $values)
Definition: NativeExportFilter.inc.php:87
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
NativeExportFilter
Base class that converts a DataObject to a Native XML document.
Definition: NativeExportFilter.inc.php:18
RepresentationNativeXmlFilter\addPubIdentifier
addPubIdentifier($doc, $representationNode, $representation, $pubIdPlugin)
Definition: RepresentationNativeXmlFilter.inc.php:142
RepresentationNativeXmlFilter\getFiles
getFiles($representation)
Definition: RepresentationNativeXmlFilter.inc.php:162
RepresentationNativeXmlFilter\__construct
__construct($filterGroup)
Definition: RepresentationNativeXmlFilter.inc.php:23
RepresentationNativeXmlFilter\createRepresentationNode
createRepresentationNode($doc, $representation)
Definition: RepresentationNativeXmlFilter.inc.php:71
Filter\setDisplayName
setDisplayName($displayName)
Definition: Filter.inc.php:140