<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.Sessions" %> <%@ page import="org.crosswire.webtools.RightsAndRoles" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Page" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="javax.validation.constraints.NotNull" %> <%! @Description(value = "Move transcription data for a manuscript.", name = "transcript/move") public static class MyParameters extends Parameters { @NotNull @Description(value = "manuscript id of the source page", example = "10046") public Integer docID = null; @NotNull @Description(value = "page id of the source page", example = "10") public Integer pageID = null; @Description(value = "if specifying a range, the last page id to move", example = "30") public Integer pageIDEnd = null; @NotNull @Description(value = "destination page id", example = "50") public Integer toPageID = null; @Description(value = "for which user to move transcription", defaultValue = "PUBLISHED", example = "psmith") public String userName = "PUBLISHED"; @Description(value = "leave source data in place after writing to destination", defaultValue = "false", example = "true") public Boolean copy = false; @Override protected void customValidation() { if (getUser() == null) { addError(-5, "Must be logged in to edit transcriptions."); return; } if (pageIDEnd == null) pageIDEnd = pageID; } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0) { String role = "VMR Administrator"; String role2 = "Transcription Manager"; Document doc = Document.getDocument(params.docID); if (doc == null) { params.addError(-6, "Document docID: " + params.docID + " not found."); } else if (!(params.getUser().hasRole(role) || (params.userName != null && params.getUser().hasRole(role2)) || (params.getUser().getUserName().equals(params.userName)) || (params.getUser().getUserName().equals(doc.getUserID())))) { params.addError(-7, "User is neither the owner of this document nor has the role: " + role + "."); } else { int count = 1; Page fromLastPage = Page.getPage(params.docID, params.pageID); for (; fromLastPage.getPageID() < params.pageIDEnd; fromLastPage = fromLastPage.getNextPage(),++count); Page toLastPage = Page.getPage(params.docID, params.toPageID); for (int i = 1; i < count; toLastPage = toLastPage.getNextPage(),++i); boolean forward = params.toPageID > params.pageID; // if were going forward, we need to do last pages first or we will clobber ourself if we overlap // if we're going backward, we need to start with the first page id. Page fromPage = (forward) ? fromLastPage : Page.getPage(params.docID, params.pageID); Page toPage = (forward) ? toLastPage : Page.getPage(params.docID, params.toPageID); StringBuffer retVal = new StringBuffer(""); for (; count > 0; --count) { if (fromPage == null) { retVal.append(""); break; } Page fromOrig = (Page)fromPage.clone(); if (toPage != null) { String tp = doc.getTranscriptionPage(fromPage.getPageID(), params.userName); doc.setTranscriptionPage(toPage.getPageID(), tp, params.userName); if (!params.copy) doc.removeTranscriptionPage(fromPage.getPageID(), params.userName); retVal.append(""); } // if we're moving page data forward, we're working in reverse from the back so we don't clobber our data while writing fromPage = (forward) ? fromPage.getPreviousPage() : fromPage.getNextPage(); toPage = (forward) ? toPage.getPreviousPage() : toPage.getNextPage(); } retVal.append(""); Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString())); return; } } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>