1 /*
2 * $Id$
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "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
25 import java.io.IOException;
26
27 import jakarta.faces.component.UIComponent;
28 import jakarta.faces.context.FacesContext;
29 import jakarta.faces.context.ResponseWriter;
30
31
32 /**
33 * <p><code>Renderer</code> implementation for the <code>stylesheet</code> tag
34 * from the <em>Struts-Faces Integration Library</em>.</p>
35 *
36 * @version $Rev$ $Date$
37 */
38
39 public class StylesheetRenderer extends AbstractRenderer {
40
41
42 // -------------------------------------------------------- Static Variables
43
44
45 // ---------------------------------------------------------- Public Methods
46
47
48 /**
49 * <p>Render a relative HTML <code><link></code> element for a
50 * <code>text/css</code> stylesheet at the specified context-relative
51 * path.</p>
52 *
53 * @param context FacesContext for the request we are processing
54 * @param component UIComponent to be rendered
55 *
56 * @exception IOException if an input/output error occurs while rendering
57 * @exception NullPointerException if <code>context</code>
58 * or <code>component</code> is <code>null</code>
59 */
60 public void encodeEnd(FacesContext context, UIComponent component)
61 throws IOException {
62
63 if ((context == null) || (component == null)) {
64 throw new NullPointerException();
65 }
66
67 ResponseWriter writer = context.getResponseWriter();
68 writer.startElement("link", component);
69 writer.writeAttribute("rel", "stylesheet", null);
70 writer.writeAttribute("type", "text/css", null);
71 writer.writeURIAttribute
72 ("href",
73 context.getExternalContext().getRequestContextPath() +
74 (String) component.getAttributes().get("path"), "path");
75 writer.endElement("link");
76 writer.writeText("\n", null);
77
78 }
79
80
81
82 // ------------------------------------------------------- Protected Methods
83
84
85 }