001/*
002 * (C) Copyright 2006-2009 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 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webengine.admin;
021
022import javax.ws.rs.GET;
023import javax.ws.rs.Path;
024import javax.ws.rs.Produces;
025import javax.ws.rs.WebApplicationException;
026import javax.ws.rs.core.Response;
027
028import org.nuxeo.ecm.core.rest.DocumentRoot;
029import org.nuxeo.ecm.webengine.model.Access;
030import org.nuxeo.ecm.webengine.model.WebObject;
031import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException;
032import org.nuxeo.ecm.webengine.model.exceptions.WebSecurityException;
033import org.nuxeo.ecm.webengine.model.impl.ModuleRoot;
034
035@WebObject(type = "Admin", administrator = Access.GRANT)
036@Produces("text/html;charset=UTF-8")
037@Path("/admin")
038public class Main extends ModuleRoot {
039
040    @Path("users")
041    public Object getUserManagement() {
042        return newObject("UserManager");
043    }
044
045    @Path("engine")
046    public Object getEngine() {
047        return newObject("Engine");
048    }
049
050    @Path("repository")
051    public Object getRepository() {
052        return new DocumentRoot(ctx, "/");
053    }
054
055    @GET
056    public Object getIndex() {
057        return getView("index");
058    }
059
060    @GET
061    @Path("help")
062    public Object getHelp() {
063        return getTemplate("help/help.ftl");
064    }
065
066    @GET
067    @Path("about")
068    public Object getAbout() {
069        return getTemplate("help/about.ftl");
070    }
071
072    // handle errors
073    @Override
074    public Object handleError(WebApplicationException e) {
075        if (e instanceof WebSecurityException) {
076            return Response.status(401).entity(getTemplate("error/error_401.ftl")).type("text/html").build();
077        } else if (e instanceof WebResourceNotFoundException) {
078            return Response.status(404).entity(getTemplate("error/error_404.ftl")).type("text/html").build();
079        } else {
080            return super.handleError(e);
081        }
082    }
083
084}