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