📄 itemtag.java
字号:
/* * ItemTag.java * * Version: $Revision: 1.40 $ * * Date: $Date: 2005/11/16 21:40:52 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.app.webui.jsptag;import org.apache.log4j.Logger;import org.dspace.app.webui.util.UIUtil;import org.dspace.content.Bitstream;import org.dspace.content.Bundle;import org.dspace.content.Collection;import org.dspace.content.DCDate;import org.dspace.content.DCValue;import org.dspace.content.Item;import org.dspace.core.ConfigurationManager;import org.dspace.core.Constants;import org.dspace.core.Utils;import java.io.IOException;import java.sql.SQLException;import java.util.Enumeration;import java.util.HashMap;import java.util.Map;import java.util.StringTokenizer;import javax.servlet.http.HttpServletRequest;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.jstl.fmt.LocaleSupport;import javax.servlet.jsp.tagext.TagSupport;/** * <P> * JSP tag for displaying an item. * </P> * <P> * The fields that are displayed can be configured in <code>dspace.cfg</code> * using the <code>webui.itemdisplay.(style)</code> property. The form is * </P> * * <PRE> * * <schema prefix>.<element>[.<qualifier>|.*][(date)|(link)], ... * * </PRE> * * <P> * For example: * </P> * * <PRE> * * dc.title = Dublin Core element 'title' (unqualified) dc.title.alternative = * DC element 'title', qualifier 'alternative' dc.title.* = All fields with * Dublin Core element 'title' (any or no qualifier) dc.identifier.uri(link) = * DC identifier.uri, render as a link dc.date.issued(date) = DC date.issued, * render as a date * * </PRE> * * <P> * If an item has no value for a particular field, it won't be displayed. The * name of the field for display will be drawn from the current UI dictionary, * using the key: * </P> * * <PRE> * * "metadata.<field>" * * e.g. "metadata.dc.title" "metadata.dc.contributor.*" * "metadata.dc.date.issued" * * </PRE> * * <P> * You can also specify which collections use which views. * </P> * * <PRE> * * webui.itemdisplay.<style>.collections = <collection handle>, ... * * </PRE> * * <P> * FIXME: This should be more database-driven * </P> * * <PRE> * * webui.itemdisplay.thesis.collections = 123456789/24, 123456789/35 * * </PRE> * * @author Robert Tansley * @version $Revision: 1.40 $ */public class ItemTag extends TagSupport{ /** Item to display */ private Item item; /** Collections this item appears in */ private Collection[] collections; /** The style to use - "default" or "full" */ private String style; /** Whether to show preview thumbs on the item page */ private boolean showThumbs; /** Hashmap of collection Handles to styles to use, from dspace.cfg */ private static Map collectionStyles; /** Default DC fields to display, in absence of configuration */ private static String defaultFields = "dc.title, dc.title.alternative, dc.contributor.*, dc.subject, dc.date.issued(date), dc.publisher, dc.identifier.citation, dc.relation.ispartofseries, dc.description.abstract, dc.description, dc.identifier.govdoc, dc.identifier.uri(link), dc.identifier.isbn, dc.identifier.issn, dc.identifier.ismn, dc.identifier"; /** log4j logger */ private static Logger log = Logger.getLogger(ItemTag.class); public ItemTag() { super(); getThumbSettings(); collectionStyles = null; } public int doStartTag() throws JspException { try { if (style == null || style.equals("")) { // see if we need to use a particular style for a style // FIXME?: Trust owning collection Collection owner = item.getOwningCollection(); if (owner != null) { getStyleFor(owner); } else { style = "default"; } } if (style.equals("full")) { renderFull(); } else { render(); } } catch (SQLException sqle) { throw new JspException(sqle); } catch (IOException ie) { throw new JspException(ie); } return SKIP_BODY; } /** * Get the item this tag should display * * @return the item */ public Item getItem() { return item; } /** * Set the item this tag should display * * @param itemIn * the item to display */ public void setItem(Item itemIn) { item = itemIn; } /** * Get the collections this item is in * * @return the collections */ public Collection[] getCollections() { return collections; } /** * Set the collections this item is in * * @param collectionsIn * the collections */ public void setCollections(Collection[] collectionsIn) { collections = collectionsIn; } /** * Get the style this tag should display * * @return the style */ public String getStyle() { return style; } /** * Set the style this tag should display * * @param styleIn * the Style to display */ public void setStyle(String styleIn) { style = styleIn; } public void release() { style = "default"; item = null; collections = null; } /** * Render an item in the given style */ private void render() throws IOException { JspWriter out = pageContext.getOut(); String configLine = ConfigurationManager .getProperty("webui.itemdisplay." + style); if (configLine == null) configLine = defaultFields; out.println("<center><table class=\"itemDisplayTable\">"); /* * Break down the configuration into fields and display them * * FIXME?: it may be more efficient to do some processing once, perhaps * to a more efficient intermediate class, but then it would become more * difficult to reload the configuration "on the fly". */ StringTokenizer st = new StringTokenizer(configLine, ","); while (st.hasMoreTokens()) { String field = st.nextToken().trim(); boolean isDate = false; boolean isLink = false; // Find out if the field should rendered as a date or link if (field.indexOf("(date)") > 0) { field = field.replaceAll("\\(date\\)", ""); isDate = true; } if (field.indexOf("(link)") > 0) { field = field.replaceAll("\\(link\\)", ""); isLink = true; } // Get the separate element + qualifier // TODO: Support for non-DC String[] eq = field.split("\\."); String element = eq[1]; String qualifier = null; if (eq.length > 2 && eq[2].equals("*")) { qualifier = Item.ANY; } else if (eq.length > 2) { qualifier = eq[2]; } // FIXME: Still need to fix for metadata language? DCValue[] values = item.getMetadata("dc", element, qualifier, Item.ANY); if (values.length > 0) { out.print("<tr><td class=\"metadataFieldLabel\">"); out.print(LocaleSupport.getLocalizedMessage(pageContext, "metadata." + field)); out.print(": </td><td class=\"metadataFieldValue\">"); for (int j = 0; j < values.length; j++) { if (j > 0) { out.print("<br />"); } if (isLink) { out.print("<a href=\"" + values[j].value + "\">" + Utils.addEntities(values[j].value) + "</a>"); } else if (isDate) { DCDate dd = new DCDate(values[j].value); // Parse the date out.print(UIUtil.displayDate(dd, false, false)); } else { out.print(Utils.addEntities(values[j].value)); } } out.println("</td></tr>"); } } listCollections(); out.println("</table></center><br/>"); listBitstreams(); if (ConfigurationManager .getBooleanProperty("webui.licence_bundle.show")) { out.println("<br/><br/>"); showLicence(); } } /** * Render full item record */ private void renderFull() throws IOException { JspWriter out = pageContext.getOut(); // Get all the metadata DCValue[] values = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY); out.println("<p align=\"center\">" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.full") + "</p>"); // Three column table - DC field, value, language out.println("<center><table class=\"itemDisplayTable\">"); out.println("<tr><th id=\"s1\" class=\"standard\">" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.dcfield") + "</th><th id=\"s2\" class=\"standard\">" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.value") + "</th><th id=\"s3\" class=\"standard\">" + LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.ItemTag.lang") + "</th></tr>"); for (int i = 0; i < values.length; i++) { boolean hidden = false; // Mask description.provenance if (values[i].element.equals("description") && ((values[i].qualifier != null) && values[i].qualifier .equals("provenance"))) { hidden = true; } if (!hidden)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -