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.jsf.html; |
20 | |
|
21 | |
import javax.faces.view.facelets.Tag; |
22 | |
import javax.faces.view.facelets.TagAttribute; |
23 | |
import javax.faces.view.facelets.TagAttributes; |
24 | |
import javax.faces.view.facelets.TagDecorator; |
25 | |
|
26 | |
import org.apache.myfaces.view.facelets.tag.TagAttributesImpl; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public final class HtmlDecorator implements TagDecorator |
33 | |
{ |
34 | |
|
35 | |
public final static String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; |
36 | |
|
37 | 0 | public final static HtmlDecorator INSTANCE = new HtmlDecorator(); |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public HtmlDecorator() |
43 | |
{ |
44 | 0 | super(); |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public Tag decorate(Tag tag) |
53 | |
{ |
54 | 0 | if (XHTML_NAMESPACE.equals(tag.getNamespace())) |
55 | |
{ |
56 | 0 | String n = tag.getLocalName(); |
57 | 0 | if ("a".equals(n)) |
58 | |
{ |
59 | 0 | return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "commandLink", tag.getQName(), tag |
60 | |
.getAttributes()); |
61 | |
} |
62 | 0 | if ("form".equals(n)) |
63 | |
{ |
64 | 0 | return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "form", tag.getQName(), tag.getAttributes()); |
65 | |
} |
66 | 0 | if ("input".equals(n)) |
67 | |
{ |
68 | 0 | TagAttribute attr = tag.getAttributes().get("type"); |
69 | 0 | if (attr != null) |
70 | |
{ |
71 | 0 | String t = attr.getValue(); |
72 | 0 | TagAttributes na = removeType(tag.getAttributes()); |
73 | 0 | if ("text".equals(t)) |
74 | |
{ |
75 | 0 | return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "inputText", tag.getQName(), na); |
76 | |
} |
77 | 0 | if ("password".equals(t)) |
78 | |
{ |
79 | 0 | return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "inputSecret", tag.getQName(), na); |
80 | |
} |
81 | 0 | if ("hidden".equals(t)) |
82 | |
{ |
83 | 0 | return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "inputHidden", tag.getQName(), na); |
84 | |
} |
85 | 0 | if ("submit".equals(t)) |
86 | |
{ |
87 | 0 | return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "commandButton", tag.getQName(), na); |
88 | |
} |
89 | |
} |
90 | |
} |
91 | |
} |
92 | 0 | return null; |
93 | |
} |
94 | |
|
95 | |
private static TagAttributes removeType(TagAttributes attrs) |
96 | |
{ |
97 | 0 | TagAttribute[] o = attrs.getAll(); |
98 | 0 | TagAttribute[] a = new TagAttribute[o.length - 1]; |
99 | 0 | int p = 0; |
100 | 0 | for (int i = 0; i < o.length; i++) |
101 | |
{ |
102 | 0 | if (!"type".equals(o[i].getLocalName())) |
103 | |
{ |
104 | 0 | a[p++] = o[i]; |
105 | |
} |
106 | |
} |
107 | 0 | return new TagAttributesImpl(a); |
108 | |
} |
109 | |
|
110 | |
} |