org.openlmis.fulfillment.web.util.ReportUtils.java Source code

Java tutorial

Introduction

Here is the source code for org.openlmis.fulfillment.web.util.ReportUtils.java

Source

/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright  2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero 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 Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses. For additional information contact info@OpenLMIS.org.
 */

package org.openlmis.fulfillment.web.util;

import static net.sf.jasperreports.engine.JRParameter.REPORT_LOCALE;
import static net.sf.jasperreports.engine.JRParameter.REPORT_RESOURCE_BUNDLE;

import org.springframework.context.i18n.LocaleContextHolder;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

public final class ReportUtils {

    private ReportUtils() {
        throw new UnsupportedOperationException();
    }

    /**
     * Set parameters of rendered pdf report.
     */
    public static Map<String, Object> createParametersMap() {
        Map<String, Object> params = new HashMap<>();
        params.put("format", "pdf");

        Locale currentLocale = LocaleContextHolder.getLocale();
        params.put(REPORT_LOCALE, currentLocale);

        ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", currentLocale);
        params.put(REPORT_RESOURCE_BUNDLE, resourceBundle);

        params.put("subreport_dir", "reports/");
        params.put("image_dir", "images/");

        return params;
    }
}