KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > latka > jelly > JellyUtils


1 /*
2  * Copyright 1999-2001,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
17 package org.apache.commons.latka.jelly;
18
19 import org.apache.commons.jelly.JellyContext;
20 import org.apache.commons.jelly.Tag;
21 import org.apache.commons.jelly.TagSupport;
22
23 import org.apache.commons.latka.event.LatkaEventInfo;
24 import org.apache.commons.latka.event.LatkaEventListener;
25 import org.apache.commons.latka.http.Request;
26
27 /**
28  *
29  * @author Morgan Delagrange
30  */

31 public class JellyUtils {
32         
33     protected static final String JavaDoc EVENT_INFO_VAR =
34         "latkaEventInfo";
35     protected static final String JavaDoc EVENT_LISTENER_VAR =
36         "latkaEventListener";
37
38     protected static JellyUtils _utils = new JellyUtils();
39
40     /** Creates a new instance of SuiteTag */
41     public JellyUtils() {
42     }
43
44     public static JellyUtils getInstance() {
45         return _utils;
46     }
47     
48     /**
49      * Return the LatkaEventInfo for the context,
50      * or null if none has been set
51      *
52      * @param context Context for the current Jelly script
53      * @return LatkaEventInfo for the context,
54      * or null if none has been set
55      */

56     public LatkaEventInfo getLatkaEventInfo(JellyContext context) {
57         return (LatkaEventInfo) context.getVariable(EVENT_INFO_VAR);
58     }
59
60     /**
61      * Provide a LatkaEventInfo object.
62      *
63      * @param context
64      * @param listener LatkaEventInfo object
65      */

66     public void setLatkaEventInfo(JellyContext context, LatkaEventInfo info) {
67         context.setVariable(EVENT_INFO_VAR,info);
68     }
69
70
71     /**
72      * Remove a LatkaEventInfo object.
73      *
74      * @param context
75      */

76     public void removeLatkaEventInfo(JellyContext context) {
77         context.removeVariable(EVENT_INFO_VAR);
78     }
79
80     /**
81      * Return the LatkaEventListener for the context,
82      * or null if none has been set
83      *
84      * @param context Context for the current Jelly script
85      * @return LatkaEventListener for the context,
86      * or null if none has been set
87      */

88     public LatkaEventListener getLatkaEventListener(JellyContext context) {
89         return (LatkaEventListener) context.getVariable(EVENT_LISTENER_VAR);
90     }
91
92     /**
93      * Provide a LatkaEventListener object.
94      *
95      * @param context
96      * @param listener LatkaEventListener object
97      */

98     public void setLatkaEventListener(JellyContext context, LatkaEventListener listener) {
99         context.setVariable(EVENT_LISTENER_VAR,listener);
100     }
101
102     /**
103      * Given a tag, find a parent RequestTag and return
104      * its Request object.
105      *
106      * @param tag Child tag of RequestTag
107      * @return Request
108      */

109     public Request findParentRequest(Tag tag) {
110         RequestTag requestTag =
111             (RequestTag) TagSupport.findAncestorWithClass(tag.getParent(), RequestTag.class);
112         return requestTag.getRequest();
113     }
114 }
115
Popular Tags