KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > tag > jsf > html > HtmlDecorator


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

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 /**
23  * @author Jacob Hookom
24  * @version $Id: HtmlDecorator.java,v 1.3 2005/08/24 04:38:45 jhook Exp $
25  */

26 public final class HtmlDecorator implements TagDecorator {
27
28     public final static String JavaDoc XhtmlNamespace = "http://www.w3.org/1999/xhtml";
29
30     public final static HtmlDecorator Instance = new HtmlDecorator();
31
32     /**
33      *
34      */

35     public HtmlDecorator() {
36         super();
37     }
38
39     /*
40      * (non-Javadoc)
41      *
42      * @see com.sun.facelets.tag.TagDecorator#decorate(com.sun.facelets.tag.Tag)
43      */

44     public Tag decorate(Tag tag) {
45         if (XhtmlNamespace.equals(tag.getNamespace())) {
46             String JavaDoc 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 JavaDoc 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