com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager.State Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager.State. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentBuilderImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #2
Source File: DocumentBuilderImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #3
Source File: DocumentBuilderImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes(Hashtable dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    Iterator entries = dbfAttrs.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        String name = (String) entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, ((Boolean)val).booleanValue());
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #4
Source File: DocumentBuilderImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #5
Source File: DocumentBuilderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #6
Source File: DocumentBuilderImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #7
Source File: DocumentBuilderImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #8
Source File: DocumentBuilderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #9
Source File: DocumentBuilderImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes( Map<String, Object> dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    for (Map.Entry<String, Object> entry : dbfAttrs.entrySet()) {
        String name = entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, (Boolean)val);
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #10
Source File: DocumentBuilderImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes(Hashtable dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    Iterator entries = dbfAttrs.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        String name = (String) entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, ((Boolean)val).booleanValue());
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example #11
Source File: DocumentBuilderImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes(Hashtable dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    Iterator entries = dbfAttrs.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        String name = (String) entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, ((Boolean)val).booleanValue());
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}