001/*
002 * (C) Copyright 2006-2011 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu, jcarsique
016 */
017package org.nuxeo.ecm.webengine.admin;
018
019import java.io.File;
020import java.net.URISyntaxException;
021import java.net.URL;
022
023import javax.ws.rs.GET;
024import javax.ws.rs.Path;
025import javax.ws.rs.Produces;
026
027import org.apache.commons.logging.Log;
028import org.apache.commons.logging.LogFactory;
029import org.nuxeo.common.Environment;
030import org.nuxeo.ecm.webengine.model.WebObject;
031import org.nuxeo.ecm.webengine.model.impl.ModuleRoot;
032
033/**
034 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
035 */
036@Path("/shell")
037@WebObject(type = "Shell")
038public class Shell extends ModuleRoot {
039    private static final Log log = LogFactory.getLog(Shell.class);
040
041    @GET
042    @Produces("text/html;charset=UTF-8")
043    public Object getShell() {
044        return getView("shell");
045    }
046
047    @GET
048    @Path("shell.jnlp")
049    @Produces("application/x-java-jnlp-file")
050    public Object getShellJnlp() {
051        return getView("shell.jnlp");
052    }
053
054    @GET
055    @Path("applet.jnlp")
056    @Produces("application/x-java-jnlp-file")
057    public Object getAppletJnlp() {
058        return getView("applet.jnlp");
059    }
060
061    @GET
062    @Path("shell.jar")
063    @Produces("application/java-archive")
064    public Object getShellJar() throws URISyntaxException {
065        File file = null;
066        try {
067            URL url = Class.forName("org.nuxeo.shell.Shell").getProtectionDomain().getCodeSource().getLocation();
068            return new File(url.toURI());
069        } catch (ClassNotFoundException e) {
070            log.debug(e);
071            file = new File(Environment.getDefault().getServerHome(), "client");
072            if (file.isDirectory()) {
073                for (File f : file.listFiles()) {
074                    String name = f.getName();
075                    if (name.endsWith(".jar") && name.contains("shell")) {
076                        return f;
077                    }
078                }
079            }
080        }
081        return redirect("http://www.nuxeo.org/static/latest-release/nuxeo-shell");
082    }
083
084}