001/* 002 * (C) Copyright 2014 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.theme.jsf.renderer; 018 019import java.io.IOException; 020import java.net.URL; 021import java.util.HashMap; 022import java.util.Map; 023 024import javax.faces.application.ResourceDependencies; 025import javax.faces.application.ResourceDependency; 026import javax.faces.component.UIComponent; 027import javax.faces.context.ExternalContext; 028import javax.faces.context.FacesContext; 029import javax.faces.context.ResponseWriter; 030import javax.servlet.http.HttpServletRequest; 031 032import org.nuxeo.ecm.platform.ui.web.util.BaseURL; 033import org.nuxeo.theme.html.Utils; 034import org.nuxeo.theme.html.ui.Resources; 035import org.nuxeo.theme.jsf.component.UIResources; 036 037import com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer; 038 039/** 040 * Renderer for {@link UIResources} component. 041 * 042 * @since 6.0 043 */ 044@ResourceDependencies({ @ResourceDependency(library = "javax.faces", name = "jsf.js"), 045 @ResourceDependency(library = "org.richfaces", name = "jquery.js"), 046 @ResourceDependency(library = "org.richfaces", name = "richfaces.js"), 047 @ResourceDependency(library = "org.richfaces", name = "richfaces-queue.js"), 048 @ResourceDependency(library = "org.nuxeo", name = "widget-utils.js"), 049 @ResourceDependency(library = "org.nuxeo.select2", name = "select2.js") }) 050public class ResourcesRenderer extends ScriptStyleBaseRenderer { 051 052 @Override 053 protected void startElement(ResponseWriter writer, UIComponent component) throws IOException { 054 } 055 056 @Override 057 protected void endElement(ResponseWriter writer) throws IOException { 058 } 059 060 @Override 061 public void encodeEnd(FacesContext context, UIComponent component) throws IOException { 062 final ResponseWriter writer = context.getResponseWriter(); 063 final ExternalContext externalContext = context.getExternalContext(); 064 065 Map<String, String> params = new HashMap<String, String>(); 066 067 Map<String, Object> requestMap = externalContext.getRequestMap(); 068 URL themeUrl = (URL) requestMap.get("org.nuxeo.theme.url"); 069 final Map<String, Object> attributes = component.getAttributes(); 070 071 String contextPath = BaseURL.getContextPath(); 072 params.put("contextPath", contextPath); 073 params.put("themeUrl", themeUrl.toString()); 074 params.put("path", contextPath); 075 params.put("ignoreLocal", (String) attributes.get("ignoreLocal")); 076 077 String basePath = contextPath + "/site"; 078 params.put("basepath", basePath); 079 080 Boolean virtualHosting = Utils.isVirtualHosting((HttpServletRequest) externalContext.getRequest()); 081 writer.write(Resources.render(params, virtualHosting)); 082 } 083 084}