Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2009-01-14 23:38:11 +0000
committerafinkbein2009-01-14 23:38:11 +0000
commit5b96ae001227fc454f23b75b33e4f11695d2cf06 (patch)
tree1b67cefcfef563f91c26b8c484bce18d8c7857ec
parent0df8100b2fe014add005bd49f40d1dca22bb9dab (diff)
downloadorg.eclipse.osee-5b96ae001227fc454f23b75b33e4f11695d2cf06.tar.gz
org.eclipse.osee-5b96ae001227fc454f23b75b33e4f11695d2cf06.tar.xz
org.eclipse.osee-5b96ae001227fc454f23b75b33e4f11695d2cf06.zip
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.classpath7
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.project28
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.settings/org.eclipse.pde.core.prefs4
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/META-INF/MANIFEST.MF22
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/build.properties4
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/Activator.java78
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactFileServlet.java113
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactUtil.java40
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/HttpArtifactFileInfo.java53
9 files changed, 349 insertions, 0 deletions
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.classpath b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.classpath
new file mode 100644
index 00000000000..8a8f1668cdc
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.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/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.project b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.project
new file mode 100644
index 00000000000..30506228435
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.framework.artifact.servlet</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/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.settings/org.eclipse.pde.core.prefs b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 00000000000..a3a92c1e104
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Tue May 20 10:41:08 MST 2008
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/META-INF/MANIFEST.MF b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..9a2cdaed380
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Artifact Servlet Plug-in (Incubation)
+Bundle-SymbolicName: org.eclipse.osee.framework.artifact.servlet;singleton:=true
+Bundle-Version: 0.4.0.qualifier
+Bundle-Activator: org.eclipse.osee.framework.artifact.servlet.Activator
+Bundle-Vendor: Eclipse.org
+Bundle-ActivationPolicy: lazy
+Import-Package: javax.servlet;version="2.4.0",
+ javax.servlet.http;version="2.4.0",
+ org.eclipse.osee.framework.core.data,
+ org.eclipse.osee.framework.core.server,
+ org.eclipse.osee.framework.db.connection,
+ org.eclipse.osee.framework.db.connection.exception,
+ org.eclipse.osee.framework.db.connection.info,
+ org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.framework.logging,
+ org.eclipse.osee.framework.resource.management,
+ org.osgi.framework;version="1.3.0",
+ org.osgi.service.http;version="1.2.0",
+ org.osgi.util.tracker;version="1.3.3"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/build.properties b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/build.properties
new file mode 100644
index 00000000000..41eb6ade2b4
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/Activator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/Activator.java
new file mode 100644
index 00000000000..666c6746c05
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/Activator.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.artifact.servlet;
+
+import org.eclipse.osee.framework.core.data.OseeServerContext;
+import org.eclipse.osee.framework.core.server.OseeHttpServiceTracker;
+import org.eclipse.osee.framework.resource.management.IResourceLocatorManager;
+import org.eclipse.osee.framework.resource.management.IResourceManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class Activator implements BundleActivator {
+
+ private static Activator instance;
+
+ private OseeHttpServiceTracker httpTracker;
+ private ServiceTracker resourceManagementTracker;
+ private ServiceTracker resourceLocatorManagerTracker;
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ instance = this;
+
+ resourceLocatorManagerTracker = new ServiceTracker(context, IResourceLocatorManager.class.getName(), null);
+ resourceLocatorManagerTracker.open();
+
+ resourceManagementTracker = new ServiceTracker(context, IResourceManager.class.getName(), null);
+ resourceManagementTracker.open();
+
+ httpTracker =
+ new OseeHttpServiceTracker(context, OseeServerContext.PROCESS_CONTEXT, ArtifactFileServlet.class);
+ httpTracker.open();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ httpTracker.close();
+ httpTracker = null;
+
+ resourceManagementTracker.close();
+ resourceManagementTracker = null;
+
+ resourceLocatorManagerTracker.close();
+ resourceLocatorManagerTracker = null;
+
+ instance = null;
+ }
+
+ public static Activator getInstance() {
+ return instance;
+ }
+
+ public IResourceManager getResourceManager() {
+ return (IResourceManager) resourceManagementTracker.getService();
+ }
+
+ public IResourceLocatorManager getResourceLocatorManager() {
+ return (IResourceLocatorManager) resourceLocatorManagerTracker.getService();
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactFileServlet.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactFileServlet.java
new file mode 100644
index 00000000000..0de877eeab2
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactFileServlet.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 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.artifact.servlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.logging.Level;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.osee.framework.core.server.OseeHttpServlet;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
+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.StandardOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ArtifactFileServlet extends OseeHttpServlet {
+
+ private static final long serialVersionUID = -6334080268467740905L;
+
+ /* (non-Javadoc)
+ * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ InputStream inputStream = null;
+ boolean wasProcessed = false;
+ try {
+ HttpArtifactFileInfo artifactFileInfo = new HttpArtifactFileInfo(request);
+ String uri = null;
+ if (artifactFileInfo.isBranchNameValid()) {
+ uri = ArtifactUtil.getUri(artifactFileInfo.getGuid(), artifactFileInfo.getBranchName());
+ } else {
+ uri = ArtifactUtil.getUri(artifactFileInfo.getGuid(), artifactFileInfo.getBranchId());
+ }
+ if (Strings.isValid(uri)) {
+ IResourceLocator locator = Activator.getInstance().getResourceLocatorManager().getResourceLocator(uri);
+ Options options = new Options();
+ options.put(StandardOptions.DecompressOnAquire.name(), true);
+ IResource resource = Activator.getInstance().getResourceManager().acquire(locator, options);
+
+ if (resource != null) {
+ wasProcessed = true;
+ inputStream = resource.getContent();
+
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentLength(inputStream.available());
+ response.setCharacterEncoding("ISO-8859-1");
+ String mimeType = HttpURLConnection.guessContentTypeFromStream(inputStream);
+ if (mimeType == null) {
+ mimeType = HttpURLConnection.guessContentTypeFromName(resource.getLocation().toString());
+ if (mimeType == null) {
+ mimeType = "application/*";
+ }
+ }
+ response.setContentType(mimeType);
+ response.setHeader("Content-Disposition", "attachment; filename=" + resource.getName());
+
+ Lib.inputStreamToOutputStream(inputStream, response.getOutputStream());
+ }
+ }
+
+ if (!wasProcessed) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ response.setContentType("text/plain");
+ response.getWriter().write(String.format("Unable to find resource: [%s]", request.getQueryString()));
+ }
+ } catch (NumberFormatException ex) {
+ handleError(response, HttpServletResponse.SC_BAD_REQUEST, String.format("Invalid Branch Id: [%s]",
+ request.getQueryString()), ex);
+ } catch (Exception ex) {
+ handleError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, String.format(
+ "Unable to acquire resource: [%s]", request.getQueryString()), ex);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ response.flushBuffer();
+ }
+ }
+
+ private void handleError(HttpServletResponse response, int status, String message, Throwable ex) throws IOException {
+ response.setStatus(status);
+ response.setContentType("text/plain");
+ OseeLog.log(Activator.class, Level.SEVERE, message, ex);
+ response.getWriter().write(Lib.exceptionToString(ex));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.core.server.internal.InternalOseeHttpServlet#checkAccessControl()
+ */
+ @Override
+ protected void checkAccessControl(HttpServletRequest request) throws OseeCoreException {
+ // Open to all
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactUtil.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactUtil.java
new file mode 100644
index 00000000000..e8e2543d808
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/ArtifactUtil.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.artifact.servlet;
+
+import org.eclipse.osee.framework.db.connection.ConnectionHandler;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ArtifactUtil {
+
+ private static final int DEFAULT_ATTRIBUTE_DATA_PROVIDER = 1;
+
+ private static String URI_BY_GUID_AND_BRANCH_ID =
+ "SELECT uri FROM osee_tx_details txd1, osee_txs txs1, osee_artifact art1, osee_attribute attr1, osee_attribute_type attyp1 WHERE art1.guid =? AND attyp1.attr_provider_type_id <> ? AND attyp1.attr_type_id = attr1.attr_type_id AND txd1.branch_id = ? AND txs1.gamma_id = attr1.gamma_id AND attr1.art_id = art1.art_id AND txs1.transaction_id = txd1.transaction_id AND txs1.tx_current = 1";
+
+ private static String URI_BY_GUID_AND_BRANCH_NAME =
+ "SELECT uri FROM osee_tx_details txd1, osee_txs txs1, osee_artifact art1, osee_attribute attr1, osee_attribute_type attyp1, osee_branch branch1 WHERE art1.guid = ? AND attyp1.attr_provider_type_id <> ? AND attyp1.attr_type_id = attr1.attr_type_id AND txs1.gamma_id = attr1.gamma_id AND attr1.art_id = art1.art_id AND txs1.transaction_id = txd1.transaction_id AND txs1.tx_current = 1 AND txd1.branch_id = branch1.branch_id AND branch1.branch_name = ?";
+
+ public static String getUri(String guid, int branchId) throws OseeDataStoreException {
+ return getUri(URI_BY_GUID_AND_BRANCH_ID, guid, DEFAULT_ATTRIBUTE_DATA_PROVIDER, branchId);
+ }
+
+ public static String getUri(String guid, String branchName) throws OseeDataStoreException {
+ return getUri(URI_BY_GUID_AND_BRANCH_NAME, guid, DEFAULT_ATTRIBUTE_DATA_PROVIDER, branchName);
+ }
+
+ private static String getUri(String query, Object... dataBindings) throws OseeDataStoreException {
+ return ConnectionHandler.runPreparedQueryFetchString((String)null, query, dataBindings);
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/HttpArtifactFileInfo.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/HttpArtifactFileInfo.java
new file mode 100644
index 00000000000..d183cd7b81c
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.artifact.servlet/src/org/eclipse/osee/framework/artifact/servlet/HttpArtifactFileInfo.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.artifact.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class HttpArtifactFileInfo {
+ private static final int INVALID_BRANCH_ID = -1;
+ private static final String GUID_KEY = "guid";
+ private static final String BRANCH_NAME_KEY = "branch";
+ private static final String BRANCH_ID_KEY = "branchId";
+
+ private String guid;
+ private String branchName;
+ private String branchId;
+
+ public HttpArtifactFileInfo(HttpServletRequest request) {
+ this.guid = request.getParameter(GUID_KEY);
+ this.branchName = request.getParameter(BRANCH_NAME_KEY);
+ this.branchId = request.getParameter(BRANCH_ID_KEY);
+ }
+
+ public String getGuid() {
+ return guid;
+ }
+
+ public boolean isBranchNameValid() {
+ return branchName != null && branchName.length() > 0;
+ }
+
+ public String getBranchName() {
+ return branchName;
+ }
+
+ public int getBranchId() throws NumberFormatException {
+ int toReturn = INVALID_BRANCH_ID;
+ if (branchId != null && branchId.length() > 0) {
+ toReturn = Integer.parseInt(branchId);
+ }
+ return toReturn;
+ }
+} \ No newline at end of file

Back to the top