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