KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > ajax > GetContinuationAction


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.apache.cocoon.ajax;
17
18 import java.util.Collections JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.activity.Disposable;
22 import org.apache.avalon.framework.parameters.Parameters;
23 import org.apache.avalon.framework.service.ServiceException;
24 import org.apache.avalon.framework.service.ServiceManager;
25 import org.apache.avalon.framework.thread.ThreadSafe;
26 import org.apache.cocoon.acting.ServiceableAction;
27 import org.apache.cocoon.components.flow.ContinuationsManager;
28 import org.apache.cocoon.components.flow.FlowHelper;
29 import org.apache.cocoon.components.flow.WebContinuation;
30 import org.apache.cocoon.environment.ObjectModelHelper;
31 import org.apache.cocoon.environment.Redirector;
32 import org.apache.cocoon.environment.SourceResolver;
33 import org.apache.cocoon.sitemap.SitemapParameters;
34
35 /**
36  * Get a continuation knowing its identifier, and set it as the current continuation
37  * in the object model, in the same manner as <code>cocoon.sendPageAndWait()</code> does.
38  * This action is useful when an Ajax request is made that needs to access data related
39  * to the continuation that originally displayed the current page.
40  * <p>
41  * The continuation id is either the <code>src</code> attribute in <code>&lt;map:act&gt;</code>
42  * or, if not specified, the <code>continuation-id</code> request parameter.
43  * <p>
44  * This action is successful if the continuation exists and is still valid.
45  *
46  * @since 2.1.8
47  * @version $Id: GetContinuationAction.java 326838 2005-10-20 06:26:53Z sylvain $
48  */

49 public class GetContinuationAction extends ServiceableAction implements ThreadSafe, Disposable {
50     ContinuationsManager contManager;
51
52     public void service(ServiceManager manager) throws ServiceException {
53         super.service(manager);
54         this.contManager = (ContinuationsManager)manager.lookup(ContinuationsManager.ROLE);
55     }
56
57     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc source, Parameters parameters) throws Exception JavaDoc {
58         String JavaDoc continuationId;
59         if (source == null) {
60             continuationId = ObjectModelHelper.getRequest(objectModel).getParameter("continuation-id");
61         } else {
62             continuationId = source;
63         }
64         
65         // The interpreter id is the sitemap's URI
66
String JavaDoc interpreterId = SitemapParameters.getLocation(parameters).getURI();
67         WebContinuation wk = this.contManager.lookupWebContinuation(continuationId, interpreterId);
68         if (wk == null || wk.disposed()) {
69             return null;
70         } else {
71             // Getting the continuation updates the last access time
72
wk.getContinuation();
73             FlowHelper.setWebContinuation(objectModel, wk);
74             return Collections.EMPTY_MAP;
75         }
76     }
77
78     public void dispose() {
79         this.manager.release(this.contManager);
80     }
81 }
82
Popular Tags