From: Bruno Sinou Date: Wed, 7 May 2014 12:24:24 +0000 (+0000) Subject: work on file downloads X-Git-Tag: argeo-slc-2.1.7~195 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=70eec596149a6344d93bdc90877787cbd19ab626;p=gpl%2Fargeo-slc.git work on file downloads git-svn-id: https://svn.argeo.org/slc/trunk@6966 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/demo/slc_demo_rap.properties b/demo/slc_demo_rap.properties index 8f87c1f65..14dd76306 100644 --- a/demo/slc_demo_rap.properties +++ b/demo/slc_demo_rap.properties @@ -31,7 +31,8 @@ slc.executionModules=org.argeo.slc.demo.ant,\ org.argeo.slc.demo.basic,\ org.argeo.slc.demo.minimal,\ -org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.anonymousDistributionPerspective +#org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.anonymousDistributionPerspective +org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.distributionPerspective #org.argeo.security.ui.initialPerspective=org.argeo.security.ui.userHomePerspective #org.argeo.security.ui.saveAndRestore=true @@ -39,10 +40,10 @@ org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.anonymousD argeo.server.tomcat.config=conf/default-server-ssl.xml # override ports to run the demo as a server -#argeo.server.port.http=9070 -#argeo.server.port.https=9073 -#argeo.server.port.ajp=9079 -#argeo.ldap.port=19389 +argeo.server.port.http=9070 +argeo.server.port.https=9073 +argeo.server.port.ajp=9079 +argeo.ldap.port=19389 # anonymous url: http://localhost:7070/ui/public # authenticated url: http://localhost:7070/ui/node diff --git a/modules/org.argeo.slc.server.repo/META-INF/spring/jcr.xml b/modules/org.argeo.slc.server.repo/META-INF/spring/jcr.xml index e6ed3f895..0d4836168 100644 --- a/modules/org.argeo.slc.server.repo/META-INF/spring/jcr.xml +++ b/modules/org.argeo.slc.server.repo/META-INF/spring/jcr.xml @@ -61,5 +61,4 @@ - \ No newline at end of file diff --git a/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml b/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml index a4b2c26e0..38dbfe648 100644 --- a/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml +++ b/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml @@ -58,4 +58,11 @@ + + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rap/META-INF/spring/commands.xml b/plugins/org.argeo.slc.client.rap/META-INF/spring/commands.xml new file mode 100644 index 000000000..78adfc6cd --- /dev/null +++ b/plugins/org.argeo.slc.client.rap/META-INF/spring/commands.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rap/META-INF/spring/jcr.xml b/plugins/org.argeo.slc.client.rap/META-INF/spring/jcr.xml new file mode 100644 index 000000000..4a35de60d --- /dev/null +++ b/plugins/org.argeo.slc.client.rap/META-INF/spring/jcr.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/plugins/org.argeo.slc.client.rap/META-INF/spring/osgi.xml b/plugins/org.argeo.slc.client.rap/META-INF/spring/osgi.xml new file mode 100644 index 000000000..bb3095bfa --- /dev/null +++ b/plugins/org.argeo.slc.client.rap/META-INF/spring/osgi.xml @@ -0,0 +1,19 @@ + + + + SLC UI RAP + + + + + + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rap/plugin.xml b/plugins/org.argeo.slc.client.rap/plugin.xml index e51a32853..6e71fa27e 100644 --- a/plugins/org.argeo.slc.client.rap/plugin.xml +++ b/plugins/org.argeo.slc.client.rap/plugin.xml @@ -1,14 +1,38 @@ - + - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.argeo.slc.client.rap/pom.xml b/plugins/org.argeo.slc.client.rap/pom.xml index c53288237..6f88645e2 100644 --- a/plugins/org.argeo.slc.client.rap/pom.xml +++ b/plugins/org.argeo.slc.client.rap/pom.xml @@ -16,11 +16,15 @@ maven-bundle-plugin + org.argeo.slc.client.rap.SlcRapPlugin org.eclipse.rap.ui;resolution:=optional - *, + javax.jcr.nodetype, javax.servlet, - javax.servlet.http + javax.servlet.http, + org.argeo.eclipse.spring, + org.argeo.slc.repo.core, + * @@ -28,11 +32,10 @@ - org.argeo.slc - org.argeo.slc.client.ui + org.argeo.slc.repo 1.1.17-SNAPSHOT diff --git a/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/rap/OpenJcrFileService.java b/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/rap/OpenJcrFileService.java new file mode 100644 index 000000000..d64a10bb7 --- /dev/null +++ b/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/rap/OpenJcrFileService.java @@ -0,0 +1,135 @@ +package org.argeo.slc.client.rap; + +import java.io.IOException; +import java.io.InputStream; + +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.nodetype.NodeType; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.repo.RepoService; +import org.eclipse.rwt.RWT; +import org.eclipse.rwt.service.IServiceHandler; +import org.eclipse.rwt.service.IServiceManager; + +/** + * Basic Default service handler that retrieves and launch download of a file + * stored in a JCR Repository + */ +public class OpenJcrFileService implements IServiceHandler { + + public final static String ID = SlcRapPlugin.PLUGIN_ID + ".openJcrFileService"; + + // use local node repo and repository factory to retrieve and log to + // relevant repository + public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath"; + // use URI and repository factory to retrieve and ANONYMOUSLY log in + // relevant repository + public final static String PARAM_REPO_URI = "param.repoUri"; + public final static String PARAM_WORKSPACE_NAME = "param.workspaceName"; + public final static String PARAM_FILE_PATH = "param.filePath"; + + public final static String SCHEME_HOST_SEPARATOR = "://"; + + /* DEPENDENCY INJECTION */ + private RepoService repoService; + + public OpenJcrFileService() { + } + + public void init() { + IServiceManager manager = RWT.getServiceManager(); + manager.registerServiceHandler(ID, this); + } + + public void destroy() { + IServiceManager manager = RWT.getServiceManager(); + manager.unregisterServiceHandler(ID); + } + + public void service() throws IOException, ServletException { + String repoNodePath = RWT.getRequest().getParameter(PARAM_REPO_NODE_PATH); + String repoUri = RWT.getRequest().getParameter(PARAM_REPO_URI); + String wkspName = RWT.getRequest().getParameter(PARAM_WORKSPACE_NAME); + String filePath = RWT.getRequest().getParameter(PARAM_FILE_PATH); + + // Get the file content + byte[] download = getFileAsByteArray(repoNodePath, repoUri, wkspName, + filePath); + + // Send the file in the response + HttpServletResponse response = RWT.getResponse(); + response.setContentType("application/octet-stream"); + response.setContentLength(download.length); + String contentDisposition = "attachment; filename=\"" + + JcrUtils.lastPathElement(filePath) + "\""; + response.setHeader("Content-Disposition", contentDisposition); + + try { + response.getOutputStream().write(download); + } catch (IOException ioe) { + throw new SlcException("Error while writing the file " + filePath + + " to the servlet response", ioe); + } + } + + protected byte[] getFileAsByteArray(String repoNodePath, String repoUri, + String wkspName, String filePath) { + Session businessSession = null; + try { + businessSession = repoService.getRemoteSession(repoNodePath, + repoUri, wkspName); + Node result = businessSession.getNode(filePath); + + boolean isValid = true; + Node child = null; + if (!result.isNodeType(NodeType.NT_FILE)) + isValid = false; + else { + child = result.getNode(Property.JCR_CONTENT); + if (!(child.isNodeType(NodeType.NT_RESOURCE) || child + .hasProperty(Property.JCR_DATA))) + isValid = false; + } + + if (!isValid) + return null; + + byte[] ba = null; + InputStream fis = null; + try { + fis = (InputStream) child.getProperty(Property.JCR_DATA) + .getBinary().getStream(); + ba = IOUtils.toByteArray(fis); + } catch (Exception e) { + throw new SlcException( + "Stream error while opening file " + filePath + + " from repo " + repoUri == null ? repoNodePath + : repoUri, e); + } finally { + IOUtils.closeQuietly(fis); + } + return ba; + + } catch (RepositoryException e) { + throw new SlcException("Unexpected error while " + + "getting repoNode info for repoNode at path " + + repoNodePath, e); + } finally { + JcrUtils.logoutQuietly(businessSession); + } + } + + /* DEPENDENCY INJECTION */ + public void setRepoService(RepoService repoService) { + this.repoService = repoService; + } + +} \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/rap/SlcRapPlugin.java b/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/rap/SlcRapPlugin.java new file mode 100644 index 000000000..e23ea747b --- /dev/null +++ b/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/rap/SlcRapPlugin.java @@ -0,0 +1,71 @@ +package org.argeo.slc.client.rap; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + * + * Enable life-cycle management of RAP specific services + */ +public class SlcRapPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.argeo.slc.client.rap"; //$NON-NLS-1$ + + // The shared instance + private static SlcRapPlugin plugin; + + /** + * The constructor + */ + public SlcRapPlugin() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static SlcRapPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given plug-in + * relative path + * + * @param path + * the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + +} \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/ui/specific/OpenJcrFile.java b/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/ui/specific/OpenJcrFile.java new file mode 100644 index 000000000..21ed8eb08 --- /dev/null +++ b/plugins/org.argeo.slc.client.rap/src/main/java/org/argeo/slc/client/ui/specific/OpenJcrFile.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.slc.client.ui.specific; + +import java.net.URL; + +import javax.jcr.Session; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.client.rap.OpenJcrFileService; +import org.argeo.slc.client.rap.SlcRapPlugin; +import org.argeo.slc.repo.RepoService; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.rwt.RWT; +import org.eclipse.rwt.service.IServiceHandler; +import org.eclipse.ui.PlatformUI; + +/** + * Rap specific command handler to open a file retrieved from a distant JCR + * Repository. It forwards the request to the correct service after encoding + * file name and path in the request URI. + * + * This command and the corresponding service are specific for RAP version [1.3, + * 2) + */ +public class OpenJcrFile extends AbstractHandler { + private final static Log log = LogFactory.getLog(OpenJcrFile.class); + + public final static String ID = SlcRapPlugin.PLUGIN_ID + ".openJcrFile"; + + public final static String PARAM_REPO_NODE_PATH = OpenJcrFileService.PARAM_REPO_NODE_PATH; + public final static String PARAM_REPO_URI = OpenJcrFileService.PARAM_REPO_URI; + public final static String PARAM_WORKSPACE_NAME = OpenJcrFileService.PARAM_WORKSPACE_NAME; + public final static String PARAM_FILE_PATH = OpenJcrFileService.PARAM_FILE_PATH; + + private RepoService repoService; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH); + String repoUri = event.getParameter(PARAM_REPO_URI); + String wkspName = event.getParameter(PARAM_WORKSPACE_NAME); + String filePath = event.getParameter(PARAM_FILE_PATH); + + // TODO remove + Session session = repoService.getRemoteSession(repoNodePath, repoUri, + wkspName); + JcrUtils.logoutQuietly(session); + + // TODO sanity check + if (filePath == null || "".equals(filePath.trim())) + return null; + + try { + if (log.isDebugEnabled()) + log.debug("URL : " + + createFullDownloadUrl(repoNodePath, repoUri, + wkspName, filePath)); + // RWT.getResponse().sendRedirect(createFullDownloadUrl(repoNodePath, + // repoUri, + // wkspName, filePath)); + + URL url = new URL(createFullDownloadUrl(repoNodePath, repoUri, + wkspName, filePath)); + PlatformUI.getWorkbench().getBrowserSupport() + .createBrowser("DownloadDialog").openURL(url); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + private String createFullDownloadUrl(String repoNodePath, String repoUri, + String wkspName, String filePath) { + StringBuilder url = new StringBuilder(); + url.append(RWT.getRequest().getRequestURL()); + + StringBuilder params = new StringBuilder(); + params.append("?"); + params.append(IServiceHandler.REQUEST_PARAM).append("="); + params.append(OpenJcrFileService.ID); + if (repoNodePath != null) + params.append("&").append(OpenJcrFileService.PARAM_REPO_NODE_PATH) + .append("=").append(repoNodePath); + + if (repoUri != null) + params.append("&").append(OpenJcrFileService.PARAM_REPO_URI) + .append("=").append(repoUri); + + if (wkspName != null) + params.append("&").append(OpenJcrFileService.PARAM_WORKSPACE_NAME) + .append("=").append(wkspName); + + if (filePath != null) + params.append("&").append(OpenJcrFileService.PARAM_FILE_PATH) + .append("=").append(filePath); + + String encodedURL = RWT.getResponse().encodeURL(params.toString()); + url.append(encodedURL); + + return url.toString(); + } + + /* Dependency Injection */ + // only used as a workaround to force the service instantiation + public void setOpenJcrFileService(OpenJcrFileService openJcrFileService) { + // do nothing. + } + + public void setRepoService(RepoService repoService) { + this.repoService = repoService; + } + +} \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rcp/META-INF/spring/commands.xml b/plugins/org.argeo.slc.client.rcp/META-INF/spring/commands.xml new file mode 100644 index 000000000..7bd302c86 --- /dev/null +++ b/plugins/org.argeo.slc.client.rcp/META-INF/spring/commands.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml b/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml new file mode 100644 index 000000000..55a940f7f --- /dev/null +++ b/plugins/org.argeo.slc.client.rcp/META-INF/spring/osgi.xml @@ -0,0 +1,18 @@ + + + + SLC UI RCP + + + + + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.rcp/plugin.xml b/plugins/org.argeo.slc.client.rcp/plugin.xml index 3cc0f922a..9c4523a48 100644 --- a/plugins/org.argeo.slc.client.rcp/plugin.xml +++ b/plugins/org.argeo.slc.client.rcp/plugin.xml @@ -30,6 +30,32 @@ + + + + + + + + + + + + + + + 4.0.0 org.argeo.slc @@ -16,12 +17,15 @@ maven-bundle-plugin - org.argeo.slc.client.rcp.ClientRcpPlugin + org.argeo.slc.client.rcp.SlcRcpPlugin org.eclipse.ui, org.eclipse.core.runtime + org.argeo.eclipse.spring, + org.argeo.slc.repo.core, + javax.jcr.nodetype, *, @@ -33,7 +37,7 @@ org.argeo.slc - org.argeo.slc.client.ui + org.argeo.slc.repo 1.1.17-SNAPSHOT diff --git a/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ClientRcpPlugin.java b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ClientRcpPlugin.java deleted file mode 100644 index 615c1879d..000000000 --- a/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ClientRcpPlugin.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.slc.client.rcp; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class ClientRcpPlugin extends AbstractUIPlugin { - public static final String PLUGIN_ID = "org.argeo.slc.client.rcp"; - private static ClientRcpPlugin plugin; - - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - public static ClientRcpPlugin getDefault() { - return plugin; - } - - @Override - protected void initializeImageRegistry(ImageRegistry reg) { - // TODO make it configurable - reg.put("argeoTrayIcon", - getImageDescriptor("icons/argeo-trayIcon-256.png")); - } - - public static ImageDescriptor getImageDescriptor(String path) { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } -} diff --git a/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcRcpPlugin.java b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcRcpPlugin.java new file mode 100644 index 000000000..816e7c020 --- /dev/null +++ b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcRcpPlugin.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.slc.client.rcp; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class SlcRcpPlugin extends AbstractUIPlugin { + public static final String PLUGIN_ID = "org.argeo.slc.client.rcp"; + private static SlcRcpPlugin plugin; + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public static SlcRcpPlugin getDefault() { + return plugin; + } + + @Override + protected void initializeImageRegistry(ImageRegistry reg) { + // TODO make it configurable + reg.put("argeoTrayIcon", + getImageDescriptor("icons/argeo-trayIcon-256.png")); + } + + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java index 1f8521617..7eecc9e94 100644 --- a/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java +++ b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java @@ -105,7 +105,7 @@ public class SlcSecureWorkbenchWindowAdvisor extends return; // image - Image trayImage = ClientRcpPlugin.getDefault().getImageRegistry() + Image trayImage = SlcRcpPlugin.getDefault().getImageRegistry() .get("argeoTrayIcon"); trayItem.setImage(trayImage); trayItem.setToolTipText("Argeo SLC"); diff --git a/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/ui/specific/OpenJcrFile.java b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/ui/specific/OpenJcrFile.java new file mode 100644 index 000000000..e2fc880dd --- /dev/null +++ b/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/ui/specific/OpenJcrFile.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.slc.client.ui.specific; + +import java.awt.Desktop; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.nodetype.NodeType; + +import org.apache.commons.io.IOUtils; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; +import org.argeo.slc.client.rcp.SlcRcpPlugin; +import org.argeo.slc.repo.RepoService; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +/** + * RCP specific command handler to open a file retrieved from a local or distant + * JCR Repository. + */ +public class OpenJcrFile extends AbstractHandler { + // private final static Log log = LogFactory.getLog(OpenJcrFile.class); + + // Here is the trick that enable single sourcing: the ID is determined at + // runtime. ALWAYS use this public variable to call the command. + public final static String ID = SlcRcpPlugin.PLUGIN_ID + ".openJcrFile"; + + public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath"; + public final static String PARAM_REPO_URI = "param.repoUri"; + public final static String PARAM_WORKSPACE_NAME = "param.workspaceName"; + public final static String PARAM_FILE_PATH = "param.filePath"; + + /* DEPENDENCY INJECTION */ + private RepoService repoService; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH); + String repoUri = event.getParameter(PARAM_REPO_URI); + String wkspName = event.getParameter(PARAM_WORKSPACE_NAME); + String filePath = event.getParameter(PARAM_FILE_PATH); + + // TODO sanity check + if (filePath == null || "".equals(filePath.trim())) + return null; + retrieveAndOpen(repoNodePath, repoUri, wkspName, filePath); + + return null; + } + + protected void retrieveAndOpen(String repoNodePath, String repoUri, + String wkspName, String filePath) { + Session businessSession = null; + try { + businessSession = repoService.getRemoteSession(repoNodePath, + repoUri, wkspName); + Node result = businessSession.getNode(filePath); + + boolean isValid = true; + Node child = null; + if (!result.isNodeType(NodeType.NT_FILE)) + isValid = false; + else { + child = result.getNode(Property.JCR_CONTENT); + if (!(child.isNodeType(NodeType.NT_RESOURCE) || child + .hasProperty(Property.JCR_DATA))) + isValid = false; + } + + if (!isValid) + return; + + InputStream fis = null; + String prefix = "", extension = ""; + String fileName = JcrUtils.lastPathElement(filePath); + int ind = fileName.lastIndexOf('.'); + if (ind > 0) { + prefix = fileName.substring(0, ind); + extension = fileName.substring(ind); + } + try { + + fis = (InputStream) child.getProperty(Property.JCR_DATA) + .getBinary().getStream(); + File file = createTmpFile(prefix, extension, fis); + Desktop desktop = null; + if (Desktop.isDesktopSupported()) { + desktop = Desktop.getDesktop(); + } + desktop.open(file); + } catch (Exception e) { + throw new SlcException( + "Stream error while opening file " + filePath + + " from repo " + repoUri == null ? repoNodePath + : repoUri, e); + } finally { + IOUtils.closeQuietly(fis); + } + } catch (RepositoryException e) { + throw new SlcException("Unexpected error while " + + "getting repoNode info for repoNode at path " + + repoNodePath, e); + } finally { + JcrUtils.logoutQuietly(businessSession); + } + } + + private File createTmpFile(String prefix, String suffix, InputStream is) { + File tmpFile = null; + OutputStream os = null; + try { + tmpFile = File.createTempFile(prefix, suffix); + os = new FileOutputStream(tmpFile); + IOUtils.copy(is, os); + } catch (IOException e) { + throw new SlcException("Cannot open file " + prefix + "." + suffix, + e); + } finally { + IOUtils.closeQuietly(os); + } + return tmpFile; + } + + /* DEPENDENCY INJECTION */ + public void setRepoService(RepoService repoService) { + this.repoService = repoService; + } +} \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml index e6b5e60dd..b5413793e 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml @@ -10,7 +10,7 @@ - + diff --git a/plugins/org.argeo.slc.client.ui.dist/pom.xml b/plugins/org.argeo.slc.client.ui.dist/pom.xml index 824d3bcf8..89fc41596 100644 --- a/plugins/org.argeo.slc.client.ui.dist/pom.xml +++ b/plugins/org.argeo.slc.client.ui.dist/pom.xml @@ -29,6 +29,7 @@ javax.jcr.nodetype, javax.jcr.security, aQute.lib.*;resolution:=optional, + org.argeo.slc.client.ui.specific, * @@ -37,12 +38,15 @@ + + - org.argeo.commons.base - org.argeo.util - ${version.argeo-commons} + org.argeo.slc + org.argeo.slc.client.rcp + 1.1.17-SNAPSHOT + provided - + org.argeo.commons.base @@ -61,7 +65,6 @@ provided - org.argeo.slc @@ -83,5 +86,13 @@ org.argeo.tp biz.aQute.bndlib + + + + org.argeo.commons.base + org.argeo.util + ${version.argeo-commons} + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoService.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoService.java deleted file mode 100644 index 8e4a09ed8..000000000 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoService.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.argeo.slc.client.ui.dist; - -import javax.jcr.Session; - -/** Start factorisation of the session management using a manager service */ -public interface RepoService { - - /** - * Returns a corresponding session given the current context. Caller must - * close the session once it as been used - */ - public Session getRemoteSession(String repoNodePath, String uri, - String workspaceName); -} diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoServiceImpl.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoServiceImpl.java deleted file mode 100644 index be012f28d..000000000 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.argeo.slc.client.ui.dist; - -import javax.jcr.Repository; -import javax.jcr.RepositoryFactory; -import javax.jcr.Session; - -import org.argeo.slc.repo.RepoUtils; -import org.argeo.util.security.Keyring; - -public class RepoServiceImpl implements RepoService { - - /* DEPENDENCY INJECTION */ - private Repository nodeRepository; - private RepositoryFactory repositoryFactory; - private Keyring keyring; - - public Session getRemoteSession(String repoNodePath, String uri, - String workspaceName) { - return RepoUtils.getRemoteSession(repositoryFactory, keyring, - nodeRepository, repoNodePath, uri, workspaceName); - } - - /* DEPENDENCY INJECTION */ - public void setNodeRepository(Repository nodeRepository) { - this.nodeRepository = nodeRepository; - } - - public void setRepositoryFactory(RepositoryFactory repositoryFactory) { - this.repositoryFactory = repositoryFactory; - } - - public void setKeyring(Keyring keyring) { - this.keyring = keyring; - } - -} diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java index 3325092de..7cf3d1a1a 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java @@ -20,8 +20,8 @@ import javax.jcr.Session; import org.argeo.jcr.JcrUtils; import org.argeo.slc.client.ui.dist.DistPlugin; -import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.model.RepoElem; +import org.argeo.slc.repo.RepoService; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java index 84ee759d7..3acbc77d9 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java @@ -16,9 +16,9 @@ package org.argeo.slc.client.ui.dist.commands; import org.argeo.slc.client.ui.dist.DistPlugin; -import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.utils.CommandHelpers; import org.argeo.slc.client.ui.dist.wizards.GenerateBinariesWizard; +import org.argeo.slc.repo.RepoService; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java index 9250b25e6..95a9aa4b7 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java @@ -22,11 +22,11 @@ import javax.jcr.Session; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; -import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.editors.ArtifactVersionEditor; import org.argeo.slc.client.ui.dist.editors.ModularDistVersionEditor; import org.argeo.slc.client.ui.dist.editors.ModuleEditorInput; import org.argeo.slc.jcr.SlcTypes; +import org.argeo.slc.repo.RepoService; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java index 9c01be72c..fc2509270 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java @@ -23,8 +23,8 @@ import org.argeo.ArgeoException; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; -import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.jcr.SlcNames; +import org.argeo.slc.repo.RepoService; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/BundleDetailPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/BundleDetailPage.java index 43f3dda9c..b63d91c61 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/BundleDetailPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/BundleDetailPage.java @@ -16,14 +16,18 @@ package org.argeo.slc.client.ui.dist.editors; import java.net.URL; +import java.util.HashMap; +import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.utils.CommandUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistConstants; import org.argeo.slc.client.ui.dist.utils.AbstractHyperlinkListener; +import org.argeo.slc.client.ui.specific.OpenJcrFile; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.repo.RepoUtils; @@ -128,7 +132,7 @@ public class BundleDetailPage extends FormPage implements SlcNames { .getString() : "N/A"); createHyperlink(parent, "Licence", DistConstants.SLC_BUNDLE_LICENCE); - addSourceSourcesLink(parent); + addSourceLink(parent); } catch (RepositoryException re) { throw new SlcException("Unable to get bundle name for node " + bundle, re); @@ -196,14 +200,14 @@ public class BundleDetailPage extends FormPage implements SlcNames { } // helper to check if sources are available - private void addSourceSourcesLink(Composite parent) { + private void addSourceLink(Composite parent) { try { String srcPath = RepoUtils.relatedPdeSourcePath( RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH, bundle); if (!bundle.getSession().nodeExists(srcPath)) { createLT(parent, "Sources", "N/A"); } else { - Node sourcesNode = bundle.getSession().getNode(srcPath); + final Node sourcesNode = bundle.getSession().getNode(srcPath); String srcName = null; if (sourcesNode.hasProperty(SlcNames.SLC_SYMBOLIC_NAME)) @@ -220,7 +224,17 @@ public class BundleDetailPage extends FormPage implements SlcNames { @Override public void linkActivated(HyperlinkEvent e) { try { - System.out.println("CLICK on Sources link"); + ModuleEditorInput editorInput = (ModuleEditorInput) getEditorInput(); + Map params = new HashMap(); + params.put(OpenJcrFile.PARAM_REPO_NODE_PATH, + editorInput.getRepoNodePath()); + params.put(OpenJcrFile.PARAM_REPO_URI, + editorInput.getUri()); + params.put(OpenJcrFile.PARAM_WORKSPACE_NAME, + editorInput.getWorkspaceName()); + params.put(OpenJcrFile.PARAM_FILE_PATH, + sourcesNode.getPath()); + CommandUtils.callCommand(OpenJcrFile.ID, params); } catch (Exception ex) { throw new SlcException("error opening browser", ex); //$NON-NLS-1$ } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java index a76d38d14..4b7e9767f 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java @@ -31,10 +31,10 @@ import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.client.ui.dist.PrivilegedJob; -import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.utils.ViewerUtils; import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.RepoConstants; +import org.argeo.slc.repo.RepoService; import org.argeo.slc.repo.RepoUtils; import org.argeo.slc.repo.maven.GenerateBinaries; import org.eclipse.core.runtime.IProgressMonitor; diff --git a/plugins/org.argeo.slc.client.ui/pom.xml b/plugins/org.argeo.slc.client.ui/pom.xml index 36ca64326..f570c1e05 100644 --- a/plugins/org.argeo.slc.client.ui/pom.xml +++ b/plugins/org.argeo.slc.client.ui/pom.xml @@ -34,6 +34,14 @@ + + + org.argeo.slc + org.argeo.slc.client.rcp + 1.1.17-SNAPSHOT + provided + + org.argeo.slc diff --git a/plugins/pom.xml b/plugins/pom.xml index 60ac16a23..a09f1cb6d 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -10,10 +10,10 @@ SLC Eclipse Plugins pom - org.argeo.slc.client.ui - org.argeo.slc.client.ui.dist org.argeo.slc.client.rcp org.argeo.slc.client.rap + org.argeo.slc.client.ui + org.argeo.slc.client.ui.dist diff --git a/pom.xml b/pom.xml index 875b0cbc0..dc55a3163 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.argeo.commons @@ -9,6 +10,7 @@ argeo-slc pom Argeo SLC + SLC is a framework integrating various build, deployment and testing technologies in order to build specific application life cycle management systems. 1.1.17-SNAPSHOT 1.1 diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArtifactIndexer.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArtifactIndexer.java index f62142254..6de832b91 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArtifactIndexer.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArtifactIndexer.java @@ -16,6 +16,7 @@ package org.argeo.slc.repo; import javax.jcr.Node; +import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; import org.apache.commons.logging.Log; @@ -25,6 +26,7 @@ import org.argeo.slc.SlcException; import org.argeo.slc.aether.AetherUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; +import org.osgi.framework.Constants; import org.sonatype.aether.artifact.Artifact; /** @@ -32,7 +34,7 @@ import org.sonatype.aether.artifact.Artifact; * name doesn't start with the artifact id (in order to skip Maven metadata XML * files and other non artifact files). */ -public class ArtifactIndexer implements NodeIndexer { +public class ArtifactIndexer implements NodeIndexer, SlcNames { private Log log = LogFactory.getLog(ArtifactIndexer.class); private Boolean force = false; @@ -95,6 +97,26 @@ public class ArtifactIndexer implements NodeIndexer { md5.getBytes()); } + // Create a default pom only with artifact coordinates if none + // already exist + String fileNodeName = fileNode.getName(); + String pomName= null; + if (fileNodeName.endsWith(".jar")) + pomName = fileNodeName.substring(0, fileNodeName.length()-".jar".length()) + ".pom"; + + if (pomName != null && !fileNode.getParent().hasNode(pomName)) { + String pom = generatePomForBundle(fileNode); + Node pomNode = JcrUtils.copyBytesAsFile(fileNode.getParent(), + pomName, pom.getBytes()); + // corresponding check sums + String sha = JcrUtils.checksumFile(pomNode, "SHA-1"); + JcrUtils.copyBytesAsFile(fileNode.getParent(), pomName + ".sha1", + sha.getBytes()); + String md5 = JcrUtils.checksumFile(fileNode, "MD5"); + JcrUtils.copyBytesAsFile(fileNode.getParent(), pomName +".md5", + md5.getBytes()); + } + // set higher levels Node artifactVersionBase = fileNode.getParent(); if (!artifactVersionBase @@ -158,4 +180,32 @@ public class ArtifactIndexer implements NodeIndexer { this.force = force; } -} + private String generatePomForBundle(Node n) throws RepositoryException { + StringBuffer p = new StringBuffer(); + + // XML header + p.append("\n"); + p.append("\n"); + p.append("4.0.0"); + + // Artifact + p.append("").append(JcrUtils.get(n, SLC_GROUP_ID)) + .append("\n"); + p.append("").append(JcrUtils.get(n, SLC_ARTIFACT_ID)) + .append("\n"); + p.append("").append(JcrUtils.get(n, SLC_ARTIFACT_VERSION)) + .append("\n"); + p.append("pom\n"); + if (n.hasProperty(SLC_ + Constants.BUNDLE_NAME)) + p.append("") + .append(JcrUtils.get(n, SLC_ + Constants.BUNDLE_NAME)) + .append("\n"); + if (n.hasProperty(SLC_ + Constants.BUNDLE_DESCRIPTION)) + p.append("") + .append(JcrUtils + .get(n, SLC_ + Constants.BUNDLE_DESCRIPTION)) + .append("\n"); + p.append("\n"); + return p.toString(); + } +} \ No newline at end of file diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoService.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoService.java new file mode 100644 index 000000000..9b9bc66b3 --- /dev/null +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoService.java @@ -0,0 +1,14 @@ +package org.argeo.slc.repo; + +import javax.jcr.Session; + +/** Start factorisation of the session management using a manager service */ +public interface RepoService { + + /** + * Returns a corresponding session given the current context. Caller must + * close the session once it has been used + */ + public Session getRemoteSession(String repoNodePath, String uri, + String workspaceName); +} diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/core/RepoServiceImpl.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/core/RepoServiceImpl.java new file mode 100644 index 000000000..a20303ca5 --- /dev/null +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/core/RepoServiceImpl.java @@ -0,0 +1,62 @@ +package org.argeo.slc.repo.core; + +import javax.jcr.LoginException; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.RepositoryFactory; +import javax.jcr.Session; + +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.repo.RepoService; +import org.argeo.slc.repo.RepoUtils; +import org.argeo.util.security.Keyring; + +/** + * Work in Progress - enhance this. First implementation of a service that + * centralizes session management in an argeo SLC context, repositories are + * either defined using an URI and a workspace name in a anonymous context or + * using connection information that are store in a corresponding node in the + * local repository home + */ +public class RepoServiceImpl implements RepoService { + + /* DEPENDENCY INJECTION */ + private Repository nodeRepository; + private RepositoryFactory repositoryFactory; + private Keyring keyring; + + public Session getRemoteSession(String repoNodePath, String uri, + String workspaceName) { + + // TODO remove this. Only usefull while investigating the RAP login + // problem + Session session = null; + try { + session = nodeRepository.login(); + } catch (LoginException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RepositoryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + JcrUtils.logoutQuietly(session); + } + + return RepoUtils.getRemoteSession(repositoryFactory, keyring, + nodeRepository, repoNodePath, uri, workspaceName); + } + + /* DEPENDENCY INJECTION */ + public void setNodeRepository(Repository nodeRepository) { + this.nodeRepository = nodeRepository; + } + + public void setRepositoryFactory(RepositoryFactory repositoryFactory) { + this.repositoryFactory = repositoryFactory; + } + + public void setKeyring(Keyring keyring) { + this.keyring = keyring; + } +} \ No newline at end of file