Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2010-09-10 19:32:44 -0400
committerRyan D. Brooks2010-09-10 19:32:44 -0400
commit442eff9a662fb84b23c4c7578c859405b224ee31 (patch)
tree31ebd47ac9067be162aa835bdb5336350ff8c9ba
parentc1c38ad4e1b3804c999b670e69b7a1e1b5b31e6f (diff)
downloadorg.eclipse.osee-442eff9a662fb84b23c4c7578c859405b224ee31.tar.gz
org.eclipse.osee-442eff9a662fb84b23c4c7578c859405b224ee31.tar.xz
org.eclipse.osee-442eff9a662fb84b23c4c7578c859405b224ee31.zip
bug[ats_JVNZA]: Fix DOM parsing error during bookmark id fix before wordML rendering
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java4
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/word/UpdateBookmarkIdTest.java2
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/UpdateBookmarkIds.java50
3 files changed, 37 insertions, 19 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java
index 8ffba90b4a..295e22a56a 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java
@@ -658,7 +658,7 @@ public class Jaxp {
String namespace = element.getNamespaceURI();
String prefix = element.getPrefix();
- String name = element.getNodeName();
+ String name = element.getLocalName();
if (Strings.isValid(name)) {
if (prefix != null && namespace != null) {
writer.writeStartElement(prefix, name, namespace);
@@ -700,7 +700,7 @@ public class Jaxp {
String namespace = attrNode.getNamespaceURI();
String prefix = attrNode.getPrefix();
- String name = attrNode.getName();
+ String name = attrNode.getLocalName();
String value = attrNode.getValue();
if (Strings.isValid(name) && Strings.isValid(value)) {
if (prefix != null && namespace != null) {
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/word/UpdateBookmarkIdTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/word/UpdateBookmarkIdTest.java
index 60cb933221..858f1c2864 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/word/UpdateBookmarkIdTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/word/UpdateBookmarkIdTest.java
@@ -13,7 +13,7 @@ import org.junit.Test;
public class UpdateBookmarkIdTest {
@Test
- public void resetBookMarkIdTest() throws OseeCoreException {
+ public void testBookMarkIdFix() throws OseeCoreException {
UpdateBookmarkIds bookMarkIds = new UpdateBookmarkIds(1000);
String bookmark =
"<aml:annotation aml:id=\"133334\" w:type=\"Word.Bookmark.Start\"/><aml:annotation aml:id=\"133334\" w:type=\"Word.Bookmark.End\" />";
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/UpdateBookmarkIds.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/UpdateBookmarkIds.java
index 8211c7e1cf..eeded06d8d 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/UpdateBookmarkIds.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/UpdateBookmarkIds.java
@@ -6,20 +6,31 @@
package org.eclipse.osee.framework.skynet.core.word;
import java.io.StringWriter;
+import java.util.Collection;
import java.util.Stack;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.eclipse.osee.framework.jdk.core.util.xml.SimpleNamespaceContext;
import org.eclipse.osee.framework.jdk.core.util.xml.Xml;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class UpdateBookmarkIds {
+ private static final String WORD_PREFIX =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><?mso-application progid=\"Word.Document\"?><w:wordDocument xmlns:aml=\"http://schemas.microsoft.com/aml/2001/core\" xmlns:dt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\" xmlns:ve=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.microsoft.com/office/word/2003/wordml\" xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" xmlns:wsp=\"http://schemas.microsoft.com/office/word/2003/wordml/sp2\" xmlns:sl=\"http://schemas.microsoft.com/schemaLibrary/2003/core\" w:macrosPresent=\"no\" w:embeddedObjPresent=\"no\" w:ocxPresent=\"no\" xml:space=\"preserve\">";
+ private static final Pattern WORD_BODY_PATTERN = Pattern.compile("<w:body>(.*?)</w:body>");
+ private static final String XPATH_EXPRESSION =
+ "//aml:annotation[@w:type='Word.Bookmark.End' or @w:type='Word.Bookmark.Start']";
+
private int bookMarkId;
public UpdateBookmarkIds(int startBookMarkId) {
@@ -45,32 +56,31 @@ public class UpdateBookmarkIds {
}
private String stripOffBodyTag(String original) {
- int startIndex = original.indexOf("<body>");
- if (startIndex < 0) {
- startIndex = 0;
- } else {
- startIndex = startIndex + 6;
- }
- int stopIndex = original.indexOf("</body>");
- if (stopIndex < 0) {
- stopIndex = original.length();
+ Matcher matcher = WORD_BODY_PATTERN.matcher(original);
+ String toReturn = original;
+ if (matcher.find()) {
+ toReturn = matcher.group(1);
}
- return original.substring(startIndex, stopIndex);
+ return toReturn;
}
public String fixTags(String content) throws OseeCoreException {
String toReturn = content;
boolean changesMade = false;
try {
- Document document = Jaxp.readXmlDocument("<body>" + content + "</body>");
+
+ Document document =
+ Jaxp.readXmlDocumentNamespaceAware(WORD_PREFIX + "<w:body>" + content + "</w:body></w:wordDocument>");
Element element = document.getDocumentElement();
Stack<Element> nodeStack = new Stack<Element>();
- Node[] list =
- Xml.selectNodeList(element, "//annotation[@type='Word.Bookmark.End' or @type='Word.Bookmark.Start']");
- for (int index = 0; index < list.length; index++) {
- Node currentNode = list[index];
+ XPath xPath = Jaxp.createXPath();
+ SimpleNamespaceContext context = new SimpleNamespaceContext();
+ Xml.addNamespacesForWordMarkupLanguage(xPath, context);
+ Collection<Node> nodes = Jaxp.selectNodesViaXPath(xPath, element, XPATH_EXPRESSION);
+
+ for (Node currentNode : nodes) {
if (isStartNode(currentNode)) {
nodeStack.push((Element) currentNode);
} else if (isEndNode(currentNode)) {
@@ -78,7 +88,7 @@ public class UpdateBookmarkIds {
changesMade = true;
Element startNode = nodeStack.pop();
Element endNode = (Element) currentNode;
- int newId = ++bookMarkId;
+ int newId = incrementBookmarkId();
startNode.setAttribute("aml:id", String.valueOf(newId));
endNode.setAttribute("aml:id", String.valueOf(newId));
}
@@ -95,6 +105,14 @@ public class UpdateBookmarkIds {
return toReturn;
}
+ private int incrementBookmarkId() {
+ bookMarkId = bookMarkId + 1;
+ if (bookMarkId >= Integer.MAX_VALUE) {
+ bookMarkId = 0;
+ }
+ return bookMarkId;
+ }
+
private static String xmlSectionToString(Node root) throws XMLStreamException {
StringWriter writer = new StringWriter();
XMLOutputFactory factory = XMLOutputFactory.newInstance();

Back to the top