View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.struts.form;
17  
18  import org.kuali.rice.kns.util.WebUtils;
19  import org.kuali.rice.krad.question.Question;
20  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.util.KRADConstants;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import java.util.ArrayList;
25  
26  /**
27   * This class is the action form for all Question Prompts.
28   * 
29   * 
30   */
31  public class QuestionPromptForm extends KualiForm {
32      private static final long serialVersionUID = 1L;
33      private ArrayList buttons;
34      private String caller;
35  
36      private String formKey;
37      private String questionIndex;
38      private String questionText;
39      private String questionType;
40      private String title;
41      private String context;
42      private String reason;
43      private String showReasonField;
44      private String questionAnchor;
45      private String methodToCallPath;
46      private String docNum;
47  
48      /**
49  	 * @return the docNum
50  	 */
51  	public String getDocNum() {
52  		return this.docNum;
53  	}
54  
55  	/**
56  	 * @param docNum the docNum to set
57  	 */
58  	public void setDocNum(String docNum) {
59  		this.docNum = docNum;
60  	}
61  
62  	/**
63       * @return boolean
64       */
65      public String getShowReasonField() {
66          return showReasonField;
67      }
68  
69      /**
70       * @param showReasonField
71       */
72      public void setShowReasonField(String showReasonField) {
73          this.showReasonField = showReasonField;
74      }
75  
76      /**
77       * @return Returns the buttons.
78       */
79      public ArrayList getButtons() {
80          return buttons;
81      }
82  
83      /**
84       * @return Returns the caller.
85       */
86      public String getCaller() {
87          return caller;
88      }
89  
90      /**
91       * @return Returns the formKey.
92       */
93      public String getFormKey() {
94          return formKey;
95      }
96  
97      /**
98       * @return Returns the questionIndex.
99       */
100     public String getQuestionIndex() {
101         return questionIndex;
102     }
103 
104     /**
105      * @return Returns the questionText.
106      */
107     public String getQuestionText() {
108         return questionText != null ? WebUtils.filterHtmlAndReplaceRiceMarkup(questionText) : questionText;
109     }
110 
111     /**
112      * @return Returns the questionName.
113      */
114     public String getQuestionType() {
115         return questionType;
116     }
117 
118     /**
119      * @return Returns the title.
120      */
121     public String getTitle() {
122         return title;
123     }
124 
125     /**
126      * @see org.kuali.rice.krad.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest)
127      */
128     public void populate(HttpServletRequest request) {
129         super.populate(request);
130 
131         // set the title of the jsp, this should come from a resource bundle
132         title = KRADConstants.QUESTION_PAGE_TITLE;
133 
134         if (request.getAttribute(KRADConstants.DOC_FORM_KEY) != null) {
135             this.setFormKey((String) request.getAttribute(KRADConstants.DOC_FORM_KEY));
136         }
137         else if (request.getParameter(KRADConstants.DOC_FORM_KEY) != null) {
138             this.setFormKey(request.getParameter(KRADConstants.DOC_FORM_KEY));
139         }
140         
141         if (request.getAttribute(KRADConstants.DOC_NUM) != null) {
142             this.setFormKey((String) request.getAttribute(KRADConstants.DOC_NUM));
143         }
144         
145 
146         if (request.getParameter(KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
147             this.setBackLocation(request.getParameter(KRADConstants.RETURN_LOCATION_PARAMETER));
148         }
149 
150         if (getMethodToCall().equals(KRADConstants.START_METHOD)) { // don't do this for the processAnswer action otherwise it blows up
151             Question kualiQuestion = KRADServiceLocatorWeb.getQuestion(questionType);
152             if (kualiQuestion == null) {
153                 throw new RuntimeException("question implementation not found: " + request.getParameter(KRADConstants.QUESTION_IMPL_ATTRIBUTE_NAME));
154             }
155 
156 
157             // some questions types default these so we should default if not
158             // present in request
159             if (questionText == null) {
160                 questionText = kualiQuestion.getQuestion();
161             }
162 
163             if (buttons == null) {
164                 buttons = kualiQuestion.getButtons();
165             }
166         }
167     }
168 
169     /**
170      * @param buttons The buttons to set.
171      */
172     public void setButtons(ArrayList buttons) {
173         this.buttons = buttons;
174     }
175 
176     /**
177      * @param caller The caller to set.
178      */
179     public void setCaller(String caller) {
180         this.caller = caller;
181     }
182 
183     /**
184      * @param formKey The formKey to set.
185      */
186     public void setFormKey(String formKey) {
187         this.formKey = formKey;
188     }
189 
190     /**
191      * @param questionIndex The questionIndex to set.
192      */
193     public void setQuestionIndex(String questionIndex) {
194         this.questionIndex = questionIndex;
195     }
196 
197     /**
198      * @param questionText The questionText to set.
199      */
200     public void setQuestionText(String questionText) {
201         this.questionText = questionText;
202     }
203 
204     /**
205      * @param questionName The questionName to set.
206      */
207     public void setQuestionType(String questionName) {
208         this.questionType = questionName;
209     }
210 
211     /**
212      * @param title The title to set.
213      */
214     public void setTitle(String title) {
215         this.title = title;
216     }
217 
218     public String getContext() {
219         return context;
220     }
221 
222     public void setContext(String context) {
223         this.context = context;
224     }
225 
226     /**
227      * @return String
228      */
229     public String getReason() {
230         return reason;
231     }
232 
233     /**
234      * @param reason
235      */
236     public void setReason(String reason) {
237         this.reason = reason;
238     }
239 
240     public String getQuestionAnchor() {
241         return questionAnchor;
242     }
243 
244     public void setQuestionAnchor(String questionAnchor) {
245         this.questionAnchor = questionAnchor;
246     }
247 
248     public String getMethodToCallPath() {
249         return methodToCallPath;
250 }
251     public void setMethodToCallPath(String methodToCallPath) {
252         this.methodToCallPath = methodToCallPath;
253     }
254     
255 }