%@ 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="java.util.Arrays" %>
<%@ page import="java.util.Collections" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ShelfInstance" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Document" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="java.util.Arrays" %>
<%!
@Description(value = "Retrieve detailed information about a shelfinstance.", name = "shelfinstance/get")
public static class MyParameters extends Parameters {
private List docIDList;
private List instIDList;
private List shelfIDList;
@Description(value = "id of the individual shelf instance to retrieve", defaultValue = "must specify one of {shelfID}, {docID}, {gaNum}, or {instID}", example = "149297")
public String shelfID;
@Description(value = "id of the manuscript for which to retrieve all shelf instances", example = "10046")
public String docID;
@Description(value = "primary name (as in, Gregory-Aland number) of the manuscript for which to retrieve all shelf instances", example = "P46")
public String gaNum;
@Description(value = "id of the institution for which to retrieve all shelf instances", example = "149")
public String instID;
@Description(value = "whether or not to include manuscript features", defaultValue = "false", example = "true")
public Boolean includeManuscriptFeatures = false;
@Description(value = "[header|complete|extra]", defaultValue = "complete", example = "header")
public String detail;
@Override
protected void customValidation() {
if (shelfID == null && docID == null && gaNum == null && instID == null) {
addError(-4, "must specify one of {shelfID}, {docID}, {gaNum}, or {instID}");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
int detail = ShelfInstance.parseDetail(params.detail, ShelfInstance.DETAIL_COMPLETE);
if (params.gaNum != null) {
Document doc = Document.getDocumentByGANumber(params.gaNum);
if (doc != null) params.docIDList = new ArrayList(Arrays.asList(doc.getDocumentID()));
}
params.getLogger().info(params.docIDList);
List insts = new ArrayList();
if (params.shelfIDList != null) {
for (int i : params.shelfIDList) {
ShelfInstance si = ShelfInstance.getShelfInstance(i);
if (si != null) {
insts.add(si);
}
}
}
else if (params.instIDList != null) {
for (int i : params.instIDList) {
insts.addAll(Arrays.asList(ShelfInstance.getShelfInstances(i, detail == ShelfInstance.DETAIL_EXTRA)));
}
}
else if (params.docIDList != null) {
for (int i : params.docIDList) {
insts.addAll(Arrays.asList(ShelfInstance.getShelfInstancesHoldingDocument(i)));
}
}
if (insts.isEmpty()) {
params.addError(-6, "no shelf instances found.");
}
else {
StringBuffer retVal = new StringBuffer();
retVal.append("");
Collections.sort(insts);
for (ShelfInstance si : insts) {
si.setIncludeManuscriptFeatures(params.includeManuscriptFeatures);
retVal.append(si.toFormattedXML(detail));
}
retVal.append("");
Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString()));
return;
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>