%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Sessions" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Regularization" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Regularization.RegularizationRule" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles.UserGroup" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%!
@Description(value = "Retrieve list of regularization rules.", name = "regularization/get")
public static class MyParameters extends Parameters {
protected ProjectManagement.Project project = null;
@Description(value = "retrieve a single rule by regularization rule id.", example = "1")
public Integer regID = -1;
@Description(value = "owner of rules", example = "jsmith")
public String userName;
@Description(value = "context verse for rules. If no verse is specified, only global rules will be returned", example = "jn.2.2")
public String indexContext = null;
@Description(value = "internal")
public String indexContent = null;
@Description(value = "internal")
public String verse = null;
@Description(value = "Project ID for which to retrieve rules", example = "1")
public Integer projectID;
@Description(value = "Project Name for which to retrieve rules", example = "ECM Matthew")
public String projectName;
@Description(value = "internal")
public String groupName;
@Description(value = "true or false whether to limit results to only rules marked public", example = "false", defaultValue = "true")
public Boolean publicOnly = null;
@Description(value = "true or false whether to include global rules in result", example = "true", defaultValue = "false")
public Boolean includeGlobals = null;
@Override
protected void afterLoad() {
// for backward compat of a typo and verse
if (projectName == null) projectName = groupName;
if (indexContext == null) indexContext = indexContent;
if (indexContext == null) indexContext = verse;
}
@Override
protected void customValidation() {
projectName = Transcription.assureUnicode(projectName);
if (projectID != null || projectName != null) {
project = projectID != null ? ProjectManagement.getProject(projectID) : ProjectManagement.getProject(projectName);
if (project == null) {
addError(-7, "Project not found.");
return;
}
}
userName = Transcription.assureUnicode(userName);
if ((regID == null || regID < 0) && userName == null && indexContext == null && publicOnly == null && includeGlobals == null) {
addError(-4, "Must supply at least one query filter.");
}
if (publicOnly == null) publicOnly = true;
if (includeGlobals == null) includeGlobals = false;
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
Vector regs = new Vector();
if (params.regID > -1) { RegularizationRule r = RegularizationRule.getRegularizationRule(params.regID, params.indexContext, params.userName, params.project != null ? params.project.getProjectName() : null); if (r != null) regs.add(r); }
else {
if (params.indexContext != null) regs.addAll(Arrays.asList(Regularization.getRulesByVerse(params.userName, params.publicOnly, params.indexContext, params.project != null ? params.project.getProjectName() : null)));
if (params.includeGlobals || (params.indexContext == null && params.regID < 0)) regs.addAll(Arrays.asList(Regularization.getRulesGlobal(params.userName, params.publicOnly, params.project != null ? params.project.getProjectName() : null, params.indexContext)));
}
if (params.regID < 0 || regs.size() > 0) {
StringBuffer retVal = new StringBuffer();
retVal.append("");
for (RegularizationRule r : regs) {
retVal.append(r.toFormattedXML());
}
retVal.append("");
XMLBlock result = XMLBlock.createXMLBlock(retVal.toString());
Serializer.output(response, out, params, result);
return;
}
else {
if (params.regID != -1) params.addError(-5, "regID: " + params.regID + " not found.");
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>