org.gedcomx.util
Class CleanXMLStreamWriter

java.lang.Object
  extended by org.gedcomx.util.CleanXMLStreamWriter
All Implemented Interfaces:
XMLStreamWriter

public class CleanXMLStreamWriter
extends Object
implements XMLStreamWriter

Delegating XMLStreamWriter that filters out UTF-8 characters that are illegal in XML, replacing them with a

Author:
Erik van Zijst (small change by Lennart Schedin, and isLegalXmlCharacter() expanded to XML 1.0 spec by Randy Wilson)

Field Summary
static char REPLACEMENT_CHARACTER
           
 
Constructor Summary
CleanXMLStreamWriter(XMLStreamWriter writer)
           
 
Method Summary
 void close()
           
protected static String escapeCharacters(String string)
          Substitutes all illegal characters in the given string by the value of REPLACEMENT_CHARACTER.
 void flush()
           
 NamespaceContext getNamespaceContext()
           
 String getPrefix(String s)
           
 Object getProperty(String s)
           
protected static boolean isLegalXmlCodePoint(int c)
          Tell whether the given character is valid in an XML document.
 void setDefaultNamespace(String s)
           
 void setNamespaceContext(NamespaceContext namespaceContext)
           
 void setPrefix(String s, String s1)
           
 void writeAttribute(String localName, String value)
           
 void writeAttribute(String namespaceUri, String localName, String value)
           
 void writeAttribute(String prefix, String namespaceUri, String localName, String value)
           
 void writeCData(String s)
           
 void writeCharacters(char[] chars, int start, int len)
           
 void writeCharacters(String s)
           
 void writeComment(String s)
           
 void writeDefaultNamespace(String s)
           
 void writeDTD(String s)
           
 void writeEmptyElement(String s)
           
 void writeEmptyElement(String s, String s1)
           
 void writeEmptyElement(String s, String s1, String s2)
           
 void writeEndDocument()
           
 void writeEndElement()
           
 void writeEntityRef(String s)
           
 void writeNamespace(String s, String s1)
           
 void writeProcessingInstruction(String s)
           
 void writeProcessingInstruction(String s, String s1)
           
 void writeStartDocument()
           
 void writeStartDocument(String s)
           
 void writeStartDocument(String s, String s1)
           
 void writeStartElement(String s)
           
 void writeStartElement(String s, String s1)
           
 void writeStartElement(String s, String s1, String s2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPLACEMENT_CHARACTER

public static final char REPLACEMENT_CHARACTER
See Also:
Constant Field Values
Constructor Detail

CleanXMLStreamWriter

public CleanXMLStreamWriter(XMLStreamWriter writer)
Method Detail

escapeCharacters

protected static String escapeCharacters(String string)
Substitutes all illegal characters in the given string by the value of REPLACEMENT_CHARACTER. If no illegal characters were found, no copy is made and the given string is returned.

Parameters:
string - the string
Returns:
same string, if not illegal characters detected; otherwise, string with illegal characters replaced with REPLACEMENT_CHARACTER

writeStartElement

public void writeStartElement(String s)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String s,
                              String s1)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String s,
                              String s1,
                              String s2)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String s,
                              String s1)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String s,
                              String s1,
                              String s2)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String s)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEndElement

public void writeEndElement()
                     throws XMLStreamException
Specified by:
writeEndElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEndDocument

public void writeEndDocument()
                      throws XMLStreamException
Specified by:
writeEndDocument in interface XMLStreamWriter
Throws:
XMLStreamException

close

public void close()
           throws XMLStreamException
Specified by:
close in interface XMLStreamWriter
Throws:
XMLStreamException

flush

public void flush()
           throws XMLStreamException
Specified by:
flush in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String localName,
                           String value)
                    throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String prefix,
                           String namespaceUri,
                           String localName,
                           String value)
                    throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String namespaceUri,
                           String localName,
                           String value)
                    throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Throws:
XMLStreamException

writeNamespace

public void writeNamespace(String s,
                           String s1)
                    throws XMLStreamException
Specified by:
writeNamespace in interface XMLStreamWriter
Throws:
XMLStreamException

writeDefaultNamespace

public void writeDefaultNamespace(String s)
                           throws XMLStreamException
Specified by:
writeDefaultNamespace in interface XMLStreamWriter
Throws:
XMLStreamException

writeComment

public void writeComment(String s)
                  throws XMLStreamException
Specified by:
writeComment in interface XMLStreamWriter
Throws:
XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(String s)
                                throws XMLStreamException
Specified by:
writeProcessingInstruction in interface XMLStreamWriter
Throws:
XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(String s,
                                       String s1)
                                throws XMLStreamException
Specified by:
writeProcessingInstruction in interface XMLStreamWriter
Throws:
XMLStreamException

writeCData

public void writeCData(String s)
                throws XMLStreamException
Specified by:
writeCData in interface XMLStreamWriter
Throws:
XMLStreamException

writeDTD

public void writeDTD(String s)
              throws XMLStreamException
Specified by:
writeDTD in interface XMLStreamWriter
Throws:
XMLStreamException

writeEntityRef

public void writeEntityRef(String s)
                    throws XMLStreamException
Specified by:
writeEntityRef in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument()
                        throws XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument(String s)
                        throws XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument(String s,
                               String s1)
                        throws XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeCharacters

public void writeCharacters(String s)
                     throws XMLStreamException
Specified by:
writeCharacters in interface XMLStreamWriter
Throws:
XMLStreamException

writeCharacters

public void writeCharacters(char[] chars,
                            int start,
                            int len)
                     throws XMLStreamException
Specified by:
writeCharacters in interface XMLStreamWriter
Throws:
XMLStreamException

getPrefix

public String getPrefix(String s)
                 throws XMLStreamException
Specified by:
getPrefix in interface XMLStreamWriter
Throws:
XMLStreamException

setPrefix

public void setPrefix(String s,
                      String s1)
               throws XMLStreamException
Specified by:
setPrefix in interface XMLStreamWriter
Throws:
XMLStreamException

setDefaultNamespace

public void setDefaultNamespace(String s)
                         throws XMLStreamException
Specified by:
setDefaultNamespace in interface XMLStreamWriter
Throws:
XMLStreamException

setNamespaceContext

public void setNamespaceContext(NamespaceContext namespaceContext)
                         throws XMLStreamException
Specified by:
setNamespaceContext in interface XMLStreamWriter
Throws:
XMLStreamException

getNamespaceContext

public NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface XMLStreamWriter

getProperty

public Object getProperty(String s)
                   throws IllegalArgumentException
Specified by:
getProperty in interface XMLStreamWriter
Throws:
IllegalArgumentException

isLegalXmlCodePoint

protected static boolean isLegalXmlCodePoint(int c)
Tell whether the given character is valid in an XML document.

Parameters:
c - - character
Returns:
true if valid in XML, false if it would make an XML invalid.


Copyright © 2015. All rights reserved.