/** * Serialize the configuration object to a file using a File object. * @param file a <code>File</code> value * @param source a <code>Configuration</code> value * @throws SAXException if an error occurs * @throws IOException if an error occurs * @throws ConfigurationException if an error occurs */ public void serializeToFile( final File file, final Configuration source ) throws SAXException, IOException, ConfigurationException { OutputStream outputStream = null; try { outputStream = new FileOutputStream( file ); serialize( outputStream, source ); } finally { if( outputStream != null ) { outputStream.close(); } } }
/** * Serialize the configuration object to an output stream. * @param outputStream an <code>OutputStream</code> value * @param source a <code>Configuration</code> value * @throws SAXException if an error occurs * @throws IOException if an error occurs * @throws ConfigurationException if an error occurs */ public void serialize( final OutputStream outputStream, final Configuration source ) throws SAXException, IOException, ConfigurationException { serialize( createContentHandler( new StreamResult( outputStream ) ), source ); }
/** * Serialize the configuration object to a string * @param source a <code>Configuration</code> value * @return configuration serialized as a string. * @throws SAXException if an error occurs * @throws ConfigurationException if an error occurs */ public String serialize( final Configuration source ) throws SAXException, ConfigurationException { final StringWriter writer = new StringWriter(); serialize( createContentHandler( new StreamResult( writer ) ), source ); return writer.toString(); } }
/** * Serialize the configuration object to an output stream derived from an * URI. The URI must be resolveable by the <code>java.net.URL</code> object. * @param uri a <code>String</code> value * @param source a <code>Configuration</code> value * @throws SAXException if an error occurs * @throws IOException if an error occurs * @throws ConfigurationException if an error occurs */ public void serialize( final String uri, final Configuration source ) throws SAXException, IOException, ConfigurationException { OutputStream outputStream = null; try { outputStream = new URL( uri ).openConnection().getOutputStream(); serialize( outputStream, source ); } finally { if( outputStream != null ) { outputStream.close(); } } }
/** * Serialize the configuration object to a String. If an exception * occurs, the exception message will be returned instead. This method is * intended to aid debugging; {@link * DefaultConfigurationSerializer#serialize(Configuration)} lets the caller * handle exceptions. * * @param configuration Configuration instance to serialize * @return a non-null String representing the <code>Configuration</code>, * or an error message. * @since 12 March, 2003 */ public static String toString( final Configuration configuration ) { DefaultConfigurationSerializer ser = new DefaultConfigurationSerializer(); try { return ser.serialize( configuration ); } catch( Exception e ) { return e.getMessage(); } }
/** * Get a generated Configuration with interpolated variable values. * @return The Configuration passed in the constructor, with {variable} * tokens in attributes and element bodies replaced with values (if * specified), or <code>null</code>. */ public Configuration getConfiguration() throws SAXException, ConfigurationException { if (this.conf == null) return null; InterpolatingConfigurationHandler handler = new InterpolatingConfigurationHandler(this.vars, this.conf.getLocation()); DefaultConfigurationSerializer ser = new DefaultConfigurationSerializer(); ser.serialize(handler, this.conf); return handler.getConfiguration(); }