001/*
002 * (C) Copyright 2010 Nuxeo SA (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 *     mcedica
016 */
017package org.nuxeo.ecm.webengine.management;
018
019import javax.ws.rs.GET;
020import javax.ws.rs.Path;
021import javax.ws.rs.Produces;
022import javax.ws.rs.WebApplicationException;
023import javax.ws.rs.core.Response;
024
025import org.apache.commons.logging.Log;
026import org.apache.commons.logging.LogFactory;
027import org.nuxeo.ecm.webengine.management.statuses.StatusesObject;
028import org.nuxeo.ecm.webengine.model.WebObject;
029import org.nuxeo.ecm.webengine.model.exceptions.WebSecurityException;
030import org.nuxeo.ecm.webengine.model.impl.ModuleRoot;
031
032/**
033 * Web object implementation corresponding to the root module for management (module used for administrative purpose).
034 *
035 * @author mcedica
036 */
037@Path("/mgmt")
038@WebObject(type = "Management")
039@Produces("text/html; charset=UTF-8")
040public class ManagementModule extends ModuleRoot {
041
042    @SuppressWarnings("unused")
043    private static final Log log = LogFactory.getLog(ManagementModule.class);
044
045    @GET
046    public Object doGet() {
047        return getView("index");
048    }
049
050    @Path("statuses")
051    public Object dispatchStatuses() {
052        return StatusesObject.newObject(this);
053    }
054
055    @Override
056    public Object handleError(WebApplicationException e) {
057        if (e instanceof WebSecurityException) {
058            return Response.status(401).entity(getTemplate("error_401.ftl")).type("text/html").build();
059        }
060        return super.handleError(e);
061    }
062
063}