001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu, jcarsique 018 */ 019package org.nuxeo.ecm.webengine.admin; 020 021import java.io.File; 022import java.net.URISyntaxException; 023import java.net.URL; 024 025import javax.ws.rs.GET; 026import javax.ws.rs.Path; 027import javax.ws.rs.Produces; 028 029import org.apache.commons.logging.Log; 030import org.apache.commons.logging.LogFactory; 031import org.nuxeo.common.Environment; 032import org.nuxeo.ecm.webengine.model.WebObject; 033import org.nuxeo.ecm.webengine.model.impl.ModuleRoot; 034 035/** 036 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 037 */ 038@Path("/shell") 039@WebObject(type = "Shell") 040public class Shell extends ModuleRoot { 041 private static final Log log = LogFactory.getLog(Shell.class); 042 043 @GET 044 @Produces("text/html;charset=UTF-8") 045 public Object getShell() { 046 return getView("shell"); 047 } 048 049 @GET 050 @Path("shell.jnlp") 051 @Produces("application/x-java-jnlp-file") 052 public Object getShellJnlp() { 053 return getView("shell.jnlp"); 054 } 055 056 @GET 057 @Path("applet.jnlp") 058 @Produces("application/x-java-jnlp-file") 059 public Object getAppletJnlp() { 060 return getView("applet.jnlp"); 061 } 062 063 @GET 064 @Path("shell.jar") 065 @Produces("application/java-archive") 066 public Object getShellJar() throws URISyntaxException { 067 File file = null; 068 try { 069 URL url = Class.forName("org.nuxeo.shell.Shell").getProtectionDomain().getCodeSource().getLocation(); 070 return new File(url.toURI()); 071 } catch (ClassNotFoundException e) { 072 log.debug(e); 073 file = new File(Environment.getDefault().getServerHome(), "client"); 074 if (file.isDirectory()) { 075 for (File f : file.listFiles()) { 076 String name = f.getName(); 077 if (name.endsWith(".jar") && name.contains("shell")) { 078 return f; 079 } 080 } 081 } 082 } 083 return redirect("http://www.nuxeo.org/static/latest-release/nuxeo-shell"); 084 } 085 086}