1 40 package org.dspace.app.webui.jsptag; 41 42 import org.dspace.app.webui.util.UIUtil; 43 44 import org.dspace.content.Bitstream; 45 import org.dspace.content.Bundle; 46 import org.dspace.content.DCValue; 47 import org.dspace.content.Item; 48 49 import org.dspace.core.ConfigurationManager; 50 import org.dspace.core.Constants; 51 import org.dspace.core.Utils; 52 53 import java.io.IOException ; 54 import java.sql.SQLException ; 55 56 import javax.servlet.http.HttpServletRequest ; 57 import javax.servlet.jsp.JspException ; 58 import javax.servlet.jsp.JspWriter ; 59 import javax.servlet.jsp.tagext.TagSupport ; 60 61 70 public class ItemPreviewTag extends TagSupport 71 { 72 73 private Item item; 74 75 public ItemPreviewTag() 76 { 77 super(); 78 } 79 80 public int doStartTag() throws JspException 81 { 82 if (!ConfigurationManager.getBooleanProperty("webui.preview.enabled")) 83 { 84 return SKIP_BODY; 85 } 86 try 87 { 88 showPreview(); 89 } 90 catch (SQLException sqle) 91 { 92 throw new JspException (sqle); 93 } 94 catch (IOException ioe) 95 { 96 throw new JspException (ioe); 97 } 98 99 return SKIP_BODY; 100 } 101 102 public void setItem(Item itemIn) 103 { 104 item = itemIn; 105 } 106 107 private void showPreview() throws SQLException , IOException 108 { 109 JspWriter out = pageContext.getOut(); 110 111 Bundle[] bundles = item.getBundles("BRANDED_PREVIEW"); 114 115 if (bundles.length > 0) 116 { 117 Bitstream[] bitstreams = bundles[0].getBitstreams(); 118 119 HttpServletRequest request = (HttpServletRequest )pageContext.getRequest(); 120 out.println("<br/><p align=\"center\">"); 121 out.println("<img SRC=\"" 122 + request.getContextPath() + "/retrieve/" 123 + bitstreams[0].getID() + "/" 124 + UIUtil.encodeBitstreamName(bitstreams[0].getName(), 125 Constants.DEFAULT_ENCODING) 126 + "\"/>"); 127 128 String s = ConfigurationManager.getProperty("webui.preview.dc"); 130 if (s != null) 131 { 132 DCValue[] dcValue; 133 134 int i = s.indexOf('.'); 135 136 if (i == -1) 137 { 138 dcValue = item.getDC(s, Item.ANY, Item.ANY); 139 } 140 else 141 { 142 dcValue = item.getDC(s.substring(0,1), s.substring(i + 1), Item.ANY); 143 } 144 145 if (dcValue.length > 0) 146 { 147 out.println("<br/>" + dcValue[0].value); 148 } 149 } 150 151 out.println("</p>"); 152 } 153 } 154 155 public void release() 156 { 157 item = null; 158 } 159 } 160 | Popular Tags |