/** What about the case where the one repeat is used twice? That's ok, as long as there is some other object between the two lots of repeats. Limitation: The user could screw this up, by manually inserting a paragraph between 2 instances of a repeat. Result would be that an instance is kept, and converted back into an extra repeat! So have a sanity check that count of repeats and conditions in result matches what we have in the original template. */ private boolean sanityCheck() throws Docx4JException { int expectedConditions = templateConditionSdtsByID.size(); int expectedRepeats = templateRepeatSdtsByID.size(); TopLevelSdtTemplateFinder sdtPrFinder = new TopLevelSdtTemplateFinder(true); findSdtsInTemplate(instancePkg, sdtPrFinder); // feed the instance through here to count (not bothering to count plain binds) boolean resultC = sdtPrFinder.conditionSdtsByID.size() == expectedConditions; if (!resultC) { log.error("Restored " + sdtPrFinder.conditionSdtsByID.size() + " condition SDTs but expected " + expectedConditions); } boolean resultR = sdtPrFinder.repeatSdtsByID.size() == expectedRepeats; if (!resultR) { log.error("Restored " + sdtPrFinder.repeatSdtsByID.size() + " repeat SDTs but expected " + expectedRepeats); } return (resultC && resultR); }
/** What about the case where the one repeat is used twice? That's ok, as long as there is some other object between the two lots of repeats. Limitation: The user could screw this up, by manually inserting a paragraph between 2 instances of a repeat. Result would be that an instance is kept, and converted back into an extra repeat! So have a sanity check that count of repeats and conditions in result matches what we have in the original template. */ private boolean sanityCheck() throws Docx4JException { int expectedConditions = templateConditionSdtsByID.size(); int expectedRepeats = templateRepeatSdtsByID.size(); TopLevelSdtTemplateFinder sdtPrFinder = new TopLevelSdtTemplateFinder(true); findSdtsInTemplate(instancePkg, sdtPrFinder); // feed the instance through here to count (not bothering to count plain binds) boolean resultC = sdtPrFinder.conditionSdtsByID.size() == expectedConditions; if (!resultC) { log.error("Restored " + sdtPrFinder.conditionSdtsByID.size() + " condition SDTs but expected " + expectedConditions); } boolean resultR = sdtPrFinder.repeatSdtsByID.size() == expectedRepeats; if (!resultR) { log.error("Restored " + sdtPrFinder.repeatSdtsByID.size() + " repeat SDTs but expected " + expectedRepeats); } return (resultC && resultR); }
public boolean revert() throws Docx4JException { // template docx:- find top level repeat/condition controls TopLevelSdtTemplateFinder sdtPrFinder = new TopLevelSdtTemplateFinder(false); findSdtsInTemplate(openDopePkg, sdtPrFinder); templateConditionSdtsByID = sdtPrFinder.conditionSdtsByID; templateRepeatSdtsByID = sdtPrFinder.repeatSdtsByID; // instance docx:- handleSdtsInInstance(); return sanityCheck(); }
public boolean revert() throws Docx4JException { // template docx:- find top level repeat/condition controls TopLevelSdtTemplateFinder sdtPrFinder = new TopLevelSdtTemplateFinder(false); findSdtsInTemplate(openDopePkg, sdtPrFinder); templateConditionSdtsByID = sdtPrFinder.conditionSdtsByID; templateRepeatSdtsByID = sdtPrFinder.repeatSdtsByID; // instance docx:- handleSdtsInInstance(); return sanityCheck(); }