Coverage Report - org.kuali.rice.core.impl.style.StyleDataExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
StyleDataExporter
0%
0/16
0%
0/6
2
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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 org.kuali.rice.core.impl.style;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.io.OutputStream;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.rice.core.api.CoreApiServiceLocator;
 24  
 import org.kuali.rice.core.api.impex.ExportDataSet;
 25  
 import org.kuali.rice.krad.bo.Exporter;
 26  
 import org.kuali.rice.krad.exception.ExportNotSupportedException;
 27  
 import org.kuali.rice.krad.util.KRADConstants;
 28  
 
 29  
 /**
 30  
  * An implementation of the {@link Exporter} class which facilitates exporting
 31  
  * of {@link StyleBo} data from the GUI.
 32  
  * 
 33  
  * @see ExportDataSet
 34  
  * @see StyleBo
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  
 public class StyleDataExporter implements Exporter {
 39  
 
 40  0
         private List<String> supportedFormats = new ArrayList<String>();
 41  
 
 42  0
         public StyleDataExporter() {
 43  0
                 supportedFormats.add(KRADConstants.XML_FORMAT);
 44  0
         }
 45  
 
 46  
         @Override
 47  
         public void export(Class<?> dataObjectClass,
 48  
                         List<? extends Object> dataObjects, String exportFormat,
 49  
                         OutputStream outputStream) throws IOException {
 50  0
                 if (!KRADConstants.XML_FORMAT.equals(exportFormat)) {
 51  0
                         throw new ExportNotSupportedException("The given export format of "
 52  
                                         + exportFormat
 53  
                                         + " is not supported by the KEW XML Exporter!");
 54  
                 }
 55  0
                 ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects);
 56  0
                 outputStream.write(CoreApiServiceLocator.getXmlExporterService()
 57  
                                 .export(dataSet));
 58  0
                 outputStream.flush();
 59  0
         }
 60  
 
 61  
         @Override
 62  
         public List<String> getSupportedFormats(Class<?> dataObjectClass) {
 63  0
                 return supportedFormats;
 64  
         }
 65  
 
 66  
         /**
 67  
          * Builds the ExportDataSet based on the BusinessObjects passed in.
 68  
          */
 69  
         protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass,
 70  
                         List<? extends Object> dataObjects) {
 71  0
                 StyleExportDataSet dataSet = new StyleExportDataSet();
 72  0
                 for (Object dataObject : dataObjects) {
 73  0
                         if (dataObjectClass.equals(StyleBo.class)) {
 74  0
                                 dataSet.getStyles().add((StyleBo) dataObject);
 75  
                         }
 76  
                 }
 77  
 
 78  0
                 return dataSet.createExportDataSet();
 79  
         }
 80  
 
 81  
 }