|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.crimson.parser.Parser2
This implements a fast non-validating SAX2 parser. This one always processes external parsed entities, strictly adheres to the XML 1.0 specification, and provides useful diagnostics. It supports an optimization allowing faster processing of valid standalone XML documents. For multi-language applications (such as web servers using XML processing to create dynamic content), a method supports choosing a locale for parser diagnostics which is both understood by the message recipient and supported by the parser.
This conforms to the XML 1.0 specification. To configure an XML processor which tests document conformance against XML Namespaces, provide a DtdEventListener which examines declarations of entities and notations, and have your document listener check other constraints such as ensuring xmlns* attribute values properly declare all namespace prefixes. (Only element and attribute names may contain colons, and even then the name prefix before the colon must be properly declared.)
SAX parsers produce a stream of parse events, which applications process to create an object model which is specific to their tasks. Applications which do not want to process event streams in that way should use an API producing a standardized object model, such as the W3C's Document Object Model (DOM). This parser supports building fully conformant DOM Document objects, through use of DtdEventListener extensions to SAX in conjunction with an appropriate implementation of a SAX DocumentHandler. In addition, it supports some features (exposing comments, CDATA sections, and entity references) which are allowed by DOM but not required to be reported by conformant XML processors. (As usual, the default handler for parsing events other than fatal errors ignores them.)
ValidatingParser
Nested Class Summary | |
(package private) static class |
Parser2.Catalog
|
(package private) class |
Parser2.DocLocator
|
(package private) static class |
Parser2.NameCache
|
(package private) static class |
Parser2.NameCacheEntry
|
private static class |
Parser2.NullHandler
|
Field Summary | |
private AttributesExImpl |
attTmp
|
private char[] |
charTmp
|
private org.xml.sax.ContentHandler |
contentHandler
|
private org.xml.sax.ext.DeclHandler |
declHandler
|
private static int |
DEFAULT_ELEMENT_ATTRIBUTE_LIMIT
|
private static int |
DEFAULT_ENTITY_EXPANSION_LIMIT
|
private boolean |
disallowDoctypeDecl
|
private boolean |
doLexicalPE
|
private boolean |
donePrologue
|
private org.xml.sax.DTDHandler |
dtdHandler
|
private int |
elementAttributeLimit
|
private SimpleHashtable |
elements
|
(package private) SimpleHashtable |
entities
|
private int |
entityExpansionCount
|
private int |
entityExpansionLimit
|
private org.xml.sax.ErrorHandler |
errHandler
|
private boolean |
fastStandalone
|
private boolean |
ignoreDeclarations
|
private InputEntity |
in
|
private boolean |
inExternalPE
|
private boolean |
isInAttribute
|
private boolean |
isStandalone
|
private boolean |
isValidating
|
private org.xml.sax.ext.LexicalHandler |
lexicalHandler
|
private Locale |
locale
|
private org.xml.sax.Locator |
locator
|
(package private) static Parser2.Catalog |
messages
|
private Parser2.NameCache |
nameCache
|
private String[] |
namePartsTmp
|
private boolean |
namespaces
|
private char[] |
nameTmp
|
(package private) Hashtable |
notations
|
private Vector |
nsAttTmp
nsAttTmp holds a list of namespace attributes used to check for #REQUIRED when validating and (namespaces == true && prefixes == false) |
private org.xml.sax.helpers.NamespaceSupport |
nsSupport
|
private static Parser2.NullHandler |
nullHandler
|
private SimpleHashtable |
params
|
private boolean |
prefixes
|
private String |
propertyDisallowDoctypeDecl
|
private String |
propertyElementAttributeLimit
|
private String |
propertyEntityExpansionLimit
|
private org.xml.sax.EntityResolver |
resolver
|
private String |
rootElementName
|
(package private) static boolean |
SECURITY_DEBUG
|
private boolean |
seenNSDecl
|
(package private) static String |
strANY
|
(package private) static String |
strEMPTY
|
private StringBuffer |
strTmp
|
private static boolean |
supportValidation
|
(package private) static String |
SYSTEM_PROPERTY_DISALLOW_DOCTYPE_DECL
|
(package private) static String |
SYSTEM_PROPERTY_ELEMENT_ATTRIBUTE_LIMIT
|
(package private) static String |
SYSTEM_PROPERTY_ENTITY_EXPANSION_LIMIT
|
private static String |
XmlLang
|
Constructor Summary | |
Parser2()
Construct a SAX2 parser object |
Method Summary | |
(package private) void |
afterDocument()
|
(package private) void |
afterRoot()
|
private void |
builtin(String entityName,
String entityValue)
|
Locale |
chooseLocale(String[] languages)
Chooses a client locale to use for diagnostics, using the first language specified in the list that is supported by this parser. |
private void |
content(ElementDecl element,
boolean allowEOF,
ElementValidator validator)
|
private boolean |
defaultAttributes(ElementDecl element)
Provide default attributes for an element and check for #REQUIRED attributes. |
(package private) void |
error(String messageId,
Object[] parameters)
|
private void |
expandEntityInContent(ElementDecl element,
String name,
ElementValidator validator)
|
private void |
expandEntityInLiteral(String name,
SimpleHashtable table,
boolean isEntityValue)
|
private void |
externalParameterEntity(ExternalEntity next)
|
private boolean |
externalParsedEntity(ElementDecl element,
ExternalEntity next,
ElementValidator validator)
|
private void |
fatal(String message)
|
private void |
fatal(String message,
Object[] parameters)
|
private void |
fatal(String messageId,
Object[] parameters,
Exception e)
|
private char |
getc()
|
private ContentModel |
getcps(String element,
InputEntity start)
|
private ContentModel |
getFrequency(ContentModel original)
|
Locale |
getLocale()
Returns the diagnostic locale. |
private String |
getMarkupDeclname(String roleId,
boolean qname)
|
private void |
getMixed(String element,
InputEntity start)
|
private String |
getMixedOrChildren(ElementDecl element)
|
private String |
getNmtoken()
|
private String |
getQuotedString(String type,
String extra)
|
private void |
init()
|
boolean |
isFastStandalone()
Returns true if standalone documents skip processing of all external DTD information. |
private boolean |
isXmlLang(String value)
|
private boolean |
maybeAttlistDecl()
|
private boolean |
maybeComment(boolean skipStart)
|
private boolean |
maybeConditionalSect()
|
private boolean |
maybeDoctypeDecl()
|
private boolean |
maybeElement(ElementValidator validator)
|
private boolean |
maybeElementDecl()
|
private boolean |
maybeEntityDecl()
|
private ExternalEntity |
maybeExternalID()
|
private String |
maybeGetName()
|
private Parser2.NameCacheEntry |
maybeGetNameCacheEntry()
|
private boolean |
maybeMarkupDecl()
|
private void |
maybeMisc(boolean eofOK)
|
private boolean |
maybeNotationDecl()
|
private boolean |
maybePEReference()
|
private boolean |
maybePI(boolean skipStart)
|
private String |
maybeReadAttribute(String name,
boolean must)
|
private boolean |
maybeReferenceInContent(ElementDecl element,
ElementValidator validator)
|
private void |
maybeTextDecl()
|
private boolean |
maybeWhitespace()
|
private void |
maybeXmlDecl()
|
private Parser2.NameCacheEntry |
nameCharString(char c)
|
(package private) ContentModel |
newContentModel(char type,
ContentModel next)
|
(package private) ContentModel |
newContentModel(String tag)
|
(package private) ElementValidator |
newValidator(ElementDecl element)
To validate, subclassers should create an object that can accept valid streams of element names, text, and terminate. |
private void |
nextChar(char c,
String location,
String near)
|
private String |
normalize(boolean invalidIfNeeded)
|
void |
parse(org.xml.sax.InputSource in)
SAX: Parse a document. |
private int |
parseCharNumber()
|
private void |
parseInternal(org.xml.sax.InputSource input)
|
private void |
parseLiteral(boolean isEntityValue)
|
private String |
parsePublicId()
|
private String |
parseSystemId()
|
private boolean |
peek(String s)
|
private InputEntity |
peekDeclaration(String s)
|
private Vector |
processAttributeNS(String attQName,
String type,
String value,
String defaultValue,
boolean isSpecified,
boolean isDefaulting,
Vector exceptions)
Process attributes for namespace support. |
private String[] |
processName(String qName,
boolean isAttribute,
boolean useException)
Process a qualified (prefixed) name. |
void |
pushInputBuffer(char[] buf,
int offset,
int len)
In support of the HTML DOM model of client side <xhtml:script> tag processing, this method permits data to be spliced into the input stream. |
private void |
pushReader(char[] buf,
String name,
boolean isGeneral)
|
private boolean |
pushReader(ExternalEntity next)
|
private void |
readEncoding(boolean must)
|
private void |
readStandalone()
|
private void |
readVersion(boolean must,
String versionNum)
|
private String |
resolveURI(String uri)
|
(package private) void |
setContentHandler(org.xml.sax.ContentHandler handler)
|
(package private) void |
setDeclHandler(org.xml.sax.ext.DeclHandler handler)
|
void |
setDTDHandler(org.xml.sax.DTDHandler handler)
|
(package private) void |
setEntityResolver(org.xml.sax.EntityResolver resolver)
|
(package private) void |
setErrorHandler(org.xml.sax.ErrorHandler handler)
|
void |
setFastStandalone(boolean value)
Setting this flag enables faster processing of valid standalone documents: external DTD information is not processed, and no attribute normalization or defaulting is done. |
private void |
setHandlers()
|
(package private) void |
setIsValidating(boolean value)
|
(package private) void |
setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
|
void |
setLocale(Locale l)
SAX: Used by applications to request locale for diagnostics. |
(package private) void |
setNamespaceFeatures(boolean namespaces,
boolean prefixes)
Set up the namespace related features for this parser. |
(package private) void |
setSecurityConstraintValues()
|
private int |
surrogatesToCharTmp(int ucs4)
|
private void |
ungetc()
|
(package private) void |
validateAttributeSyntax(AttributeDecl attr,
String value)
To validate, subclassers should at this time make sure that values are of the declared types: ID and IDREF(S) values are Names NMTOKEN(S) are Nmtokens ENUMERATION values match one of the tokens NOTATION values match a notation name ENTITIY(IES) values match an unparsed external entity Separately, make sure IDREF values match some ID provided in the document (in the afterRoot method). |
private void |
warning(String messageId,
Object[] parameters)
|
private void |
whitespace(String roleId)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private InputEntity in
private AttributesExImpl attTmp
private StringBuffer strTmp
private char[] nameTmp
private Parser2.NameCache nameCache
private char[] charTmp
private String[] namePartsTmp
private boolean seenNSDecl
private org.xml.sax.helpers.NamespaceSupport nsSupport
private Vector nsAttTmp
private boolean isValidating
private boolean fastStandalone
private boolean isInAttribute
private boolean namespaces
private boolean prefixes
private boolean inExternalPE
private boolean doLexicalPE
private boolean donePrologue
private boolean isStandalone
private String rootElementName
private boolean ignoreDeclarations
private SimpleHashtable elements
private SimpleHashtable params
Hashtable notations
SimpleHashtable entities
private org.xml.sax.ContentHandler contentHandler
private org.xml.sax.DTDHandler dtdHandler
private org.xml.sax.EntityResolver resolver
private org.xml.sax.ErrorHandler errHandler
private Locale locale
private org.xml.sax.Locator locator
private org.xml.sax.ext.DeclHandler declHandler
private org.xml.sax.ext.LexicalHandler lexicalHandler
private boolean disallowDoctypeDecl
private String propertyEntityExpansionLimit
private String propertyDisallowDoctypeDecl
private String propertyElementAttributeLimit
private int entityExpansionCount
private int entityExpansionLimit
private int elementAttributeLimit
private static final int DEFAULT_ENTITY_EXPANSION_LIMIT
private static final int DEFAULT_ELEMENT_ATTRIBUTE_LIMIT
private static final boolean supportValidation
static final String strANY
static final String strEMPTY
static final String SYSTEM_PROPERTY_ENTITY_EXPANSION_LIMIT
static final String SYSTEM_PROPERTY_DISALLOW_DOCTYPE_DECL
static final String SYSTEM_PROPERTY_ELEMENT_ATTRIBUTE_LIMIT
static final boolean SECURITY_DEBUG
private static final Parser2.NullHandler nullHandler
private static final String XmlLang
static final Parser2.Catalog messages
Constructor Detail |
public Parser2()
Method Detail |
void setNamespaceFeatures(boolean namespaces, boolean prefixes)
void setEntityResolver(org.xml.sax.EntityResolver resolver)
public void setDTDHandler(org.xml.sax.DTDHandler handler)
void setContentHandler(org.xml.sax.ContentHandler handler)
void setErrorHandler(org.xml.sax.ErrorHandler handler)
void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
void setDeclHandler(org.xml.sax.ext.DeclHandler handler)
public void setLocale(Locale l) throws org.xml.sax.SAXException
l
- The locale to use, or null to use system defaults
(which may include only message IDs).
org.xml.sax.SAXException
- If no diagnostic messages are available
in that locale.public Locale getLocale()
public Locale chooseLocale(String[] languages) throws org.xml.sax.SAXException
languages
- Array of language specifiers, ordered with the most
preferable one at the front. For example, "en-ca" then "fr-ca",
followed by "zh_CN". Both RFC 1766 and Java styles are supported.
org.xml.sax.SAXException
MessageCatalog
public void parse(org.xml.sax.InputSource in) throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
public void setFastStandalone(boolean value)
For documents which are declared as standalone, but which are not valid, a fatal error may be reported for references to externally defined entities. That could happen in any nonvalidating parser which did not read externally defined entities. Also, if any attribute values need normalization or defaulting, it will not be done.
public boolean isFastStandalone()
public void pushInputBuffer(char[] buf, int offset, int len) throws org.xml.sax.SAXException
org.xml.sax.SAXException
void setIsValidating(boolean value)
private void init()
void setSecurityConstraintValues()
private void setHandlers()
private void builtin(String entityName, String entityValue)
private void parseInternal(org.xml.sax.InputSource input) throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
void afterRoot() throws org.xml.sax.SAXException
org.xml.sax.SAXException
void afterDocument()
private void whitespace(String roleId) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeWhitespace() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String maybeGetName() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private Parser2.NameCacheEntry maybeGetNameCacheEntry() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String getNmtoken() throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
private Parser2.NameCacheEntry nameCharString(char c) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void parseLiteral(boolean isEntityValue) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void expandEntityInLiteral(String name, SimpleHashtable table, boolean isEntityValue) throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
private String getQuotedString(String type, String extra) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String parsePublicId() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeComment(boolean skipStart) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybePI(boolean skipStart) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void maybeXmlDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String maybeReadAttribute(String name, boolean must) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void readVersion(boolean must, String versionNum) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void maybeMisc(boolean eofOK) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String getMarkupDeclname(String roleId, boolean qname) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeDoctypeDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeMarkupDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void readStandalone() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean isXmlLang(String value)
private boolean maybeElement(ElementValidator validator) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private Vector processAttributeNS(String attQName, String type, String value, String defaultValue, boolean isSpecified, boolean isDefaulting, Vector exceptions) throws org.xml.sax.SAXException
isDefaulting
param specifies where the code is called
from.
isDefaulting
- true iff we are processing this attribute from
the defaultAttributes(...)
method
The namespace processing code is derived from the SAX2 ParserAdapter
code. This code should be kept in sync with ParserAdapter bug
fixes.
Note: Modifies seenNSDecl
iff a xmlns attribute, ie a
namespace decl, was found. Modifies attTmp
and
nsAttTmp
.
org.xml.sax.SAXException
private String[] processName(String qName, boolean isAttribute, boolean useException) throws org.xml.sax.SAXException
If the name has an undeclared prefix, use only the qname and make an ErrorHandler.error callback in case the app is interested.
qName
- The qualified (prefixed) name.isAttribute
- true if this is an attribute name.
org.xml.sax.SAXException
- The client may throw
an exception if there is an error callback.ElementValidator newValidator(ElementDecl element)
void validateAttributeSyntax(AttributeDecl attr, String value) throws org.xml.sax.SAXException
Separately, make sure IDREF values match some ID provided in the document (in the afterRoot method).
org.xml.sax.SAXException
private boolean defaultAttributes(ElementDecl element) throws org.xml.sax.SAXException
attTmp
and
nsAttTmp
org.xml.sax.SAXException
private void content(ElementDecl element, boolean allowEOF, ElementValidator validator) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeElementDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String getMixedOrChildren(ElementDecl element) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
ContentModel newContentModel(String tag)
ContentModel newContentModel(char type, ContentModel next)
private ContentModel getcps(String element, InputEntity start) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private ContentModel getFrequency(ContentModel original) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void getMixed(String element, InputEntity start) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeAttlistDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String normalize(boolean invalidIfNeeded) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private boolean maybeConditionalSect() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeReferenceInContent(ElementDecl element, ElementValidator validator) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private int parseCharNumber() throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
private int surrogatesToCharTmp(int ucs4) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void expandEntityInContent(ElementDecl element, String name, ElementValidator validator) throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
private boolean maybePEReference() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeEntityDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private ExternalEntity maybeExternalID() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String parseSystemId() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private String resolveURI(String uri) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void maybeTextDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean externalParsedEntity(ElementDecl element, ExternalEntity next, ElementValidator validator) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void externalParameterEntity(ExternalEntity next) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void readEncoding(boolean must) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private boolean maybeNotationDecl() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private char getc() throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void ungetc()
private boolean peek(String s) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private InputEntity peekDeclaration(String s) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void nextChar(char c, String location, String near) throws IOException, org.xml.sax.SAXException
IOException
org.xml.sax.SAXException
private void pushReader(char[] buf, String name, boolean isGeneral) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private boolean pushReader(ExternalEntity next) throws org.xml.sax.SAXException, IOException
org.xml.sax.SAXException
IOException
private void warning(String messageId, Object[] parameters) throws org.xml.sax.SAXException
org.xml.sax.SAXException
void error(String messageId, Object[] parameters) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void fatal(String message) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void fatal(String message, Object[] parameters) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void fatal(String messageId, Object[] parameters, Exception e) throws org.xml.sax.SAXException
org.xml.sax.SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |