1   package com.atlassian.config.xml;
2   
3   import com.atlassian.config.ConfigurationException;
4   import org.dom4j.DocumentException;
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   
8   import java.io.File;
9   import java.io.FileInputStream;
10  import java.io.FileNotFoundException;
11  import java.io.InputStream;
12  
13  public class DefaultDom4jXmlConfigurationPersister extends AbstractDom4jXmlConfigurationPersister
14  {
15      private static final Logger log = LoggerFactory.getLogger(DefaultDom4jXmlConfigurationPersister.class);
16  
17      public String getRootName()
18      {
19          return "application-configuration";
20      }
21  
22      public synchronized void save(String configPath, String configFile) throws ConfigurationException
23      {
24          saveDocument(configPath, configFile);
25      }
26  
27      public Object load(InputStream is) throws ConfigurationException
28      {
29          try
30          {
31              loadDocument(is);
32          }
33          catch (DocumentException e)
34          {
35              throw new ConfigurationException("Failed to parse config file: " + e.getMessage(), e);
36          }
37  
38          return null;
39      }
40  
41      public String getStringConfigElement(String elementName)
42      {
43          String val = null;
44          try
45          {
46              val = (String) getConfigElement(String.class, elementName);
47          }
48          catch (ConfigurationException e)
49          {
50              log.error("Could not load text from " + elementName +" element: " + e.getMessage());
51          }
52  
53          return val;
54      }
55  
56      public Object load(String configPath, String configFile) throws ConfigurationException
57      {
58          if (configPath == null)
59          {
60              configPath = ".";
61          }
62  
63          try
64          {
65              return load(new FileInputStream(new File(configPath + "/" + configFile)));
66          }
67          catch (FileNotFoundException e)
68          {
69              throw new ConfigurationException("failed to find config at: " + configPath + "/" + configFile, e);
70          }
71      }
72  }