View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package javax.faces.webapp;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.context.FacesContext;
23  import javax.faces.el.ValueBinding;
24  import javax.servlet.jsp.JspException;
25  import javax.servlet.jsp.tagext.Tag;
26  import javax.servlet.jsp.tagext.TagSupport;
27  
28  /**
29   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
30   * 
31   * @deprecated the implementation of this clazz is now an implementation detail.
32   */
33  public class AttributeTag extends TagSupport
34  {
35      private static final long serialVersionUID = 3147657100171678632L;
36      private String _name;
37      private String _value;
38  
39      /**
40       * @deprecated
41       * @param name
42       */
43      public void setName(String name)
44      {
45          _name = name;
46      }
47  
48      /**
49       * @deprecated
50       * @param value
51       */
52      public void setValue(String value)
53      {
54          _value = value;
55      }
56  
57      /**
58       * @deprecated
59       */
60      @Override
61      public int doStartTag() throws JspException
62      {
63          UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
64          if (componentTag == null)
65          {
66              throw new JspException("no parent UIComponentTag found");
67          }
68          UIComponent component = componentTag.getComponentInstance();
69          if (component == null)
70          {
71              throw new JspException("parent UIComponentTag has no UIComponent");
72          }
73          String name = getName();
74          if (component.getAttributes().get(name) == null)
75          {
76              Object value = getValue();
77  
78              if (value != null)
79              {
80                  component.getAttributes().put(name, value);
81              }
82          }
83          return Tag.SKIP_BODY;
84      }
85  
86      /**
87       * @deprecated
88       */
89      @Override
90      public void release()
91      {
92          super.release();
93          _name = null;
94          _value = null;
95      }
96  
97      private String getName()
98      {
99          if (UIComponentTag.isValueReference(_name))
100         {
101             FacesContext facesContext = FacesContext.getCurrentInstance();
102             ValueBinding vb = facesContext.getApplication().createValueBinding(_name);
103             return (String)vb.getValue(facesContext);
104         }
105 
106         return _name;
107     }
108 
109     private Object getValue()
110     {
111         if (UIComponentTag.isValueReference(_value))
112         {
113             FacesContext facesContext = FacesContext.getCurrentInstance();
114             ValueBinding vb = facesContext.getApplication().createValueBinding(_value);
115             return vb.getValue(facesContext);
116         }
117 
118         return _value;
119     }
120 
121 }