Coverage Report - de.smartics.properties.reports.XmlPropertyReport
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlPropertyReport
0%
0/25
N/A
N/A
2,333
 
 1  
 /*
 2  
  * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package de.smartics.properties.reports;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.io.OutputStream;
 20  
 
 21  
 import org.apache.commons.io.IOUtils;
 22  
 
 23  
 import de.smartics.properties.report.app.ReportException;
 24  
 import de.smartics.properties.report.data.PropertyReportItem;
 25  
 import de.smartics.properties.report.data.PropertyReportSet;
 26  
 import de.smartics.util.io.StreamHandler;
 27  
 
 28  
 /**
 29  
  * Writes each report to a file.
 30  
  */
 31  
 public final class XmlPropertyReport extends AbstractPropertyReport
 32  
 {
 33  
   // ********************************* Fields *********************************
 34  
 
 35  
   // --- constants ------------------------------------------------------------
 36  
 
 37  
   // --- members --------------------------------------------------------------
 38  
 
 39  
   /**
 40  
    * The location for property set reports being written to.
 41  
    */
 42  
   private final StreamHandler propertySetReportsRootDir;
 43  
 
 44  
   /**
 45  
    * The location for property reports being written to.
 46  
    */
 47  
   private final StreamHandler propertyReportsRootDir;
 48  
 
 49  
   // ****************************** Initializer *******************************
 50  
 
 51  
   // ****************************** Constructors ******************************
 52  
 
 53  
   /**
 54  
    * Default constructor.
 55  
    *
 56  
    * @param propertySetReportsRootDir the location for property set reports
 57  
    *          being written to.
 58  
    * @param propertyReportsRootDir the location for property reports being
 59  
    *          written to.
 60  
    */
 61  
   public XmlPropertyReport(final StreamHandler propertySetReportsRootDir,
 62  
       final StreamHandler propertyReportsRootDir)
 63  0
   {
 64  0
     this.propertySetReportsRootDir = propertySetReportsRootDir;
 65  0
     this.propertyReportsRootDir = propertyReportsRootDir;
 66  0
   }
 67  
 
 68  
   // ****************************** Inner Classes *****************************
 69  
 
 70  
   // ********************************* Methods ********************************
 71  
 
 72  
   // --- init -----------------------------------------------------------------
 73  
 
 74  
   // --- get&set --------------------------------------------------------------
 75  
 
 76  
   // --- business -------------------------------------------------------------
 77  
 
 78  
   /**
 79  
    * {@inheritDoc}
 80  
    *
 81  
    * @see de.smartics.properties.report.data.PropertyReport#handle(de.smartics.properties.report.data.PropertyReportSet)
 82  
    */
 83  
   @Override
 84  
   public void handle(final PropertyReportSet reportSet) throws ReportException
 85  
   {
 86  0
     final String resourceId = reportSet.getName() + ".xml";
 87  0
     OutputStream out = null;
 88  
     try
 89  
     {
 90  0
       out = propertySetReportsRootDir.openToWrite(resourceId);
 91  0
       final PropertySetReporter reporter = new PropertySetReporter(reportSet);
 92  0
       reporter.write(out);
 93  
     }
 94  0
     catch (final IOException e)
 95  
     {
 96  0
       throw new ReportException("Cannot write report '" + resourceId + "'.", e);
 97  
     }
 98  
     finally
 99  
     {
 100  0
       IOUtils.closeQuietly(out);
 101  0
     }
 102  0
   }
 103  
 
 104  
   /**
 105  
    * {@inheritDoc}
 106  
    *
 107  
    * @see de.smartics.properties.report.data.PropertyReport#handle(de.smartics.properties.report.data.PropertyReportItem)
 108  
    */
 109  
   @Override
 110  
   public void handle(final PropertyReportItem item) throws ReportException
 111  
   {
 112  0
     super.handle(item);
 113  
 
 114  0
     final String resourceId = item.getName() + ".xml";
 115  0
     OutputStream out = null;
 116  
     try
 117  
     {
 118  0
       out = propertyReportsRootDir.openToWrite(resourceId);
 119  0
       final PropertyReporter reporter = new PropertyReporter(item);
 120  0
       reporter.write(out);
 121  
     }
 122  0
     catch (final IOException e)
 123  
     {
 124  0
       throw new ReportException("Cannot write report '" + resourceId + "'.", e);
 125  
     }
 126  
     finally
 127  
     {
 128  0
       IOUtils.closeQuietly(out);
 129  0
     }
 130  0
   }
 131  
 
 132  
   // --- object basics --------------------------------------------------------
 133  
 
 134  
 }