<%@ 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.keys.VerseKey" %> <%@ page import="org.crosswire.sword.keys.ListKey" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%! @Description(value = "Parse freehand verse reference.", name = "v11n/parse") public static class MyParameters extends Parameters { @Description(value = "show usage for this web service", defaultValue = "false", example = "true") public Boolean usage = false; @Description(value = "versification id to use, instead of system default", example = "KJV") public String v11nid; @Description(value = "freehand verse reference text", example = "John 3:16") public String text; @Description(value = "position away from parsed text", example = "-1 would jump to the previous verse to the parsed text") public Integer step = 0; @Description(value = "whether or not to turn on introduction slots; e.g., Matt.1.0, Matt.Inscriptio, Matt.Subscriptio", defaultValue = "false", example = "true") public Boolean intros = false; @Description(value = "whether or not to expand ranges to return individual verses within a range", defaultValue = "false", example = "true") public Boolean expandRange = false; @Description(value = "[(v11ndef)|verses|wce|freetext] which format to return", defaultValue = "v11ndef", example = "verses") public String detail; @Description(value = "[(v11ndef)|verses|wce|freetext|xml|json|csv] which format to return", defaultValue = "v11ndef", example = "json") public String format; @Override protected void afterLoad() { if (detail == null) detail = format; if (format != null) { super.format = format; if ( ("freetext".equals(super.format)) || ("wce".equals(super.format)) || ("verses".equals(super.format)) ) { super.format = "xml"; } } } @Override protected void customValidation() { if (text == null || text.length() < 1) { addError(-1, "Must supply {text}."); return; } } } %> <% 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"); VerseKey vk = new VerseKey(); if (params.v11nid != null) vk.setVersificationSystem(params.v11nid); vk.setIntros(params.intros); vk.setText(params.text); if (params.step > 0) vk.increment(params.step); if (params.step < 0) vk.decrement(params.step*-1); if ("freetext".equals(params.format)) { response.setContentType("text/plain"); ListKey verses = vk.ParseVerseList(params.text, "Mat.1.1", true); out.print(verses.getShortRangeText()); } else { StringBuffer retVal = new StringBuffer(); if ("freetext".equals(params.detail)) { ListKey verses = vk.ParseVerseList(params.text, "Mat.1.1", true); retVal.append("" + verses.getShortRangeText() + ""); } else if ("wce".equals(params.detail)) { retVal.append("" + vk.getOSISRef() + ""); } else if ("verses".equals(params.detail)) { ListKey verses = vk.ParseVerseList(params.text, "Mat.1.1", true); // special handling of step for verses with only one verse if (verses.getCount() == 1 && ((VerseKey)verses.getElement(0)).getLowerBound().getHashNumber() == ((VerseKey)verses.getElement(0)).getUpperBound().getHashNumber()) { ((VerseKey)verses.getElement(0)).setHashNumber(vk.getHashNumber()); ((VerseKey)verses.getElement(0)).setUpperBound(vk); ((VerseKey)verses.getElement(0)).setLowerBound(vk); } retVal.append(""); if (params.expandRange != null && params.expandRange) { int verseOrdinal = 0; for (verses.setPosition(verses.TOP); verses.popError() == 0; verses.increment()) { VerseKey v = (VerseKey)verses.getElement(); boolean lowerBound = (v.getLowerBound() != null && v.getLowerBound().getHashNumber() == v.getHashNumber()); String osisRef = v.getOSISRef(); /* if (v.getChapter() == 0 && osisRef.split(".").length < 1) { osisRef += ".0"; } if (v.getVerse() == 0 && osisRef.split(".").length < 2) { osisRef += ".0"; } */ retVal.append(""); retVal.append(v.getText()); retVal.append(""); ++verseOrdinal; } } else { int verseOrdinal = 0; for (int i = 0; i < verses.getCount(); ++i) { VerseKey verseKey = (VerseKey)verses.getElement(i); retVal.append( ""); ++verseOrdinal; } } retVal.append(""); } else { retVal.append(""); retVal.append(""); retVal.append(""); retVal.append(""); retVal.append(""); retVal.append(""); retVal.append(""); } Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString())); } return; } else ((Parameters)params).format = "html"; Serializer.reportErrors(request, response, out, params, true); %>