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.components.language.markup.xsp;
18:
19: import org.apache.avalon.framework.component.Component;
20: import org.apache.avalon.framework.component.ComponentManager;
21: import org.apache.avalon.framework.component.ComponentException;
22:
23: import org.apache.cocoon.ProcessingException;
24:
25: import org.apache.cocoon.webapps.session.SessionManager;
26:
27: import org.w3c.dom.DocumentFragment;
28:
29: /**
30: * The <code>Session-fw</code> object helper
31: *
32: * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
33: * @deprecated This block is deprecated and will be removed in future versions.
34: * @version CVS $Id: XSPSessionFwHelper.java 433543 2006-08-22 06:22:54Z crossley $
35: * @since 2.1.1
36: */
37: public class XSPSessionFwHelper {
38:
39: /** GetXML Fragment from the given session context and path
40: *
41: *
42: * @param cm The ComponentManager
43: * @param context The Session context tha define where to search
44: * @param path The parameter path
45: **/
46: public static DocumentFragment getXML(ComponentManager cm,
47: String context, String path) throws ProcessingException {
48:
49: SessionManager sessionManager = null;
50: try {
51: // Start looking up the manager
52: sessionManager = (SessionManager) cm
53: .lookup(SessionManager.ROLE);
54: // Get the fragment
55: DocumentFragment df = sessionManager.getContextFragment(
56: context, path);
57: return df;
58: } catch (ComponentException ce) {
59: throw new ProcessingException(
60: "Error during lookup of SessionManager component.",
61: ce);
62: } finally {
63: // End releasing the sessionmanager
64: cm.release((Component) sessionManager);
65: }
66: }
67:
68: /** GetXML Fragment from the given session context and path
69: *
70: *
71: * @param cm The ComponentManager
72: * @param context The Session context tha define where to search
73: * @param path The parameter path
74: **/
75: public static String getXMLAsString(ComponentManager cm,
76: String context, String path) throws ProcessingException {
77: DocumentFragment df = getXML(cm, context, path);
78: return df != null ? df.getFirstChild().getNodeValue() : "";
79: }
80: }
|