001/*
002 * (C) Copyright 2015 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.web.resources.jsf;
018
019import java.io.IOException;
020import java.util.Map;
021
022import javax.faces.component.UIComponent;
023import javax.faces.context.FacesContext;
024
025import org.nuxeo.ecm.web.resources.api.Resource;
026import org.nuxeo.ecm.web.resources.api.service.WebResourceManager;
027
028/**
029 * Renderer for HTML resources declared on the {@link WebResourceManager} extension point.
030 *
031 * @since 7.3
032 */
033public class ResourceImportRenderer extends HTMLImportRenderer {
034
035    @Override
036    protected String resolveUrl(FacesContext context, UIComponent component) throws IOException {
037        Map<String, Object> attributes = component.getAttributes();
038        String name = (String) attributes.get("name");
039        if (name != null) {
040            Resource r = resolveNuxeoResource(context, component, name);
041            if (r != null) {
042                return getUrlWithParams(context, component, r.getURI());
043            }
044        }
045        return null;
046    }
047
048}