1 16 19 20 package org.apache.pluto.portalImpl.util; 21 22 import java.util.ArrayList ; 23 import java.util.Enumeration ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import javax.servlet.ServletConfig ; 29 import javax.servlet.ServletContext ; 30 31 public class Parameters extends NameValuePairs 32 { 33 34 public Parameters (Map params) 35 { 36 Iterator iterator = params.keySet().iterator(); 37 38 while (iterator.hasNext()) 39 { 40 String name = (String )iterator.next(); 41 42 super.add (name, (String )params.get(name)); 43 } 44 } 45 46 public Parameters (ServletConfig aConfig) 47 { 48 for (Enumeration e = aConfig.getInitParameterNames (); e.hasMoreElements ();) 49 { 50 String name = (String ) e.nextElement (); 51 52 super.add (name, aConfig.getInitParameter (name)); 53 } 54 } 55 56 public Parameters (ServletContext aContext) 57 { 58 for (Enumeration e = aContext.getInitParameterNames (); e.hasMoreElements ();) 59 { 60 String name = (String ) e.nextElement (); 61 62 super.add (name, aContext.getInitParameter (name)); 63 } 64 } 65 66 public void setString(String aKey, String aValue) 67 { 68 if (aKey == null) 69 throw (new IllegalArgumentException ("Parameters: Argument \"aKey\" cannot be null.")); 70 if (aValue == null) 71 throw (new IllegalArgumentException ("Parameters: Argument \"aValue\" cannot be null.")); 72 73 super.add(aKey, aValue); 74 } 75 76 82 83 public void remove (String aName) 84 { 85 super.removeEntry (aName); 86 } 87 88 94 95 public void removeWithPrefix (String aPrefix) 96 { 97 List deletables = new ArrayList (); 98 99 for (Iterator iter = names (); iter.hasNext (); ) 100 { 101 String name = (String ) iter.next (); 102 103 if (name.startsWith (aPrefix)) 104 { 105 deletables.add (name); 106 } 107 } 108 109 for (Iterator iter = deletables.iterator (); iter.hasNext (); ) 110 { 111 super.removeEntry ((String ) iter.next ()); 112 } 113 } 114 } 115 | Popular Tags |