com.aurel.track.exchange.docx.exporter.LaTeXExportBL.java Source code

Java tutorial

Introduction

Here is the source code for com.aurel.track.exchange.docx.exporter.LaTeXExportBL.java

Source

/**
 * Genji Scrum Tool and Issue Tracker
 * Copyright (C) 2015 Steinbeis GmbH & Co. KG Task Management Solutions
    
 * <a href="http://www.trackplus.com">Genji Scrum Tool</a>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/* $Id:$ */

package com.aurel.track.exchange.docx.exporter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import com.aurel.track.admin.customize.category.report.execute.ReportBeansToLaTeXConverter;
import com.aurel.track.beans.TPersonBean;
import com.aurel.track.beans.TWorkItemBean;
import com.aurel.track.report.execute.ReportBeans;

/**
 * Logic for exporting a docx file
 * @author Tamas
 *
 */
public class LaTeXExportBL extends DocxExportBL {

    private static final Logger LOGGER = LogManager.getLogger(LaTeXExportBL.class);

    /**
     * Serializes the docx content into the response's output stream
     * @param response
     * @param wordMLPackage
     * @return
     */
    static String prepareReportResponse(HttpServletResponse response, TWorkItemBean workItem,
            ReportBeans reportBeans, TPersonBean user, Locale locale, String templateDir, String templateFile) {
        ReportBeansToLaTeXConverter rl = new ReportBeansToLaTeXConverter();
        File pdf = rl.generatePdf(workItem, reportBeans.getItems(), true, locale, user, "", "", false,
                new File(templateFile), new File(templateDir));

        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            InputStream is = new FileInputStream(pdf);
            IOUtils.copy(is, outputStream);
            is.close();
        } catch (FileNotFoundException e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        } catch (IOException e) {
            LOGGER.error("Getting the output stream failed with " + e.getMessage());
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        } catch (Exception e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        }

        return null;
    }

}