1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.faces.component;
23
24
25 import javax.faces.component.UIOutput;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28
29
30 /**
31 * <p>Custom component that replaces the Struts
32 * <code><html:stylesheet></code> tag.</p>
33 */
34
35 public class StylesheetComponent extends UIOutput {
36
37
38
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
53
54
55 /**
56 * <p>Context-relative path of the stylesheet resource.</p>
57 */
58 private String path = null;
59
60
61
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 ValueBinding vb = getValueBinding("path");
80 if (vb != null) {
81 return (String) vb.getValue(getFacesContext());
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
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 }