%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ShelfInstance" %>
<%@ 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 = "Unlink a manuscript page from a shelf instance.", name = "shelfinstance/unlinkpage")
public static class MyParameters extends Parameters {
List pageIDs = new ArrayList();
@NotNull
@Description(value = "shelf id of the shelf instance", example = "146789")
public Integer shelfID;
@NotNull
@Description(value = "manuscript id for page(s) to unlink; if not passed, all pages of every document will be unlinked from this shelf instance", example = "10046")
public Integer docID;
@Description(value = "page id to unlink from the shelf instance; can repeat parameter or separate multiple pageIDs by |", example = "10|20|30")
public String pageID;
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in.");
return;
}
String pageIDStrings[] = request.getParameterValues("pageID");
if (pageIDStrings != null) {
for (String pgs : pageIDStrings) {
try { for (String p : pgs.split("\\|")) pageIDs.add(Integer.parseInt(p)); } catch (Exception e) {}
}
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
String role = "VMR Administrator";
boolean permission = params.getUser().hasRole(role);
if (!permission) {
params.addError(-6, "User does not have the role: " + role + ".");
}
else {
ShelfInstance si = ShelfInstance.getShelfInstance(params.shelfID);
if (si == null) {
params.addError(-7, "Couldn't find shelf instance, shelfID: " + params.shelfID + ".");
}
else {
int success = 0;
if (params.docID == null || params.pageID == null) {
success += si.unlinkPage(params.docID == null ? -1 : params.docID, -1);
}
else {
for (Integer pageID : params.pageIDs) {
success += si.unlinkPage(params.docID, pageID);
}
}
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>