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 static java.util.Map<java.lang.String,OutTextPreparer> |
idxScript
Should be also static because the
OutTextPreparer.parse(Class, Map, Map) should only be called one time
for the static otxCfgHead and otxNode on first usage. |
private static OutTextPreparer |
otxCfgHead
Control for
writeToText(File, LogMessage) for the head of the text file. |
private static 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()
Constructor for empty instance.
|
XmlCfg(boolean readFromText)
Deprecated.
use
XmlCfg(). |
| Modifier and Type | Method and Description |
|---|---|
(package private) XmlCfg.XmlCfgNode |
addSubTree(java.lang.CharSequence name)
Gets the root of a
subtrees entry or adds an new created empty subtree and returns it. |
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 from XML.
|
boolean |
readCfgFile(java.io.File fText,
LogMessage log)
Read the XmlCfg content from the textual representation file.
|
boolean |
readFromJar(java.lang.Class<?> clazz,
java.lang.String pathInJarFromClazz,
LogMessage log)
Read the XmlCfg content from the textual representation in a jar file.
|
boolean |
readFromText(StringPartScan sp,
LogMessage log)
Read the XmlCfg content from the textual representation.
|
private boolean |
readFromTextNode(XmlCfg.XmlCfgNode node,
StringPartScan sp,
LogMessage log)
Read the configuration from the given text in StringPartScan already prepared.
|
(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 which can be later read with
readCfgFile(File, LogMessage)
or with readFromJar(Class, String, LogMessage). |
public static final java.lang.String version
XmlJzReader.
readFromTextNode(XmlCfgNode, StringPartScan, LogMessage)(...) read compatible, more variants.
otxNode: First write attributes necessary for NEW, then NEW and ADD,
then only "=>SUBTREE" in the better explainable order.
XmlCfg.XmlCfgNode.attribsForCheck correct filled, and new XmlCfg.XmlCfgNode.attribsArg and XmlCfg.XmlCfgNode.attribsSet
set in XmlCfg.XmlCfgNode.addAttribStorePath(String, String) and used for otxNode pattern for write
addSubTree(CharSequence) and transferNamespaceAssignment(Map) now supports
add for supplementing a given XmlCfg with new inputs by XmlJzAnalyzer.
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
private static final OutTextPreparer otxCfgHead
writeToText(File, LogMessage) for the head of the text file.protected boolean readFromText
private static final OutTextPreparer otxNode
private static java.util.Map<java.lang.String,OutTextPreparer> idxScript
OutTextPreparer.parse(Class, Map, Map) should only be called one time
for the static otxCfgHead and otxNode on first usage.
That is only in writeToText(File, LogMessage).@Deprecated public XmlCfg(boolean readFromText)
XmlCfg().readFromText - public XmlCfg()
readCfgFile(File, LogMessage) or adequate to set a configuration.static XmlCfg newCfgCfg()
XmlCfg.XmlCfgNode addSubTree(java.lang.CharSequence name)
subtrees entry or adds an new created empty subtree and returns it.
XmlCfg.XmlCfgNode.addSubTree(CharSequence) while reading a XML configuration from a text file.
The subtree is part of the XmlConfig, outside of the intrinsic given XmlCfgNode element where this is called.
XmlJzCfgAnalyzer.checkStructTree()
if it is detected that a subtree entry is necessary.
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:element
In 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 file
And this aliasInCfg is then used to search in cfg.
It is not systematically but often given that both alias nameSpace keys are equal.src - xmlnsAssign, able to add name spaces. This is used to supplement
a given configuration with new results from XmlJzCfgAnalyzer.storeInCfg(XmlJzReader).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).
XmlCfg is initialized as config file for XmlJzReader.setCfg(XmlCfg)
to read a XML files with this configuration.
It calls readFromText(StringPartScan, LogMessage).fText - The filelog - log on errorjava.nio.charset.IllegalCharsetNameExceptionjava.nio.charset.UnsupportedCharsetExceptionjava.io.FileNotFoundExceptionjava.io.IOExceptionpublic 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).
XmlCfg is initialized as config file for XmlJzReader.setCfg(XmlCfg)
to read a XML files with this configuration.clazz - Any class in the same directory as the text file to read inside the jar filepathInJarFromClazz - The relative path from the clazz to the text filelog - output of errorsjava.nio.charset.IllegalCharsetNameExceptionjava.nio.charset.UnsupportedCharsetExceptionjava.io.FileNotFoundExceptionjava.io.IOExceptionpublic 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)
readFromText(StringPartScan, LogMessage) for the while file.node - sp - log - public void writeToText(java.io.File fText,
LogMessage log)
readCfgFile(File, LogMessage)
or with readFromJar(Class, String, LogMessage).
This operation is used especially after XmlJzCfgAnalyzer.analyzeXmlStruct(File) or XmlJzCfgAnalyzer#analyzeXmlStructZip(File, String)
to write out the result.
otxCfgHead for the head of the text, with the subtree definitioons and the <root>....</root>
otxNode for all node contents,
idxScript is set.
otxNode will be called recursively for all child nodes in the otxNode script itself:
fText - destination.log - protected void writeSubNode(java.lang.Appendable wr,
java.lang.String indent,
XmlCfg.XmlCfgNode node)
throws java.io.IOException
java.io.IOExceptionprotected static void wrDataAccess(java.lang.Appendable wr,
DataAccess.DatapathElement dacc)
throws java.io.IOException
otxNode from script via <:exec:wrDataAccess(...)>wr - dacc - java.io.IOExceptionpublic 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)