001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.edl.impl.xml.export;
017
018 import org.kuali.rice.core.api.CoreApiServiceLocator;
019 import org.kuali.rice.core.api.impex.ExportDataSet;
020 import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
021 import org.kuali.rice.krad.bo.Exporter;
022 import org.kuali.rice.krad.exception.ExportNotSupportedException;
023 import org.kuali.rice.krad.util.KRADConstants;
024
025 import java.io.IOException;
026 import java.io.OutputStream;
027 import java.util.ArrayList;
028 import java.util.List;
029
030 /**
031 * An implementation of the {@link Exporter} class which facilitates exporting
032 * of EDocLite data from the GUI.
033 *
034 * @see ExportDataSet
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038 public class EdlDataExporter implements Exporter {
039
040 private List<String> supportedFormats = new ArrayList<String>();
041
042 public EdlDataExporter() {
043 supportedFormats.add(KRADConstants.XML_FORMAT);
044 }
045
046 @Override
047 public List<String> getSupportedFormats(Class<?> dataObjectClass) {
048 return supportedFormats;
049 }
050
051 /**
052 * Builds the ExportDataSet based on the BusinessObjects passed in.
053 */
054 protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass, List<? extends Object> dataObjects) {
055 EdlExportDataSet dataSet = new EdlExportDataSet();
056 for (Object dataObject : dataObjects) {
057 if (dataObjectClass.equals(EDocLiteAssociation.class)) {
058 dataSet.getEdocLites().add((EDocLiteAssociation)dataObject);
059 }
060 }
061
062 return dataSet.createExportDataSet();
063 }
064
065 /**
066 * This overridden method ...
067 *
068 * @see org.kuali.rice.krad.bo.Exporter#export(java.lang.Class, java.util.List, java.lang.String, java.io.OutputStream)
069 */
070 @Override
071 public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat, OutputStream outputStream) throws IOException,
072 ExportNotSupportedException {
073 if (!KRADConstants.XML_FORMAT.equals(exportFormat)) {
074 throw new ExportNotSupportedException("The given export format of " + exportFormat + " is not supported by the EDocLite XML Exporter!");
075 }
076 ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects);
077 outputStream.write(CoreApiServiceLocator.getXmlExporterService().export(dataSet));
078 outputStream.flush();
079
080 }
081 }