01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.providers.userinfo.tag;
07:
08: import com.sun.portal.providers.context.ProviderContext;
09: import com.sun.portal.providers.context.ProviderContextException;
10: import com.sun.portal.log.common.PortalLogger;
11:
12: import java.util.logging.Level;
13: import java.util.logging.Logger;
14: import java.util.logging.LogRecord;
15:
16: /**
17: * this class provides the mechanism for lazy evaluation of tags.
18: * essentially, it is put into the tag table, but the value for the
19: * tag is not actually fetched until toString() is called.
20: */
21:
22: public class TagModuleElement {
23:
24: private static Logger logger = PortalLogger
25: .getLogger(TagModuleElement.class);
26: private ReadTag tagModule = null;
27: private String key = null;
28: private ProviderContext context = null;
29: private boolean escape = false;
30:
31: public TagModuleElement(ReadTag t, String k, boolean esc,
32: ProviderContext pc) {
33: tagModule = t;
34: key = k;
35: context = pc;
36: escape = esc;
37: }
38:
39: public String toString() {
40: try {
41: String tagVal = tagModule.get(key);
42: //
43: // Do the escaping if necessary
44: //
45: if ((tagVal != null) && (escape)) {
46: try {
47: tagVal = context.escape(tagVal);
48: } catch (ProviderContextException pce) {
49: // Cannot escape for whatever reason. Return null.
50: if (logger.isLoggable(Level.INFO)) {
51: LogRecord record = new LogRecord(Level.INFO,
52: "PSCR_CSPPUIT0001");
53: record.setLoggerName(logger.getName());
54: record.setParameters(new Object[] { key });
55: record.setThrown(pce);
56: logger.log(record);
57: }
58: return null;
59: }
60: }
61: return tagVal;
62: } catch (TagException te) {
63: logger.log(Level.INFO, "PSCR_CSPPUIT0002", te);
64: return null;
65: }
66: }
67: }
|