-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathswordappentry.php
157 lines (121 loc) · 3.88 KB
/
swordappentry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
require_once("utils.php");
class SWORDAPPEntry {
// The HTTP status code returned
public $sac_status;
// The XML returned by the deposit
public $sac_xml;
// The human readable status code
public $sac_statusmessage;
// The atom:id identifier
public $sac_id;
// The atom:content value
public $sac_content_src;
public $sac_content_type;
// The authors
public $sac_authors;
// The contributors
public $sac_contributors;
// The links
public $sac_links;
// The title
public $sac_title;
// The summary
public $sac_summary;
// The rights
public $sac_rights;
// The update date
public $sac_updated;
// The packaging format used
public $sac_packaging;
// The generator
public $sac_generator;
public $sac_generator_uri;
// The user agent
public $sac_useragent;
// The noOp status
public $sac_noOp;
// Construct a new deposit response by passing in the http status code
function __construct($sac_newstatus, $sac_thexml) {
// Store the status
$this->sac_status = $sac_newstatus;
// Store the xml
$this->sac_xml = $sac_thexml;
// Store the status message
switch($this->sac_status) {
case 201:
$this->sac_statusmessage = "Created";
break;
case 202:
$this->sac_statusmessage = "Accepted";
break;
case 401:
$this->sac_statusmessage = "Unauthorized";
break;
case 412:
$this->sac_statusmessage = "Precondition failed";
break;
case 413:
$this->sac_statusmessage = "Request entity too large";
break;
case 415:
$this->sac_statusmessage = "Unsupported media type";
break;
default:
$this->sac_statusmessage = "Unknown error (status code " . $this->sac_status . ")";
break;
}
// Initalise arrays
$this->sac_authors = array();
$this->sac_contributors = array();
$this->sac_links = array();
// Assume noOp is false unless we change it later
$this->sac_noOp = false;
}
// Build the workspace hierarchy
function buildhierarchy($sac_dr, $sac_ns) {
// Set the default namespace
$sac_dr->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
// Parse the results
$this->sac_id = $sac_dr->children($sac_ns['atom'])->id;
$sac_contentbits = $sac_dr->xpath("atom:content");
if (!empty($sac_contentbits)) {
$this->sac_content_src = $sac_contentbits[0]['src'];
$this->sac_content_type = $sac_contentbits[0]['type'];
}
// Store the authors
foreach ($sac_dr->children($sac_ns['atom'])->author as $sac_author) {
$sac_theauthor = $sac_author->children($sac_ns['atom'])->name . "";
$this->sac_authors[] = $sac_theauthor;
}
// Store the contributors
foreach ($sac_dr->children($sac_ns['atom'])->contributor as $sac_contributor) {
$sac_thecontributor = $sac_contributor->children($sac_ns['atom'])->name . "";
$this->sac_contributors[] = $sac_thecontributor;
}
// Store the links
foreach ($sac_dr->xpath("atom:link") as $sac_link) {
$this->sac_links[] = sac_clean($sac_link[0]['href']);
}
// Store the title and summary
$this->sac_title = sac_clean($sac_dr->children($sac_ns['atom'])->title);
$this->sac_summary = sac_clean($sac_dr->children($sac_ns['atom'])->summary);
// Store the updated date
$this->sac_updated = $sac_dr->children($sac_ns['atom'])->updated;
// Store the rights
$this->sac_rights = sac_clean($sac_dr->children($sac_ns['atom'])->rights);
// Store the format namespace
$this->sac_packaging = $sac_dr->children($sac_ns['sword'])->packaging;
// Store the generator
$this->sac_generator = sac_clean($sac_dr->children($sac_ns['atom'])->generator);
$sac_gen = $sac_dr->xpath("atom:generator");
if (!empty($sac_gen)) { $this->sac_generator_uri = $sac_gen[0]['uri']; }
// Store the user agent
$this->sac_useragent = sac_clean($sac_dr->children($sac_ns['sword'])->userAgent);
// Store the noOp status
if (strtolower((string)$sac_dr->children($sac_ns['sword'])->noOp) == 'true') {
$this->sac_noOp = true;
}
}
}
?>