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

net.sf.jasperreports.export.parameters.ParametersExporterInput Maven / Gradle / Ivy

There is a newer version: 6.21.3
Show newest version
/*
 * JasperReports - Free Java Reporting Library.
 * Copyright (C) 2001 - 2022 TIBCO Software Inc. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of JasperReports.
 *
 * JasperReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JasperReports 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JasperReports. If not, see .
 */
package net.sf.jasperreports.export.parameters;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.export.ExporterInputItem;
import net.sf.jasperreports.export.SimpleExporterInput;


/**
 * @deprecated To be removed.
 * @author Teodor Danciu ([email protected])
 */
public class ParametersExporterInput extends SimpleExporterInput
{
	public static final String EXCEPTION_MESSAGE_KEY_EMPTY_INPUT_SOURCE_IN_BATCH_MODE = "export.parameters.empty.input.source.in.batch.mode";
	public static final String EXCEPTION_MESSAGE_KEY_NO_INPUT_SOURCE = "export.parameters.no.input.source";
	
	/**
	 * 
	 */
	public ParametersExporterInput(Map parameters)
	{
		super(getInputItems(parameters));
	}

	@SuppressWarnings("unchecked")
	private static List getInputItems(Map parameters)
	{
		List items = (List) parameters.get(net.sf.jasperreports.engine.JRExporterParameter.INPUT_ITEM_LIST);
		if (items == null)
		{
			items = getItems(getJasperPrintList(parameters));
		}
		return items;
	}
	
	/**
	 * 
	 */
	@SuppressWarnings("unchecked")
	private static List getJasperPrintList(Map parameters)
	{
		List jasperPrintList = 
			(List)parameters.get(net.sf.jasperreports.engine.JRExporterParameter.JASPER_PRINT_LIST);
		if (jasperPrintList == null)
		{
			JasperPrint jasperPrint = (JasperPrint)parameters.get(net.sf.jasperreports.engine.JRExporterParameter.JASPER_PRINT);
			if (jasperPrint == null)
			{
				try
				{
					InputStream is = (InputStream)parameters.get(net.sf.jasperreports.engine.JRExporterParameter.INPUT_STREAM);
					if (is != null)
					{
						jasperPrint = (JasperPrint)JRLoader.loadObject(is);
					}
					else
					{
						URL url = (URL)parameters.get(net.sf.jasperreports.engine.JRExporterParameter.INPUT_URL);
						if (url != null)
						{
							jasperPrint = (JasperPrint)JRLoader.loadObject(url);
						}
						else
						{
							File file = (File)parameters.get(net.sf.jasperreports.engine.JRExporterParameter.INPUT_FILE);
							if (file != null)
							{
								jasperPrint = (JasperPrint)JRLoader.loadObject(file);
							}
							else
							{
								String fileName = (String)parameters.get(net.sf.jasperreports.engine.JRExporterParameter.INPUT_FILE_NAME);
								if (fileName != null)
								{
									jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(fileName);
								}
								else
								{
									throw 
										new JRRuntimeException(
											EXCEPTION_MESSAGE_KEY_NO_INPUT_SOURCE,
											(Object[])null);
								}
							}
						}
					}
				}
				catch (JRException e)
				{
					throw new JRRuntimeException(e);
				}
			}
			
			jasperPrintList = new ArrayList<>();
			jasperPrintList.add(jasperPrint);
		}
		else
		{
			if (jasperPrintList.size() == 0)
			{
				throw 
					new JRRuntimeException(
						EXCEPTION_MESSAGE_KEY_EMPTY_INPUT_SOURCE_IN_BATCH_MODE,
						(Object[])null);
			}
		}

		return jasperPrintList;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy