01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.desktop.taglib.theme;
06:
07: import javax.servlet.jsp.JspException;
08: import java.util.Map;
09: import java.util.HashMap;
10:
11: import com.sun.portal.providers.Provider;
12: import com.sun.portal.providers.context.ProviderContext;
13: import com.sun.portal.providers.context.ProviderContextException;
14: import com.sun.portal.providers.context.Theme;
15:
16: import com.sun.portal.desktop.taglib.DesktopTaglibException;
17: import com.sun.portal.desktop.taglib.DesktopTaglibConstants;
18:
19: public class GetAttributeTag extends BaseThemeTagSupport {
20: boolean mReqOverride = false;
21: String mDefault = null;
22:
23: public void setRequestOverride(String reqOverride)
24: throws JspException {
25: Boolean bReqOverride = new Boolean(reqOverride);
26: mReqOverride = bReqOverride.booleanValue();
27: }
28:
29: public void setDefault(String def) throws JspException {
30: if (def != null && def.length() > 0) {
31: mDefault = (String) resolveParameter(def);
32: }
33: }
34:
35: public int doStartTag() throws JspException {
36: String theme = (mTheme != null) ? mTheme : getSelectedTheme();
37: String result = null;
38:
39: // Request parameter override the actual value, used for preview
40: if (mReqOverride) {
41: result = pageContext.getRequest().getParameter(mName);
42: if (result != null) {
43: processResult(result);
44: return SKIP_BODY;
45: }
46: }
47:
48: Map themeMap = getThemeMap(theme);
49:
50: result = (String) themeMap.get(mName);
51:
52: if (result == null) {
53: result = mDefault;
54: if (result == null) {
55: throw new DesktopTaglibException(
56: "BaseThemeTagSupport.getThemeAttribute(): attribute "
57: + mName + " not defined in " + theme);
58: }
59: }
60:
61: processResult(result);
62: return SKIP_BODY;
63: }
64:
65: private Map getThemeMap(String theme) throws DesktopTaglibException {
66:
67: ProviderContext pc = getCurrentProviderContext();
68: Provider p = getCurrentObj();
69: Map themeMaps = (Map) getCachedObj(_ThemeMap);
70: Map themeMap = null;
71:
72: if (themeMaps == null) {
73: themeMaps = new HashMap();
74: } else {
75: themeMap = (Map) themeMaps.get(theme);
76: }
77:
78: if (themeMap == null) {
79:
80: // the theme map is not in the cache
81:
82: try {
83: themeMap = Theme.getMap(p.getName(), pc, theme);
84: } catch (ProviderContextException pce) {
85: throw new DesktopTaglibException(pce);
86: }
87: themeMaps.put(theme, themeMap);
88: cacheObj(_ThemeMap, themeMaps);
89: }
90: return themeMap;
91: }
92: }
|