@Override public boolean isNamespaceAware() { try { return reader.getFeature("http://xml.org/sax/features/namespaces"); } catch (SAXException ex) { return false; } }
public boolean getFeature(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException { return reader.getFeature(uri); }
public boolean getFeature(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException { return this.reader.getFeature(uri); }
public static boolean needsInterning( XMLReader reader ) { // attempt to set it to true, which could fail try { reader.setFeature("http://xml.org/sax/features/string-interning",true); } catch (SAXException e) { // if it fails that's fine. we'll work around on our side } try { if (reader.getFeature("http://xml.org/sax/features/string-interning")) { return false; // no need for intern } } catch (SAXException e) { // unrecognized/unsupported } // otherwise we need intern return true; }
/** * Look up the value of a feature. * * <p>This will always fail if the parent is null.</p> * * @param name The feature name. * @return The current value of the feature. * @exception org.xml.sax.SAXNotRecognizedException If the feature * value can't be assigned or retrieved from the parent. * @exception org.xml.sax.SAXNotSupportedException When the * parent recognizes the feature name but * cannot determine its value at this time. */ public boolean getFeature (String name) throws SAXNotRecognizedException, SAXNotSupportedException { if (parent != null) { return parent.getFeature(name); } else { throw new SAXNotRecognizedException("Feature: " + name); } }
@Test // SPR-10806 public void unmarshalSaxSourceWithXmlOptions() throws Exception { final javax.xml.bind.Unmarshaller unmarshaller = mock(javax.xml.bind.Unmarshaller.class); Jaxb2Marshaller marshaller = new Jaxb2Marshaller() { @Override protected javax.xml.bind.Unmarshaller createUnmarshaller() { return unmarshaller; } }; // 1. external-general-entities and dtd support disabled (default) marshaller.unmarshal(new SAXSource(new InputSource("1"))); ArgumentCaptor<SAXSource> sourceCaptor = ArgumentCaptor.forClass(SAXSource.class); verify(unmarshaller).unmarshal(sourceCaptor.capture()); SAXSource result = sourceCaptor.getValue(); assertEquals(true, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")); assertEquals(false, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")); // 2. external-general-entities and dtd support enabled reset(unmarshaller); marshaller.setProcessExternalEntities(true); marshaller.setSupportDtd(true); marshaller.unmarshal(new SAXSource(new InputSource("1"))); verify(unmarshaller).unmarshal(sourceCaptor.capture()); result = sourceCaptor.getValue(); assertEquals(false, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")); assertEquals(true, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")); }
@Test // SPR-10806 public void unmarshalStreamSourceWithXmlOptions() throws Exception { final javax.xml.bind.Unmarshaller unmarshaller = mock(javax.xml.bind.Unmarshaller.class); Jaxb2Marshaller marshaller = new Jaxb2Marshaller() { @Override protected javax.xml.bind.Unmarshaller createUnmarshaller() { return unmarshaller; } }; // 1. external-general-entities and dtd support disabled (default) marshaller.unmarshal(new StreamSource("1")); ArgumentCaptor<SAXSource> sourceCaptor = ArgumentCaptor.forClass(SAXSource.class); verify(unmarshaller).unmarshal(sourceCaptor.capture()); SAXSource result = sourceCaptor.getValue(); assertEquals(true, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")); assertEquals(false, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")); // 2. external-general-entities and dtd support enabled reset(unmarshaller); marshaller.setProcessExternalEntities(true); marshaller.setSupportDtd(true); marshaller.unmarshal(new StreamSource("1")); verify(unmarshaller).unmarshal(sourceCaptor.capture()); result = sourceCaptor.getValue(); assertEquals(false, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")); assertEquals(true, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")); }
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return reader.getFeature(name); }
public static boolean needsInterning( XMLReader reader ) { // attempt to set it to true, which could fail try { reader.setFeature("http://xml.org/sax/features/string-interning",true); } catch (SAXException e) { // if it fails that's fine. we'll work around on our side } try { if (reader.getFeature("http://xml.org/sax/features/string-interning")) { return false; // no need for intern } } catch (SAXException e) { // unrecognized/unsupported } // otherwise we need intern return true; }
if (parser.getFeature(SAX_FEATURE_EXTERNAL_ENT) != expand) { parser.setFeature(SAX_FEATURE_EXTERNAL_ENT, expand);
@Override public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return delegate.getFeature(name); }
@Override public boolean isNamespaceAware() { try { return reader.getFeature("http://xml.org/sax/features/namespaces"); } catch (SAXException ex) { return false; } }
/** * @param name * @return * @throws SAXNotRecognizedException * @throws SAXNotSupportedException * @see org.xml.sax.XMLReader#getFeature(java.lang.String) */ @Override public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return wrappedReader.getFeature(name); }
/** * @param name * @return * @throws SAXNotRecognizedException * @throws SAXNotSupportedException * @see org.xml.sax.XMLReader#getFeature(java.lang.String) */ @Override public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return wrappedReader.getFeature(name); }
@Override public boolean isNamespaceAware() { try { return reader.getFeature("http://xml.org/sax/features/namespaces"); } catch (SAXException ex) { return false; } }
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return xmlReader.getFeature(name); }
@Override public boolean isNamespaceAware() { try { return reader.getFeature("http://xml.org/sax/features/namespaces"); } catch (SAXException ex) { return false; } }
/** * @param name * @return * @throws SAXNotRecognizedException * @throws SAXNotSupportedException * @see org.xml.sax.XMLReader#getFeature(java.lang.String) */ @Override public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return wrappedReader.getFeature(name); }
@Override public boolean isNamespaceAware() { try { return reader.getFeature("http://xml.org/sax/features/namespaces"); } catch (SAXException ex) { return false; } }
/** * @param arg0 * @return * @throws SAXNotRecognizedException * @throws SAXNotSupportedException * @see org.xml.sax.XMLReader#getFeature(java.lang.String) */ @Override public boolean getFeature(String arg0) throws SAXNotRecognizedException, SAXNotSupportedException { return wrappedReader.getFeature(arg0); }