Class Dtd2Def
Usage: Create an instance (always anew, no re-usage) and call
convert()
.
Currently called by the ModuleRegistry
, when a file (or resource)
with ".dtd" is found relevant as a text format definition, and by Main
directly when "task == dtd2def
", because error handling is
slightly different.
This code works on the DTM model of a dtd. It accepts a dtd in two cases
- No single name contains a colon character.
- Otherwise: No single name contains more than one(1) colon character.
The pre-colon parts are considered namespace prefices.
All occuring namespace prefices p are declared by a
<?tdom xmlns:p="name_space_uri" ?>
declaration. These declarations have the whole dtd (incl. all inclusions) as their scope, and do not conflict.
In the second mode, we need dis-ambiguation w.r.t. tags and w.r.t. names. In the current approach both is done by name mangling:
xml:lang --> xml_lang or xml_0_lang or xml_1_lang etc.Currently, the "namespace" declarations on the d2d-module-level are indeed reconstructed, but they are not needed since explicit "xmlrep" modifiers are added to each constructed definition.
A different approach would generate local modules and import them again, but this would only avoid clashes of definition names, not of input tags!
What is done, is
- create top-level tags-parser for every element
- create one top-level dummy definition as container for local definitions for attributes.
- create a global attribute definition in this global container, if this is possible without a name clash.
- otherwise create a local definition.
- if the attribute's tag conflicts with the tag of a child element
in the "first set" of the element's content model, than disambiguate by
adding some prefix to the attribute's name to create an unambiguous tag.
Technically this class returns an instance of
Module
, but it is completely resolved, thus can replace a genuine d2dResolvedModule
.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Main translation phase which visits all DTD element definitions and generates their d2d tag expression according to their dtd content model and attribute list. -
Field Summary
Modifier and TypeFieldDescriptionprotected TypedDOMGenerator.ElementAccessCollector
Analyses the "<?tdom public ..?>
" processing instructions.protected TagsRegExp
One synthetic definition, used only for containing all common attribute definitions as its local definitions.protected final int
EvidentDeclared as the default name space by an explicit "<?tdom xmlns=...?>"
processing instruction.(package private) final DTD2DTM
One single converter instanceprotected final Map<NamespaceName,
String> Maps the names of the element and tttribute definitions in the dtd to the names of the generated d2d defintions.protected final DTD.Dtd
Evidentprotected final MessageReceiver<SimpleMessage<XMLDocumentIdentifier>>
Receiver of all error messages.protected final MessageCounter
Evidentprotected final String
The name for the d2d definition module to create.protected boolean
Whether a single "<?tdom xmlns...?>"
has been found.protected Module
Evident. -
Constructor Summary
ConstructorDescriptionDtd2Def
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> p_msg, int debuglevel, DTD.Dtd input_dtd, String name) Construct a one-use instance to convert the given dtd into a d2d definition module. -
Method Summary
Modifier and TypeMethodDescriptionconvert()
Convert one DTD.Dtd to a d2d module.protected void
Make element name translation map.protected void
Make element name translation map.protected void
mapNames
(NamespaceName nn, String s, Location<XMLDocumentIdentifier> elloc) Maps the dtd NamespaceName to an internal element name, after checking that not illegal characters are in the latter by callingChars.checkName(String,Location,MessageReceiver)
.protected boolean
tryMangle
(NamespaceName nn, String name, Location<XMLDocumentIdentifier> elloc) If the name is already used, return false.
-
Field Details
-
msg
Receiver of all error messages. -
debuglevel
protected final int debuglevelEvident -
msgCounter
Evident -
input_dtd
Evident -
name
The name for the d2d definition module to create. -
accesses
Analyses the "<?tdom public ..?>
" processing instructions. etc. -
dtd2dtm
One single converter instance -
result
Evident. -
attContainer
One synthetic definition, used only for containing all common attribute definitions as its local definitions. -
defaultNamespaceURI
Declared as the default name space by an explicit "<?tdom xmlns=...?>"
processing instruction. -
dtdname2ddfname
Maps the names of the element and tttribute definitions in the dtd to the names of the generated d2d defintions. (The name is a little misleading, because the resolved names as stored in the DTM are contained, not those from the original DTD.) -
namespacesDeclared
protected boolean namespacesDeclaredWhether a single "<?tdom xmlns...?>"
has been found. If not, all DTD names are considered non-namespace-mode, and the colon ":" is not allowed to appear.
-
-
Constructor Details
-
Dtd2Def
Dtd2Def(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> p_msg, int debuglevel, DTD.Dtd input_dtd, String name) Construct a one-use instance to convert the given dtd into a d2d definition module.- Parameters:
p_msg
- target of error messags and warnings.debuglevel
- seeModuleRegistry.setTracelevel(int)
input_dtd
- the data to convertname
- the name for the d2d definition module to create
-
-
Method Details
-
convert
Convert one DTD.Dtd to a d2d module.- Decide whether we are in namespace mode by collecting the corresponding tdom pi-s.
- Convert the DTD.Dtd to a DTM.Dtd, which may fail.
- Create a translation table for all namespace names in the Dtd.
- Visit all elements and translate their content model and attribute declarations.
-
mapNames
Maps the dtd NamespaceName to an internal element name, after checking that not illegal characters are in the latter by callingChars.checkName(String,Location,MessageReceiver)
.- Parameters:
nn
- the name as occuring in the dtds
- the name as occuring in the constructed d2d definitionelloc
- the location of the source element declaration, for error messages.
-
tryMangle
If the name is already used, return false. Then the caller can try a different disambiguation mangling. Otherwise store it as a counterpart of the namespace name. Only called locally from makeElementNameTranslations_namespaceMode. -
makeElementNameTranslations_namespaceMode
Make element name translation map. First add all names without uri (non-namespace name) and with the uri selected as default (no prefix) as directly corresponding to the d2d definition name. Afterwards mangle all those with different uris, using the prefices as hint for disambiguation mangling.(This assumes that a prefix carries some semantics, namely refers to the mapping which was in effect when reading the dtd. This shall be preserved for the programmer as a mere hint. Normally we ignore "prefix" and consider only uri and localName.)
-
makeElementNameTranslations_nonNamespaceMode
Make element name translation map. Assumes that no dtd-name contains a colon ":". So the name for element from the dtd can be taken as a d2d definition name directly.
-