public class XmlCfg
extends java.lang.Object
XmlJzReader.readCfg(java.io.File)
from a given xml file.
<tag attr="!storepath" xmlinput:data="!getOrCreateCurrentOutputPath()">!contentStorePath(text) ... <subelements ....
DataAccess.DataPathElement
with invocation of DataAccess.storeValue(org.vishia.util.DataAccess.DatapathElement, Object, Object, boolean)
or DataAccess#invokeMethod(org.vishia.util.DataAccess.DatapathElement, Class, Object, boolean, boolean, Object[])
.
xmlinput:data
contains the path to get or create the output instance for this element
based on the current output instance.
<?xml version="1.0" encoding="utf-8"?> <xmlinput:root xmlns:xmlinput="www.vishia.org/XmlReader-xmlinput"> <xmlinput:subtree xmlinput:name="NAMESUBTREE"> ..... <xmlinput:cfg> ......
<xmlinput:subtree ...
contains some templates of sub trees which should be parsed in the user.xml.
Typically they are recursively sub trees.
<xmlinput:cfg ...
contains the configuration from the root node of the user.xml.
<tag attr="!@attr" .... xmlinput:data="!newInstance(attr)" >!storeText(text, attr)If the store path starts with
!@
then the attribute value of a given attr
is locally stored with a name (key) following after "!@...". It may be usual the same as the attribute name.
That stored attribute value can be used for the datapath-routine as argument to create the instance to store the data,
or to invoke the store routine for the text of the element.
If attribute values should be used as arguments for the xmlinput:data
routine, then no attribute values should be stored
with a storePath (attr="!storePath
). Both approaches are exclusively.
<tag attr="!CHECK"/> <tag attr="key1">!invoke1() <tag attr="key2">!invoke2()The first
<tag ...ATTR="!CHECK" ...>
designates this attribute to check it, use its value as key.
Any following <tag ...ATTR="..." ...>
builds a key with the tag, the attribute and the value
to search the proper config node with given data in user.xml. So they are different entries for the same tag but with different attribute values.
The key for this element is internally build with tag@attr="key1"@anotherAttr="itsKey"
<subtreeTag xmlinput:subtree="subtreeTag" xmlinput:data="!addmodule()"/>If a node
<subtreeTag ...
was found in the user.xml, then via xmlinput:subtree="subtreeTag"
the named
<xmlinput:subtree ....
is searched in the config file. That is used for sub nodes from this position.
Typically this is proper to use for recursively content in the user.xml. Then the sub tree contains a link to the same sub tree itself.
The config node above itself can contain more attributes but no content.
Modifier and Type | Class and Description |
---|---|
static class |
XmlCfg.AttribDstCheck
An instance of this class describes for any attribute how to proceed-
|
static class |
XmlCfg.XmlCfgNode
This class describes one node as pattern how the content of a parsed xml file should be stored.
|
Modifier and Type | Field and Description |
---|---|
(package private) java.util.Map<java.lang.String,DataAccess.IntegerIx> |
attribNameVale |
private OutTextPreparer |
otxCfgHead
Control for
writeToText(File, LogMessage) for the head of the text file. |
private OutTextPreparer |
otxNode
Control for writing a Node.
|
protected boolean |
readFromText |
(package private) XmlCfg.XmlCfgNode |
rootNode |
(package private) java.util.Map<java.lang.String,java.util.List<XmlCfg.XmlCfgNode>> |
subtreeForward
entries of usage of subtree instances which are defined later in the text.
|
(package private) java.util.Map<java.lang.String,XmlCfg.XmlCfgNode> |
subtrees
Configuration for subtrees which can occur anywhere in the XML file.
|
static java.lang.String |
version
Version, License and History: See
XmlJzReader . |
(package private) java.util.Map<java.lang.String,java.lang.String> |
xmlnsAssign
Assignment between nameSpace-value and nameSpace-alias gotten from the xmlns:ns="value" declaration in the read cfg.XML file.
|
Constructor and Description |
---|
XmlCfg(boolean readFromText) |
Modifier and Type | Method and Description |
---|---|
(package private) XmlCfg.XmlCfgNode |
addSubTree(java.lang.CharSequence name)
Invoked from
XmlCfg.XmlCfgNode.addSubTree(CharSequence) to execute for the whole configuration. |
void |
checkCfg(LogMessage log)
Detect different entries in sub node and node via sub tree to clarify it.
|
private void |
checkCfg(XmlCfg.XmlCfgNode node,
LogMessage log,
java.util.HashMap<XmlCfg.XmlCfgNode,XmlCfg.XmlCfgNode> nodesChecked,
int recursively) |
(package private) void |
finishReadCfg()
TODO this operation may be non sensible, change XmlJzReader, TODO
It transfers the
subtrees content to the real sub trees of nodes. |
java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> |
iterNamespace()
Returns an iterator over all internal name space assignments.
|
(package private) static XmlCfg |
newCfgCfg()
Creates the configuration to read a config.xml file.
|
boolean |
readCfgFile(java.io.File fText,
LogMessage log)
Read the XmlCfg content from the textual representation.
|
boolean |
readFromJar(java.lang.Class<?> clazz,
java.lang.String pathInJarFromClazz,
LogMessage log)
Read the XmlCfg content from the textual representation.
|
boolean |
readFromText(StringPartScan sp,
LogMessage log)
Read the XmlCfg content from the textual representation.
|
private boolean |
readFromTextNode(XmlCfg.XmlCfgNode node,
StringPartScan sp,
LogMessage log) |
(package private) void |
transferNamespaceAssignment(java.util.Map<java.lang.String,java.lang.String> src)
Transfer the nameSpace assignments read from
XmlJzReader stored there in XmlJzReader.namespaces
in backward direction in the xmlnsAssign . |
protected static void |
wrDataAccess(java.lang.Appendable wr,
DataAccess.DatapathElement dacc)
Writes the data access path, called inside
otxNode from script via <:exec:wrDataAccess( |
protected void |
writeSubNode(java.lang.Appendable wr,
java.lang.String indent,
XmlCfg.XmlCfgNode node) |
void |
writeToText(java.io.File fText,
LogMessage log)
writes the content of the config to a text file.
|
public static final java.lang.String version
XmlJzReader
.
readCfgFile(File, LogMessage)
, readFromJar(Class, String, LogMessage)
, readFromText(StringPartScan, LogMessage)
Now the representation can be better editable as normal syntactical tet.
transferNamespaceAssignment(Map)
does no more call src.clean(), instead it is called outside.
The clean is not a task of this operation. Clean() is necessary before read a new Xml file in XmlJzReader
instead.
The solution before was dirty.
writeToText(File, LogMessage)
as new concept starting but not finished in 2022.
newCfgCfg()
also setContentStorePath(...) for the xmlinput:subtree node itself.
it is a special case, hence first not regarded, but possible and necessary.
Some sorting and comments there.
XmlCfg.XmlCfgNode.nameSpaceDef
to store namespace definitions in user data.
XmlCfg.XmlCfgNode.allArgNames
gets initial name, value, tag and text as unified for ReadCfgCfg and the used cfg
DataAccess
usage of variables.
XmlCfgNode#addFromSubtree(XmlCfgNode)
copies only not defined attributes from the subtree block definition.
hence the definition of an attribute in the call subtree line is prior to the attribute defined in the subtree.
subtreeForward
. It is possible that a definition in a subtree uses another subtree which is declared below.
The information from the subtree will be copied on end of reading config. #finishReadCfg(Map)
(moved from XmlJzReader) does it.
XmlCfg.XmlCfgNode.subnodes
.
newCfgCfg()
more simple. Don't use the root node as config for root node.
#newCfgReadStruct()
accepts all XML structures, stores the structure of the nodes and attributes.
java.util.Map<java.lang.String,java.lang.String> xmlnsAssign
java.util.Map<java.lang.String,XmlCfg.XmlCfgNode> subtrees
java.util.Map<java.lang.String,java.util.List<XmlCfg.XmlCfgNode>> subtreeForward
#finishReadCfg(Map)
.XmlCfg.XmlCfgNode rootNode
java.util.Map<java.lang.String,DataAccess.IntegerIx> attribNameVale
protected final boolean readFromText
private OutTextPreparer otxCfgHead
writeToText(File, LogMessage)
for the head of the text file.private OutTextPreparer otxNode
static XmlCfg newCfgCfg()
XmlCfg.XmlCfgNode addSubTree(java.lang.CharSequence name)
XmlCfg.XmlCfgNode.addSubTree(CharSequence)
to execute for the whole configuration.name
- void transferNamespaceAssignment(java.util.Map<java.lang.String,java.lang.String> src)
XmlJzReader
stored there in XmlJzReader.namespaces
in backward direction in the xmlnsAssign
. Backward means, from the path to the namespace key.
This is necessary because a read XML file uses the same nameSpace string but maybe different namespace keys.
The simple thinking it, it's the same. Then this operation or field xmlnsAssign
would not be necessary.
But this thinking is consequently worse. Follow the nameSpace concept in XML:
<... xmlns:keyXY="nameSpace/string" .... <keyXY:elementIn an XML file instance the
keyXY
is only a locally valid. The real used value is the "nameSpace/string"
To search the element here in cfg this nameSpace string is used, not the short nameSpace alias.
String aliasInCfg = xmlnsAssign.get("nameSpace/String"); // value from the read XML fileAnd this
aliasInCfg
is then used to search in cfg.
It is not systematically but often given that both alias nameSpace keys are equal.src
- void finishReadCfg()
subtrees
content to the real sub trees of nodes.
Better search in subtrees
while parsing XML.transferNamespaceAssignment(Map)
, should be called outside.public boolean readCfgFile(java.io.File fText, LogMessage log) throws java.nio.charset.IllegalCharsetNameException, java.nio.charset.UnsupportedCharsetException, java.io.FileNotFoundException, java.io.IOException
writeToText(File, LogMessage)
It calls readFromText(StringPartScan, LogMessage)
.fText
- The filelog
- log on errorjava.nio.charset.IllegalCharsetNameException
java.nio.charset.UnsupportedCharsetException
java.io.FileNotFoundException
java.io.IOException
public boolean readFromJar(java.lang.Class<?> clazz, java.lang.String pathInJarFromClazz, LogMessage log) throws java.nio.charset.IllegalCharsetNameException, java.nio.charset.UnsupportedCharsetException, java.io.FileNotFoundException, java.io.IOException
writeToText(File, LogMessage)
It calls readFromText(StringPartScan, LogMessage)
.fText
- The filelog
- log on errorjava.nio.charset.IllegalCharsetNameException
java.nio.charset.UnsupportedCharsetException
java.io.FileNotFoundException
java.io.IOException
public boolean readFromText(StringPartScan sp, LogMessage log)
writeToText(File, LogMessage)
sp
- should be initialized with the textlog
- log on errorprivate boolean readFromTextNode(XmlCfg.XmlCfgNode node, StringPartScan sp, LogMessage log)
public void writeToText(java.io.File fText, LogMessage log)
fText
- log
- protected void writeSubNode(java.lang.Appendable wr, java.lang.String indent, XmlCfg.XmlCfgNode node) throws java.io.IOException
java.io.IOException
protected static void wrDataAccess(java.lang.Appendable wr, DataAccess.DatapathElement dacc) throws java.io.IOException
otxNode
from script via <:exec:wrDataAccess(...)>wr
- dacc
- java.io.IOException
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> iterNamespace()
xmlnsAssign
container, prevent for change.public void checkCfg(LogMessage log)
log
- private void checkCfg(XmlCfg.XmlCfgNode node, LogMessage log, java.util.HashMap<XmlCfg.XmlCfgNode,XmlCfg.XmlCfgNode> nodesChecked, int recursively)