📄 itemlisttag.java
字号:
/* * ItemListTag.java * * Version: $Revision: 1.30 $ * * Date: $Date: 2006/04/05 02:15:45 $ * * 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.dspace.app.webui.util.UIUtil;import org.dspace.authorize.AuthorizeManager;import org.dspace.content.Bitstream;import org.dspace.content.Bundle;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.Context;import org.dspace.core.Utils;import org.dspace.storage.bitstore.BitstreamStorageManager;import java.awt.image.BufferedImage;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import java.sql.SQLException;import java.util.StringTokenizer;import javax.imageio.ImageIO;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;/** * Tag for display a list of items * * @author Robert Tansley * @version $Revision: 1.30 $ */public class ItemListTag extends TagSupport{ /** Items to display */ private Item[] items; /** Row to highlight, -1 for no row */ private int highlightRow = -1; /** Column to emphasise - null, "title" or "date" */ private String emphColumn; /** Config value of thumbnail view toggle */ private boolean showThumbs; /** Config browse/search width and height */ private int thumbItemListMaxWidth; private int thumbItemListMaxHeight; /** Config browse/search thumbnail link behaviour */ private boolean linkToBitstream = false; /** The default fields to be displayed when listing items */ private static String listFields = "dc.date.issued(date), dc.title, dc.contributor.*"; /** The default field which is bound to the browse by date */ private static String dateField = "dc.date.issued"; /** The default field which is bound to the browse by title */ private static String titleField = "dc.title"; public ItemListTag() { super(); getThumbSettings(); } public int doStartTag() throws JspException { JspWriter out = pageContext.getOut(); HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest(); boolean emphasiseDate = false; boolean emphasiseTitle = false; if (emphColumn != null) { emphasiseDate = emphColumn.equalsIgnoreCase("date"); emphasiseTitle = emphColumn.equalsIgnoreCase("title"); } // get the elements to display String configLine = ConfigurationManager.getProperty("webui.itemlist.columns"); if (configLine != null) { listFields = configLine; } // get the date and title fields String dateLine = ConfigurationManager.getProperty("webui.browse.index.date"); if (dateLine != null) { dateField = dateLine; } String titleLine = ConfigurationManager.getProperty("webui.browse.index.title"); if (titleLine != null) { titleField = titleLine; } StringTokenizer st = new StringTokenizer(listFields, ","); // make an array to hold all the frags that we will use int columns = st.countTokens(); String[] frags = new String[columns * items.length]; try { out.println("<table align=\"center\" class=\"miscTable\" summary=\"This table browse all dspace content\">"); out.println("<tr>"); // Write the column headings int colCount = 1; boolean isDate = false; boolean emph = false; while (st.hasMoreTokens()) { String field = st.nextToken().toLowerCase().trim(); String cOddOrEven = ((colCount % 2) == 0 ? "Odd" : "Even"); // find out if the field is a date if (field.indexOf("(date)") > 0) { field = field.replaceAll("\\(date\\)", ""); isDate = true; } // get the schema and the element qualifier pair // (Note, the schema is not used for anything yet) // (second note, I hate this bit of code. There must be // a much more elegant way of doing this. Tomcat has // some weird problems with variations on this code that // I tried, which is why it has ended up the way it is) StringTokenizer eq = new StringTokenizer(field, "."); String[] tokens = { "", "", "" }; int k = 0; while(eq.hasMoreTokens()) { tokens[k] = eq.nextToken().toLowerCase().trim(); k++; } String schema = tokens[0]; String element = tokens[1]; String qualifier = tokens[2]; // find out if we are emphasising this field if ((field.equals(dateField) && emphasiseDate) || (field.equals(titleField) && emphasiseTitle)) { emph = true; } // prepare the strings for the header String id = "t" + Integer.toString(colCount); String css = "oddRow" + cOddOrEven + "Col"; String message = "itemlist." + field; // output the header out.print("<th id=\"" + id + "\" class=\"" + css + "\">" + (emph ? "<strong>" : "") + LocaleSupport.getLocalizedMessage(pageContext, message) + (emph ? "</strong>" : "") + "</th>"); // now prepare the frags for each of the table elements for (int i = 0; i < items.length; i++) { // first get hold of the relevant metadata for this column DCValue[] metadataArray; if (qualifier.equals("*")) { metadataArray = items[i].getMetadata(schema, element, Item.ANY, Item.ANY); } else if (qualifier.equals("")) { metadataArray = items[i].getMetadata(schema, element, null, Item.ANY); } else { metadataArray = items[i].getMetadata(schema, element, qualifier, Item.ANY); } // now prepare the content of the table division String metadata = "-"; if (metadataArray.length > 0) { // format the date field correctly if (isDate) { // this is to be consistent with the existing setup. // seems like an odd place to put it though (FIXME) String thumbs = ""; if (showThumbs) { thumbs = getThumbMarkup(hrq, items[i]); } DCDate dd = new DCDate(metadataArray[0].value); metadata = UIUtil.displayDate(dd, false, false) + thumbs; } // format the title field correctly else if (field.equals(titleField)) { metadata = "<a href=\"" + hrq.getContextPath() + "/handle/" + items[i].getHandle() + "\">" + Utils.addEntities(metadataArray[0].value) + "</a>"; } // format all other fields else { StringBuffer sb = new StringBuffer(); for (int j = 0; j < metadataArray.length; j++) { sb.append(Utils.addEntities(metadataArray[j].value)); if (j < (metadataArray.length - 1)) { sb.append("; "); } } metadata = "<em>" + sb.toString() + "</em>"; } } // now prepare the XHTML frag for this division String rOddOrEven; if (i == highlightRow) { rOddOrEven = "highlight"; } else { rOddOrEven = ((i % 2) == 1 ? "odd" : "even"); } // prepare extra special layout requirements for dates String extras = ""; if (isDate) { extras = "nowrap=\"nowrap\" align=\"right\""; } int idx = ((i + 1) * columns) - columns + colCount - 1; frags[idx] = "<td headers=\"" + id + "\" class=\"" + rOddOrEven + "Row" + cOddOrEven + "Col\" " + extras + ">" + (emph ? "<strong>" : "") + metadata + (emph ? "</strong>" : "") + "</td>"; } colCount++; isDate = false; emph = false; } out.println("</tr>"); // now output all the frags in the right order for the page for (int i = 0; i < frags.length; i++) { if ((i + 1) % columns == 1) { out.println("<tr>"); } out.println(frags[i]); if ((i + 1) % columns == 0) { out.println("</tr>"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -