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