forked from DSpace/DSpace
/
Navigation.java
149 lines (127 loc) · 4.81 KB
/
Navigation.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
/**
* 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.discovery;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.NOPValidity;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.app.xmlui.utils.UIException;
import org.dspace.app.xmlui.wing.WingException;
import org.dspace.app.xmlui.wing.element.Options;
import org.dspace.app.xmlui.wing.element.PageMeta;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.xml.sax.SAXException;
/**
* Navigation that adds code needed for discovery search
*
* @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 Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent
{
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.
*/
public Serializable getKey() {
try {
Request request = ObjectModelHelper.getRequest(objectModel);
String key = request.getScheme() + request.getServerName() + request.getServerPort() + request.getSitemapURI() + request.getQueryString();
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (dso != null)
{
key += "-" + dso.getHandle();
}
return HashUtil.hash(key);
}
catch (SQLException sqle)
{
// Ignore all errors and just return that the component is not cachable.
return "0";
}
}
/**
* Generate the cache validity object.
*
* The cache is always valid.
*/
public SourceValidity getValidity() {
return NOPValidity.SHARED_INSTANCE;
}
/**
* Add the basic navigational options:
*
* Search - advanced search
*
* browse - browse by Titles - browse by Authors - browse by Dates
*
* language FIXME: add languages
*
* context no context options are added.
*
* action no action options are added.
*/
public void addOptions(Options options) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
// DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
// List test = options.addList("browse");
// List discovery = options.addList("discovery-search");
// discovery.setHead("Discovery");
//
// discovery.addItem().addXref(contextPath + "/discover" , "Discover");
/*
List browse = options.addList("browse");
browse.setHead(T_head_browse);
List browseGlobal = browse.addList("global");
List browseContext = browse.addList("context");
browseGlobal.setHead(T_head_all_of_dspace);
if (dso != null)
{
if (dso instanceof Collection)
{
browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Al" + dso.getID(), T_head_this_collection );
}
if (dso instanceof Community)
{
browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Am" + dso.getID(), T_head_this_community );
}
}
browseGlobal.addItem().addXref(contextPath + "/community-list", T_head_all_of_dspace );
*/
/* regulate the ordering */
options.addList("discovery");
options.addList("browse");
options.addList("account");
options.addList("context");
options.addList("administrative");
}
/**
* Insure that the context path is added to the page meta.
*/
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, UIException, SQLException, IOException,
AuthorizeException
{
// Add metadata for quick searches:
pageMeta.addMetadata("search", "simpleURL").addContent(
contextPath + "/discover");
pageMeta.addMetadata("search", "advancedURL").addContent(
contextPath + "/discover");
pageMeta.addMetadata("search", "queryField").addContent("query");
}
}