You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2011/05/25 08:35:44 UTC
svn commit: r1127396 -
/struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/ValueStackDataSource.java
Author: lukaszlenart
Date: Wed May 25 06:35:44 2011
New Revision: 1127396
URL: http://svn.apache.org/viewvc?rev=1127396&view=rev
Log:
WW-2776 - Uses JRRewindableDataSource for JasperReports
Modified:
struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/ValueStackDataSource.java
Modified: struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/ValueStackDataSource.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/ValueStackDataSource.java?rev=1127396&r1=1127395&r2=1127396&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/ValueStackDataSource.java (original)
+++ struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/ValueStackDataSource.java Wed May 25 06:35:44 2011
@@ -21,23 +21,20 @@
package org.apache.struts2.views.jasperreports;
-import java.util.Iterator;
-
-import net.sf.jasperreports.engine.JRDataSource;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
-
+import net.sf.jasperreports.engine.JRRewindableDataSource;
import org.apache.struts2.util.MakeIterator;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import java.util.Iterator;
/**
* Ported to Struts.
- *
*/
-public class ValueStackDataSource implements JRDataSource {
+public class ValueStackDataSource implements JRRewindableDataSource {
/**
* Logger for this class
@@ -47,18 +44,20 @@ public class ValueStackDataSource implem
Iterator iterator;
ValueStack valueStack;
+ String dataSource;
boolean firstTimeThrough = true;
/**
* Create a value stack data source on the given iterable property
*
- * @param valueStack The value stack to base the data source on
- * @param dataSource The property to iterate over for the report
+ * @param valueStack The value stack to base the data source on
+ * @param dataSourceParam The property to iterate over for the report
*/
- public ValueStackDataSource(ValueStack valueStack, String dataSource) {
+ public ValueStackDataSource(ValueStack valueStack, String dataSourceParam) {
this.valueStack = valueStack;
+ dataSource = dataSourceParam;
Object dataSourceValue = valueStack.findValue(dataSource);
if (dataSourceValue != null) {
@@ -71,7 +70,7 @@ public class ValueStackDataSource implem
}
} else {
if (LOG.isWarnEnabled()) {
- LOG.warn("Data source value for data source " + dataSource + " was null");
+ LOG.warn("Data source value for data source " + dataSource + " was null");
}
}
}
@@ -114,6 +113,29 @@ public class ValueStackDataSource implem
}
/**
+ * Move to the first item.
+ *
+ * @throws JRException if there is a problem with moving to the first
+ * data element
+ */
+ public void moveFirst() throws JRException {
+ Object dataSourceValue = valueStack.findValue(dataSource);
+ if (dataSourceValue != null) {
+ if (MakeIterator.isIterable(dataSourceValue)) {
+ iterator = MakeIterator.convert(dataSourceValue);
+ } else {
+ Object[] array = new Object[1];
+ array[0] = dataSourceValue;
+ iterator = MakeIterator.convert(array);
+ }
+ } else {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Data source value for data source [" + dataSource + "] was null");
+ }
+ }
+ }
+
+ /**
* Is there any more data
*
* @return <code>true</code> if there are more elements to iterate over and
@@ -131,13 +153,13 @@ public class ValueStackDataSource implem
if ((iterator != null) && (iterator.hasNext())) {
valueStack.push(iterator.next());
if (LOG.isDebugEnabled()) {
- LOG.debug("Pushed next value: " + valueStack.findValue("."));
+ LOG.debug("Pushed next value: " + valueStack.findValue("."));
}
return true;
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug("No more values");
+ LOG.debug("No more values");
}
return false;