001/*
002 * (C) Copyright 2006-2007 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 *     Jean-Marc Orliaguet, Chalmers
018 *
019 * $Id$
020 */
021
022package org.nuxeo.theme.jsf.component;
023
024import java.io.IOException;
025import java.net.URL;
026import java.util.Map;
027
028import javax.faces.component.UIOutput;
029import javax.faces.context.ExternalContext;
030import javax.faces.context.FacesContext;
031
032import org.nuxeo.theme.Manager;
033
034public class UIRequire extends UIOutput {
035
036    private String resource;
037
038    @Override
039    public void encodeAll(final FacesContext context) throws IOException {
040        final ExternalContext externalContext = context.getExternalContext();
041        Map<String, Object> requestMap = externalContext.getRequestMap();
042        URL themeUrl = (URL) requestMap.get("org.nuxeo.theme.url");
043
044        Map<String, Object> attributes = getAttributes();
045        String resourceName = (String) attributes.get("resource");
046
047        // Register as a local resource
048        final boolean local = true;
049        Manager.getResourceManager().addResource(resourceName, themeUrl, local);
050    }
051
052    public String getResource() {
053        return resource;
054    }
055
056    public void setResource(String resource) {
057        this.resource = resource;
058    }
059
060}