Open Journal Systems  3.3.0
swordappentry.php
1 <?php
2 
3 require_once("swordapplink.php");
4 require_once("utils.php");
5 
6 class SWORDAPPEntry {
7 
8  // The HTTP status code returned
9  public $sac_status;
10 
11  // The XML returned by the deposit
12  public $sac_xml;
13 
14  // The human readable status code
16 
17  // The atom:id identifier
18  public $sac_id;
19 
20  // The atom:content values
23 
24  // The authors
25  public $sac_authors;
26 
27  // The contributors
29 
30  // The links
31  public $sac_links;
32 
33  // The title
34  public $sac_title;
35 
36  // The summary
37  public $sac_summary;
38 
39  // The rights
40  public $sac_rights;
41 
42  // The treatment
44 
45  // The verbose description
47 
48  // The update date
49  public $sac_updated;
50 
51  // The packaging format used
53 
54  // The generator
57 
58  // The user agent
60 
61  // The noOp status
62  public $sac_noOp;
63 
64  // Any dcterms metadata
65  public $sac_dcterms;
66 
67  // The Edit IRI
68  public $sac_edit_iri;
69 
70  // The SE-IRI
71  public $sac_se_iri;
72 
73  // The Atom Statement IRI
75 
76  // The Atom Statement IRI
78 
79  // The Edit Media IRI
81 
82  // The Atom feed representation of media resources
84 
85  // Construct a new deposit response by passing in the http status code
86  function __construct($sac_newstatus, $sac_thexml) {
87  // Store the status
88  $this->sac_status = $sac_newstatus;
89 
90  // Store the xml
91  $this->sac_xml = $sac_thexml;
92 
93  // Store the status message
94  switch($this->sac_status) {
95  case 200:
96  $this->sac_statusmessage = "OK";
97  break;
98  case 201:
99  $this->sac_statusmessage = "Created";
100  break;
101  case 202:
102  $this->sac_statusmessage = "Accepted";
103  break;
104  case 400:
105  $this->sac_statusmessage = "Bad request";
106  break;
107  case 401:
108  $this->sac_statusmessage = "Unauthorized";
109  break;
110  case 403:
111  $this->sac_statusmessage = "Forbidden";
112  break;
113  case 412:
114  $this->sac_statusmessage = "Precondition failed";
115  break;
116  case 413:
117  $this->sac_statusmessage = "Request entity too large";
118  break;
119  case 415:
120  $this->sac_statusmessage = "Unsupported media type";
121  break;
122  default:
123  $this->sac_statusmessage = "Unknown error (status code " . $this->sac_status . ")";
124  break;
125  }
126 
127  // Initalise arrays
128  $this->sac_authors = array();
129  $this->sac_contributors = array();
130  $this->sac_links = array();
131  $this->sac_dcterms = array();
132 
133  // Assume noOp is false unless we change it later
134  $this->sac_noOp = false;
135  }
136 
137  // Build the workspace hierarchy
138  function buildhierarchy($sac_dr, $sac_ns) {
139  // Set the default namespace
140  $sac_dr->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
141  if (!isset($sac_ns['atom'])) $sac_ns['atom'] = 'http://www.w3.org/2005/Atom';
142  if (!isset($sac_ns['dcterms'])) $sac_ns['dcterms'] = 'http://purl.org/dc/terms/';
143  if (!isset($sac_ns['sword'])) $sac_ns['sword'] = 'http://purl.org/net/sword/';
144 
145  // Parse the results
146  $this->sac_id = $sac_dr->children($sac_ns['atom'])->id;
147  $sac_contentbits = $sac_dr->xpath("atom:content");
148  if (!empty($sac_contentbits)) {
149  $this->sac_content_src = $sac_contentbits[0]->attributes()->src;
150  $this->sac_content_type = $sac_contentbits[0]->attributes()->type;
151  }
152 
153  // Store the authors
154  foreach ($sac_dr->children($sac_ns['atom'])->author as $sac_author) {
155  $sac_theauthor = $sac_author->children($sac_ns['atom'])->name . "";
156  $this->sac_authors[] = $sac_theauthor;
157  }
158 
159  // Store the contributors
160  foreach ($sac_dr->children($sac_ns['atom'])->contributor as $sac_contributor) {
161  $sac_thecontributor = $sac_contributor->children($sac_ns['atom'])->name . "";
162  $this->sac_contributors[] = $sac_thecontributor;
163  }
164 
165  // Store the links
166  foreach ($sac_dr->xpath("atom:link") as $sac_link) {
167  $sac_linkobject = new SWORDAPPLink($sac_link->attributes()->rel, $sac_link->attributes()->href, $sac_link->attributes()->type);
168  array_push($this->sac_links, $sac_linkobject);
169 
170  // Store the Edit IRI
171  if ($sac_linkobject->sac_linkrel == 'edit') $this->sac_edit_iri = $sac_linkobject->sac_linkhref;
172 
173  // Store the SE-IRI
174  if ($sac_linkobject->sac_linkrel == 'http://purl.org/net/sword/terms/add') $this->sac_se_iri = $sac_linkobject->sac_linkhref;
175 
176  // Store the Statement IRIs
177  if ($sac_linkobject->sac_linkrel == 'http://purl.org/net/sword/terms/statement') {
178  if (($sac_linkobject->sac_linktype == 'application/atom+xml;type=feed') ||
179  ($sac_linkobject->sac_linktype == 'application/atom+xml; type=feed')) {
180  $this->sac_state_iri_atom = $sac_linkobject->sac_linkhref;
181  } else if ($sac_linkobject->sac_linktype == 'application/rdf+xml') {
182  $this->sac_state_iri_ore = $sac_linkobject->sac_linkhref;
183  }
184  }
185  // Store the Edit Media IRIs
186  if ($sac_linkobject->sac_linkrel == 'edit-media') {
187  // Edit media IRI as Atom feed
188  if (($sac_linkobject->sac_linktype == 'application/atom+xml;type=feed') ||
189  ($sac_linkobject->sac_linktype == 'application/atom+xml; type=feed')) {
190  $this->sac_edit_media_iri_atom = $sac_linkobject->sac_linkhref;
191  }
192  else {
193  // Edit media IRI
194  $this->sac_edit_media_iri = $sac_linkobject->sac_linkhref;
195  }
196  }
197  }
198 
199  // Store the title and summary
200  $this->sac_title = sac_clean($sac_dr->children($sac_ns['atom'])->title);
201  $this->sac_summary = sac_clean($sac_dr->children($sac_ns['atom'])->summary);
202 
203  // Store the updated date
204  $this->sac_updated = $sac_dr->children($sac_ns['atom'])->updated;
205 
206  // Store the rights
207  $this->sac_rights = sac_clean($sac_dr->children($sac_ns['atom'])->rights);
208 
209  // Store the treatment
210  $this->sac_treatment = sac_clean($sac_dr->children($sac_ns['sword'])->treatment);
211 
212  // Store the verboseDescription
213  $this->sac_verbose_treatment = sac_clean($sac_dr->children($sac_ns['sword'])->verboseDescription);
214 
215  // Store the format namespace
216  $this->sac_packaging = $sac_dr->children($sac_ns['sword'])->packaging;
217 
218  // Store the generator
219  $this->sac_generator = sac_clean($sac_dr->children($sac_ns['atom'])->generator);
220  $sac_gen = $sac_dr->xpath("atom:generator");
221  if (!empty($sac_gen)) { $this->sac_generator_uri = $sac_gen[0]->attributes()->uri; }
222 
223  // Store the user agent
224  $this->sac_useragent = sac_clean($sac_dr->children($sac_ns['sword'])->userAgent);
225 
226  // Store any embedded metadata
227  foreach ($sac_dr->children($sac_ns['dcterms']) as $sac_dcterm) {
228  if (!isset($this->sac_dcterms[$sac_dcterm->getName()])) {
229  $this->sac_dcterms[$sac_dcterm->getName()] = array();
230  }
231  array_push($this->sac_dcterms[$sac_dcterm->getName()], $sac_dcterm);
232  }
233 
234  // Store the noOp status
235  if (strtolower((string)$sac_dr->children($sac_ns['sword'])->noOp) == 'true') {
236  $this->sac_noOp = true;
237  }
238  }
239 
240  function toString() {
241  print " - ID: " . $this->sac_id . "\n";
242  print " - Title: " . $this->sac_title . "\n";
243  print " - Content: " . $this->sac_content_src ." (" . $this->sac_content_type . ")\n";
244  foreach ($this->sac_authors as $author) {
245  print " - Author: " . $author . "\n";
246  }
247  foreach ($this->sac_contributors as $contributor) {
248  print " - Contributor: " . $contributor . "\n";
249  }
250  foreach ($this->sac_links as $links) {
251  print ' - Link: rel=' . $links->sac_linkrel . ' ';
252  print 'href=' . $links->sac_linkhref . ' ';
253  if (isset($links->sac_linktype)) {
254  print 'type=' . $links->sac_linktype;
255  }
256  print "\n";
257  }
258  print " - Summary: " . $this->sac_summary . "\n";
259  print " - Updated: " . $this->sac_updated . "\n";
260  print " - Rights: " . $this->sac_rights . "\n";
261  print " - Treatment: " . $this->sac_treatment . "\n";
262  print " - Verbose description: " . $this->sac_verbose_treatment . "\n";
263  print " - Packaging: " . $this->sac_packaging . "\n";
264  print " - Generator: " . $this->sac_generator . " (" . $this->sac_generator_uri . ")\n";
265  print " - User agent: " . $this->sac_useragent . "\n";
266  if (!empty($this->sac_noOp)) { print " - noOp: " . $this->sac_noOp . "\n"; }
267 
268  foreach ($this->sac_dcterms as $dcterm => $dcvalues) {
269  print ' - Dublin Core Metadata: ' . $dcterm . "\n";
270  foreach ($dcvalues as $dcvalue) {
271  print ' - ' . $dcvalue . "\n";
272  }
273  }
274  }
275 }
276 
277 ?>
SWORDAPPEntry\__construct
__construct($sac_newstatus, $sac_thexml)
Definition: swordappentry.php:86
SWORDAPPEntry\buildhierarchy
buildhierarchy($sac_dr, $sac_ns)
Definition: swordappentry.php:138
SWORDAPPEntry\$sac_links
$sac_links
Definition: swordappentry.php:31
SWORDAPPEntry\$sac_generator_uri
$sac_generator_uri
Definition: swordappentry.php:56
SWORDAPPEntry\$sac_noOp
$sac_noOp
Definition: swordappentry.php:62
SWORDAPPEntry\$sac_state_iri_atom
$sac_state_iri_atom
Definition: swordappentry.php:74
SWORDAPPEntry\$sac_packaging
$sac_packaging
Definition: swordappentry.php:52
SWORDAPPEntry\$sac_content_type
$sac_content_type
Definition: swordappentry.php:22
SWORDAPPEntry\toString
toString()
Definition: swordappentry.php:240
SWORDAPPEntry\$sac_state_iri_ore
$sac_state_iri_ore
Definition: swordappentry.php:77
SWORDAPPEntry\$sac_status
$sac_status
Definition: swordappentry.php:9
SWORDAPPEntry\$sac_summary
$sac_summary
Definition: swordappentry.php:37
SWORDAPPEntry\$sac_generator
$sac_generator
Definition: swordappentry.php:55
SWORDAPPEntry\$sac_verbose_treatment
$sac_verbose_treatment
Definition: swordappentry.php:46
SWORDAPPEntry\$sac_useragent
$sac_useragent
Definition: swordappentry.php:59
SWORDAPPEntry\$sac_xml
$sac_xml
Definition: swordappentry.php:12
SWORDAPPEntry\$sac_dcterms
$sac_dcterms
Definition: swordappentry.php:65
SWORDAPPEntry\$sac_updated
$sac_updated
Definition: swordappentry.php:49
SWORDAPPEntry
Definition: swordappentry.php:6
SWORDAPPEntry\$sac_content_src
$sac_content_src
Definition: swordappentry.php:21
SWORDAPPEntry\$sac_edit_media_iri
$sac_edit_media_iri
Definition: swordappentry.php:80
SWORDAPPEntry\$sac_edit_media_iri_atom
$sac_edit_media_iri_atom
Definition: swordappentry.php:83
SWORDAPPEntry\$sac_se_iri
$sac_se_iri
Definition: swordappentry.php:71
SWORDAPPEntry\$sac_edit_iri
$sac_edit_iri
Definition: swordappentry.php:68
SWORDAPPEntry\$sac_rights
$sac_rights
Definition: swordappentry.php:40
SWORDAPPEntry\$sac_treatment
$sac_treatment
Definition: swordappentry.php:43
SWORDAPPEntry\$sac_authors
$sac_authors
Definition: swordappentry.php:25
SWORDAPPEntry\$sac_id
$sac_id
Definition: swordappentry.php:18
SWORDAPPEntry\$sac_title
$sac_title
Definition: swordappentry.php:34
SWORDAPPEntry\$sac_statusmessage
$sac_statusmessage
Definition: swordappentry.php:15
SWORDAPPEntry\$sac_contributors
$sac_contributors
Definition: swordappentry.php:28