19 package cz.vutbr.fit.knot.annotations.document;
 
   27 import java.util.ArrayList;
 
   28 import java.util.Iterator;
 
   29 import java.util.logging.Level;
 
   30 import java.util.logging.Logger;
 
   31 import org.w3c.dom.Document;
 
   32 import org.w3c.dom.DocumentFragment;
 
   33 import org.w3c.dom.Element;
 
   34 import org.w3c.dom.Node;
 
   68       this.reverseModifications.addAll(0,tm);
 
   86       this.errorMessage = msg;
 
  104       this.resyncFlag = flag;
 
  143   private ArrayList<TextModification> 
modificationsAL = 
new ArrayList<TextModification>();
 
  215     modificationsAL.add(modification);
 
  224     modificationsAL.addAll(modifications);
 
  233     modificationsAL.remove(modification);
 
  267     if (modifications.isEmpty()) {
 
  271     Integer createdReversModsNum = 0;
 
  281     boolean skipNContinue = 
false;
 
  283       skipNContinue = 
true;
 
  289     } 
catch (Exception ex) {
 
  292         String msg = 
"Unable to parse document";
 
  293         Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  303     doc.normalizeDocument();
 
  310       DocumentUpdateHelper.sortModifications(modifications);  
 
  316     Iterator<TextModification> modsIt;
 
  318       modsIt = modifications.iterator();
 
  320       modsIt = reverseModifications.iterator();
 
  323     while (modsIt.hasNext()) {
 
  327       String xPath = tm.getPath();
 
  328       String content = tm.getNewContent();
 
  331       Node sourceNode = DocumentUpdateHelper.getDocumentNode(
doc, xPath);
 
  332       if(sourceNode == null){
 
  340           docUpdateEx.setResyncFlag(
true);
 
  343           docUpdateEx.setErrorMessage(
"Unable to search for a node");
 
  353         if (createdReversModsNum == null) {
 
  365         Integer offset = tm.getOffset();
 
  366         Integer length = tm.getLength();
 
  369         Node sourceParentNode = sourceNode.getParentNode();
 
  370         if (sourceParentNode == null) {
 
  377             docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  380             docUpdateEx.setErrorMessage(
"Unable to search for a parent node");
 
  392         if (offset == null && length == null && content != null) {
 
  395           DocumentFragment fragment;
 
  397             fragment = matcherProvider.getFragmentFromString(content);
 
  398           } 
catch (Exception ex) {
 
  399             String msg = 
"Unable to parse fragment";
 
  400             Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  403               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  406               docUpdateEx.setErrorMessage(
"Unable to parse fragment");
 
  420           if (fragment.getTextContent().isEmpty()) {
 
  421             if (sourceNode.getChildNodes().getLength() < 2) {
 
  424               while (sourceNode.getChildNodes().getLength() < 2 && !sourceNode.getNodeName().equalsIgnoreCase(
"body")) {
 
  425                 tmpNode = sourceNode;
 
  426                 sourceNode = sourceNode.getParentNode();
 
  429               sourceNode = tmpNode;
 
  433             sourceParentNode = sourceNode.getParentNode();
 
  436             sourceParentNode.removeChild(sourceNode);
 
  444             Node replaceNode = doc.importNode(fragment, 
true);
 
  447             sourceParentNode.replaceChild(replaceNode, sourceNode);
 
  450             sourceParentNode.normalize();
 
  452         } 
else if (offset == null && length == null && content == null) {
 
  457           if (sourceNode.getChildNodes().getLength() < 2) {
 
  460             while (sourceNode.getChildNodes().getLength() < 2 && !sourceNode.getNodeName().equalsIgnoreCase(
"body")) {
 
  461               tmpNode = sourceNode;
 
  462               sourceNode = sourceNode.getParentNode();
 
  465             sourceNode = tmpNode;
 
  469           sourceParentNode = sourceNode.getParentNode();
 
  472           sourceParentNode.removeChild(sourceNode);
 
  473         } 
else if (offset != null && length == null && content != null) {
 
  480           if (sourceNode.getNodeType() != Node.TEXT_NODE) {
 
  483               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  486               docUpdateEx.setErrorMessage(
"Unable to apply modification on non-text node");
 
  496           if (offset > sourceNode.getTextContent().length()) {
 
  499               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  502               docUpdateEx.setErrorMessage(
"Offset extends node text content length");
 
  512           String tmpStr = sourceNode.getTextContent().substring(0, offset) + content + sourceNode.getTextContent().substring(offset);
 
  515           DocumentFragment fragment;
 
  517             fragment = matcherProvider.getFragmentFromString(tmpStr);
 
  518           } 
catch (Exception ex) {
 
  519             String msg = 
"Unable to parse fragment";
 
  520             Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  523               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  526               docUpdateEx.setErrorMessage(
"Unable to parse fragment");
 
  536           Node replaceNode = doc.importNode(fragment, 
true);
 
  539           sourceParentNode.replaceChild(replaceNode, sourceNode);
 
  542           sourceParentNode.normalize();
 
  543         } 
else if (offset != null && length != null && content != null) {
 
  549           if (sourceNode.getNodeType() != Node.TEXT_NODE) {
 
  552               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  555               docUpdateEx.setErrorMessage(
"Unable to apply modification on non-text node");
 
  565           if (offset > sourceNode.getTextContent().length()) {
 
  568               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  571               docUpdateEx.setErrorMessage(
"Set modification's offset extends node text content length");
 
  581           if (offset + length > sourceNode.getTextContent().length()) {
 
  584               docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  587               docUpdateEx.setErrorMessage(
"Set modification's length extends node text content length");
 
  607           if (content.isEmpty() && offset == 0 && length == sourceNode.getTextContent().length()) {
 
  608             if (sourceNode.getChildNodes().getLength() < 2) {
 
  611               while (sourceNode.getChildNodes().getLength() < 2 && !sourceNode.getNodeName().equalsIgnoreCase(
"body")) {
 
  612                 tmpNode = sourceNode;
 
  613                 sourceNode = sourceNode.getParentNode();
 
  615               sourceNode = tmpNode;
 
  619             sourceParentNode = sourceNode.getParentNode();
 
  622             sourceParentNode.removeChild(sourceNode);
 
  625             String tmpStr = sourceNode.getTextContent().substring(0, offset) + content + sourceNode.getTextContent().substring(offset + length);
 
  628             DocumentFragment fragment;
 
  630               fragment = matcherProvider.getFragmentFromString(tmpStr);
 
  631             } 
catch (Exception ex) {
 
  632               String msg = 
"Unable to parse fragment";
 
  633               Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  636                 docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  639                 docUpdateEx.setErrorMessage(
"Unable to parse fragment");
 
  649             Node replaceNode = doc.importNode(fragment, 
true);
 
  652             sourceParentNode.replaceChild(replaceNode, sourceNode);
 
  655             sourceParentNode.normalize();
 
  663         Node sourceParentNode = sourceNode.getParentNode();
 
  664         if(sourceParentNode == null){
 
  671             docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  674             docUpdateEx.setErrorMessage(
"Unable to search for a parent node");
 
  684         DocumentFragment fragment;
 
  686           fragment = matcherProvider.getFragmentFromString(content);
 
  687         } 
catch (Exception ex) {
 
  688           String msg = 
"Unable to parse fragment";
 
  689           Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  692             docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  695             docUpdateEx.setErrorMessage(
"Unable to parse fragment");
 
  705         Node insertNode = doc.importNode(fragment, 
true);
 
  706         sourceParentNode.insertBefore(insertNode, sourceNode);
 
  709         sourceParentNode.normalize();
 
  715         Node sourceParentNode = sourceNode.getParentNode();
 
  716         if (sourceParentNode == null) {
 
  723             docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  726             docUpdateEx.setErrorMessage(
"Unable to search for a parent node");
 
  736         DocumentFragment fragment;
 
  738           fragment = matcherProvider.getFragmentFromString(content);
 
  739         } 
catch (Exception ex) {
 
  740           String msg = 
"Unable to parse fragment";
 
  741           Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  744             docUpdateEx.addReverseModifications(
new ArrayList<TextModification>(reverseModifications.subList(0, createdReversModsNum)));
 
  747             docUpdateEx.setErrorMessage(
"Unable to parse fragment");
 
  757         Node insertNode = doc.importNode(fragment, 
true);
 
  760         if (sourceNode.getNextSibling() == null) {
 
  762           sourceParentNode.appendChild(insertNode);
 
  765           sourceParentNode.insertBefore(insertNode, sourceNode.getNextSibling());
 
  769         sourceParentNode.normalize();
 
  773     String tmp = DocumentUpdateHelper.nodeToString(doc.getDocumentElement());    
 
  776     if (failed && !reverseRun) {
 
  796     DocumentFragment tmpFrag = null;
 
  800         tmpFrag = matcherProvider.getFragmentFromString(modification.getNewContent());
 
  801       } 
catch (Exception ex) {
 
  802         String msg = 
"Unable to parse fragment";
 
  803         Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
  809     String mainXPath = modification.getPath();
 
  810     int modificationNumber = 0;
 
  817       Node child = tmpFrag.getFirstChild();
 
  825       while (child != null) {
 
  827         modificationNumber++;
 
  830         if (sourceNode.getNodeType() != Node.TEXT_NODE) {  
 
  831           if (child.getNodeType() != Node.TEXT_NODE) {
 
  834             reversedAL.add(0, tmpMod);
 
  841             if (sourceNode.getPreviousSibling() != null) {
 
  842               if (sourceNode.getPreviousSibling().getNodeType() != Node.TEXT_NODE) {
 
  845                 reversedAL.add(0, tmpMod);
 
  847                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
  849                 reversedAL.add(counter, tmpMod);
 
  856           if(child.getNodeType() != Node.TEXT_NODE){
 
  859             reversedAL.add(0, tmpMod);
 
  862             reversedAL.add(counter, tmpMod);
 
  867         child = child.getNextSibling();
 
  875       Node child = tmpFrag.getFirstChild();
 
  883       while (child != null) {
 
  885         modificationNumber++;
 
  889         if (sourceNode.getNodeType() != Node.TEXT_NODE) { 
 
  890           if (child.getNodeType() != Node.TEXT_NODE) {
 
  891             String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_INS_AFTER);
 
  893             reversedAL.add(0, tmpMod);
 
  902             if (sourceNode.getNextSibling() != null) {
 
  903               if (sourceNode.getNextSibling().getNodeType() != Node.TEXT_NODE) {
 
  904                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_INS_AFTER);
 
  906                 reversedAL.add(0, tmpMod);
 
  908                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
  910                 reversedAL.add(counter, tmpMod);
 
  917           if(child.getNodeType() != Node.TEXT_NODE){
 
  918             String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_INS_AFTER);
 
  920             reversedAL.add(0, tmpMod);
 
  923             reversedAL.add(counter, tmpMod);
 
  928         child = child.getNextSibling();
 
  936       String content = modification.getNewContent();
 
  937       Integer offset = modification.getOffset();
 
  938       Integer length = modification.getLength();
 
  944       if (offset == null && length == null && content == null) {
 
  952         if (sourceNode.getChildNodes().getLength() < 2) {
 
  955           while (sourceNode.getChildNodes().getLength() < 2 && !sourceNode.getNodeName().equalsIgnoreCase(
"body")) {
 
  956             tmpNode = sourceNode;
 
  957             sourceNode = sourceNode.getParentNode();
 
  960           sourceNode = tmpNode;
 
  968         if (sourceNode.getParentNode().getNodeName().equalsIgnoreCase(
"body")
 
  969                 && sourceNode.getPreviousSibling() == null && sourceNode.getNextSibling() == null) {
 
  971           String oldContent = DocumentUpdateHelper.nodeToString(sourceNode.getParentNode());
 
  972           String xPath = XPathHelper.XPathStringOfNode(sourceNode.getParentNode());
 
  975           reversedAL.add(0, tmpMod);
 
  978           modificationNumber++;
 
  979         } 
else if (sourceNode.getPreviousSibling() != null && sourceNode.getNextSibling() != null
 
  980                 && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE 
 
  981                 && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE) {
 
  991           String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
  992           String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
  993           int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
  996           reversedAL.add(0, tmpMod);
 
  999           modificationNumber++;
 
 1000         } 
else if (sourceNode.getPreviousSibling() != null) {
 
 1004           modificationNumber++;
 
 1006           String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1007           String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1009           reversedAL.add(0, tmpMod);
 
 1010         } 
else if (sourceNode.getNextSibling() != null) {
 
 1015           modificationNumber++;
 
 1017           if (sourceNode.getNodeType() != Node.TEXT_NODE) {
 
 1018             if (((Element) sourceNode).getTagName().equals(((Element) sourceNode.getNextSibling()).getTagName())) {
 
 1019               xPath = DocumentUpdateHelper.getNodePathForReversed(XPathHelper.XPathStringOfNode(sourceNode.getNextSibling()), sourceNode,
 
 1023             xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
 1026           String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1028           reversedAL.add(0, tmpMod);
 
 1031       } 
else if (offset == null && length == null && content != null) {
 
 1038         DocumentFragment frag = null;
 
 1040           frag = matcherProvider.getFragmentFromString(content);
 
 1041         } 
catch (Exception ex) {
 
 1042           String msg = 
"Unable to parse fragment";
 
 1043           Logger.getLogger(DocumentUpdate.class.getName()).log(Level.SEVERE, null, msg);
 
 1056         if (frag.getTextContent().isEmpty()) {
 
 1064           if (sourceNode.getChildNodes().getLength() < 2) {
 
 1066             Node tmpNode = null;
 
 1067             while (sourceNode.getChildNodes().getLength() < 2 && !sourceNode.getNodeName().equalsIgnoreCase(
"body")) {
 
 1068               tmpNode = sourceNode;
 
 1069               sourceNode = sourceNode.getParentNode();
 
 1072             sourceNode = tmpNode;
 
 1080           if (sourceNode.getParentNode().getNodeName().equalsIgnoreCase(
"body")
 
 1081               && sourceNode.getPreviousSibling() == null && sourceNode.getNextSibling() == null) {
 
 1083             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode.getParentNode());
 
 1084             String xPath = XPathHelper.XPathStringOfNode(sourceNode.getParentNode());
 
 1087             reversedAL.add(0, tmpMod);
 
 1090             modificationNumber++;
 
 1091           } 
else if (sourceNode.getPreviousSibling() != null && sourceNode.getNextSibling() != null
 
 1092             && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE 
 
 1093             && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE){
 
 1102             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1103             String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1104             int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
 1107             reversedAL.add(0, tmpMod);
 
 1110             modificationNumber++;
 
 1111           } 
else if (sourceNode.getPreviousSibling() != null) {
 
 1115             modificationNumber++;
 
 1117             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1118             String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1120             reversedAL.add(0, tmpMod);
 
 1121           } 
else if (sourceNode.getNextSibling() != null) {
 
 1127             modificationNumber++;
 
 1129             if (sourceNode.getNodeType() != Node.TEXT_NODE) {
 
 1130               if (((Element) sourceNode).getTagName().equals(((Element) sourceNode.getNextSibling()).getTagName())) {
 
 1131                 xPath = DocumentUpdateHelper.getNodePathForReversed(XPathHelper.XPathStringOfNode(sourceNode.getNextSibling()), sourceNode,
 
 1135               xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
 1138             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1140             reversedAL.add(0, tmpMod);
 
 1147           Node child = frag.getLastChild();
 
 1149           if (frag.getChildNodes().getLength() == 1) {
 
 1154             if (child.getNodeType() == Node.TEXT_NODE) {
 
 1161               if (sourceNode.getPreviousSibling() != null && sourceNode.getNextSibling() != null
 
 1162                   && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE 
 
 1163                   && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE) {
 
 1165                 String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1166                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1167                 int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
 1175                 reversedAL.add(0, tmpMod);
 
 1178                 reversedAL.add(0, tmpMod2);
 
 1181                 modificationNumber++;
 
 1182               } 
else if (sourceNode.getPreviousSibling() != null && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE){
 
 1185                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1186                 int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
 1189                 reversedAL.add(0, tmpMod);
 
 1191                 modificationNumber++;
 
 1192               } 
else if (sourceNode.getNextSibling() != null && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE) {
 
 1194                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
 1197                 reversedAL.add(0, tmpMod);
 
 1199                 modificationNumber++;
 
 1202                 String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1203                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1206                 reversedAL.add(0, tmpMod);
 
 1207                 modificationNumber++;
 
 1212               String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1213               String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1216               reversedAL.add(0, tmpMod);
 
 1217               modificationNumber++;
 
 1219           } 
else if (frag.getChildNodes().getLength() == 2) {
 
 1224             Node child1 = frag.getFirstChild();
 
 1225             Node child2 = frag.getLastChild();
 
 1226             if (frag.getFirstChild().getNodeType() == Node.TEXT_NODE) {
 
 1230               if (sourceNode.getPreviousSibling() != null && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE) {
 
 1231                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1232                 int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
 1235                 reversedAL.add(0, tmpMod);
 
 1237                 modificationNumber++;
 
 1239                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child1.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1241                 reversedAL.add(0, tmpMod);
 
 1242                 modificationNumber++;
 
 1245               String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1246               String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child2.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1250               reversedAL.add(1, tmpMod);
 
 1251               modificationNumber++;
 
 1252             } 
else if (frag.getLastChild().getNodeType() == Node.TEXT_NODE) {
 
 1256               if(sourceNode.getNextSibling() != null && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE){
 
 1257                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
 1260                 reversedAL.add(0, tmpMod);
 
 1262                 modificationNumber++;
 
 1266                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child2.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1269                 reversedAL.add(0, tmpMod);
 
 1271                 modificationNumber++;
 
 1275               String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1276               String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child1.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1280               reversedAL.add(1, tmpMod);
 
 1281               modificationNumber++;
 
 1285               String xPath1 = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child1.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1286               String xPath2 = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child2.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1287               String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1292               reversedAL.add(0, tmpMod2);
 
 1293               reversedAL.add(0, tmpMod);
 
 1295               modificationNumber++;
 
 1296               modificationNumber++;
 
 1304             ArrayList<TextModification> stack = 
new ArrayList<TextModification>();
 
 1310             while (child != null) {
 
 1318               if (child.getPreviousSibling() == null && sourceNode.getPreviousSibling() != null
 
 1319                   && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE && child.getNodeType() == Node.TEXT_NODE) {
 
 1321                 String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1322                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1323                 int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
 1326                 reversedAL.add(0, tmpMod);
 
 1327               } 
else if (child.getNextSibling() != null && child.getNextSibling().getNextSibling() == null) {
 
 1332                 String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1333                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1336                 reversedAL.add(0, tmpMod);
 
 1337               } 
else if (child.getNextSibling() == null && sourceNode.getNextSibling() != null
 
 1338                          && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE && child.getNodeType() == Node.TEXT_NODE) {
 
 1346                 String xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
 1347                 int newLength = child.getTextContent().length();
 
 1350                 reversedAL.add(0, tmpMod);
 
 1351               } 
else if (child.getNextSibling() == null) {
 
 1356                 String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1357                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1360                 reversedAL.add(0, tmpMod);
 
 1366                 String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1369                 if(child.getNodeType() == Node.TEXT_NODE){
 
 1370                   stack.add(0, tmpMod);
 
 1372                   reversedAL.add(0, tmpMod);
 
 1376               modificationNumber++;
 
 1378               child = child.getPreviousSibling();
 
 1382             reversedAL.addAll(0, stack);
 
 1385       } 
else if (offset != null && length == null && content != null) {
 
 1392         Node child = tmpFrag.getFirstChild();
 
 1395         while (child != null) {
 
 1397           modificationNumber++;
 
 1400           if (child.getNodeType() != Node.TEXT_NODE) {
 
 1401             String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1403             reversedAL.add(0, tmpMod);
 
 1406             reversedAL.add(counter, tmpMod);
 
 1409           child = child.getNextSibling();
 
 1412       } 
else if (offset != null && length != null && content != null) {
 
 1419         Node child = tmpFrag.getFirstChild();
 
 1433         if (content.isEmpty() && offset == 0 && length == sourceNode.getTextContent().length()) {
 
 1441           if (sourceNode.getChildNodes().getLength() < 2) {
 
 1443             Node tmpNode = null;
 
 1444             while (sourceNode.getChildNodes().getLength() < 2 && !sourceNode.getNodeName().equalsIgnoreCase(
"body")) {
 
 1445               tmpNode = sourceNode;
 
 1446               sourceNode = sourceNode.getParentNode();
 
 1449             sourceNode = tmpNode;
 
 1457           if (sourceNode.getParentNode().getNodeName().equalsIgnoreCase(
"body")
 
 1458               && sourceNode.getPreviousSibling() == null && sourceNode.getNextSibling() == null) {
 
 1460             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode.getParentNode());
 
 1461             String xPath = XPathHelper.XPathStringOfNode(sourceNode.getParentNode());
 
 1464             reversedAL.add(0, tmpMod);
 
 1467             modificationNumber++;
 
 1468           } 
else if (sourceNode.getPreviousSibling() != null && sourceNode.getNextSibling() != null
 
 1469                      && sourceNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE
 
 1470                      && sourceNode.getNextSibling().getNodeType() == Node.TEXT_NODE) {
 
 1480             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1481             String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1482             int newOffset = sourceNode.getPreviousSibling().getTextContent().length();
 
 1485             reversedAL.add(0, tmpMod);
 
 1488             modificationNumber++;
 
 1489           } 
else if (sourceNode.getPreviousSibling() != null) {
 
 1493             modificationNumber++;
 
 1495             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1496             String xPath = XPathHelper.XPathStringOfNode(sourceNode.getPreviousSibling());
 
 1498             reversedAL.add(0, tmpMod);
 
 1499           } 
else if (sourceNode.getNextSibling() != null) {
 
 1505             modificationNumber++;
 
 1507             if (sourceNode.getNodeType() != Node.TEXT_NODE) {
 
 1508               if (((Element) sourceNode).getTagName().equals(((Element) sourceNode.getNextSibling()).getTagName())) {
 
 1509                 xPath = DocumentUpdateHelper.getNodePathForReversed(XPathHelper.XPathStringOfNode(sourceNode.getNextSibling()), sourceNode,
 
 1513               xPath = XPathHelper.XPathStringOfNode(sourceNode.getNextSibling());
 
 1516             String oldContent = DocumentUpdateHelper.nodeToString(sourceNode);
 
 1518             reversedAL.add(0, tmpMod);
 
 1522           String overContent = sourceNode.getTextContent().substring(offset, offset + length);
 
 1524           while (child != null) {
 
 1526             modificationNumber++;
 
 1530             if (child.getNodeType() != Node.TEXT_NODE) {
 
 1531               String xPath = DocumentUpdateHelper.getNodePathForReversed(mainXPath, sourceNode, child.getNodeName(), 
Constants.
TEXT_MOD_REPLACE);
 
 1533               reversedAL.add(0, tmpMod);
 
 1536               reversedAL.add(counter, tmpMod);
 
 1539             child = child.getNextSibling();
 
 1545           reversedAL.add(counter, tmpMod);
 
 1549     return modificationNumber;
 
void setErrorCode(Integer errorCode)
String getDocumentString()
void removeModification(TextModification modification)
void setDocumentString(String documentString)
void setResyncFlag(boolean flag)
DocumentUpdateException docUpdateEx
static final int ERROR_105_MODIFICATION_SPECIFICATION
DocumentUpdate(String documentString)
ArrayList< TextModification > reverseModifications
static final int LOG_LEVEL_SERVER_INTERNAL_ERRORS
static final int TEXT_MOD_REPLACE
void setErrorMessage(String msg)
Class providing access to available matchers. 
void addReverseModifications(ArrayList< TextModification > tm)
Integer generateReverseModifications(ArrayList< TextModification > reversedAL, TextModification modification, Node sourceNode)
static final int ERROR_36_BAD_DOCUMENT
void updateDocument(boolean failed, boolean reverseRun, ArrayList< TextModification > modifications)
ArrayList< TextModification > modificationsAL
void setDocument(Document doc)
ArrayList< TextModification > getReverseModifications()
static final int TEXT_MOD_INS_AFTER
ArrayList< TextModification > reverseModifications
static final int LOG_LEVEL
Exception of DocumentUpdate class which is thrown in case of modification failure. 
Class representing modification of annotated document text. 
void appendModifications(ArrayList< TextModification > modifications)
static final int PROTOCOL_LOD_V2
MatcherProvider matcherProvider
void appendModification(TextModification modification)
Helper class with util XPath methods. 
void updateDocument(boolean failed, boolean reverseRun)
Class responsible for localised strings. 
Informations about client session. 
DocumentUpdate(String documentString, EditorSession edSession)
static final int TEXT_MOD_INS_BEFORE
static final int ERROR_33_MODULE_ERROR