View Javadoc

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