/** * 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(); } }
/** * 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 file using a filename. * @param filename 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 serializeToFile( final String filename, final Configuration source ) throws SAXException, IOException, ConfigurationException { serializeToFile( new File( filename ), source ); }
/** * 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 to a ContentHandler * @param handler a <code>ContentHandler</code> to serialize to * @param source a <code>Configuration</code> value * @throws SAXException if an error occurs * @throws ConfigurationException if an error occurs */ public void serialize( final ContentHandler handler, final Configuration source ) throws SAXException, ConfigurationException { handler.startDocument(); serializeElement( handler, new NamespaceSupport(), source ); handler.endDocument(); }
/** * Create a ContentHandler for an OutputStream * @param result the result * @return contenthandler that goes to specified OutputStream */ protected ContentHandler createContentHandler( final Result result ) { try { TransformerHandler handler = getTransformerFactory().newTransformerHandler(); m_format.put( OutputKeys.METHOD, "xml" ); handler.setResult( result ); handler.getTransformer().setOutputProperties( m_format ); return handler; } catch( final Exception e ) { throw new RuntimeException( e.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(); } } }
serializeElement( handler, namespaceSupport, children[ i ] );
/** * 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(); }
/** * 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(); } }