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

ch.epfl.gsn.reports.scriptlets.ReportScriptlet Maven / Gradle / Ivy

The newest version!
/**
* Global Sensor Networks (GSN) Source Code
* Copyright (c) 2006-2016, Ecole Polytechnique Federale de Lausanne (EPFL)
* 
* This file is part of GSN.
* 
* GSN 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.
* 
* GSN 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 GSN.  If not, see .
* 
* File: src/ch/epfl/gsn/reports/scriptlets/ReportScriptlet.java
*
* @author Timotee Maret
* @author Ali Salehi
*
*/

package ch.epfl.gsn.reports.scriptlets;

import java.util.Collection;
import java.util.Iterator;
import java.util.TimeZone;

import ch.epfl.gsn.reports.beans.VirtualSensor;
import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;

public class ReportScriptlet extends JRDefaultScriptlet {
	
	public ReportScriptlet () {
		super () ;
	}
	
	public void afterReportInit() throws JRScriptletException {
		setListOfVirtualSensors () ;
		setServerTimeZone () ;
	}
	
	private void setServerTimeZone () throws JRScriptletException {
		this.setVariableValue("serverTimeZone", 
				TimeZone.getDefault().getDisplayName().toString() + 
				" - " +
				TimeZone.getDefault().getID().toString()
		);
	}
	
	@SuppressWarnings("unchecked")
	private void setListOfVirtualSensors () throws JRScriptletException {
		Collection virtualSensors = (Collection) this.getFieldValue("virtualSensors");
		StringBuilder sb = new StringBuilder () ;
		Iterator iter = (Iterator) virtualSensors.iterator();
		String nextName;
		while (iter.hasNext()) {
			nextName = ((VirtualSensor)iter.next()).getVirtualSensorName();
			sb.append(nextName);
			if (iter.hasNext()) sb.append(", ") ;
		}
		this.setVariableValue("listOfVirtualSensors", sb.toString());
	}	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy