forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CommunityViewer.java
355 lines (296 loc) · 12 KB
/
CommunityViewer.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* 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 java.util.Map;
import java.util.HashMap;
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.List;
import org.dspace.app.xmlui.wing.element.Reference;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.authorize.AuthorizeException;
import org.dspace.browse.BrowseException;
import org.dspace.browse.BrowseIndex;
import org.dspace.browse.ItemCountException;
import org.dspace.browse.ItemCounter;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
import org.xml.sax.SAXException;
/**
* Display a single community. This includes a full text search, browse by list,
* community display and a list of recent submissions.
* private static final Logger log = Logger.getLogger(DSpaceFeedGenerator.class);
* @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 CommunityViewer 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");
private static final Message T_head_browse =
message("xmlui.ArtifactBrowser.CommunityViewer.head_browse");
private static final Message T_browse_titles =
message("xmlui.ArtifactBrowser.CommunityViewer.browse_titles");
private static final Message T_browse_authors =
message("xmlui.ArtifactBrowser.CommunityViewer.browse_authors");
private static final Message T_browse_dates =
message("xmlui.ArtifactBrowser.CommunityViewer.browse_dates");
private static final Message T_head_sub_communities =
message("xmlui.ArtifactBrowser.CommunityViewer.head_sub_communities");
private static final Message T_head_sub_collections =
message("xmlui.ArtifactBrowser.CommunityViewer.head_sub_collections");
/** 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"; // no item, something is wrong
}
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.
*
* This validity object includes the community being viewed, all
* sub-communites (one level deep), all sub-collections, and
* recently submitted items.
*/
public SourceValidity getValidity()
{
if (this.validity == null)
{
Community community = null;
try {
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso == null)
{
return null;
}
if (!(dso instanceof Community))
{
return null;
}
community = (Community) dso;
DSpaceValidity validity = new DSpaceValidity();
validity.add(community);
Community[] subCommunities = community.getSubcommunities();
Collection[] collections = community.getCollections();
// Sub communities
for (Community subCommunity : subCommunities)
{
validity.add(subCommunity);
// Include the item count in the validity, only if the value is cached.
boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
if (useCache)
{
try {
int size = new ItemCounter(context).getCount(subCommunity);
validity.add("size:"+size);
} catch(ItemCountException e) { /* ignore */ }
}
}
// Sub collections
for (Collection collection : collections)
{
validity.add(collection);
// Include the item count in the validity, only if the value is cached.
boolean useCache = ConfigurationManager.getBooleanProperty("webui.strengths.cache");
if (useCache)
{
try {
int size = new ItemCounter(context).getCount(collection);
validity.add("size:"+size);
} catch(ItemCountException e) { /* ignore */ }
}
}
this.validity = validity.complete();
}
catch (Exception e)
{
// Ignore all errors and invalidate the cache.
}
}
return this.validity;
}
/**
* Add the community's title and trail links to the page's metadata
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Community))
{
return;
}
// Set up the major variables
Community community = (Community) dso;
// Set the page title
String name = community.getMetadata("name");
if (name == null || name.length() == 0)
{
pageMeta.addMetadata("title").addContent(T_untitled);
}
else
{
pageMeta.addMetadata("title").addContent(name);
}
// Add the trail back to the repository root.
pageMeta.addTrailLink(contextPath + "/",T_dspace_home);
HandleUtil.buildHandleTrail(community, 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()+"/"+community.getHandle();
pageMeta.addMetadata("feed", feedFormat).addContent(feedURL);
}
}
}
/**
* Display a single community (and reference any sub communites or
* collections)
*/
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Community))
{
return;
}
// Set up the major variables
Community community = (Community) dso;
Community[] subCommunities = community.getSubcommunities();
Collection[] collections = community.getCollections();
// Build the community viewer division.
Division home = body.addDivision("community-home", "primary repository community");
String name = community.getMetadata("name");
if (name == null || name.length() == 0)
{
home.setHead(T_untitled);
}
else
{
home.setHead(name);
}
// The search / browse box.
{
Division search = home.addDivision("community-search-browse",
"secondary search-browse");
// TODO: move browse stuff out of here
// Browse by list
Division browseDiv = search.addDivision("community-browse","secondary browse");
List browse = browseDiv.addList("community-browse", List.TYPE_SIMPLE,
"community-browse");
browse.setHead(T_head_browse);
String url = contextPath + "/handle/" + community.getHandle();
try
{
// Get a Map of all the browse tables
BrowseIndex[] bis = BrowseIndex.getBrowseIndices();
for (BrowseIndex bix : bis)
{
// Create a Map of the query parameters for this link
Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put("type", bix.getName());
// Add a link to this browse
browse.addItemXref(super.generateURL(url + "/browse", queryParams),
message("xmlui.ArtifactBrowser.Navigation.browse_" + bix.getName()));
}
}
catch (BrowseException bex)
{
browse.addItemXref(url + "/browse?type=title",T_browse_titles);
browse.addItemXref(url + "/browse?type=author",T_browse_authors);
browse.addItemXref(url + "/browse?type=dateissued",T_browse_dates);
}
}
// Add main reference:
{
Division viewer = home.addDivision("community-view","secondary");
ReferenceSet referenceSet = viewer.addReferenceSet("community-view",
ReferenceSet.TYPE_DETAIL_VIEW);
Reference communityInclude = referenceSet.addReference(community);
// If the community has any children communities also reference them.
if (subCommunities != null && subCommunities.length > 0)
{
ReferenceSet communityReferenceSet = communityInclude
.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
communityReferenceSet.setHead(T_head_sub_communities);
// Subcommunities
for (Community subCommunity : subCommunities)
{
communityReferenceSet.addReference(subCommunity);
}
}
if (collections != null && collections.length > 0)
{
ReferenceSet communityReferenceSet = communityInclude
.addReferenceSet(ReferenceSet.TYPE_SUMMARY_LIST,null,"hierarchy");
communityReferenceSet.setHead(T_head_sub_collections);
// Subcollections
for (Collection collection : collections)
{
communityReferenceSet.addReference(collection);
}
}
} // main reference
}
/**
* Recycle
*/
public void recycle()
{
// Clear out our item's cache.
this.validity = null;
super.recycle();
}
}