01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.jsp.util;
16:
17: import java.util.StringTokenizer;
18: import javax.servlet.jsp.PageContext;
19: import org.araneaframework.core.ApplicationWidget;
20: import org.araneaframework.jsp.exception.AraneaJspException;
21: import org.araneaframework.jsp.tag.context.WidgetContextTag;
22:
23: /**
24: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
25: */
26: public abstract class JspWidgetUtil {
27:
28: /**
29: * @since 1.1
30: */
31: public static ApplicationWidget getContextWidget(
32: PageContext pageContext) {
33: return (ApplicationWidget) pageContext.getRequest()
34: .getAttribute(WidgetContextTag.CONTEXT_WIDGET_KEY);
35: }
36:
37: public static String getContextWidgetFullId(PageContext pageContext) {
38: return getContextWidget(pageContext).getScope().toString();
39: }
40:
41: public static ApplicationWidget traverseToSubWidget(
42: ApplicationWidget root, String path)
43: throws AraneaJspException {
44: ApplicationWidget widget = root;
45:
46: if ("".equals(path))
47: throw new AraneaJspException(
48: "Trying to traverse to a widget with an empty path!");
49:
50: // Traverse
51: for (StringTokenizer tokenizer = new StringTokenizer(path, "."); tokenizer
52: .hasMoreElements();) {
53: String token = tokenizer.nextToken();
54:
55: widget = (ApplicationWidget) widget._getComposite()
56: .getChildren().get(token);
57: if (widget == null)
58: throw new AraneaJspException(
59: "Failed to traverse widget with path '" + path
60: + "' because widget '" + token
61: + "' was not found");
62: }
63:
64: // Complete
65: return widget;
66: }
67: }
|