KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > markup > xsp > XSPSessionFwHelper


1 /*
2  * Copyright 1999-2002,2004 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.components.language.markup.xsp;
17
18 import org.apache.avalon.framework.component.Component;
19 import org.apache.avalon.framework.component.ComponentManager;
20 import org.apache.avalon.framework.component.ComponentException;
21
22 import org.apache.cocoon.ProcessingException;
23
24 import org.apache.cocoon.webapps.session.SessionManager;
25
26 import org.w3c.dom.DocumentFragment JavaDoc;
27
28 /**
29  * The <code>Session-fw</code> object helper
30  *
31  * @author <a HREF="mailto:antonio@apache.org">Antonio Gallardo</a>
32  * @version CVS $Id: XSPSessionFwHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  * @since 2.1.1
34  */

35 public class XSPSessionFwHelper {
36
37     /** GetXML Fragment from the given session context and path
38      *
39      *
40      * @param cm The ComponentManager
41      * @param context The Session context tha define where to search
42      * @param path The parameter path
43     **/

44     public static DocumentFragment JavaDoc getXML(ComponentManager cm, String JavaDoc context, String JavaDoc path) throws ProcessingException {
45
46         SessionManager sessionManager = null;
47         try {
48             // Start looking up the manager
49
sessionManager = (SessionManager)cm.lookup(SessionManager.ROLE);
50             // Get the fragment
51
DocumentFragment JavaDoc df = sessionManager.getContextFragment(context, path);
52             return df;
53         } catch (ComponentException ce) {
54             throw new ProcessingException("Error during lookup of SessionManager component.", ce);
55         } finally {
56             // End releasing the sessionmanager
57
cm.release((Component)sessionManager);
58         }
59      }
60     
61     /** GetXML Fragment from the given session context and path
62      *
63      *
64      * @param cm The ComponentManager
65      * @param context The Session context tha define where to search
66      * @param path The parameter path
67      **/

68     public static String JavaDoc getXMLAsString(ComponentManager cm, String JavaDoc context, String JavaDoc path) throws ProcessingException {
69         DocumentFragment JavaDoc df = getXML(cm, context, path);
70         return df != null ? df.getFirstChild().getNodeValue() : "";
71     }
72 }
73
74
Popular Tags