|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.xml.base.XmlUtilImpl
@Singleton @Named public class XmlUtilImpl
This utility class contains methods that help to deal with XML.
DomUtilImpl
Field Summary | |
---|---|
private static Map<String,Character> |
ENTITY_MAP
|
private static XmlUtil |
instance
|
Constructor Summary | |
---|---|
XmlUtilImpl()
The constructor. |
Method Summary | |
---|---|
Reader |
createXmlReader(InputStream inputStream)
This method creates a Reader from the given
inputStream that uses the encoding specified in the
(potential) XML header of the InputStream s content. |
Reader |
createXmlReader(InputStream inputStream,
Charset defaultCharset)
This method creates a Reader from the given
inputStream that uses the encoding specified in the
(potential) XML header of the InputStream s content. |
String |
escapeXml(String string,
boolean escapeQuotations)
This method escapes the given string for usage in XML (or
HTML, etc.). |
void |
escapeXml(String string,
Writer writer,
boolean escapeQuotations)
This method writes the given string to the writer
while escaping special characters for XML (or HTML, etc.). |
ParserState |
extractPlainText(String htmlFragment,
StringBuilder buffer,
ParserState parserState)
This method extracts the plain text from the given htmlFragment and appends it to the given buffer . |
static XmlUtil |
getInstance()
This method gets the singleton instance of this XmlUtilImpl . |
Character |
resolveEntity(String entityName)
This method resolves an HTML entity given by entityName . |
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
---|
doInitialize, doInitialized, getInitializationState, initialize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static XmlUtil instance
getInstance()
private static final Map<String,Character> ENTITY_MAP
resolveEntity(String)
Constructor Detail |
---|
public XmlUtilImpl()
Method Detail |
---|
public static XmlUtil getInstance()
XmlUtilImpl
.getInstance()
methods and
construct new instances via the container-framework of your choice (like
plexus, pico, springframework, etc.). To wire up the dependent components
everything is properly annotated using common-annotations (JSR-250). If
your container does NOT support this, you should consider using a better
one.
public Reader createXmlReader(InputStream inputStream)
Reader
from the given
inputStream
that uses the encoding specified in the
(potential) XML header of the InputStream
s content. If no XML
header is specified, the default encoding is used.
createXmlReader
in interface XmlUtil
inputStream
- is a fresh input-stream that is supposed to point to the
content of an XML document.
inputStream
that takes respect
on the encoding specified in the (potential) XML header.public Reader createXmlReader(InputStream inputStream, Charset defaultCharset)
Reader
from the given
inputStream
that uses the encoding specified in the
(potential) XML header of the InputStream
s content. If no XML
header is specified, the default encoding is used.
createXmlReader
in interface XmlUtil
inputStream
- is a fresh input-stream that is supposed to point to the
content of an XML document.defaultCharset
- is the Charset
used if NO encoding was
specified via an XML header.
inputStream
that takes respect
on the encoding specified in the (potential) XML header.public String escapeXml(String string, boolean escapeQuotations)
string
for usage in XML (or
HTML, etc.).
escapeXml
in interface XmlUtil
string
- is the string to escape.escapeQuotations
- if true
also the ASCII quotation
characters (apos '\''
and quot '"'
) will
be escaped, else if false
quotations are untouched. Set
this to true
if you are writing the value of an
attribute.
public void escapeXml(String string, Writer writer, boolean escapeQuotations)
string
to the writer
while escaping special characters for XML (or HTML, etc.).
escapeXml
in interface XmlUtil
string
- is the string to escape.writer
- is where to write the string to.escapeQuotations
- if true
also the ASCII quotation
characters (apos '\''
and quot '"'
) will
be escaped, else if false
quotations are untouched. Set
this to true
if you are writing the value of an
attribute.public Character resolveEntity(String entityName)
entityName
.
resolveEntity
in interface XmlUtil
entityName
- is the bare name of the entity (e.g. "amp" or "uuml").
Please note that entity-names are case-sensitive.
null
if no entity exists
for the given entityName
.public ParserState extractPlainText(String htmlFragment, StringBuilder buffer, ParserState parserState)
htmlFragment
and appends it to the given buffer
.
This includes removing tags, un-escaping entities and parsing CDATA
sections. Unlike DOM parsers this method is completely fault tolerant, fast
and uses a minimum amount of memory.
extractPlainText
in interface XmlUtil
htmlFragment
- is the HTML fragment to parse.buffer
- is the buffer where the plain text will be appended to.parserState
- is the state to continue on a subsequent call for
multiple htmlFragment
s of the same HTML-document or
null
for a fresh start.
htmlFragment
. You can pass
this as parserState
argument on subsequent call to
continue parsing.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |