01: /*
02: * $Id: StylesheetRenderer.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: package org.apache.struts.faces.renderer;
23:
24: import java.io.IOException;
25:
26: import javax.faces.component.UIComponent;
27: import javax.faces.context.FacesContext;
28: import javax.faces.context.ResponseWriter;
29:
30: import org.apache.commons.logging.Log;
31: import org.apache.commons.logging.LogFactory;
32:
33: /**
34: * <p><code>Renderer</code> implementation for the <code>stylesheet</code> tag
35: * from the <em>Struts-Faces Integration Library</em>.</p>
36: *
37: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
38: */
39:
40: public class StylesheetRenderer extends AbstractRenderer {
41:
42: // -------------------------------------------------------- Static Variables
43:
44: /**
45: * <p>The <code>Log</code> instance for this class.</p>
46: */
47: private static Log log = LogFactory
48: .getLog(StylesheetRenderer.class);
49:
50: // ---------------------------------------------------------- Public Methods
51:
52: /**
53: * <p>Render a relative HTML <code><link></code> element for a
54: * <code>text/css</code> stylesheet at the specified context-relative
55: * path.</p>
56: *
57: * @param context FacesContext for the request we are processing
58: * @param component UIComponent to be rendered
59: *
60: * @exception IOException if an input/output error occurs while rendering
61: * @exception NullPointerException if <code>context</code>
62: * or <code>component</code> is <code>null</code>
63: */
64: public void encodeEnd(FacesContext context, UIComponent component)
65: throws IOException {
66:
67: if ((context == null) || (component == null)) {
68: throw new NullPointerException();
69: }
70:
71: ResponseWriter writer = context.getResponseWriter();
72: writer.startElement("link", component);
73: writer.writeAttribute("rel", "stylesheet", null);
74: writer.writeAttribute("type", "text/css", null);
75: writer.writeURIAttribute("href", context.getExternalContext()
76: .getRequestContextPath()
77: + (String) component.getAttributes().get("path"),
78: "path");
79: writer.endElement("link");
80: writer.writeText("\n", null);
81:
82: }
83:
84: // ------------------------------------------------------- Protected Methods
85:
86: }
|