1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 import java.util.ArrayList ; 61 import java.util.HashMap ; 62 63 import com.sun.org.apache.xerces.internal.impl.Constants; 64 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 65 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 66 67 82 public class ParserConfigurationSettings 83 implements XMLComponentManager { 84 85 protected static final String PARSER_SETTINGS = 86 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 87 88 92 94 95 protected ArrayList fRecognizedProperties; 96 97 98 protected HashMap fProperties; 99 100 101 protected ArrayList fRecognizedFeatures; 102 103 104 protected HashMap fFeatures; 105 106 107 protected XMLComponentManager fParentSettings; 108 109 113 114 public ParserConfigurationSettings() { 115 this(null); 116 } 118 122 public ParserConfigurationSettings(XMLComponentManager parent) { 123 124 fRecognizedFeatures = new ArrayList (); 126 fRecognizedProperties = new ArrayList (); 127 128 fFeatures = new HashMap (); 130 fProperties = new HashMap (); 131 132 fParentSettings = parent; 134 135 } 137 141 148 public void addRecognizedFeatures(String [] featureIds) { 149 150 int featureIdsCount = featureIds != null ? featureIds.length : 0; 152 for (int i = 0; i < featureIdsCount; i++) { 153 String featureId = featureIds[i]; 154 if (!fRecognizedFeatures.contains(featureId)) { 155 fRecognizedFeatures.add(featureId); 156 } 157 } 158 159 } 161 174 public void setFeature(String featureId, boolean state) 175 throws XMLConfigurationException { 176 177 checkFeature(featureId); 179 180 fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE); 181 } 183 190 public void addRecognizedProperties(String [] propertyIds) { 191 192 int propertyIdsCount = propertyIds != null ? propertyIds.length : 0; 194 for (int i = 0; i < propertyIdsCount; i++) { 195 String propertyId = propertyIds[i]; 196 if (!fRecognizedProperties.contains(propertyId)) { 197 fRecognizedProperties.add(propertyId); 198 } 199 } 200 201 } 203 211 public void setProperty(String propertyId, Object value) 212 throws XMLConfigurationException { 213 214 checkProperty(propertyId); 216 if(value == null){ 217 fProperties.remove(propertyId); 218 }else 219 fProperties.put(propertyId, value); 220 221 } 223 227 239 public boolean getFeature(String featureId) 240 throws XMLConfigurationException { 241 242 Boolean state = (Boolean ) fFeatures.get(featureId); 243 244 if (state == null) { 245 checkFeature(featureId); 246 return false; 247 } 248 return state.booleanValue(); 249 250 } 252 264 public Object getProperty(String propertyId) 265 throws XMLConfigurationException { 266 267 Object propertyValue = fProperties.get(propertyId); 268 269 if (propertyValue == null) { 270 checkProperty(propertyId); 271 } 272 273 return propertyValue; 274 275 } 277 281 290 protected void checkFeature(String featureId) 291 throws XMLConfigurationException { 292 293 if (!fRecognizedFeatures.contains(featureId)) { 295 if (fParentSettings != null) { 296 fParentSettings.getFeature(featureId); 297 } 298 else { 299 short type = XMLConfigurationException.NOT_RECOGNIZED; 300 throw new XMLConfigurationException(type, featureId); 301 } 302 } 303 304 } 306 315 protected void checkProperty(String propertyId) 316 throws XMLConfigurationException { 317 318 if (!fRecognizedProperties.contains(propertyId)) { 320 if (fParentSettings != null) { 321 fParentSettings.getProperty(propertyId); 322 } 323 else { 324 short type = XMLConfigurationException.NOT_RECOGNIZED; 325 throw new XMLConfigurationException(type, propertyId); 326 } 327 } 328 329 } 331 } | Popular Tags |