Java Code Examples for com.sun.org.apache.xerces.internal.utils.ObjectFactory#findProviderClass()

The following examples show how to use com.sun.org.apache.xerces.internal.utils.ObjectFactory#findProviderClass() . 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: CoreDOMImplementationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * DOM Level 3 WD - Experimental.
 */
public Object getFeature(String feature, String version) {
    if (singleton.hasFeature(feature, version)) {
        if ((feature.equalsIgnoreCase("+XPath"))) {
            try {
                Class xpathClass = ObjectFactory.findProviderClass(
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
                // Check if the DOM XPath implementation implements
                // the interface org.w3c.dom.XPathEvaluator
                Class interfaces[] = xpathClass.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                        return xpathClass.newInstance();
                    }
                }
            } catch (Exception e) {
                return null;
            }
        } else {
            return singleton;
        }
    }
    return null;
}
 
Example 2
Source File: CoreDOMImplementationImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * DOM Level 3 WD - Experimental.
 */
public Object getFeature(String feature, String version) {
    if (singleton.hasFeature(feature, version)) {
        if ((feature.equalsIgnoreCase("+XPath"))) {
            try {
                Class xpathClass = ObjectFactory.findProviderClass(
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
                // Check if the DOM XPath implementation implements
                // the interface org.w3c.dom.XPathEvaluator
                Class interfaces[] = xpathClass.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                        return xpathClass.newInstance();
                    }
                }
            } catch (Exception e) {
                return null;
            }
        } else {
            return singleton;
        }
    }
    return null;
}
 
Example 3
Source File: CoreDOMImplementationImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * DOM Level 3 WD - Experimental.
 */
public Object getFeature(String feature, String version) {
    if (singleton.hasFeature(feature, version)) {
        if ((feature.equalsIgnoreCase("+XPath"))) {
            try {
                Class xpathClass = ObjectFactory.findProviderClass(
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
                // Check if the DOM XPath implementation implements
                // the interface org.w3c.dom.XPathEvaluator
                Class interfaces[] = xpathClass.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                        return xpathClass.newInstance();
                    }
                }
            } catch (Exception e) {
                return null;
            }
        } else {
            return singleton;
        }
    }
    return null;
}
 
Example 4
Source File: CoreDOMImplementationImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * DOM Level 3 WD - Experimental.
 */
public Object getFeature(String feature, String version) {
    if (singleton.hasFeature(feature, version)) {
        if ((feature.equalsIgnoreCase("+XPath"))) {
            try {
                Class xpathClass = ObjectFactory.findProviderClass(
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
                // Check if the DOM XPath implementation implements
                // the interface org.w3c.dom.XPathEvaluator
                Class interfaces[] = xpathClass.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                        return xpathClass.newInstance();
                    }
                }
            } catch (Exception e) {
                return null;
            }
        } else {
            return singleton;
        }
    }
    return null;
}
 
Example 5
Source File: AbstractDOMParser.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class<?> _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 6
Source File: AbstractDOMParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 7
Source File: AbstractDOMParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 8
Source File: AbstractDOMParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 9
Source File: AbstractDOMParser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 10
Source File: AbstractDOMParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 11
Source File: AbstractDOMParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method allows the programmer to decide which document
 * factory to use when constructing the DOM tree. However, doing
 * so will lose the functionality of the default factory. Also,
 * a document class other than the default will lose the ability
 * to defer node expansion on the DOM tree produced.
 *
 * @param documentClassName The fully qualified class name of the
 *                      document factory to use when constructing
 *                      the DOM tree.
 *
 * @see #getDocumentClassName
 * @see #DEFAULT_DOCUMENT_CLASS_NAME
 */
protected void setDocumentClassName (String documentClassName) {

    // normalize class name
    if (documentClassName == null) {
        documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
    }

    if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
        !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
        // verify that this class exists and is of the right type
        try {
            Class _class = ObjectFactory.findProviderClass (documentClassName, true);
            //if (!_class.isAssignableFrom(Document.class)) {
            if (!Document.class.isAssignableFrom (_class)) {
                throw new IllegalArgumentException (
                    DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "InvalidDocumentClassName", new Object [] {documentClassName}));
            }
        }
        catch (ClassNotFoundException e) {
            throw new IllegalArgumentException (
                DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "MissingDocumentClassName", new Object [] {documentClassName}));
        }
    }

    // set document class name
    fDocumentClassName = documentClassName;
    if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
        fDeferNodeExpansion = false;
    }

}
 
Example 12
Source File: CoreDocumentImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since DOM Level 3
 */
public Object getFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are
    // considered.
    if ((feature.equalsIgnoreCase("+XPath"))
            && (anyVersion || version.equals("3.0"))) {

        // If an XPathEvaluator was created previously
        // return it otherwise create a new one.
        if (fXPathEvaluator != null) {
            return fXPathEvaluator;
        }

        try {
            Class xpathClass = ObjectFactory.findProviderClass (
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
            Constructor xpathClassConstr =
                xpathClass.getConstructor(new Class[] { Document.class });

            // Check if the DOM XPath implementation implements
            // the interface org.w3c.dom.XPathEvaluator
            Class interfaces[] = xpathClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                    fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
                    return fXPathEvaluator;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }
    return super.getFeature(feature, version);
}
 
Example 13
Source File: CoreDOMImplementationImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test if the DOM implementation supports a specific "feature" --
 * currently meaning language and level thereof.
 *
 * @param feature The package name of the feature to test.
 * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
 * At this writing, com.sun.org.apache.xerces.internal.dom supports only XML.
 *
 * @param version The version number of the feature being tested.
 * This is interpreted as "Version of the DOM API supported for the
 * specified Feature", and in Level 1 should be "1.0"
 *
 * @return true iff this implementation is compatable with the specified
 * feature and version.
 */
public boolean hasFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // check if Xalan implementation is around and if yes report true for supporting
    // XPath API
    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are considered.
    if ((feature.equalsIgnoreCase("+XPath"))
        && (anyVersion || version.equals("3.0"))) {
        try {
            Class xpathClass = ObjectFactory.findProviderClass(
                "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);

        // Check if the DOM XPath implementation implements
        // the interface org.w3c.dom.XPathEvaluator
        Class interfaces[] = xpathClass.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            if (interfaces[i].getName().equals(
                "org.w3c.dom.xpath.XPathEvaluator")) {
                return true;
            }
        }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
    if (feature.startsWith("+")) {
        feature = feature.substring(1);
    }
    return (
        feature.equalsIgnoreCase("Core")
            && (anyVersion
                || version.equals("1.0")
                || version.equals("2.0")
                || version.equals("3.0")))
                || (feature.equalsIgnoreCase("XML")
            && (anyVersion
                || version.equals("1.0")
                || version.equals("2.0")
                || version.equals("3.0")))
                || (feature.equalsIgnoreCase("LS")
            && (anyVersion || version.equals("3.0")));
}
 
Example 14
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since DOM Level 3
 */
public Object getFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are
    // considered.
    if ((feature.equalsIgnoreCase("+XPath"))
        && (anyVersion || version.equals("3.0"))) {

        // If an XPathEvaluator was created previously
        // return it otherwise create a new one.
        if (fXPathEvaluator != null) {
            return fXPathEvaluator;
        }

        try {
            Class xpathClass = ObjectFactory.findProviderClass (
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
            Constructor xpathClassConstr =
                xpathClass.getConstructor(new Class[] { Document.class });

            // Check if the DOM XPath implementation implements
            // the interface org.w3c.dom.XPathEvaluator
            Class interfaces[] = xpathClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].getName().equals(
                "org.w3c.dom.xpath.XPathEvaluator")) {
                    fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
                    return fXPathEvaluator;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }
    return super.getFeature(feature, version);
}
 
Example 15
Source File: CoreDocumentImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * @since DOM Level 3
 */
public Object getFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are
    // considered.
    if ((feature.equalsIgnoreCase("+XPath"))
            && (anyVersion || version.equals("3.0"))) {

        // If an XPathEvaluator was created previously
        // return it otherwise create a new one.
        if (fXPathEvaluator != null) {
            return fXPathEvaluator;
        }

        try {
            Class xpathClass = ObjectFactory.findProviderClass (
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
            Constructor xpathClassConstr =
                xpathClass.getConstructor(new Class[] { Document.class });

            // Check if the DOM XPath implementation implements
            // the interface org.w3c.dom.XPathEvaluator
            Class interfaces[] = xpathClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                    fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
                    return fXPathEvaluator;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }
    return super.getFeature(feature, version);
}
 
Example 16
Source File: CoreDOMImplementationImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Test if the DOM implementation supports a specific "feature" --
 * currently meaning language and level thereof.
 *
 * @param feature The package name of the feature to test.
 * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
 * At this writing, com.sun.org.apache.xerces.internal.dom supports only XML.
 *
 * @param version The version number of the feature being tested.
 * This is interpreted as "Version of the DOM API supported for the
 * specified Feature", and in Level 1 should be "1.0"
 *
 * @return true iff this implementation is compatable with the specified
 * feature and version.
 */
public boolean hasFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // check if Xalan implementation is around and if yes report true for supporting
    // XPath API
    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are considered.
    if ((feature.equalsIgnoreCase("+XPath"))
        && (anyVersion || version.equals("3.0"))) {
        try {
            Class xpathClass = ObjectFactory.findProviderClass(
                "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);

        // Check if the DOM XPath implementation implements
        // the interface org.w3c.dom.XPathEvaluator
        Class interfaces[] = xpathClass.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            if (interfaces[i].getName().equals(
                "org.w3c.dom.xpath.XPathEvaluator")) {
                return true;
            }
        }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
    if (feature.startsWith("+")) {
        feature = feature.substring(1);
    }
    return (
        feature.equalsIgnoreCase("Core")
            && (anyVersion
                || version.equals("1.0")
                || version.equals("2.0")
                || version.equals("3.0")))
                || (feature.equalsIgnoreCase("XML")
            && (anyVersion
                || version.equals("1.0")
                || version.equals("2.0")
                || version.equals("3.0")))
                || (feature.equalsIgnoreCase("LS")
            && (anyVersion || version.equals("3.0")));
}
 
Example 17
Source File: CoreDocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since DOM Level 3
 */
public Object getFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are
    // considered.
    if ((feature.equalsIgnoreCase("+XPath"))
            && (anyVersion || version.equals("3.0"))) {

        // If an XPathEvaluator was created previously
        // return it otherwise create a new one.
        if (fXPathEvaluator != null) {
            return fXPathEvaluator;
        }

        try {
            Class xpathClass = ObjectFactory.findProviderClass (
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
            Constructor xpathClassConstr =
                xpathClass.getConstructor(new Class[] { Document.class });

            // Check if the DOM XPath implementation implements
            // the interface org.w3c.dom.XPathEvaluator
            Class interfaces[] = xpathClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                    fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
                    return fXPathEvaluator;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }
    return super.getFeature(feature, version);
}
 
Example 18
Source File: CoreDocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since DOM Level 3
 */
public Object getFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are
    // considered.
    if ((feature.equalsIgnoreCase("+XPath"))
            && (anyVersion || version.equals("3.0"))) {

        // If an XPathEvaluator was created previously
        // return it otherwise create a new one.
        if (fXPathEvaluator != null) {
            return fXPathEvaluator;
        }

        try {
            Class xpathClass = ObjectFactory.findProviderClass (
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
            Constructor xpathClassConstr =
                xpathClass.getConstructor(new Class[] { Document.class });

            // Check if the DOM XPath implementation implements
            // the interface org.w3c.dom.XPathEvaluator
            Class interfaces[] = xpathClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                    fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
                    return fXPathEvaluator;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }
    return super.getFeature(feature, version);
}
 
Example 19
Source File: CoreDocumentImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since DOM Level 3
 */
public Object getFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are
    // considered.
    if ((feature.equalsIgnoreCase("+XPath"))
            && (anyVersion || version.equals("3.0"))) {

        // If an XPathEvaluator was created previously
        // return it otherwise create a new one.
        if (fXPathEvaluator != null) {
            return fXPathEvaluator;
        }

        try {
            Class xpathClass = ObjectFactory.findProviderClass (
                    "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
            Constructor xpathClassConstr =
                xpathClass.getConstructor(new Class[] { Document.class });

            // Check if the DOM XPath implementation implements
            // the interface org.w3c.dom.XPathEvaluator
            Class interfaces[] = xpathClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                if (interfaces[i].getName().equals(
                        "org.w3c.dom.xpath.XPathEvaluator")) {
                    fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
                    return fXPathEvaluator;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }
    return super.getFeature(feature, version);
}
 
Example 20
Source File: CoreDOMImplementationImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test if the DOM implementation supports a specific "feature" --
 * currently meaning language and level thereof.
 *
 * @param feature The package name of the feature to test.
 * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
 * At this writing, com.sun.org.apache.xerces.internal.dom supports only XML.
 *
 * @param version The version number of the feature being tested.
 * This is interpreted as "Version of the DOM API supported for the
 * specified Feature", and in Level 1 should be "1.0"
 *
 * @return true iff this implementation is compatable with the specified
 * feature and version.
 */
public boolean hasFeature(String feature, String version) {

    boolean anyVersion = version == null || version.length() == 0;

    // check if Xalan implementation is around and if yes report true for supporting
    // XPath API
    // if a plus sign "+" is prepended to any feature name, implementations
    // are considered in which the specified feature may not be directly
    // castable DOMImplementation.getFeature(feature, version). Without a
    // plus, only features whose interfaces are directly castable are considered.
    if ((feature.equalsIgnoreCase("+XPath"))
        && (anyVersion || version.equals("3.0"))) {
        try {
            Class xpathClass = ObjectFactory.findProviderClass(
                "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);

        // Check if the DOM XPath implementation implements
        // the interface org.w3c.dom.XPathEvaluator
        Class interfaces[] = xpathClass.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            if (interfaces[i].getName().equals(
                "org.w3c.dom.xpath.XPathEvaluator")) {
                return true;
            }
        }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
    if (feature.startsWith("+")) {
        feature = feature.substring(1);
    }
    return (
        feature.equalsIgnoreCase("Core")
            && (anyVersion
                || version.equals("1.0")
                || version.equals("2.0")
                || version.equals("3.0")))
                || (feature.equalsIgnoreCase("XML")
            && (anyVersion
                || version.equals("1.0")
                || version.equals("2.0")
                || version.equals("3.0")))
                || (feature.equalsIgnoreCase("LS")
            && (anyVersion || version.equals("3.0")));
}