<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.Utils" %> <%@ page import="org.crosswire.sword.mgr.VersificationMgr" %> <%@ page import="org.crosswire.sword.keys.VerseKey" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="javax.validation.constraints.Pattern" %> <%@ page import="java.util.Map" %> <%! @Description(value = "Retrieve detailed information about a versification system", name = "v11n/get") public static class MyParameters extends Parameters { @Description(value = "Versification ID to retrieve", example = "KJV") public String v11nid; @Description(value = "Level of detail [book, chapter]", defaultValue = "book", example = "chapter") public String detail; @Description(value = "Limit results to a subset of data [\"OT\", \"NT\", osisID]", example = "OT, John, John.1") public String subset; @Description(value = "show usage for this web service", defaultValue = "false", example = "true") public Boolean usage = false; @Description(value = "response output format [(xml), transcription, csv, json]", example="json", defaultValue = "xml") @Pattern(regexp = "^(xml|json|transcription|csv)([ +].+)?$", message = "Valid respose formats: \"xml\", \"transcription\", \"csv\", \"json\"") public String format = "xml"; @Override protected void customValidation() { if (v11nid == null && detail == null && subset == null) { addError(-1, "Must supply at least one of: {v11nid}, {detail}, {subset}."); } } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0 && !params.usage) { if (params.v11nid == null) params.v11nid = Utils.getSysConfig(session).getProperty("PrimaryVersification"); if (params.v11nid != null && VersificationMgr.getSystemVersificationMgr().getVersificationSystems().contains(params.v11nid)) { VerseKey verse = new VerseKey(); verse.setVersificationSystem(params.v11nid); int testamentMax = verse.getTestamentMax(); int limitChapter = -1; int limitBook = -1; if (params.subset != null) { if ("OT".equals(params.subset)) testamentMax = 1; else if ("NT".equals(params.subset)) verse.setTestament(2); else { int offset = params.subset.indexOf("."); String bookName = params.subset.substring(0,(offset<0)?params.subset.length():offset); limitChapter = -1; try { if (offset > -1) limitChapter = Integer.parseInt(params.subset.substring(offset+1)); } catch (Exception e) {} verse.setBookName(bookName); testamentMax = verse.getTestament(); limitBook = verse.getBook(); if (limitChapter > -1) verse.setChapter(limitChapter); } } StringBuffer retVal = new StringBuffer(); if ("transcription".equals(params.format)) { retVal.append("\n"); } else retVal.append(""); for (int t = verse.getTestament(); verse.popError() == 0 && t <= testamentMax; verse.setBook(1),verse.setTestament(++t)) { int testament = verse.getTestament(); if ("transcription".equals(params.format)) { } else retVal.append(""); int bookMax = verse.getBookMax(); for (int b = verse.getBook(); verse.popError() == 0 && b <= bookMax && (limitBook == -1 || limitBook == b); verse.setBook(++b)) { if ("transcription".equals(params.format)) { retVal.append("\n"); retVal.append("
\n"); } else { retVal.append(""); int chapterMax = verse.getChapterMax(); for (int c = verse.getChapter(); verse.popError() == 0 && c <= chapterMax && (limitChapter == -1 || limitChapter == c); verse.setChapter(++c)) { if ("transcription".equals(params.format)) { if (verse.getChapter() > 1 || verse.getVerse() > 1) { retVal.append("\n"); } retVal.append("
\n"); // retVal.append(""); retVal.append("
\n"); } else { retVal.append(""); } } if ("transcription".equals(params.format)) { retVal.append("
\n"); } else retVal.append(""); } else { if (!"transcription".equals(params.format)) retVal.append("/>"); else retVal.append("\n"); } } if (!"transcription".equals(params.format)) retVal.append("
"); } if (!"transcription".equals(params.format)) retVal.append("
"); else { retVal.append("
"); } if ("json".equals(params.format) || "csv".equals(params.format)) { try { Map result = Serializer.fromXML(retVal.toString()); Serializer.output(response, out, params, result, null); } catch (Exception e) { params.getLogger().error("ERROR! " + e); e.printStackTrace(); } return; } response.setContentType("text/xml"); out.print(retVal.toString()); return; } params.addError(-3, "v11n id: " + params.v11nid + " not found."); } else { ((Parameters)params).format = "html"; } Serializer.reportErrors(request, response, out, params, true); %>