View Javadoc

1   package com.atlassian.config.xml;
2   
3   import com.atlassian.config.ConfigurationException;
4   import org.dom4j.Element;
5   
6   import java.util.ArrayList;
7   import java.util.Iterator;
8   import java.util.List;
9   
10  /**
11   * Created by IntelliJ IDEA.
12   * User: ROSS
13   * Date: 17/03/2004
14   * Time: 10:35:52
15   * To change this template use File | Settings | File Templates.
16   */
17  public class Dom4jXmlListConfigElement extends Dom4jXmlStringConfigElement
18  {
19      public Dom4jXmlListConfigElement(String name, Element context, AbstractDom4jXmlConfigurationPersister config)
20      {
21          super(name, context, config);
22      }
23  
24      public Class getObjectClass()
25      {
26          return List.class;
27      }
28  
29      public void saveConfig(Object object) throws ConfigurationException
30      {
31          List list = (List) object;
32          Element listElement = getOrMakeElement(getPropertyName());
33          listElement.clearContent();
34  
35          Element itemElement;
36          String item;
37          for (Iterator iterator = list.iterator(); iterator.hasNext();)
38          {
39              item = (String) iterator.next();
40              itemElement = listElement.addElement("item");
41  
42              if (useCData)
43              {
44                  itemElement.addCDATA(item);
45              }
46              else
47              {
48                  itemElement.setText(item);
49              }
50          }
51      }
52  
53      public Object loadConfig() throws ConfigurationException
54      {
55          Element element = (Element) context.selectSingleNode(getPropertyName());
56          String item;
57          List list = new ArrayList();
58  
59          for (Iterator iterator = element.elementIterator(); iterator.hasNext();)
60          {
61              item = (String) getConfiguration().getConfigElement(String.class, "item", (Element) iterator.next());
62              list.add(item);
63          }
64          return list;
65      }
66  }