1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.workflow.web;
18
19
20 import java.io.IOException;
21 import java.util.EmptyStackException;
22 import javax.servlet.RequestDispatcher;
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.ServletResponse;
26 import org.apache.commons.workflow.Context;
27 import org.apache.commons.workflow.StepException;
28 import org.apache.commons.workflow.base.BaseStep;
29 import org.apache.commons.workflow.util.WorkflowUtils;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class IncludeStep23 extends BaseStep {
54
55
56
57
58
59
60
61
62 public IncludeStep23() {
63
64 super();
65
66 }
67
68
69
70
71
72
73
74 public IncludeStep23(String id) {
75
76 super();
77 setId(id);
78
79 }
80
81
82
83
84
85
86
87
88 public IncludeStep23(String id, String page) {
89
90 super();
91 setId(id);
92 setPage(page);
93
94 }
95
96
97
98
99
100
101
102
103
104 protected String page = null;
105
106 public String getPage() {
107 return (this.page);
108 }
109
110 public void setPage(String page) {
111 this.page = page;
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126 public void execute(Context context) throws StepException {
127
128
129 if (!(context instanceof WebContext))
130 throw new StepException("Execution context is not a WebContext",
131 this);
132 WebContext webContext = (WebContext) context;
133
134
135 String resource = page;
136 if (resource == null) {
137 try {
138 resource = (String) webContext.pop();
139 } catch (EmptyStackException e) {
140 throw new StepException("Evaluation stack is empty", this);
141 }
142 }
143
144
145 RequestDispatcher rd =
146 webContext.getServletContext().getRequestDispatcher(resource);
147 if (rd == null)
148 throw new StepException("No request dispatcher for '" +
149 resource + "'", this);
150 ServletRequest request = webContext.getServletRequest();
151 ServletResponse response =
152 new IncludeResponse23(webContext.getServletResponse());
153
154
155 String content = null;
156 try {
157 rd.include(request, response);
158 content = ((IncludeResponse23) response).getContent();
159 } catch (IOException e) {
160 throw new StepException("IOException including '" +
161 resource + "'", e, this);
162 } catch (ServletException e) {
163 throw new StepException("ServletException including '" +
164 resource + "'", e, this);
165 }
166
167
168 webContext.push(content);
169
170 }
171
172
173
174
175
176 public String toString() {
177
178 StringBuffer sb = new StringBuffer("<web:include");
179 if (getId() != null) {
180 sb.append(" id=\"");
181 sb.append(getId());
182 sb.append("\"");
183 }
184 sb.append(" page=\"");
185 sb.append(getPage());
186 sb.append("\"/>");
187 return (sb.toString());
188
189 }
190
191
192 }