org.inria.ns.reflex.xml
Class ParserConfiguration.Impl

java.lang.Object
  extended by org.inria.ns.reflex.xml.ParserConfiguration.Impl
All Implemented Interfaces:
Configurable, ParserConfiguration
Enclosing interface:
ParserConfiguration

public static class ParserConfiguration.Impl
extends Object
implements ParserConfiguration, Configurable

A standard configuration contains a set of flags and a set of attributes (features and properties) to set to a DOM or SAX parser.

When attributes are not used, the configuration is said to be static (because at runtime, the flags are the same but the attributes may differ).

The parser will use getAttributes() for its configuration, thus subclasses may override this method (and surely, other methods relative to attributes won't have any effect).

The getAttributes() method will be invoked as late as possible.

SAX features and properties

In SAX terminology, a parser can be configured with features and properties. Boolean attributes will be set as SAX features, non-boolean attributes as SAX properties.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.xml.ParserConfiguration
ParserConfiguration.Impl
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Configurable
Configurable.Impl
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.xml.ParserConfiguration
NAMESPACEAWARE_PARSER_CONFIGURATION
 
Constructor Summary
ParserConfiguration.Impl(boolean isValidating, boolean isNamespaceAware, boolean isCoalescing, boolean isExpandingEntityReferences, boolean isIgnoringComments, boolean isIgnoringWhitespace)
          Create a new instance of ParserConfiguration.Impl.
ParserConfiguration.Impl(ParserConfiguration.Impl staticConfiguration)
          Create a new instance of ParserConfiguration.Impl.
 
Method Summary
 boolean containsAttribute(Object key)
          Indicates if a key is contains in the attributes of this configuration.
 boolean containsAttribute(String key)
          Indicates if a key is contains in the attributes of this configuration.
 Object getAttribute(Object key)
          Return an attribute.
 Object getAttribute(String key)
          Return an attribute.
 Map getAttributes()
          Get the attributes to set to the parser.
 boolean isCoalescing()
          Indicates whether the parser will coalesce CDATA nodes or not.
 boolean isExpandingEntityReferences()
          Indicates whether the parser will expand entity references or not.
 boolean isIgnoringComments()
          Indicates whether the parser will ignore comments or not.
 boolean isIgnoringWhitespace()
          Indicates whether the parser will ignore whitespaces or not.
 boolean isNamespaceAware()
          Indicates whether the parser will recognize namespaces or not.
 boolean isValidating()
          Indicates whether the parser will validate documents or not.
 void mergeAttributes(Map attributes)
          Adds an attribute set to the current one.
 DocumentBuilder newDocumentBuilder()
          Return a configured DocumentBuilderFactory ; if attributes have been previously set, the parser will use them.
 XMLReader newXMLReader()
          Return a configured XMLReader ; if attributes have been previously set, the parser will use them.
 void setAttribute(Object name, Object value)
          Adds an attribute to the current set of attributes.
 void setAttribute(String name, Object value)
          Adds an attribute to the current set of attributes.
 void setAttributes(Map attributes)
          Replace the current attributes set with a new one.
 void setCoalescing(boolean isCoalescing)
          Indicates to the parser whether it must coalesce CDATA nodes or not.
 void setExpandingEntityReferences(boolean isExpandingEntityReferences)
          Indicates to the parser whether it must expand entity references or not.
 void setIgnoringComments(boolean isIgnoringComments)
          Indicates to the parser whether it must ignore comments or not.
 void setIgnoringWhitespace(boolean isIgnoringWhitespace)
          Indicates to the parser whether it must ignore whitespace or not.
 void setNamespaceAware(boolean isNamespaceAware)
          Indicates to the parser whether it must recognize namespaces or not.
 void setValidating(boolean isValidating)
          Indicates to the parser whether it must validate documents or not.
 String toString()
          Return this configuration as a detailed message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParserConfiguration.Impl

public ParserConfiguration.Impl(boolean isValidating,
                                boolean isNamespaceAware,
                                boolean isCoalescing,
                                boolean isExpandingEntityReferences,
                                boolean isIgnoringComments,
                                boolean isIgnoringWhitespace)
Create a new instance of ParserConfiguration.Impl.

Parameters:
isValidating - true if the parser will validate documents as they are parsed, false otherwise.
isNamespaceAware - true if the parser will provide support for XML namespaces, false otherwise.
isCoalescing - true if the parser will convert CDATA nodes to Text nodes and append it to the adjacent (if any) text node, false otherwise.
isExpandingEntityReferences - true if the parser will expand entity reference nodes, false otherwise.
isIgnoringComments - true if the parser will ignore comments, false otherwise.
isIgnoringWhitespace - true if the parser must eliminate whitespace in element content (sometimes known loosely as 'ignorable whitespace') when parsing, false otherwise.

ParserConfiguration.Impl

public ParserConfiguration.Impl(ParserConfiguration.Impl staticConfiguration)
Create a new instance of ParserConfiguration.Impl.

Parameters:
staticConfiguration - A static configuration to copy. All fields are copied except the attributes.
Method Detail

newDocumentBuilder

public DocumentBuilder newDocumentBuilder()
                                   throws ParserConfigurationException
Return a configured DocumentBuilderFactory ; if attributes have been previously set, the parser will use them.

Specified by:
newDocumentBuilder in interface ParserConfiguration
Returns:
A DocumentBuilderFactory configured as expected.
Throws:
ParserConfigurationException - If a parser with this settings can't be created.
See Also:
setAttributes(Map), mergeAttributes(Map), ParserConfiguration#newDocumentBuilderFactory()

newXMLReader

public XMLReader newXMLReader()
                       throws SAXException
Return a configured XMLReader ; if attributes have been previously set, the parser will use them.

Specified by:
newXMLReader in interface ParserConfiguration
Returns:
An XMLReader configured as expected.
Throws:
SAXException - When a SAX parser with such a configuration can't be get.
See Also:
setAttributes(Map), mergeAttributes(Map), ParserConfiguration.newXMLReader()

getAttributes

public Map getAttributes()
Get the attributes to set to the parser. The map returned may be immutable ; never use it to update this attributes. Use the xxxAttributex() methods instead. However, this method may be override to provide a dynamic set of attributes.

Specified by:
getAttributes in interface Configurable
Returns:
The non-null attributes to set to the parser. By default, the map returned is the immutable empty map.
See Also:
setAttributes(Map), mergeAttributes(Map), setAttribute(String, Object), Collections.EMPTY_MAP, Configurable.getAttributes()

setAttributes

public void setAttributes(Map attributes)
Replace the current attributes set with a new one.

Specified by:
setAttributes in interface Configurable
Parameters:
attributes - The new attributes to set to the parser.
See Also:
Configurable.setAttributes(Map)

mergeAttributes

public void mergeAttributes(Map attributes)
Adds an attribute set to the current one.

Specified by:
mergeAttributes in interface Configurable
Parameters:
attributes - The attributes to add.
See Also:
Configurable.mergeAttributes(Map)

setAttribute

public void setAttribute(Object name,
                         Object value)
Adds an attribute to the current set of attributes.

Specified by:
setAttribute in interface Configurable
Parameters:
name - The name of the attribute to add.
value - The value of the attribute to add.
See Also:
Configurable.setAttribute(Object, Object), setAttribute(String, Object)

setAttribute

public void setAttribute(String name,
                         Object value)
Adds an attribute to the current set of attributes.

Parameters:
name - The name of the attribute to add.
value - The value of the attribute to add.

getAttribute

public Object getAttribute(Object key)
Return an attribute.

Specified by:
getAttribute in interface Configurable
Parameters:
key - The key of the attribute.
Returns:
The value of the attribute, null if it doesn't exists.
See Also:
Configurable.getAttribute(java.lang.Object), getAttribute(String)

getAttribute

public Object getAttribute(String key)
Return an attribute.

Parameters:
key - The key of the attribute.
Returns:
The value of the attribute, null if it doesn't exists.
See Also:
Configurable.getAttribute(java.lang.Object)

containsAttribute

public boolean containsAttribute(Object key)
Indicates if a key is contains in the attributes of this configuration.

Specified by:
containsAttribute in interface Configurable
Parameters:
key - The key to retrieve.
Returns:
true if the key exists, false otherwise.
See Also:
Configurable.containsAttribute(java.lang.Object), containsAttribute(String)

containsAttribute

public boolean containsAttribute(String key)
Indicates if a key is contains in the attributes of this configuration.

Parameters:
key - The key to retrieve.
Returns:
true if the key exists, false otherwise.
See Also:
Configurable.containsAttribute(java.lang.Object)

isCoalescing

public boolean isCoalescing()
Indicates whether the parser will coalesce CDATA nodes or not.

Returns:
true if the parser will convert CDATA nodes to Text nodes and append it to the adjacent (if any) text node, false otherwise.

setCoalescing

public void setCoalescing(boolean isCoalescing)
Indicates to the parser whether it must coalesce CDATA nodes or not.

Parameters:
isCoalescing - true to coalesce CDATA nodes, false otherwise.

isExpandingEntityReferences

public boolean isExpandingEntityReferences()
Indicates whether the parser will expand entity references or not.

Returns:
true if the parser will expand entity reference nodes, false otherwise.

setExpandingEntityReferences

public void setExpandingEntityReferences(boolean isExpandingEntityReferences)
Indicates to the parser whether it must expand entity references or not.

Parameters:
isExpandingEntityReferences - true to expand entity references, false otherwise.

isIgnoringComments

public boolean isIgnoringComments()
Indicates whether the parser will ignore comments or not.

Returns:
true if the parser will ignore comments, false otherwise.

setIgnoringComments

public void setIgnoringComments(boolean isIgnoringComments)
Indicates to the parser whether it must ignore comments or not.

Parameters:
isIgnoringComments - true to ignore comments, false otherwise.

isIgnoringWhitespace

public boolean isIgnoringWhitespace()
Indicates whether the parser will ignore whitespaces or not.

Returns:
true if the parser must eliminate whitespace in element content (sometimes known loosely as 'ignorable whitespace') when parsing, false otherwise.

setIgnoringWhitespace

public void setIgnoringWhitespace(boolean isIgnoringWhitespace)
Indicates to the parser whether it must ignore whitespace or not.

Parameters:
isIgnoringWhitespace - true to ignore whitespaces, false otherwise.

isNamespaceAware

public boolean isNamespaceAware()
Indicates whether the parser will recognize namespaces or not.

Returns:
true if the parser will provide support for XML namespaces, false otherwise.

setNamespaceAware

public void setNamespaceAware(boolean isNamespaceAware)
Indicates to the parser whether it must recognize namespaces or not.

Parameters:
isNamespaceAware - true to recognize namespaces, false otherwise.

isValidating

public boolean isValidating()
Indicates whether the parser will validate documents or not.

Returns:
true if the parser will validate documents as they are parsed, false otherwise.

setValidating

public void setValidating(boolean isValidating)
Indicates to the parser whether it must validate documents or not.

Parameters:
isValidating - true to validate documents, false otherwise.

toString

public String toString()
Return this configuration as a detailed message.

Overrides:
toString in class Object
Returns:
A string like this : [ [flag] [flag] [flag] [attributes] ]
See Also:
Object.toString()