001: /*
002: * ItemPreviewTag.java
003: *
004: * Version: $Revision: 1426 $
005: *
006: * Date: $Date: 2006-03-10 14:22:52 -0600 (Fri, 10 Mar 2006) $
007: *
008: * Copyright (c) 2002-2006, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.webui.jsptag;
041:
042: import org.dspace.app.webui.util.UIUtil;
043:
044: import org.dspace.content.Bitstream;
045: import org.dspace.content.Bundle;
046: import org.dspace.content.DCValue;
047: import org.dspace.content.Item;
048:
049: import org.dspace.core.ConfigurationManager;
050: import org.dspace.core.Constants;
051: import org.dspace.core.Utils;
052:
053: import java.io.IOException;
054: import java.sql.SQLException;
055:
056: import javax.servlet.http.HttpServletRequest;
057: import javax.servlet.jsp.JspException;
058: import javax.servlet.jsp.JspWriter;
059: import javax.servlet.jsp.tagext.TagSupport;
060:
061: /**
062: * <p>
063: * JSP tag for displaying a preview version of an item. For this tag to
064: * output anything, the preview feature must be activated in DSpace.
065: * </p>
066: *
067: * @author Scott Yeadon
068: * @version $Revision: 1426 $
069: */
070: public class ItemPreviewTag extends TagSupport {
071: /** Item to display */
072: private Item item;
073:
074: public ItemPreviewTag() {
075: super ();
076: }
077:
078: public int doStartTag() throws JspException {
079: if (!ConfigurationManager
080: .getBooleanProperty("webui.preview.enabled")) {
081: return SKIP_BODY;
082: }
083: try {
084: showPreview();
085: } catch (SQLException sqle) {
086: throw new JspException(sqle);
087: } catch (IOException ioe) {
088: throw new JspException(ioe);
089: }
090:
091: return SKIP_BODY;
092: }
093:
094: public void setItem(Item itemIn) {
095: item = itemIn;
096: }
097:
098: private void showPreview() throws SQLException, IOException {
099: JspWriter out = pageContext.getOut();
100:
101: // Only shows 1 preview image at the moment (the first encountered) regardless
102: // of the number of bundles/bitstreams of this type
103: Bundle[] bundles = item.getBundles("BRANDED_PREVIEW");
104:
105: if (bundles.length > 0) {
106: Bitstream[] bitstreams = bundles[0].getBitstreams();
107:
108: HttpServletRequest request = (HttpServletRequest) pageContext
109: .getRequest();
110: out.println("<br/><p align=\"center\">");
111: out.println("<img src=\""
112: + request.getContextPath()
113: + "/retrieve/"
114: + bitstreams[0].getID()
115: + "/"
116: + UIUtil.encodeBitstreamName(bitstreams[0]
117: .getName(), Constants.DEFAULT_ENCODING)
118: + "\"/>");
119:
120: // Currently only one metadata item supported. Only the first match is taken
121: String s = ConfigurationManager
122: .getProperty("webui.preview.dc");
123: if (s != null) {
124: DCValue[] dcValue;
125:
126: int i = s.indexOf('.');
127:
128: if (i == -1) {
129: dcValue = item.getDC(s, Item.ANY, Item.ANY);
130: } else {
131: dcValue = item.getDC(s.substring(0, 1), s
132: .substring(i + 1), Item.ANY);
133: }
134:
135: if (dcValue.length > 0) {
136: out.println("<br/>" + dcValue[0].value);
137: }
138: }
139:
140: out.println("</p>");
141: }
142: }
143:
144: public void release() {
145: item = null;
146: }
147: }
|