1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.composite;
20
21 import java.beans.FeatureDescriptor;
22 import java.util.Arrays;
23
24 import javax.faces.view.facelets.FaceletContext;
25 import javax.faces.view.facelets.Tag;
26 import javax.faces.view.facelets.TagAttribute;
27
28
29
30
31
32
33
34 public final class CompositeTagAttributeUtils
35 {
36
37
38 private CompositeTagAttributeUtils()
39 {
40 }
41
42
43
44
45
46
47
48
49
50
51
52 public static void addUnspecifiedAttributes(FeatureDescriptor descriptor,
53 Tag tag, String[] standardAttributesSorted, FaceletContext ctx)
54 {
55 for (TagAttribute attribute : tag.getAttributes().getAll())
56 {
57 final String name = attribute.getLocalName();
58 if (Arrays.binarySearch(standardAttributesSorted, name) < 0)
59 {
60
61
62 descriptor.setValue(name, attribute.getValueExpression(ctx, Object.class));
63 }
64 }
65 }
66
67
68
69
70
71
72
73
74
75
76 public static boolean containsUnspecifiedAttributes(Tag tag, String[] standardAttributesSorted)
77 {
78 for (TagAttribute attribute : tag.getAttributes().getAll())
79 {
80 final String name = attribute.getLocalName();
81 if (Arrays.binarySearch(standardAttributesSorted, name) < 0)
82 {
83 return true;
84 }
85 }
86 return false;
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100 public static void addDevelopmentAttributes(FeatureDescriptor descriptor,
101 FaceletContext ctx, TagAttribute displayName, TagAttribute shortDescription,
102 TagAttribute expert, TagAttribute hidden, TagAttribute preferred)
103 {
104 if (displayName != null)
105 {
106 descriptor.setDisplayName(displayName.getValue(ctx));
107 }
108 if (shortDescription != null)
109 {
110 descriptor.setShortDescription(shortDescription.getValue(ctx));
111 }
112 if (expert != null)
113 {
114 descriptor.setExpert(expert.getBoolean(ctx));
115 }
116 if (hidden != null)
117 {
118 descriptor.setHidden(hidden.getBoolean(ctx));
119 }
120 if (preferred != null)
121 {
122 descriptor.setPreferred(preferred.getBoolean(ctx));
123 }
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 public static void addDevelopmentAttributesLiteral(FeatureDescriptor descriptor,
138 TagAttribute displayName, TagAttribute shortDescription,
139 TagAttribute expert, TagAttribute hidden, TagAttribute preferred)
140 {
141 if (displayName != null)
142 {
143 descriptor.setDisplayName(displayName.getValue());
144 }
145 if (shortDescription != null)
146 {
147 descriptor.setShortDescription(shortDescription.getValue());
148 }
149 if (expert != null)
150 {
151 descriptor.setExpert(Boolean.valueOf(expert.getValue()));
152 }
153 if (hidden != null)
154 {
155 descriptor.setHidden(Boolean.valueOf(hidden.getValue()));
156 }
157 if (preferred != null)
158 {
159 descriptor.setPreferred(Boolean.valueOf(preferred.getValue()));
160 }
161 }
162
163
164
165
166
167 public static boolean areAttributesLiteral(TagAttribute... attributes)
168 {
169 for (TagAttribute attribute : attributes)
170 {
171 if (attribute != null && !attribute.isLiteral())
172 {
173
174 return false;
175 }
176 }
177
178 return true;
179 }
180
181 }