// Path: apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/IXmlWriter.java
// public interface IXmlWriter {
// 
//     /**
//      * Starts a document by writing a prolog.
//      * Calling this method is optional.
//      * When writing a document fragment, it should <em>not</em> be called.
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called after the first element has been written
//      * or once a prolog has already been written
//      */
//     IXmlWriter startDocument() throws IOException;
//     
//     /**
//      * Writes the start of an element.
//      * 
//      * @param elementName the name of the element, not null
//      * @return this object 
//      * @throws InvalidXmlException if the name is not valid for an xml element
//      * @throws OperationNotAllowedException 
//      * if called after the first element has been closed
//      */
//     IXmlWriter openElement(CharSequence elementName) throws IOException;
//     
//     /**
//      * Writes an attribute of an element.
//      * Note that this is only allowed directly after {@link #openElement(CharSequence)}
//      * or {@link #attribute}.
//      * 
//      * @param name the attribute name, not null
//      * @param value the attribute value, not null
//      * @return this object
//      * @throws InvalidXmlException if the name is not valid for an xml attribute 
//      * or if a value for the attribute has already been written
//      * @throws OperationNotAllowedException if called after {@link #content(CharSequence)} 
//      * or {@link #closeElement()} or before any call to {@link #openElement(CharSequence)}
//      */
//     IXmlWriter attribute(CharSequence name, CharSequence value) throws IOException;
//     
//     /**
//      * Writes content.
//      * Calling this method will automatically 
//      * Note that this method does not use CDATA.
//      * 
//      * @param content the content to write
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called before any call to {@link #openElement} 
//      * or after the first element has been closed
//      */
//     IXmlWriter content(CharSequence content) throws IOException;
//     
//     /**
//      * Closes the last element written.
//      * 
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called before any call to {@link #openElement} 
//      * or after the first element has been closed
//      */
//     IXmlWriter closeElement() throws IOException;
//     
//     /**
//      * Closes all pending elements.
//      * When appropriate, resources are also flushed and closed.
//      * No exception is raised when called upon a document whose
//      * root element has already been closed.
//      * 
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called before any call to {@link #openElement} 
//      */
//     IXmlWriter closeDocument() throws IOException;
// }


import org.apache.commons.collections4.ArrayStack;
import org.apache.rat.report.xml.writer.IXmlWriter;
import org.apache.rat.report.xml.writer.InvalidXmlException;
import org.apache.rat.report.xml.writer.OperationNotAllowedException;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
                throw new OperationNotAllowedException("Root element has already been closed.");
            } else {
                throw new OperationNotAllowedException("Close called before an element has been opened.");
            }
        }
        final CharSequence elementName = (CharSequence) elementNames.pop();
        if (inElement) {
            writer.write('/');
            writer.write('>');
        } else {
            writer.write('<');
            writer.write('/');
            rawWrite(elementName);
            writer.write('>');
        }
        writer.flush();
        inElement = false;
        return this;
    }


    /**
     * Closes all pending elements.
     * When appropriate, resources are also flushed and closed.
     * No exception is raised when called upon a document whose
     * root element has already been closed.
     *
     * @return this object
     * @throws OperationNotAllowedException if called before any call to {@link #openElement}
     */
// Path: apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/IXmlWriter.java
// public interface IXmlWriter {
// 
//     /**
//      * Starts a document by writing a prolog.
//      * Calling this method is optional.
//      * When writing a document fragment, it should <em>not</em> be called.
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called after the first element has been written
//      * or once a prolog has already been written
//      */
//     IXmlWriter startDocument() throws IOException;
//     
//     /**
//      * Writes the start of an element.
//      * 
//      * @param elementName the name of the element, not null
//      * @return this object 
//      * @throws InvalidXmlException if the name is not valid for an xml element
//      * @throws OperationNotAllowedException 
//      * if called after the first element has been closed
//      */
//     IXmlWriter openElement(CharSequence elementName) throws IOException;
//     
//     /**
//      * Writes an attribute of an element.
//      * Note that this is only allowed directly after {@link #openElement(CharSequence)}
//      * or {@link #attribute}.
//      * 
//      * @param name the attribute name, not null
//      * @param value the attribute value, not null
//      * @return this object
//      * @throws InvalidXmlException if the name is not valid for an xml attribute 
//      * or if a value for the attribute has already been written
//      * @throws OperationNotAllowedException if called after {@link #content(CharSequence)} 
//      * or {@link #closeElement()} or before any call to {@link #openElement(CharSequence)}
//      */
//     IXmlWriter attribute(CharSequence name, CharSequence value) throws IOException;
//     
//     /**
//      * Writes content.
//      * Calling this method will automatically 
//      * Note that this method does not use CDATA.
//      * 
//      * @param content the content to write
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called before any call to {@link #openElement} 
//      * or after the first element has been closed
//      */
//     IXmlWriter content(CharSequence content) throws IOException;
//     
//     /**
//      * Closes the last element written.
//      * 
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called before any call to {@link #openElement} 
//      * or after the first element has been closed
//      */
//     IXmlWriter closeElement() throws IOException;
//     
//     /**
//      * Closes all pending elements.
//      * When appropriate, resources are also flushed and closed.
//      * No exception is raised when called upon a document whose
//      * root element has already been closed.
//      * 
//      * @return this object
//      * @throws OperationNotAllowedException 
//      * if called before any call to {@link #openElement} 
//      */
//     IXmlWriter closeDocument() throws IOException;
// }


// Path: apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java
import org.apache.commons.collections4.ArrayStack;
import org.apache.rat.report.xml.writer.IXmlWriter;
import org.apache.rat.report.xml.writer.InvalidXmlException;
import org.apache.rat.report.xml.writer.OperationNotAllowedException;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

                throw new OperationNotAllowedException("Root element has already been closed.");
            } else {
                throw new OperationNotAllowedException("Close called before an element has been opened.");
            }
        }
        final CharSequence elementName = (CharSequence) elementNames.pop();
        if (inElement) {
            writer.write('/');
            writer.write('>');
        } else {
            writer.write('<');
            writer.write('/');
            rawWrite(elementName);
            writer.write('>');
        }
        writer.flush();
        inElement = false;
        return this;
    }


    /**
     * Closes all pending elements.
     * When appropriate, resources are also flushed and closed.
     * No exception is raised when called upon a document whose
     * root element has already been closed.
     *
     * @return this object
     * @throws OperationNotAllowedException if called before any call to {@link #openElement}
     */
    public IXmlWriter closeDocument() throws IOException {