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