@Override public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { reader.setProperty(name, value); } }
public void setProperty(final String uri, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException { reader.setProperty(uri, value); }
public void setProperty(final String uri, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException { reader.setProperty(uri, value); }
public void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler) { // Not supported by all SAX2 parsers but should work in Xerces: try { // Typecast required in Xerces2; SAXParser doesn't inheret XMLReader // %OPT% Cast at asignment? ((XMLReader)fIncrementalParser).setProperty("http://xml.org/sax/properties/lexical-handler", handler); } catch(org.xml.sax.SAXNotRecognizedException e) { // Nothing we can do about it } catch(org.xml.sax.SAXNotSupportedException e) { // Nothing we can do about it } }
private void configureXMLReader() { if (this.xmlReader != null) { try { if (this.xstream != null) { this.xmlReader.setProperty( SaxWriter.CONFIGURED_XSTREAM_PROPERTY, this.xstream); } if (this.source != null) { this.xmlReader.setProperty( SaxWriter.SOURCE_OBJECT_LIST_PROPERTY, this.source); } } catch (SAXException e) { throw new IllegalArgumentException(e.getMessage()); } } } }
protected void installLexicalHandler() { XMLReader parent = getParent(); if (parent == null) { throw new NullPointerException("No parent for filter"); } // try to register for lexical events for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { try { parent.setProperty(LEXICAL_HANDLER_NAMES[i], this); break; } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { // ignore } } }
private static void trySetXercesSecurityManager(XMLReader xmlReader) { // Try built-in JVM one first, standalone if not for (String securityManagerClassName : new String[] { "com.sun.org.apache.xerces.internal.util.SecurityManager", "org.apache.xerces.util.SecurityManager" }) { try { Object mgr = Class.forName(securityManagerClassName).newInstance(); Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE); setLimit.invoke(mgr, 4096); xmlReader.setProperty("http://apache.org/xml/properties/security-manager", mgr); // Stop once one can be setup without error return; } catch (Exception e) { logger.warn( "SAX Security Manager could not be setup", e); } } } }
protected XMLReader createXMLReader() { XMLReader parser = null; try { parser = XMLUtil.createXMLReader(false, true); try { parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); //NOI18N } catch (SAXException sex) { Logger.getLogger(XMLMIMEComponent.class.getName()).fine(NbBundle.getMessage(XMLMIMEComponent.class, "W-003")); //NOI18N } } catch (SAXException ex) { Logger.getLogger(XMLMIMEComponent.class.getName()).log(Level.WARNING, null, ex); } return parser; }
/** * Set the value of a property. * * <p>This will always fail if the parent is null.</p> * * @param name The property name. * @param value The requested property value. * @exception org.xml.sax.SAXNotRecognizedException If the property * value can't be assigned or retrieved from the parent. * @exception org.xml.sax.SAXNotSupportedException When the * parent recognizes the property name but * cannot set the requested value. */ public void setProperty (String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if (parent != null) { parent.setProperty(name, value); } else { throw new SAXNotRecognizedException("Property: " + name); } }
/** Bind our input streams to an XMLReader. * * Just a convenience routine; obviously you can explicitly register * this as a listener with the same effect. * */ public void setXMLReader(XMLReader eventsource) { fXMLReader=eventsource; eventsource.setContentHandler(this); eventsource.setDTDHandler(this); eventsource.setErrorHandler(this); // to report fatal errors in filtering mode // Not supported by all SAX2 filters: try { eventsource. setProperty("http://xml.org/sax/properties/lexical-handler", this); } catch(SAXNotRecognizedException e) { // Nothing we can do about it } catch(SAXNotSupportedException e) { // Nothing we can do about it } // Should we also bind as other varieties of handler? // (DTDHandler and so on) }
/** Bind our input streams to an XMLReader. * * Just a convenience routine; obviously you can explicitly register * this as a listener with the same effect. * */ public void setXMLReader(XMLReader eventsource) { fXMLReader=eventsource; eventsource.setContentHandler(this); eventsource.setDTDHandler(this); eventsource.setErrorHandler(this); // to report fatal errors in filtering mode // Not supported by all SAX2 filters: try { eventsource. setProperty("http://xml.org/sax/properties/lexical-handler", this); } catch(SAXNotRecognizedException e) { // Nothing we can do about it } catch(SAXNotSupportedException e) { // Nothing we can do about it } // Should we also bind as other varieties of handler? // (DTDHandler and so on) }
@Test public void namespacePrefixesDom() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document expected = documentBuilder.parse(new InputSource(new StringReader(SIMPLE_XML))); Document result = documentBuilder.newDocument(); AbstractStaxHandler handler = createStaxHandler(new DOMResult(result)); xmlReader.setContentHandler(handler); xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); xmlReader.setFeature("http://xml.org/sax/features/namespaces", true); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML))); assertThat(expected, isSimilarTo(result).withNodeFilter(nodeFilter)); }
@Test public void noNamespacePrefixesDom() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document expected = documentBuilder.parse(new InputSource(new StringReader(SIMPLE_XML))); Document result = documentBuilder.newDocument(); AbstractStaxHandler handler = createStaxHandler(new DOMResult(result)); xmlReader.setContentHandler(handler); xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); xmlReader.setFeature("http://xml.org/sax/features/namespaces", true); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML))); assertThat(result, isSimilarTo(expected).withNodeFilter(nodeFilter)); }
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE); setLimit.invoke(mgr, 1); xmlReader.setProperty(POIXMLConstants.PROPERTY_SECURITY_MANAGER, mgr); xmlReader.setProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT, 1); } catch (SAXException e) { // NOSONAR - also catch things like NoClassDefError here
xmlReader.setProperty(name, value); } catch (SAXNotRecognizedException e) { throw new BuildException(
@Test public void namespacePrefixes() throws Exception { Assume.assumeTrue(wwwSpringframeworkOrgIsAccessible()); StringWriter stringWriter = new StringWriter(); AbstractStaxHandler handler = createStaxHandler(new StreamResult(stringWriter)); xmlReader.setContentHandler(handler); xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); xmlReader.setFeature("http://xml.org/sax/features/namespaces", true); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML))); assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML).withNodeFilter(nodeFilter)); }
@Test public void noNamespacePrefixes() throws Exception { Assume.assumeTrue(wwwSpringframeworkOrgIsAccessible()); StringWriter stringWriter = new StringWriter(); AbstractStaxHandler handler = createStaxHandler(new StreamResult(stringWriter)); xmlReader.setContentHandler(handler); xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); xmlReader.setFeature("http://xml.org/sax/features/namespaces", true); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML))); assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML).withNodeFilter(nodeFilter)); }
parser.setProperty("http://apache.org/xml/features/disallow-doctype-decl", true); } catch (Exception e) {} parser.setProperty("http://xml.org/sax/features/external-general-entities", false); parser.setProperty("http://xml.org/sax/features/external-parameter-entities", false);
/** * Set a property * @return true if the feature could be set */ public boolean evalProperty() { XMLReader reader = getReader(); try { reader.setProperty(property, value); } catch (SAXNotRecognizedException e) { log(PROPERTY + NOT_RECOGNIZED + property, Project.MSG_VERBOSE); return false; } catch (SAXNotSupportedException e) { log(PROPERTY + NOT_SUPPORTED + property, Project.MSG_VERBOSE); return false; } return true; } }
@Test public void lexicalHandler() throws Exception { Resource testLexicalHandlerXml = new ClassPathResource("testLexicalHandler.xml", getClass()); LexicalHandler expectedLexicalHandler = mockLexicalHandler(); standardReader.setContentHandler(null); standardReader.setProperty("http://xml.org/sax/properties/lexical-handler", expectedLexicalHandler); standardReader.parse(new InputSource(testLexicalHandlerXml.getInputStream())); inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.FALSE); inputFactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE); inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE); inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE); LexicalHandler actualLexicalHandler = mockLexicalHandler(); willAnswer(invocation -> invocation.getArguments()[0] = "element"). given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString()); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream()); staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler); staxXmlReader.parse(new InputSource()); // TODO: broken comparison since Mockito 2.2 upgrade // verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler); }