net.sf.gluebooster.java.booster.basic.text.xml.AbstractXmlEventWriter Maven / Gradle / Ivy
package net.sf.gluebooster.java.booster.basic.text.xml;
import java.util.HashMap;
import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;
/**
* Handles the context of the events.
* The default namespace, the namespace context and the prefixes are stored here.
* Other functionalities must be done in subclasses.
* @author Christian Bauer
*
*/
public abstract class AbstractXmlEventWriter implements XMLEventWriter
{
/**
* The value of the corresponding property.
*/
private String defaultNamespace;
/**
* The value of the corresponding property.
*/
private NamespaceContext context;
/**
* The value of the corresponding property.
*/
private Map prefixes = new HashMap();
/**
* Default constructor.
*/
protected AbstractXmlEventWriter()
{
}
/**
* Invokes the add method for each event of the reader.
*/
@Override
public void add(XMLEventReader reader) throws XMLStreamException
{
while (reader.hasNext())
add(reader.nextEvent());
}
@Override
public NamespaceContext getNamespaceContext()
{
return context;
}
@Override
public String getPrefix(String uri) throws XMLStreamException
{
return prefixes.get(uri);
}
@Override
public void setDefaultNamespace(String uri) throws XMLStreamException
{
defaultNamespace = uri;
}
@Override
public void setNamespaceContext(NamespaceContext context)
throws XMLStreamException
{
this.context = context;
}
@Override
public void setPrefix(String prefix, String uri) throws XMLStreamException
{
prefixes.put(uri, prefix);
}
/**
* Returns the value of the property
* @return the value set
*/
public String getDefaultNamespace()
{
return defaultNamespace;
}
}