ebourg      2004/07/13 07:08:47

  Modified:    configuration/xdocs changes.xml
               configuration/src/java/org/apache/commons/configuration
                        XMLConfiguration.java
  Log:
  Added save methods in XMLConfiguration similar to PropertiesConfiguration to save 
the configuration to another file (bug 29721)
  
  Revision  Changes    Path
  1.25      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- changes.xml       12 Jul 2004 12:14:38 -0000      1.24
  +++ changes.xml       13 Jul 2004 14:08:47 -0000      1.25
  @@ -7,6 +7,10 @@
   
     <body>
       <release version="1.0rc1" date="2004-06-??">
  +      <action dev="ebourg" type="add">
  +        Added save methods in XMLConfiguration similar to PropertiesConfiguration
  +        to save the configuration to another file (bug 29721).
  +      </action>
         <action dev="ebourg" type="update">
           Removed the DOM4J implementations in favor of the DOM ones.
           DOMConfiguration has been renamed to XMLConfiguration, and
  
  
  
  1.6       +63 -7     
jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java
  
  Index: XMLConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLConfiguration.java     12 Jul 2004 14:40:54 -0000      1.5
  +++ XMLConfiguration.java     13 Jul 2004 14:08:47 -0000      1.6
  @@ -19,7 +19,11 @@
   import java.io.File;
   import java.io.FileWriter;
   import java.io.IOException;
  +import java.io.OutputStream;
  +import java.io.OutputStreamWriter;
  +import java.io.Writer;
   import java.net.URL;
  +
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.FactoryConfigurationError;
  @@ -365,11 +369,12 @@
       }
   
       /**
  -     * Save the configuration if the automatic persistence is enabled.
  +     * Save the configuration if the automatic persistence is enabled and a
  +     * file is specified.
        */
       private void possiblySave()
       {
  -        if (autoSave)
  +        if (autoSave && fileName != null)
           {
               try
               {
  @@ -392,15 +397,34 @@
           this.autoSave = autoSave;
       }
   
  -    public synchronized void save() throws ConfigurationException
  +    /**
  +     * Save the configuration to the file specified by the fileName attribute.
  +     *
  +     * @throws ConfigurationException
  +     */
  +    public void save() throws ConfigurationException
  +    {
  +        save(getFile().toString());
  +    }
  +
  +    /**
  +     * Save the configuration to a file.
  +     *
  +     * @param filename the name of the xml file
  +     *
  +     * @throws ConfigurationException
  +     */
  +    public void save(String filename) throws ConfigurationException
       {
           FileWriter writer = null;
  +
           try
           {
  -            writer = new FileWriter(getFile());
  -            writer.write(toString());
  +            writer = new FileWriter(filename);
  +            save(writer);
           }
  -        catch (IOException ioe){
  +        catch (IOException ioe)
  +        {
                throw new ConfigurationException("Could not save to " + getFile());
           }
           finally
  @@ -417,6 +441,38 @@
                        throw new ConfigurationException(ioe);
                }
           }
  +    }
  +
  +    /**
  +     * Save the configuration to the specified stream.
  +     *
  +     * @param out the output stream used to save the configuration
  +     */
  +    public void save(OutputStream out) throws IOException
  +    {
  +        save(out, null);
  +    }
  +
  +    /**
  +     * Save the configuration to the specified stream.
  +     *
  +     * @param out the output stream used to save the configuration
  +     * @param encoding the charset used to write the configuration
  +     */
  +    public void save(OutputStream out, String encoding) throws IOException
  +    {
  +        OutputStreamWriter writer = new OutputStreamWriter(out, encoding);
  +        save(writer);
  +    }
  +
  +    /**
  +     * Save the configuration to the specified stream.
  +     *
  +     * @param writer the output stream used to save the configuration
  +     */
  +    public void save(Writer writer) throws IOException
  +    {
  +        writer.write(toString());
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to