KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > renderer > StylesheetRenderer


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.faces.renderer;
18
19
20 import java.io.IOException JavaDoc;
21
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.faces.context.ResponseWriter;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29
30 /**
31  * <p><code>Renderer</code> implementation for the <code>stylesheet</code> tag
32  * from the <em>Struts-Faces Integration Library</em>.</p>
33  *
34  * @version $Rev: 54934 $ $Date: 2004-10-16 18:07:50 +0100 (Sat, 16 Oct 2004) $
35  */

36
37 public class StylesheetRenderer extends AbstractRenderer {
38
39
40     // -------------------------------------------------------- Static Variables
41

42
43     /**
44      * <p>The <code>Log</code> instance for this class.</p>
45      */

46     private static Log log = LogFactory.getLog(StylesheetRenderer.class);
47
48
49     // ---------------------------------------------------------- Public Methods
50

51
52     /**
53      * <p>Render a relative HTML <code>&lt;link&gt;</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 JavaDoc {
66
67         if ((context == null) || (component == null)) {
68             throw new NullPointerException JavaDoc();
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
76             ("href",
77              context.getExternalContext().getRequestContextPath() +
78              (String JavaDoc) component.getAttributes().get("path"), "path");
79         writer.endElement("link");
80         writer.writeText("\n", null);
81
82     }
83
84
85
86     // ------------------------------------------------------- Protected Methods
87

88
89 }
90
Popular Tags