Top Description Fields Constructors Methods
com.ctc.wstx.dtd

public Class FullDTDReader

extends MinimalDTDReader
Class Inheritance
Imports
java.io.IOException, .Writer, java.net.URL, java.text.MessageFormat, java.util.*, javax.xml.stream.Location, .XMLReporter, .XMLStreamException, javax.xml.stream.events.NotationDeclaration, org.codehaus.stax2.validation.XMLValidationProblem, .XMLValidator, com.ctc.wstx.api.ReaderConfig, com.ctc.wstx.cfg.ErrorConsts, .XmlConsts, com.ctc.wstx.ent.*, com.ctc.wstx.evt.WNotationDeclaration, com.ctc.wstx.exc.WstxIOException, com.ctc.wstx.io.WstxInputData, .WstxInputSource, com.ctc.wstx.util.*

Reader that reads in DTD information from internal or external subset.

There are 2 main modes for DTDReader, depending on whether it is parsing internal or external subset. Parsing of internal subset is somewhat simpler, since no dependency checking is needed. For external subset, handling of parameter entities is bit more complicated, as care has to be taken to distinguish between using PEs defined in int. subset, and ones defined in ext. subset itself. This determines cachability of external subsets.

Reader also implements simple stand-alone functionality for flattening DTD files (expanding all references to their eventual textual form); this is sometimes useful when optimizing modularized DTDs (which are more maintainable) into single monolithic DTDs (which in general can be more performant).

Author
Tatu Saloranta

Field Summary

Modifier and TypeField and Description
pack-priv static final Boolean
pack-priv static final Boolean
pack-priv static final boolean
INTERN_SHARED_NAMES

Flag that can be changed to enable or disable interning of shared names; shared names are used for enumerated values to reduce memory usage.

pack-priv final PrefixedName
pack-priv boolean
mAnyDTDppFeatures

Flag that indicates if any DTD++ features have been encountered (in DTD++-supporting mode).

pack-priv final boolean
mCfgFullyValidating

This flag indicates whether we should build a validating 'real' validator (true, the usual case), or a simpler pseudo-validator that can do all non-validation tasks that are based on DTD info (entity expansion, notation references, default attribute values).

pack-priv final boolean
pack-priv boolean
mCheckForbiddenPEs

This flag is used to catch uses of PEs in the internal subset within declarations (full declarations are ok, but not other types)

pack-priv final int
pack-priv DefaultAttrValue
mCurrAttrDefault

This is the attribute default value that is currently being parsed.

pack-priv String
mCurrDeclaration

Keyword of the declaration being currently parsed (if any).

pack-priv String
mDefaultNsURI

Currently active default namespace URI.

pack-priv LinkedHashMap<PrefixedName, DTDElement>
mElements

Contains definition of elements and matching content specifications.

pack-priv final DTDEventListener
pack-priv boolean
mExpandingPE

Flag that indicates if the currently expanding (or last expanded) entity is a Parameter Entity or General Entity.

pack-priv DTDWriter
pack-priv HashMap<String, EntityDecl>
mGeneralEntities

Set of generic entities defined so far in this subset.

pack-priv int
mIncludeCount

Nesting count for conditionally included sections; 0 means that we are not inside such a section.

pack-priv HashMap<String, String>
mNamespaces

Prefix-to-NsURI mappings for this DTD, if any: lazily constructed when needed

pack-priv HashMap<String, Location>
mNotationForwardRefs

Finally, we need to keep track of Notation references that were made prior to declaration.

pack-priv HashMap<String, NotationDeclaration>
mNotations

Set of notations defined so far.

pack-priv HashMap<String, EntityDecl>
mParamEntities

Set of parameter entities defined so far in the currently parsed subset.

pack-priv final HashMap<String, EntityDecl>
mPredefdGEs

Set of general entities already defined for the subset being parsed; namely, PEs defined in the internal subset passed when parsing matching external subset.

pack-priv final HashMap<String, NotationDeclaration>
mPredefdNotations

Notations already parsed before current subset; that is, notations from the internal subset if we are currently parsing matching external subset.

pack-priv final HashMap<String, EntityDecl>
mPredefdPEs

Set of parameter entities already defined for the subset being parsed; namely, PEs defined in the internal subset passed when parsing matching external subset.

pack-priv Set<String>
mRefdGEs

Set of general entities (ids) that have been referenced by this DTD; only maintained for external subsets, and only as long as no pre-defined GEs have been referenced.

pack-priv Set<String>
mRefdPEs

Set of parameter entities (ids) that have been referenced by this DTD; only maintained for external subsets, and only as long as no pre-defined PE has been referenced.

pack-priv HashMap<String, String>
mSharedEnumValues

Map used for sharing legal enumeration values; used since oftentimes same enumeration values are used with multiple attributes

pack-priv HashMap<PrefixedName, PrefixedName>
mSharedNames

Map used to shared PrefixedName instances, to reduce memory usage of (qualified) element and attribute names

pack-priv transient TextBuffer
pack-priv boolean
mUsesPredefdEntities

Flag used to keep track of whether current (external) subset has referenced at least one PE that was pre-defined.

pack-priv boolean
mUsesPredefdNotations

Flag used to keep track of whether current (external) subset has referenced at least one notation that was defined in internal subset.

pack-priv TextBuffer
mValueBuffer

Text buffer used for constructing expansion value of the internal entities, and for default attribute values.

Inherited from com.ctc.wstx.dtd.MinimalDTDReader:
mIsExternal

Constructor Summary

AccessConstructor and Description
private
FullDTDReader(WstxInputSource input, ReaderConfig cfg, boolean constructFully, int xmlVersion)

Constructor used for reading/skipping internal subset.

private
FullDTDReader(WstxInputSource input, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion)

Constructor used for reading external subset.

private
FullDTDReader(WstxInputSource input, ReaderConfig cfg, boolean isExt, DTDSubset intSubset, boolean constructFully, int xmlVersion)

Common initialization part of int/ext subset constructors.

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
_reportWarning(XMLReporter rep, String probType, String msg, Location loc)

private void
private void
private String
attrDesc(Object elem, PrefixedName attrName)

protected String
checkDTDKeyword(String exp)

Method called to verify whether input has specified keyword; if it has, returns null and points to char after the keyword; if not, returns whatever constitutes a keyword matched, for error reporting purposes.

private void
private boolean

Returns:

True, if input contains 'PUBLIC' keyword; false if it contains 'SYSTEM'; otherwise throws an exception.
checkPublicSystemKeyword
(char c)

protected void
checkXmlIdAttr(int type)

protected void
checkXmlSpaceAttr(int type, WordResolver enumValues)

private static char
combineArities(char arity1, char arity2)

private char

Returns:

Next character from the current input block, if any left; NULL if end of block (entity expansion)
dtdNextIfAvailable
()

private String
protected boolean
ensureInput(int minAmount)

Overrides com.ctc.wstx.sr.StreamScanner.ensureInput.

Method called to make sure current main-level input buffer has at least specified number of characters available consequtively, without having to call loadMore.

private String
private void
expandPE()

Method called to handle expansion of parameter entities.

public EntityDecl
findEntity(String entName)

Overrides com.ctc.wstx.dtd.MinimalDTDReader.findEntity.

Method that may need to be called by attribute default value validation code, during parsing....

protected EntityDecl
findEntity(String
Identifier of the entity to find
id
,
Object
If Boolean.TRUE, we are expanding a general entity
arg
)

Overrides com.ctc.wstx.dtd.MinimalDTDReader.findEntity.

Abstract method for sub-classes to implement, for finding a declared general or parsed entity.

private PrefixedName
findSharedName(String prefix, String localName)

Method used to 'intern()' qualified names; main benefit is reduced memory usage as the name objects are shared.

public static DTDSubset
flattenExternalSubset(WstxInputSource
Input source used to read the main external subset
src
,
Writer
Writer to output processed DTD content to
flattenWriter
,
boolean
If true, will pass comments to the writer; if false, will strip comments out
inclComments
,
boolean
If true, will include conditional block markers, as well as intervening content; if false, will strip out both markers and ignorable sections.
inclConditionals
,
boolean
If true, will output parameter entity declarations; if false will parse and use them, but not output.
inclPEs
)

Method that will parse, process and output contents of an external DTD subset.

private void
private LinkedHashMap<PrefixedName, DTDElement>
private char
getNextExpanded()

Method that will get next character, and either return it as is (for normal chars), or expand parameter entity that starts with next character (which has to be '%').

private TextBuffer
private void
handleAttlistDecl()

Note

when this method is called, the keyword itself has been succesfully parsed.

private void
handleAttrDecl(DTDElement
Element that contains this attribute
elem
,
char
First character of what should be the attribute name
c
,
int
Sequential index number of this attribute as children of the element; used for creating bit masks later on.
index
,
Location
Location of the element name in attribute list declaration
loc
)

private void
handleDeclaration(char c)

Note

c is known to be a letter (from 'A' to 'Z') at this poit.

private void
private void
handleEntityDecl(boolean
If true, will need to take of enabling/disabling of flattened output.
suppressPEDecl
)

This method is tricky to implement, since it can contain parameter entities in multiple combinations...

private EntityDecl
handleExternalEntityDecl(WstxInputSource
Input source for the start of the declaration. Needed for resolving relative system references, if any.
inputSource
,
boolean
True if this a parameter entity declaration; false if general entity declaration
isParam
,
String id, char c, Location
Location where entity declaration directive started; needed when construction event Objects for declarations.
evtLoc
)

Method that handles rest of external entity declaration, after it's been figured out entity is not internal (does not continue with a quote).

protected void
private void
private void
protected void
handleIncompleteEntityProblem(WstxInputSource closing)

Overrides com.ctc.wstx.dtd.MinimalDTDReader.handleIncompleteEntityProblem.

Handling of PE matching problems is actually intricate; one type will be a WFC ("PE Between Declarations", which refers to PEs that start from outside declarations), and another just a VC ("Proper Declaration/PE Nesting", when PE is contained within declaration)

private void
handleNotationDecl()

Method called to handle declaration.

private void
handleSuppressedDeclaration()

Specialized method that handles potentially suppressable entity declaration.

private void
handleTargetNsDecl()

Method called to handle declaration (the only new declaration type for DTD++)

Note

only valid for DTD++, in 'plain DTD' mode shouldn't get called.

protected void
handleUndeclaredEntity(String id)

Overrides com.ctc.wstx.dtd.MinimalDTDReader.handleUndeclaredEntity.

Undeclared parameter entity is a VC, not WFC...

protected void
initInputSource(WstxInputSource newInput, boolean isExt, String
Name of the entity being expanded
entityId
)

Overrides com.ctc.wstx.sr.StreamScanner.initInputSource.

Method called when an entity has been expanded (new input source has been created).

protected boolean
loadMore()

Overrides com.ctc.wstx.sr.StreamScanner.loadMore.

Need to override this method, to check couple of things: first, that nested input sources are balanced, when expanding parameter entities inside entity value definitions (as per XML specs), and secondly, to handle (optional) flattening output.

protected boolean
private void
loadMoreScoped(WstxInputSource currScope, String entityName, Location loc)

private void
parseAttrDefaultValue(DefaultAttrValue defVal, char quoteChar, PrefixedName attrName, Location loc, boolean gotFixed)

This method is similar to parseEntityValue in some ways, but has some notable differences, due to the way XML specs define differences.

protected void
protected void
parseDirectiveFlattened()

Method similar to parseDirective, but one that takes care to properly output dtd contents using com.ctc.wstx.dtd.DTDWriter as necessary.

protected DTDSubset
private char[]
parseEntityValue(String id, Location loc, char quoteChar)

Method that reads and pre-processes replacement text for an internal entity (parameter or generic).

private WordResolver
parseEnumerated(DTDElement elem, PrefixedName attrName, boolean isNotation)

Parsing method that reads a list of one or more space-separated tokens (nmtoken or name, depending on 'isNotation' argument)

private char
protected void
readComment(DTDEventListener l)

Method similar to skipComment, but that has to collect contents, to be reported for a SAX handler.

private ContentSpec
readContentSpec(final PrefixedName elemName, final boolean construct, final int recursionDepth)

protected String
readDTDKeyword(String
Part of keyword already read in.
prefix
)

Method called usually to indicate an error condition; will read rest of specified keyword (including characters that can be part of XML identifiers), append that to passed prefix (which is optional), and return resulting String.

private String
readDTDLocalName(char c, boolean checkChar)

private String
readDTDName(char c)

private String
readDTDNmtoken(char c)

Similar to readDTDName, except that the rules are bit looser, ie.

private PrefixedName
readDTDQName(char firstChar)

Method that will read an element or attribute name from DTD; depending on namespace mode, it can have prefix as well.

private String
readEnumEntry(char c, HashMap<String, String> sharedEnums)

public static DTDSubset
readExternalSubset(WstxInputSource src, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion)

Method called to read in the external subset definition.

public static DTDSubset
readInternalSubset(WstxInputData srcData, WstxInputSource input, ReaderConfig cfg, boolean constructFully, int xmlVersion)

Method called to read in the internal subset definition.

private StructValidator
readMixedSpec(PrefixedName elemName, boolean
If true, will build full object for validating content within mixed content model; if false, will just parse and discard information (done in non-validating DTD-supporting mode)
construct
)

Method called to parse what seems like a mixed content specification.

private String
readNotationEntry(char c, PrefixedName
Name of attribute in declaration that refers to this entity
attrName
,
Location
Starting location of the DTD component that contains the reference
refLoc
)

Method called to read a notation reference entry; done both for attributes of type NOTATION, and for external unparsed entities that refer to a notation.

protected void
readPI()

Method similar to skipPI, but one that does basic well-formedness checks.

public void
setFlattenWriter(Writer w, boolean inclComments, boolean inclConditionals, boolean inclPEs)

Method that will set specified Writer as the 'flattening writer'; writer used to output flattened version of DTD read in. This is similar to running a C-preprocessor on C-sources, except that defining writer will not prevent normal parsing of DTD itself.

private char
skipDtdWs(boolean handlePEs)

private char

Returns:

Character following the obligatory boundary (white space or PE start/end)
skipObligatoryDtdWs
()

Note

Apparently a parameter entity expansion does also count as white space (that is, PEs outside of quoted text are considered to be separated by white spaces on both sides).

private void
private void
private void
throwDTDUnexpectedChar(int i, String extraMsg)

private void
Inherited from com.ctc.wstx.dtd.MinimalDTDReader:
dtdNextChardtdNextFromCurrgetErrorMsggetLocationgetNextSkippingPEshandleExpandedSurrogateskipCommentskipCommentContentskipInternalSubsetskipInternalSubsetskipPIthrowIllegalCall