<commit_before>//$HeadURL$
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2009 by:
   Department of Geography, University of Bonn
 and
   lat/lon GmbH

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. <NAME>
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: <EMAIL>
----------------------------------------------------------------------------*/

package org.deegree.services.controller.exception.serializer;

import java.io.IOException;
import java.io.OutputStream;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.deegree.commons.xml.XMLAdapter;
import org.deegree.commons.xml.stax.IndentingXMLStreamWriter;
import org.deegree.services.controller.exception.ControllerException;

/**
 * The <code>XMLExceptionSerializer</code> class TODO add class documentation here.
 *
 * @author <a href="mailto:<EMAIL>"><NAME>zema</a>
 *
 * @author last edited by: $Author$
 *
 * @version $Revision$, $Date$
 * @param <T>
 *            the exception which will be serialized, a subtype of {@link ControllerException}
 *
 */
public abstract class XMLExceptionSerializer<T extends ControllerException> extends XMLAdapter implements
                                                                                              ExceptionSerializer<T> {

    /**
     * Wraps a {@link IndentingXMLStreamWriter} around the given output stream and calls
     * {@link #serializeExceptionToXML(XMLStreamWriter, ControllerException)}. The writer will prepare namespaces and
     * will start and end the XML document.
     *
     * @param outputStream
     *            which will be wrapped.
     * @param exception
     *            which must be serialized
     */
    @Override
    public final void serializeException( OutputStream outputStream, T exception, String requestedEncoding )
                            throws IOException {
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        factory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE );
        try {
            IndentingXMLStreamWriter xmlWriter = new IndentingXMLStreamWriter(
                                                                                 factory.createXMLStreamWriter(
                                                                                                                outputStream,
                                                                                                                requestedEncoding ) );
            xmlWriter.writeStartDocument("UTF-8", "1.0");
            serializeExceptionToXML( xmlWriter, exception );
            xmlWriter.writeEndDocument();
        } catch ( XMLStreamException e ) {
            throw new IOException( e );
        }
    }

    /**
     * Implementations can use the xml writer to serialize the given exception as a specific xml representation.
     *
     * @param writer
     *            a formatting xml writer, wrapped around an output stream.
     * @param exception
     *            to serialize
     * @throws XMLStreamException
     *             if an error occurred while serializing the given exception.
     */
    public abstract void serializeExceptionToXML( XMLStreamWriter writer, T exception )
                            throws XMLStreamException;

}<commit_msg>Fixed indenting.<commit_after>//$HeadURL$
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2009 by:
 Department of Geography, University of Bonn
 and
 lat/lon GmbH

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. <NAME>
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: <EMAIL>
 ----------------------------------------------------------------------------*/

package org.deegree.services.controller.exception.serializer;

import java.io.IOException;
import java.io.OutputStream;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.deegree.commons.xml.XMLAdapter;
import org.deegree.commons.xml.stax.IndentingXMLStreamWriter;
import org.deegree.services.controller.exception.ControllerException;

/**
 * The <code>XMLExceptionSerializer</code> class TODO add class documentation here.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * 
 * @author last edited by: $Author$
 * 
 * @version $Revision$, $Date$
 * @param <T>
 *            the exception which will be serialized, a subtype of {@link ControllerException}
 * 
 */
public abstract class XMLExceptionSerializer<T extends ControllerException> extends XMLAdapter implements
                                                                                              ExceptionSerializer<T> {

    /**
     * Wraps a {@link IndentingXMLStreamWriter} around the given output stream and calls
     * {@link #serializeExceptionToXML(XMLStreamWriter, ControllerException)}. The writer will prepare namespaces and
     * will start and end the XML document.
     * 
     * @param outputStream
     *            which will be wrapped.
     * @param exception
     *            which must be serialized
     */
    @Override
    public final void serializeException( OutputStream outputStream, T exception, String requestedEncoding )
                            throws IOException {
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        factory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE );
        try {
            IndentingXMLStreamWriter xmlWriter = new IndentingXMLStreamWriter(
                                                                               factory.createXMLStreamWriter( outputStream,
                                                                                                              requestedEncoding ) );
            xmlWriter.writeStartDocument( "UTF-8", "1.0" );
            serializeExceptionToXML( xmlWriter, exception );
            xmlWriter.writeEndDocument();
        } catch ( XMLStreamException e ) {
            throw new IOException( e );
        }
    }

    /**
     * Implementations can use the xml writer to serialize the given exception as a specific xml representation.
     * 
     * @param writer
     *            a formatting xml writer, wrapped around an output stream.
     * @param exception
     *            to serialize
     * @throws XMLStreamException
     *             if an error occurred while serializing the given exception.
     */
    public abstract void serializeExceptionToXML( XMLStreamWriter writer, T exception )
                            throws XMLStreamException;

}
{'fraction_non_alphanumeric': 0.10167295004712536, 'fraction_numerical': 0.010131950989632422, 'mean_word_length': 2.0602018745493873, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2776135', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1901, 'n_words': 712}