<%@ 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.community.projects.ntmss.data.Page" %> <%@ 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" %> <% String userName = Sessions.getSessionStringValue(request, "userName"); StringBuffer imageData = new StringBuffer(); String docID = request.getParameter("d"); String pageID = request.getParameter("p"); String surrID = request.getParameter("s"); String url = request.getParameter("url"); String callback = request.getParameter("callback"); String attribution = ""; if (url != null && callback != null) { String type="jpeg"; if (url.endsWith(".png")) type = "png"; response.setContentType("text/javascript"); imageData.append(callback + "(\"data:image/"+type+";base64,").append(HTTPUtils.postURL(url, "", null, null, null, HTTPUtils.GET, true)).append("\")"); } else if (docID != null && pageID != null && surrID != null) { // let's check to see if we're a privileged user int contentAccessLevel = 0; contentAccessLevel = Sessions.hasRole(request, "Internal User") ? Math.max(2, contentAccessLevel) : contentAccessLevel; contentAccessLevel = Sessions.hasRole(request, "Expert User") ? Math.max(1, contentAccessLevel) : contentAccessLevel; //System.out.println("ContentAccessLevel: " + contentAccessLevel); Page p = Page.getPage(Integer.parseInt(docID), Integer.parseInt(pageID)); 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.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 = new StringBuffer(); imageData.append(Base64.encodeBase64String(imgData.toByteArray())); } else { imageData=HTTPUtils.postURL(i.getWebFriendlyURL(), "", 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%>