%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Feature" %>
<%@ 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.*" %>
<%!
@Description(value = "Retrieve list of feature tags associated with a manuscript or manuscript page", name = "feature/get")
public static class MyParameters extends Parameters {
@Description(value = "manuscript ID to query", example = "10046")
public Integer docID = null;
@Description(value = "manuscript primary name to query", example = "P46")
public String gaNum = null;
@Description(value = "page ID to query. if not present or -1, then all features; if -2, then only manuscript features (not page features", example = "10")
public Integer pageID = null;
@Description(value = "feature ID to retrieve", example = "123")
public Integer featureID = null;
@Description(value = "get all featureCode instances", example = "IlluminatedLetters")
public String featureCode = null;
@Override
protected void customValidation() {
if (gaNum != null) {
Document doc = Document.getDocumentByGANumber(gaNum);
if (doc != null) {
docID = doc.getDocumentID();
}
else addError(-5, "{gaNum} supplied could not be found.");
}
if (docID == null && featureID == null && featureCode == null) {
addError(-4, "Must provide at least one of: {docID}, {gaNum}, {featureID}, {featureCode}.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
Feature features[] = null;
if (params.featureID != null && params.featureID > -1) {
features = new Feature[1];
features[0] = Feature.getFeature(params.featureID);
}
else features = Feature.getFeatures(params.docID != null ? params.docID : -1, params.pageID != null ? params.pageID : -1, params.featureCode);
if (features != null && (features.length < 1 || features[0] != null)) {
StringBuffer retVal = new StringBuffer("");
for (Feature f : features) {
retVal.append(f.toFormattedXML());
}
retVal.append("");
Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString()));
return;
}
else {
if (features.length == 1 && features[0] == null) params.addError(-6, "featureID: " + params.featureID + " not found.");
else if (params.pageID != null) params.addError(-7, "docID: " + params.docID + "; pageID: " + params.pageID + " not found.");
else params.addError(-8, "docID: " + params.docID + " not found.");
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>