Class FullDTDReader
- java.lang.Object
-
- com.ctc.wstx.io.WstxInputData
-
- com.ctc.wstx.sr.StreamScanner
-
- com.ctc.wstx.dtd.MinimalDTDReader
-
- com.ctc.wstx.dtd.FullDTDReader
-
- All Implemented Interfaces:
InputConfigFlags
,ParsingErrorMsgs
,InputProblemReporter
public class FullDTDReader extends MinimalDTDReader
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).
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.Boolean
ENTITY_EXP_GE
(package private) static java.lang.Boolean
ENTITY_EXP_PE
(package private) static 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.(package private) PrefixedName
mAccessKey
(package private) boolean
mAnyDTDppFeatures
Flag that indicates if any DTD++ features have been encountered (in DTD++-supporting mode).(package private) 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).(package private) boolean
mCfgSupportDTDPP
(package private) 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)(package private) int
mConfigFlags
(package private) DefaultAttrValue
mCurrAttrDefault
This is the attribute default value that is currently being parsed.(package private) java.lang.String
mCurrDeclaration
Keyword of the declaration being currently parsed (if any).(package private) java.lang.String
mDefaultNsURI
Currently active default namespace URI.(package private) java.util.LinkedHashMap<PrefixedName,DTDElement>
mElements
Contains definition of elements and matching content specifications.(package private) DTDEventListener
mEventListener
(package private) boolean
mExpandingPE
Flag that indicates if the currently expanding (or last expanded) entity is a Parameter Entity or General Entity.(package private) DTDWriter
mFlattenWriter
(package private) java.util.HashMap<java.lang.String,EntityDecl>
mGeneralEntities
Set of generic entities defined so far in this subset.(package private) int
mIncludeCount
Nesting count for conditionally included sections; 0 means that we are not inside such a section.(package private) java.util.HashMap<java.lang.String,java.lang.String>
mNamespaces
Prefix-to-NsURI mappings for this DTD, if any: lazily constructed when needed(package private) java.util.HashMap<java.lang.String,javax.xml.stream.Location>
mNotationForwardRefs
Finally, we need to keep track of Notation references that were made prior to declaration.(package private) java.util.HashMap<java.lang.String,javax.xml.stream.events.NotationDeclaration>
mNotations
Set of notations defined so far.(package private) java.util.HashMap<java.lang.String,EntityDecl>
mParamEntities
Set of parameter entities defined so far in the currently parsed subset.(package private) java.util.HashMap<java.lang.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.(package private) java.util.HashMap<java.lang.String,javax.xml.stream.events.NotationDeclaration>
mPredefdNotations
Notations already parsed before current subset; that is, notations from the internal subset if we are currently parsing matching external subset.(package private) java.util.HashMap<java.lang.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.(package private) java.util.Set<java.lang.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.(package private) java.util.Set<java.lang.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.(package private) java.util.HashMap<java.lang.String,java.lang.String>
mSharedEnumValues
Map used for sharing legal enumeration values; used since oftentimes same enumeration values are used with multiple attributes(package private) java.util.HashMap<PrefixedName,PrefixedName>
mSharedNames
Map used to shared PrefixedName instances, to reduce memory usage of (qualified) element and attribute names(package private) TextBuffer
mTextBuffer
(package private) boolean
mUsesPredefdEntities
Flag used to keep track of whether current (external) subset has referenced at least one PE that was pre-defined.(package private) boolean
mUsesPredefdNotations
Flag used to keep track of whether current (external) subset has referenced at least one notation that was defined in internal subset.(package private) TextBuffer
mValueBuffer
Text buffer used for constructing expansion value of the internal entities, and for default attribute values.-
Fields inherited from class com.ctc.wstx.dtd.MinimalDTDReader
mIsExternal
-
Fields inherited from class com.ctc.wstx.sr.StreamScanner
CHAR_CR_LF_OR_NULL, CHAR_FIRST_PURE_TEXT, CHAR_LOWEST_LEGAL_LOCALNAME_CHAR, INT_CR_LF_OR_NULL, mAllowXml11EscapedCharsInXml10, mCachedEntities, mCfgNsEnabled, mCfgReplaceEntities, mCfgTreatCharRefsAsEntities, mConfig, mCurrDepth, mCurrEntity, mCurrName, mDocInputEncoding, mDocXmlEncoding, mDocXmlVersion, mEntityExpansionCount, mEntityResolver, mInput, mInputTopDepth, mNameBuffer, mNormalizeLFs, mRootInput, mTokenInputCol, mTokenInputRow, mTokenInputTotal
-
Fields inherited from class com.ctc.wstx.io.WstxInputData
CHAR_NULL, CHAR_SPACE, INT_NULL, INT_SPACE, MAX_UNICODE_CHAR, mCurrInputProcessed, mCurrInputRow, mCurrInputRowStart, mInputBuffer, mInputEnd, mInputPtr, mXml11
-
Fields inherited from interface com.ctc.wstx.cfg.InputConfigFlags
CFG_ALLOW_XML11_ESCAPED_CHARS_IN_XML10, CFG_AUTO_CLOSE_INPUT, CFG_CACHE_DTDS, CFG_CACHE_DTDS_BY_PUBLIC_ID, CFG_COALESCE_TEXT, CFG_INTERN_NAMES, CFG_INTERN_NS_URIS, CFG_JAXP_FEATURE_SECURE_PROCESSING, CFG_LAZY_PARSING, CFG_NAMESPACE_AWARE, CFG_NORMALIZE_LFS, CFG_PRESERVE_LOCATION, CFG_REPLACE_ENTITY_REFS, CFG_REPORT_CDATA, CFG_REPORT_PROLOG_WS, CFG_SUPPORT_DTD, CFG_SUPPORT_DTDPP, CFG_SUPPORT_EXTERNAL_ENTITIES, CFG_TREAT_CHAR_REFS_AS_ENTS, CFG_VALIDATE_AGAINST_DTD, CFG_XMLID_TYPING, CFG_XMLID_UNIQ_CHECKS
-
Fields inherited from interface com.ctc.wstx.cfg.ParsingErrorMsgs
SUFFIX_EOF_EXP_NAME, SUFFIX_IN_ATTR_VALUE, SUFFIX_IN_CDATA, SUFFIX_IN_CLOSE_ELEMENT, SUFFIX_IN_COMMENT, SUFFIX_IN_DEF_ATTR_VALUE, SUFFIX_IN_DOC, SUFFIX_IN_DTD, SUFFIX_IN_DTD_EXTERNAL, SUFFIX_IN_DTD_INTERNAL, SUFFIX_IN_ELEMENT, SUFFIX_IN_ENTITY_REF, SUFFIX_IN_EPILOG, SUFFIX_IN_NAME, SUFFIX_IN_PROC_INSTR, SUFFIX_IN_PROLOG, SUFFIX_IN_TEXT, SUFFIX_IN_XML_DECL
-
-
Constructor Summary
Constructors Modifier Constructor Description private
FullDTDReader(WstxInputSource input, ReaderConfig cfg, boolean constructFully, int xmlVersion)
Constructor used for reading/skipping internal subset.private
FullDTDReader(WstxInputSource input, ReaderConfig cfg, boolean isExt, DTDSubset intSubset, boolean constructFully, int xmlVersion)
Common initialization part of int/ext subset constructors.private
FullDTDReader(WstxInputSource input, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion)
Constructor used for reading external subset.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_reportBadDirective(java.lang.String dir)
private void
_reportUndefinedNotationRefs()
private void
_reportVCViolation(java.lang.String msg)
private void
_reportWarning(javax.xml.stream.XMLReporter rep, java.lang.String probType, java.lang.String msg, javax.xml.stream.Location loc)
private void
_reportWFCViolation(java.lang.String msg)
private void
_reportWFCViolation(java.lang.String format, java.lang.Object arg)
private java.lang.String
attrDesc(java.lang.Object elem, PrefixedName attrName)
protected java.lang.String
checkDTDKeyword(java.lang.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
checkInclusion()
private boolean
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
dtdNextIfAvailable()
private java.lang.String
elemDesc(java.lang.Object elem)
protected boolean
ensureInput(int minAmount)
Method called to make sure current main-level input buffer has at least specified number of characters available consequtively, without having to callStreamScanner.loadMore()
.private java.lang.String
entityDesc(WstxInputSource input)
private void
expandPE()
Method called to handle expansion of parameter entities.EntityDecl
findEntity(java.lang.String entName)
Method that may need to be called by attribute default value validation code, during parsing....protected EntityDecl
findEntity(java.lang.String id, java.lang.Object arg)
Abstract method for sub-classes to implement, for finding a declared general or parsed entity.private PrefixedName
findSharedName(java.lang.String prefix, java.lang.String localName)
Method used to 'intern()' qualified names; main benefit is reduced memory usage as the name objects are shared.static DTDSubset
flattenExternalSubset(WstxInputSource src, java.io.Writer flattenWriter, boolean inclComments, boolean inclConditionals, boolean inclPEs)
Method that will parse, process and output contents of an external DTD subset.private void
flushFlattenWriter()
private java.util.LinkedHashMap<PrefixedName,DTDElement>
getElementMap()
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
getTextBuffer()
private void
handleAttlistDecl()
note: when this method is called, the keyword itself has been succesfully parsed.private void
handleAttrDecl(DTDElement elem, char c, int index, javax.xml.stream.Location loc)
private void
handleDeclaration(char c)
Note: c is known to be a letter (from 'A' to 'Z') at this poit.private void
handleElementDecl()
private void
handleEntityDecl(boolean suppressPEDecl)
This method is tricky to implement, since it can contain parameter entities in multiple combinations...private EntityDecl
handleExternalEntityDecl(WstxInputSource inputSource, boolean isParam, java.lang.String id, char c, javax.xml.stream.Location 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
handleGreedyEntityProblem(WstxInputSource input)
private void
handleIgnored()
private void
handleIncluded()
protected void
handleIncompleteEntityProblem(WstxInputSource closing)
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 handleprivate void
handleSuppressedDeclaration()
Specialized method that handles potentially suppressable entity declaration.private void
handleTargetNsDecl()
Method called to handleprotected void
handleUndeclaredEntity(java.lang.String id)
Undeclared parameter entity is a VC, not WFC...protected void
initInputSource(WstxInputSource newInput, boolean isExt, java.lang.String entityId)
Method called when an entity has been expanded (new input source has been created).protected boolean
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
loadMoreFromCurrent()
private void
loadMoreScoped(WstxInputSource currScope, java.lang.String entityName, javax.xml.stream.Location loc)
private void
parseAttrDefaultValue(DefaultAttrValue defVal, char quoteChar, PrefixedName attrName, javax.xml.stream.Location loc, boolean gotFixed)
This method is similar toparseEntityValue(java.lang.String, javax.xml.stream.Location, char)
in some ways, but has some notable differences, due to the way XML specs define differences.protected void
parseDirective()
protected void
parseDirectiveFlattened()
Method similar toparseDirective()
, but one that takes care to properly output dtd contents usingcom.ctc.wstx.dtd.DTDWriter
as necessary.protected DTDSubset
parseDTD()
private char[]
parseEntityValue(java.lang.String id, javax.xml.stream.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
readArity()
protected void
readComment(DTDEventListener l)
Method similar toMinimalDTDReader.skipComment()
, but that has to collect contents, to be reported for a SAX handler.private ContentSpec
readContentSpec(PrefixedName elemName, boolean mainLevel, boolean construct)
protected java.lang.String
readDTDKeyword(java.lang.String 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 java.lang.String
readDTDLocalName(char c, boolean checkChar)
private java.lang.String
readDTDName(char c)
private java.lang.String
readDTDNmtoken(char c)
Similar toreadDTDName(char)
, 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 java.lang.String
readEnumEntry(char c, java.util.HashMap<java.lang.String,java.lang.String> sharedEnums)
static DTDSubset
readExternalSubset(WstxInputSource src, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion)
Method called to read in the external subset definition.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 construct)
Method called to parse what seems like a mixed content specification.private java.lang.String
readNotationEntry(char c, PrefixedName attrName, javax.xml.stream.Location 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 toMinimalDTDReader.skipPI()
, but one that does basic well-formedness checks.void
setFlattenWriter(java.io.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.private char
skipDtdWs(boolean handlePEs)
private char
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
throwDTDAttrError(java.lang.String msg, DTDElement elem, PrefixedName attrName)
private void
throwDTDElemError(java.lang.String msg, java.lang.Object elem)
private void
throwDTDUnexpectedChar(int i, java.lang.String extraMsg)
private void
throwForbiddenPE()
-
Methods inherited from class com.ctc.wstx.dtd.MinimalDTDReader
dtdNextChar, dtdNextFromCurr, getErrorMsg, getLocation, getNextSkippingPEs, handleExpandedSurrogate, skipComment, skipCommentContent, skipInternalSubset, skipInternalSubset, skipPI, throwIllegalCall
-
Methods inherited from class com.ctc.wstx.sr.StreamScanner
_reportProblem, _reportProblem, closeAllInput, constructFromIOE, constructLimitViolation, constructNullCharException, constructWfcException, expandBy50Pct, expandEntity, fullyResolveEntity, getConfig, getCurrentInput, getCurrentLocation, getIntEntity, getLastCharLocation, getNameBuffer, getNext, getNextAfterWS, getNextChar, getNextCharAfterWS, getNextCharFromCurrent, getNextInCurrAfterWS, getNextInCurrAfterWS, getSource, getStartLocation, getSystemId, inputInBuffer, loadMore, loadMoreFromCurrent, markLF, markLF, parseEntityName, parseFNameForError, parseFullName, parseFullName, parseFullName2, parseLocalName, parseLocalName2, parsePublicId, parseSystemId, parseUntil, peekNext, pushback, reportProblem, reportProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, resolveCharOnlyEntity, resolveNonCharEntity, resolveSimpleEntity, skipCRLF, skipFullName, throwFromIOE, throwFromStrE, throwInvalidSpace, throwInvalidSpace, throwLazyError, throwNullChar, throwNullParent, throwParseError, throwParseError, throwUnexpectedChar, throwUnexpectedEOB, throwUnexpectedEOF, throwWfcException, tokenTypeDesc, verifyLimit
-
Methods inherited from class com.ctc.wstx.io.WstxInputData
copyBufferStateFrom, findIllegalNameChar, findIllegalNmtokenChar, getCharDesc, isNameChar, isNameChar, isNameStartChar, isNameStartChar, isSpaceChar
-
-
-
-
Field Detail
-
INTERN_SHARED_NAMES
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.- See Also:
- Constant Field Values
-
ENTITY_EXP_GE
static final java.lang.Boolean ENTITY_EXP_GE
-
ENTITY_EXP_PE
static final java.lang.Boolean ENTITY_EXP_PE
-
mConfigFlags
final int mConfigFlags
-
mCfgSupportDTDPP
final boolean mCfgSupportDTDPP
-
mCfgFullyValidating
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). Latter is used in non-validating mode.
-
mParamEntities
java.util.HashMap<java.lang.String,EntityDecl> mParamEntities
Set of parameter entities defined so far in the currently parsed subset. Note: the first definition sticks, entities can not be redefined.Keys are entity name Strings; values are instances of EntityDecl
-
mPredefdPEs
final java.util.HashMap<java.lang.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. Null when parsing internal subset.
-
mRefdPEs
java.util.Set<java.lang.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.
-
mGeneralEntities
java.util.HashMap<java.lang.String,EntityDecl> mGeneralEntities
Set of generic entities defined so far in this subset. As with parameter entities, the first definition sticks.Keys are entity name Strings; values are instances of EntityDecl
Note: this Map only contains entities declared and defined in the subset being parsed; no previously defined values are passed.
-
mPredefdGEs
final java.util.HashMap<java.lang.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. Null when parsing internal subset. Such entities are only needed directly for one purpose; to be expanded when reading attribute default value definitions.
-
mRefdGEs
java.util.Set<java.lang.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.
-
mUsesPredefdEntities
boolean mUsesPredefdEntities
Flag used to keep track of whether current (external) subset has referenced at least one PE that was pre-defined.
-
mNotations
java.util.HashMap<java.lang.String,javax.xml.stream.events.NotationDeclaration> mNotations
Set of notations defined so far. Since it's illegal to (try to) redefine notations, there's no specific precedence.Keys are entity name Strings; values are instances of NotationDecl objects
-
mPredefdNotations
final java.util.HashMap<java.lang.String,javax.xml.stream.events.NotationDeclaration> mPredefdNotations
Notations already parsed before current subset; that is, notations from the internal subset if we are currently parsing matching external subset.
-
mUsesPredefdNotations
boolean mUsesPredefdNotations
Flag used to keep track of whether current (external) subset has referenced at least one notation that was defined in internal subset. If so, can not cache the external subset
-
mNotationForwardRefs
java.util.HashMap<java.lang.String,javax.xml.stream.Location> mNotationForwardRefs
Finally, we need to keep track of Notation references that were made prior to declaration. This is needed to ensure that all references can be properly resolved.
-
mSharedNames
java.util.HashMap<PrefixedName,PrefixedName> mSharedNames
Map used to shared PrefixedName instances, to reduce memory usage of (qualified) element and attribute names
-
mElements
java.util.LinkedHashMap<PrefixedName,DTDElement> mElements
Contains definition of elements and matching content specifications. Also contains temporary placeholders for elements that are indirectly "created" by ATTLIST declarations that precede actual declaration for the ELEMENT referred to.
-
mSharedEnumValues
java.util.HashMap<java.lang.String,java.lang.String> mSharedEnumValues
Map used for sharing legal enumeration values; used since oftentimes same enumeration values are used with multiple attributes
-
mCurrAttrDefault
DefaultAttrValue mCurrAttrDefault
This is the attribute default value that is currently being parsed. Needs to be a global member due to the way entity expansion failures are reported: problems need to be attached to this object, even thought the default value itself will not be passed through.
-
mExpandingPE
boolean mExpandingPE
Flag that indicates if the currently expanding (or last expanded) entity is a Parameter Entity or General Entity.
-
mValueBuffer
TextBuffer mValueBuffer
Text buffer used for constructing expansion value of the internal entities, and for default attribute values. Lazily constructed when needed, reused.
-
mIncludeCount
int mIncludeCount
Nesting count for conditionally included sections; 0 means that we are not inside such a section. Note that condition ignore is handled separately.
-
mCheckForbiddenPEs
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)
-
mCurrDeclaration
java.lang.String mCurrDeclaration
Keyword of the declaration being currently parsed (if any). Can be used for error reporting purposes.
-
mAnyDTDppFeatures
boolean mAnyDTDppFeatures
Flag that indicates if any DTD++ features have been encountered (in DTD++-supporting mode).
-
mDefaultNsURI
java.lang.String mDefaultNsURI
Currently active default namespace URI.
-
mNamespaces
java.util.HashMap<java.lang.String,java.lang.String> mNamespaces
Prefix-to-NsURI mappings for this DTD, if any: lazily constructed when needed
-
mFlattenWriter
DTDWriter mFlattenWriter
-
mEventListener
final DTDEventListener mEventListener
-
mTextBuffer
transient TextBuffer mTextBuffer
-
mAccessKey
final PrefixedName mAccessKey
-
-
Constructor Detail
-
FullDTDReader
private FullDTDReader(WstxInputSource input, ReaderConfig cfg, boolean constructFully, int xmlVersion)
Constructor used for reading/skipping internal subset.
-
FullDTDReader
private FullDTDReader(WstxInputSource input, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion)
Constructor used for reading external subset.
-
FullDTDReader
private FullDTDReader(WstxInputSource input, ReaderConfig cfg, boolean isExt, DTDSubset intSubset, boolean constructFully, int xmlVersion)
Common initialization part of int/ext subset constructors.
-
-
Method Detail
-
readInternalSubset
public static DTDSubset readInternalSubset(WstxInputData srcData, WstxInputSource input, ReaderConfig cfg, boolean constructFully, int xmlVersion) throws javax.xml.stream.XMLStreamException
Method called to read in the internal subset definition.- Throws:
javax.xml.stream.XMLStreamException
-
readExternalSubset
public static DTDSubset readExternalSubset(WstxInputSource src, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion) throws javax.xml.stream.XMLStreamException
Method called to read in the external subset definition.- Throws:
javax.xml.stream.XMLStreamException
-
flattenExternalSubset
public static DTDSubset flattenExternalSubset(WstxInputSource src, java.io.Writer flattenWriter, boolean inclComments, boolean inclConditionals, boolean inclPEs) throws java.io.IOException, javax.xml.stream.XMLStreamException
Method that will parse, process and output contents of an external DTD subset. It will do processing similar toreadExternalSubset(com.ctc.wstx.io.WstxInputSource, com.ctc.wstx.api.ReaderConfig, com.ctc.wstx.dtd.DTDSubset, boolean, int)
, but additionally will copy its processed ("flattened") input to specified writer.- Parameters:
src
- Input source used to read the main external subsetflattenWriter
- Writer to output processed DTD content toinclComments
- If true, will pass comments to the writer; if false, will strip comments outinclConditionals
- If true, will include conditional block markers, as well as intervening content; if false, will strip out both markers and ignorable sections.inclPEs
- If true, will output parameter entity declarations; if false will parse and use them, but not output.- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
getTextBuffer
private TextBuffer getTextBuffer()
-
setFlattenWriter
public void setFlattenWriter(java.io.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.
-
flushFlattenWriter
private void flushFlattenWriter() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
findEntity
public EntityDecl findEntity(java.lang.String entName)
Method that may need to be called by attribute default value validation code, during parsing....Note: see base class for some additional remarks about this method.
- Overrides:
findEntity
in classMinimalDTDReader
-
parseDTD
protected DTDSubset parseDTD() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseDirective
protected void parseDirective() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseDirectiveFlattened
protected void parseDirectiveFlattened() throws javax.xml.stream.XMLStreamException
Method similar toparseDirective()
, but one that takes care to properly output dtd contents usingcom.ctc.wstx.dtd.DTDWriter
as necessary. Separated to simplify both methods; otherwise would end up with 'if (... flatten...) ... else ...' spaghetti code.- Throws:
javax.xml.stream.XMLStreamException
-
initInputSource
protected void initInputSource(WstxInputSource newInput, boolean isExt, java.lang.String entityId) throws javax.xml.stream.XMLStreamException
Description copied from class:StreamScanner
Method called when an entity has been expanded (new input source has been created). Needs to initialize location information and change active input source.- Overrides:
initInputSource
in classStreamScanner
entityId
- Name of the entity being expanded- Throws:
javax.xml.stream.XMLStreamException
-
loadMore
protected boolean loadMore() throws javax.xml.stream.XMLStreamException
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.- Overrides:
loadMore
in classStreamScanner
- Returns:
- true if reading succeeded (or may succeed), false if we reached EOF.
- Throws:
javax.xml.stream.XMLStreamException
-
loadMoreFromCurrent
protected boolean loadMoreFromCurrent() throws javax.xml.stream.XMLStreamException
- Overrides:
loadMoreFromCurrent
in classStreamScanner
- Throws:
javax.xml.stream.XMLStreamException
-
ensureInput
protected boolean ensureInput(int minAmount) throws javax.xml.stream.XMLStreamException
Description copied from class:StreamScanner
Method called to make sure current main-level input buffer has at least specified number of characters available consequtively, without having to callStreamScanner.loadMore()
. It can only be called when input comes from main-level buffer; further, call can shift content in input buffer, so caller has to flush any data still pending. In short, caller has to know exactly what it's doing. :-)Note: method does not check for any other input sources than the current one -- if current source can not fulfill the request, a failure is indicated.
- Overrides:
ensureInput
in classStreamScanner
- Returns:
- true if there's now enough data; false if not (EOF)
- Throws:
javax.xml.stream.XMLStreamException
-
loadMoreScoped
private void loadMoreScoped(WstxInputSource currScope, java.lang.String entityName, javax.xml.stream.Location loc) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
dtdNextIfAvailable
private char dtdNextIfAvailable() throws javax.xml.stream.XMLStreamException
- Returns:
- Next character from the current input block, if any left; NULL if end of block (entity expansion)
- Throws:
javax.xml.stream.XMLStreamException
-
getNextExpanded
private char getNextExpanded() throws javax.xml.stream.XMLStreamException
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 '%').- Throws:
javax.xml.stream.XMLStreamException
-
skipDtdWs
private char skipDtdWs(boolean handlePEs) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
skipObligatoryDtdWs
private char skipObligatoryDtdWs() throws javax.xml.stream.XMLStreamException
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). Fortunately this can be handled by 2 little hacks: both a start of a PE, and an end of input block (== end of PE expansion) count as succesful spaces.- Returns:
- Character following the obligatory boundary (white space or PE start/end)
- Throws:
javax.xml.stream.XMLStreamException
-
expandPE
private void expandPE() throws javax.xml.stream.XMLStreamException
Method called to handle expansion of parameter entities. When called, '%' character has been encountered as a reference indicator, and now we should get parameter entity name.- Throws:
javax.xml.stream.XMLStreamException
-
checkDTDKeyword
protected java.lang.String checkDTDKeyword(java.lang.String exp) throws javax.xml.stream.XMLStreamException
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.- Throws:
javax.xml.stream.XMLStreamException
-
readDTDKeyword
protected java.lang.String readDTDKeyword(java.lang.String prefix) throws javax.xml.stream.XMLStreamException
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.- Parameters:
prefix
- Part of keyword already read in.- Throws:
javax.xml.stream.XMLStreamException
-
checkPublicSystemKeyword
private boolean checkPublicSystemKeyword(char c) throws javax.xml.stream.XMLStreamException
- Returns:
- True, if input contains 'PUBLIC' keyword; false if it contains 'SYSTEM'; otherwise throws an exception.
- Throws:
javax.xml.stream.XMLStreamException
-
readDTDName
private java.lang.String readDTDName(char c) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
readDTDLocalName
private java.lang.String readDTDLocalName(char c, boolean checkChar) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
readDTDNmtoken
private java.lang.String readDTDNmtoken(char c) throws javax.xml.stream.XMLStreamException
Similar toreadDTDName(char)
, except that the rules are bit looser, ie. there are no additional restrictions for the first char- Throws:
javax.xml.stream.XMLStreamException
-
readDTDQName
private PrefixedName readDTDQName(char firstChar) throws javax.xml.stream.XMLStreamException
Method that will read an element or attribute name from DTD; depending on namespace mode, it can have prefix as well.Note: returned
PrefixedName
instances are canonicalized so that all instances read during parsing of a single DTD subset so that identity comparison can be used instead of callingequals()
method (but only within a single subset!). This also reduces memory usage to some extent.- Throws:
javax.xml.stream.XMLStreamException
-
readArity
private char readArity() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseEntityValue
private char[] parseEntityValue(java.lang.String id, javax.xml.stream.Location loc, char quoteChar) throws javax.xml.stream.XMLStreamException
Method that reads and pre-processes replacement text for an internal entity (parameter or generic).- Throws:
javax.xml.stream.XMLStreamException
-
parseAttrDefaultValue
private void parseAttrDefaultValue(DefaultAttrValue defVal, char quoteChar, PrefixedName attrName, javax.xml.stream.Location loc, boolean gotFixed) throws javax.xml.stream.XMLStreamException
This method is similar toparseEntityValue(java.lang.String, javax.xml.stream.Location, char)
in some ways, but has some notable differences, due to the way XML specs define differences. Main differences are that parameter entities are not allowed (or rather, recognized as entities), and that general entities need to be verified, but NOT expanded right away. Whether forward references are allowed or not is an open question right now.- Throws:
javax.xml.stream.XMLStreamException
-
readPI
protected void readPI() throws javax.xml.stream.XMLStreamException
Method similar toMinimalDTDReader.skipPI()
, but one that does basic well-formedness checks.- Throws:
javax.xml.stream.XMLStreamException
-
readComment
protected void readComment(DTDEventListener l) throws javax.xml.stream.XMLStreamException
Method similar toMinimalDTDReader.skipComment()
, but that has to collect contents, to be reported for a SAX handler.- Throws:
javax.xml.stream.XMLStreamException
-
checkInclusion
private void checkInclusion() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
handleIncluded
private void handleIncluded() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
handleIgnored
private void handleIgnored() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_reportUndefinedNotationRefs
private void _reportUndefinedNotationRefs() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_reportBadDirective
private void _reportBadDirective(java.lang.String dir) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_reportVCViolation
private void _reportVCViolation(java.lang.String msg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_reportWFCViolation
private void _reportWFCViolation(java.lang.String msg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_reportWFCViolation
private void _reportWFCViolation(java.lang.String format, java.lang.Object arg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwDTDElemError
private void throwDTDElemError(java.lang.String msg, java.lang.Object elem) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwDTDAttrError
private void throwDTDAttrError(java.lang.String msg, DTDElement elem, PrefixedName attrName) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwDTDUnexpectedChar
private void throwDTDUnexpectedChar(int i, java.lang.String extraMsg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwForbiddenPE
private void throwForbiddenPE() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
elemDesc
private java.lang.String elemDesc(java.lang.Object elem)
-
attrDesc
private java.lang.String attrDesc(java.lang.Object elem, PrefixedName attrName)
-
entityDesc
private java.lang.String entityDesc(WstxInputSource input)
-
handleDeclaration
private void handleDeclaration(char c) throws javax.xml.stream.XMLStreamException
Note: c is known to be a letter (from 'A' to 'Z') at this poit.
- Throws:
javax.xml.stream.XMLStreamException
-
handleSuppressedDeclaration
private void handleSuppressedDeclaration() throws javax.xml.stream.XMLStreamException
Specialized method that handles potentially suppressable entity declaration. Specifically: at this point it is known that first letter is 'E', that we are outputting flattened DTD info, and that parameter entity declarations are to be suppressed. Furthermore, flatten output is still being disabled, and needs to be enabled by the method at some point.- Throws:
javax.xml.stream.XMLStreamException
-
handleAttlistDecl
private void handleAttlistDecl() throws javax.xml.stream.XMLStreamException
note: when this method is called, the keyword itself has been succesfully parsed.- Throws:
javax.xml.stream.XMLStreamException
-
handleElementDecl
private void handleElementDecl() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
handleEntityDecl
private void handleEntityDecl(boolean suppressPEDecl) throws javax.xml.stream.XMLStreamException
This method is tricky to implement, since it can contain parameter entities in multiple combinations... and yet declare one as well.- Parameters:
suppressPEDecl
- If true, will need to take of enabling/disabling of flattened output.- Throws:
javax.xml.stream.XMLStreamException
-
handleNotationDecl
private void handleNotationDecl() throws javax.xml.stream.XMLStreamException
Method called to handle declaration.- Throws:
javax.xml.stream.XMLStreamException
-
handleTargetNsDecl
private void handleTargetNsDecl() throws javax.xml.stream.XMLStreamException
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.
- Throws:
javax.xml.stream.XMLStreamException
-
handleAttrDecl
private void handleAttrDecl(DTDElement elem, char c, int index, javax.xml.stream.Location loc) throws javax.xml.stream.XMLStreamException
- Parameters:
elem
- Element that contains this attributec
- First character of what should be the attribute nameindex
- Sequential index number of this attribute as children of the element; used for creating bit masks later on.loc
- Location of the element name in attribute list declaration- Throws:
javax.xml.stream.XMLStreamException
-
parseEnumerated
private WordResolver parseEnumerated(DTDElement elem, PrefixedName attrName, boolean isNotation) throws javax.xml.stream.XMLStreamException
Parsing method that reads a list of one or more space-separated tokens (nmtoken or name, depending on 'isNotation' argument)- Throws:
javax.xml.stream.XMLStreamException
-
readNotationEntry
private java.lang.String readNotationEntry(char c, PrefixedName attrName, javax.xml.stream.Location refLoc) throws javax.xml.stream.XMLStreamException
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. In both cases, notation referenced needs to have been defined earlier; but only if we are building a fully validating DTD subset object (there is the alternative of a minimal DTD in DTD-aware mode, which does no validation but allows attribute defaulting and normalization, as well as access to entity and notation declarations).- Parameters:
attrName
- Name of attribute in declaration that refers to this entityrefLoc
- Starting location of the DTD component that contains the reference- Throws:
javax.xml.stream.XMLStreamException
-
readEnumEntry
private java.lang.String readEnumEntry(char c, java.util.HashMap<java.lang.String,java.lang.String> sharedEnums) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
readMixedSpec
private StructValidator readMixedSpec(PrefixedName elemName, boolean construct) throws javax.xml.stream.XMLStreamException
Method called to parse what seems like a mixed content specification.- Parameters:
construct
- 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)- Throws:
javax.xml.stream.XMLStreamException
-
readContentSpec
private ContentSpec readContentSpec(PrefixedName elemName, boolean mainLevel, boolean construct) throws javax.xml.stream.XMLStreamException
- Parameters:
mainLevel
- Whether this is the main-level content specification or nested- Throws:
javax.xml.stream.XMLStreamException
-
combineArities
private static char combineArities(char arity1, char arity2)
-
handleExternalEntityDecl
private EntityDecl handleExternalEntityDecl(WstxInputSource inputSource, boolean isParam, java.lang.String id, char c, javax.xml.stream.Location evtLoc) throws javax.xml.stream.XMLStreamException
Method that handles rest of external entity declaration, after it's been figured out entity is not internal (does not continue with a quote).- Parameters:
inputSource
- Input source for the start of the declaration. Needed for resolving relative system references, if any.isParam
- True if this a parameter entity declaration; false if general entity declarationevtLoc
- Location where entity declaration directive started; needed when construction event Objects for declarations.- Throws:
javax.xml.stream.XMLStreamException
-
getElementMap
private java.util.LinkedHashMap<PrefixedName,DTDElement> getElementMap()
-
findSharedName
private PrefixedName findSharedName(java.lang.String prefix, java.lang.String localName)
Method used to 'intern()' qualified names; main benefit is reduced memory usage as the name objects are shared. May also slightly speed up Map access, as more often identity comparisons catch matches.Note: it is assumed at this point that access is only from a single thread, and non-recursive -- generally valid assumption as readers are not shared. Restriction is needed since the method is not re-entrant: it uses mAccessKey during the method call.
-
findEntity
protected EntityDecl findEntity(java.lang.String id, java.lang.Object arg)
Description copied from class:StreamScanner
Abstract method for sub-classes to implement, for finding a declared general or parsed entity.- Overrides:
findEntity
in classMinimalDTDReader
- Parameters:
arg
- If Boolean.TRUE, we are expanding a general entityid
- Identifier of the entity to find
-
handleUndeclaredEntity
protected void handleUndeclaredEntity(java.lang.String id) throws javax.xml.stream.XMLStreamException
Undeclared parameter entity is a VC, not WFC...- Overrides:
handleUndeclaredEntity
in classMinimalDTDReader
- Throws:
javax.xml.stream.XMLStreamException
-
handleIncompleteEntityProblem
protected void handleIncompleteEntityProblem(WstxInputSource closing) throws javax.xml.stream.XMLStreamException
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)- Overrides:
handleIncompleteEntityProblem
in classMinimalDTDReader
- Throws:
javax.xml.stream.XMLStreamException
-
handleGreedyEntityProblem
protected void handleGreedyEntityProblem(WstxInputSource input) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
checkXmlSpaceAttr
protected void checkXmlSpaceAttr(int type, WordResolver enumValues) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
checkXmlIdAttr
protected void checkXmlIdAttr(int type) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_reportWarning
private void _reportWarning(javax.xml.stream.XMLReporter rep, java.lang.String probType, java.lang.String msg, javax.xml.stream.Location loc) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
-