forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CollectionViewer.java
228 lines (195 loc) · 6.61 KB
/
CollectionViewer.java
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.xmlui.aspect.artifactbrowser;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.DSpaceValidity;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.Body;
import org.dspace.app.xmlui.wing.element.Division;
import org.dspace.app.xmlui.wing.element.ReferenceSet;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* Display a single collection. This includes a full text search, browse by
* list, community display and a list of recent submissions.
*
* @author Scott Phillips
* @author Kevin Van de Velde (kevin at atmire dot com)
* @author Mark Diggory (markd at atmire dot com)
* @author Ben Bosman (ben at atmire dot com)
*/
public class CollectionViewer extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/** Language Strings */
private static final Message T_dspace_home =
message("xmlui.general.dspace_home");
public static final Message T_untitled =
message("xmlui.general.untitled");
/** Cached validity object */
private SourceValidity validity;
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey()
{
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso == null)
{
return "0";
}
return HashUtil.hash(dso.getHandle());
}
catch (SQLException sqle)
{
// Ignore all errors and just return that the component is not
// cachable.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The validity object will include the collection being viewed and
* all recently submitted items. This does not include the community / collection
* hierarch, when this changes they will not be reflected in the cache.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
Collection collection = null;
try
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso == null)
{
return null;
}
if (!(dso instanceof Collection))
{
return null;
}
collection = (Collection) dso;
DSpaceValidity validity = new DSpaceValidity();
// Add the actual collection;
validity.add(collection);
this.validity = validity.complete();
}
catch (Exception e)
{
// Just ignore all errors and return an invalid cache.
}
}
return this.validity;
}
/**
* Add a page title and trail links.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Collection))
{
return;
}
Collection collection = (Collection) dso;
// Set the page title
String name = collection.getMetadata("name");
if (name == null || name.length() == 0)
{
pageMeta.addMetadata("title").addContent(T_untitled);
}
else
{
pageMeta.addMetadata("title").addContent(name);
}
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
HandleUtil.buildHandleTrail(collection,pageMeta,contextPath);
// Add RSS links if available
String formats = ConfigurationManager.getProperty("webui.feed.formats");
if ( formats != null )
{
for (String format : formats.split(","))
{
// Remove the protocol number, i.e. just list 'rss' or' atom'
String[] parts = format.split("_");
if (parts.length < 1)
{
continue;
}
String feedFormat = parts[0].trim()+"+xml";
String feedURL = contextPath+"/feed/"+format.trim()+"/"+collection.getHandle();
pageMeta.addMetadata("feed", feedFormat).addContent(feedURL);
}
}
}
/**
* Display a single collection
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Collection))
{
return;
}
// Set up the major variables
Collection collection = (Collection) dso;
// Build the collection viewer division.
Division home = body.addDivision("collection-home", "primary repository collection");
String name = collection.getMetadata("name");
if (name == null || name.length() == 0)
{
home.setHead(T_untitled);
}
else
{
home.setHead(name);
}
// The search / browse box placeholder, this division will be populated either in the browse or discovery aspect
{
home.addDivision("collection-search-browse",
"secondary search-browse");
}
// Add the reference
{
Division viewer = home.addDivision("collection-view","secondary");
ReferenceSet mainInclude = viewer.addReferenceSet("collection-view",
ReferenceSet.TYPE_DETAIL_VIEW);
mainInclude.addReference(collection);
}
}
/**
* Recycle
*/
public void recycle()
{
// Clear out our item's cache.
this.validity = null;
super.recycle();
}
}