1 40 41 package org.dspace.content.packager; 42 43 import java.util.Enumeration ; 44 import java.util.Properties ; 45 46 import javax.servlet.ServletRequest ; 47 48 59 60 public class PackageParameters extends Properties 61 { 62 private static final String SEPARATOR = "\034"; 64 65 private static final String SEPARATOR_REGEX = "\\034"; 67 68 public PackageParameters() 69 { 70 super(); 71 } 72 73 public PackageParameters(Properties defaults) 74 { 75 super(defaults); 76 } 77 78 85 public static PackageParameters create(ServletRequest request) 86 { 87 PackageParameters result = new PackageParameters(); 88 89 Enumeration pe = request.getParameterNames(); 90 while (pe.hasMoreElements()) 91 { 92 String name = (String )pe.nextElement(); 93 String v[] = request.getParameterValues(name); 94 if (v.length == 0) 95 result.setProperty(name, ""); 96 else if (v.length == 1) 97 result.setProperty(name, v[0]); 98 else 99 { 100 StringBuffer sb = new StringBuffer (); 101 for (int i = 0; i < v.length; ++i) 102 { 103 if (i > 0) 104 sb.append(SEPARATOR); 105 sb.append(v[i]); 106 } 107 result.setProperty(name, sb.toString()); 108 } 109 } 110 return result; 111 } 112 113 114 123 public Object addProperty(String key, String value) 124 { 125 String oldVal = getProperty(key); 126 if (oldVal == null) 127 setProperty(key, value); 128 else 129 setProperty(key, oldVal + SEPARATOR + value); 130 return oldVal; 131 } 132 133 139 public String [] getProperties(String key) 140 { 141 String val = getProperty(key); 142 if (val == null) 143 return null; 144 else 145 return val.split(SEPARATOR_REGEX); 146 } 147 148 155 public boolean getBooleanProperty(String key, boolean defaultAnswer) 156 { 157 String stringValue = getProperty(key); 158 159 if (stringValue == null) 160 return defaultAnswer; 161 else 162 return stringValue.equalsIgnoreCase("true") || 163 stringValue.equalsIgnoreCase("on") || 164 stringValue.equalsIgnoreCase("yes"); 165 } 166 } 167 | Popular Tags |