/**
* 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.browseArtifacts;
import org.apache.cocoon.ProcessingException;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
import org.dspace.app.xmlui.utils.HandleUtil;
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.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.browse.BrowseException;
import org.dspace.browse.BrowseIndex;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* Renders the browse links for a collection
*
* @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 CollectionBrowse extends AbstractDSpaceTransformer {
private static final Message T_head_browse =
message("xmlui.ArtifactBrowser.CollectionViewer.head_browse");
private static final Message T_browse_titles =
message("xmlui.ArtifactBrowser.CollectionViewer.browse_titles");
private static final Message T_browse_authors =
message("xmlui.ArtifactBrowser.CollectionViewer.browse_authors");
private static final Message T_browse_dates =
message("xmlui.ArtifactBrowser.CollectionViewer.browse_dates");
@Override
public void addBody(Body body) throws SAXException, WingException, SQLException, IOException, AuthorizeException, ProcessingException {
DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
if (!(dso instanceof Collection))
{
return;
}
// Set up the major variables
Collection collection = (Collection) dso;
Division home = body.addDivision("collection-home", "primary repository collection");
Division search = home.addDivision("collection-search-browse",
"secondary search-browse");
// Browse by list
Division browseDiv = search.addDivision("collection-browse", "secondary browse");
List browse = browseDiv.addList("collection-browse", List.TYPE_SIMPLE,
"collection-browse");
browse.setHead(T_head_browse);
String url = contextPath + "/handle/" + collection.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(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);
}
}
}