1 16 17 package org.apache.xerces.util; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 22 import org.apache.xerces.impl.Constants; 23 import org.apache.xerces.xni.parser.XMLComponentManager; 24 import org.apache.xerces.xni.parser.XMLConfigurationException; 25 26 41 public class ParserConfigurationSettings 42 implements XMLComponentManager { 43 44 protected static final String PARSER_SETTINGS = 45 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 46 47 51 53 54 protected ArrayList fRecognizedProperties; 55 56 57 protected HashMap fProperties; 58 59 60 protected ArrayList fRecognizedFeatures; 61 62 63 protected HashMap fFeatures; 64 65 66 protected XMLComponentManager fParentSettings; 67 68 72 73 public ParserConfigurationSettings() { 74 this(null); 75 } 77 81 public ParserConfigurationSettings(XMLComponentManager parent) { 82 83 fRecognizedFeatures = new ArrayList (); 85 fRecognizedProperties = new ArrayList (); 86 87 fFeatures = new HashMap (); 89 fProperties = new HashMap (); 90 91 fParentSettings = parent; 93 94 } 96 100 107 public void addRecognizedFeatures(String [] featureIds) { 108 109 int featureIdsCount = featureIds != null ? featureIds.length : 0; 111 for (int i = 0; i < featureIdsCount; i++) { 112 String featureId = featureIds[i]; 113 if (!fRecognizedFeatures.contains(featureId)) { 114 fRecognizedFeatures.add(featureId); 115 } 116 } 117 118 } 120 133 public void setFeature(String featureId, boolean state) 134 throws XMLConfigurationException { 135 136 checkFeature(featureId); 138 139 fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE); 140 } 142 149 public void addRecognizedProperties(String [] propertyIds) { 150 151 int propertyIdsCount = propertyIds != null ? propertyIds.length : 0; 153 for (int i = 0; i < propertyIdsCount; i++) { 154 String propertyId = propertyIds[i]; 155 if (!fRecognizedProperties.contains(propertyId)) { 156 fRecognizedProperties.add(propertyId); 157 } 158 } 159 160 } 162 170 public void setProperty(String propertyId, Object value) 171 throws XMLConfigurationException { 172 173 checkProperty(propertyId); 175 fProperties.put(propertyId, value); 176 177 } 179 183 195 public boolean getFeature(String featureId) 196 throws XMLConfigurationException { 197 198 Boolean state = (Boolean ) fFeatures.get(featureId); 199 200 if (state == null) { 201 checkFeature(featureId); 202 return false; 203 } 204 return state.booleanValue(); 205 206 } 208 220 public Object getProperty(String propertyId) 221 throws XMLConfigurationException { 222 223 Object propertyValue = fProperties.get(propertyId); 224 225 if (propertyValue == null) { 226 checkProperty(propertyId); 227 } 228 229 return propertyValue; 230 231 } 233 237 246 protected void checkFeature(String featureId) 247 throws XMLConfigurationException { 248 249 if (!fRecognizedFeatures.contains(featureId)) { 251 if (fParentSettings != null) { 252 fParentSettings.getFeature(featureId); 253 } 254 else { 255 short type = XMLConfigurationException.NOT_RECOGNIZED; 256 throw new XMLConfigurationException(type, featureId); 257 } 258 } 259 260 } 262 271 protected void checkProperty(String propertyId) 272 throws XMLConfigurationException { 273 274 if (!fRecognizedProperties.contains(propertyId)) { 276 if (fParentSettings != null) { 277 fParentSettings.getProperty(propertyId); 278 } 279 else { 280 short type = XMLConfigurationException.NOT_RECOGNIZED; 281 throw new XMLConfigurationException(type, propertyId); 282 } 283 } 284 285 } 287 } | Popular Tags |