Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JellyUtils |
|
| 1.0;1 |
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 EVENT_INFO_VAR = | |
34 | "latkaEventInfo"; | |
35 | protected static final String EVENT_LISTENER_VAR = | |
36 | "latkaEventListener"; | |
37 | ||
38 | 0 | protected static JellyUtils _utils = new JellyUtils(); |
39 | ||
40 | /** Creates a new instance of SuiteTag */ | |
41 | 0 | public JellyUtils() { |
42 | 0 | } |
43 | ||
44 | public static JellyUtils getInstance() { | |
45 | 0 | 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 | 0 | 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 | 0 | context.setVariable(EVENT_INFO_VAR,info); |
68 | 0 | } |
69 | ||
70 | ||
71 | /** | |
72 | * Remove a LatkaEventInfo object. | |
73 | * | |
74 | * @param context | |
75 | */ | |
76 | public void removeLatkaEventInfo(JellyContext context) { | |
77 | 0 | context.removeVariable(EVENT_INFO_VAR); |
78 | 0 | } |
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 | 0 | 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 | 0 | context.setVariable(EVENT_LISTENER_VAR,listener); |
100 | 0 | } |
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 | 0 | RequestTag requestTag = |
111 | 0 | (RequestTag) TagSupport.findAncestorWithClass(tag.getParent(), RequestTag.class); |
112 | 0 | return requestTag.getRequest(); |
113 | } | |
114 | } |