XMLFormatter.java

    1/*******************************************************************************
    2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
    3 * All rights reserved. This program and the accompanying materials
    4 * are made available under the terms of the Eclipse Public License v1.0
    5 * which accompanies this distribution, and is available at
    6 * http://www.eclipse.org/legal/epl-v10.html
    7 *
    8 * Contributors:
    9 *    Brock Janiczak -initial API and implementation
   10 *    
   11 * $Id: $
   12 *******************************************************************************/
   13package org.jacoco.report.xml;
   14
   15import java.io.IOException;
   16
   17import org.jacoco.core.analysis.ICoverageNode;
   18import org.jacoco.report.IReportFormatter;
   19import org.jacoco.report.IReportVisitor;
   20import org.jacoco.report.ISingleReportOutput;
   21
   22/**
   23 * Report formatter that creates a single XML file for a coverage session
   24 * 
   25 * @author Brock Janiczak
   26 * @version $Revision: $
   27 */
   28public class XMLFormatter implements IReportFormatter {
   29
   30    private ISingleReportOutput output;
   31
   32    private String outputEncoding = "UTF-8";
   33
   34    public IReportVisitor createReportVisitor(final ICoverageNode session)
   35            throws IOException {
   36        return new XMLReportFile(outputEncoding, output.createFile());
   37    }
   38
   39    /**
   40     * Sets the report output callback for this report formatter. This is a
   41     * mandatory property.
   42     * 
   43     * @param output
   44     *            report output
   45     */
   46    public void setReportOutput(final ISingleReportOutput output) {
   47        this.output = output;
   48    }
   49
   50    /**
   51     * Sets the encoding used for generated XML document. Default is UTF-8.
   52     * 
   53     * @param outputEncoding
   54     *            XML output encoding
   55     */
   56    public void setOutputEncoding(final String outputEncoding) {
   57        this.outputEncoding = outputEncoding;
   58    }
   59
   60}