001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Jean-Marc Orliaguet, Chalmers
011 *
012 * $Id$
013 */
014
015package org.nuxeo.theme.jsf.component;
016
017import java.io.IOException;
018import java.net.URL;
019import java.util.Map;
020
021import javax.faces.component.UIOutput;
022import javax.faces.context.ExternalContext;
023import javax.faces.context.FacesContext;
024
025import org.nuxeo.theme.Manager;
026
027public class UIRequire extends UIOutput {
028
029    private String resource;
030
031    @Override
032    public void encodeAll(final FacesContext context) throws IOException {
033        final ExternalContext externalContext = context.getExternalContext();
034        Map<String, Object> requestMap = externalContext.getRequestMap();
035        URL themeUrl = (URL) requestMap.get("org.nuxeo.theme.url");
036
037        Map<String, Object> attributes = getAttributes();
038        String resourceName = (String) attributes.get("resource");
039
040        // Register as a local resource
041        final boolean local = true;
042        Manager.getResourceManager().addResource(resourceName, themeUrl, local);
043    }
044
045    public String getResource() {
046        return resource;
047    }
048
049    public void setResource(String resource) {
050        this.resource = resource;
051    }
052
053}