diff options
author | rbrooks | 2011-01-21 23:03:59 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-01-21 23:03:59 +0000 |
commit | 61b759dc7f72a3ee1ba8f197b366536d8dc9e1f4 (patch) | |
tree | e95157516c07f188b2323900393a8b1ac90cc589 | |
parent | e847982e21edf58404ba4f4cc8061c699ef4509d (diff) | |
download | org.eclipse.osee-61b759dc7f72a3ee1ba8f197b366536d8dc9e1f4.tar.gz org.eclipse.osee-61b759dc7f72a3ee1ba8f197b366536d8dc9e1f4.tar.xz org.eclipse.osee-61b759dc7f72a3ee1ba8f197b366536d8dc9e1f4.zip |
refactor: Eliminate complex artifact and branch detection logic in renderer edit logic
17 files changed, 546 insertions, 687 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java index 0984e0b983f..2824856ec02 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeDslRenderer.java @@ -27,13 +27,13 @@ import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.logging.OseeLevel; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer; import org.eclipse.osee.framework.ui.skynet.render.FileSystemRenderer; -import org.eclipse.osee.framework.ui.skynet.render.IArtifactUpdateOperationFactory; import org.eclipse.osee.framework.ui.skynet.render.PresentationType; import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.program.Program; @@ -46,22 +46,8 @@ import org.eclipse.ui.ide.IDE; * @author Roberto E. Escobar */ public final class OseeDslRenderer extends FileSystemRenderer { - private static final String COMMAND_ID = "org.eclipse.osee.framework.core.dsl.OseeDsl.editor.command"; - private static final OseeDslSegmentParser parser = new OseeDslSegmentParser(); - private static final class OseeDslArtifactUpdateOperationFactory implements IArtifactUpdateOperationFactory { - - @SuppressWarnings("unused") - @Override - public IOperation createUpdateOp(File file) throws OseeCoreException { - return new OseeDslArtifactUpdateOperation(parser, file); - } - }; - - public OseeDslRenderer() { - super(new OseeDslArtifactUpdateOperationFactory()); - } @Override public String getName() { @@ -150,4 +136,9 @@ public final class OseeDslRenderer extends FileSystemRenderer { public Program getAssociatedProgram(Artifact artifact) throws OseeCoreException { throw new OseeCoreException("should not be called"); } + + @Override + protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) { + return new OseeDslArtifactUpdateOperation(parser, file); + } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java index 45c4642ed6a..312e0b8ea6c 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java @@ -11,8 +11,6 @@ package org.eclipse.osee.framework.skynet.core.artifact; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; @@ -32,7 +30,6 @@ import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.core.exception.BranchDoesNotExist; import org.eclipse.osee.framework.core.exception.MultipleBranchesExist; -import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.MergeBranch; @@ -46,7 +43,6 @@ import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.core.util.Conditions; import org.eclipse.osee.framework.database.core.SQL3DataType; 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.Strings; import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime; import org.eclipse.osee.framework.logging.OseeLog; @@ -498,37 +494,6 @@ public class BranchManager { getCache().storeItems(branches); } - public static Branch fromFileName(String fileName) throws OseeCoreException { - if (!Strings.isValid(fileName)) { - throw new OseeArgumentException("file name cannot be null or empty"); - } - Branch toReturn = null; - String branchGuid = decode(fileName); - if (GUID.isValid(branchGuid)) { - toReturn = getCache().getByGuid(branchGuid); - if (toReturn == null) { - throw new OseeArgumentException("Unable to find branch matching guid [%s]", branchGuid); - } - } else { - int branchId = Integer.parseInt(Lib.getExtension(fileName)); - toReturn = getCache().getById(branchId); - if (toReturn == null) { - throw new OseeArgumentException("Unable to find branch matching id [%s]", branchId); - } - } - return toReturn; - } - - private static String decode(String name) { - String toReturn = name; - try { - toReturn = URLDecoder.decode(name, "UTF-8"); - } catch (UnsupportedEncodingException ex) { - // Do Nothing - } - return toReturn; - } - public static void decache(Branch branch) throws OseeCoreException { getCache().decache(branch); } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/renderer/RenderingUtilTest.java b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/renderer/RenderingUtilTest.java index c152873f090..b4b7f4bcdca 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/renderer/RenderingUtilTest.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/test/renderer/RenderingUtilTest.java @@ -32,13 +32,9 @@ public class RenderingUtilTest { @Test public void testBranchToFileName() throws Exception { AbstractOseeCache<Branch> cache = new TestCache(); - for (int index = 0; index < 100; index++) { - String guid = GUID.create(); - Branch branch = createBranch(cache, guid, String.format("Test %s", index + 1), index); - - String actual = RenderingUtil.toFileName(branch); - Assert.assertEquals(encode(guid), actual); - } + Branch branch = createBranch(cache, GUID.create(), "Test 1", 1); + String actual = RenderingUtil.toFileName(branch); + Assert.assertEquals(encode(branch.getShortName()), actual); } private String encode(String guid) throws UnsupportedEncodingException { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileMonitor.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileMonitor.java index d66e78ea1c7..012f89fa983 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileMonitor.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileMonitor.java @@ -11,38 +11,52 @@ package org.eclipse.osee.framework.ui.skynet.render; import java.io.File; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.jdk.core.util.io.FileChangeEvent; +import org.eclipse.osee.framework.jdk.core.util.io.FileChangeType; import org.eclipse.osee.framework.jdk.core.util.io.FileWatcher; +import org.eclipse.osee.framework.jdk.core.util.io.IFileWatcherListener; +import org.eclipse.osee.framework.logging.OseeLevel; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchListener; import org.eclipse.ui.PlatformUI; -final class ArtifactFileMonitor { +final class ArtifactFileMonitor implements IFileWatcherListener { private final ResourceAttributes readonlyfileAttributes; private final FileWatcher watcher; private boolean firstTime; + private final Map<File, IOperation> fileMap = new ConcurrentHashMap<File, IOperation>(128); - public ArtifactFileMonitor(IArtifactUpdateOperationFactory opFactory) { + public ArtifactFileMonitor() { firstTime = true; readonlyfileAttributes = new ResourceAttributes(); readonlyfileAttributes.setReadOnly(true); watcher = new FileWatcher(3, TimeUnit.SECONDS); - watcher.addListener(new ArtifactFileWatcherListener(opFactory)); + watcher.addListener(this); watcher.start(); } - public void addFile(IFile file) { - monitorFile(file.getLocation().toFile()); + public void addFile(File file, IOperation updateOperation) { + watcher.addFile(file); + fileMap.put(file, updateOperation); } public void markAsReadOnly(IFile file) throws OseeCoreException { @@ -53,6 +67,33 @@ final class ArtifactFileMonitor { } } + @Override + public void filesModified(Collection<FileChangeEvent> fileChangeEvents) { + for (FileChangeEvent event : fileChangeEvents) { + if (event.getChangeType() == FileChangeType.MODIFIED) { + processFileUpdate(event.getFile()); + } + } + } + + private void processFileUpdate(final File file) { + IOperation op = fileMap.get(file); + Operations.executeAsJob(op, false, Job.LONG, new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + if (event.getResult().isOK()) { + OseeLog.log(SkynetGuiPlugin.class, Level.INFO, "Updated artifact linked to: " + file.getAbsolutePath()); + } + } + }); + } + + @Override + public void handleException(Exception ex) { + OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); + } + private void monitorFile(File file) { watcher.addFile(file); if (firstTime) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileWatcherListener.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileWatcherListener.java deleted file mode 100644 index 51dab398845..00000000000 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/ArtifactFileWatcherListener.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.File; -import java.util.Collection; -import java.util.logging.Level; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.framework.jdk.core.util.io.FileChangeEvent; -import org.eclipse.osee.framework.jdk.core.util.io.FileChangeType; -import org.eclipse.osee.framework.jdk.core.util.io.IFileWatcherListener; -import org.eclipse.osee.framework.logging.OseeLevel; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; - -/** - * @author Ryan D. Brooks - */ -public class ArtifactFileWatcherListener implements IFileWatcherListener { - private final IArtifactUpdateOperationFactory opFactory; - - public ArtifactFileWatcherListener(IArtifactUpdateOperationFactory opFactory) { - this.opFactory = opFactory; - } - - @Override - public void filesModified(Collection<FileChangeEvent> fileChangeEvents) { - for (FileChangeEvent event : fileChangeEvents) { - if (event.getChangeType() == FileChangeType.MODIFIED) { - try { - processFileUpdate(event.getFile()); - } catch (OseeCoreException ex) { - OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); - } - } - } - } - - private void processFileUpdate(final File file) throws OseeCoreException { - IOperation op = opFactory.createUpdateOp(file); - Operations.executeAsJob(op, false, Job.LONG, new JobChangeAdapter() { - - @Override - public void done(IJobChangeEvent event) { - if (event.getResult().isOK()) { - OseeLog.log(SkynetGuiPlugin.class, Level.INFO, "Updated artifact linked to: " + file.getAbsolutePath()); - } - } - }); - } - - @Override - public void handleException(Exception ex) { - OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); - } -} diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/FileSystemRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/FileSystemRenderer.java index 260afe4c8c6..d0081928153 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/FileSystemRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/FileSystemRenderer.java @@ -16,8 +16,6 @@ import java.io.File; import java.io.InputStream; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -42,37 +40,7 @@ import org.eclipse.ui.part.FileEditorInput; * @author Jeff C. Phillips */ public abstract class FileSystemRenderer extends DefaultArtifactRenderer { - - private static final Map<Class<? extends IArtifactUpdateOperationFactory>, ArtifactFileMonitor> FILE_MONITOR_MAP = - new ConcurrentHashMap<Class<? extends IArtifactUpdateOperationFactory>, ArtifactFileMonitor>(); - - private static final IArtifactUpdateOperationFactory DEFAULT_ARTIFACT_OP_FACTORY = new UpdateArtifactJobFactory(); - - private static final class UpdateArtifactJobFactory implements IArtifactUpdateOperationFactory { - - @SuppressWarnings("unused") - @Override - public IOperation createUpdateOp(File file) throws OseeCoreException { - return new UpdateArtifactOperation(file); - } - } - - private final Class<? extends IArtifactUpdateOperationFactory> monitorKey; - - protected FileSystemRenderer(IArtifactUpdateOperationFactory jobFactory) { - super(); - this.monitorKey = jobFactory.getClass(); - - ArtifactFileMonitor monitor = getFileMonitor(); - if (monitor == null) { - monitor = new ArtifactFileMonitor(jobFactory); - FILE_MONITOR_MAP.put(monitorKey, monitor); - } - } - - public FileSystemRenderer() { - this(DEFAULT_ARTIFACT_OP_FACTORY); - } + private static final ArtifactFileMonitor monitor = new ArtifactFileMonitor(); public IFile getRenderedFileForOpen(List<Artifact> artifacts) throws OseeCoreException { return getRenderedFile(artifacts, PresentationType.SPECIALIZED_EDIT); @@ -96,8 +64,7 @@ public abstract class FileSystemRenderer extends DefaultArtifactRenderer { } else { artifacts = Collections.emptyList(); } - InputStream inputStream = getRenderInputStream(presentationType, artifacts); - return renderToFile(baseFolder, fileName, branch, inputStream, presentationType); + return renderToFile(baseFolder, fileName, branch, presentationType, artifacts); } public IFile renderToFileSystem(IFolder baseFolder, List<Artifact> artifacts, PresentationType presentationType) throws OseeCoreException { @@ -117,37 +84,29 @@ public abstract class FileSystemRenderer extends DefaultArtifactRenderer { artifact = artifacts.iterator().next(); } String fileName = RenderingUtil.getFilenameFromArtifact(this, artifact, presentationType); - InputStream inputStream = getRenderInputStream(presentationType, artifacts); - return renderToFile(baseFolder, fileName, initialBranch, inputStream, presentationType); + return renderToFile(baseFolder, fileName, initialBranch, presentationType, artifacts); } - public IFile renderToFile(IFolder baseFolder, String fileName, Branch branch, InputStream renderInputStream, PresentationType presentationType) throws OseeCoreException { + public IFile renderToFile(IFolder baseFolder, String fileName, Branch branch, PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException { + InputStream renderInputStream = getRenderInputStream(presentationType, artifacts); IFile workingFile = baseFolder.getFile(fileName); AIFile.writeToFile(workingFile, renderInputStream); if (presentationType == PresentationType.SPECIALIZED_EDIT || presentationType == PresentationType.MERGE_EDIT) { - getFileMonitor().addFile(workingFile); + File file = workingFile.getLocation().toFile(); + monitor.addFile(file, getUpdateOperation(file, artifacts, branch, presentationType)); } else if (presentationType == PresentationType.PREVIEW) { - getFileMonitor().markAsReadOnly(workingFile); + monitor.markAsReadOnly(workingFile); } return workingFile; } - public void addFileToWatcher(IFolder baseFolder, String fileName) { - IFile workingFile = baseFolder.getFile(fileName); - getFileMonitor().addFile(workingFile); - } - public abstract InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException; public abstract Program getAssociatedProgram(Artifact artifact) throws OseeCoreException; public abstract String getAssociatedExtension(Artifact artifact) throws OseeCoreException; - private ArtifactFileMonitor getFileMonitor() { - return FILE_MONITOR_MAP.get(monitorKey); - } - @Override public void open(List<Artifact> artifacts, PresentationType presentationType) throws OseeCoreException { if (presentationType == DEFAULT_OPEN) { @@ -185,4 +144,6 @@ public abstract class FileSystemRenderer extends DefaultArtifactRenderer { } } } + + protected abstract IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) throws OseeCoreException; } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/IArtifactUpdateOperationFactory.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/IArtifactUpdateOperationFactory.java deleted file mode 100644 index 90483fd4ae1..00000000000 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/IArtifactUpdateOperationFactory.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.File; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.operation.IOperation; - -public interface IArtifactUpdateOperationFactory { - - IOperation createUpdateOp(File file) throws OseeCoreException; -} diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/NativeRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/NativeRenderer.java index c687cb51afb..a41ae57779d 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/NativeRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/NativeRenderer.java @@ -13,6 +13,7 @@ package org.eclipse.osee.framework.ui.skynet.render; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.DEFAULT_OPEN; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.PREVIEW; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.SPECIALIZED_EDIT; +import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -22,6 +23,8 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; @@ -115,4 +118,9 @@ public class NativeRenderer extends FileSystemRenderer { Artifact artifact = artifacts.iterator().next(); return artifact.getSoleAttributeValue(CoreAttributeTypes.NativeContent); } + + @Override + protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) { + return new WholeAttributeUpdateOperation(file, artifacts.get(0), CoreAttributeTypes.NativeContent); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/OpenOfficeWriterRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/OpenOfficeWriterRenderer.java index 2905edf9b2c..542b7603a67 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/OpenOfficeWriterRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/OpenOfficeWriterRenderer.java @@ -10,8 +10,12 @@ *******************************************************************************/ package org.eclipse.osee.framework.ui.skynet.render; +import java.io.File; import java.io.InputStream; import java.util.List; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.swt.program.Program; @@ -44,4 +48,9 @@ public class OpenOfficeWriterRenderer extends FileSystemRenderer implements ITem public int getApplicabilityRating(PresentationType presentationType, Artifact artifact) { return NO_MATCH; } + + @Override + protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) throws OseeCoreException { + throw new UnsupportedOperationException(); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RenderingUtil.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RenderingUtil.java index 5b20643d86f..a311509132e 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RenderingUtil.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RenderingUtil.java @@ -22,6 +22,7 @@ import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.model.Branch; 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; @@ -167,7 +168,7 @@ public final class RenderingUtil { } public static String toFileName(IOseeBranch branch) throws OseeCoreException { - return encode(branch.getGuid()); + return encode(Branch.getShortName(branch)); } private static String encode(String name) throws OseeCoreException { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactOperation.java index a9dc17bc84a..d9ef374d56d 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactOperation.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/UpdateArtifactOperation.java @@ -15,21 +15,16 @@ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.LinkedList; 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.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.DeletionFlag; import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeExceptions; @@ -42,7 +37,6 @@ import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.skynet.core.UserManager; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; import org.eclipse.osee.framework.skynet.core.linking.LinkType; import org.eclipse.osee.framework.skynet.core.linking.WordMlLinkHandler; @@ -63,46 +57,27 @@ import org.xml.sax.SAXException; * @author Ryan D. Brooks */ public class UpdateArtifactOperation extends AbstractOperation { - private static final Pattern guidPattern = Pattern.compile(".*\\(([^)]+)\\)[^()]*"); - private static final Pattern multiPattern = Pattern.compile(".*[^()]*"); - private Element oleDataElement; - private String singleGuid = null; private final File workingFile; + private final List<Artifact> artifacts; + private final Branch branch; - public UpdateArtifactOperation(File workingFile) { + public UpdateArtifactOperation(File workingFile, List<Artifact> artifacts, Branch branch) { super("Update Artifact", SkynetGuiPlugin.PLUGIN_ID); this.workingFile = workingFile; + this.artifacts = artifacts; + this.branch = branch; } @Override protected void doWork(IProgressMonitor monitor) throws Exception { - processUpdate(); - } - - private void processUpdate() throws Exception { - Branch branch = BranchManager.fromFileName(workingFile.getParentFile().getName()); - if (branch.isEditable()) { - Matcher singleEditMatcher = guidPattern.matcher(workingFile.getName()); - Matcher multiEditMatcher = multiPattern.matcher(workingFile.getName()); - - if (singleEditMatcher.matches()) { - singleGuid = singleEditMatcher.group(1); - - if (isMergeEdit()) { - processMergeEdit(new MergeEditArtifactElementExtractor(extractJaxpDocument()), branch); - } else { - Artifact artifact = ArtifactQuery.getArtifactFromId(singleGuid, branch); - processSingleEdit(artifact); - } - } else if (multiEditMatcher.matches()) { - WordImageArtifactElementExtractor elementExtractor = new WordImageArtifactElementExtractor(extractJaxpDocument()); - processMultiEdit(elementExtractor, branch); - } + IElementExtractor elementExtractor; + Document document = extractJaxpDocument(); + if (branch.getBranchType().isMergeBranch()) { + elementExtractor = new MergeEditArtifactElementExtractor(document); + } else { + elementExtractor = new WordImageArtifactElementExtractor(document); } - } - - private boolean isMergeEdit() { - return workingFile.getAbsolutePath().contains("mergeEdit"); + wordArtifactUpdate(elementExtractor); } private Document extractJaxpDocument() throws ParserConfigurationException, SAXException, IOException { @@ -116,73 +91,26 @@ public class UpdateArtifactOperation extends AbstractOperation { return document; } - private void processMergeEdit(IElementExtractor elementExtractor, Branch branch) throws OseeCoreException, DOMException, ParserConfigurationException, SAXException, IOException { - wordArtifactUpdate(elementExtractor, branch); - } - - private void processSingleEdit(Artifact artifact) throws OseeCoreException, ParserConfigurationException, SAXException, IOException { - if (artifact.isAttributeTypeValid(CoreAttributeTypes.WordTemplateContent)) { - WordImageArtifactElementExtractor elementExtractor = new WordImageArtifactElementExtractor(extractJaxpDocument()); - wordArtifactUpdate(elementExtractor, artifact.getBranch()); - } else { - processNativeDocuments(artifact); - } - } - - private void processNativeDocuments(Artifact artifact) throws OseeCoreException, FileNotFoundException { - if (artifact.isAttributeTypeValid(CoreAttributeTypes.WholeWordContent)) { - updateNativeArtifact(artifact, CoreAttributeTypes.WholeWordContent); - } else if (artifact.isAttributeTypeValid(CoreAttributeTypes.NativeContent)) { - updateNativeArtifact(artifact, CoreAttributeTypes.NativeContent); - } else { - throw new OseeArgumentException("Artifact must be of type WordArtifact or NativeArtifact."); - } - } - - private void processMultiEdit(IElementExtractor elementExtractor, Branch branch) throws OseeCoreException, ParserConfigurationException, SAXException, IOException { - wordArtifactUpdate(elementExtractor, branch); - } - - private void logUpdateSkip(Artifact artifact) { - OseeLog.log(SkynetGuiPlugin.class, Level.INFO, - String.format("Skipping update - artifact [%s] is read-only", artifact.toString())); - } - - private void updateNativeArtifact(Artifact artifact, IAttributeType attributeType) throws OseeCoreException, FileNotFoundException { - if (!artifact.isReadOnly()) { - InputStream stream = null; - try { - stream = new BufferedInputStream(new FileInputStream(workingFile)); - artifact.setSoleAttributeFromStream(attributeType, stream); - artifact.persist(); - } finally { - Lib.close(stream); - } - } else { - logUpdateSkip(artifact); - } - } - - private void wordArtifactUpdate(IElementExtractor elementExtractor, Branch branch) throws OseeCoreException, DOMException, ParserConfigurationException, SAXException, IOException { - List<String> deletedGuids = new LinkedList<String>(); + private void wordArtifactUpdate(IElementExtractor elementExtractor) throws OseeCoreException, DOMException, ParserConfigurationException, SAXException, IOException { + List<Artifact> deletedArtifacts = new LinkedList<Artifact>(); Collection<Element> artElements = elementExtractor.extractElements(); - oleDataElement = elementExtractor.getOleDataElement(); + Element oleDataElement = elementExtractor.getOleDataElement(); try { boolean singleArtifact = artElements.size() == 1; boolean containsOleData = false; for (Element artElement : artElements) { - String guid = getGuid(artElement); - Artifact artifact = ArtifactQuery.getArtifactFromId(guid, branch); - if (artifact == null) { - deletedGuids.add(guid); + Artifact artifact = getArtifact(artElement); + + if (artifact.isDeleted()) { + deletedArtifacts.add(artifact); } else { if (artifact.isReadOnly()) { logUpdateSkip(artifact); continue; } - containsOleData = !artifact.getSoleAttributeValue(CoreAttributeTypes.WordOleData, "").equals(""); + containsOleData = artifact.getAttributeCount(CoreAttributeTypes.WordOleData) > 0; if (oleDataElement == null && containsOleData) { artifact.setSoleAttributeValue(CoreAttributeTypes.WordOleData, ""); @@ -222,28 +150,32 @@ public class UpdateArtifactOperation extends AbstractOperation { } } } finally { - if (!deletedGuids.isEmpty()) { + if (!deletedArtifacts.isEmpty()) { throw new OseeStateException("The following deleted artifacts could not be saved [%s]", - Collections.toString(",", deletedGuids)); + Collections.toString(",", deletedArtifacts)); } } } - private String getGuid(Element artifactElement) throws OseeCoreException { - if (singleGuid != null) { - return singleGuid; + private void logUpdateSkip(Artifact artifact) { + OseeLog.log(SkynetGuiPlugin.class, Level.INFO, + String.format("Skipping update - artifact [%s] is read-only", artifact.toString())); + } + + private Artifact getArtifact(Element artifactElement) throws OseeCoreException { + if (artifacts.size() == 1) { + return artifacts.get(0); } NamedNodeMap attributes = artifactElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { - // MS Word has a nasty habit of changing the namespace say from - // ns0 to ns1, so we must - // ignore the namespace by using endsWith() + // MS Word has a nasty habit of changing the namespace say from ns0 to ns1, so we must ignore the namespace by using endsWith() if (attributes.item(i).getNodeName().endsWith("guid")) { - return attributes.item(i).getNodeValue(); + String guid = attributes.item(i).getNodeValue(); + return ArtifactQuery.getArtifactFromId(guid, branch, DeletionFlag.INCLUDE_DELETED); } } + throw new OseeArgumentException("didn't find the guid attribure in element [%s]", artifactElement); } - }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeAttributeUpdateOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeAttributeUpdateOperation.java new file mode 100644 index 00000000000..7b4ba7dbfb9 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeAttributeUpdateOperation.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011 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.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; + +/** + * @author Ryan D. Brooks + */ +public class WholeAttributeUpdateOperation extends AbstractOperation { + private final Artifact artifact; + private final IAttributeType attributeType; + private final File file; + + public WholeAttributeUpdateOperation(File file, Artifact artifact, IAttributeType attributeType) { + super("Native Artifact Update", SkynetGuiPlugin.PLUGIN_ID); + this.artifact = artifact; + this.attributeType = attributeType; + this.file = file; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + InputStream stream = null; + try { + stream = new BufferedInputStream(new FileInputStream(file)); + artifact.setSoleAttributeFromStream(attributeType, stream); + artifact.persist(); + } finally { + Lib.close(stream); + } + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeWordRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeWordRenderer.java index a4b8dc6662c..e0bdf395783 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeWordRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WholeWordRenderer.java @@ -15,6 +15,7 @@ import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.WholeWord import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERALIZED_EDIT; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERAL_REQUESTED; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.PRODUCE_ATTRIBUTE; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -23,6 +24,8 @@ import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeExceptions; import org.eclipse.osee.framework.core.exception.OseeStateException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.jdk.core.util.io.Streams; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.attribute.WordWholeDocumentAttribute; @@ -100,4 +103,9 @@ public class WholeWordRenderer extends WordRenderer { public IComparator getComparator() { return comparator; } + + @Override + protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) { + return new WholeAttributeUpdateOperation(file, artifacts.get(0), CoreAttributeTypes.WholeWordContent); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java index 9bf2b837fc4..7559cf38fc8 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/WordTemplateRenderer.java @@ -14,6 +14,7 @@ package org.eclipse.osee.framework.ui.skynet.render; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERALIZED_EDIT; import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERAL_REQUESTED; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -26,6 +27,8 @@ import org.apache.xml.serialize.XMLSerializer; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.artifact.Attribute; @@ -148,7 +151,6 @@ public class WordTemplateRenderer extends WordRenderer implements ITemplateRende @Override public void renderAttribute(IAttributeType attributeType, Artifact artifact, PresentationType presentationType, Producer producer, VariableMap map, AttributeElement attributeElement) throws OseeCoreException { - // String value = ""; WordMLProducer wordMl = (WordMLProducer) producer; if (attributeType.equals(CoreAttributeTypes.WordTemplateContent)) { @@ -236,4 +238,9 @@ public class WordTemplateRenderer extends WordRenderer implements ITemplateRende public IComparator getComparator() { return comparator; } + + @Override + protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) throws OseeCoreException { + return new UpdateArtifactOperation(file, artifacts, branch); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/IElementExtractor.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/IElementExtractor.java index 68fb4d3a1a2..99e086d3bb6 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/IElementExtractor.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/IElementExtractor.java @@ -23,8 +23,7 @@ import org.xml.sax.SAXException; * @author Jeff C. Phillips */ public interface IElementExtractor { + public abstract Element getOleDataElement(); - public Element getOleDataElement(); - - public Collection<Element> extractElements() throws DOMException, ParserConfigurationException, SAXException, IOException, OseeCoreException; -} + public abstract Collection<Element> extractElements() throws DOMException, ParserConfigurationException, SAXException, IOException, OseeCoreException; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/WordImageArtifactElementExtractor.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/WordImageArtifactElementExtractor.java index 46080c57f2b..6cdc1fdb3ed 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/WordImageArtifactElementExtractor.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/artifactElement/WordImageArtifactElementExtractor.java @@ -16,7 +16,6 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; - import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.skynet.core.linking.OseeLinkBuilder; import org.eclipse.osee.framework.skynet.core.word.WordUtil; @@ -30,377 +29,361 @@ import org.w3c.dom.NodeList; * @author Jeff C. Phillips */ public class WordImageArtifactElementExtractor implements IElementExtractor { - private static final String SECTION_TAG = "wx:sect"; - private static final String SUB_SECTION_TAG = "wx:sub-section"; - private static final String BODY_TAG = "w:body"; - private static final String PICT = "pict"; - private static final String IMAGE = "v:imagedata"; - private static final String SRC = "src"; - private static final String BIN_DATA = "w:binData"; - private static String START_IMG_ID; - private static String END_IMG_ID; - private static final String TITLE = "o:title"; - - private final Map<String, Element> pictureMap; - private Element oleDataElement; - private final Document document; - private int numberOfStartTags; - private int numberOfEndTags; - private String guid; - - private enum ParseState { - LOOKING_FOR_START, LOOKING_FOR_END - }; - - private enum Side { - left, right - }; - - public WordImageArtifactElementExtractor(Document document) { - super(); - this.document = document; - this.numberOfEndTags = 0; - this.numberOfStartTags = 0; - this.pictureMap = new HashMap<String, Element>(); - } - - @Override - public Element getOleDataElement() { - return oleDataElement; - } - - @Override - public List<Element> extractElements() throws DOMException, OseeCoreException { - OseeLinkBuilder linkBuilder = new OseeLinkBuilder(); - return extractElements(linkBuilder); - } - - private void resetClassFields() { - pictureMap.clear(); - numberOfStartTags = 0; - numberOfEndTags = 0; - oleDataElement = null; - guid = null; - } - - public List<Element> extractElements(OseeLinkBuilder linkBuilder) - throws DOMException, OseeCoreException { - final List<Element> artifactElements = new LinkedList<Element>(); - Element rootElement = document.getDocumentElement(); - resetClassFields(); - - NodeList nodeList = rootElement.getElementsByTagName("*"); - Element newArtifactElement = null; - ParseState parseState = ParseState.LOOKING_FOR_START; - - for (int i = 0; i < nodeList.getLength(); i++) { - Element element = (Element) nodeList.item(i); - if (parseState == ParseState.LOOKING_FOR_START && isArtifactEditTag(element, true)) { - parseState = ParseState.LOOKING_FOR_END; - newArtifactElement = handleStartElement(linkBuilder, artifactElements, element); - } else if (parseState == ParseState.LOOKING_FOR_END && isArtifactEditTag(element, false)) { - parseState = handleEndElement(linkBuilder, newArtifactElement, element); - } else if (parseState == ParseState.LOOKING_FOR_END && properLevelChild(element)) { - handleImages(element); - newArtifactElement.appendChild(element.cloneNode(true)); - } - } - - validateEditTags(); - clearImageIds(); - return artifactElements; - } - - private ParseState handleEndElement(OseeLinkBuilder linkBuilder, - Element newArtifactElement, Element element) { - ParseState parseState; - numberOfEndTags++; - guid = null; - parseState = ParseState.LOOKING_FOR_START; - - Node clonedElement = cloneWithoutArtifactEditImage(element, - Side.left, linkBuilder); - if (elementHasGrandChildren(clonedElement)) { - newArtifactElement.appendChild(clonedElement); - } - return parseState; - } - - private Element handleStartElement(OseeLinkBuilder linkBuilder, - final List<Element> artifactElements, Element element) { - Element newArtifactElement; - numberOfStartTags++; - newArtifactElement = document - .createElement("WordAttribute.WORD_TEMPLATE_CONTENT"); - populateNewArtifactElement(newArtifactElement); - artifactElements.add(newArtifactElement); - - Node clonedElement = cloneWithoutArtifactEditImage(element, - Side.right, linkBuilder); - if (elementHasGrandChildren(clonedElement)) { - newArtifactElement.appendChild(clonedElement); - } - return newArtifactElement; - } - - private void clearImageIds() { - START_IMG_ID = null; - END_IMG_ID = null; - } - - private boolean elementHasGrandChildren(Node element) { - return element.getChildNodes().getLength() > 0 - && element.getChildNodes().item(0).getChildNodes().getLength() > 0; - } - - private Node cloneWithoutArtifactEditImage(Element element, Side keepSide, - OseeLinkBuilder linkBuilder) { - Collection<Node> removals = new LinkedList<Node>(); - - Element clonedElement = (Element) element.cloneNode(true); - boolean beforeEditTag = true; - boolean afterEditTag = false; - NodeList descendants = clonedElement.getElementsByTagName("*"); - - for (int i = 0; i < descendants.getLength(); i++) { - Node descendant = descendants.item(i); - if (isEditStartImage(descendant)) { - removals.add(descendant); - beforeEditTag = false; - } else if (isEditEndImage(descendant)) { - removals.add(descendant); - afterEditTag = true; - } else if ((beforeEditTag && keepSide == Side.right) - || (afterEditTag && keepSide == Side.left)) { - removals.add(descendant); - } - } - - for (Node remove : removals) { - Node parentNode = remove.getParentNode(); - if (parentNode != null) { - parentNode.removeChild(remove); - } - } - return clonedElement; - } - - private boolean isEditEndImage(Node descendant) { - return isEditImage(descendant, false); - } - - private boolean isEditStartImage(Node descendant) { - return isEditImage(descendant, true); - } - - private boolean isEditImage(Node element, boolean lookingForStartImage) { - boolean hasEditImage = false; - String pictName = WordUtil.elementNameFor(PICT); - String name = element.getNodeName(); - - if (name.contains(pictName)) { - hasEditImage = isImageBinData((Element) element, lookingForStartImage); - } - return hasEditImage; - } - - private boolean isImageBinData(Element pictElement, boolean lookingForStart) { - boolean foundBinData = false; - String imageId; - - if (lookingForStart) { - imageId = START_IMG_ID; - } else { - imageId = END_IMG_ID; - } - - if (imageId == null) { - foundBinData = compareBinData(pictElement, lookingForStart); - } else { - foundBinData = compareImageId(imageId, getImageId(pictElement)); - } - - if(foundBinData){ - setGuid(pictElement); - } - return foundBinData; - } - - private boolean compareImageId(String storedImageId, String currentElementId){ - return storedImageId.equals(currentElementId); - } - - private boolean compareBinData(Element pictElement, boolean lookingForStart) { - boolean foundBindata = false; - String binData; - - if (lookingForStart) { - binData = OseeLinkBuilder.START_BIN_DATA; - } else { - binData = OseeLinkBuilder.END_BIN_DATA; - } - - Node currentBinData = getElement(pictElement, BIN_DATA); - if (currentBinData != null) { - Node bindDataValue = currentBinData.getFirstChild(); - foundBindata = getCheckSum(bindDataValue.getNodeValue()) == (getCheckSum(binData)); - if (foundBindata) { - if (lookingForStart) { - START_IMG_ID = getImageId(pictElement); - } else { - END_IMG_ID = getImageId(pictElement); - } - } - } - return foundBindata; - } - - private String getImageId(Element pictElement) { - String imgId = null; - Node imageData = getElement(pictElement, IMAGE); - - if (imageData != null) { - Node srcAttribute = imageData.getAttributes().getNamedItem(SRC); - imgId = srcAttribute.getNodeValue(); - } - return imgId; - } - - private void setGuid(Element pictElement) { - Node imageData = getElement(pictElement, IMAGE); - - if (imageData != null) { - Node srcAttribute = imageData.getAttributes().getNamedItem(TITLE); - guid = srcAttribute.getNodeValue(); - } - } - - private Node getElement(Element element, String name) { - Node discoveredNode = null; - NodeList descendants = element.getElementsByTagName("*"); - - for (int i = 0; i < descendants.getLength(); i++) { - Node descendant = descendants.item(i); - String descendantName = descendant.getNodeName(); - if (descendantName.contains(name)) { - discoveredNode = descendant; - break; - } - } - return discoveredNode; - } - - private static int getCheckSum(String data) { - int checksum = -1; - for (int index = 0; index < data.length(); index++) { - char character = data.charAt(index); - if (character != '\n' && character != '\t' && character != '\r' - && character != ' ') { - checksum += character; - } - } - return checksum; - } - - private void validateEditTags() throws OseeCoreException { - if (numberOfStartTags == 0 || numberOfEndTags != numberOfStartTags) { - throw new OseeCoreException( - "This document is missing start/end edit tags, therefore the document will not be saved. You can re-edit the artifact and the edit tags should reappear."); - } - } - - private void populateNewArtifactElement(Element newArtifactElement) throws DOMException { - newArtifactElement.setAttribute("guid", guid); - } - - private boolean isArtifactEditTag(Element element, boolean lookingForStart) { - if (!properLevelChild(element)) { - return false; - } - boolean isArtifactEditTag = false; - NodeList descendants = element.getElementsByTagName("*"); - for (int i = 0; i < descendants.getLength(); i++) { - Node descendant = descendants.item(i); - isArtifactEditTag = isEditImage(descendant, lookingForStart); - - if (isArtifactEditTag) { - break; - } - } - return isArtifactEditTag; - } - - private boolean properLevelChild(Element element) { - return (properLevelChildWord2003(element) || properLevelChildWord2007(element)); - } - - private void handleImages(Element element) { - NodeList descendants = element.getElementsByTagName("*"); - for (int i = 0; i < descendants.getLength(); i++) { - Node descendant = descendants.item(i); - if (descendant.getNodeName().contains(PICT)) { - NodeList imageDataElement = ((Element) descendant) - .getElementsByTagName(IMAGE); - if (imageDataElement.getLength() > 0) { - String imgKey = ((Element) imageDataElement.item(0)) - .getAttribute(SRC); - Element storedPictureElement = pictureMap.get(imgKey); - NodeList binDataElement = ((Element) descendant) - .getElementsByTagName(BIN_DATA); - - if (storedPictureElement != null) { - if (binDataElement.getLength() == 0) { - descendant.appendChild(storedPictureElement); - } - } else { - pictureMap.put(imgKey, (Element) binDataElement.item(0)); - } - } - } - } - } - - private String getAncestorName(Element element, int level) { - String name = ""; - Node parent = element; - for (int i = 0; i < level; i++) { - if (parent != null) { - parent = parent.getParentNode(); - } - } - if (parent != null) { - name = parent.getNodeName(); - } - return name; - } - - private boolean properLevelChildWord2003(Element element) { - String grandParentName = getAncestorName(element, 2); - String parentName = getAncestorName(element, 1); - String myName = element.getNodeName(); - - boolean nonSubsectionBodyChild = parentName.equals(BODY_TAG) - && !myName.equals(SUB_SECTION_TAG) - && !myName.equals(SECTION_TAG); - boolean sectionChild = grandParentName.equals(BODY_TAG) - && parentName.equals(SECTION_TAG) - && !myName.equals(SUB_SECTION_TAG); - boolean subsectionChild = parentName.equals(SUB_SECTION_TAG) - && !myName.equals(SUB_SECTION_TAG); - - return (nonSubsectionBodyChild || sectionChild || subsectionChild); - } - - private boolean properLevelChildWord2007(Element element) { - String parentName = getAncestorName(element, 1); - String myName = element.getNodeName(); - - boolean nonSubsectionBodyChild = parentName.equals(BODY_TAG) - && !myName.equals(SUB_SECTION_TAG) - && !myName.equals(SECTION_TAG); - boolean subsectionChild = parentName.equals(SUB_SECTION_TAG) - && !myName.equals(SUB_SECTION_TAG); - - return nonSubsectionBodyChild || subsectionChild; - } -} + private static final String SECTION_TAG = "wx:sect"; + private static final String SUB_SECTION_TAG = "wx:sub-section"; + private static final String BODY_TAG = "w:body"; + private static final String PICT = "pict"; + private static final String IMAGE = "v:imagedata"; + private static final String SRC = "src"; + private static final String BIN_DATA = "w:binData"; + private static String START_IMG_ID; + private static String END_IMG_ID; + private static final String TITLE = "o:title"; + + private final Map<String, Element> pictureMap; + private Element oleDataElement; + private final Document document; + private int numberOfStartTags; + private int numberOfEndTags; + private String guid; + + private enum ParseState { + LOOKING_FOR_START, + LOOKING_FOR_END + }; + + private enum Side { + left, + right + }; + + public WordImageArtifactElementExtractor(Document document) { + super(); + this.document = document; + this.numberOfEndTags = 0; + this.numberOfStartTags = 0; + this.pictureMap = new HashMap<String, Element>(); + } + + @Override + public Element getOleDataElement() { + return oleDataElement; + } + + @Override + public List<Element> extractElements() throws DOMException, OseeCoreException { + OseeLinkBuilder linkBuilder = new OseeLinkBuilder(); + return extractElements(linkBuilder); + } + + private void resetClassFields() { + pictureMap.clear(); + numberOfStartTags = 0; + numberOfEndTags = 0; + oleDataElement = null; + guid = null; + } + + public List<Element> extractElements(OseeLinkBuilder linkBuilder) throws DOMException, OseeCoreException { + final List<Element> artifactElements = new LinkedList<Element>(); + Element rootElement = document.getDocumentElement(); + resetClassFields(); + + NodeList nodeList = rootElement.getElementsByTagName("*"); + Element newArtifactElement = null; + ParseState parseState = ParseState.LOOKING_FOR_START; + + for (int i = 0; i < nodeList.getLength(); i++) { + Element element = (Element) nodeList.item(i); + if (parseState == ParseState.LOOKING_FOR_START && isArtifactEditTag(element, true)) { + parseState = ParseState.LOOKING_FOR_END; + newArtifactElement = handleStartElement(linkBuilder, artifactElements, element); + } else if (parseState == ParseState.LOOKING_FOR_END && isArtifactEditTag(element, false)) { + parseState = handleEndElement(linkBuilder, newArtifactElement, element); + } else if (parseState == ParseState.LOOKING_FOR_END && properLevelChild(element)) { + handleImages(element); + newArtifactElement.appendChild(element.cloneNode(true)); + } + } + + validateEditTags(); + clearImageIds(); + return artifactElements; + } + + private ParseState handleEndElement(OseeLinkBuilder linkBuilder, Element newArtifactElement, Element element) { + ParseState parseState; + numberOfEndTags++; + guid = null; + parseState = ParseState.LOOKING_FOR_START; + + Node clonedElement = cloneWithoutArtifactEditImage(element, Side.left, linkBuilder); + if (elementHasGrandChildren(clonedElement)) { + newArtifactElement.appendChild(clonedElement); + } + return parseState; + } + + private Element handleStartElement(OseeLinkBuilder linkBuilder, final List<Element> artifactElements, Element element) { + Element newArtifactElement; + numberOfStartTags++; + newArtifactElement = document.createElement("WordAttribute.WORD_TEMPLATE_CONTENT"); + populateNewArtifactElement(newArtifactElement); + artifactElements.add(newArtifactElement); + + Node clonedElement = cloneWithoutArtifactEditImage(element, Side.right, linkBuilder); + if (elementHasGrandChildren(clonedElement)) { + newArtifactElement.appendChild(clonedElement); + } + return newArtifactElement; + } + + private void clearImageIds() { + START_IMG_ID = null; + END_IMG_ID = null; + } + + private boolean elementHasGrandChildren(Node element) { + return element.getChildNodes().getLength() > 0 && element.getChildNodes().item(0).getChildNodes().getLength() > 0; + } + + private Node cloneWithoutArtifactEditImage(Element element, Side keepSide, OseeLinkBuilder linkBuilder) { + Collection<Node> removals = new LinkedList<Node>(); + + Element clonedElement = (Element) element.cloneNode(true); + boolean beforeEditTag = true; + boolean afterEditTag = false; + NodeList descendants = clonedElement.getElementsByTagName("*"); + + for (int i = 0; i < descendants.getLength(); i++) { + Node descendant = descendants.item(i); + if (isEditStartImage(descendant)) { + removals.add(descendant); + beforeEditTag = false; + } else if (isEditEndImage(descendant)) { + removals.add(descendant); + afterEditTag = true; + } else if ((beforeEditTag && keepSide == Side.right) || (afterEditTag && keepSide == Side.left)) { + removals.add(descendant); + } + } + + for (Node remove : removals) { + Node parentNode = remove.getParentNode(); + if (parentNode != null) { + parentNode.removeChild(remove); + } + } + return clonedElement; + } + + private boolean isEditEndImage(Node descendant) { + return isEditImage(descendant, false); + } + + private boolean isEditStartImage(Node descendant) { + return isEditImage(descendant, true); + } + + private boolean isEditImage(Node element, boolean lookingForStartImage) { + boolean hasEditImage = false; + String pictName = WordUtil.elementNameFor(PICT); + String name = element.getNodeName(); + + if (name.contains(pictName)) { + hasEditImage = isImageBinData((Element) element, lookingForStartImage); + } + return hasEditImage; + } + + private boolean isImageBinData(Element pictElement, boolean lookingForStart) { + boolean foundBinData = false; + String imageId; + + if (lookingForStart) { + imageId = START_IMG_ID; + } else { + imageId = END_IMG_ID; + } + + if (imageId == null) { + foundBinData = compareBinData(pictElement, lookingForStart); + } else { + foundBinData = compareImageId(imageId, getImageId(pictElement)); + } + + if (foundBinData) { + setGuid(pictElement); + } + return foundBinData; + } + + private boolean compareImageId(String storedImageId, String currentElementId) { + return storedImageId.equals(currentElementId); + } + + private boolean compareBinData(Element pictElement, boolean lookingForStart) { + boolean foundBindata = false; + String binData; + + if (lookingForStart) { + binData = OseeLinkBuilder.START_BIN_DATA; + } else { + binData = OseeLinkBuilder.END_BIN_DATA; + } + + Node currentBinData = getElement(pictElement, BIN_DATA); + if (currentBinData != null) { + Node bindDataValue = currentBinData.getFirstChild(); + foundBindata = getCheckSum(bindDataValue.getNodeValue()) == (getCheckSum(binData)); + if (foundBindata) { + if (lookingForStart) { + START_IMG_ID = getImageId(pictElement); + } else { + END_IMG_ID = getImageId(pictElement); + } + } + } + return foundBindata; + } + + private String getImageId(Element pictElement) { + String imgId = null; + Node imageData = getElement(pictElement, IMAGE); + + if (imageData != null) { + Node srcAttribute = imageData.getAttributes().getNamedItem(SRC); + imgId = srcAttribute.getNodeValue(); + } + return imgId; + } + + private void setGuid(Element pictElement) { + Node imageData = getElement(pictElement, IMAGE); + + if (imageData != null) { + Node srcAttribute = imageData.getAttributes().getNamedItem(TITLE); + guid = srcAttribute.getNodeValue(); + } + } + + private Node getElement(Element element, String name) { + Node discoveredNode = null; + NodeList descendants = element.getElementsByTagName("*"); + + for (int i = 0; i < descendants.getLength(); i++) { + Node descendant = descendants.item(i); + String descendantName = descendant.getNodeName(); + if (descendantName.contains(name)) { + discoveredNode = descendant; + break; + } + } + return discoveredNode; + } + + private static int getCheckSum(String data) { + int checksum = -1; + for (int index = 0; index < data.length(); index++) { + char character = data.charAt(index); + if (character != '\n' && character != '\t' && character != '\r' && character != ' ') { + checksum += character; + } + } + return checksum; + } + + private void validateEditTags() throws OseeCoreException { + if (numberOfStartTags == 0 || numberOfEndTags != numberOfStartTags) { + throw new OseeCoreException( + "This document is missing start/end edit tags, therefore the document will not be saved. You can re-edit the artifact and the edit tags should reappear."); + } + } + + private void populateNewArtifactElement(Element newArtifactElement) throws DOMException { + newArtifactElement.setAttribute("guid", guid); + } + + private boolean isArtifactEditTag(Element element, boolean lookingForStart) { + if (!properLevelChild(element)) { + return false; + } + boolean isArtifactEditTag = false; + NodeList descendants = element.getElementsByTagName("*"); + for (int i = 0; i < descendants.getLength(); i++) { + Node descendant = descendants.item(i); + isArtifactEditTag = isEditImage(descendant, lookingForStart); + + if (isArtifactEditTag) { + break; + } + } + return isArtifactEditTag; + } + + private boolean properLevelChild(Element element) { + return (properLevelChildWord2003(element) || properLevelChildWord2007(element)); + } + + private void handleImages(Element element) { + NodeList descendants = element.getElementsByTagName("*"); + for (int i = 0; i < descendants.getLength(); i++) { + Node descendant = descendants.item(i); + if (descendant.getNodeName().contains(PICT)) { + NodeList imageDataElement = ((Element) descendant).getElementsByTagName(IMAGE); + if (imageDataElement.getLength() > 0) { + String imgKey = ((Element) imageDataElement.item(0)).getAttribute(SRC); + Element storedPictureElement = pictureMap.get(imgKey); + NodeList binDataElement = ((Element) descendant).getElementsByTagName(BIN_DATA); + + if (storedPictureElement != null) { + if (binDataElement.getLength() == 0) { + descendant.appendChild(storedPictureElement); + } + } else { + pictureMap.put(imgKey, (Element) binDataElement.item(0)); + } + } + } + } + } + + private String getAncestorName(Element element, int level) { + String name = ""; + Node parent = element; + for (int i = 0; i < level; i++) { + if (parent != null) { + parent = parent.getParentNode(); + } + } + if (parent != null) { + name = parent.getNodeName(); + } + return name; + } + + private boolean properLevelChildWord2003(Element element) { + String grandParentName = getAncestorName(element, 2); + String parentName = getAncestorName(element, 1); + String myName = element.getNodeName(); + + boolean nonSubsectionBodyChild = + parentName.equals(BODY_TAG) && !myName.equals(SUB_SECTION_TAG) && !myName.equals(SECTION_TAG); + boolean sectionChild = + grandParentName.equals(BODY_TAG) && parentName.equals(SECTION_TAG) && !myName.equals(SUB_SECTION_TAG); + boolean subsectionChild = parentName.equals(SUB_SECTION_TAG) && !myName.equals(SUB_SECTION_TAG); + + return (nonSubsectionBodyChild || sectionChild || subsectionChild); + } + + private boolean properLevelChildWord2007(Element element) { + String parentName = getAncestorName(element, 1); + String myName = element.getNodeName(); + + boolean nonSubsectionBodyChild = + parentName.equals(BODY_TAG) && !myName.equals(SUB_SECTION_TAG) && !myName.equals(SECTION_TAG); + boolean subsectionChild = parentName.equals(SUB_SECTION_TAG) && !myName.equals(SUB_SECTION_TAG); + + return nonSubsectionBodyChild || subsectionChild; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/compare/AbstractWordCompare.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/compare/AbstractWordCompare.java index 79b57270618..7ffc7b04cea 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/compare/AbstractWordCompare.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/compare/AbstractWordCompare.java @@ -71,9 +71,6 @@ public abstract class AbstractWordCompare implements IComparator { presentationType == PresentationType.MERGE_EDIT); if (presentationType == PresentationType.MERGE_EDIT && baseVersion != null) { - IFolder folder = RenderingUtil.getRenderFolder(baseVersion.getBranch(), PresentationType.MERGE_EDIT); - renderer.addFileToWatcher(folder, diffPath.substring(diffPath.lastIndexOf('\\') + 1)); - diffGenerator.addComparison(baseFile, newerFile, diffPath, true); launchCompareVbs(diffGenerator, diffPath, "mergeDocs.vbs"); } else { |