Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2008-09-26 16:55:16 +0000
committerafinkbein2008-09-26 16:55:16 +0000
commit2d77631d7d243763b2480c80db1cc4904281fccb (patch)
treea6e7ebdbd59c287f45b5f1116d20466cb4ebd3f8
parentfcf986b63795e6d16d556011bfb648eeb996110b (diff)
downloadorg.eclipse.osee-2d77631d7d243763b2480c80db1cc4904281fccb.tar.gz
org.eclipse.osee-2d77631d7d243763b2480c80db1cc4904281fccb.tar.xz
org.eclipse.osee-2d77631d7d243763b2480c80db1cc4904281fccb.zip
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/.classpath7
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/.project28
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/.settings/org.eclipse.pde.core.prefs4
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/META-INF/MANIFEST.MF14
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/build.properties4
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/Activator.java26
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/OptionsProcessor.java132
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/CompressedResourceBridge.java66
-rw-r--r--org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/Resources.java65
9 files changed, 346 insertions, 0 deletions
diff --git a/org.eclipse.osee.framework.resource.provider.common/.classpath b/org.eclipse.osee.framework.resource.provider.common/.classpath
new file mode 100644
index 00000000000..8a8f1668cdc
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.osee.framework.resource.provider.common/.project b/org.eclipse.osee.framework.resource.provider.common/.project
new file mode 100644
index 00000000000..e2f3ddabd67
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.framework.resource.provider.common</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.osee.framework.resource.provider.common/.settings/org.eclipse.pde.core.prefs b/org.eclipse.osee.framework.resource.provider.common/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 00000000000..c6d8450861f
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Wed May 07 16:13:05 MST 2008
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/org.eclipse.osee.framework.resource.provider.common/META-INF/MANIFEST.MF b/org.eclipse.osee.framework.resource.provider.common/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..d89296b01a9
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Resource Provider Common Plug-in
+Bundle-SymbolicName: org.eclipse.osee.framework.resource.provider.common
+Bundle-Version: 0.4.0.qualifier
+Bundle-Vendor: Boeing
+Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.osee.framework.resource.common.io,
+ org.osgi.framework;version="1.4.0"
+Require-Bundle: org.eclipse.osee.framework.resource.management
+Bundle-Activator: org.eclipse.osee.framework.resource.provider.common.Activator
+Export-Package: org.eclipse.osee.framework.resource.provider.common,
+ org.eclipse.osee.framework.resource.provider.common.resources
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/org.eclipse.osee.framework.resource.provider.common/build.properties b/org.eclipse.osee.framework.resource.provider.common/build.properties
new file mode 100644
index 00000000000..41eb6ade2b4
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/Activator.java b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/Activator.java
new file mode 100644
index 00000000000..c97d9b0bddd
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/Activator.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.resource.provider.common;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ @Override
+ public void start(BundleContext arg0) throws Exception {
+ }
+
+ @Override
+ public void stop(BundleContext arg0) throws Exception {
+ }
+
+}
diff --git a/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/OptionsProcessor.java b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/OptionsProcessor.java
new file mode 100644
index 00000000000..81e5b169ca4
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/OptionsProcessor.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * 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.resource.provider.common;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import org.eclipse.osee.framework.resource.common.io.Files;
+import org.eclipse.osee.framework.resource.management.IResource;
+import org.eclipse.osee.framework.resource.management.IResourceLocator;
+import org.eclipse.osee.framework.resource.management.Options;
+import org.eclipse.osee.framework.resource.management.Resource;
+import org.eclipse.osee.framework.resource.management.ResourceLocator;
+import org.eclipse.osee.framework.resource.management.StandardOptions;
+import org.eclipse.osee.framework.resource.provider.common.resources.Resources;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class OptionsProcessor {
+
+ private URI fileuri;
+ private URI locatoruri;
+ private IResource resource;
+ private String extension;
+ private boolean deCompressOnSave;
+ private boolean shouldCompress;
+ private boolean decompressOnAcquire;
+ private boolean compressOnAcquire;
+ private boolean overwrite;
+
+ /**
+ * @param resource
+ * @param uri
+ * @param locator
+ * @param options
+ * @throws URISyntaxException
+ */
+ public OptionsProcessor(URI uri, IResourceLocator locator, IResource resource, Options options) throws URISyntaxException {
+ this.resource = resource;
+ decompressOnAcquire = options.getBoolean(StandardOptions.DecompressOnAquire.name());
+ compressOnAcquire = options.getBoolean(StandardOptions.CompressOnAcquire.name());
+ overwrite = options.getBoolean(StandardOptions.Overwrite.name());
+ shouldCompress = options.getBoolean(StandardOptions.CompressOnSave.name());
+ deCompressOnSave = options.getBoolean(StandardOptions.DecompressOnSave.name());
+ extension = options.getString(StandardOptions.Extension.name());
+
+ StringBuilder sb = new StringBuilder(uri.toString());
+ StringBuilder sb2 = new StringBuilder(locator.toString());
+ if (extension.length() > 0) {
+ sb.append(".");
+ sb.append(extension);
+ sb2.append(".");
+ sb2.append(extension);
+ }
+ if (shouldCompress) {
+ sb.append(".");
+ sb.append("zip");
+ sb2.append(".");
+ sb2.append("zip");
+ }
+ this.fileuri = new URI(sb.toString());
+ this.locatoruri = new URI(sb2.toString());
+ }
+
+ /**
+ * @return
+ * @throws IOException
+ */
+ public File getStorageFile() throws IOException {
+ File storageFile = new File(fileuri);
+ if (!overwrite) {
+ if (storageFile.exists()) {
+ throw new IOException(String.format("The file [%s] already exists.", storageFile.getAbsolutePath()));
+ }
+ }
+ File parent = storageFile.getParentFile();
+ if (parent != null && !parent.exists()) {
+ parent.mkdirs();
+ }
+ return storageFile;
+ }
+
+ /**
+ * @return
+ * @throws Exception
+ */
+ public IResource getResourceToStore() throws Exception {
+ IResource resourceToReturn;
+ if (shouldCompress && !resource.isCompressed()) {
+ resourceToReturn = Resources.compressResource(resource);
+ } else if (deCompressOnSave && resource.isCompressed()) {
+ resourceToReturn = Resources.decompressResource(resource);
+ } else {
+ resourceToReturn = resource;
+ }
+ return resourceToReturn;
+ }
+
+ public IResource getResourceToServer() throws Exception {
+ IResource toReturn = null;
+ File testFile = new File(this.fileuri);
+ if (testFile != null && testFile.exists() != false) {
+ boolean isCompressed = Files.isCompressed(testFile);
+ toReturn = new Resource(this.fileuri, isCompressed);
+
+ if (compressOnAcquire && !isCompressed) {
+ toReturn = Resources.compressResource(toReturn);
+ } else if (decompressOnAcquire && isCompressed) {
+ toReturn = Resources.decompressResource(toReturn);
+ }
+ }
+ return toReturn;
+ }
+
+ /**
+ * @return
+ */
+ public IResourceLocator getActualResouceLocator() {
+ return new ResourceLocator(this.locatoruri);
+ }
+
+}
diff --git a/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/CompressedResourceBridge.java b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/CompressedResourceBridge.java
new file mode 100644
index 00000000000..458f5c24e32
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/CompressedResourceBridge.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.resource.provider.common.resources;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import org.eclipse.osee.framework.resource.management.IResource;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CompressedResourceBridge implements IResource {
+ private byte[] backing;
+ private boolean isCompressed;
+ private URI uri;
+
+ public CompressedResourceBridge(byte[] backing, URI uri, boolean isCompressed) {
+ this.backing = backing;
+ this.isCompressed = isCompressed;
+ this.uri = uri;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.resource.management.IResource#getContent()
+ */
+ @Override
+ public InputStream getContent() throws IOException {
+ return new ByteArrayInputStream(backing);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.resource.management.IResource#getLocation()
+ */
+ @Override
+ public URI getLocation() {
+ return uri;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.resource.management.IResource#getName()
+ */
+ @Override
+ public String getName() {
+ String value = uri.toASCIIString();
+ return value.substring(value.lastIndexOf("/") + 1, value.length());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.resource.management.IResource#isCompressed()
+ */
+ @Override
+ public boolean isCompressed() {
+ return isCompressed;
+ }
+
+}
diff --git a/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/Resources.java b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/Resources.java
new file mode 100644
index 00000000000..ba0205e77c3
--- /dev/null
+++ b/org.eclipse.osee.framework.resource.provider.common/src/org/eclipse/osee/framework/resource/provider/common/resources/Resources.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.resource.provider.common.resources;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URLEncoder;
+import org.eclipse.osee.framework.resource.common.io.Files;
+import org.eclipse.osee.framework.resource.common.io.Streams;
+import org.eclipse.osee.framework.resource.management.IResource;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class Resources {
+
+ private static String removeName(String path) {
+ int index = path.lastIndexOf("/");
+ if (index != -1) {
+ path = path.substring(0, index + 1);
+ }
+ return path;
+ }
+
+ public static IResource compressResource(IResource resource) throws Exception {
+ InputStream inputStream = null;
+ byte[] buffer = new byte[0];
+ try {
+ inputStream = resource.getContent();
+ buffer = Streams.compressStream(inputStream, resource.getName());
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ return new CompressedResourceBridge(buffer, new URI(resource.getLocation() + ".zip"), true);
+ }
+
+ public static IResource decompressResource(IResource resource) throws Exception {
+ String path = resource.getLocation().toASCIIString();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ String fileName = null;
+ try {
+ fileName = Streams.decompressStream(resource.getContent(), outputStream);
+ fileName = URLEncoder.encode(fileName, "UTF-8");
+ } finally {
+ outputStream.close();
+ }
+ if (fileName != null && fileName.length() > 0) {
+ path = removeName(path) + fileName;
+ } else {
+ path = Files.removeExtension(path);
+ }
+ return new CompressedResourceBridge(outputStream.toByteArray(), new URI(path), false);
+ }
+}

Back to the top