Java Code Examples for javax.xml.xpath.XPathFactory#setFeature()
The following examples show how to use
javax.xml.xpath.XPathFactory#setFeature() .
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: XmlFactory.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Returns properly configured (e.g. security features) factory * - securityProcessing == is set based on security processing property, default is true */ public static XPathFactory createXPathFactory(boolean disableSecureProcessing) throws IllegalStateException { try { XPathFactory factory = XPathFactory.newInstance(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "XPathFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (XPathFactoryConfigurationException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException( ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
Example 2
Source File: XmlFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns properly configured (e.g. security features) factory * - securityProcessing == is set based on security processing property, default is true */ public static XPathFactory createXPathFactory(boolean disableSecureProcessing) throws IllegalStateException { try { XPathFactory factory = XPathFactory.newInstance(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "XPathFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (XPathFactoryConfigurationException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException( ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
Example 3
Source File: XmlFactory.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns properly configured (e.g. security features) factory * - securityProcessing == is set based on security processing property, default is true */ public static XPathFactory createXPathFactory(boolean disableSecureProcessing) throws IllegalStateException { try { XPathFactory factory = XPathFactory.newInstance(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "XPathFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (XPathFactoryConfigurationException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException( ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
Example 4
Source File: JmsSubscription.java From cxf with Apache License 2.0 | 6 votes |
protected boolean doFilter(Element content) { if (contentFilter != null) { if (!contentFilter.getDialect().equals(XPATH1_URI)) { throw new IllegalStateException("Unsupported dialect: " + contentFilter.getDialect()); } try { XPathFactory xpfactory = XPathFactory.newInstance(); try { xpfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); } catch (Throwable t) { //possibly old version, though doesn't really matter as content is already parsed as an Element } XPath xpath = xpfactory.newXPath(); XPathExpression exp = xpath.compile(contentFilter.getContent().get(0).toString()); Boolean ret = (Boolean) exp.evaluate(content, XPathConstants.BOOLEAN); return ret.booleanValue(); } catch (XPathExpressionException e) { LOGGER.log(Level.WARNING, "Could not filter notification", e); } return false; } return true; }
Example 5
Source File: XPathExFuncTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException { Document document = getDocument(); XPathFactory xPathFactory = XPathFactory.newInstance(); /** * Use of the extension function 'http://exslt.org/strings:tokenize' is * not allowed when the secure processing feature is set to true. * Attempt to use the new property to enable extension function */ if (enableExt) { boolean isExtensionSupported = enableExtensionFunction(xPathFactory); } xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver()); if (System.getSecurityManager() == null) { xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); } XPath xPath = xPathFactory.newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document); System.out.println( "XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\""); }
Example 6
Source File: XPathExFuncTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
boolean enableExtensionFunction(XPathFactory factory) { boolean isSupported = true; try { factory.setFeature(ENABLE_EXTENSION_FUNCTIONS, true); } catch (XPathFactoryConfigurationException ex) { isSupported = false; } return isSupported; }
Example 7
Source File: XPathExFuncTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException { Document document = getDocument(); XPathFactory xPathFactory = XPathFactory.newInstance(); /** * Use of the extension function 'http://exslt.org/strings:tokenize' is * not allowed when the secure processing feature is set to true. * Attempt to use the new property to enable extension function */ if (enableExt) { boolean isExtensionSupported = enableExtensionFunction(xPathFactory); } xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver()); if (System.getSecurityManager() == null) { xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); } XPath xPath = xPathFactory.newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document); System.out.println( "XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\""); }
Example 8
Source File: XMLSource.java From cxf with Apache License 2.0 | 5 votes |
private Object evaluate(String expression, Map<String, String> namespaces, QName type) { XPathFactory factory = XPathFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); } catch (XPathFactoryConfigurationException e) { throw new RuntimeException(e); } XPath xpath = factory.newXPath(); xpath.setNamespaceContext(new NamespaceContextImpl(namespaces)); boolean releaseDoc = false; try { if (stream != null) { //xalan xpath evaluate parses to a DOM via a DocumentBuilderFactory, but doesn't //set the SecureProcessing on that. Since a DOM is always created, might as well //do it via stax and avoid the service factory performance hits that the //DocumentBuilderFactory will entail as well as get the extra security //that woodstox provides setBuffering(); releaseDoc = true; } return xpath.compile(expression).evaluate(doc, type); } catch (XPathExpressionException ex) { throw new IllegalArgumentException("Illegal XPath expression '" + expression + "'", ex); } finally { if (releaseDoc) { //don't need to maintain the doc doc = null; } } }
Example 9
Source File: XPathExFuncTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException { Document document = getDocument(); XPathFactory xPathFactory = XPathFactory.newInstance(); /** * Use of the extension function 'http://exslt.org/strings:tokenize' is * not allowed when the secure processing feature is set to true. * Attempt to use the new property to enable extension function */ if (enableExt) { boolean isExtensionSupported = enableExtensionFunction(xPathFactory); } xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver()); if (System.getSecurityManager() == null) { xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); } XPath xPath = xPathFactory.newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document); System.out.println( "XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\""); }
Example 10
Source File: XPathExFuncTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException { Document document = getDocument(); XPathFactory xPathFactory = XPathFactory.newInstance(); /** * Use of the extension function 'http://exslt.org/strings:tokenize' is * not allowed when the secure processing feature is set to true. * Attempt to use the new property to enable extension function */ if (enableExt) { boolean isExtensionSupported = enableExtensionFunction(xPathFactory); } xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver()); if (System.getSecurityManager() == null) { xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); } XPath xPath = xPathFactory.newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document); System.out.println( "XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\""); }
Example 11
Source File: XmlUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static XPathFactory newXPathFactory(boolean secureXmlProcessingEnabled) { XPathFactory factory = XPathFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); } catch (XPathFactoryConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; }
Example 12
Source File: XPathExFuncTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException { Document document = getDocument(); XPathFactory xPathFactory = XPathFactory.newInstance(); /** * Use of the extension function 'http://exslt.org/strings:tokenize' is * not allowed when the secure processing feature is set to true. * Attempt to use the new property to enable extension function */ if (enableExt) { boolean isExtensionSupported = enableExtensionFunction(xPathFactory); } xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver()); if (System.getSecurityManager() == null) { xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); } XPath xPath = xPathFactory.newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document); System.out.println( "XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\""); }
Example 13
Source File: XPathExFuncTest.java From hottub with GNU General Public License v2.0 | 5 votes |
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException { Document document = getDocument(); XPathFactory xPathFactory = XPathFactory.newInstance(); /** * Use of the extension function 'http://exslt.org/strings:tokenize' is * not allowed when the secure processing feature is set to true. * Attempt to use the new property to enable extension function */ if (enableExt) { boolean isExtensionSupported = enableExtensionFunction(xPathFactory); } xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver()); if (System.getSecurityManager() == null) { xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); } XPath xPath = xPathFactory.newXPath(); xPath.setNamespaceContext(new MyNamespaceContext()); String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document); System.out.println( "XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\""); }
Example 14
Source File: XmlUtil.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static XPathFactory newXPathFactory(boolean secureXmlProcessingEnabled) { XPathFactory factory = XPathFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); } catch (XPathFactoryConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; }
Example 15
Source File: XPathExFuncTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
boolean enableExtensionFunction(XPathFactory factory) { boolean isSupported = true; try { factory.setFeature(ENABLE_EXTENSION_FUNCTIONS, true); } catch (XPathFactoryConfigurationException ex) { isSupported = false; } return isSupported; }
Example 16
Source File: XmlUtil.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static XPathFactory newXPathFactory(boolean secureXmlProcessingEnabled) { XPathFactory factory = XPathFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); } catch (XPathFactoryConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; }
Example 17
Source File: XmlUtil.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static XPathFactory newXPathFactory(boolean secureXmlProcessingEnabled) { XPathFactory factory = XPathFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); } catch (XPathFactoryConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; }
Example 18
Source File: XPathExFuncTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
boolean enableExtensionFunction(XPathFactory factory) { boolean isSupported = true; try { factory.setFeature(ENABLE_EXTENSION_FUNCTIONS, true); } catch (XPathFactoryConfigurationException ex) { isSupported = false; } return isSupported; }
Example 19
Source File: XmlUtil.java From hottub with GNU General Public License v2.0 | 5 votes |
public static XPathFactory newXPathFactory(boolean secureXmlProcessingEnabled) { XPathFactory factory = XPathFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, isXMLSecurityDisabled(secureXmlProcessingEnabled)); } catch (XPathFactoryConfigurationException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support secure xml processing!", new Object[] { factory.getClass().getName() } ); } return factory; }
Example 20
Source File: XPathExFuncTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
boolean enableExtensionFunction(XPathFactory factory) { boolean isSupported = true; try { factory.setFeature(ENABLE_EXTENSION_FUNCTIONS, true); } catch (XPathFactoryConfigurationException ex) { isSupported = false; } return isSupported; }