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 public final static HtmlDecorator INSTANCE = new HtmlDecorator();
38
39 public HtmlDecorator()
40 {
41 super();
42 }
43
44 @Override
45 public Tag decorate(Tag tag)
46 {
47 if (XHTML_NAMESPACE.equals(tag.getNamespace()))
48 {
49 String n = tag.getLocalName();
50 if ("a".equals(n))
51 {
52 return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "commandLink", tag.getQName(), tag
53 .getAttributes());
54 }
55 if ("form".equals(n))
56 {
57 return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "form", tag.getQName(), tag.getAttributes());
58 }
59 if ("input".equals(n))
60 {
61 TagAttribute attr = tag.getAttributes().get("type");
62 if (attr != null)
63 {
64 String t = attr.getValue();
65 TagAttributes na = removeType(tag.getAttributes());
66 if ("text".equals(t))
67 {
68 return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "inputText", tag.getQName(), na);
69 }
70 if ("password".equals(t))
71 {
72 return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "inputSecret", tag.getQName(), na);
73 }
74 if ("hidden".equals(t))
75 {
76 return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "inputHidden", tag.getQName(), na);
77 }
78 if ("submit".equals(t))
79 {
80 return new Tag(tag.getLocation(), HtmlLibrary.NAMESPACE, "commandButton", tag.getQName(), na);
81 }
82 }
83 }
84 }
85 return null;
86 }
87
88 private static TagAttributes removeType(TagAttributes attrs)
89 {
90 TagAttribute[] o = attrs.getAll();
91 TagAttribute[] a = new TagAttribute[o.length - 1];
92 int p = 0;
93 for (int i = 0; i < o.length; i++)
94 {
95 if (!"type".equals(o[i].getLocalName()))
96 {
97 a[p++] = o[i];
98 }
99 }
100 return new TagAttributesImpl(a);
101 }
102
103 }