001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.plugin.jfreereport.components;
014:
015: import java.util.Iterator;
016: import java.util.Set;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.pentaho.core.runtime.IActionParameter;
021: import org.pentaho.messages.Messages;
022: import org.pentaho.plugin.jfreereport.AbstractJFreeReportComponent;
023:
024: /**
025: * Creation-Date: 07.07.2006, 16:26:25
026: *
027: * @author Thomas Morgner
028: */
029: public class JFreeReportValidateParametersComponent extends
030: AbstractJFreeReportComponent {
031: private static final long serialVersionUID = -2888256934867581182L;
032:
033: private boolean parameterUiNeeded;
034:
035: public JFreeReportValidateParametersComponent() {
036: }
037:
038: protected boolean validateAction() {
039: return true;
040: }
041:
042: protected boolean validateSystemSettings() {
043: return true;
044: }
045:
046: public void done() {
047:
048: }
049:
050: private boolean isParameterUIAvailable() {
051: /*
052: * See if we are allowed to generate a parameter selection user interface. If
053: * we are being called as part of a process, this will not be allowed.
054: */
055: if (!feedbackAllowed()) {
056: // We could not get an output stream for the feedback, but we are
057: // allowed
058: // to generate UI, so return an error
059: error(Messages
060: .getErrorString("JFreeReport.ERROR_0020_INVALID_FEEDBACK_STREAM")); //$NON-NLS-1$
061: return false;
062: }
063: // We need input from the user, we have delivered an input form into the
064: // feeback stream
065: setFeedbackMimeType("text/html"); //$NON-NLS-1$
066: return true;
067: }
068:
069: protected boolean executeAction() throws Throwable {
070: final String defaultValue = ""; //$NON-NLS-1$
071:
072: // Get input parameters, and set them as properties in the report
073: // object.
074: final Set paramNames = getInputNames();
075: boolean parameterUINeeded = false;
076:
077: final Iterator it = paramNames.iterator();
078: while (it.hasNext()) {
079: String paramName = (String) it.next();
080: Object paramValue = getInputValue(paramName);
081: if (paramValue == null || ("".equals(paramValue))) //$NON-NLS-1$
082: {
083: IActionParameter paramParameter = getInputParameter(paramName);
084: if (paramParameter.getPromptStatus() == IActionParameter.PROMPT_PENDING) {
085: parameterUINeeded = true;
086: continue;
087: }
088: if (isParameterUIAvailable()) {
089: // The parameter value was not provided, and we are allowed
090: // to
091: // create user interface forms
092: createFeedbackParameter(paramName, paramName,
093: "", defaultValue, true); //$NON-NLS-1$
094: parameterUINeeded = true;
095: } else {
096: return false;
097: }
098: }
099: }
100: if (parameterUINeeded) {
101: addTempParameterObject(
102: REPORTVALIDATECOMPONENT_REPORTTEMP_UI_NEEDED,
103: Boolean.TRUE);
104: this .parameterUiNeeded = true;
105: } else {
106: addTempParameterObject(
107: REPORTVALIDATECOMPONENT_REPORTTEMP_UI_NEEDED,
108: Boolean.FALSE);
109: this .parameterUiNeeded = false;
110: }
111:
112: return true;
113: }
114:
115: public boolean isParameterUiNeeded() {
116: return parameterUiNeeded;
117: }
118:
119: public boolean init() {
120: return true;
121: }
122:
123: public Log getLogger() {
124: return LogFactory
125: .getLog(JFreeReportValidateParametersComponent.class);
126: }
127: }
|