01: /*
02: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.taskadmin.taglib;
06:
07: import java.io.IOException;
08: import javax.servlet.jsp.tagext.TagSupport;
09: import javax.servlet.jsp.PageContext;
10: import javax.servlet.jsp.tagext.Tag;
11:
12: public class BaseTaskAdminTagSupport extends TagSupport {
13: private static final String VARIABLE_PREFIX = "$";
14: // page context attributes
15: private static final String AMUSER = "AMUser";
16: private static final String USERDN = "UserDN";
17: private static final String NODES = "nodes";
18:
19: protected String mId = null;
20: protected int mScope = PageContext.PAGE_SCOPE;
21:
22: static protected boolean toBoolean(String name) {
23: return ((name != null) && name.toLowerCase().equals("true"));
24: }
25:
26: public void setId(String id) {
27: if (id != null && id.length() > 0)
28: this .mId = id;
29: }
30:
31: public void setScope(String scope) {
32: if (scope != null) {
33: if (scope.equalsIgnoreCase("request")) {
34: mScope = PageContext.REQUEST_SCOPE;
35: } else if (scope.equalsIgnoreCase("session")) {
36: mScope = PageContext.SESSION_SCOPE;
37: } else if (scope.equalsIgnoreCase("application")) {
38: mScope = PageContext.APPLICATION_SCOPE;
39: }
40: }
41: }
42:
43: protected void processResult(Object result)
44: throws TaskAdminTaglibException {
45: if (mId != null) {
46: if (result != null) {
47: pageContext.setAttribute(mId, result, mScope);
48: } else {
49: pageContext.removeAttribute(mId, mScope);
50: }
51: } else {
52: try {
53: pageContext.getOut().print(result);
54: } catch (IOException e) {
55: throw new TaskAdminTaglibException(e);
56: }
57: }
58: }
59:
60: protected boolean isContextVariable(String parameter) {
61: if (parameter != null) {
62: return parameter.startsWith(VARIABLE_PREFIX);
63: } else {
64: return false;
65: }
66: }
67:
68: protected Object resolveParameter(String parameter)
69: throws TaskAdminTaglibException {
70: if (isContextVariable(parameter)) {
71: String var = getVariable(parameter);
72: Object obj = pageContext.findAttribute(var);
73: if (obj == null) {
74: throw new TaskAdminTaglibException(
75: TaskAdminTaglibException.UNDEFINED_PARAMETER,
76: var);
77: }
78: return obj;
79: } else {
80: return parameter;
81: }
82: }
83:
84: protected String getVariable(String parameter) {
85: if (isContextVariable(parameter)) {
86: return parameter.substring(VARIABLE_PREFIX.length());
87: } else {
88: return parameter;
89: }
90: }
91: }
|