Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SubmissionNativeXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
23  function SubmissionNativeXmlFilter($filterGroup) {
24  $this->setDisplayName('Native XML submission export');
25  parent::NativeExportFilter($filterGroup);
26  }
27 
28 
29  //
30  // Implement template methods from PersistableFilter
31  //
35  function getClassName() {
36  return 'lib.pkp.plugins.importexport.native.filter.SubmissionNativeXmlFilter';
37  }
38 
39 
40  //
41  // Implement template methods from Filter
42  //
48  function &process(&$submissions) {
49  // Create the XML document
50  $doc = new DOMDocument('1.0');
51  $deployment = $this->getDeployment();
52 
53  if (count($submissions)==1) {
54  // Only one submission specified; create root node
55  $rootNode = $this->createSubmissionNode($doc, $submissions[0]);
56  } else {
57  // Multiple submissions; wrap in a <submissions> element
58  $rootNode = $doc->createElementNS($deployment->getNamespace(), $deployment->getSubmissionsNodeName());
59  foreach ($submissions as $submission) {
60  $rootNode->appendChild($this->createSubmissionNode($doc, $submission));
61  }
62  }
63  $doc->appendChild($rootNode);
64  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
65  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
66 
67  return $doc;
68  }
69 
70  //
71  // Submission conversion functions
72  //
79  function createSubmissionNode($doc, $submission) {
80  // Create the root node and attributes
81  $deployment = $this->getDeployment();
82  $deployment->setSubmission($submission);
83  $submissionNode = $doc->createElementNS($deployment->getNamespace(), $deployment->getSubmissionNodeName());
84  $submissionNode->setAttribute('locale', $submission->getLocale());
85  if ($datePublished = $submission->getDatePublished()) {
86  $submissionNode->setAttribute('date_published', strftime('%F', strtotime($datePublished)));
87  }
88  // FIXME: language attribute (from old DTD). Necessary? Data migration needed?
89 
90  $this->addIdentifiers($doc, $submissionNode, $submission);
91  $this->addMetadata($doc, $submissionNode, $submission);
92  $this->addAuthors($doc, $submissionNode, $submission);
93  $this->addFiles($doc, $submissionNode, $submission);
94  $this->addRepresentations($doc, $submissionNode, $submission);
95 
96  return $submissionNode;
97  }
98 
105  function addIdentifiers($doc, $submissionNode, $submission) {
106  $deployment = $this->getDeployment();
107 
108  // Add internal ID
109  $submissionNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'id', $submission->getId()));
110  $node->setAttribute('type', 'internal');
111 
112  // Add public ID
113  if ($pubId = $submission->getPubId('publisher-id')) {
114  $submissionNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'id', $pubId));
115  $node->setAttribute('type', 'public');
116  }
117 
118  // Add pub IDs by plugin
119  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $deployment->getContext()->getId());
120  foreach ((array) $pubIdPlugins as $pubIdPlugin) {
121  $this->addPubIdentifier($doc, $submissionNode, $submission, $pubIdPlugin);
122  }
123  }
124 
133  function addPubIdentifier($doc, $submissionNode, $submission, $pubIdPlugin) {
134  $pubId = $pubIdPlugin->getPubId($submission, !$submission->getPublished());
135  if ($pubId) {
136  $submissionNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'id', $pubId));
137  $node->setAttribute('type', $pubIdPlugin->getPubIdType());
138  return $node;
139  }
140  return null;
141  }
142 
149  function addMetadata($doc, $submissionNode, $submission) {
150  $this->createLocalizedNodes($doc, $submissionNode, 'title', $submission->getTitle(null));
151  $this->createLocalizedNodes($doc, $submissionNode, 'prefix', $submission->getPrefix(null));
152  $this->createLocalizedNodes($doc, $submissionNode, 'subtitle', $submission->getSubtitle(null));
153  $this->createLocalizedNodes($doc, $submissionNode, 'abstract', $submission->getAbstract(null));
154  $this->createLocalizedNodes($doc, $submissionNode, 'subject_class', $submission->getSubjectClass(null));
155  $this->createLocalizedNodes($doc, $submissionNode, 'coverage_geo', $submission->getCoverageGeo(null));
156  $this->createLocalizedNodes($doc, $submissionNode, 'coverage_chron', $submission->getCoverageChron(null));
157  $this->createLocalizedNodes($doc, $submissionNode, 'coverage_sample', $submission->getCoverageSample(null));
158  $this->createLocalizedNodes($doc, $submissionNode, 'type', $submission->getType(null));
159  $this->createLocalizedNodes($doc, $submissionNode, 'source', $submission->getSource(null));
160  $this->createLocalizedNodes($doc, $submissionNode, 'rights', $submission->getRights(null));
161  $this->createOptionalNode($doc, $submissionNode, 'comments_to_editor', $submission->getCommentsToEditor());
162  }
163 
170  function addAuthors($doc, $submissionNode, $submission) {
171  $filterDao = DAORegistry::getDAO('FilterDAO');
172  $nativeExportFilters = $filterDao->getObjectsByGroup('author=>native-xml');
173  assert(count($nativeExportFilters)==1); // Assert only a single serialization filter
174  $exportFilter = array_shift($nativeExportFilters);
175  $exportFilter->setDeployment($this->getDeployment());
176 
177  $authorsDoc = $exportFilter->execute($submission->getAuthors());
178  if ($authorsDoc->documentElement instanceof DOMElement) {
179  $clone = $doc->importNode($authorsDoc->documentElement, true);
180  $submissionNode->appendChild($clone);
181  }
182  }
183 
190  function addRepresentations($doc, $submissionNode, $submission) {
191  $filterDao = DAORegistry::getDAO('FilterDAO');
192  $nativeExportFilters = $filterDao->getObjectsByGroup($this->getRepresentationExportFilterGroupName());
193  assert(count($nativeExportFilters)==1); // Assert only a single serialization filter
194  $exportFilter = array_shift($nativeExportFilters);
195  $exportFilter->setDeployment($this->getDeployment());
196 
197  $representationDao = Application::getRepresentationDAO();
198  $representations = $representationDao->getBySubmissionId($submission->getId());
199  while ($representation = $representations->next()) {
200  $representationDoc = $exportFilter->execute($representation);
201  $clone = $doc->importNode($representationDoc->documentElement, true);
202  $submissionNode->appendChild($clone);
203  }
204  }
205 
212  function addFiles($doc, $submissionNode, $submission) {
213  $filterDao = DAORegistry::getDAO('FilterDAO');
214  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
215  $submissionFiles = $submissionFileDao->getBySubmissionId($submission->getId());
216 
217  // Submission files will come back from the file export filter
218  // with one revision each, wrapped in a submission_file node:
219  // <submission_file ...>
220  // <revision ...>...</revision>
221  // </submission_file>
222  // Reformat them into groups by submission_file, i.e.:
223  // <submission_file ...>
224  // <revision ...>...</revision>
225  // <revision ...>...</revision>
226  // </submission_file>
227  $submissionFileNodesByFileId = array();
228  foreach ($submissionFiles as $submissionFile) {
229  $nativeExportFilters = $filterDao->getObjectsByGroup(get_class($submissionFile) . '=>native-xml');
230  assert(count($nativeExportFilters)==1); // Assert only a single serialization filter
231  $exportFilter = array_shift($nativeExportFilters);
232  $exportFilter->setDeployment($this->getDeployment());
233 
234  $submissionFileDoc = $exportFilter->execute($submissionFile);
235  $fileId = $submissionFileDoc->documentElement->getAttribute('id');
236  if (!isset($submissionFileNodesByFileId[$fileId])) {
237  $clone = $doc->importNode($submissionFileDoc->documentElement, true);
238  $submissionNode->appendChild($clone);
239  $submissionFileNodesByFileId[$fileId] = $clone;
240  } else {
241  $submissionFileNode = $submissionFileNodesByFileId[$fileId];
242  // Look for a <revision> element
243  $revisionNode = null;
244  foreach ($submissionFileDoc->documentElement->childNodes as $childNode) {
245  if (!is_a($childNode, 'DOMElement')) continue;
246  if ($childNode->tagName == 'revision') $revisionNode = $childNode;
247  }
248  assert(is_a($revisionNode, 'DOMElement'));
249  $clone = $doc->importNode($revisionNode, true);
250  $submissionFileNode->appendChild($clone);
251  }
252  }
253  }
254 
255 
256  //
257  // Abstract methods for subclasses to implement
258  //
264  assert(false); // Must be overridden by subclasses
265  }
266 }
267 
268 ?>
static & getDAO($name, $dbconn=null)
static getRepresentationDAO()
addMetadata($doc, $submissionNode, $submission)
addRepresentations($doc, $submissionNode, $submission)
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
setDisplayName($displayName)
Definition: Filter.inc.php:140
addPubIdentifier($doc, $submissionNode, $submission, $pubIdPlugin)
Base class that converts a set of submissions to a Native XML document.
addFiles($doc, $submissionNode, $submission)
addIdentifiers($doc, $submissionNode, $submission)
Base class that converts a DataObject to a Native XML document.
createLocalizedNodes($doc, $parentNode, $name, $values)
addAuthors($doc, $submissionNode, $submission)
createOptionalNode($doc, $parentNode, $name, $value)