<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.Utils" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Page" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Surrogate.SurrogateImage" %> <%@ page import="java.util.Set" %> <%@ page import="java.util.HashSet" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="javax.validation.constraints.NotNull" %> <%! @Description(value = "Generate a new image thumbnail for a manuscript page image.", name = "image/generatethumb") public static class MyParameters extends Parameters { protected Set pageIDs = new HashSet(); @NotNull @Description(value = "manuscript id of the image", example = "10046") public Integer docID; @Description(value = "page id of the image (can repeat). If not given, all images of all pages will be generated", example = "10") public Integer pageID; /* TODO: Not finished yet @NotNull @Description(value = "surrogate id of the image. If not given, all images a a page will be generated", example = "10") public String surrID; */ @Override protected void afterLoad() { String pageIDStrings[] = request.getParameterValues("pageID"); if (pageIDStrings != null && pageIDStrings.length > 0) { for (String p : pageIDStrings) { try { pageIDs.add(Integer.parseInt(p));} catch (Exception e){} } } } @Override protected void customValidation() { if (getUser() == null) { addError(-5, "Must be logged in."); return; } } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0) { Document doc = Document.getDocument(params.docID); if (doc == null) { params.addError(-6, "Document docID: " + params.docID + " not found."); } else { String role = "VMR Administrator"; boolean permission = params.getUser().hasRole(role) || (params.getUser().getUserName().equals(doc.getUserID())); if (!permission) { params.getUser().includeUserRoles(); XMLBlock ur = params.getUser().getBlock("userRoles"); if (ur != null) { XMLBlock rs[] = ur.getBlocks("role"); for (XMLBlock r : rs) { String roleName = r.getAttribute("roleName"); if (roleName.startsWith("Catalog Admin:")) { try { int min = Integer.parseInt(roleName.split(":")[1].split("-")[0].trim()); int max = Integer.parseInt(roleName.split("-")[1].trim()); if (params.docID >= min && params.docID <= max) permission = true; } catch(Exception e) {} } } } } if (!permission) { params.addError(-7, "User is not the owner of this document nor has the role: " + role + "."); } else { int count = 0; String imagesRootFolder = Utils.getSysConfig(session).getProperty("ImagesRootFolder"); String imagesRootURL = Utils.getSysConfig(session).getProperty("ImagesRootURL"); if (!imagesRootFolder.endsWith("/")) imagesRootFolder += "/"; if (!imagesRootURL.endsWith("/")) imagesRootURL += "/"; String errors = ""; for (Page p : doc.getPages(true)) { if (!params.pageIDs.isEmpty() && !params.pageIDs.contains(p.getPageID())) continue; p.setContentAccessLevel(5); for (SurrogateImage img : p.getSurrogateImages()) { if (!img.generateThumbnail(imagesRootFolder +"thumbs/", imagesRootURL + "thumbs/", 240)) { if (errors.length() < 1) { errors = "Problem generating thumbnail for some pages:"; } errors += " " + p.getPageID(); } else ++count; } } // What do we do if we have errors? Well, we report success and state how many pages were successful. Hmmm. Not the worst that could happen. String retVal = ""; Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal)); return; } } } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>