@MinDoc(copyright="Copyright 2005, 2009, 2016 A. Weinert", author="Albrecht Weinert", version="V.33", lastModified="27.03.2021", usage="use in XML applications", purpose="encapsulate the configuration") public class XMLconf extends Object implements Cloneable
PropMap
respectively App.prop
this class simplifies the
usage of DOM (org.w3c.dom) and SAX parsers.XMLReader
), DOM builder (as
DocumentBuilder
) and XML inputs (as
InputSource
) all according to the properties set in
this XMLconf
object.makeInputSource(CharSequence)
can be
used for inputing XML in the narrower sense as as for inputing the
transforming style sheets.XMLdoc
is build upon this class using an associated
internal XMLconf
object.Modifier and Type | Field and Description |
---|---|
boolean |
clearDefAtts
Delete HTML default attributes before output.
|
boolean |
coalescing
Unite character data in a text node.
|
String |
encoding
Coding of the XML text output.
|
boolean |
expandEmptyElements
Expand empty elements on the XML text output.
|
boolean |
expandEntityReferences
Replace references.
|
boolean |
ignoreComments
Delete comments.
|
boolean |
ignoreWhiteSpace
Ignore white space.
|
String |
impEncoding
Coding of the XML text input.
|
boolean |
namespaceAware
Parse XML with XML namespace support.
|
boolean |
newlines
Output line feeds with the XML text output.
|
boolean |
omitDeclaration
Declare XML coding in the XML output text.
|
boolean |
omitEncoding
Declare the coding with the XML text output.
|
protected String |
proxyHost
Name of the proxy server for fetching from URL.
|
protected String |
proxyPort
Port of the proxy server for fetching from URL.
|
boolean |
textNormalize
Compact the XML text output.
|
boolean |
useSchema
Parse XML validating with XML scheme en lieu de DTD.
|
boolean |
validating
Parse XML validating.
|
Constructor and Description |
---|
XMLconf()
Make with standard settings.
|
XMLconf(PropMap prop)
Make with settings from a PropMap.
|
Modifier and Type | Method and Description |
---|---|
StringBuilder |
appendProxy(StringBuilder bastel)
Append host and port as text.
|
String |
getIndent()
Indentation of the XML text output.
|
int |
getIndentSize()
Indentation of the XML text output.
|
String |
getProxyHost()
Name of the proxy server for fetching from URL.
|
String |
getProxyPort()
Port of the proxy server for fetching from URL.
|
String |
getSchemaSource()
Name of a local schema.
|
boolean |
isProxySet()
Use a proxy server when fetching from URL.
|
DocumentBuilder |
makeDocumentBuilder(ParseErrorHandler dbeh)
Make a DocumentBuilder.
|
InputSource |
makeInputSource(CharSequence fileOrURL)
Make a XML input.
|
StreamSource |
makeStreamSource(CharSequence fileOrURL)
Make a XML input.
|
Transformer |
makeTransformer(Source transI)
Make a XML style sheet transformer.
|
XMLReader |
makeXMLReader(ContentHandler cnth,
ErrorHandler dbeh)
Make a XML parser / reader.
|
XMLReader |
makeXMLReader(SAXHandler handler)
Make a XML reader / SAX parser.
|
void |
set(PropMap prop)
Set the properties by a PropMap object.
|
void |
setClearDefAtts(boolean clearDefAtts)
Standard setter for
clearDefAtts . |
void |
setCoalescing(boolean coalescing)
Standard setter for
coalescing . |
void |
setEncoding(String encoding)
Set the coding of the XML text (input and) output.
|
void |
setExpandEmptyElements(boolean expandEmptyElements)
Standard setter for
expandEmptyElements . |
void |
setExpandEntityReferences(boolean expandEntityReferences)
Standard setter for
expandEntityReferences . |
void |
setIgnoreComments(boolean ignoreComments)
Standard setter for
ignoreComments . |
void |
setIgnoreWhiteSpace(boolean ignoreWhiteSpace)
Set
ignoreWhiteSpace . |
void |
setImpEncoding(String impEncoding)
Set the coding of the XML text input.
|
void |
setIndent(String indent)
Set the indentation String.
|
void |
setIndentSize(int indentSize)
Set the indentation length.
|
void |
setNamespaceAware(boolean namespaceAware)
Standard setter for
namespaceAware . |
void |
setNewlines(boolean newlines)
Standard setter for
newlines . |
void |
setOmitDeclaration(boolean omitDeclaration)
Standard setter for
omitDeclaration . |
void |
setOmitEncoding(boolean omitEncoding)
Standard setter for
omitEncoding . |
void |
setProxyHost(CharSequence proxyHost)
Set the name of the proxy server for fetching from URL.
|
void |
setProxyPort(CharSequence proxyPort)
Set the port of the proxy server for fetching from URL.
|
void |
setProxySet(boolean proxySet)
Use a proxy server when fetching from URL.
|
void |
setSchemaSource(String schemaSource)
Set the name of a local schema.
|
void |
setTextNormalize(boolean textNormalize)
Standard setter for
textNormalize . |
void |
setUseSchema(boolean useSchema)
Set parse XML validating with XML scheme en lieu de DTD.
|
void |
setValidating(boolean validating)
Set validating XML parsing.
|
void |
simplifyInput()
Settings for simplified, non checking input.
|
protected String proxyHost
getProxyHost()
protected String proxyPort
getProxyPort()
public boolean validating
public boolean namespaceAware
public boolean useSchema
public boolean ignoreWhiteSpace
validating
has to be true on most XML implementations if
ignoreWhiteSpace
respectively
ignoringElementWhiteSpaceContent is true.public boolean expandEntityReferences
public boolean coalescing
public boolean ignoreComments
public boolean clearDefAtts
clearHTMLdefAtts(Element)
.public String impEncoding
public String encoding
omitEncoding
is not true).public boolean omitDeclaration
public boolean newlines
public boolean omitEncoding
public boolean textNormalize
public boolean expandEmptyElements
public XMLconf()
XMLconf(PropMap)
,
set(PropMap)
,
simplifyInput()
public XMLconf(PropMap prop)
prop
- stating properties; null means default settingsset(PropMap)
,
simplifyInput()
public void set(PropMap prop)
XMLconf
object will be set
according to the PropMap
object prop
.prop
nothing happens
in each case.prop
in the order given. The first name given above
is the property name within XMLdoc.setProxySet()
).prop
- source of the properties to be usedXMLconf(PropMap)
,
simplifyInput()
public void simplifyInput()
coalescing
, ignoreComments
as well as
ignoreWhiteSpace
true and sets namespaceAware
and validating
false.set(PropMap)
public boolean isProxySet()
proxyHost
and
proxyHost
are effective.public void setProxySet(boolean proxySet)
proxyHost
and
proxyHost
are effective.setProxySet()
has to be called
after setProyHost()
and
setProyPort()
, to make the changes effective. (If
using makeInputSource()
one
doesn't have to bother a this method does it right by itself.)proxySet
- true if a proxy is to be used.public String getProxyHost()
proxySet
public void setProxyHost(CharSequence proxyHost)
proxyHost
will be stripped from surrounding white
space; empty will be taken as null.prooxyHost
or
proxyPort
will only be effective after calling
setProxySet(true)
.proxyHost
- the proxy servergetProxyHost()
public String getProxyPort()
proxySet
public void setProxyPort(CharSequence proxyPort)
proxyPort
will be stripped from surrounding white
space; empty will be taken as null.prooxyHost
or
proxyPort
will only be effective after calling
setProxySet(true)
.proxyPort
- the proxy port (a number as String)getProxyPort()
public StringBuilder appendProxy(StringBuilder bastel)
proxySet
,
proxyHost
and proxyPort
to bastel
is appended either "no proxy" or
"proxy host = cache, port = 8080"
(e.g. the default).bastel
- the StringBuilder to append to; if null it will be made with
starting capacity 80 characterpublic final void setValidating(boolean validating)
validating
- true if XML parsing should be validating (requires
schema or documentation type)public final void setUseSchema(boolean useSchema)
useSchema
- true means a schema and not a DTD is to be used for
validatingpublic final String getSchemaSource()
useSchema
true it will be taken as the name of a local
schema file for schema validation. public void setSchemaSource(String schemaSource)
schemaSource
stripped from surrounding white space is not empty
it will be used as new local source (file) of a schema. Otherwise the
property schemaSource
will be set null.schemaSource
- a schema file nameTextHelper.trimUq(CharSequence, String)
public void setImpEncoding(String impEncoding)
encoding
will be stripped from surrounding white
spaces and then used to set impEncoding
.ComVar.FILE_ENCODING
.impEncoding
- the encoding for XML inputpublic void setEncoding(String encoding)
encoding
will be stripped from surrounding white
spaces and then used to set encoding
.encoding
- the encoding for XML input and outputpublic String getIndent()
public void setIndent(String indent)
indent
- an indentation string or nullgetIndent()
,
getIndentSize()
public int getIndentSize()
public void setIndentSize(int indentSize)
indentSize
- new indentation length 0..18; getIndent()
,
getIndentSize()
public void setClearDefAtts(boolean clearDefAtts)
clearDefAtts
. clearDefAtts
- true means delete HTML default attributes before outputpublic void setExpandEmptyElements(boolean expandEmptyElements)
expandEmptyElements
. expandEmptyElements
- true means expand respectively auto-close empty
elements on the XML text outputpublic void setNamespaceAware(boolean namespaceAware)
namespaceAware
. namespaceAware
- true means be aware of namespacespublic void setNewlines(boolean newlines)
newlines
. newlines
- true means output line feeds with the XML text outputpublic void setOmitDeclaration(boolean omitDeclaration)
omitDeclaration
. omitDeclaration
- false means a XML declaration will prepend the outputpublic void setOmitEncoding(boolean omitEncoding)
omitEncoding
. omitEncoding
- true means declare the coding with the XML text outputpublic void setTextNormalize(boolean textNormalize)
textNormalize
. textNormalize
- true means make a compact XML text outputpublic final void setCoalescing(boolean coalescing)
coalescing
. coalescing
- see coalescing
public void setExpandEntityReferences(boolean expandEntityReferences)
expandEntityReferences
. expandEntityReferences
- expandEntityReferences
public final void setIgnoreComments(boolean ignoreComments)
ignoreComments
. ignoreComments
- ignoreComments
public final void setIgnoreWhiteSpace(boolean ignoreWhiteSpace)
ignoreWhiteSpace
. ignoreWhiteSpace
- ignoreWhiteSpace
public XMLReader makeXMLReader(ContentHandler cnth, ErrorHandler dbeh) throws ParserConfigurationException, SAXException, SAXNotRecognizedException, SAXNotSupportedException
cnth
- a ContentHandler if given; may here be null, but a SAX parser
without ContentHandler makes no sense in most casesdbeh
- ErrorHandler, for example a ParseErrorHandler
object;
may be nullSAXParser
as XMLReader
ParserConfigurationException
- if a SAXparser with the basic
properties (namespace, validating) set in this XMLconf object
can't be madeSAXException
- the rest of the errors (its the enclosing type) while
making the internal SAXParser or the XMLReader
SAXNotRecognizedException
- if the XMLReader made does not honour
a property to be set, like for example
MLHelper.JAXP_SCHEMA_LANGUAGE
SAXNotSupportedException
- if the XMLReader made does know /
recognise a property to be set, but won't accept the value,
like e.g. for MLHelper.W3C_XML_SCHEMA
public XMLReader makeXMLReader(SAXHandler handler) throws ParserConfigurationException, SAXException, SAXNotRecognizedException, SAXNotSupportedException
handler
- ContentHandler and ErrorHandler in one object —
supplied as an inheritor of SAXHandler
; may be null, even
if that does not make any sense in virtually all casesSAXParser
as XMLReader
ParserConfigurationException
- if a SAXparser with the basic
properties (namespace, validating) set in this XMLconf object
can't be madeSAXException
- the rest of the errors (its the enclosing type) while
making the internal SAXParser or the XMLReader
SAXNotRecognizedException
- if the XMLReader made does not honour
a property to be set, like for example
MLHelper.JAXP_SCHEMA_LANGUAGE
SAXNotSupportedException
- if the XMLReader made does know /
recognise a property to be set, but won't accept the value,
like e.g. for MLHelper.W3C_XML_SCHEMA
public DocumentBuilder makeDocumentBuilder(ParseErrorHandler dbeh) throws FactoryConfigurationError, IllegalArgumentException, ParserConfigurationException
dbeh
- ErrorHandler, e.g. a
ParseErrorHandler
-Objekt; may be nullFactoryConfigurationError
- forwardedParserConfigurationException
- if a DocumentBuilder with the basic
properties (namespace, validating) set in this XMLconf object
can't be madeIllegalArgumentException
- if a property to be set, that is not
known by the SAX/DOM implementation, like for example
MLHelper.JAXP_SCHEMA_LANGUAGE
public StreamSource makeStreamSource(CharSequence fileOrURL) throws IllegalArgumentException, IOException
fileOrURL
- denotation of the inputSource
IllegalArgumentException
- if fileOrURL null or emptyIOException
- on problems making the Source
public InputSource makeInputSource(CharSequence fileOrURL) throws IllegalArgumentException, IOException
fileOrURL
- denotation of the inputInputSource
objectIllegalArgumentException
- if fileOrURL null or emptyIOException
- on problems making the Input
public Transformer makeTransformer(Source transI) throws IllegalArgumentException, TransformerConfigurationException
transI
- input source, like for example one made by
makeInputSource(CharSequence)
IllegalArgumentException
- if transI is nullTransformerConfigurationException
- on problems setting relevant
properties