Package eu.bandm.tools.dtd
Class TunedDTDParser
java.lang.Object
eu.bandm.tools.rdparser.TunableParser<D>
eu.bandm.tools.rdparser.TunableParserForXml<XMLDocumentIdentifier>
eu.bandm.tools.dtd.TunedDTDParser
- Direct Known Subclasses:
EntityClassifier
,HtmlRenderer
Parser implementation, optimized for treating the idiosyncratics
of the w3c xml dtd specification.
Cf. w3c xml spec
Cf. w3c xml spec
Attention : The base classes have the following convention w.r.t errors: they use "MessageGenerator", provide "error()", "warning()" etc., and require "fatalError()" to be provided here!
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Nested classes/interfaces inherited from class eu.bandm.tools.rdparser.TunableParser
TunableParser.CharSet, TunableParser.ExtensionalCharSet
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
Is !=null iff we are currently in an elements content definition.protected CheckedMultimap_RD<String,
String> protected boolean
Set by the corresponding parameter.protected HashMap<String,
DTD.Entity> Catalog of all general entities defined in this dtd modelprotected static final MessageDisposer
static final String
Catalog of all those parameter entities which can be used as content model.protected HashMap<String,
DTD.Entity> Catalog of all parameter entities defined in this dtd modelstatic final String
Fields inherited from class eu.bandm.tools.rdparser.TunableParserForXml
asciiLetterSet, decDigitSet, encNameSet, hexDigitSet, initialSet, nameSet, prefix_GE, prefix_PE, pubidCharSet, sNoPESet, sSet, stringconstant_IGNORE, stringconstant_INCLUDE, versionNumSet
Fields inherited from class eu.bandm.tools.rdparser.TunableParser
base, in, messageReceiver, topleveldocumentid
-
Constructor Summary
ModifierConstructorDescriptionprotected
TunedDTDParser
(Reader in, @Opt XMLDocumentIdentifier id, @Opt File base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Deprecated, for removal: This API element is subject to removal in a future version.protected
TunedDTDParser
(Reader in, @Opt XMLDocumentIdentifier id, @Opt URL base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) -
Method Summary
Modifier and TypeMethodDescriptionprotected DTD.AttDef
attDef()
Parsing function.protected DTD.Attlist
Parsing function.protected DTD.AttType
attType()
Parsing function.protected String
attValue()
Parsing function.AUX_convert
(@Opt File f) Deprecated, for removal: This API element is subject to removal in a future version.protected DTD.CP
children()
Parsing function.protected DTD.Comment
comment()
Parsing function.protected void
Parsing function.constructReplacementText
(String currentlyDefined, String definition, boolean normalizeSpace) Normalizes whitespace and expands pe-refs and character refs in the literal definition value of an INTERNAL (parameter or general) entity.protected DTD.ContentModel
content()
Parsing function.protected DTD.CP
cp()
Parsing function.void
declareGeneralEntity
(String name, DTD.Entity entity) void
declareParameterEntity
(String name, DTD.Entity entity) Called by the parser, as soon as a parameter entity declaration is recognized.protected DTD.DefaultDecl
Parsing function.protected DTD.Dtd
dtd()
Parsing function.protected DTD.Element
Parsing function.protected String
encName()
Parsing function.protected String
Parsing function.protected DTD.Entity
Parsing function.protected String
Parsing function.protected DTD.Enumerated
Parsing function.protected final void
eq()
Parsing function for an equal sign with optional space before and after.protected String
eRef()
Parsing function.protected XMLDocumentIdentifier
externalId
(boolean notation) Parsing function.protected void
Toplevel parsing function, called bydtd()
andconditionalSection(DTD.Dtd)
.protected void
fatalError
(String msg) Gnerates aTunedDTDParser.ParsingFailed
exception as a "semantic signal", indicating that a sub-parser failed.protected void
ignore()
Parsing function.protected DTD.MarkupDecl
Parsing function.protected DTD.Mixed
mixed()
Parsing function.protected DTD.CP
modifierOpt
(DTD.CP cp) Parsing function.protected String
name()
Parsing function.protected DTD.CP
Auxiliary parsing function to test whether a replacement text of an entity is a well-formed content model.protected String
nmtoken()
Parsing function.protected DTD.Notation
Parsing function.static DTD.Dtd
parse
(Reader in, XMLDocumentIdentifier id, @Opt File base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Deprecated, for removal: This API element is subject to removal in a future version.static DTD.Dtd
parse
(Reader in, XMLDocumentIdentifier id, URL base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Main service access point for parsing a dtd into an internal model.static XMLDocumentIdentifier
Parse anXMLDocumentIdentifier
.static DTD.Dtd
parselocal
(String in, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Parse a local (or temporary generated) dtd declaration.protected String
peRef()
Parsing function.protected DTD.PI
pi()
Parsing function.protected String
Parsing function.void
Insert the replace text of a parameter entity (internal or external) into the input stream, framed by whitespace.protected DTD.Entity
retrieveGeneralEntity
(String name) Retrieve a general entity (internal or external) by its name, Create error msg if undefined.protected DTD.Entity
Retrieve a parameter entity (internal or external) by its name, Create error msg if undefined.protected String
retrieveReplacementText
(DTD.Entity entity) Retrieve the replacement text of an entity (parameter or general, internal or external).protected void
s()
Parsing function for required space, while expanding parameter entities.protected void
sNoPE()
Parsing function for required space, while NOT expanding parameter entities.protected void
sOpt()
Parsing function for optional space, while expanding parameter entities.protected void
sOptNoPE()
Parsing function for optional space, while NOT expanding parameter entities.protected void
storeEntityUsage
(String def, String refersTo) protected void
sWsOpt()
Parsing function for space and PEs expanding to space.protected String
Parsing function.protected String
Parsing function.protected String
Parsing function.protected DTD.XmlDecl
xmlDecl()
Parsing function.Methods inherited from class eu.bandm.tools.rdparser.TunableParserForXml
lookahead_pe, prefixedEntityName
Methods inherited from class eu.bandm.tools.rdparser.TunableParser
consume, eof, error, failure, getMessageReceiver, lookahead, lookahead, lookahead, lookahead, lookahead, lookahead_eof, match, match, match, match, matchahead, matchahead, matchahead, matchUpto, matchUpto, readExternal, setBase, setMessageReceiver, skipUpto, warning, word
-
Field Details
-
errorOnExpand
protected boolean errorOnExpandSet by the corresponding parameter. Iff true, an unreachable (/non-existing) external parsed (parameter/general) entity does generate an error message not before it is really used/expanded (which may never happen!) -
parameterEntities
Catalog of all parameter entities defined in this dtd model -
nicePE
Catalog of all those parameter entities which can be used as content model. -
generalEntities
Catalog of all general entities defined in this dtd model -
ignoreErrors
-
currentElementName
Is !=null iff we are currently in an elements content definition. The use of PEs will be recorded inDTD.Dtd.entityUsage
. -
entityUsage
-
LAZY_ENTITY_ERROR
- See Also:
-
UNPARSED_CONTENTS
- See Also:
-
-
Constructor Details
-
TunedDTDParser
protected TunedDTDParser(Reader in, @Opt @Opt XMLDocumentIdentifier id, @Opt @Opt URL base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) -
TunedDTDParser
@Deprecated(forRemoval=true) protected TunedDTDParser(Reader in, @Opt @Opt XMLDocumentIdentifier id, @Opt @Opt File base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
AUX_convert
Deprecated, for removal: This API element is subject to removal in a future version.Aux method to cnvert a fileinto an URL via URI ??? -
fatalError
Gnerates aTunedDTDParser.ParsingFailed
exception as a "semantic signal", indicating that a sub-parser failed. It is called ONLY by "match()", which is only called if the match is syntactically necessary. This exception is caught by the "speculating" parsing of entity contents. During this parsing the error receiver is inactivated (replaced byignoreErrors
- Specified by:
fatalError
in classTunableParser<XMLDocumentIdentifier>
-
declareGeneralEntity
-
declareParameterEntity
Called by the parser, as soon as a parameter entity declaration is recognized.
First it is stored toparameterEntities
.
Then a "speculative parsing" is started with the start symbolniceEntityValue()
and on success the result of this function is (additionally) stored tonicePE
. -
retrieveParameterEntity
Retrieve a parameter entity (internal or external) by its name, Create error msg if undefined.- Parameters:
name
- the name of the entity.
-
retrieveGeneralEntity
Retrieve a general entity (internal or external) by its name, Create error msg if undefined.- Parameters:
name
- the name of the entity.
-
retrieveReplacementText
Retrieve the replacement text of an entity (parameter or general, internal or external). Create error msg in case of "errorOnExpand" mode when an external entity could not be read when it was declared.- Parameters:
entity
- the entity for which the replacement text is retrieved
-
resolve
Insert the replace text of a parameter entity (internal or external) into the input stream, framed by whitespace. Is only called bycp()
for content models, and bys()
for ubiquituous whitespace.- Parameters:
name
- the name of the entity.
-
constructReplacementText
public String constructReplacementText(String currentlyDefined, String definition, boolean normalizeSpace) Normalizes whitespace and expands pe-refs and character refs in the literal definition value of an INTERNAL (parameter or general) entity. Called byentityDecl()
for the whole text, and forattValue()
, for explicitly extracted character references only. FIXME whitespace coming out of entities/char references is NOT normalized.- Parameters:
definition
- the text to expand
-
parse
public static DTD.Dtd parse(Reader in, XMLDocumentIdentifier id, URL base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Main service access point for parsing a dtd into an internal model.- Parameters:
in
- the source of the dtd to parseid
- the document id, for tracing etc.base
- from where relative includes shall be resolvederrorOnExpand
- whether any "read error" of external parsed entities is signalled not before they are expanded (which may never happen!)msg
- receiver for errors and warnings
-
parse
@Deprecated(forRemoval=true) public static DTD.Dtd parse(Reader in, XMLDocumentIdentifier id, @Opt @Opt File base, boolean errorOnExpand, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Deprecated, for removal: This API element is subject to removal in a future version. -
parselocal
public static DTD.Dtd parselocal(String in, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Parse a local (or temporary generated) dtd declaration. (Currently only called by TypedDomGenerator and /bajama/mmod/core/MMod2Dtd.java)- Parameters:
in
- sourcemsg
- error channel- Returns:
- null if parsing is not possible = error has occured
-
parseId
Parse anXMLDocumentIdentifier
. (Currently only called from TypedDomGenerator).- Parameters:
in
- source- Returns:
- null if parsing is not possible
-
dtd
Parsing function. -
xmlDecl
Parsing function. -
versionInfo
Parsing function. -
eq
protected final void eq()Parsing function for an equal sign with optional space before and after. -
versionNum
Parsing function. -
encodingDecl
Parsing function. -
encName
Parsing function. -
storeEntityUsage
-
s
protected void s()Parsing function for required space, while expanding parameter entities. -
sOpt
protected void sOpt()Parsing function for optional space, while expanding parameter entities. -
sWsOpt
protected void sWsOpt()Parsing function for space and PEs expanding to space. Used for optional space immediately preceding a closing parenthesis of a declaration>
or a conditional section]
, cf. XML standard "VC: Proper Conditional Section/PE Nesting" "VC: Proper Declaration/PE Nesting" and "VC: Proper Group/PE Nesting" -
sNoPE
protected void sNoPE()Parsing function for required space, while NOT expanding parameter entities. -
sOptNoPE
protected void sOptNoPE()Parsing function for optional space, while NOT expanding parameter entities. -
extSubset
Toplevel parsing function, called bydtd()
andconditionalSection(DTD.Dtd)
. -
conditionalSection
Parsing function. -
ignore
protected void ignore()Parsing function. Does not look for any PERef. This is possible because of "VC: Proper Conditional Section/PE Nesting" -
pi
Parsing function. -
name
Parsing function. Accepts a non-empty name according to production "Name" from XML-specs. -
nmtoken
Parsing function. Only called fromenumerated()
-
markupDecl
Parsing function. -
comment
Parsing function. -
elementDecl
Parsing function. -
content
Parsing function. -
mixed
Parsing function. -
children
Parsing function. Assume OPENING parenthesis just consumed. Leaves closing parenthesis un-consumed. -
cp
Parsing function. -
modifierOpt
Parsing function. -
entityDecl
Parsing function. Entities are encoded with the following combinations:parameter id(=fileposition) notation --------------------------------------------------------------------- true null (null) internal PE true !=null (null) external PE false null (null) internal general entity false !=null ==null external parsed gen-ent false !=null !=null external UNparsed gen-ent
Attention: iferrorOnExpand==true
, then a non-existing (non-loadable) external (parsed/unparsed) entitiy does NOT raise an error here, when being declared. Instead, this fact is encoded by the combinationreplacement==null && definition == LAZY_ENTITY_ERROR
The error message is sent LATER, iff (and when) the first attempt to expand will happen. There the combination will be changed to the combinationreplacement== ""
, to prevent further error generation.
In all non-error cases, the values of the fields definition and replacement aredefinition replacement --------------------------------------------------------------------- internal PE verbatim source text processed/expanded source text (expand char refs and PE refs) external PE read file contents ==definition (no expansion) internal gen.Ent. verbatim source text processed/expanded source text (expand char refs and PE refs) external gen.Ent. read file contents ==definition (no expansion) unparsed (general external) entity dedicated string constant (used as flag)
-
externalId
Parsing function. Normal XML document identifier (via the nonterminal "ExternalId") take the formSYSTEM systemLiteral PUBLIC pubidLiteral systemLiteral
The production "NotationDecl" from the XML standard allows additionally (via the nonterminal "PublicId")PUBLIC pubidLiteral
-
systemLiteral
Parsing function. -
pubidLiteral
Parsing function. -
entityValue
Parsing function. Returns the verbatim text input, w/o any expansion. -
eRef
Parsing function. Consumes lead in character and semicolon, but delivers only characters in between. FIXME word(hexDigitSet) includes EMPTY WORD !?!?! -
peRef
Parsing function. Consumes lead in character and semicolon, but delivers only characters in between. -
notationDecl
Parsing function. -
attlistDecl
Parsing function. -
attDef
Parsing function. DOES consume trailing sOpt(). Differs from XML specs: They start with obligate S ! This obligate s not reflected in this parser here ?!?!? FIXME -
attType
Parsing function. Does NOT consume trailing sOpt(). -
enumerated
Parsing function. -
defaultDecl
Parsing function. Does NOT consume trailing space. -
attValue
Parsing function. -
niceEntityValue
Auxiliary parsing function to test whether a replacement text of an entity is a well-formed content model. A "test run" of the parser must be set-up before this method is called in a try/catch block, and the main parser reconstructed afterwards. It calls the parser functioncp()
, which will return aDTD.CP
in case of success, or throw aTunedDTDParser.ParsingFailed
in case of error. Only called fromdeclareParameterEntity(String,DTD.Entity)
.
-
TunedDTDParser(Reader,XMLDocumentIdentifier,URL,boolean,MessageReceiver)
instead.