<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ 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="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ 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 = "Submit a new image association for a manuscript page.", name = "image/put") public static class MyParameters extends Parameters { @NotNull @Description(value = "manuscript id for the image", example = "10046") public Integer docID; @NotNull @Description(value = "page id for the image", example = "10") public Integer pageID; @Description(value = "surrogate id for the image. If not given, one will be assigned", example = "10") public String surrID; @Description(value = "image uri", example = "") public String uri; @Description(value = "distribution license id. [0 - public, 1 - expert access]", example = "0") public Integer distLicID; @Description(value = "level of protect for image. Higher levels make it harder to grab image from viewer, but also make loading slower and sometimes disable caching. Default: 0", example = "99") public Integer protectLevel; @Description(value = "credit attribution which should be associated with image", example = "Image courtesy of XYZ Library") public String attribution; @Override protected void afterLoad() { attribution = Transcription.assureUnicode(attribution); } @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) { do { String role = "VMR Administrator"; boolean permission = params.getUser().hasRole(role); 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) { Document doc = Document.getDocument(params.docID); if (doc == null || !params.getUser().getUserName().equals(doc.getUserID())) { params.addError(-5, "User does not own this document nor has the role: " + role + "."); break; } } Page p = Page.getPage(params.docID, params.pageID); if (p == null) { params.addError(-6, "Document docID: " + params.docID + "; pageID: " + params.pageID + " not found."); break; } SurrogateImage surrogateImage = null; // if we've been given a surrID, then we'll see if we can find an existing object to modify if (params.surrID != null) { for (SurrogateImage si : p.getSurrogateImages()) { if (params.surrID.equals(si.getSurrogateID())) { surrogateImage = si; } } } if (surrogateImage != null) { if (params.uri != null) surrogateImage.setURL(params.uri); if (params.distLicID != null) surrogateImage.setDistributionLicenseID(params.distLicID); if (params.protectLevel != null) surrogateImage.setProtectLevel(params.protectLevel); if (params.attribution != null) surrogateImage.setAttribution(params.attribution); p.removeSurrogateImage(surrogateImage.getSurrogateID()); } else { surrogateImage = new SurrogateImage(p, params.uri, params.uri, (params.distLicID != null ? params.distLicID : 0), (params.protectLevel != null ? params.protectLevel : 0), params.attribution, params.getUser().getUserName()); } // add userID in case we removed the image and didn't specify the userID in the delete filter surrogateImage.setUserID(params.getUser().getUserName()); p.addSurrogateImage(surrogateImage); Serializer.output(response, out, params, XMLBlock.createXMLBlock("")); return; } while (false); } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>