Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.resource.management/src/org')
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ByteStreamResource.java59
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/DataResource.java78
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResource.java23
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocator.java17
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocatorProvider.java23
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceManager.java50
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceProvider.java26
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ResourceManager.java218
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/StandardOptions.java17
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/exception/MalformedLocatorException.java17
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/CompressedResourceBridge.java17
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/ResourceManager.java126
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/OptionsProcessor.java25
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resource.java19
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/ResourceLocator.java20
-rw-r--r--plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resources.java23
16 files changed, 511 insertions, 247 deletions
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ByteStreamResource.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ByteStreamResource.java
new file mode 100644
index 00000000000..c734cc6fbfb
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ByteStreamResource.java
@@ -0,0 +1,59 @@
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ **********************************************************************/
+
+package org.eclipse.osee.framework.resource.management;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ByteStreamResource implements IResource {
+
+ private final IResourceLocator locator;
+ private final byte[] rawContent;
+ private final boolean isCompressed;
+
+ public ByteStreamResource(IResourceLocator locator, byte[] rawContent, boolean isCompressed) {
+ this.locator = locator;
+ this.rawContent = rawContent;
+ this.isCompressed = isCompressed;
+ }
+
+ @Override
+ public InputStream getContent() {
+ return new ByteArrayInputStream(rawContent);
+ }
+
+ @Override
+ public URI getLocation() {
+ return locator.getLocation();
+ }
+
+ @Override
+ public String getName() {
+ String path = locator.getLocation().toASCIIString();
+ int index = path.lastIndexOf("/");
+ if (index != -1 && index + 1 < path.length()) {
+ path = path.substring(index + 1, path.length());
+ }
+ return path;
+ }
+
+ @Override
+ public boolean isCompressed() {
+ return isCompressed;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/DataResource.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/DataResource.java
new file mode 100644
index 00000000000..867b1a6e396
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/DataResource.java
@@ -0,0 +1,78 @@
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ **********************************************************************/
+
+package org.eclipse.osee.framework.resource.management;
+
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DataResource {
+
+ private String contentType;
+ private String encoding;
+ private String extension;
+ private String locator;
+
+ public DataResource() {
+ }
+
+ public DataResource(String contentType, String encoding, String extension, String locator) {
+ this.contentType = contentType;
+ this.encoding = encoding;
+ this.extension = extension;
+ this.locator = locator;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public String getExtension() {
+ return extension;
+ }
+
+ public String getLocator() {
+ return locator;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void setExtension(String extension) {
+ this.extension = extension;
+ }
+
+ public void setLocator(String locator) {
+ this.locator = locator;
+ }
+
+ public boolean isLocatorValid() {
+ return Strings.isValid(getLocator());
+ }
+
+ @Override
+ public String toString() {
+ return "DataResource [contentType=" + contentType + ", encoding=" + encoding + ", extension=" + extension + ", locator=" + locator + "]";
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResource.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResource.java
index 4da208c3d77..096d8bd8528 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResource.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResource.java
@@ -1,18 +1,20 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management;
import java.io.InputStream;
import java.net.URI;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
/**
* @author Roberto E. Escobar
@@ -22,10 +24,9 @@ public interface IResource {
/**
* Returns an open input stream of the contents of this resource.
*
- * @return an input stream containing the contents of this resource
- * @throws OseeCoreException if this method fails.
+ * @return an input stream containing the contents of this resource if this method fails.
*/
- public InputStream getContent() throws OseeCoreException;
+ public InputStream getContent();
/**
* Returns the absolute URI of this resource, or <code>null</code> if no URI can be determined.
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocator.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocator.java
index ac77bf99eb3..281969ad0e4 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocator.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocator.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management;
import java.net.URI;
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocatorProvider.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocatorProvider.java
index fd00a1c560d..683fbf0de80 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocatorProvider.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceLocatorProvider.java
@@ -1,16 +1,17 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.resource.management;
+ **********************************************************************/
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+package org.eclipse.osee.framework.resource.management;
/**
* @author Roberto E. Escobar
@@ -34,12 +35,12 @@ public interface IResourceLocatorProvider {
*
* @return a resource locator
*/
- IResourceLocator generateResourceLocator(String seed, String name) throws OseeCoreException;
+ IResourceLocator generateResourceLocator(String seed, String name);
/**
* Get resource locator
*
* @return a resource locator
*/
- IResourceLocator getResourceLocator(String path) throws OseeCoreException;
+ IResourceLocator getResourceLocator(String path);
}
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceManager.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceManager.java
index eaf351c68a7..04e8652dd63 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceManager.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceManager.java
@@ -1,17 +1,19 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management;
import java.util.Collection;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
/**
@@ -25,54 +27,60 @@ public interface IResourceManager {
/**
* Acquire resource specified by resource locator
- *
+ *
* @param locator location of the resource needed
* @param options operation options
* @return the resource
*/
- IResource acquire(IResourceLocator locator, PropertyStore options) throws OseeCoreException;
+ IResource acquire(IResourceLocator locator, PropertyStore options);
/**
* Determines if a resource exists for the given locator.
- *
+ *
* @param locator location of the data to check
*/
- boolean exists(IResourceLocator locator) throws OseeCoreException;
+ boolean exists(IResourceLocator locator);
/**
* Save input to location specified by resource locator
- *
+ *
* @param locator location where to store the data
* @param resource to store
* @param options operation options
*/
- IResourceLocator save(final IResourceLocator locatorHint, final IResource resource, final PropertyStore options) throws OseeCoreException;
+ IResourceLocator save(final IResourceLocator locatorHint, final IResource resource, final PropertyStore options);
/**
* Delete resource specified by resource locator
- *
+ *
* @param locator location of the resource to delete
*/
- int delete(IResourceLocator locator) throws OseeCoreException;
+ int delete(IResourceLocator locator);
/**
* Generate a resource locator based on protocol, seed and name
- *
+ *
* @return a resource locator
*/
- IResourceLocator generateResourceLocator(String protocol, String seed, String name) throws OseeCoreException;
+ IResourceLocator generateResourceLocator(String protocol, String seed, String name);
/**
* Get resource locator based on protocol and path
- *
+ *
* @return a resource locator
*/
- IResourceLocator getResourceLocator(String path) throws OseeCoreException;
+ IResourceLocator getResourceLocator(String path);
/**
* Supported Protocols
- *
+ *
* @return supported protocols
*/
Collection<String> getProtocols();
+
+ byte[] acquire(DataResource dataResource);
+
+ void save(long storageId, String storageName, DataResource dataResource, byte[] rawContent);
+
+ void purge(DataResource dataResource);
}
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceProvider.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceProvider.java
index 880f05e5ca0..c97b1a69499 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceProvider.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/IResourceProvider.java
@@ -1,17 +1,19 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management;
import java.util.Collection;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
/**
@@ -33,14 +35,14 @@ public interface IResourceProvider {
* @param options operation options
* @return the resource
*/
- public IResource acquire(IResourceLocator locator, PropertyStore options) throws OseeCoreException;
+ public IResource acquire(IResourceLocator locator, PropertyStore options);
/**
* Determines if a resource exists for the given locator.
*
* @param locator location of the data to check
*/
- public boolean exists(IResourceLocator locator) throws OseeCoreException;
+ public boolean exists(IResourceLocator locator);
/**
* Save input to location specified by resource locator
@@ -49,14 +51,14 @@ public interface IResourceProvider {
* @param options operation options
* @param resource the resource to save
*/
- public IResourceLocator save(IResourceLocator locator, IResource resource, PropertyStore options) throws OseeCoreException;
+ public IResourceLocator save(IResourceLocator locator, IResource resource, PropertyStore options);
/**
* Delete resource specified by resource locator
*
* @param locator location of the resource to delete
*/
- public int delete(IResourceLocator locator) throws OseeCoreException;
+ public int delete(IResourceLocator locator);
/**
* Get provider supported protocols
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ResourceManager.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ResourceManager.java
new file mode 100644
index 00000000000..bfc08502f63
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/ResourceManager.java
@@ -0,0 +1,218 @@
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ **********************************************************************/
+
+package org.eclipse.osee.framework.resource.management;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.core.exception.OseeNotFoundException;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
+import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ResourceManager implements IResourceManager {
+ private static final PropertyStore DEFAULT_OPTIONS = new PropertyStore();
+ private final Collection<IResourceProvider> resourceProviders;
+ private final Collection<IResourceLocatorProvider> resourceLocatorProviders;
+
+ public ResourceManager() {
+ this.resourceProviders = new CopyOnWriteArraySet<>();
+ this.resourceLocatorProviders = new CopyOnWriteArraySet<>();
+ }
+
+ private IResourceProvider getProvider(IResourceLocator locator) {
+ for (IResourceProvider provider : resourceProviders) {
+ if (provider.isValid(locator)) {
+ return provider;
+ }
+ }
+
+ throw new OseeNotFoundException("No resource provider found for Locator: [%s]. Searched providers: [%s]",
+ locator, Arrays.deepToString(resourceProviders.toArray()));
+ }
+
+ public void addResourceProvider(IResourceProvider resourceProvider) {
+ resourceProviders.add(resourceProvider);
+ }
+
+ public void removeResourceProvider(IResourceProvider resourceProvider) {
+ resourceProviders.remove(resourceProvider);
+ }
+
+ @Override
+ public IResource acquire(IResourceLocator locator, PropertyStore options) {
+ IResourceProvider provider = getProvider(locator);
+ IResource toReturn = provider.acquire(locator, options);
+ return toReturn;
+ }
+
+ @Override
+ public IResourceLocator save(IResourceLocator locator, IResource resource, PropertyStore options) {
+ IResourceProvider provider = getProvider(locator);
+ IResourceLocator actualLocator = provider.save(locator, resource, options);
+ return actualLocator;
+ }
+
+ @Override
+ public int delete(IResourceLocator locator) {
+ int toReturn = IResourceManager.FAIL;
+ IResourceProvider provider = getProvider(locator);
+ toReturn = provider.delete(locator);
+ return toReturn;
+ }
+
+ @Override
+ public boolean exists(IResourceLocator locator) {
+ IResourceProvider provider = getProvider(locator);
+ return provider.exists(locator);
+ }
+
+ @Override
+ public Collection<String> getProtocols() {
+ Set<String> protocols = new HashSet<>();
+ for (IResourceLocatorProvider provider : resourceLocatorProviders) {
+ protocols.add(provider.getSupportedProtocol());
+ }
+ return protocols;
+ }
+
+ public void addResourceLocatorProvider(IResourceLocatorProvider resourceLocatorProvider) {
+ this.resourceLocatorProviders.add(resourceLocatorProvider);
+ }
+
+ public void removeResourceLocatorProvider(IResourceLocatorProvider resourceLocatorProvider) {
+ this.resourceLocatorProviders.remove(resourceLocatorProvider);
+ }
+
+ @Override
+ public IResourceLocator generateResourceLocator(String protocol, String seed, String name) {
+ IResourceLocatorProvider resourceLocatorProvider = getProvider(protocol);
+ return resourceLocatorProvider.generateResourceLocator(seed, name);
+ }
+
+ @Override
+ public IResourceLocator getResourceLocator(String path) {
+ IResourceLocatorProvider resourceLocatorProvider = getProvider(path);
+ return resourceLocatorProvider.getResourceLocator(path);
+ }
+
+ private IResourceLocatorProvider getProvider(String protocol) {
+ for (IResourceLocatorProvider provider : resourceLocatorProviders) {
+ if (provider.isValid(protocol)) {
+ return provider;
+ }
+ }
+
+ throw new OseeNotFoundException("No locator proivder found for [%s]. Searched providers: [%s]", protocol,
+ Arrays.deepToString(resourceLocatorProviders.toArray()));
+ }
+
+ @Override
+ public byte[] acquire(DataResource dataResource) {
+ String path = dataResource.getLocator();
+ Conditions.checkNotNull(path, "resource path");
+
+ IResourceLocator locator = getResourceLocator(path);
+ Conditions.checkNotNull(locator, "resource locator", "Unable to locate resource: [%s]", path);
+ IResource resource = acquire(locator, DEFAULT_OPTIONS);
+ String mimeType = getContentType(resource);
+
+ byte[] data = null;
+ InputStream inputStream = null;
+ try {
+ inputStream = resource.getContent();
+ data = Lib.inputStreamToBytes(inputStream);
+ } catch (IOException ex) {
+ throw new OseeCoreException(ex, "Error acquiring resource - [%s]", dataResource);
+ } finally {
+ Lib.close(inputStream);
+ }
+ String extension = Lib.getExtension(resource.getName());
+ if (Strings.isValid(extension)) {
+ dataResource.setExtension(extension);
+ }
+ dataResource.setContentType(mimeType);
+ dataResource.setEncoding("ISO-8859-1");
+ return data;
+ }
+
+ @Override
+ public void save(long storageId, String storageName, DataResource dataResource, byte[] rawContent) {
+ StringBuilder fullName = new StringBuilder();
+
+ fullName.append(storageName);
+ String extension = dataResource.getExtension();
+ if (Strings.isValid(extension)) {
+ fullName.append(".");
+ fullName.append(extension);
+ }
+
+ String seed = String.valueOf(storageId);
+ IResourceLocator locatorHint = generateResourceLocator("attr", seed, fullName.toString());
+
+ String contentType = dataResource.getContentType();
+ boolean isCompressed = Strings.isValid(contentType) && contentType.contains("zip");
+
+ IResource resource = new ByteStreamResource(locatorHint, rawContent, isCompressed);
+ IResourceLocator locator = save(locatorHint, resource, DEFAULT_OPTIONS);
+ Conditions.checkNotNull(locator, "locator", "Error saving resource [%s]", locatorHint.getRawPath());
+
+ dataResource.setLocator(locator.getLocation().toASCIIString());
+ }
+
+ @Override
+ public void purge(DataResource dataResource) {
+ String path = dataResource.getLocator();
+ Conditions.checkNotNull(path, "resource path");
+
+ IResourceLocator locator = getResourceLocator(path);
+ Conditions.checkNotNull(locator, "resource locator", "Unable to locate resource [%s]", dataResource);
+
+ int result = delete(locator);
+ if (IResourceManager.OK != result) {
+ throw new OseeDataStoreException("Error deleting resource located at [%s]", dataResource.getLocator());
+ }
+ }
+
+ private static String getContentType(IResource resource) {
+ String mimeType;
+ InputStream inputStream = null;
+ try {
+ inputStream = resource.getContent();
+ mimeType = URLConnection.guessContentTypeFromStream(inputStream);
+ } catch (IOException ex) {
+ throw new OseeCoreException(ex, "Error determining mime type for - [%s]", resource.getName());
+ } finally {
+ Lib.close(inputStream);
+ }
+ if (mimeType == null) {
+ mimeType = URLConnection.guessContentTypeFromName(resource.getLocation().toASCIIString());
+ if (mimeType == null) {
+ mimeType = "application/*";
+ }
+ }
+ return mimeType;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/StandardOptions.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/StandardOptions.java
index 791787e9d70..ec58f100d28 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/StandardOptions.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/StandardOptions.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management;
/**
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/exception/MalformedLocatorException.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/exception/MalformedLocatorException.java
index 8cad5ddfe8e..9e5a98a9b1e 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/exception/MalformedLocatorException.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/exception/MalformedLocatorException.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management.exception;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/CompressedResourceBridge.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/CompressedResourceBridge.java
index 3e3970abfc4..45c41529f01 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/CompressedResourceBridge.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/CompressedResourceBridge.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management.internal;
import java.io.ByteArrayInputStream;
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/ResourceManager.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/ResourceManager.java
deleted file mode 100644
index 79633e1fb3f..00000000000
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/internal/ResourceManager.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * 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.management.internal;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-import org.eclipse.osee.framework.core.exception.OseeNotFoundException;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
-import org.eclipse.osee.framework.resource.management.IResource;
-import org.eclipse.osee.framework.resource.management.IResourceLocator;
-import org.eclipse.osee.framework.resource.management.IResourceLocatorProvider;
-import org.eclipse.osee.framework.resource.management.IResourceManager;
-import org.eclipse.osee.framework.resource.management.IResourceProvider;
-
-/**
- * @author Roberto E. Escobar
- */
-public class ResourceManager implements IResourceManager {
-
- private final Collection<IResourceProvider> resourceProviders;
- private final Collection<IResourceLocatorProvider> resourceLocatorProviders;
-
- public ResourceManager() {
- this.resourceProviders = new CopyOnWriteArraySet<>();
- this.resourceLocatorProviders = new CopyOnWriteArraySet<>();
- }
-
- private IResourceProvider getProvider(IResourceLocator locator) throws OseeCoreException {
- for (IResourceProvider provider : resourceProviders) {
- if (provider.isValid(locator)) {
- return provider;
- }
- }
-
- throw new OseeNotFoundException("No resource provider found for Locator: [%s]. Searched providers: [%s]",
- locator, Arrays.deepToString(resourceProviders.toArray()));
- }
-
- public boolean addResourceProvider(IResourceProvider resourceProvider) {
- return resourceProviders.add(resourceProvider);
- }
-
- public boolean removeResourceProvider(IResourceProvider resourceProvider) {
- return resourceProviders.remove(resourceProvider);
- }
-
- @Override
- public IResource acquire(IResourceLocator locator, PropertyStore options) throws OseeCoreException {
- IResourceProvider provider = getProvider(locator);
- IResource toReturn = provider.acquire(locator, options);
- return toReturn;
- }
-
- @Override
- public IResourceLocator save(IResourceLocator locator, IResource resource, PropertyStore options) throws OseeCoreException {
- IResourceProvider provider = getProvider(locator);
- IResourceLocator actualLocator = provider.save(locator, resource, options);
- return actualLocator;
- }
-
- @Override
- public int delete(IResourceLocator locator) throws OseeCoreException {
- int toReturn = IResourceManager.FAIL;
- IResourceProvider provider = getProvider(locator);
- toReturn = provider.delete(locator);
- return toReturn;
- }
-
- @Override
- public boolean exists(IResourceLocator locator) throws OseeCoreException {
- IResourceProvider provider = getProvider(locator);
- return provider.exists(locator);
- }
-
- @Override
- public Collection<String> getProtocols() {
- Set<String> protocols = new HashSet<>();
- for (IResourceLocatorProvider provider : resourceLocatorProviders) {
- protocols.add(provider.getSupportedProtocol());
- }
- return protocols;
- }
-
- public boolean addResourceLocatorProvider(IResourceLocatorProvider resourceLocatorProvider) {
- return this.resourceLocatorProviders.add(resourceLocatorProvider);
- }
-
- public boolean removeResourceLocatorProvider(IResourceLocatorProvider resourceLocatorProvider) {
- return this.resourceLocatorProviders.remove(resourceLocatorProvider);
- }
-
- @Override
- public IResourceLocator generateResourceLocator(String protocol, String seed, String name) throws OseeCoreException {
- IResourceLocatorProvider resourceLocatorProvider = getProvider(protocol);
- return resourceLocatorProvider.generateResourceLocator(seed, name);
- }
-
- @Override
- public IResourceLocator getResourceLocator(String path) throws OseeCoreException {
- IResourceLocatorProvider resourceLocatorProvider = getProvider(path);
- return resourceLocatorProvider.getResourceLocator(path);
- }
-
- private IResourceLocatorProvider getProvider(String protocol) throws OseeCoreException {
- for (IResourceLocatorProvider provider : resourceLocatorProviders) {
- if (provider.isValid(protocol)) {
- return provider;
- }
- }
-
- throw new OseeNotFoundException("No locator proivder found for [%s]. Searched providers: [%s]", protocol,
- Arrays.deepToString(resourceLocatorProviders.toArray()));
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/OptionsProcessor.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/OptionsProcessor.java
index 68764cf96af..7a1b31fc1f3 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/OptionsProcessor.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/OptionsProcessor.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management.util;
import java.io.File;
@@ -73,7 +76,7 @@ public class OptionsProcessor {
}
}
- public File getStorageFile() throws OseeCoreException {
+ public File getStorageFile() {
File storageFile = new File(fileuri);
if (!overwrite) {
if (storageFile.exists()) {
@@ -89,7 +92,7 @@ public class OptionsProcessor {
return storageFile;
}
- public IResource getResourceToStore() throws OseeCoreException {
+ public IResource getResourceToStore() {
IResource resourceToReturn;
if (shouldCompress && !resource.isCompressed()) {
resourceToReturn = Resources.compressResource(resource);
@@ -101,7 +104,7 @@ public class OptionsProcessor {
return resourceToReturn;
}
- public IResource getResourceToServer() throws OseeCoreException {
+ public IResource getResourceToServer() {
IResource toReturn = null;
File testFile = new File(this.fileuri);
if (testFile.exists()) {
@@ -117,7 +120,7 @@ public class OptionsProcessor {
return toReturn;
}
- public IResourceLocator getActualResouceLocator() throws OseeCoreException {
+ public IResourceLocator getActualResouceLocator() {
return new ResourceLocator(this.locatoruri);
}
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resource.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resource.java
index 9c79edaba2e..aadf9ac4ad4 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resource.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resource.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management.util;
import java.io.BufferedInputStream;
@@ -30,7 +33,7 @@ public class Resource implements IResource {
}
@Override
- public InputStream getContent() throws OseeCoreException {
+ public InputStream getContent() {
try {
return new BufferedInputStream(uri.toURL().openStream());
} catch (IOException ex) {
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/ResourceLocator.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/ResourceLocator.java
index 3c3da2cb210..a1c9e215f79 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/ResourceLocator.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/ResourceLocator.java
@@ -1,18 +1,20 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management.util;
import java.net.URI;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.resource.management.IResourceLocator;
/**
@@ -22,7 +24,7 @@ public class ResourceLocator implements IResourceLocator {
private final URI uri;
- public ResourceLocator(URI uri) throws OseeCoreException {
+ public ResourceLocator(URI uri) {
if (uri == null) {
throw new OseeArgumentException("URI was null.");
}
diff --git a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resources.java b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resources.java
index 70723c142c7..922bd7996a7 100644
--- a/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resources.java
+++ b/plugins/org.eclipse.osee.framework.resource.management/src/org/eclipse/osee/framework/resource/management/util/Resources.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
+/*********************************************************************
+ * Copyright (c) 2004, 2007 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
- *******************************************************************************/
+ **********************************************************************/
+
package org.eclipse.osee.framework.resource.management.util;
import java.io.ByteArrayOutputStream;
@@ -34,7 +37,7 @@ public class Resources {
return path;
}
- public static IResource compressResource(IResource resource) throws OseeCoreException {
+ public static IResource compressResource(IResource resource) {
InputStream inputStream = null;
byte[] buffer = new byte[0];
try {
@@ -48,7 +51,7 @@ public class Resources {
return createResourceFromBytes(buffer, resource.getLocation() + ".zip", true);
}
- public static IResource decompressResource(IResource resource) throws OseeCoreException {
+ public static IResource decompressResource(IResource resource) {
String path = resource.getLocation().toASCIIString();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String fileName = null;
@@ -72,7 +75,7 @@ public class Resources {
return createResourceFromBytes(outputStream.toByteArray(), path, false);
}
- public static IResource createResourceFromBytes(byte[] bytes, String path, boolean isCompressed) throws OseeCoreException {
+ public static IResource createResourceFromBytes(byte[] bytes, String path, boolean isCompressed) {
try {
return new CompressedResourceBridge(bytes, new URI(path), isCompressed);
} catch (URISyntaxException ex) {

Back to the top