All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.metamodel.excel.XlsxRowPublisherAction Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.metamodel.excel;

import java.io.InputStream;
import java.util.List;

import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.metamodel.data.RowPublisher;
import org.apache.metamodel.data.Style;
import org.apache.metamodel.schema.Column;
import org.apache.metamodel.util.Action;
import org.apache.metamodel.util.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

class XlsxRowPublisherAction implements Action {

	private static final Logger logger = LoggerFactory
			.getLogger(XlsxRowPublisherAction.class);

	private final ExcelConfiguration _configuration;
	private final List _columns;
	private final String _relationshipId;
	private final XSSFReader _xssfReader;

	public XlsxRowPublisherAction(ExcelConfiguration configuration,
			List columns, String relationshipId, XSSFReader xssfReader) {
		_configuration = configuration;
		_columns = columns;
		_relationshipId = relationshipId;
		_xssfReader = xssfReader;
	}

	@Override
	public void run(final RowPublisher publisher) throws Exception {
		final InputStream sheetData = _xssfReader.getSheet(_relationshipId);

		final XlsxRowCallback rowCallback = new XlsxRowCallback() {
			@Override
			public boolean row(int rowNumber, List values,
					List