Java Code Examples for jdk.xml.internal.JdkXmlUtils#getDOMFactory()

The following examples show how to use jdk.xml.internal.JdkXmlUtils#getDOMFactory() . 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: SAX2DOM.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Document createDocument(boolean overrideDefaultParser)
        throws ParserConfigurationException {
    if (_factory == null) {
        _factory = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        _internal = true;
        if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
            _internal = false;
        }
    }
    Document doc;
    if (_internal) {
        //default implementation is thread safe
        doc = _factory.newDocumentBuilder().newDocument();
    } else {
        synchronized(SAX2DOM.class) {
            doc = _factory.newDocumentBuilder().newDocument();
        }
    }
    return doc;
}
 
Example 2
Source File: XPathImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private DocumentBuilder getParser() {
    try {
        // we'd really like to cache those DocumentBuilders, but we can't because:
        // 1. thread safety. parsers are not thread-safe, so at least
        //    we need one instance per a thread.
        // 2. parsers are non-reentrant, so now we are looking at having a
        // pool of parsers.
        // 3. then the class loading issue. The look-up procedure of
        //    DocumentBuilderFactory.newInstance() depends on context class loader
        //    and system properties, which may change during the execution of JVM.
        //
        // so we really have to create a fresh DocumentBuilder every time we need one
        // - KK
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        return dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // this should never happen with a well-behaving JAXP implementation.
        throw new Error(e);
    }
}
 
Example 3
Source File: DTMManagerDefault.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method createDocumentFragment
 *
 *
 * NEEDSDOC (createDocumentFragment) @return
 */
synchronized public DTM createDocumentFragment()
{

  try
  {
    DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(super.overrideDefaultParser());

    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Node df = doc.createDocumentFragment();

    return getDTM(new DOMSource(df), true, null, false, false);
  }
  catch (Exception e)
  {
    throw new DTMException(e);
  }
}
 
Example 4
Source File: XPathImplUtil.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the input source and return a Document.
 * @param source The {@code InputSource} of the document
 * @return a DOM Document
 * @throws XPathExpressionException if there is an error parsing the source.
 */
Document getDocument(InputSource source)
    throws XPathExpressionException {
    requireNonNull(source, "Source");
    try {
        // we'd really like to cache those DocumentBuilders, but we can't because:
        // 1. thread safety. parsers are not thread-safe, so at least
        //    we need one instance per a thread.
        // 2. parsers are non-reentrant, so now we are looking at having a
        // pool of parsers.
        // 3. then the class loading issue. The look-up procedure of
        //    DocumentBuilderFactory.newInstance() depends on context class loader
        //    and system properties, which may change during the execution of JVM.
        //
        // so we really have to create a fresh DocumentBuilder every time we need one
        // - KK
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        return dbf.newDocumentBuilder().parse(source);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new XPathExpressionException (e);
    }
}
 
Example 5
Source File: SAX2DOM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Document createDocument(boolean overrideDefaultParser)
        throws ParserConfigurationException {
    if (_factory == null) {
        _factory = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        _internal = true;
        if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
            _internal = false;
        }
    }
    Document doc;
    if (_internal) {
        //default implementation is thread safe
        doc = _factory.newDocumentBuilder().newDocument();
    } else {
        synchronized(SAX2DOM.class) {
            doc = _factory.newDocumentBuilder().newDocument();
        }
    }
    return doc;
}
 
Example 6
Source File: XPathImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private DocumentBuilder getParser() {
    try {
        // we'd really like to cache those DocumentBuilders, but we can't because:
        // 1. thread safety. parsers are not thread-safe, so at least
        //    we need one instance per a thread.
        // 2. parsers are non-reentrant, so now we are looking at having a
        // pool of parsers.
        // 3. then the class loading issue. The look-up procedure of
        //    DocumentBuilderFactory.newInstance() depends on context class loader
        //    and system properties, which may change during the execution of JVM.
        //
        // so we really have to create a fresh DocumentBuilder every time we need one
        // - KK
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        return dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // this should never happen with a well-behaving JAXP implementation.
        throw new Error(e);
    }
}
 
Example 7
Source File: DTMManagerDefault.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method createDocumentFragment
 *
 *
 * NEEDSDOC (createDocumentFragment) @return
 */
synchronized public DTM createDocumentFragment()
{

  try
  {
    DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(super.overrideDefaultParser());

    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Node df = doc.createDocumentFragment();

    return getDTM(new DOMSource(df), true, null, false, false);
  }
  catch (Exception e)
  {
    throw new DTMException(e);
  }
}
 
Example 8
Source File: SAX2DOM.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Document createDocument(boolean overrideDefaultParser)
        throws ParserConfigurationException {
    if (_factory == null) {
        _factory = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        _internal = true;
        if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
            _internal = false;
        }
    }
    Document doc;
    if (_internal) {
        //default implementation is thread safe
        doc = _factory.newDocumentBuilder().newDocument();
    } else {
        synchronized(SAX2DOM.class) {
            doc = _factory.newDocumentBuilder().newDocument();
        }
    }
    return doc;
}
 
Example 9
Source File: XPathImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private DocumentBuilder getParser() {
    try {
        // we'd really like to cache those DocumentBuilders, but we can't because:
        // 1. thread safety. parsers are not thread-safe, so at least
        //    we need one instance per a thread.
        // 2. parsers are non-reentrant, so now we are looking at having a
        // pool of parsers.
        // 3. then the class loading issue. The look-up procedure of
        //    DocumentBuilderFactory.newInstance() depends on context class loader
        //    and system properties, which may change during the execution of JVM.
        //
        // so we really have to create a fresh DocumentBuilder every time we need one
        // - KK
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        return dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // this should never happen with a well-behaving JAXP implementation.
        throw new Error(e);
    }
}
 
Example 10
Source File: DTMManagerDefault.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Method createDocumentFragment
 *
 *
 * NEEDSDOC (createDocumentFragment) @return
 */
synchronized public DTM createDocumentFragment()
{

  try
  {
    DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(super.overrideDefaultParser());

    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Node df = doc.createDocumentFragment();

    return getDTM(new DOMSource(df), true, null, false, false);
  }
  catch (Exception e)
  {
    throw new DTMException(e);
  }
}
 
Example 11
Source File: SAX2DOM.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private Document createDocument(boolean overrideDefaultParser)
        throws ParserConfigurationException {
    if (_factory == null) {
        _factory = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        _internal = true;
        if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
            _internal = false;
        }
    }
    Document doc;
    if (_internal) {
        //default implementation is thread safe
        doc = _factory.newDocumentBuilder().newDocument();
    } else {
        synchronized(SAX2DOM.class) {
            doc = _factory.newDocumentBuilder().newDocument();
        }
    }
    return doc;
}
 
Example 12
Source File: XPathImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private DocumentBuilder getParser() {
    try {
        // we'd really like to cache those DocumentBuilders, but we can't because:
        // 1. thread safety. parsers are not thread-safe, so at least
        //    we need one instance per a thread.
        // 2. parsers are non-reentrant, so now we are looking at having a
        // pool of parsers.
        // 3. then the class loading issue. The look-up procedure of
        //    DocumentBuilderFactory.newInstance() depends on context class loader
        //    and system properties, which may change during the execution of JVM.
        //
        // so we really have to create a fresh DocumentBuilder every time we need one
        // - KK
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
        return dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // this should never happen with a well-behaving JAXP implementation.
        throw new Error(e);
    }
}
 
Example 13
Source File: DTMManagerDefault.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method createDocumentFragment
 *
 *
 * NEEDSDOC (createDocumentFragment) @return
 */
synchronized public DTM createDocumentFragment()
{

  try
  {
    DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(super.overrideDefaultParser());

    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Node df = doc.createDocumentFragment();

    return getDTM(new DOMSource(df), true, null, false, false);
  }
  catch (Exception e)
  {
    throw new DTMException(e);
  }
}
 
Example 14
Source File: DOMValidatorHelper.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Sets up handler for <code>DOMResult</code>.
 */
private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException {
    // If there's no DOMResult, unset the validator handler
    if (result == null) {
        fDOMValidatorHandler = null;
        fSchemaValidator.setDocumentHandler(null);
        return;
    }
    final Node nodeResult = result.getNode();
    // If the source node and result node are the same use the DOMResultAugmentor.
    // Otherwise use the DOMResultBuilder.
    if (source.getNode() == nodeResult) {
        fDOMValidatorHandler = fDOMResultAugmentor;
        fDOMResultAugmentor.setDOMResult(result);
        fSchemaValidator.setDocumentHandler(fDOMResultAugmentor);
        return;
    }
    if (result.getNode() == null) {
        try {
            DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
                    fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
            DocumentBuilder builder = factory.newDocumentBuilder();
            result.setNode(builder.newDocument());
        }
        catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
    fDOMValidatorHandler = fDOMResultBuilder;
    fDOMResultBuilder.setDOMResult(result);
    fSchemaValidator.setDocumentHandler(fDOMResultBuilder);
}
 
Example 15
Source File: AbstractTranslet.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Document newDocument(String uri, String qname)
    throws ParserConfigurationException
{
    if (_domImplementation == null) {
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
        _domImplementation = dbf.newDocumentBuilder().getDOMImplementation();
    }
    return _domImplementation.createDocument(uri, qname, null);
}
 
Example 16
Source File: DOMValidatorHelper.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up handler for <code>DOMResult</code>.
 */
private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException {
    // If there's no DOMResult, unset the validator handler
    if (result == null) {
        fDOMValidatorHandler = null;
        fSchemaValidator.setDocumentHandler(null);
        return;
    }
    final Node nodeResult = result.getNode();
    // If the source node and result node are the same use the DOMResultAugmentor.
    // Otherwise use the DOMResultBuilder.
    if (source.getNode() == nodeResult) {
        fDOMValidatorHandler = fDOMResultAugmentor;
        fDOMResultAugmentor.setDOMResult(result);
        fSchemaValidator.setDocumentHandler(fDOMResultAugmentor);
        return;
    }
    if (result.getNode() == null) {
        try {
            DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
                    fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
            DocumentBuilder builder = factory.newDocumentBuilder();
            result.setNode(builder.newDocument());
        }
        catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
    fDOMValidatorHandler = fDOMResultBuilder;
    fDOMResultBuilder.setDOMResult(result);
    fSchemaValidator.setDocumentHandler(fDOMResultBuilder);
}
 
Example 17
Source File: AbstractTranslet.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Document newDocument(String uri, String qname)
    throws ParserConfigurationException
{
    if (_domImplementation == null) {
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
        _domImplementation = dbf.newDocumentBuilder().getDOMImplementation();
    }
    return _domImplementation.createDocument(uri, qname, null);
}
 
Example 18
Source File: DOMValidatorHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up handler for <code>DOMResult</code>.
 */
private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException {
    // If there's no DOMResult, unset the validator handler
    if (result == null) {
        fDOMValidatorHandler = null;
        fSchemaValidator.setDocumentHandler(null);
        return;
    }
    final Node nodeResult = result.getNode();
    // If the source node and result node are the same use the DOMResultAugmentor.
    // Otherwise use the DOMResultBuilder.
    if (source.getNode() == nodeResult) {
        fDOMValidatorHandler = fDOMResultAugmentor;
        fDOMResultAugmentor.setDOMResult(result);
        fSchemaValidator.setDocumentHandler(fDOMResultAugmentor);
        return;
    }
    if (result.getNode() == null) {
        try {
            DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
                    fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
            DocumentBuilder builder = factory.newDocumentBuilder();
            result.setNode(builder.newDocument());
        }
        catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
    fDOMValidatorHandler = fDOMResultBuilder;
    fDOMResultBuilder.setDOMResult(result);
    fSchemaValidator.setDocumentHandler(fDOMResultBuilder);
}
 
Example 19
Source File: DOMValidatorHelper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up handler for <code>DOMResult</code>.
 */
private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException {
    // If there's no DOMResult, unset the validator handler
    if (result == null) {
        fDOMValidatorHandler = null;
        fSchemaValidator.setDocumentHandler(null);
        return;
    }
    final Node nodeResult = result.getNode();
    // If the source node and result node are the same use the DOMResultAugmentor.
    // Otherwise use the DOMResultBuilder.
    if (source.getNode() == nodeResult) {
        fDOMValidatorHandler = fDOMResultAugmentor;
        fDOMResultAugmentor.setDOMResult(result);
        fSchemaValidator.setDocumentHandler(fDOMResultAugmentor);
        return;
    }
    if (result.getNode() == null) {
        try {
            DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
                    fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
            DocumentBuilder builder = factory.newDocumentBuilder();
            result.setNode(builder.newDocument());
        }
        catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
    fDOMValidatorHandler = fDOMResultBuilder;
    fDOMResultBuilder.setDOMResult(result);
    fSchemaValidator.setDocumentHandler(fDOMResultBuilder);
}
 
Example 20
Source File: AbstractTranslet.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Document newDocument(String uri, String qname)
    throws ParserConfigurationException
{
    if (_domImplementation == null) {
        DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
        _domImplementation = dbf.newDocumentBuilder().getDOMImplementation();
    }
    return _domImplementation.createDocument(uri, qname, null);
}