| 1 13 package org.pentaho.plugin.jfreereport.components; 14 15 import java.util.Iterator ; 16 import java.util.Set ; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.jfree.report.JFreeReport; 21 import org.pentaho.messages.Messages; 22 import org.pentaho.plugin.jfreereport.AbstractJFreeReportComponent; 23 24 31 public class JFreeReportParametersComponent extends 32 AbstractJFreeReportComponent { 33 private static final long serialVersionUID = -3760254131944082953L; 34 35 public JFreeReportParametersComponent() { 36 } 37 38 protected boolean validateAction() { 39 return isDefinedInput(DATACOMPONENT_REPORTTEMP_OBJINPUT); 40 } 41 42 protected boolean validateSystemSettings() { 43 return true; 44 } 45 46 public void done() { 47 48 } 49 50 protected JFreeReport getReport() { 51 Object maybeReport = getInputValue(DATACOMPONENT_REPORTTEMP_OBJINPUT); 52 if (maybeReport instanceof JFreeReport) { 53 return (JFreeReport) maybeReport; 54 } 55 error(Messages 56 .getString("JFreeReportParametersComponent.ERROR_0033_NO_REPORT_BOUND") + maybeReport); return null; 58 } 59 60 protected boolean executeAction() throws Throwable { 61 JFreeReport report = getReport(); 62 if (report == null) { 63 error(Messages 64 .getString("JFreeReportParametersComponent.ERROR_0034_NO_REPORT_DEFINITION")); return false; 66 } 67 68 final boolean privateCopy = getInputBooleanValue( 69 REPORTPARAMCOMPONENT_PRIVATEREPORT_OUTPUT, false); 70 if (privateCopy && isDefinedOutput(DATACOMPONENT_REPORTTEMP_OBJINPUT)) { 71 report = (JFreeReport) report.clone(); 72 } 73 74 final Set paramNames = getInputNames(); 77 final Iterator it = paramNames.iterator(); 78 while (it.hasNext()) { 79 String paramName = (String ) it.next(); 80 Object paramValue = getInputValue(paramName); 81 if (paramValue == null || "".equals(paramValue)) { continue; 83 } 84 85 89 if (DATACOMPONENT_REPORTTEMP_OBJINPUT.equals(paramName)) { 90 continue; 91 } 92 if (DATACOMPONENT_REPORTTEMP_DATAINPUT.equals(paramName)) { 93 continue; 94 } 95 if (DATACOMPONENT_DATAINPUT.equals(paramName)) { 96 continue; 97 } 98 99 if (paramValue instanceof Object []) { 100 Object values[] = (Object []) paramValue; 101 StringBuffer valuesBuffer = new StringBuffer (); 102 for (int i = 0; i < values.length; i++) { 104 if (i == 0) { 105 valuesBuffer.append(values[i].toString()); 106 } else { 107 valuesBuffer.append(',').append(values[i].toString()); 108 } 109 } 110 report.setProperty(paramName, valuesBuffer.toString()); 111 } else { 112 report.setProperty(paramName, paramValue); 113 } 114 } 115 116 if (privateCopy && isDefinedInput(DATACOMPONENT_REPORTTEMP_OBJINPUT)) { 117 addTempParameterObject(DATACOMPONENT_REPORTTEMP_OBJINPUT, report); 118 } 119 return true; 120 } 121 122 public boolean init() { 123 return true; 124 } 125 126 public Log getLogger() { 127 return LogFactory.getLog(JFreeReportParametersComponent.class); 128 } 129 } 130 | Popular Tags |