%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Vector" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Document" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.Convert" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.WitnessReading" %>
<%@ page import="org.crosswire.sword.keys.VerseKey" %>
<%@ page import="org.crosswire.sword.keys.ListKey" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%@ page import="javax.validation.constraints.Pattern" %>
<%!
@Description(value = "Export the verses of transcription in SWORD imp format.", name = "transcript/export")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "manuscript id for which to export a transcript", example = "10046")
public Integer docID = null;
@NotNull
@Description(value = "manscript indexContent (osisRef) for which to retrieve a transcript, e.g., ", example = "Ps.1 or Matt.1.1,5-7,9 or Matt-Rev")
public String indexContent = null;
@Pattern(regexp = "^((download|txt|imp).*)?$", message = "Valid response formats: \"imp\", \"download\", or \"txt\"")
@Description(value = "specify the result format: imp, download[=filename], txt", defaultValue = "imp", example = "download=myTranscription.txt")
public String format = "imp";
@Description(value = "whether or not to filter out diacritics, accents, etc.", defaultValue = "false", example = "true")
public Boolean filterNoise = false;
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HHmm");
response.setContentType("text/plain");
if (params.format != null && params.format.indexOf("download") > -1) {
String fileName = "basetext.txt";
if (params.format.indexOf("download=") > -1) {
int end = params.format.indexOf(",", params.format.indexOf("download="));
if (end == -1) end = params.format.length();
fileName = params.format.substring(params.format.indexOf("download=") + 9, end);
if (fileName.indexOf("{DATE}") > -1) {
fileName = fileName.substring(0, fileName.indexOf("{DATE}")) + df.format(new Date()) + fileName.substring(fileName.indexOf("{DATE}") + 6);
}
}
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
}
Document doc = Document.getDocument(params.docID);
String v11n = doc.getV11n();
VerseKey vk = new VerseKey();
vk.setIntros(true);
if (v11n != null) vk.setVersificationSystem(v11n);
vk.setText(params.indexContent);
ListKey verses = vk.ParseVerseList(params.indexContent, vk.toString(), true);
for (verses.setPosition(VerseKey.TOP); verses.popError()==0; verses.increment()) {
String transcription = doc.getTranscriptionVerse(new VerseKey(verses.getText()).getHashNumber());
if (transcription == null) transcription = "";
if (params.format != null && params.format.startsWith("txt")) {
String verseText = new VerseKey(verses).getOSISRef();
out.print(verseText);
for (int i = verseText.length(); i < 12; ++i) out.print(" ");
transcription = Convert.getTEIPlainText(transcription, vk.getTestament(), false);
if (params.filterNoise) {
Vector wr = Convert.getTEITranscriptionText(transcription, false, false, false, false);
if (wr != null && wr.size() > 0) {
transcription = wr.get(0).getText()
.replaceAll("\\[([^-])", "$1")
.replaceAll("([^-])\\]", "$1");
}
}
out.println(transcription);
}
else {
out.println("$$$"+verses.getText());
transcription = transcription
// be sure to remove and but not, e.g.,
.replaceAll(" ][^>]*>", "")
.replaceAll(" ", "");
out.println(transcription);
}
}
return;
}
else ((Parameters)params).format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>