Abstract(Stax)XMLReader recognizes standard features as not supported
Issue: SPR-14056
This commit is contained in:
		
							parent
							
								
									b1121fba70
								
							
						
					
					
						commit
						35eb52e558
					
				|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2002-2012 the original author or authors. | ||||
|  * Copyright 2002-2016 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -35,6 +35,7 @@ import org.springframework.util.StringUtils; | |||
|  * Abstract base class for SAX {@code XMLReader} implementations that use StAX as a basis. | ||||
|  * | ||||
|  * @author Arjen Poutsma | ||||
|  * @author Juergen Hoeller | ||||
|  * @since 3.0 | ||||
|  * @see #setContentHandler(org.xml.sax.ContentHandler) | ||||
|  * @see #setDTDHandler(org.xml.sax.DTDHandler) | ||||
|  | @ -58,6 +59,7 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader { | |||
| 
 | ||||
| 	private final Map<String, String> namespaces = new LinkedHashMap<String, String>(); | ||||
| 
 | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { | ||||
| 		if (NAMESPACES_FEATURE_NAME.equals(name)) { | ||||
|  | @ -170,12 +172,13 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader { | |||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Template-method that parses the StAX reader passed at construction-time. | ||||
| 	 * Template method that parses the StAX reader passed at construction-time. | ||||
| 	 */ | ||||
| 	protected abstract void parseInternal() throws SAXException, XMLStreamException; | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Starts the prefix mapping for the given prefix. | ||||
| 	 * Start the prefix mapping for the given prefix. | ||||
| 	 * @see org.xml.sax.ContentHandler#startPrefixMapping(String, String) | ||||
| 	 */ | ||||
| 	protected void startPrefixMapping(String prefix, String namespace) throws SAXException { | ||||
|  | @ -186,57 +189,58 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader { | |||
| 			if (!StringUtils.hasLength(namespace)) { | ||||
| 				return; | ||||
| 			} | ||||
| 			if (!namespace.equals(namespaces.get(prefix))) { | ||||
| 			if (!namespace.equals(this.namespaces.get(prefix))) { | ||||
| 				getContentHandler().startPrefixMapping(prefix, namespace); | ||||
| 				namespaces.put(prefix, namespace); | ||||
| 				this.namespaces.put(prefix, namespace); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Ends the prefix mapping for the given prefix. | ||||
| 	 * End the prefix mapping for the given prefix. | ||||
| 	 * @see org.xml.sax.ContentHandler#endPrefixMapping(String) | ||||
| 	 */ | ||||
| 	protected void endPrefixMapping(String prefix) throws SAXException { | ||||
| 		if (getContentHandler() != null) { | ||||
| 			if (namespaces.containsKey(prefix)) { | ||||
| 			if (this.namespaces.containsKey(prefix)) { | ||||
| 				getContentHandler().endPrefixMapping(prefix); | ||||
| 				namespaces.remove(prefix); | ||||
| 				this.namespaces.remove(prefix); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Implementation of the {@code Locator} interface that is based on a StAX {@code Location}. | ||||
| 	 * Implementation of the {@code Locator} interface based on a given StAX {@code Location}. | ||||
| 	 * @see Locator | ||||
| 	 * @see Location | ||||
| 	 */ | ||||
| 	private static class StaxLocator implements Locator { | ||||
| 
 | ||||
| 		private Location location; | ||||
| 		private final Location location; | ||||
| 
 | ||||
| 		protected StaxLocator(Location location) { | ||||
| 		public StaxLocator(Location location) { | ||||
| 			this.location = location; | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public String getPublicId() { | ||||
| 			return location.getPublicId(); | ||||
| 			return this.location.getPublicId(); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public String getSystemId() { | ||||
| 			return location.getSystemId(); | ||||
| 			return this.location.getSystemId(); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public int getLineNumber() { | ||||
| 			return location.getLineNumber(); | ||||
| 			return this.location.getLineNumber(); | ||||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public int getColumnNumber() { | ||||
| 			return location.getColumnNumber(); | ||||
| 			return this.location.getColumnNumber(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2002-2012 the original author or authors. | ||||
|  * Copyright 2002-2016 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -26,15 +26,16 @@ import org.xml.sax.XMLReader; | |||
| import org.xml.sax.ext.LexicalHandler; | ||||
| 
 | ||||
| /** | ||||
|  * Abstract base class for SAX {@code XMLReader} implementations. Contains properties as defined in {@link | ||||
|  * XMLReader}, and does not recognize any features. | ||||
|  * Abstract base class for SAX {@code XMLReader} implementations. | ||||
|  * Contains properties as defined in {@link XMLReader}, and does not recognize any features. | ||||
|  * | ||||
|  * @author Arjen Poutsma | ||||
|  * @author Juergen Hoeller | ||||
|  * @since 3.0 | ||||
|  * @see #setContentHandler(org.xml.sax.ContentHandler) | ||||
|  * @see #setDTDHandler(org.xml.sax.DTDHandler) | ||||
|  * @see #setEntityResolver(org.xml.sax.EntityResolver) | ||||
|  * @see #setErrorHandler(org.xml.sax.ErrorHandler) | ||||
|  * @since 3.0 | ||||
|  */ | ||||
| abstract class AbstractXMLReader implements XMLReader { | ||||
| 
 | ||||
|  | @ -48,16 +49,17 @@ abstract class AbstractXMLReader implements XMLReader { | |||
| 
 | ||||
| 	private LexicalHandler lexicalHandler; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ContentHandler getContentHandler() { | ||||
| 		return contentHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setContentHandler(ContentHandler contentHandler) { | ||||
| 		this.contentHandler = contentHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ContentHandler getContentHandler() { | ||||
| 		return this.contentHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setDTDHandler(DTDHandler dtdHandler) { | ||||
| 		this.dtdHandler = dtdHandler; | ||||
|  | @ -65,12 +67,7 @@ abstract class AbstractXMLReader implements XMLReader { | |||
| 
 | ||||
| 	@Override | ||||
| 	public DTDHandler getDTDHandler() { | ||||
| 		return dtdHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public EntityResolver getEntityResolver() { | ||||
| 		return entityResolver; | ||||
| 		return this.dtdHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
|  | @ -79,8 +76,8 @@ abstract class AbstractXMLReader implements XMLReader { | |||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ErrorHandler getErrorHandler() { | ||||
| 		return errorHandler; | ||||
| 	public EntityResolver getEntityResolver() { | ||||
| 		return this.entityResolver; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
|  | @ -88,29 +85,46 @@ abstract class AbstractXMLReader implements XMLReader { | |||
| 		this.errorHandler = errorHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	protected LexicalHandler getLexicalHandler() { | ||||
| 		return lexicalHandler; | ||||
| 	@Override | ||||
| 	public ErrorHandler getErrorHandler() { | ||||
| 		return this.errorHandler; | ||||
| 	} | ||||
| 
 | ||||
| 	protected LexicalHandler getLexicalHandler() { | ||||
| 		return this.lexicalHandler; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Throws a {@code SAXNotRecognizedException} exception. | ||||
| 	 * | ||||
| 	 * @throws org.xml.sax.SAXNotRecognizedException | ||||
| 	 *          always | ||||
| 	 * This implementation throws a {@code SAXNotRecognizedException} exception | ||||
| 	 * for any feature outside of the "http://xml.org/sax/features/" namespace | ||||
| 	 * and returns {@code false} for any feature within. | ||||
| 	 */ | ||||
| 	@Override | ||||
| 	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { | ||||
| 		throw new SAXNotRecognizedException(name); | ||||
| 		if (name.startsWith("http://xml.org/sax/features/")) { | ||||
| 			return false; | ||||
| 		} | ||||
| 		else { | ||||
| 			throw new SAXNotRecognizedException(name); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Throws a {@code SAXNotRecognizedException} exception. | ||||
| 	 * | ||||
| 	 * @throws SAXNotRecognizedException always | ||||
| 	 * This implementation throws a {@code SAXNotRecognizedException} exception | ||||
| 	 * for any feature outside of the "http://xml.org/sax/features/" namespace | ||||
| 	 * and accepts a {@code false} value for any feature within. | ||||
| 	 */ | ||||
| 	@Override | ||||
| 	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { | ||||
| 		throw new SAXNotRecognizedException(name); | ||||
| 		if (name.startsWith("http://xml.org/sax/features/")) { | ||||
| 			if (value) { | ||||
| 				throw new SAXNotSupportedException(name); | ||||
| 			} | ||||
| 		} | ||||
| 		else { | ||||
| 			throw new SAXNotRecognizedException(name); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -120,7 +134,7 @@ abstract class AbstractXMLReader implements XMLReader { | |||
| 	@Override | ||||
| 	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { | ||||
| 		if ("http://xml.org/sax/properties/lexical-handler".equals(name)) { | ||||
| 			return lexicalHandler; | ||||
| 			return this.lexicalHandler; | ||||
| 		} | ||||
| 		else { | ||||
| 			throw new SAXNotRecognizedException(name); | ||||
|  | @ -134,10 +148,11 @@ abstract class AbstractXMLReader implements XMLReader { | |||
| 	@Override | ||||
| 	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { | ||||
| 		if ("http://xml.org/sax/properties/lexical-handler".equals(name)) { | ||||
| 			lexicalHandler = (LexicalHandler) value; | ||||
| 			this.lexicalHandler = (LexicalHandler) value; | ||||
| 		} | ||||
| 		else { | ||||
| 			throw new SAXNotRecognizedException(name); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue