001/* 002 * (C) Copyright 2014 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-2.1.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 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.ui.web.application; 018 019import javax.faces.application.ResourceHandler; 020import javax.faces.application.ResourceHandlerWrapper; 021import javax.faces.application.ViewResource; 022import javax.faces.context.FacesContext; 023 024import org.nuxeo.ecm.web.resources.api.service.WebResourceManager; 025 026/** 027 * Custom resource handler resolving resources thanks to {@link WebResourceManager} service, and handling error 028 * management of unknown resources. 029 * 030 * @since 6.0 031 */ 032public class NuxeoResourceHandler extends ResourceHandlerWrapper { 033 034 protected ResourceHandler wrapped; 035 036 public NuxeoResourceHandler(ResourceHandler wrapped) { 037 this.wrapped = wrapped; 038 } 039 040 @Override 041 public ViewResource createViewResource(FacesContext facesContext, String resourceName) { 042 if (resourceName.startsWith(NuxeoUnknownResource.MARKER)) { 043 return new NuxeoUnknownResource(resourceName.substring(NuxeoUnknownResource.MARKER.length())); 044 } 045 ViewResource res = wrapped.createViewResource(facesContext, resourceName); 046 if (res == null) { 047 res = new NuxeoUnknownResource(resourceName); 048 } 049 return res; 050 } 051 052 @Override 053 public ResourceHandler getWrapped() { 054 return wrapped; 055 } 056 057}