<%@ page language="java" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.Sessions" %> <%@ page import="org.crosswire.utils.HTTPUtils" %> <%@ page import="org.crosswire.webtools.RightsAndRoles" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Page" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Surrogate.SurrogateImage" %> <%@ page import="java.net.URL" %> <%@ page import="java.awt.Graphics2D" %> <%@ page import="java.awt.image.BufferedImage" %> <%@ page import="javax.imageio.ImageIO" %> <%@ page import="java.io.ByteArrayOutputStream" %> <%@ page import="org.apache.commons.codec.binary.Base64" %> <%@ page import="org.apache.log4j.Logger" %> <% Logger logger = Logger.getLogger("image/get"); String userName = Sessions.getSessionStringValue(request, "userName"); StringBuffer imageData = new StringBuffer(); Integer docID = null; try { docID = Integer.parseInt(request.getParameter("d")); } catch (Exception e) {} Integer pageID = null; try { pageID = Integer.parseInt(request.getParameter("p")); } catch (Exception e) {} String surrID = request.getParameter("s"); String url = request.getParameter("url"); String callback = request.getParameter("callback"); String attribution = callback == null ? "|" : ""; if (url != null && callback != null) { String type="jpeg"; if (url.endsWith(".png")) type = "png"; response.setContentType("text/javascript"); url = url.replaceAll(" ", "%20"); imageData.append(callback + "(\"data:image/"+type+";base64,").append(HTTPUtils.postURL(url, "", null, null, null, HTTPUtils.GET, true)).append("\")"); } else if (url != null) { String type="jpeg"; if (url.endsWith(".png")) type = "png"; response.setContentType("text/html"); url = url.replaceAll(" ", "%20"); imageData.append(HTTPUtils.postURL(url, "", null, null, null, HTTPUtils.GET, true)); } else if (docID != null && pageID != null && surrID != null) { // let's check to see if we're a privileged user int contentAccessLevel = 0; contentAccessLevel = RightsAndRoles.hasRole(request, response, "Internal User") ? Math.max(2, contentAccessLevel) : contentAccessLevel; contentAccessLevel = RightsAndRoles.hasRole(request, response, "Expert User") ? Math.max(1, contentAccessLevel) : contentAccessLevel; logger.debug("userName: " + userName + "; ContentAccessLevel: " + contentAccessLevel); Page p = Page.getPage(docID, pageID); try { Document d = Document.getDocument(docID); if (d != null) d.addCSNTMSurrogates(new Page[]{p}); } catch (Exception e) { e.printStackTrace(); } p.setContentAccessLevel(contentAccessLevel); response.setContentType("image/jpeg"); //System.out.println(p.getSurrogateImages().length); for (SurrogateImage i : p.getSurrogateImages()) { //System.out.println("SID: " + i.getSurrogateID()); //System.out.println("surrID: " + surrID); if (surrID.equals(i.getSurrogateID())) { if (i.getProtectLevel() < 1) { imageData.append(i.getWebFriendlyURL()); } else { if (i.getWebFriendlyURL().toUpperCase().endsWith(".TIF") || i.getWebFriendlyURL().toUpperCase().endsWith(".TIFF")) { BufferedImage image = ImageIO.read(new URL(i.getWebFriendlyURL())); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); BufferedImage zimage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = zimage.createGraphics(); g.drawImage(image, 0, 0, imageWidth, imageHeight, null); g.dispose(); ByteArrayOutputStream imgData = new ByteArrayOutputStream(); ImageIO.write(zimage, "jpg", imgData); imageData.append("enc://"); imageData.append(Base64.encodeBase64String(imgData.toByteArray())); } else { imageData.append("enc://"); String wfURL = i.getWebFriendlyURL().replaceAll(" ", "%20"); imageData.append(HTTPUtils.postURL(wfURL, "", null, null, null, HTTPUtils.GET, true)); } } if (i.getAttribution() != null && i.getAttribution().length() > 0) attribution = i.getAttribution() + "|"; //System.out.println(imageData.length()); break; } } } %><%=attribution%><%=imageData%>