01: /*
02: * Created by IntelliJ IDEA.
03: * User: sanjib.ghosh@sun.com
04: * Date: Dec 24, 2001
05: * Time: $TME$
06: */
07: package com.sun.portal.proxylet.servlet;
08:
09: import java.util.*;
10:
11: public class AttributeExtractor {
12:
13: public static String getString(Map source, String name,
14: String defaultValue) {
15: Set set = (Set) source.get(name);
16: if (null == set) {
17: return defaultValue;
18: }
19: Iterator it = set.iterator();
20: return (it.hasNext()) ? (String) it.next() : defaultValue;
21: }
22:
23: public static int getInt(Map source, String name, int defaultValue) {
24: Set set = (Set) source.get(name);
25: if (null == set) {
26: return defaultValue;
27: }
28: Iterator it = set.iterator();
29: return (it.hasNext()) ? Integer.parseInt((String) it.next())
30: : defaultValue;
31: }
32:
33: public static boolean getBoolean(Map source, String name,
34: boolean defaultValue) {
35: Set set = (Set) source.get(name);
36: if (null == set) {
37: return defaultValue;
38: }
39: Iterator it = set.iterator();
40: return (it.hasNext()) ? new Boolean((String) it.next())
41: .booleanValue() : defaultValue;
42: }
43:
44: public static List getStringList(Map source, String name) {
45: Set set = (Set) source.get(name);
46: if (null == set) {
47: return new ArrayList();
48: }
49: List ret = new ArrayList(set.size());
50: for (Iterator it = set.iterator(); it.hasNext();) {
51: ret.add((String) it.next());
52: }
53: return ret;
54: }
55:
56: }
|