KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > stylesheet > StylesheetRenderer


1 /*
2  * Copyright 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 package org.apache.myfaces.custom.stylesheet;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.context.ResponseWriter;
23
24 import org.apache.myfaces.renderkit.html.HtmlRenderer;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * @author mwessendorf (latest modification by $Author: matze $)
31  * @version $Revision: 1.2 $ $Date: 2004/10/13 11:50:58 $
32  * $Log: StylesheetRenderer.java,v $
33  * Revision 1.2 2004/10/13 11:50:58 matze
34  * renamed packages to org.apache
35  *
36  * Revision 1.1 2004/08/18 15:36:09 mwessendorf
37  * added a new Stylesheet-Component
38  *
39 */

40
41 public class StylesheetRenderer extends HtmlRenderer {
42
43      private static final Log log = LogFactory.getLog(StylesheetRenderer.class);
44
45      public void encodeEnd(FacesContext context, UIComponent component)
46         throws IOException JavaDoc {
47
48         if ((context == null) || (component == null)) {
49             throw new NullPointerException JavaDoc();
50         }
51         Stylesheet stylesheet = (Stylesheet) component;
52
53         ResponseWriter writer = context.getResponseWriter();
54         writer.startElement("link", component);
55         writer.writeAttribute("rel", "stylesheet", null);
56         writer.writeAttribute("type", "text/css", null);
57         writer.writeURIAttribute
58             ("href",
59              context.getExternalContext().getRequestContextPath()+stylesheet.getPath(),
60              "path");
61         writer.endElement("link");
62     }
63 }
Popular Tags