Class DTDReader
- java.lang.Object
-
- com.sun.msv.reader.dtd.DTDReader
-
- All Implemented Interfaces:
DTDEventListener,java.util.EventListener
public class DTDReader extends java.lang.Object implements DTDEventListener
constructsTREXGrammarobject that exactly matches to the parsed DTD.Each element declaration will have its own ReferenceExp by the name of the element.
Note that this class does NOT extend GrammarReader, because DTD is not written in XML format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDTDReader.AttModelprotected classDTDReader.Context
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringABANDON_URI_SNIFFINGwhen this value is in the above set, that indicates we couldn't detect what URIs are going to be used with that prefix.protected java.util.MapattributeDeclsmap from element name to (map from attribute name to AttModel).protected shortCONNECTOR_UNKNOWNprotected shortconnectorTypeprotected ExpressioncontentModelprotected DTDReader.ContextcontextStackprotected Controllercontrollerprivate org.relaxng.datatype.DatatypeLibrarydatatypeLibraryUsed to create Datatype objects.private java.util.MapdeclaredLocationsthis map remembers where ReferenceExps are defined, and where user defined types are defined.protected java.util.MapelementDeclsmap from element name to its content model.static java.lang.StringERR_UNDECLARED_PREFIXstatic java.lang.StringERR_UNDEFINED_ELEMENTprotected TREXGrammargrammarprotected org.xml.sax.Locatorlocatorprotected java.util.Mapnamespacesmap from prefix to set of possible namespace URI.private booleanreportedXmlnsWarningthis flag is set to true after reporting WRN_ATTEMPT_TO_USE_NAMESPACE.static java.lang.StringWRN_ATTEMPT_TO_USE_NAMESPACE-
Fields inherited from interface com.sun.msv.scanner.dtd.DTDEventListener
CHOICE, CONTENT_MODEL_ANY, CONTENT_MODEL_CHILDREN, CONTENT_MODEL_EMPTY, CONTENT_MODEL_MIXED, OCCURENCE_ONCE, OCCURENCE_ONE_OR_MORE, OCCURENCE_ZERO_OR_MORE, OCCURENCE_ZERO_OR_ONE, SEQUENCE, USE_FIXED, USE_IMPLIED, USE_NORMAL, USE_REQUIRED
-
-
Constructor Summary
Constructors Constructor Description DTDReader(GrammarReaderController controller, ExpressionPool pool)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattributeDecl(java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeType, java.lang.String[] enums, short attributeUse, java.lang.String defaultValue)For each entry in an ATTLIST declaration, this event will be fired.voidcharacters(char[] ch, int start, int length)Receive notification of character data.voidchildElement(java.lang.String elementName, short occurence)protected voidcombineToContentModel(Expression exp)voidcomment(java.lang.String n)Receive notification that a comment has been read.voidconnector(short type)Connectors in one model group is guaranteed to be the same.protected ExpressioncreateAttributeBody(java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeType, java.lang.String[] enums, short attributeUse, java.lang.String defaultValue)Creates an attribute body from the declaration found in the DTD.org.relaxng.datatype.DatatypecreateDatatype(java.lang.String name)Obtains a Datatype object from its name.protected ReferenceExpcreateElementDeclaration(java.lang.String elementName)Creates an element declaration in the grammar object by using the parsed result.protected ExpressioncreateElementDeclarations()Creates element declarations from the parsed result.protected static java.util.MapcreateInitialNamespaceMap()voidendCDATA()Receive notification that the CDATA section finished.voidendContentModel(java.lang.String elementName, short type)receives notification that parsing of content model is finished.voidendDTD()Receive notification of the end of a DTD.voidendModelGroup(short occurence)voiderror(org.xml.sax.SAXParseException e)voidexternalGeneralEntityDecl(java.lang.String n, java.lang.String p, java.lang.String s)Receive notification of an external parsed general entity declaration event.voidexternalParameterEntityDecl(java.lang.String n, java.lang.String p, java.lang.String s)Receive notification of an external parameter entity declaration event.voidfatalError(org.xml.sax.SAXParseException e)protected ReferenceExpgetAnyExp()Gets the expression that corresponds to the "ANY".org.xml.sax.LocatorgetDeclaredLocationOf(java.lang.Object o)protected NameClassgetNameClass(java.lang.String maybeQName, boolean handleAsAttribute)private java.util.SetgetPossibleNamespaces(java.lang.String prefix)TREXGrammargetResult()Obtains the parsed grammar object.voidignorableWhitespace(char[] ch, int start, int length)Receive notification of ignorable whitespace in element content.voidinternalGeneralEntityDecl(java.lang.String n, java.lang.String v)Receive notification of a internal general entity declaration event.voidinternalParameterEntityDecl(java.lang.String n, java.lang.String v)Receive notification of a internal parameter entity declaration event.booleanisUnparsedEntity(java.lang.String entityName)voidmixedElement(java.lang.String elementName)receives notification of child element of mixed content model.voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)Receive notification of a Notation Declaration.static TREXGrammarparse(org.xml.sax.InputSource source, GrammarReaderController controller)static TREXGrammarparse(org.xml.sax.InputSource source, GrammarReaderController controller, ExpressionPool pool)voidprocessingInstruction(java.lang.String target, java.lang.String data)Receive notification of a Processing Instruction.protected ExpressionprocessOccurs(Expression item, short occurence)processes occurence (?,+,*) of the given expressionjava.lang.StringresolveNamespacePrefix(java.lang.String prefix)voidsetDatatypeLibrary(org.relaxng.datatype.DatatypeLibrary datatypeLibrary)voidsetDeclaredLocationOf(java.lang.Object o)voidsetDocumentLocator(org.xml.sax.Locator loc)protected java.lang.String[]splitQName(java.lang.String maybeQName)returns an array of (URI,localName).voidstartCDATA()Receive notification that a CDATA section is beginning.voidstartContentModel(java.lang.String elementName, short type)receives notification that parsing of content model is beginning.voidstartDTD(InputEntity in)Receive notification of the beginning of the DTD.voidstartModelGroup()voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)Receive notification of an unparsed entity declaration.voidwarning(org.xml.sax.SAXParseException e)
-
-
-
Field Detail
-
controller
protected final Controller controller
-
datatypeLibrary
private org.relaxng.datatype.DatatypeLibrary datatypeLibrary
Used to create Datatype objects. This datatype library should be able to handle XML Schema datatypes because those are the names we ask to this library.
-
namespaces
protected final java.util.Map namespaces
map from prefix to set of possible namespace URI. default namespace (without prefix) is stored by using "" as a key.
-
ABANDON_URI_SNIFFING
protected static final java.lang.String ABANDON_URI_SNIFFING
when this value is in the above set, that indicates we couldn't detect what URIs are going to be used with that prefix.- See Also:
- Constant Field Values
-
grammar
protected final TREXGrammar grammar
-
locator
protected org.xml.sax.Locator locator
-
elementDecls
protected final java.util.Map elementDecls
map from element name to its content model.
-
attributeDecls
protected final java.util.Map attributeDecls
map from element name to (map from attribute name to AttModel).
-
contextStack
protected DTDReader.Context contextStack
-
contentModel
protected Expression contentModel
-
connectorType
protected short connectorType
-
CONNECTOR_UNKNOWN
protected final short CONNECTOR_UNKNOWN
- See Also:
- Constant Field Values
-
reportedXmlnsWarning
private boolean reportedXmlnsWarning
this flag is set to true after reporting WRN_ATTEMPT_TO_USE_NAMESPACE. this is used to prevent issuing the same warning more than once.
-
declaredLocations
private final java.util.Map declaredLocations
this map remembers where ReferenceExps are defined, and where user defined types are defined. some ReferenceExp can be defined in more than one location. In those cases, the last one is always memorized. This behavior is essential to correctly implement TREX constraint that no two <define> is allowed in the same file.
-
ERR_UNDEFINED_ELEMENT
public static final java.lang.String ERR_UNDEFINED_ELEMENT
- See Also:
- Constant Field Values
-
WRN_ATTEMPT_TO_USE_NAMESPACE
public static final java.lang.String WRN_ATTEMPT_TO_USE_NAMESPACE
- See Also:
- Constant Field Values
-
ERR_UNDECLARED_PREFIX
public static final java.lang.String ERR_UNDECLARED_PREFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DTDReader
public DTDReader(GrammarReaderController controller, ExpressionPool pool)
-
-
Method Detail
-
parse
public static TREXGrammar parse(org.xml.sax.InputSource source, GrammarReaderController controller)
-
parse
public static TREXGrammar parse(org.xml.sax.InputSource source, GrammarReaderController controller, ExpressionPool pool)
-
setDatatypeLibrary
public void setDatatypeLibrary(org.relaxng.datatype.DatatypeLibrary datatypeLibrary)
-
createDatatype
public org.relaxng.datatype.Datatype createDatatype(java.lang.String name)
Obtains a Datatype object from its name.
-
createInitialNamespaceMap
protected static final java.util.Map createInitialNamespaceMap()
-
getNameClass
protected NameClass getNameClass(java.lang.String maybeQName, boolean handleAsAttribute)
-
splitQName
protected java.lang.String[] splitQName(java.lang.String maybeQName)
returns an array of (URI,localName).
-
getResult
public TREXGrammar getResult()
Obtains the parsed grammar object.- Returns:
- null if there was an error. Otherwise a parsed grammar object will be returned.
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator loc)
- Specified by:
setDocumentLocatorin interfaceDTDEventListener
-
startContentModel
public void startContentModel(java.lang.String elementName, short type)Description copied from interface:DTDEventListenerreceives notification that parsing of content model is beginning.- Specified by:
startContentModelin interfaceDTDEventListener- Parameters:
elementName- name of the element whose content model is going to be defined.type-DTDEventListener.CONTENT_MODEL_EMPTYthis element has EMPTY content model. This notification will be immediately followed by the corresponding endContentModel.DTDEventListener.CONTENT_MODEL_ANYthis element has ANY content model. This notification will be immediately followed by the corresponding endContentModel.DTDEventListener.CONTENT_MODEL_MIXEDthis element has mixed content model. #PCDATA will not be reported. each child element will be reported by mixedElement method.DTDEventListener.CONTENT_MODEL_CHILDRENthis elemen has child content model. The actual content model will be reported by childElement, startModelGroup, endModelGroup, and connector methods. Possible call sequences are: START := MODEL_GROUP MODEL_GROUP := startModelGroup TOKEN (connector TOKEN)* endModelGroup TOKEN := childElement | MODEL_GROUP
-
getAnyExp
protected final ReferenceExp getAnyExp()
Gets the expression that corresponds to the "ANY".Its defeinition will be later filled by the choice of all elements.
-
endContentModel
public void endContentModel(java.lang.String elementName, short type)Description copied from interface:DTDEventListenerreceives notification that parsing of content model is finished.- Specified by:
endContentModelin interfaceDTDEventListener
-
processOccurs
protected Expression processOccurs(Expression item, short occurence)
processes occurence (?,+,*) of the given expression
-
childElement
public void childElement(java.lang.String elementName, short occurence)- Specified by:
childElementin interfaceDTDEventListener
-
combineToContentModel
protected void combineToContentModel(Expression exp)
-
mixedElement
public void mixedElement(java.lang.String elementName)
Description copied from interface:DTDEventListenerreceives notification of child element of mixed content model. this method is called for each child element.- Specified by:
mixedElementin interfaceDTDEventListener- See Also:
DTDEventListener.startContentModel(String, short)
-
startModelGroup
public void startModelGroup()
- Specified by:
startModelGroupin interfaceDTDEventListener
-
endModelGroup
public void endModelGroup(short occurence)
- Specified by:
endModelGroupin interfaceDTDEventListener
-
connector
public void connector(short type) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerConnectors in one model group is guaranteed to be the same.IOW, you'll never see an event sequence like (a|b,c)
- Specified by:
connectorin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException
-
getPossibleNamespaces
private java.util.Set getPossibleNamespaces(java.lang.String prefix)
-
attributeDecl
public void attributeDecl(java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeType, java.lang.String[] enums, short attributeUse, java.lang.String defaultValue) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerFor each entry in an ATTLIST declaration, this event will be fired.DTD allows the same attributes to be declared more than once, and in that case the first one wins. I think this method will be only fired for the first one, but I need to check.
- Specified by:
attributeDeclin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException
-
createAttributeBody
protected Expression createAttributeBody(java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeType, java.lang.String[] enums, short attributeUse, java.lang.String defaultValue) throws org.xml.sax.SAXException
Creates an attribute body from the declaration found in the DTD.- Throws:
org.xml.sax.SAXException
-
createElementDeclaration
protected ReferenceExp createElementDeclaration(java.lang.String elementName)
Creates an element declaration in the grammar object by using the parsed result.- Returns:
- ReferenceExp that corresponds to the created element declaration.
-
createElementDeclarations
protected Expression createElementDeclarations()
Creates element declarations from the parsed result.- Returns:
- An expression that corresponds to the choice of all element declarations. This will be used to implement "ANY".
-
endDTD
public void endDTD() throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of the end of a DTD. The parser will invoke this method only once.- Specified by:
endDTDin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.startDTD(InputEntity)
-
fatalError
public void fatalError(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException- Specified by:
fatalErrorin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException
-
error
public void error(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException- Specified by:
errorin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException
-
warning
public void warning(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException- Specified by:
warningin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException
-
setDeclaredLocationOf
public void setDeclaredLocationOf(java.lang.Object o)
-
getDeclaredLocationOf
public org.xml.sax.Locator getDeclaredLocationOf(java.lang.Object o)
-
isUnparsedEntity
public boolean isUnparsedEntity(java.lang.String entityName)
-
resolveNamespacePrefix
public java.lang.String resolveNamespacePrefix(java.lang.String prefix)
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of a Processing Instruction. Processing instructions contain information meaningful to the application.- Specified by:
processingInstructionin interfaceDTDEventListener- Parameters:
target- The target of the proceessing instruction which should have meaning to the application.data- The instruction itself which should contain valid XML characters.- Throws:
org.xml.sax.SAXException
-
notationDecl
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of a Notation Declaration. Notation declarations are used by elements and entities for identifying embedded non-XML data.- Specified by:
notationDeclin interfaceDTDEventListener- Parameters:
name- The notation name, referred to by entities and elements.publicId- The public identifiersystemId- The system identifier- Throws:
org.xml.sax.SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of an unparsed entity declaration. Unparsed entities are non-XML data.- Specified by:
unparsedEntityDeclin interfaceDTDEventListener- Parameters:
name- The name of the unparsed entity.publicId- The public identifiersystemId- The system identifiernotationName- The associated notation- Throws:
org.xml.sax.SAXException
-
externalGeneralEntityDecl
public void externalGeneralEntityDecl(java.lang.String n, java.lang.String p, java.lang.String s) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of an external parsed general entity declaration event.If a system identifier is present, and it is a relative URL, the parser will have resolved it fully before passing it through this method to a listener.
- Specified by:
externalGeneralEntityDeclin interfaceDTDEventListener- Parameters:
n- The entity name.p- The entity's public identifier, or null if none was given.s- The entity's system identifier.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.unparsedEntityDecl(String, String, String, String)
-
internalGeneralEntityDecl
public void internalGeneralEntityDecl(java.lang.String n, java.lang.String v) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of a internal general entity declaration event.- Specified by:
internalGeneralEntityDeclin interfaceDTDEventListener- Parameters:
n- The internal general entity name.v- The value of the entity, which may include unexpanded entity references. Character references will have been expanded.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.externalGeneralEntityDecl(String, String, String)
-
externalParameterEntityDecl
public void externalParameterEntityDecl(java.lang.String n, java.lang.String p, java.lang.String s) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of an external parameter entity declaration event.If a system identifier is present, and it is a relative URL, the parser will have resolved it fully before passing it through this method to a listener.
- Specified by:
externalParameterEntityDeclin interfaceDTDEventListener- Parameters:
n- The parameter entity name.p- The entity's public identifier, or null if none was given.s- The entity's system identifier.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.unparsedEntityDecl(String, String, String, String)
-
internalParameterEntityDecl
public void internalParameterEntityDecl(java.lang.String n, java.lang.String v) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of a internal parameter entity declaration event.- Specified by:
internalParameterEntityDeclin interfaceDTDEventListener- Parameters:
n- The internal parameter entity name.v- The value of the entity, which may include unexpanded entity references. Character references will have been expanded.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.externalParameterEntityDecl(String, String, String)
-
startDTD
public void startDTD(InputEntity in) throws org.xml.sax.SAXException
Description copied from interface:DTDEventListenerReceive notification of the beginning of the DTD.- Specified by:
startDTDin interfaceDTDEventListener- Parameters:
in- Current input entity.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.endDTD()
-
comment
public void comment(java.lang.String n) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification that a comment has been read.Note that processing instructions are the mechanism designed to hold information for consumption by applications, not comments. XML systems may rely on applications being able to access information found in processing instructions; this is not true of comments, which are typically discarded.
- Specified by:
commentin interfaceDTDEventListener- Parameters:
n- the text within the comment delimiters.- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of character data.The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).
- Specified by:
charactersin interfaceDTDEventListener- Parameters:
ch- The characters from the DTD.start- The start position in the array.length- The number of characters to read from the array.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.ignorableWhitespace(char[], int, int)
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification of ignorable whitespace in element content.Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.
SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
- Specified by:
ignorableWhitespacein interfaceDTDEventListener- Parameters:
ch- The characters from the DTD.start- The start position in the array.length- The number of characters to read from the array.- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.characters(char[], int, int)
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification that a CDATA section is beginning. Data in a CDATA section is is reported through the appropriate event, either characters() or ignorableWhitespace.- Specified by:
startCDATAin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.endCDATA()
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXExceptionDescription copied from interface:DTDEventListenerReceive notification that the CDATA section finished.- Specified by:
endCDATAin interfaceDTDEventListener- Throws:
org.xml.sax.SAXException- See Also:
DTDEventListener.startCDATA()
-
-