Skip to content

Package: EMFFormsSpreadsheetStreamExporterImpl

EMFFormsSpreadsheetStreamExporterImpl

nameinstructionbranchcomplexitylinemethod
EMFFormsSpreadsheetStreamExporterImpl()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
render(OutputStream, Collection, EObject, VViewModelProperties)
M: 48 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.spreadsheet.stream;
15:
16: import java.io.IOException;
17: import java.io.OutputStream;
18: import java.util.Collection;
19:
20: import org.apache.poi.ss.usermodel.Workbook;
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecp.view.spi.model.VViewModelProperties;
23: import org.eclipse.emfforms.spi.common.report.ReportService;
24: import org.eclipse.emfforms.spi.spreadsheet.core.EMFFormsSpreadsheetReport;
25: import org.eclipse.emfforms.spi.spreadsheet.core.transfer.EMFFormsSpreadsheetExporter;
26: import org.eclipse.emfforms.spi.spreadsheet.stream.EMFFormsSpreadsheetStreamExporter;
27: import org.osgi.framework.BundleContext;
28: import org.osgi.framework.FrameworkUtil;
29: import org.osgi.framework.ServiceReference;
30:
31: /**
32: * Class for exporting data to a workbook based on the provided OutputStream.
33: *
34: * @author Eugen Neufeld
35: *
36: */
37: public class EMFFormsSpreadsheetStreamExporterImpl implements EMFFormsSpreadsheetStreamExporter {
38:
39:         @Override
40:         public void render(OutputStream outputStream, Collection<EObject> domainObjects, EObject viewEobject,
41:                 VViewModelProperties properties) {
42:                 final Workbook workbook = EMFFormsSpreadsheetExporter.INSTANCE.render(domainObjects, viewEobject, properties);
43:
44:                 final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
45:                 final ServiceReference<ReportService> serviceReference = bundleContext.getServiceReference(ReportService.class);
46:                 final ReportService reportService = bundleContext.getService(serviceReference);
47:
48:                 try {
49:                         workbook.write(outputStream);
50:                 } catch (final IOException ex) {
51:                         reportService.report(new EMFFormsSpreadsheetReport(ex, 4));
52:                 } finally {
53:                         try {
54:                                 outputStream.close();
55:                         } catch (final IOException ex) {
56:                                 reportService.report(new EMFFormsSpreadsheetReport(ex, 4));
57:                         }
58:                 }
59:                 bundleContext.ungetService(serviceReference);
60:         }
61:
62: }