View Javadoc

1   /*
2    * $Id: StylesheetRenderer.java 471754 2006-11-06 14:55:09Z husted $
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 javax.faces.component.UIComponent;
28  import javax.faces.context.FacesContext;
29  import javax.faces.context.ResponseWriter;
30  
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  
35  /**
36   * <p><code>Renderer</code> implementation for the <code>stylesheet</code> tag
37   * from the <em>Struts-Faces Integration Library</em>.</p>
38   *
39   * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
40   */
41  
42  public class StylesheetRenderer extends AbstractRenderer {
43  
44  
45      // -------------------------------------------------------- Static Variables
46  
47  
48      /**
49       * <p>The <code>Log</code> instance for this class.</p>
50       */
51      private static Log log = LogFactory.getLog(StylesheetRenderer.class);
52  
53  
54      // ---------------------------------------------------------- Public Methods
55  
56  
57      /**
58       * <p>Render a relative HTML <code>&lt;link&gt;</code> element for a
59       * <code>text/css</code> stylesheet at the specified context-relative
60       * path.</p>
61       *
62       * @param context FacesContext for the request we are processing
63       * @param component UIComponent to be rendered
64       *
65       * @exception IOException if an input/output error occurs while rendering
66       * @exception NullPointerException if <code>context</code>
67       *  or <code>component</code> is <code>null</code>
68       */
69      public void encodeEnd(FacesContext context, UIComponent component)
70          throws IOException {
71  
72          if ((context == null) || (component == null)) {
73              throw new NullPointerException();
74          }
75  
76          ResponseWriter writer = context.getResponseWriter();
77          writer.startElement("link", component);
78          writer.writeAttribute("rel", "stylesheet", null);
79          writer.writeAttribute("type", "text/css", null);
80          writer.writeURIAttribute
81              ("href",
82               context.getExternalContext().getRequestContextPath() +
83               (String) component.getAttributes().get("path"), "path");
84          writer.endElement("link");
85          writer.writeText("\n", null);
86  
87      }
88  
89  
90  
91      // ------------------------------------------------------- Protected Methods
92  
93  
94  }