Package org.gedcomx.util
Class CleanXMLStreamWriter
- java.lang.Object
-
- org.gedcomx.util.CleanXMLStreamWriter
-
- All Implemented Interfaces:
XMLStreamWriter
public class CleanXMLStreamWriter extends Object implements XMLStreamWriter
DelegatingXMLStreamWriterthat 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
Fields Modifier and Type Field Description static charREPLACEMENT_CHARACTER
-
Constructor Summary
Constructors Constructor Description CleanXMLStreamWriter(XMLStreamWriter writer)
-
Method Summary
-
-
-
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 ofREPLACEMENT_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:
writeStartElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartElement
public void writeStartElement(String s, String s1) throws XMLStreamException
- Specified by:
writeStartElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartElement
public void writeStartElement(String s, String s1, String s2) throws XMLStreamException
- Specified by:
writeStartElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(String s, String s1) throws XMLStreamException
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(String s, String s1, String s2) throws XMLStreamException
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(String s) throws XMLStreamException
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEndElement
public void writeEndElement() throws XMLStreamException- Specified by:
writeEndElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEndDocument
public void writeEndDocument() throws XMLStreamException- Specified by:
writeEndDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
close
public void close() throws XMLStreamException- Specified by:
closein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
flush
public void flush() throws XMLStreamException- Specified by:
flushin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException
- Specified by:
writeAttributein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String namespaceUri, String localName, String value) throws XMLStreamException
- Specified by:
writeAttributein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String namespaceUri, String localName, String value) throws XMLStreamException
- Specified by:
writeAttributein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeNamespace
public void writeNamespace(String s, String s1) throws XMLStreamException
- Specified by:
writeNamespacein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeDefaultNamespace
public void writeDefaultNamespace(String s) throws XMLStreamException
- Specified by:
writeDefaultNamespacein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeComment
public void writeComment(String s) throws XMLStreamException
- Specified by:
writeCommentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeProcessingInstruction
public void writeProcessingInstruction(String s) throws XMLStreamException
- Specified by:
writeProcessingInstructionin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeProcessingInstruction
public void writeProcessingInstruction(String s, String s1) throws XMLStreamException
- Specified by:
writeProcessingInstructionin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeCData
public void writeCData(String s) throws XMLStreamException
- Specified by:
writeCDatain interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeDTD
public void writeDTD(String s) throws XMLStreamException
- Specified by:
writeDTDin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEntityRef
public void writeEntityRef(String s) throws XMLStreamException
- Specified by:
writeEntityRefin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument() throws XMLStreamException- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument(String s) throws XMLStreamException
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument(String s, String s1) throws XMLStreamException
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeCharacters
public void writeCharacters(String s) throws XMLStreamException
- Specified by:
writeCharactersin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeCharacters
public void writeCharacters(char[] chars, int start, int len) throws XMLStreamException- Specified by:
writeCharactersin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
getPrefix
public String getPrefix(String s) throws XMLStreamException
- Specified by:
getPrefixin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
setPrefix
public void setPrefix(String s, String s1) throws XMLStreamException
- Specified by:
setPrefixin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
setDefaultNamespace
public void setDefaultNamespace(String s) throws XMLStreamException
- Specified by:
setDefaultNamespacein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
setNamespaceContext
public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException
- Specified by:
setNamespaceContextin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
getNamespaceContext
public NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContextin interfaceXMLStreamWriter
-
getProperty
public Object getProperty(String s) throws IllegalArgumentException
- Specified by:
getPropertyin interfaceXMLStreamWriter- 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.
-
-