001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache 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 *      https://www.apache.org/licenses/LICENSE-2.0
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
017package org.springframework.web.servlet.view.document;
018
019import java.io.IOException;
020import java.util.Map;
021
022import javax.servlet.http.HttpServletRequest;
023import javax.servlet.http.HttpServletResponse;
024
025import org.apache.poi.ss.usermodel.Workbook;
026import org.apache.poi.xssf.streaming.SXSSFWorkbook;
027
028/**
029 * Convenient superclass for Excel document views in the Office 2007 XLSX format,
030 * using POI's streaming variant. Compatible with Apache POI 3.9 and higher.
031 *
032 * <p>For working with the workbook in subclasses, see
033 * <a href="https://poi.apache.org">Apache's POI site</a>.
034 *
035 * @author Juergen Hoeller
036 * @since 4.2
037 */
038public abstract class AbstractXlsxStreamingView extends AbstractXlsxView {
039
040        /**
041         * This implementation creates a {@link SXSSFWorkbook} for streaming the XLSX format.
042         */
043        @Override
044        protected SXSSFWorkbook createWorkbook(Map<String, Object> model, HttpServletRequest request) {
045                return new SXSSFWorkbook();
046        }
047
048        /**
049         * This implementation disposes of the {@link SXSSFWorkbook} when done with rendering.
050         * @see org.apache.poi.xssf.streaming.SXSSFWorkbook#dispose()
051         */
052        @Override
053        protected void renderWorkbook(Workbook workbook, HttpServletResponse response) throws IOException {
054                super.renderWorkbook(workbook, response);
055
056                // Dispose of temporary files in case of streaming variant...
057                ((SXSSFWorkbook) workbook).dispose();
058        }
059
060}