View Javadoc

1   /***
2    * Copyright (c) 2003 held jointly by the individual authors.
3    * 
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    * 
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12   * for more details.
13   * 
14   * You should have received a copy of the GNU Lesser General Public License
15   * along with this library; if not, write to the Free Software Foundation, Inc.,
16   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. >
17   * http://www.gnu.org/copyleft/lesser.html >
18   * http://www.opensource.org/licenses/lgpl-license.php
19   */
20  package net.mlw.vlh.web.tag.support;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import net.mlw.vlh.web.util.JspUtils;
26  
27  /***
28   * Holds a map of attributes.
29   * 
30   * @author Matthew L. Wilson
31   * @version $Revision: 1.4 $ $Date: 2005/08/19 16:06:30 $
32   */
33  public class Attributes implements Attributeable
34  {
35      private Map attributes = new HashMap();
36  
37      /***
38       * Default constructore.
39       */
40      public Attributes()
41      {
42  
43      }
44  
45      /***
46       * @see net.mlw.vlh.web.tag.support.Attributeable#setAttribute(java.lang.String,
47       *      java.lang.String)
48       */
49      public void setCellAttribute(String name, String value)
50      {
51          attributes.put(name, value);
52      }
53  
54      /***
55       * returns a String in the form or nameX="valueX".
56       * 
57       * @return A String in the form or nameX="valueX".
58       */
59      public String getCellAttributesAsString()
60      {
61          return JspUtils.toAttributesString(attributes);
62      }
63  
64      public Map getMap()
65      {
66          return attributes;
67      }
68  
69      /***
70       * reset this bean.
71       */
72      public void reset()
73      {
74          attributes.clear();
75      }
76  
77      /***
78       * Append with the space to existing non null or empty key's value. If not exist key, uses
79       * setCellAttribute Ussually used with "class" attributes.
80       * 
81       * @param key
82       * @param style to append
83       * @see #setCellAttribute(String, String)
84       */
85      public void appendCellAttribute(String key, String style)
86      {
87          if (attributes.containsKey(key))
88          {
89              String current = (String) attributes.get(key);
90              if (current!=null && current.length()>0){
91                  attributes.put(key, current + " " + style);
92              } else {
93                 setCellAttribute(key, style); 
94              }
95          }
96          else
97          {
98              setCellAttribute(key, style);
99          }
100 
101     }
102 }