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