01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.example.main.web.popups;
16:
17: import java.io.ByteArrayOutputStream;
18: import java.io.OutputStream;
19: import javax.servlet.http.HttpServletResponse;
20: import org.araneaframework.InputData;
21: import org.araneaframework.OutputData;
22: import org.araneaframework.Path;
23: import org.araneaframework.core.BaseService;
24: import org.araneaframework.framework.ManagedServiceContext;
25: import org.araneaframework.http.util.ServletUtil;
26:
27: /**
28: * Sample service that applies the flow return value to opener
29: * window widget purely on client-side.
30: *
31: * @author Taimo Peelo (taimo@araneaframework.org)
32: */
33: public class ParentActionInvokingService extends BaseService implements
34: ClientSideReturnService {
35: private String value;
36: private String widgetId;
37:
38: public ParentActionInvokingService(String widgetId) {
39: this .widgetId = widgetId;
40: }
41:
42: protected void action(Path path, InputData input, OutputData output)
43: throws Exception {
44: HttpServletResponse response = ServletUtil.getResponse(output);
45: String script = "if (window.opener) { window.opener.setTimeout(\""
46: + "araneaPage().action(document.getElementById('"
47: + widgetId
48: + "'), 'testAction', '"
49: + widgetId.substring(0, widgetId.lastIndexOf('.'))
50: + "' , '"
51: + value
52: + "', window['tehcallback']);"
53: + "\", 0); }" + "window.close();";
54:
55: String responseStr = "<html>" + "<head>"
56: + "<script type=\"text/javascript\">" + script
57: + "</script>" + "</head>" + "<body>" + "</body>"
58: + "</html>";
59:
60: byte[] rsp = responseStr.getBytes();
61:
62: ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
63: byteOutputStream.write(rsp);
64:
65: response.setContentType("text/html");
66: response.setContentLength(byteOutputStream.size());
67:
68: OutputStream out = response.getOutputStream();
69: byteOutputStream.writeTo(out);
70: out.flush();
71:
72: ManagedServiceContext mngCtx = (ManagedServiceContext) getEnvironment()
73: .getEntry(ManagedServiceContext.class);
74: mngCtx.close(mngCtx.getCurrentId());
75: }
76:
77: public Object getResult() {
78: return value;
79: }
80:
81: public void setResult(Object returnValue) {
82: this.value = returnValue.toString();
83: }
84: }
|