View Javadoc
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.component;
23  
24  
25  import jakarta.el.ValueExpression;
26  import jakarta.faces.component.UIOutput;
27  import jakarta.faces.context.FacesContext;
28  
29  
30  /**
31   * <p>Custom component that replaces the Struts
32   * <code>&lt;html:stylesheet&gt;</code> tag.</p>
33   */
34  
35  public class StylesheetComponent extends UIOutput {
36  
37  
38      // ------------------------------------------------------------ Constructors
39  
40  
41      /**
42       * <p>Create a new {@link StylesheetComponent} with default properties.</p>
43       */
44      public StylesheetComponent() {
45  
46          super();
47          setRendererType("org.apache.struts.faces.Stylesheet");
48  
49      }
50  
51  
52      // ------------------------------------------------------ Instance Variables
53  
54  
55      /**
56       * <p>Context-relative path of the stylesheet resource.</p>
57       */
58      private String path = null;
59  
60  
61      // ---------------------------------------------------- Component Properties
62  
63  
64      /**
65       * <p>Return the component family to which this component belongs.</p>
66       */
67      public String getFamily() {
68  
69          return "org.apache.struts.faces.Stylesheet";
70  
71      }
72  
73  
74      /**
75       * <p>Return the context-relative stylesheet path.</p>
76       */
77      public String getPath() {
78  
79          ValueExpression vb = getValueExpression("path");
80          if (vb != null) {
81              return (String) vb.getValue(getFacesContext().getELContext());
82          } else {
83              return path;
84          }
85  
86      }
87  
88  
89      /**
90       * <p>Set the context-relative stylesheet path.</p>
91       *
92       * @param path The new path
93       */
94      public void setPath(String path) {
95  
96          this.path = path;
97  
98      }
99  
100 
101     // ---------------------------------------------------- StateManager Methods
102 
103 
104     /**
105      * <p>Restore the state of this component.</p>
106      *
107      * @param context <code>FacesContext</code> for the current request
108      * @param state State object from which to restore our state
109      */
110     public void restoreState(FacesContext context, Object state) {
111 
112         Object values[] = (Object[]) state;
113         super.restoreState(context, values[0]);
114         path = (String) values[1];
115 
116     }
117 
118 
119     /**
120      * <p>Save the state of this component.</p>
121      *
122      * @param context <code>FacesContext</code> for the current request
123      */
124     public Object saveState(FacesContext context) {
125 
126         Object values[] = new Object[2];
127         values[0] = super.saveState(context);
128         values[1] = path;
129         return values;
130 
131     }
132 
133 
134 }