1 20 21 27 28 package com.sun.org.apache.xerces.internal.impl; 29 30 import java.util.HashMap ; 31 import javax.xml.stream.XMLInputFactory; 32 import javax.xml.stream.XMLOutputFactory; 33 import javax.xml.stream.XMLResolver; 34 35 import com.sun.xml.internal.stream.StaxEntityResolverWrapper; 36 37 46 47 public class PropertyManager { 48 49 50 protected static final String STAX_NOTATIONS = "javax.xml.stream.notations"; 51 protected static final String STAX_ENTITIES = "javax.xml.stream.entities"; 52 53 private static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning"; 54 55 56 HashMap supportedProps = new HashMap (); 57 58 public static final int CONTEXT_READER = 1; 59 public static final int CONTEXT_WRITER = 2; 60 61 62 public PropertyManager(int context) { 63 switch(context){ 64 case CONTEXT_READER:{ 65 initConfigurableReaderProperties(); 66 break; 67 } 68 case CONTEXT_WRITER:{ 69 initWriterProps(); 70 break; 71 } 72 } 73 } 74 75 78 public PropertyManager(PropertyManager propertyManager){ 79 80 HashMap properties = propertyManager.getProperties(); 81 supportedProps.putAll(properties); 82 } 83 84 private HashMap getProperties(){ 85 return supportedProps ; 86 } 87 88 89 95 private void initConfigurableReaderProperties(){ 96 supportedProps.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); 98 supportedProps.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); 99 supportedProps.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); 100 supportedProps.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); 101 supportedProps.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE); 102 supportedProps.put(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE); 103 supportedProps.put(XMLInputFactory.REPORTER, null); 104 supportedProps.put(XMLInputFactory.RESOLVER, null); 105 supportedProps.put(XMLInputFactory.ALLOCATOR, null); 106 supportedProps.put(STAX_NOTATIONS,null ); 107 108 supportedProps.put(Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE , new Boolean (true)); 111 supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE, new Boolean (true)) ; 113 supportedProps.put(Constants.ADD_NAMESPACE_DECL_AS_ATTRIBUTE , Boolean.FALSE) ; 115 supportedProps.put(Constants.READER_IN_DEFINED_STATE, new Boolean (true)); 116 supportedProps.put(Constants.REUSE_INSTANCE, new Boolean (true)); 117 supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT , new Boolean (false)); 118 supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, new Boolean (false)); 119 supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, new Boolean (false)); 120 supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, new Boolean (false)); 121 } 122 123 private void initWriterProps(){ 124 supportedProps.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE); 125 supportedProps.put(Constants.ESCAPE_CHARACTERS , Boolean.TRUE); 127 supportedProps.put(Constants.REUSE_INSTANCE, new Boolean (true)); 128 } 129 130 135 public boolean containsProperty(String property){ 136 return supportedProps.containsKey(property) ; 137 } 138 139 public Object getProperty(String property){ 140 return supportedProps.get(property); 141 } 142 143 public void setProperty(String property, Object value){ 144 String equivalentProperty = null ; 145 if(property == XMLInputFactory.IS_NAMESPACE_AWARE || property.equals(XMLInputFactory.IS_NAMESPACE_AWARE)){ 146 equivalentProperty = Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE ; 147 } 148 else if(property == XMLInputFactory.IS_VALIDATING || property.equals(XMLInputFactory.IS_VALIDATING)){ 149 if( (value instanceof Boolean ) && ((Boolean )value).booleanValue()){ 150 throw new java.lang.IllegalArgumentException ("true value of isValidating not supported") ; 151 } 152 } 153 else if(property == STRING_INTERNING || property.equals(STRING_INTERNING)){ 154 if( (value instanceof Boolean ) && !((Boolean )value).booleanValue()){ 155 throw new java.lang.IllegalArgumentException ("false value of " + STRING_INTERNING + "feature is not supported") ; 156 } 157 } 158 else if(property == XMLInputFactory.RESOLVER || property.equals(XMLInputFactory.RESOLVER)){ 159 supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ; 161 } 162 supportedProps.put(property, value ) ; 163 if(equivalentProperty != null){ 164 supportedProps.put(equivalentProperty, value ) ; 165 } 166 } 167 168 public String toString(){ 169 return supportedProps.toString(); 170 } 171 172 } | Popular Tags |