001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.function;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.ArrayList;
013: import javax.servlet.http.HttpServletRequest;
014: import javax.servlet.jsp.PageContext;
015:
016: //project specific classes
017: import org.jfolder.common.UnexpectedSystemException;
018: import org.jfolder.common.utils.misc.MiscHelper;
019: import org.jfolder.common.utils.web.ParameterHelper;
020: import org.jfolder.common.utils.web.ParameterSet;
021:
022: //other classes
023:
024: public class ComponentsForReturnableWebPageTag {
025:
026: private ReturnValueAndClassForWebPageTagContext rvacfwtc = null;
027: private ParameterSet ps = null;
028: private PageContext pc = null;
029: //
030: private ArrayList selectedWorkflowInstances = null;
031: private int selectedWorkflowInstancesIndex = 0;
032: private ArrayList selectedWorkflowInstanceIds = null;
033: //
034: private String waitState = null;
035: //
036: private String selectedFormParameter = null;
037: private int selectedFormParameterIndex = 0;
038:
039: ComponentsForReturnableWebPageTag(
040: ReturnValueAndClassForWebPageTagContext inRvacfwtc) {
041: //MiscHelper.println("<!-- ComForRetWebTag -->");
042: //MiscHelper.println("ComForRetWebTag ~");
043: //(new Exception()).printStackTrace();
044: //MiscHelper.println("<!--------------------->");
045: try {
046: this .rvacfwtc = inRvacfwtc;
047: this .pc = this .rvacfwtc.getPageContext();
048: HttpServletRequest hsr = (HttpServletRequest) this .pc
049: .getRequest();
050: this .ps = ParameterHelper.getParameterSet(hsr);
051: //
052: this .selectedWorkflowInstances = new ArrayList();
053: this .selectedWorkflowInstancesIndex = 1;
054: this .selectedWorkflowInstanceIds = new ArrayList();
055: } catch (IOException ioe) {
056: throw new UnexpectedSystemException(ioe);
057: }
058: }
059:
060: public void setForwardInvoked(boolean inInvoked) {
061: this .rvacfwtc.setForwardInvoked(inInvoked);
062: }
063:
064: public PageContext getPageContext() {
065: return this .pc;
066: }
067:
068: public String getApplicationName() {
069:
070: String outValue = null;
071:
072: //
073: PageContext pc = this .rvacfwtc.getPageContext();
074: HttpServletRequest hsr = (HttpServletRequest) pc.getRequest();
075: //TO DO: duplicate code here and in ProjectApplicationServlet
076: outValue = hsr.getContextPath();
077: if (outValue.startsWith("/")) {
078: outValue = outValue.substring(1);
079: }
080: if (outValue.endsWith("/")) {
081: outValue = outValue.substring(0, outValue.length() - 1);
082: }
083:
084: return outValue;
085: }
086:
087: public ParameterSet getParameterSet() {
088: return this .ps;
089: }
090:
091: //public UserHolder getCurrentUser() {
092: //
093: // UserHolder outValue = null;
094: //
095: // SecurityLifecycle uaaac =
096: // SecurityLifecycleHelper.getSecurityLifecycle();
097: // PageContext pc = this.rvacfwtc.getPageContext();
098: // HttpServletRequest hsr = (HttpServletRequest)pc.getRequest();
099: //
100: // UserHolderContext uhc = SecurityLifecycleHelper.getUserHolderContext(
101: // hsr, getParameterSet());
102: //
103: // outValue = uaaac.getUser(uhc);
104: //
105: // //MiscHelper.println("CompForRetWebTag outValue = " + outValue);
106: // //MiscHelper.println("CompForRetWebTag hsr = " + hsr);
107: // //MiscHelper.println("CompForRetWebTag getParSet = "
108: // // + getParameterSet());
109: //
110: // return outValue;
111: //}
112:
113: public String getWaitState() {
114: return this .waitState;
115: }
116:
117: //public void selectWorkflowInstances(String inWaitState,
118: // String inApplication, QueryContainer inQc) {
119: //
120: // WorkflowLifecycle wl =
121: // WorkflowLifecycleFactory.getWorkflowLifecycle();
122: //
123: // this.waitState = inWaitState;
124: //
125: // //add wait at state
126: // QueryContainer endQc =
127: //WaitHelper.getWaitQC(inApplication, inWaitState);
128: // if (inQc != null) {
129: // endQc = AndQC.createQuery(endQc, inQc);
130: // }
131: // inQc = WaitHelper.getWaitQC(inApplication, inWaitState);
132: //
133: // //COLUMN
134: // ColumnContainer cc = ColumnContainer.createColumnContainer();
135: // cc.registerSystemString(AttributeSet.ID, null);
136: //
137: // //STATEMENT
138: // StatementContainer sc = StatementContainer.createStatement(cc, endQc);
139: //
140: // //RESULT SET
141: // ResultSetContainer rsc = wl.queryWorkflowInstances(sc);
142: //
143: // //this.idList = new ArrayList();
144: // this.selectedWorkflowInstances = new ArrayList();
145: // this.selectedWorkflowInstancesIndex = -1;
146: // this.selectedWorkflowInstanceIds = new ArrayList();
147: //
148: // //MiscHelper.println("rsc.getRowCount() = " + rsc.getRowCount());
149: // for (int i = 0; i < rsc.getRowCount(); i++) {
150: // String nextId = rsc.getValueAsString(i, 0);
151: // this.selectedWorkflowInstanceIds.add(nextId);
152: // WorkflowInstance nextWi = wl.retrieveWorkflowInstance(nextId);
153: // this.selectedWorkflowInstances.add(nextWi);
154: // }
155: //
156: // wl.close();
157: //}
158:
159: public boolean hasNextWorkflowInstance() {
160:
161: boolean outValue = false;
162:
163: int nextIndex = (this .selectedWorkflowInstancesIndex + 1);
164:
165: if (nextIndex < this .selectedWorkflowInstances.size()) {
166: this .selectedWorkflowInstancesIndex = nextIndex;
167: outValue = true;
168: }
169:
170: //MiscHelper.println("CompForRetWebTag wfIndex = "
171: // + this.selectedWorkflowInstancesIndex);
172: //MiscHelper.println("CompForRetWebTag outValue = " + outValue);
173:
174: return outValue;
175: }
176:
177: //public WorkflowInstance getNextWorkflowInstance() {
178: //
179: // WorkflowInstance outValue = null;
180: //
181: // //MiscHelper.println("CompForRetWebTag wfNextIndex = "
182: // // + this.selectedWorkflowInstancesIndex);
183: // //outValue = (WorkflowInstance)this.selectedWorkflowInstances.get(
184: // // this.selectedWorkflowInstancesIndex);
185: //
186: // return outValue;
187: //}
188:
189: public void saveChangesToWorkflowIntances() {
190:
191: //WorkflowServiceCaller wsc =
192: // WorkflowServiceCallerFactory.getWorkflowServiceCaller();
193: //WorkflowLifecycle wl =
194: // WorkflowLifecycleFactory.getWorkflowLifecycle();
195:
196: //for (int i = 0; i < this.selectedWorkflowInstances.size(); i++) {
197: //
198: // WorkflowInstance nextWi =
199: // (WorkflowInstance)this.selectedWorkflowInstances.get(i);
200: // wl.updateWorkflowInstance(nextWi);
201: //}
202:
203: //wl.close();
204: throw UnexpectedSystemException.notImplemented();
205: }
206:
207: //
208: public void selectFormParameters(String inParameter) {
209: this .selectedFormParameter = inParameter;
210: this .selectedFormParameterIndex = -1;
211: }
212:
213: public boolean hasNextFormParameter() {
214:
215: boolean outValue = false;
216:
217: int parameterLength = this .ps
218: .getParameterValuesLength(this .selectedFormParameter);
219: this .selectedFormParameterIndex++;
220:
221: if (this .selectedFormParameterIndex < parameterLength) {
222: outValue = true;
223: }
224:
225: return outValue;
226: }
227:
228: public String getNextFormParameter() {
229: return this.ps.getParameter(this.selectedFormParameter,
230: this.selectedFormParameterIndex);
231: }
232: }
|