KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > components > JFreeReportValidateParametersComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12 */

13 package org.pentaho.plugin.jfreereport.components;
14
15 import java.util.Iterator JavaDoc;
16 import java.util.Set JavaDoc;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.pentaho.core.runtime.IActionParameter;
21 import org.pentaho.messages.Messages;
22 import org.pentaho.plugin.jfreereport.AbstractJFreeReportComponent;
23
24 /**
25  * Creation-Date: 07.07.2006, 16:26:25
26  *
27  * @author Thomas Morgner
28  */

29 public class JFreeReportValidateParametersComponent extends AbstractJFreeReportComponent {
30     private static final long serialVersionUID = -2888256934867581182L;
31
32     private boolean parameterUiNeeded;
33
34     public JFreeReportValidateParametersComponent() {
35     }
36
37     protected boolean validateAction() {
38         return true;
39     }
40
41     protected boolean validateSystemSettings() {
42         return true;
43     }
44
45     public void done() {
46
47     }
48     
49     private boolean isParameterUIAvailable() {
50         /*
51          * See if we are allowed to generate a parameter selection user interface. If
52          * we are being called as part of a process, this will not be allowed.
53          */

54         if (!feedbackAllowed()) {
55             // We could not get an output stream for the feedback, but we are
56
// allowed
57
// to generate UI, so return an error
58
error(Messages.getErrorString("JFreeReport.ERROR_0020_INVALID_FEEDBACK_STREAM")); //$NON-NLS-1$
59
return false;
60         }
61         // We need input from the user, we have delivered an input form into the
62
// feeback stream
63
setFeedbackMimeType("text/html"); //$NON-NLS-1$
64
return true;
65     }
66
67     protected boolean executeAction() throws Throwable JavaDoc {
68         final String JavaDoc defaultValue = ""; //$NON-NLS-1$
69

70         // Get input parameters, and set them as properties in the report
71
// object.
72
final Set JavaDoc paramNames = getInputNames();
73         boolean parameterUINeeded = false;
74
75         final Iterator JavaDoc it = paramNames.iterator();
76         while (it.hasNext()) {
77             String JavaDoc paramName = (String JavaDoc) it.next();
78             Object JavaDoc paramValue = getInputValue(paramName);
79             if (paramValue == null || ("".equals(paramValue))) //$NON-NLS-1$
80
{
81                 IActionParameter paramParameter = getInputParameter(paramName);
82                 if (paramParameter.getPromptStatus() == IActionParameter.PROMPT_PENDING) {
83                     parameterUINeeded = true;
84                     continue;
85                 }
86                 if (isParameterUIAvailable()) {
87                     // The parameter value was not provided, and we are allowed
88
// to
89
// create user interface forms
90
createFeedbackParameter(paramName, paramName, "", defaultValue, true); //$NON-NLS-1$
91
parameterUINeeded = true;
92                 } else {
93                     return false;
94                 }
95             }
96         }
97         if (parameterUINeeded) {
98             addTempParameterObject(REPORTVALIDATECOMPONENT_REPORTTEMP_UI_NEEDED, Boolean.TRUE);
99             this.parameterUiNeeded = true;
100         } else {
101             addTempParameterObject(REPORTVALIDATECOMPONENT_REPORTTEMP_UI_NEEDED, Boolean.FALSE);
102             this.parameterUiNeeded = false;
103         }
104
105         return true;
106     }
107
108     public boolean isParameterUiNeeded() {
109         return parameterUiNeeded;
110     }
111
112     public boolean init() {
113         return true;
114     }
115
116     public Log getLogger() {
117         return LogFactory.getLog(JFreeReportValidateParametersComponent.class);
118     }
119 }
120
Popular Tags