src/com/sun/org/apache/xerces/internal/impl/PropertyManager.java

Print this page




  70     public PropertyManager(int context) {
  71         switch(context){
  72             case CONTEXT_READER:{
  73                 initConfigurableReaderProperties();
  74                 break;
  75             }
  76             case CONTEXT_WRITER:{
  77                 initWriterProps();
  78                 break;
  79             }
  80         }
  81     }
  82 
  83     /**
  84      * Initialize this object with the properties taken from passed PropertyManager object.
  85      */
  86     public PropertyManager(PropertyManager propertyManager){
  87 
  88         HashMap properties = propertyManager.getProperties();
  89         supportedProps.putAll(properties);
  90         fSecurityManager = (XMLSecurityManager)getProperty(SECURITY_MANAGER);
  91         fSecurityPropertyMgr = (XMLSecurityPropertyManager)getProperty(XML_SECURITY_PROPERTY_MANAGER);



  92     }







  93 
  94     private HashMap getProperties(){
  95         return supportedProps ;
  96     }
  97 
  98 
  99     /**
 100      * Important point:
 101      * 1. We are not exposing Xerces namespace property. Application should configure namespace through
 102      * Stax specific property.
 103      *
 104      */
 105     private void initConfigurableReaderProperties(){
 106         //spec default values
 107         supportedProps.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
 108         supportedProps.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
 109         supportedProps.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
 110         supportedProps.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
 111         supportedProps.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
 112         supportedProps.put(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE);


 165         }
 166         else if(property == XMLInputFactory.IS_VALIDATING || property.equals(XMLInputFactory.IS_VALIDATING)){
 167             if( (value instanceof Boolean) && ((Boolean)value).booleanValue()){
 168                 throw new java.lang.IllegalArgumentException("true value of isValidating not supported") ;
 169             }
 170         }
 171         else if(property == STRING_INTERNING || property.equals(STRING_INTERNING)){
 172             if( (value instanceof Boolean) && !((Boolean)value).booleanValue()){
 173                 throw new java.lang.IllegalArgumentException("false value of " + STRING_INTERNING + "feature is not supported") ;
 174             }
 175         }
 176         else if(property == XMLInputFactory.RESOLVER || property.equals(XMLInputFactory.RESOLVER)){
 177             //add internal stax property
 178             supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ;
 179         }
 180 
 181         /**
 182          * It's possible for users to set a security manager through the interface.
 183          * If it's the old SecurityManager, convert it to the new XMLSecurityManager
 184          */
 185         if (property.equals(Constants.SECURITY_MANAGER)) {
 186             fSecurityManager = XMLSecurityManager.convert(value, fSecurityManager);
 187             supportedProps.put(Constants.SECURITY_MANAGER, fSecurityManager);
 188             return;
 189         }
 190         if (property.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) {
 191             if (value == null) {
 192                 fSecurityPropertyMgr = new XMLSecurityPropertyManager();
 193             } else {
 194                 fSecurityPropertyMgr = (XMLSecurityPropertyManager)value;
 195             }
 196             supportedProps.put(Constants.XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
 197             return;
 198         }
 199 
 200         //check if the property is managed by security manager
 201         if (fSecurityManager == null ||
 202                 !fSecurityManager.setLimit(property, XMLSecurityManager.State.APIPROPERTY, value)) {
 203             //check if the property is managed by security property manager
 204             if (fSecurityPropertyMgr == null ||
 205                     !fSecurityPropertyMgr.setValue(property, XMLSecurityPropertyManager.State.APIPROPERTY, value)) {
 206                 //fall back to the existing property manager
 207                 supportedProps.put(property, value);
 208             }
 209         }
 210 
 211         if(equivalentProperty != null){
 212             supportedProps.put(equivalentProperty, value ) ;
 213         }
 214     }
 215 
 216     public String toString(){


  70     public PropertyManager(int context) {
  71         switch(context){
  72             case CONTEXT_READER:{
  73                 initConfigurableReaderProperties();
  74                 break;
  75             }
  76             case CONTEXT_WRITER:{
  77                 initWriterProps();
  78                 break;
  79             }
  80         }
  81     }
  82 
  83     /**
  84      * Initialize this object with the properties taken from passed PropertyManager object.
  85      */
  86     public PropertyManager(PropertyManager propertyManager){
  87 
  88         HashMap properties = propertyManager.getProperties();
  89         supportedProps.putAll(properties);
  90         Object temp = getProperty(SECURITY_MANAGER);
  91         //writers have no need for the managers
  92         if (temp != null) {        
  93             fSecurityManager = new XMLSecurityManager((XMLSecurityManager)temp);
  94             supportedProps.put(SECURITY_MANAGER, fSecurityManager);
  95         }
  96         temp = getProperty(XML_SECURITY_PROPERTY_MANAGER);
  97         if (temp != null) {
  98             fSecurityPropertyMgr = new XMLSecurityPropertyManager(
  99                     (XMLSecurityPropertyManager)temp);
 100             supportedProps.put(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);    
 101         }
 102     }
 103 
 104     private HashMap getProperties(){
 105         return supportedProps ;
 106     }
 107 
 108 
 109     /**
 110      * Important point:
 111      * 1. We are not exposing Xerces namespace property. Application should configure namespace through
 112      * Stax specific property.
 113      *
 114      */
 115     private void initConfigurableReaderProperties(){
 116         //spec default values
 117         supportedProps.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
 118         supportedProps.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
 119         supportedProps.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
 120         supportedProps.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
 121         supportedProps.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
 122         supportedProps.put(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE);


 175         }
 176         else if(property == XMLInputFactory.IS_VALIDATING || property.equals(XMLInputFactory.IS_VALIDATING)){
 177             if( (value instanceof Boolean) && ((Boolean)value).booleanValue()){
 178                 throw new java.lang.IllegalArgumentException("true value of isValidating not supported") ;
 179             }
 180         }
 181         else if(property == STRING_INTERNING || property.equals(STRING_INTERNING)){
 182             if( (value instanceof Boolean) && !((Boolean)value).booleanValue()){
 183                 throw new java.lang.IllegalArgumentException("false value of " + STRING_INTERNING + "feature is not supported") ;
 184             }
 185         }
 186         else if(property == XMLInputFactory.RESOLVER || property.equals(XMLInputFactory.RESOLVER)){
 187             //add internal stax property
 188             supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ;
 189         }
 190 
 191         /**
 192          * It's possible for users to set a security manager through the interface.
 193          * If it's the old SecurityManager, convert it to the new XMLSecurityManager
 194          */
 195         if (property.equals(SECURITY_MANAGER)) {
 196             fSecurityManager = XMLSecurityManager.convert(value, fSecurityManager);
 197             supportedProps.put(SECURITY_MANAGER, fSecurityManager);
 198             return;
 199         }
 200         if (property.equals(XML_SECURITY_PROPERTY_MANAGER)) {
 201             if (value == null) {
 202                 fSecurityPropertyMgr = new XMLSecurityPropertyManager();
 203             } else {
 204                 fSecurityPropertyMgr = (XMLSecurityPropertyManager)value;
 205             }
 206             supportedProps.put(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
 207             return;
 208         }
 209 
 210         //check if the property is managed by security manager
 211         if (fSecurityManager == null ||
 212                 !fSecurityManager.setLimit(property, XMLSecurityManager.State.APIPROPERTY, value)) {
 213             //check if the property is managed by security property manager
 214             if (fSecurityPropertyMgr == null ||
 215                     !fSecurityPropertyMgr.setValue(property, XMLSecurityPropertyManager.State.APIPROPERTY, value)) {
 216                 //fall back to the existing property manager
 217                 supportedProps.put(property, value);
 218             }
 219         }
 220 
 221         if(equivalentProperty != null){
 222             supportedProps.put(equivalentProperty, value ) ;
 223         }
 224     }
 225 
 226     public String toString(){