Open Journal Systems  3.3.0
swordappservicedocument.php
1 <?php
2 
3 require_once('workspace.php');
4 
6 
7  // The URL of this Service Document
8  public $sac_url;
9 
10  // The HTTP status code returned
11  public $sac_status;
12 
13  // The XML of the service doucment
14  public $sac_xml;
15 
16  // The human readable status code
18 
19  // The version of the SWORD server
20  public $sac_version;
21 
22  // Whether or not verbose output is supported
23  public $sac_verbose;
24 
25  // Whether or not the noOp command is supported
26  public $sac_noop;
27 
28  // The max upload size of deposits
30 
31  // Workspaces in the servicedocument
33 
34  // Construct a new servicedocument
35  function __construct($sac_theurl, $sac_newstatus, $sac_thexml = '') {
36  // Store the URL
37  $this->sac_url = $sac_theurl;
38 
39  // Store the status
40  $this->sac_status = $sac_newstatus;
41 
42  // Store the raw xml
43  $this->sac_xml = $sac_thexml;
44 
45  // Store the status message
46  switch($this->sac_status) {
47  case 200:
48  $this->sac_statusmessage = "OK";
49  break;
50  case 401:
51  $this->sac_statusmessage = "Unauthorized";
52  break;
53  case 404:
54  $this->sac_statusmessage = "Service document not found";
55  break;
56  default:
57  $this->sac_statusmessage = "Unknown error (status code " . $this->sac_status . ")";
58  break;
59  }
60 
61  // Parse the xml if there is some
62  if ($sac_thexml != '') {
63  $sac_xml = @new SimpleXMLElement($sac_thexml);
64  $sac_ns = $sac_xml->getNamespaces(true);
65  if (!isset($sac_ns['sword'])) $sac_ns['sword'] = 'http://purl.org/net/sword/terms/';
66  $this->sac_version = $sac_xml->children($sac_ns['sword'])->version;
67  $this->sac_verbose = $sac_xml->children($sac_ns['sword'])->verbose;
68  $this->sac_noop = $sac_xml->children($sac_ns['sword'])->noOp;
69  $this->sac_maxuploadsize = $sac_xml->children($sac_ns['sword'])->maxUploadSize;
70 
71  // Build the workspaces
72  $sac_ws = @$sac_xml->children($sac_ns['app'])->workspace;
73  foreach ($sac_ws as $sac_workspace) {
74  $sac_newworkspace = new Workspace($sac_workspace->children($sac_ns['atom'])->title);
75  $sac_newworkspace->buildhierarchy(@$sac_workspace->children($sac_ns['app']), $sac_ns);
76  $this->sac_workspaces[] = $sac_newworkspace;
77  }
78  }
79  }
80 
81  function toString() {
82  print " - Version: " . $this->sac_version . "\n";
83  if (!empty($this->sac_verbose)) print " - Supports Verbose: " . $this->sac_verbose . "\n";
84  if (!empty($this->sac_noop)) print " - Supports NoOp: " . $this->sac_noop . "\n";
85  print " - Maximum uplaod size: ";
86  if (!empty($this->sac_maxuploadsize)) {
87  print $this->sac_maxuploadsize . " kB\n";
88  } else {
89  print "undefined\n";
90  }
91 
92  foreach ($this->sac_workspaces as $workspace) {
93  $wstitle = $workspace->sac_workspacetitle;
94  echo " - Workspace: ".$wstitle."\n";
95  $collections = $workspace->sac_collections;
96  foreach ($collections as $collection) {
97  $ctitle = $collection->sac_colltitle;
98  echo " - Collection: " . $ctitle . " (" . $collection->sac_href . ")\n";
99  if (count($collection->sac_accept) > 0) {
100  foreach ($collection->sac_accept as $accept) {
101  echo " - Accepts: " . $accept . "\n";
102  }
103  }
104  if (count($collection->sac_acceptalternative) > 0) {
105  foreach ($collection->sac_acceptalternative as $accept) {
106  echo " - Accepts: " . $accept . " alternative='multipart-related'\n";
107  }
108  }
109  if (count($collection->sac_acceptpackaging) > 0) {
110  foreach ($collection->sac_acceptpackaging as $acceptpackaging => $q) {
111  echo " - Accepted packaging format: " . $acceptpackaging . " (q=" . $q . ")\n";
112  }
113  }
114  if (!empty($collection->sac_collpolicy)) {
115  echo " - Collection Policy: " . $collection->sac_collpolicy . "\n";
116  }
117  echo " - Collection abstract: " . $collection->sac_abstract . "\n";
118  $mediation = "false";
119  if ($collection->sac_mediation == true) { $mediation = "true"; }
120  echo " - Mediation: " . $mediation . "\n";
121  if (!empty($collection->sac_service)) {
122  echo " - Service document: " . $collection->sac_service . "\n";
123  }
124  }
125  }
126  }
127 }
128 
129 ?>
SWORDAPPServiceDocument\toString
toString()
Definition: swordappservicedocument.php:81
SWORDAPPServiceDocument
Definition: swordappservicedocument.php:5
SWORDAPPServiceDocument\$sac_verbose
$sac_verbose
Definition: swordappservicedocument.php:23
SWORDAPPServiceDocument\$sac_xml
$sac_xml
Definition: swordappservicedocument.php:14
SWORDAPPServiceDocument\$sac_noop
$sac_noop
Definition: swordappservicedocument.php:26
SWORDAPPServiceDocument\$sac_statusmessage
$sac_statusmessage
Definition: swordappservicedocument.php:17
SWORDAPPServiceDocument\$sac_workspaces
$sac_workspaces
Definition: swordappservicedocument.php:32
SWORDAPPServiceDocument\$sac_maxuploadsize
$sac_maxuploadsize
Definition: swordappservicedocument.php:29
SWORDAPPServiceDocument\$sac_version
$sac_version
Definition: swordappservicedocument.php:20
SWORDAPPServiceDocument\__construct
__construct($sac_theurl, $sac_newstatus, $sac_thexml='')
Definition: swordappservicedocument.php:35
Workspace
Definition: workspace.php:6
SWORDAPPServiceDocument\$sac_url
$sac_url
Definition: swordappservicedocument.php:8
SWORDAPPServiceDocument\$sac_status
$sac_status
Definition: swordappservicedocument.php:11