<%@ 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.community.projects.ntmss.data.Regularization.RegularizationRule" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Regularization" %> <%@ page import="org.crosswire.sword.keys.VerseKey" %> <% // who we are String userName = Sessions.getSessionStringValue(request, "userName"); // who's rules we want to modify String targetUserName = request.getParameter("userName"); if (targetUserName == null) targetUserName = userName; int regID = -1; try {regID = Integer.parseInt(request.getParameter("regID"));} catch (Exception e){} String groupName = request.getParameter("groupName"); String verse = request.getParameter("verse"); String scope = request.getParameter("scope"); String visibility = request.getParameter("visibility"); String optionsText = request.getParameter("options"); String sourceWord = request.getParameter("sourceWord"); if (sourceWord != null) { sourceWord = new String(sourceWord.getBytes("iso8859-1"), "UTF-8"); if (sourceWord.replaceAll("[ .:;'\"!,]", "").indexOf("?") == 0) sourceWord = request.getParameter("sourceWord");} String targetWord = request.getParameter("targetWord"); if (targetWord != null) { targetWord = new String(targetWord.getBytes("iso8859-1"), "UTF-8"); if (targetWord.replaceAll("[ ().:;'\"!,]", "").indexOf("?") == 0) targetWord = request.getParameter("targetWord");} String contextPre = request.getParameter("contextPre"); if (contextPre != null) contextPre = new String(contextPre.getBytes("iso8859-1"), "UTF-8"); String contextPost = request.getParameter("contextPost"); if (contextPost != null) contextPost = new String(contextPost.getBytes("iso8859-1"), "UTF-8"); String comment = request.getParameter("comment"); if (comment != null) comment = new String(comment.getBytes("iso8859-1"), "UTF-8"); String type = request.getParameter("type"); int options = -1; try { options = Integer.parseInt(optionsText); } catch(Exception e) {} if (optionsText != null && options == -1) { options = 0; for (String o : optionsText.split("\\|")) { if ("IGNORE_SUPPLIED".equalsIgnoreCase(o)) { options |= RegularizationRule.OPTION_IGNORE_SUPPLIED; } else if ("IGNORE_UNCLEAR".equalsIgnoreCase(o)) { options |= RegularizationRule.OPTION_IGNORE_UNCLEAR; } else if ("ONLY_NOMSAC".equalsIgnoreCase(o)) { options |= RegularizationRule.OPTION_ONLY_NOMSAC; } } } if (regID > -1 || sourceWord != null) { response.setContentType("text/xml"); RegularizationRule orig = null; RegularizationRule reg = null; if (regID > -1) { orig = RegularizationRule.getRegularizationRule(regID); reg = (RegularizationRule)orig.clone(); if (orig == null) { out.print(""); return; } } else reg = new RegularizationRule(); // we need these first, to check if we have a parallel segmentation rule we're modifying if (sourceWord != null) reg.setSourceWord(sourceWord); if (verse != null) reg.setContextVerse(new VerseKey(verse).getHashNumber()); if ("Parallel Segmentation".equals(type)) { if (orig == null) { RegularizationRule regs[] = Regularization.getRulesByVerse(targetUserName, false, reg.getContextVerse()); if (regs != null) { for (RegularizationRule r : regs) { if ( r.getType() == RegularizationRule.TYPE_PARALLEL_SEGMENTATION && ( reg.getSourceWord().startsWith(r.getSourceWord()) || reg.getSourceWord().endsWith(r.getSourceWord())) ) { orig = r; reg = (RegularizationRule)orig.clone(); reg.setSourceWord(sourceWord); break; } } } } reg.setType(RegularizationRule.TYPE_PARALLEL_SEGMENTATION); } else if (type != null) { String typeTexts[] = RegularizationRule.getTypeTexts(); int i = 0; for (; i < typeTexts.length; ++i) { if (typeTexts[i].equalsIgnoreCase(type)) break; } if (i == typeTexts.length) { out.print(""); return; } reg.setType(i); } if (targetUserName != null) reg.setUserID(targetUserName); if (groupName != null) reg.setGroupName(groupName); if (options != -1) reg.setOptions(options); if ("Verse".equals(scope)) { reg.setScope(RegularizationRule.SCOPE_VERSE); } else if ("Global".equals(scope)) { reg.setScope(RegularizationRule.SCOPE_GLOBAL); } else if ("Once".equals(scope)) { reg.setScope(RegularizationRule.SCOPE_ONCE); } else if (scope != null) { out.print(""); return; } else { if (orig == null) reg.setScope(verse != null ? RegularizationRule.SCOPE_VERSE : RegularizationRule.SCOPE_GLOBAL); } if ("Private".equals(visibility)) { reg.setVisibility(RegularizationRule.VISIBILITY_PRIVATE); } else if ("Public".equals(visibility)) { reg.setVisibility(RegularizationRule.VISIBILITY_PUBLIC); } else if (visibility != null) { out.print(""); return; } if (targetWord != null) reg.setTargetWord(targetWord); if (contextPre != null) reg.setContextPre(contextPre); if (contextPost != null) reg.setContextPost(contextPost); if (orig != null) { reg.save(orig); } else { reg = reg.saveNew(); } out.print(""); return; } %>

regularization/put

Submit a new or modified regularization rule

Parameters

regIDregularization rule id to modify. if not provided, a new regularization rule will be created.
userNameowner of the regularization rule
groupNamegroup name to assign rule to
versecontext verse
scopescope of rule (Verse, Global, Once)
visibilityvisibility of rule (Public, Private)
sourceWordsource word to change in the text
targetWordtarget word to change the source word to
contextPrecontext immediately before the source word
contextPostcontext immediately after the source word
typetype of rule (Spelling, Iticism)
optionspipe-separated list of options for the rule or an int value, e.g., IGNORE_SUPPLIED|IGNORE_UNCLEAR|ONLY_NOMSAC
commentany user notes about this rule