01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.flow.javascript;
18:
19: import org.mozilla.javascript.ScriptableObject;
20: import org.mozilla.javascript.Undefined;
21: import org.mozilla.javascript.Wrapper;
22: import org.mozilla.javascript.continuations.Continuation;
23: import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon;
24: import org.apache.cocoon.components.flow.javascript.fom.FOM_WebContinuation;
25: import org.apache.cocoon.environment.Request;
26:
27: /**
28: * cforms flowscript integration helper class.
29: * @version $Id: Form.java 449149 2006-09-23 03:58:05Z crossley $
30: */
31: public class Form extends ScriptableObject {
32: FOM_Cocoon cocoon;
33:
34: public String getClassName() {
35: return "Form";
36: }
37:
38: private FOM_Cocoon getCocoon() {
39: if (cocoon == null) {
40: cocoon = (FOM_Cocoon) getProperty(getTopLevelScope(this ),
41: "cocoon");
42: }
43: return cocoon;
44: }
45:
46: public FOM_WebContinuation jsFunction_makeWebContinuation(Object k,
47: Object lastContinuation, int ttl) throws Exception {
48: Continuation kont = (Continuation) unwrap(k);
49: FOM_WebContinuation fom_wk = (FOM_WebContinuation) unwrap(lastContinuation);
50: FOM_Cocoon cocoon = getCocoon();
51: return cocoon.makeWebContinuation(kont, fom_wk, ttl);
52: }
53:
54: public void jsFunction_forwardTo(String uri, Object bizData,
55: Object continuation) throws Exception {
56: FOM_Cocoon cocoon = getCocoon();
57: FOM_WebContinuation fom_wk = (FOM_WebContinuation) unwrap(continuation);
58: cocoon.forwardTo(uri, unwrap(bizData), fom_wk);
59:
60: }
61:
62: public Request jsGet_request() {
63: FOM_Cocoon cocoon = getCocoon();
64: return cocoon.getRequest();
65: }
66:
67: private Object unwrap(Object obj) {
68: if (obj == Undefined.instance) {
69: return null;
70: }
71: if (obj instanceof Wrapper) {
72: return ((Wrapper) obj).unwrap();
73: }
74: return obj;
75: }
76: }
|