cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Cocoon Wiki] Update of "UseCocoonXMLSerializerCode" by AlexanderKlimetschek
Date Thu, 10 May 2007 10:34:36 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cocoon Wiki" for change notification.

The following page has been changed by AlexanderKlimetschek:

New page:
    public static InputStream getInputStream( params...)
            throws IOException, SourceNotFoundException {

        Serializer serializer = createSerializer();

        ByteArrayOutputStream outputStream = null;
        try {
            outputStream = new ByteArrayOutputStream();

            // fill the serializer with SAX Events (it's a ContentHandler)
            MyBrilliantClass.toSAX(serializer, params...);

            return new ByteArrayInputStream(outputStream.toByteArray());
        } catch (SAXException e) {
            throw new CascadingIOException(e);
        } finally {
            if (null != outputStream)
    private static Serializer createSerializer() {
        // we use Cocoons XMLSerializer here which is configurable in terms
        // of the Transformer Implementation to use (some are buggy, so we
        // want to ensure which one is used)
        DefaultConfiguration transformerConfig = 
            new DefaultConfiguration("transformer-factory", null);
        DefaultConfiguration serializerConfig = 
            new DefaultConfiguration("serializer", null);
        serializerConfig.setAttribute("class", "org.apache.cocoon.serialization.XMLSerializer");
        XMLSerializer serializer = new XMLSerializer();
        serializer.enableLogging(new NullLogger());
        try {
        } catch (ConfigurationException e) {
            throw new InitializationException(
                    "could not confiure XMLSerializer", e);
        return serializer;

View raw message