1 14 15 package com.sun.facelets.tag.jsf.html; 16 17 import com.sun.facelets.tag.Tag; 18 import com.sun.facelets.tag.TagAttribute; 19 import com.sun.facelets.tag.TagAttributes; 20 import com.sun.facelets.tag.TagDecorator; 21 22 26 public final class HtmlDecorator implements TagDecorator { 27 28 public final static String XhtmlNamespace = "http://www.w3.org/1999/xhtml"; 29 30 public final static HtmlDecorator Instance = new HtmlDecorator(); 31 32 35 public HtmlDecorator() { 36 super(); 37 } 38 39 44 public Tag decorate(Tag tag) { 45 if (XhtmlNamespace.equals(tag.getNamespace())) { 46 String n = tag.getLocalName(); 47 if ("a".equals(n)) { 48 return new Tag(tag.getLocation(), HtmlLibrary.Namespace, 49 "commandLink", tag.getQName(), tag.getAttributes()); 50 } 51 if ("form".equals(n)) { 52 return new Tag(tag.getLocation(), HtmlLibrary.Namespace, 53 "form", tag.getQName(), tag.getAttributes()); 54 } 55 if ("input".equals(n)) { 56 TagAttribute attr = tag.getAttributes().get("type"); 57 if (attr != null) { 58 String t = attr.getValue(); 59 TagAttributes na = removeType(tag.getAttributes()); 60 if ("text".equals(t)) { 61 return new Tag(tag.getLocation(), 62 HtmlLibrary.Namespace, "inputText", tag 63 .getQName(), na); 64 } 65 if ("password".equals(t)) { 66 return new Tag(tag.getLocation(), 67 HtmlLibrary.Namespace, "inputSecret", tag 68 .getQName(), na); 69 } 70 if ("hidden".equals(t)) { 71 return new Tag(tag.getLocation(), 72 HtmlLibrary.Namespace, "inputHidden", tag 73 .getQName(), na); 74 } 75 if ("submit".equals(t)) { 76 return new Tag(tag.getLocation(), 77 HtmlLibrary.Namespace, "commandButton", tag 78 .getQName(), na); 79 } 80 } 81 } 82 } 83 return null; 84 } 85 86 private static TagAttributes removeType(TagAttributes attrs) { 87 TagAttribute[] o = attrs.getAll(); 88 TagAttribute[] a = new TagAttribute[o.length - 1]; 89 int p = 0; 90 for (int i = 0; i < o.length; i++) { 91 if (!"type".equals(o[i].getLocalName())) { 92 a[p++] = o[i]; 93 } 94 } 95 return new TagAttributes(a); 96 } 97 98 } 99 | Popular Tags |