Class DTDReader
- java.lang.Object
-
- com.sun.msv.reader.dtd.DTDReader
-
- All Implemented Interfaces:
DTDEventListener
,EventListener
public class DTDReader extends Object implements DTDEventListener
constructsTREXGrammar
object 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.
- Author:
- Kohsuke KAWAGUCHI
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DTDReader.Context
-
Field Summary
Fields Modifier and Type Field Description protected static 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.protected Map
attributeDecls
map from element name to (map from attribute name to AttModel).protected short
CONNECTOR_UNKNOWN
protected short
connectorType
protected Expression
contentModel
protected DTDReader.Context
contextStack
protected Controller
controller
protected Map
elementDecls
map from element name to its content model.static String
ERR_UNDECLARED_PREFIX
static String
ERR_UNDEFINED_ELEMENT
protected TREXGrammar
grammar
protected Locator
locator
protected Map
namespaces
map from prefix to set of possible namespace URI.static String
WRN_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 void
attributeDecl(String elementName, String attributeName, String attributeType, String[] enums, short attributeUse, String defaultValue)
For each entry in an ATTLIST declaration, this event will be fired.void
characters(char[] ch, int start, int length)
Receive notification of character data.void
childElement(String elementName, short occurence)
protected void
combineToContentModel(Expression exp)
void
comment(String n)
Receive notification that a comment has been read.void
connector(short type)
Connectors in one model group is guaranteed to be the same.protected Expression
createAttributeBody(String elementName, String attributeName, String attributeType, String[] enums, short attributeUse, String defaultValue)
Creates an attribute body from the declaration found in the DTD.org.relaxng.datatype.Datatype
createDatatype(String name)
Obtains a Datatype object from its name.protected ReferenceExp
createElementDeclaration(String elementName)
Creates an element declaration in the grammar object by using the parsed result.protected Expression
createElementDeclarations()
Creates element declarations from the parsed result.protected static Map
createInitialNamespaceMap()
void
endCDATA()
Receive notification that the CDATA section finished.void
endContentModel(String elementName, short type)
receives notification that parsing of content model is finished.void
endDTD()
Receive notification of the end of a DTD.void
endModelGroup(short occurence)
void
error(SAXParseException e)
void
externalGeneralEntityDecl(String n, String p, String s)
Receive notification of an external parsed general entity declaration event.void
externalParameterEntityDecl(String n, String p, String s)
Receive notification of an external parameter entity declaration event.void
fatalError(SAXParseException e)
protected ReferenceExp
getAnyExp()
Gets the expression that corresponds to the "ANY".Locator
getDeclaredLocationOf(Object o)
protected NameClass
getNameClass(String maybeQName, boolean handleAsAttribute)
TREXGrammar
getResult()
Obtains the parsed grammar object.void
ignorableWhitespace(char[] ch, int start, int length)
Receive notification of ignorable whitespace in element content.void
internalGeneralEntityDecl(String n, String v)
Receive notification of a internal general entity declaration event.void
internalParameterEntityDecl(String n, String v)
Receive notification of a internal parameter entity declaration event.boolean
isUnparsedEntity(String entityName)
void
mixedElement(String elementName)
receives notification of child element of mixed content model.void
notationDecl(String name, String publicId, String systemId)
Receive notification of a Notation Declaration.static TREXGrammar
parse(InputSource source, GrammarReaderController controller)
static TREXGrammar
parse(InputSource source, GrammarReaderController controller, ExpressionPool pool)
void
processingInstruction(String target, String data)
Receive notification of a Processing Instruction.protected Expression
processOccurs(Expression item, short occurence)
processes occurence (?,+,*) of the given expressionString
resolveNamespacePrefix(String prefix)
void
setDatatypeLibrary(org.relaxng.datatype.DatatypeLibrary datatypeLibrary)
void
setDeclaredLocationOf(Object o)
void
setDocumentLocator(Locator loc)
protected String[]
splitQName(String maybeQName)
returns an array of (URI,localName).void
startCDATA()
Receive notification that a CDATA section is beginning.void
startContentModel(String elementName, short type)
receives notification that parsing of content model is beginning.void
startDTD(InputEntity in)
Receive notification of the beginning of the DTD.void
startModelGroup()
void
unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
Receive notification of an unparsed entity declaration.void
warning(SAXParseException e)
-
-
-
Field Detail
-
controller
protected final Controller controller
-
namespaces
protected final 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 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 Locator locator
-
elementDecls
protected final Map elementDecls
map from element name to its content model.
-
attributeDecls
protected final 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
-
ERR_UNDEFINED_ELEMENT
public static final String ERR_UNDEFINED_ELEMENT
- See Also:
- Constant Field Values
-
WRN_ATTEMPT_TO_USE_NAMESPACE
public static final String WRN_ATTEMPT_TO_USE_NAMESPACE
- See Also:
- Constant Field Values
-
ERR_UNDECLARED_PREFIX
public static final 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(InputSource source, GrammarReaderController controller)
-
parse
public static TREXGrammar parse(InputSource source, GrammarReaderController controller, ExpressionPool pool)
-
setDatatypeLibrary
public void setDatatypeLibrary(org.relaxng.datatype.DatatypeLibrary datatypeLibrary)
-
createDatatype
public org.relaxng.datatype.Datatype createDatatype(String name)
Obtains a Datatype object from its name.
-
createInitialNamespaceMap
protected static final Map createInitialNamespaceMap()
-
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(Locator loc)
- Specified by:
setDocumentLocator
in interfaceDTDEventListener
-
startContentModel
public void startContentModel(String elementName, short type)
Description copied from interface:DTDEventListener
receives notification that parsing of content model is beginning.- Specified by:
startContentModel
in interfaceDTDEventListener
- Parameters:
elementName
- name of the element whose content model is going to be defined.type
-DTDEventListener.CONTENT_MODEL_EMPTY
this element has EMPTY content model. This notification will be immediately followed by the corresponding endContentModel.DTDEventListener.CONTENT_MODEL_ANY
this element has ANY content model. This notification will be immediately followed by the corresponding endContentModel.DTDEventListener.CONTENT_MODEL_MIXED
this element has mixed content model. #PCDATA will not be reported. each child element will be reported by mixedElement method.DTDEventListener.CONTENT_MODEL_CHILDREN
this 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(String elementName, short type)
Description copied from interface:DTDEventListener
receives notification that parsing of content model is finished.- Specified by:
endContentModel
in interfaceDTDEventListener
-
processOccurs
protected Expression processOccurs(Expression item, short occurence)
processes occurence (?,+,*) of the given expression
-
childElement
public void childElement(String elementName, short occurence)
- Specified by:
childElement
in interfaceDTDEventListener
-
combineToContentModel
protected void combineToContentModel(Expression exp)
-
mixedElement
public void mixedElement(String elementName)
Description copied from interface:DTDEventListener
receives notification of child element of mixed content model. this method is called for each child element.- Specified by:
mixedElement
in interfaceDTDEventListener
- See Also:
DTDEventListener.startContentModel(String, short)
-
startModelGroup
public void startModelGroup()
- Specified by:
startModelGroup
in interfaceDTDEventListener
-
endModelGroup
public void endModelGroup(short occurence)
- Specified by:
endModelGroup
in interfaceDTDEventListener
-
connector
public void connector(short type) throws SAXException
Description copied from interface:DTDEventListener
Connectors in one model group is guaranteed to be the same.IOW, you'll never see an event sequence like (a|b,c)
- Specified by:
connector
in interfaceDTDEventListener
- Throws:
SAXException
-
attributeDecl
public void attributeDecl(String elementName, String attributeName, String attributeType, String[] enums, short attributeUse, String defaultValue) throws SAXException
Description copied from interface:DTDEventListener
For 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:
attributeDecl
in interfaceDTDEventListener
- Throws:
SAXException
-
createAttributeBody
protected Expression createAttributeBody(String elementName, String attributeName, String attributeType, String[] enums, short attributeUse, String defaultValue) throws SAXException
Creates an attribute body from the declaration found in the DTD.- Throws:
SAXException
-
createElementDeclaration
protected ReferenceExp createElementDeclaration(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 SAXException
Description copied from interface:DTDEventListener
Receive notification of the end of a DTD. The parser will invoke this method only once.- Specified by:
endDTD
in interfaceDTDEventListener
- Throws:
SAXException
- See Also:
DTDEventListener.startDTD(InputEntity)
-
fatalError
public void fatalError(SAXParseException e) throws SAXException
- Specified by:
fatalError
in interfaceDTDEventListener
- Throws:
SAXException
-
error
public void error(SAXParseException e) throws SAXException
- Specified by:
error
in interfaceDTDEventListener
- Throws:
SAXException
-
warning
public void warning(SAXParseException e) throws SAXException
- Specified by:
warning
in interfaceDTDEventListener
- Throws:
SAXException
-
setDeclaredLocationOf
public void setDeclaredLocationOf(Object o)
-
isUnparsedEntity
public boolean isUnparsedEntity(String entityName)
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
Description copied from interface:DTDEventListener
Receive notification of a Processing Instruction. Processing instructions contain information meaningful to the application.- Specified by:
processingInstruction
in 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:
SAXException
-
notationDecl
public void notationDecl(String name, String publicId, String systemId) throws SAXException
Description copied from interface:DTDEventListener
Receive notification of a Notation Declaration. Notation declarations are used by elements and entities for identifying embedded non-XML data.- Specified by:
notationDecl
in interfaceDTDEventListener
- Parameters:
name
- The notation name, referred to by entities and elements.publicId
- The public identifiersystemId
- The system identifier- Throws:
SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException
Description copied from interface:DTDEventListener
Receive notification of an unparsed entity declaration. Unparsed entities are non-XML data.- Specified by:
unparsedEntityDecl
in interfaceDTDEventListener
- Parameters:
name
- The name of the unparsed entity.publicId
- The public identifiersystemId
- The system identifiernotationName
- The associated notation- Throws:
SAXException
-
externalGeneralEntityDecl
public void externalGeneralEntityDecl(String n, String p, String s) throws SAXException
Description copied from interface:DTDEventListener
Receive 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:
externalGeneralEntityDecl
in 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:
SAXException
- See Also:
DTDEventListener.unparsedEntityDecl(String, String, String, String)
-
internalGeneralEntityDecl
public void internalGeneralEntityDecl(String n, String v) throws SAXException
Description copied from interface:DTDEventListener
Receive notification of a internal general entity declaration event.- Specified by:
internalGeneralEntityDecl
in 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:
SAXException
- See Also:
DTDEventListener.externalGeneralEntityDecl(String, String, String)
-
externalParameterEntityDecl
public void externalParameterEntityDecl(String n, String p, String s) throws SAXException
Description copied from interface:DTDEventListener
Receive 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:
externalParameterEntityDecl
in 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:
SAXException
- See Also:
DTDEventListener.unparsedEntityDecl(String, String, String, String)
-
internalParameterEntityDecl
public void internalParameterEntityDecl(String n, String v) throws SAXException
Description copied from interface:DTDEventListener
Receive notification of a internal parameter entity declaration event.- Specified by:
internalParameterEntityDecl
in 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:
SAXException
- See Also:
DTDEventListener.externalParameterEntityDecl(String, String, String)
-
startDTD
public void startDTD(InputEntity in) throws SAXException
Description copied from interface:DTDEventListener
Receive notification of the beginning of the DTD.- Specified by:
startDTD
in interfaceDTDEventListener
- Parameters:
in
- Current input entity.- Throws:
SAXException
- See Also:
DTDEventListener.endDTD()
-
comment
public void comment(String n) throws SAXException
Description copied from interface:DTDEventListener
Receive 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:
comment
in interfaceDTDEventListener
- Parameters:
n
- the text within the comment delimiters.- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException
Description copied from interface:DTDEventListener
Receive 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:
characters
in 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:
SAXException
- See Also:
DTDEventListener.ignorableWhitespace(char[], int, int)
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
Description copied from interface:DTDEventListener
Receive 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:
ignorableWhitespace
in 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:
SAXException
- See Also:
DTDEventListener.characters(char[], int, int)
-
startCDATA
public void startCDATA() throws SAXException
Description copied from interface:DTDEventListener
Receive 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:
startCDATA
in interfaceDTDEventListener
- Throws:
SAXException
- See Also:
DTDEventListener.endCDATA()
-
endCDATA
public void endCDATA() throws SAXException
Description copied from interface:DTDEventListener
Receive notification that the CDATA section finished.- Specified by:
endCDATA
in interfaceDTDEventListener
- Throws:
SAXException
- See Also:
DTDEventListener.startCDATA()
-
-