blob: 215e1a3318eb873aa597095424115aefe9c7493a [file] [log] [blame]
/*
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id: StylesheetRenderer.java,v 1.3 2004/11/14 07:33:15 tcfujii Exp $
*/
package components.renderkit;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIOutput;
import jakarta.faces.context.FacesContext;
import jakarta.faces.context.ResponseWriter;
import java.io.IOException;
/**
* <p>Render a stylesheet link for the value of our component's
* <code>path</code> attribute, prefixed by the context path of this
* web application.</p>
*/
public class StylesheetRenderer extends BaseRenderer {
public boolean supportsComponentType(UIComponent component) {
return (component instanceof UIOutput);
}
public void decode(FacesContext context, UIComponent component) {
}
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {
;
}
public void encodeChildren(FacesContext context, UIComponent component)
throws IOException {
;
}
/**
* <p>Render a relative HTML <code>&lt;link&gt;</code> element for a
* <code>text/css</code> stylesheet at the specified context-relative
* path.</p>
*
* @param context FacesContext for the request we are processing
* @param component UIComponent to be rendered
*
* @throws IOException if an input/output error occurs while rendering
* @throws NullPointerException if <code>context</code>
* or <code>component</code> is null
*/
public void encodeEnd(FacesContext context, UIComponent component)
throws IOException {
if ((context == null) || (component == null)) {
throw new NullPointerException();
}
ResponseWriter writer = context.getResponseWriter();
String contextPath = context.getExternalContext()
.getRequestContextPath();
writer.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
writer.write(contextPath);
writer.write((String) component.getAttributes().get("path"));
writer.write("\">");
}
}