View Javadoc
1   /**
2    * Copyright 2005-2016 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.edl.impl.xml.export;
17  
18  import org.kuali.rice.core.api.CoreApiServiceLocator;
19  import org.kuali.rice.core.api.impex.ExportDataSet;
20  import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
21  import org.kuali.rice.krad.bo.Exporter;
22  import org.kuali.rice.krad.exception.ExportNotSupportedException;
23  import org.kuali.rice.krad.util.KRADConstants;
24  
25  import java.io.IOException;
26  import java.io.OutputStream;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * An implementation of the {@link Exporter} class which facilitates exporting
32   * of EDocLite data from the GUI.
33   * 
34   * @see ExportDataSet
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class EdlDataExporter implements Exporter {
39  
40  	private List<String> supportedFormats = new ArrayList<String>();
41  
42  	public EdlDataExporter() {
43  		supportedFormats.add(KRADConstants.XML_FORMAT);
44  	}
45  
46  	@Override
47  	public List<String> getSupportedFormats(Class<?> dataObjectClass) {
48  		return supportedFormats;
49  	}
50  
51  	/**
52  	 * Builds the ExportDataSet based on the BusinessObjects passed in.
53  	 */
54  	protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass, List<? extends Object> dataObjects) {
55  		EdlExportDataSet dataSet = new EdlExportDataSet();
56  		for (Object dataObject : dataObjects) {
57  			if (dataObjectClass.equals(EDocLiteAssociation.class)) {
58  				dataSet.getEdocLites().add((EDocLiteAssociation)dataObject);
59  			}   
60  		}
61  
62  		return  dataSet.createExportDataSet();
63  	}
64  
65  	/**
66  	 * This overridden method ...
67  	 * 
68  	 * @see org.kuali.rice.krad.bo.Exporter#export(java.lang.Class, java.util.List, java.lang.String, java.io.OutputStream)
69  	 */
70  	@Override
71  	public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat, OutputStream outputStream) throws IOException,
72  			ExportNotSupportedException {
73  		if (!KRADConstants.XML_FORMAT.equals(exportFormat)) {
74  			throw new ExportNotSupportedException("The given export format of " + exportFormat + " is not supported by the EDocLite XML Exporter!");
75  		}
76  		ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects);
77  		outputStream.write(CoreApiServiceLocator.getXmlExporterService().export(dataSet));
78  		outputStream.flush();
79  		
80  	}
81  }