Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjphillips2010-02-11 19:41:38 +0000
committerjphillips2010-02-11 19:41:38 +0000
commit31a2b4359b6cb8d47eb6157419e8653202ad1aed (patch)
treebb3c1becb48cbe51a4cd6510f2b558c86c6bf957
parent396d9db86e4b26f42108cf364559dc2a85748a8f (diff)
downloadorg.eclipse.osee-31a2b4359b6cb8d47eb6157419e8653202ad1aed.tar.gz
org.eclipse.osee-31a2b4359b6cb8d47eb6157419e8653202ad1aed.tar.xz
org.eclipse.osee-31a2b4359b6cb8d47eb6157419e8653202ad1aed.zip
7HVZE - "Update OSEE Word to support Microsoft XML patch KB974631 & KB979045"
-rw-r--r--org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/OseeLinkParserTest.java43
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkBuilder.java16
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/WordUtil.java43
-rw-r--r--org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactElementExtractor.java167
-rw-r--r--org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactJob.java290
-rw-r--r--org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java12
-rw-r--r--org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java25
7 files changed, 373 insertions, 223 deletions
diff --git a/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/OseeLinkParserTest.java b/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/OseeLinkParserTest.java
new file mode 100644
index 00000000000..fe58def1d62
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/OseeLinkParserTest.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.skynet.core.test.cases;
+
+import junit.framework.Assert;
+
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.skynet.core.linking.OseeLinkParser;
+
+/**
+ * @author Jeff C. Phillips
+ */
+public class OseeLinkParserTest {
+
+ @org.junit.Test
+ public void testOldSchoolLink() throws Exception {
+ OseeLinkParser parser = new OseeLinkParser();
+ String guid = GUID.create();
+ parser.parse(String.format("http://127.0.0.1:8081/get/guid/%s/Define", guid));
+
+ Assert.assertEquals(guid, parser.getGuid());
+ }
+
+ @org.junit.Test
+ public void testNewSchoolLink() throws Exception {
+ OseeLinkParser parser = new OseeLinkParser();
+ String guid = GUID.create();
+ int branchId = 12;
+ parser.parse(String.format("http://127.0.0.1:8081/Define?guid=%s&branchId=%s", guid, branchId));
+
+ Assert.assertEquals(guid, parser.getGuid());
+ Assert.assertEquals(branchId, parser.getId());
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkBuilder.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkBuilder.java
index 955412112f0..7e884ca3581 100644
--- a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkBuilder.java
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/linking/OseeLinkBuilder.java
@@ -41,9 +41,19 @@ public class OseeLinkBuilder {
}
public String getUnknownArtifactLink(String guid, Branch branch) {
- String internalLink = String.format("http://none/unknown?guid=%s&branchId=%s", guid, branch.getId());
- return String.format(WORDML_LINK_FORMAT, internalLink, String.format(
- "Invalid Link: artifact with guid:[%s] on branchId:[%s] does not exist", guid, branch.getId()));
+ String processType = "unknown";
+ return getArtifactLinkWithMessage(processType, guid, branch,
+ String.format("Invalid Link: artifact with guid:[%s] on branchId:[%s] does not exist", guid, branch.getId()));
+ }
+
+ public String getEditArtifactLink(String guid, Branch branch, String message) {
+ String processType = "edit";
+ return getArtifactLinkWithMessage(processType, guid, branch, message);
+ }
+
+ private String getArtifactLinkWithMessage(String processType, String guid, Branch branch, String message){
+ String internalLink = String.format("http://none/%s?guid=%s&branchId=%s",processType, guid, branch.getId());
+ return String.format(WORDML_LINK_FORMAT, internalLink, message);
}
public String getWordMlBookmark(Artifact source) {
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/WordUtil.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/WordUtil.java
index cf41ce0f2c2..46451a9c536 100644
--- a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/WordUtil.java
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/word/WordUtil.java
@@ -14,6 +14,9 @@ package org.eclipse.osee.framework.skynet.core.word;
import static org.eclipse.osee.framework.skynet.core.artifact.search.SkynetDatabase.ATTRIBUTE_VERSION_TABLE;
import static org.eclipse.osee.framework.skynet.core.artifact.search.SkynetDatabase.TRANSACTIONS_TABLE;
import static org.eclipse.osee.framework.skynet.core.artifact.search.SkynetDatabase.TRANSACTION_DETAIL_TABLE;
+
+import java.io.BufferedInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -26,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.AttributeType;
import org.eclipse.osee.framework.core.model.Branch;
@@ -34,6 +38,7 @@ import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.io.Streams;
import org.eclipse.osee.framework.jdk.core.util.xml.Xml;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
@@ -49,6 +54,8 @@ import org.eclipse.osee.framework.skynet.core.attribute.WordAttribute;
public class WordUtil {
public static final String BODY_START = "<w:body>";
public static final String BODY_END = "</w:body>";
+ private static final String[] NUMBER =
+ new String[] {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
private static final String SELECT_WORD_VALUES =
"SELECT " + ATTRIBUTE_VERSION_TABLE.columns("content", "gamma_id") + " FROM " + ATTRIBUTE_VERSION_TABLE + "," + TRANSACTIONS_TABLE + "," + TRANSACTION_DETAIL_TABLE + " WHERE art_id=? AND attr_type_id=? AND " + ATTRIBUTE_VERSION_TABLE.join(
@@ -167,6 +174,28 @@ public class WordUtil {
chStmt.close();
}
}
+
+ public static String elementNameFor(String artifactName) {
+ // Since artifact names are free text it is important to reformat the name
+ // to ensure it is suitable as an element name
+ // NOTE: The current program.launch has a tokenizing bug that causes an error if consecutive
+ // spaces are in the name
+ String elementName = artifactName.trim().replaceAll("[^A-Za-z0-9]", "_");
+
+ // Ensure the name did not end up empty
+ if (elementName.equals("")) {
+ elementName = "nameless";
+ }
+
+ // Fix the first character if it is a number by replacing it with its name
+ char firstChar = elementName.charAt(0);
+ if (firstChar >= '0' && firstChar <= '9') {
+ elementName = NUMBER[firstChar - '0'] + elementName.substring(1);
+ }
+
+ return elementName;
+ }
+
public static String textOnly(String str) {
str = paragraphPattern.matcher(str).replaceAll(" ");
@@ -215,14 +244,20 @@ public class WordUtil {
return adjustedWordContentString;
}
- public final static String getGUIDFromFileInputStream(FileInputStream myFileInputStream) throws IOException {
+ public final static String getGUIDFromFile(File file) throws IOException {
String guid = null;
+ InputStream stream = new BufferedInputStream(new FileInputStream(file));
byte[] myBytes = new byte[4096];
- if (myFileInputStream.read(myBytes) == -1) {
- throw new IOException("Buffer underrun");
+
+ try{
+ if (stream.read(myBytes) == -1) {
+ throw new IOException("Buffer underrun");
+ }
+ }finally{
+ Lib.close(stream);
}
+
String leadingPartOfFile = new String(myBytes);
- myFileInputStream = null;
String[] splitsBeforeAndAfter =
leadingPartOfFile.split(Artifact.BEFORE_GUID_STRING + "|" + Artifact.AFTER_GUID_STRING);
if (splitsBeforeAndAfter.length == 3) {
diff --git a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactElementExtractor.java b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactElementExtractor.java
new file mode 100644
index 00000000000..c08f695a535
--- /dev/null
+++ b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactElementExtractor.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.ui.skynet.render;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeWrappedException;
+import org.eclipse.osee.framework.skynet.core.linking.OseeLinkParser;
+import org.eclipse.osee.framework.skynet.core.word.WordUtil;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Jeff C. Phillips
+ */
+public class ArtifactElementExtractor {
+ private Element oleDataElement;
+ private final Document document;
+
+ public ArtifactElementExtractor(Document document) {
+ super();
+ this.document = document;
+ }
+
+ public Element getOleDataElement() {
+ return oleDataElement;
+ }
+
+ public Collection<Element> extract(boolean isSingleEdit) throws DOMException, ParserConfigurationException, SAXException, IOException, OseeCoreException{
+ final Collection<Element> artifacts = new LinkedList<Element>();
+ final String elementNameForWordAttribute = WordUtil.elementNameFor("hlink");
+ Collection<Element> sectList = new LinkedList<Element>();
+ Element rootElement = document.getDocumentElement();
+ Element body = null;
+ boolean containsEditTag = false;
+ oleDataElement = null;
+
+ NodeList nodeList = rootElement.getElementsByTagName("*");
+ Node artifactTagParentNode = null;
+ Element newArtifactElement = null;
+ ParseState parseState = ParseState.LOOKING_FOR_START;
+
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Element element = (Element) nodeList.item(i);
+ if (isArtifactEditTag(elementNameForWordAttribute, element)) {
+ if(parseState == ParseState.LOOKING_FOR_START){
+ parseState = ParseState.LOOKING_FOR_END;
+ artifactTagParentNode = element.getParentNode().getParentNode();
+ containsEditTag = true;
+
+ newArtifactElement = document.createElement("WordAttribute.WORD_TEMPLATE_CONTENT");
+ populateNewArtifactElementFromHlink(newArtifactElement,element);
+ artifacts.add(newArtifactElement);
+ }else if(parseState == ParseState.LOOKING_FOR_END){
+ parseState = ParseState.LOOKING_FOR_START;
+ artifactTagParentNode = null;
+ }
+ }else if(parseState == ParseState.LOOKING_FOR_END && element.getParentNode() == artifactTagParentNode
+ && !isArtifactEditTag(elementNameForWordAttribute, element.getFirstChild())){
+ newArtifactElement.appendChild(element.cloneNode(true));
+ }
+ if (element.getNodeName().endsWith("wx:sect")) {
+ //handle the case where there exists two wx:sext elements
+ if (element != null) {
+ sectList.add(element);
+ }
+ }
+ if (element.getNodeName().endsWith("body") && isSingleEdit) {
+ artifacts.add(element);
+ body = element;
+ } else if (oleDataElement == null && element.getNodeName().endsWith("docOleData")) {
+ oleDataElement = element;
+ }
+ }
+ //When creating a three way merge the tags are not added as they create conflicts. Therefore
+ //we remove template information using the listnum fldChar tag. The following code checks for the
+ //attribute tags and if they are not there removes all the paragraphs following the one that contains the
+ //fldChar
+ if (containsEditTag) {
+ artifacts.remove(body);
+ } else if (!sectList.isEmpty()) {
+ handleMultiSectTags(sectList);
+ }
+ return artifacts;
+ }
+
+ private void handleMultiSectTags(Collection<Element> sectList) throws OseeCoreException {
+ boolean containTag = false;
+ // need to check all wx:sect for the listnum tag
+ for (Element sectElem : sectList) {
+ containTag |= cleanUpParagraph(sectElem);
+ }
+ if (!containTag) {
+ throw new OseeCoreException("This document does not contain the approporate tags to be correctly saved.");
+ }
+ }
+
+ //To handle the case of sub-sections
+ private boolean cleanUpParagraph(Node rootNode) throws OseeCoreException {
+ boolean worked = false;
+ boolean delete = false;
+ Node node = rootNode.getFirstChild();
+ while (node != null) {
+ Node nextNode = node.getNextSibling();
+ if (node.getNodeName().endsWith("sub-section")) {
+ worked = cleanUpParagraph(node);
+ } else {
+ String content = node.getTextContent();
+ if (content != null && content.contains("LISTNUM\"listreset\"")) {
+ delete = true;
+ }
+ if (delete) {
+ rootNode.removeChild(node);
+ }
+ }
+ node = nextNode;
+ }
+ return worked || delete;
+ }
+
+ /**
+ * @param newArtifactElement
+ * @param element
+ * @throws DOMException
+ * @throws OseeWrappedException
+ */
+ private void populateNewArtifactElementFromHlink(Element newArtifactElement, Element element) throws OseeCoreException, DOMException {
+ OseeLinkParser linkParser = new OseeLinkParser();
+ linkParser.parse(element.getAttribute("w:dest"));
+ newArtifactElement.setAttribute("guid", linkParser.getGuid());
+ }
+
+ /**
+ * @param elementNameForWordAttribute
+ * @param element
+ * @return
+ */
+ private boolean isArtifactEditTag(final String elementNameForWordAttribute, Node element) {
+ boolean isValid = false;
+ if(element != null && element.getNodeName().contains(elementNameForWordAttribute)){
+ isValid = element.getTextContent().contains("OSEE_EDIT");
+ }
+ return isValid ;
+ }
+
+ private enum ParseState{
+ LOOKING_FOR_START, LOOKING_FOR_END;
+ }
+}
diff --git a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactJob.java b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactJob.java
index 8db36fbd60f..46011ee6c1e 100644
--- a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactJob.java
+++ b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactJob.java
@@ -11,8 +11,8 @@
package org.eclipse.osee.framework.ui.skynet.render;
+import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -23,7 +23,9 @@ import java.util.List;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import javax.xml.parsers.ParserConfigurationException;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
@@ -49,12 +51,10 @@ import org.eclipse.osee.framework.skynet.core.word.WordUtil;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.osee.framework.ui.skynet.preferences.MsWordPreferencePage;
import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer;
-import org.eclipse.osee.framework.ui.skynet.render.word.WordTemplateProcessor;
+import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
@@ -65,8 +65,7 @@ public class UpdateArtifactJob extends UpdateJob {
private static final Pattern multiPattern = Pattern.compile(".*[^()]*");
private Element oleDataElement;
private String singleGuid = null;
- private static final boolean DEBUG =
- "TRUE".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.osee.framework.ui.skynet/debug/Renderer"));
+ private static final boolean DEBUG = "TRUE".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.osee.framework.ui.skynet/debug/Renderer"));
public UpdateArtifactJob() {
super("Update Artifact");
@@ -76,8 +75,10 @@ public class UpdateArtifactJob extends UpdateJob {
protected IStatus run(IProgressMonitor monitor) {
try {
processUpdate();
- } catch (Exception ex) {
- return new Status(Status.ERROR, SkynetGuiPlugin.PLUGIN_ID, Status.OK, ex.getLocalizedMessage(), ex);
+ }
+ catch (Exception ex) {
+ return new Status(Status.ERROR, SkynetGuiPlugin.PLUGIN_ID, Status.OK,
+ ex.getLocalizedMessage(), ex);
}
return Status.OK_STATUS;
}
@@ -85,12 +86,11 @@ public class UpdateArtifactJob extends UpdateJob {
private void processUpdate() throws Exception {
Branch branch = BranchManager.fromFileName(workingFile.getParentFile().getName());
if (branch.isEditable()) {
- FileInputStream myFileInputStream = new FileInputStream(workingFile);
-
- String guid = WordUtil.getGUIDFromFileInputStream(myFileInputStream);
+ String guid = WordUtil.getGUIDFromFile(workingFile);
if (guid == null) {
processNonWholeDocumentUpdates(branch);
- } else {
+ }
+ else {
Artifact myArtifact = ArtifactQuery.getArtifactFromId(guid, branch);
updateWholeDocumentArtifact(myArtifact);
}
@@ -98,45 +98,75 @@ public class UpdateArtifactJob extends UpdateJob {
}
private void processNonWholeDocumentUpdates(Branch branch) throws OseeCoreException, ParserConfigurationException, SAXException, IOException {
- Artifact artifact;
-
Matcher singleEditMatcher = guidPattern.matcher(workingFile.getName());
Matcher multiEditMatcher = multiPattern.matcher(workingFile.getName());
+ Artifact artifact;
+ boolean isSingleEdit = false;
if (singleEditMatcher.matches()) {
singleGuid = singleEditMatcher.group(1);
artifact = ArtifactQuery.getArtifactFromId(singleGuid, branch);
- if (artifact.isAttributeTypeValid(CoreAttributeTypes.WHOLE_WORD_CONTENT.getName()) || artifact.isAttributeTypeValid(CoreAttributeTypes.WORD_TEMPLATE_CONTENT.getName())) {
- wordArtifactUpdate(getArtifacts(workingFile, true), branch);
- } else if (artifact.isAttributeTypeValid(CoreAttributeTypes.NATIVE_CONTENT.getName())) {
+ if (artifact.isAttributeTypeValid(CoreAttributeTypes.WHOLE_WORD_CONTENT.getName())
+ || artifact.isAttributeTypeValid(CoreAttributeTypes.WORD_TEMPLATE_CONTENT.getName())) {
+ isSingleEdit = true;
+ wordArtifactUpdate(isSingleEdit, branch);
+ }
+ else if (artifact.isAttributeTypeValid(CoreAttributeTypes.NATIVE_CONTENT.getName())) {
updateNativeArtifact(artifact);
- } else {
- throw new OseeArgumentException("Artifact must be of type WordArtifact or NativeArtifact.");
}
- } else if (multiEditMatcher.matches()) {
- wordArtifactUpdate(getArtifacts(workingFile, false), branch);
- } else {
+ else {
+ throw new OseeArgumentException(
+ "Artifact must be of type WordArtifact or NativeArtifact.");
+ }
+ }
+ else if (multiEditMatcher.matches()) {
+ isSingleEdit = false;
+ wordArtifactUpdate(isSingleEdit, branch);
+ }
+ else {
throw new OseeArgumentException("File name did not contain the artifact guid");
}
}
private void logUpdateSkip(Artifact artifact) {
- OseeLog.log(SkynetGuiPlugin.class, Level.INFO, String.format("Skipping update - artifact [%s] is read-only",
- artifact.toString()));
+ OseeLog.log(
+ SkynetGuiPlugin.class,
+ Level.INFO,
+ String.format("Skipping update - artifact [%s] is read-only", artifact.toString()));
}
private void updateNativeArtifact(Artifact artifact) throws OseeCoreException, FileNotFoundException {
if (!artifact.isReadOnly()) {
- artifact.setSoleAttributeFromStream(CoreAttributeTypes.NATIVE_CONTENT.getName(), new FileInputStream(workingFile));
- artifact.persist();
- } else {
+ InputStream stream = null;
+ try {
+ stream = new BufferedInputStream(new FileInputStream(workingFile));
+ artifact.setSoleAttributeFromStream(CoreAttributeTypes.NATIVE_CONTENT.getName(), stream);
+ artifact.persist();
+ }
+ finally {
+ Lib.close(stream);
+ }
+ }
+ else {
logUpdateSkip(artifact);
}
}
- private void wordArtifactUpdate(Collection<Element> artElements, Branch branch) throws OseeCoreException {
+ private void wordArtifactUpdate(boolean isSingle, Branch branch) throws OseeCoreException, DOMException, ParserConfigurationException, SAXException, IOException {
List<String> deletedGuids = new LinkedList<String>();
+ InputStream inputStream = new BufferedInputStream(new FileInputStream(workingFile));
+ Document document;
+ try{
+ document = Jaxp.readXmlDocument(workingFile);
+ }finally{
+ Lib.close(inputStream);
+ }
+
+ ArtifactElementExtractor extractor = new ArtifactElementExtractor(document);
+ Collection<Element> artElements = extractor.extract(isSingle);
+ oleDataElement = extractor.getOleDataElement();
+
try {
boolean singleArtifact = artElements.size() == 1;
boolean containsOleData = false;
@@ -146,7 +176,8 @@ public class UpdateArtifactJob extends UpdateJob {
if (artifact == null) {
deletedGuids.add(guid);
- } else {
+ }
+ else {
if (artifact.isReadOnly()) {
logUpdateSkip(artifact);
continue;
@@ -155,70 +186,37 @@ public class UpdateArtifactJob extends UpdateJob {
if (oleDataElement == null && containsOleData) {
artifact.setSoleAttributeValue(WordAttribute.OLE_DATA_NAME, "");
- } else if (oleDataElement != null && singleArtifact) {
- artifact.setSoleAttributeFromStream(WordAttribute.OLE_DATA_NAME, new ByteArrayInputStream(
- WordTemplateRenderer.getFormattedContent(oleDataElement)));
}
-
+ else if (oleDataElement != null && singleArtifact) {
+ artifact.setSoleAttributeFromStream(WordAttribute.OLE_DATA_NAME,
+ new ByteArrayInputStream(
+ WordTemplateRenderer.getFormattedContent(oleDataElement)));
+ }
String content;
try {
- content =
- Lib.inputStreamToString(new ByteArrayInputStream(
- WordTemplateRenderer.getFormattedContent(artElement)));
- } catch (IOException ex) {
- throw new OseeWrappedException(ex);
+ content = Lib.inputStreamToString(new ByteArrayInputStream(
+ WordTemplateRenderer.getFormattedContent(artElement)));
}
-
- StringBuilder stringBuffer = new StringBuilder();
-
- // Decided not to support multi edit of artifacts that
- // contain equations.
- if (false && containsOleData && !singleArtifact) {
- int startIndex = 0, endIndex = 0, tagCursorStart = 0, tagCursorEnd = 0;
- String equationTag;
-
- content = content.replaceAll("MyObject", "OLEObject").replaceAll("number", "ObjectID");
-
- while (endIndex < content.length()) {
- tagCursorStart = content.indexOf(":OLEObject ", startIndex);
-
- if (tagCursorStart != -1) {
- tagCursorStart = content.lastIndexOf('<', tagCursorStart);
-
- tagCursorEnd = content.indexOf(">", tagCursorStart) + 1;
- equationTag = content.substring(tagCursorStart, tagCursorEnd);
-
- tagCursorEnd = content.indexOf("OLEObject>", tagCursorStart) + "OLEObject>".length();
- content = content.replace(content.subSequence(tagCursorStart, tagCursorEnd), "");
-
- endIndex = content.indexOf("</w:pict>", startIndex);
- stringBuffer.append(content.substring(startIndex, endIndex));
-
- equationTag = equationTag.replaceFirst("ns\\d+", "o").replace(">", "/>");
- stringBuffer.append(equationTag + "</w:pict>");
- startIndex = endIndex + "</w:pict>".length();
- } else {
- endIndex = content.length();
- stringBuffer.append(content.substring(startIndex, endIndex));
- }
- }
- content = stringBuffer.toString();
+ catch (IOException ex) {
+ throw new OseeWrappedException(ex);
}
// Only update if editing a single artifact or if in
- // multi-edit mode only update if the artifact has at least one textual change (if the MUTI_EDIT_SAVE_ALL_CHANGES preference is not set).
- boolean multiSave =
- UserManager.getUser().getBooleanSetting(MsWordPreferencePage.MUTI_EDIT_SAVE_ALL_CHANGES) || !WordUtil.textOnly(
- artifact.getSoleAttributeValue(WordAttribute.WORD_TEMPLATE_CONTENT).toString()).equals(
- WordUtil.textOnly(content));
+ // multi-edit mode only update if the artifact has at least one textual change (if
+ // the MUTI_EDIT_SAVE_ALL_CHANGES preference is not set).
+ boolean multiSave = UserManager.getUser().getBooleanSetting(MsWordPreferencePage.MUTI_EDIT_SAVE_ALL_CHANGES)
+ || !WordUtil.textOnly(artifact.getSoleAttributeValue(
+ WordAttribute.WORD_TEMPLATE_CONTENT).toString()).equals(
+ WordUtil.textOnly(content));
if (singleArtifact || multiSave) {
- //TODO
+ // TODO
if (DEBUG) {
System.err.println("Initial: " + content);
}
if (artElement.getNodeName().endsWith("body")) {
- //This code pulls out all of the stuff after the inserted listnum reordering stuff. This needs to be
- //here so that we remove unwanted template information from single editing
+ // This code pulls out all of the stuff after the inserted listnum reordering
+ // stuff. This needs to be
+ // here so that we remove unwanted template information from single editing
content = content.replace(WordMLProducer.LISTNUM_FIELD_HEAD, "");
if (DEBUG) {
System.err.println("AFTER: " + content);
@@ -231,125 +229,40 @@ public class UpdateArtifactJob extends UpdateJob {
artifact.persist();
}
}
- } finally {
+ }
+ finally {
if (!deletedGuids.isEmpty()) {
- throw new OseeStateException("The following deleted artifacts could not be saved: " + Collections.toString(
- ",", deletedGuids));
+ throw new OseeStateException("The following deleted artifacts could not be saved: "
+ + Collections.toString(",", deletedGuids));
}
}
}
private void updateWholeDocumentArtifact(Artifact artifact) throws FileNotFoundException, OseeCoreException {
- InputStream inputStream = null;
- try {
- if (!artifact.isReadOnly()) {
- inputStream = new FileInputStream(workingFile);
- String content = Lib.inputStreamToString(inputStream);
- LinkType linkType = LinkType.OSEE_SERVER_LINK;
- content = WordMlLinkHandler.unlink(linkType, artifact, content);
- artifact.setSoleAttributeFromString(WordAttribute.WHOLE_WORD_CONTENT, content);
- artifact.persist();
- } else {
- logUpdateSkip(artifact);
- }
- } catch (IOException ex) {
- throw new OseeWrappedException(ex);
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException ex) {
- OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
- }
- }
- }
- }
-
- private Collection<Element> getArtifacts(File wordFile, boolean single) throws ParserConfigurationException, SAXException, IOException, OseeCoreException {
- final Collection<Element> artifacts = new LinkedList<Element>();
- final String elementNameForWordAttribute =
- WordTemplateProcessor.elementNameFor(WordAttribute.WORD_TEMPLATE_CONTENT);
-
- Document doc = Jaxp.readXmlDocument(wordFile);
- Element paragraphRoot = null;
- Collection<Element> sectList = new LinkedList<Element>();
- Element rootElement = doc.getDocumentElement();
- Element body = null;
- boolean containsTag = false;
- oleDataElement = null;
-
- NodeList nodeList = rootElement.getElementsByTagName("*");
- for (int i = 0; i < nodeList.getLength(); i++) {
- Element element = (Element) nodeList.item(i);
- if (element.getNodeName().endsWith(elementNameForWordAttribute)) {
- artifacts.add(element);
- containsTag = true;
+ if (!artifact.isReadOnly()) {
+ String content = null;
+ InputStream inputStream = null;
+ try {
+ inputStream = new BufferedInputStream(new FileInputStream(workingFile));
+ content = Lib.inputStreamToString(inputStream);
}
- if (element.getNodeName().endsWith("wx:sect")) {
- paragraphRoot = element;
- //handle the case where there exists two wx:sext elements
- if (element != null) {
- sectList.add(element);
- }
+ catch (IOException ex) {
+ throw new OseeWrappedException(ex);
}
- if (element.getNodeName().endsWith("body") && single) {
- artifacts.add(element);
- body = element;
- } else if (oleDataElement == null && element.getNodeName().endsWith("docOleData")) {
- oleDataElement = element;
+ finally {
+ Lib.close(inputStream);
}
+ LinkType linkType = LinkType.OSEE_SERVER_LINK;
+ content = WordMlLinkHandler.unlink(linkType, artifact, content);
+ artifact.setSoleAttributeFromString(WordAttribute.WHOLE_WORD_CONTENT, content);
+ artifact.persist();
}
- //When creating a three way merge the tags are not added as they create conflicts. Therefore
- //we remove template information using the listnum fldChar tag. The following code checks for the
- //attribute tags and if they are not there removes all the paragraphs following the one that contains the
- //fldChar
- if (containsTag) {
- artifacts.remove(body);
- } else if (!sectList.isEmpty()) {
- handleMultiSectTags(sectList);
- }
- return artifacts;
- }
-
- private void handleMultiSectTags(Collection<Element> sectList) throws OseeCoreException {
- boolean containTag = false;
- // need to check all wx:sect for the listnum tag
- for (Element sectElem : sectList) {
- containTag |= cleanUpParagraph(sectElem);
- }
- if (!containTag) {
- throw new OseeCoreException("This document does not contain the approporate tags to be correctly saved.");
- }
- }
-
- //To handle the case of sub-sections
- private boolean cleanUpParagraph(Node rootNode) throws OseeCoreException {
- boolean worked = false;
- boolean delete = false;
- Node node = rootNode.getFirstChild();
- while (node != null) {
- Node nextNode = node.getNextSibling();
- if (node.getNodeName().endsWith("sub-section")) {
- worked = cleanUpParagraph(node);
- } else {
- String content = node.getTextContent();
- if (DEBUG) {
- System.out.println(" " + node.getNodeName());
- System.out.println(" " + content);
- }
- if (content != null && content.contains("LISTNUM\"listreset\"")) {
- delete = true;
- }
- if (delete) {
- rootNode.removeChild(node);
- }
- }
- node = nextNode;
+ else {
+ logUpdateSkip(artifact);
}
- return worked || delete;
}
- private String getGuid(Element artifactElement) throws OseeArgumentException {
+ private String getGuid(Element artifactElement) throws OseeCoreException {
if (singleGuid != null) {
return singleGuid;
}
@@ -362,6 +275,7 @@ public class UpdateArtifactJob extends UpdateJob {
return attributes.item(i).getNodeValue();
}
}
- throw new OseeArgumentException("didn't find the guid attribure in element: " + artifactElement);
+ throw new OseeArgumentException("didn't find the guid attribure in element: "
+ + artifactElement);
}
} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java
index 9fe92617a3b..148c41a9728 100644
--- a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java
+++ b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java
@@ -21,7 +21,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
+
import javax.xml.namespace.QName;
+
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.eclipse.core.resources.IFile;
@@ -47,6 +49,7 @@ import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.skynet.core.attribute.WordAttribute;
import org.eclipse.osee.framework.skynet.core.linking.LinkType;
+import org.eclipse.osee.framework.skynet.core.linking.OseeLinkBuilder;
import org.eclipse.osee.framework.skynet.core.linking.WordMlLinkHandler;
import org.eclipse.osee.framework.skynet.core.word.WordAnnotationHandler;
import org.eclipse.osee.framework.skynet.core.word.WordUtil;
@@ -413,9 +416,10 @@ public class WordTemplateRenderer extends WordRenderer implements ITemplateRende
}
if (presentationType == PresentationType.SPECIALIZED_EDIT) {
- WordTemplateProcessor.writeXMLMetaDataWrapper(wordMl,
- WordTemplateProcessor.elementNameFor(attributeTypeName), "ns0:guid=\"" + artifact.getGuid() + "\"",
- "ns0:attrId=\"" + wordTempConAttr.getAttributeType().getId() + "\"", value);
+ OseeLinkBuilder linkBuilder = new OseeLinkBuilder();
+ wordMl.addParagraphNoEscape(linkBuilder.getEditArtifactLink(artifact.getGuid(), artifact.getBranch(), "OSEE_EDIT_START"));
+ wordMl.addWordMl(value);
+ wordMl.addParagraphNoEscape(linkBuilder.getEditArtifactLink(artifact.getGuid(), artifact.getBranch(), "OSEE_EDIT_END"));
} else {
wordMl.addWordMl(value);
}
@@ -441,7 +445,7 @@ public class WordTemplateRenderer extends WordRenderer implements ITemplateRende
if (presentationType == PresentationType.SPECIALIZED_EDIT && artifacts.size() > 1) {
// currently we can't support the editing of multiple artifacts with OLE data
for (Artifact artifact : artifacts) {
- if (!artifact.getSoleAttributeValue(WordAttribute.OLE_DATA_NAME, "").equals("") && presentationType == PresentationType.GENERALIZED_EDIT) {
+ if (!artifact.getSoleAttributeValue(WordAttribute.OLE_DATA_NAME, "").equals("")) {
notMultiEditableArtifacts.add(artifact);
}
}
diff --git a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java
index ce988529c07..0445f216cc1 100644
--- a/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java
+++ b/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -104,9 +105,6 @@ public class WordTemplateProcessor {
Pattern.compile("<((\\w+:)?(HeadingAttribute|RecurseChildren|Number))>(.*?)</\\1>",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
- private static final String[] NUMBER =
- new String[] {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
-
private String slaveTemplate;
private boolean outlining;
private boolean recurseChildren;
@@ -479,27 +477,6 @@ public class WordTemplateProcessor {
return theMap;
}
- public static String elementNameFor(String artifactName) {
- // Since artifact names are free text it is important to reformat the name
- // to ensure it is suitable as an element name
- // NOTE: The current program.launch has a tokenizing bug that causes an error if consecutive
- // spaces are in the name
- String elementName = artifactName.trim().replaceAll("[^A-Za-z0-9]", "_");
-
- // Ensure the name did not end up empty
- if (elementName.equals("")) {
- elementName = "nameless";
- }
-
- // Fix the first character if it is a number by replacing it with its name
- char firstChar = elementName.charAt(0);
- if (firstChar >= '0' && firstChar <= '9') {
- elementName = NUMBER[firstChar - '0'] + elementName.substring(1);
- }
-
- return elementName;
- }
-
public static void writeXMLMetaDataWrapper(WordMLProducer wordMl, String name, String guid, String attributeId, String contentString) throws OseeWrappedException {
wordMl.addWordMl("<ns0:" + name + " xmlns:ns0=\"" + WordTemplateRenderer.ARTIFACT_SCHEMA + "\" " + guid + " " + attributeId + ">");
wordMl.addWordMl(contentString);

Back to the top