KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > taglib > AttributeTag


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.faces.taglib;
17
18 import org.apache.cocoon.taglib.TagSupport;
19
20 import org.apache.cocoon.faces.FacesUtils;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 import javax.faces.component.UIComponent;
25
26 /**
27  * @version CVS $Id: AttributeTag.java 46253 2004-09-17 14:36:29Z vgritsenko $
28  */

29 public class AttributeTag extends TagSupport {
30
31     private String JavaDoc name;
32     private String JavaDoc value;
33
34     public void setName(String JavaDoc name) {
35         this.name = name;
36     }
37
38     public void setValue(String JavaDoc value) {
39         this.value = value;
40     }
41
42     public int doStartTag(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts)
43     throws SAXException JavaDoc {
44         UIComponentTag tag = FacesUtils.findParentUIComponentTag(this);
45         if (tag == null) {
46             throw new SAXException JavaDoc("Tag <" + getClass().getName() + "> have to be nested within a UIComponentTag");
47         }
48
49         UIComponent component = tag.getComponentInstance();
50         if (component == null) {
51             throw new SAXException JavaDoc("Parent tag <" + tag.getClass(). getName() + "> has no component instance");
52         }
53
54         String JavaDoc nameVal = (String JavaDoc) tag.evaluate(name);
55         Object JavaDoc valueVal = tag.evaluate(value);
56         if (component.getAttributes().get(nameVal) == null) {
57             component.getAttributes().put(nameVal, valueVal);
58         }
59
60         return SKIP_BODY;
61     }
62
63     public void recycle() {
64         super.recycle();
65         this.name = null;
66         this.value = null;
67     }
68 }
69
Popular Tags