Top Description Fields Constructors Methods
org.apache.xerces.impl

public abstract Class XMLScanner

extends Object
implements XMLComponent
Class Inheritance
All Implemented Interfaces
org.apache.xerces.xni.parser.XMLComponent
Known Direct Subclasses
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl, org.apache.xerces.impl.XMLDTDScannerImpl
Imports
java.io.IOException, org.apache.xerces.impl.msg.XMLMessageFormatter, org.apache.xerces.util.SymbolTable, .XMLChar, .XMLResourceIdentifierImpl, .XMLStringBuffer, org.apache.xerces.xni.Augmentations, .XMLResourceIdentifier, .XMLString, .XNIException, org.apache.xerces.xni.parser.XMLComponent, .XMLComponentManager, .XMLConfigurationException

This class is responsible for holding scanning methods common to scanning the XML document structure and content as well as the DTD structure and content. Both XMLDocumentScanner and XMLDTDScanner inherit from this base class.

This component requires the following features and properties from the component manager that uses it:

Authors
Andy Clark, IBM, Arnaud Le Hors, IBM, Eric Ye, IBM
Version
$Id: XMLScanner.java 1499506 2013-07-03 18:29:43Z mrglavas $

Field Summary

Modifier and TypeField and Description
protected static final boolean
DEBUG_ATTR_NORMALIZATION

Debug attribute normalization.

protected static final String
ENTITY_MANAGER

Property identifier: entity manager.

protected static final String
ERROR_REPORTER

Property identifier: error reporter.

protected static final String
fAmpSymbol

Symbol: "amp".

protected static final String
fAposSymbol

Symbol: "apos".

protected String
fCharRefLiteral

Literal value of the last character refence scanned.

protected static final String
fEncodingSymbol

Symbol: "encoding".

protected int
fEntityDepth

Entity depth.

protected XMLEntityManager
fEntityManager

Entity manager.

protected XMLEntityScanner
fEntityScanner

Entity scanner.

protected XMLErrorReporter
fErrorReporter

Error reporter.

protected static final String
fGtSymbol

Symbol: "gt".

protected static final String
fLtSymbol

Symbol: "lt".

protected boolean
fNamespaces

Namespaces.

protected boolean
fNotifyCharRefs

Character references notification.

protected boolean
fParserSettings

Internal parser-settings feature

protected static final String
fQuotSymbol

Symbol: "quot".

protected boolean
fReportEntity

Report entity boundary.

protected final XMLResourceIdentifierImpl
protected boolean
fScanningAttribute

Scanning attribute.

protected static final String
fStandaloneSymbol

Symbol: "standalone".

private final XMLString
fString

String.

private final XMLStringBuffer
fStringBuffer

String buffer.

private final XMLStringBuffer
fStringBuffer2

String buffer.

private final XMLStringBuffer
fStringBuffer3

String buffer.

protected SymbolTable
fSymbolTable

Symbol table.

protected boolean
fValidation

Validation.

protected static final String
fVersionSymbol

Symbol: "version".

protected static final String
NAMESPACES

Feature identifier: namespaces.

protected static final String
NOTIFY_CHAR_REFS

Feature identifier: notify character references.

protected static final String
protected static final String
SYMBOL_TABLE

Property identifier: symbol table.

protected static final String
VALIDATION

Feature identifier: validation.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
endEntity(String
The name of the entity.
name
,
Augmentations
Additional information that may include infoset augmentations
augs
)

This method notifies the end of an entity.

public boolean
getFeature(String featureId)

protected String
private void
init()

protected boolean
isInvalid(int value)

protected boolean
isInvalidLiteral(int value)

protected int

Returns:

-1 if the value would be unchanged by normalization, otherwise the index of the first whitespace character which would be transformed.
isUnchangedByNormalization
(XMLString value)

Checks whether this string would be unchanged by normalization.

protected boolean
isValidNameChar(int value)

protected boolean
protected boolean
protected boolean
isValidNCName(int value)

protected void
normalizeWhitespace(XMLString value)

Normalize whitespace in an XMLString converting all whitespace characters to space characters.

protected void
normalizeWhitespace(XMLString value, int fromIndex)

Normalize whitespace in an XMLString converting all whitespace characters to space characters.

protected void
reportFatalError(String msgId, Object[] args)

Convenience function used in all XML scanners.

public void
reset(XMLComponentManager
The component manager.
componentManager
)

Implements org.apache.xerces.xni.parser.XMLComponent.reset.

Resets the component.
protected void
protected boolean

Returns:

true if the non-normalized and normalized value are the same

Note

This method uses fStringBuffer2, anything in it at the time of calling is lost.

scanAttributeValue
(XMLString
The XMLString to fill in with the value.
value
,
XMLString
The XMLString to fill in with the non-normalized value.
nonNormalizedValue
,
String
The name of the attribute being parsed (for error msgs).
atName
,
boolean
true if undeclared entities should be reported as VC violation, false if undeclared entities should be reported as WFC violation.
checkEntities
,
String
The name of element to which this attribute belongs.
eleName
)

Scans an attribute value and normalizes whitespace converting all whitespace characters to space characters.

protected int

Returns:

the character value or (-1) on conversion failure
scanCharReferenceValue
(XMLStringBuffer
the character buffer to append chars to
buf
,
XMLStringBuffer
the character buffer to append non-normalized chars to
buf2
)

Scans a character reference and append the corresponding chars to the specified buffer.

protected void
scanComment(XMLStringBuffer
The buffer to fill in with the text.
text
)

Scans a comment.

protected void
scanExternalID(String[]
An array of size 2 to return the system id, and public id (in that order).
identifiers
,
boolean
Specifies whether the system id is optional

Note

This method uses fString and fStringBuffer, anything in them at the time of calling is lost.

optionalSystemId
)

Scans External ID and return the public and system IDs.

protected void
scanPI()

Scans a processing instruction.

protected void
scanPIData(String
The PI target
target
,
XMLString
The string to fill in with the data
data
)

Scans a processing data.

public String

Returns:

The name of the attribute

Note

This method uses fStringBuffer2, anything in it at the time of calling is lost.

scanPseudoAttribute
(boolean
True if scanning this pseudo-attribute for a TextDecl; false if scanning XMLDecl. This flag is needed to report the correct type of error.
scanningTextDecl
,
XMLString
The string to fill in with the attribute value.
value
)

Scans a pseudo attribute.

private String

Returns:

the name of the pseudo attribute or null if a legal pseudo attribute name could not be scanned.
scanPseudoAttributeName
()

Scans the name of a pseudo attribute.

protected boolean

Returns:

True on success

Note

This method uses fStringBuffer, anything in it at the time of calling is lost.

scanPubidLiteral
(XMLString
The string to fill in with the public ID literal.
literal
)

Scans public ID literal.

protected boolean

Returns:

True if it succeeded.
scanSurrogates
(XMLStringBuffer
The StringBuffer to append the read surrogates to.
buf
)

Scans surrogates and append them to the specified buffer.

protected void
scanXMLDeclOrTextDecl(boolean
True if a text declaration is to be scanned instead of an XML declaration.
scanningTextDecl
,
String[]
An array of size 3 to return the version, encoding and standalone pseudo attribute values (in that order)

Note

This method uses fString, anything in it at the time of calling is lost.

pseudoAttributeValues
)

Scans an XML or text declaration.

public void
setFeature(String
The feature identifier.
featureId
,
boolean
The state of the feature.
value
)

Implements org.apache.xerces.xni.parser.XMLComponent.setFeature.

Sets the state of a feature.
public void
setProperty(String propertyId, Object value)

Implements org.apache.xerces.xni.parser.XMLComponent.setProperty.

Sets the value of a property during parsing.
public void
startEntity(String
The name of the entity.
name
,
XMLResourceIdentifier
The resource identifier.
identifier
,
String
The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
encoding
,
Augmentations
Additional information that may include infoset augmentations
augs
)

This method notifies of the start of an entity.

protected boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUG_ATTR_NORMALIZATIONback to summary
protected static final boolean DEBUG_ATTR_NORMALIZATION

Debug attribute normalization.

ENTITY_MANAGERback to summary
protected static final String ENTITY_MANAGER

Property identifier: entity manager.

ERROR_REPORTERback to summary
protected static final String ERROR_REPORTER

Property identifier: error reporter.

fAmpSymbolback to summary
protected static final String fAmpSymbol

Symbol: "amp".

fAposSymbolback to summary
protected static final String fAposSymbol

Symbol: "apos".

fCharRefLiteralback to summary
protected String fCharRefLiteral

Literal value of the last character refence scanned.

fEncodingSymbolback to summary
protected static final String fEncodingSymbol

Symbol: "encoding".

fEntityDepthback to summary
protected int fEntityDepth

Entity depth.

fEntityManagerback to summary
protected XMLEntityManager fEntityManager

Entity manager.

fEntityScannerback to summary
protected XMLEntityScanner fEntityScanner

Entity scanner.

fErrorReporterback to summary
protected XMLErrorReporter fErrorReporter

Error reporter.

fGtSymbolback to summary
protected static final String fGtSymbol

Symbol: "gt".

fLtSymbolback to summary
protected static final String fLtSymbol

Symbol: "lt".

fNamespacesback to summary
protected boolean fNamespaces

Namespaces.

fNotifyCharRefsback to summary
protected boolean fNotifyCharRefs

Character references notification.

fParserSettingsback to summary
protected boolean fParserSettings

Internal parser-settings feature

fQuotSymbolback to summary
protected static final String fQuotSymbol

Symbol: "quot".

fReportEntityback to summary
protected boolean fReportEntity

Report entity boundary.

fResourceIdentifierback to summary
protected final XMLResourceIdentifierImpl fResourceIdentifier
fScanningAttributeback to summary
protected boolean fScanningAttribute

Scanning attribute.

fStandaloneSymbolback to summary
protected static final String fStandaloneSymbol

Symbol: "standalone".

fStringback to summary
private final XMLString fString

String.

fStringBufferback to summary
private final XMLStringBuffer fStringBuffer

String buffer.

fStringBuffer2back to summary
private final XMLStringBuffer fStringBuffer2

String buffer.

fStringBuffer3back to summary
private final XMLStringBuffer fStringBuffer3

String buffer.

fSymbolTableback to summary
protected SymbolTable fSymbolTable

Symbol table.

fValidationback to summary
protected boolean fValidation

Validation. This feature identifier is: http://xml.org/sax/features/validation

fVersionSymbolback to summary
protected static final String fVersionSymbol

Symbol: "version".

NAMESPACESback to summary
protected static final String NAMESPACES

Feature identifier: namespaces.

NOTIFY_CHAR_REFSback to summary
protected static final String NOTIFY_CHAR_REFS

Feature identifier: notify character references.

PARSER_SETTINGSback to summary
protected static final String PARSER_SETTINGS
SYMBOL_TABLEback to summary
protected static final String SYMBOL_TABLE

Property identifier: symbol table.

VALIDATIONback to summary
protected static final String VALIDATION

Feature identifier: validation.

Constructor Detail

XMLScannerback to summary
public XMLScanner()

Method Detail

endEntityback to summary
public void endEntity(String name, Augmentations augs) throws XNIException

This method notifies the end of an entity. The document entity has the pseudo-name of "[xml]" the DTD has the pseudo-name of "[dtd]" parameter entity names start with '%'; and general entities are just specified by their name.

Parameters
name:String

The name of the entity.

augs:Augmentations

Additional information that may include infoset augmentations

Exceptions
XNIException:
Thrown by handler to signal an error.
getFeatureback to summary
public boolean getFeature(String featureId) throws XMLConfigurationException
getVersionNotSupportedKeyback to summary
protected String getVersionNotSupportedKey()
initback to summary
private void init()
isInvalidback to summary
protected boolean isInvalid(int value)
isInvalidLiteralback to summary
protected boolean isInvalidLiteral(int value)
isUnchangedByNormalizationback to summary
protected int isUnchangedByNormalization(XMLString value)

Checks whether this string would be unchanged by normalization.

Returns:int

-1 if the value would be unchanged by normalization, otherwise the index of the first whitespace character which would be transformed.

isValidNameCharback to summary
protected boolean isValidNameChar(int value)
isValidNameStartCharback to summary
protected boolean isValidNameStartChar(int value)
isValidNameStartHighSurrogateback to summary
protected boolean isValidNameStartHighSurrogate(int value)
isValidNCNameback to summary
protected boolean isValidNCName(int value)
normalizeWhitespaceback to summary
protected void normalizeWhitespace(XMLString value)

Normalize whitespace in an XMLString converting all whitespace characters to space characters.

normalizeWhitespaceback to summary
protected void normalizeWhitespace(XMLString value, int fromIndex)

Normalize whitespace in an XMLString converting all whitespace characters to space characters.

reportFatalErrorback to summary
protected void reportFatalError(String msgId, Object[] args) throws XNIException

Convenience function used in all XML scanners.

resetback to summary
public void reset(XMLComponentManager componentManager) throws XMLConfigurationException

Implements org.apache.xerces.xni.parser.XMLComponent.reset.

Doc from org.apache.xerces.xni.parser.XMLComponent.reset.

Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

Parameters
componentManager:XMLComponentManager

The component manager.

Exceptions
SAXException:
Throws exception if required features and properties cannot be found.
resetback to summary
protected void reset()
scanAttributeValueback to summary
protected boolean scanAttributeValue(XMLString value, XMLString nonNormalizedValue, String atName, boolean checkEntities, String eleName) throws IOException, XNIException

Scans an attribute value and normalizes whitespace converting all whitespace characters to space characters. [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"

Parameters
value:XMLString

The XMLString to fill in with the value.

nonNormalizedValue:XMLString

The XMLString to fill in with the non-normalized value.

atName:String

The name of the attribute being parsed (for error msgs).

checkEntities:boolean

true if undeclared entities should be reported as VC violation, false if undeclared entities should be reported as WFC violation.

eleName:String

The name of element to which this attribute belongs.

Returns:boolean

true if the non-normalized and normalized value are the same

Note

This method uses fStringBuffer2, anything in it at the time of calling is lost.

scanCharReferenceValueback to summary
protected int scanCharReferenceValue(XMLStringBuffer buf, XMLStringBuffer buf2) throws IOException, XNIException

Scans a character reference and append the corresponding chars to the specified buffer.

[66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'

Note

This method uses fStringBuffer, anything in it at the time of calling is lost.

Parameters
buf:XMLStringBuffer

the character buffer to append chars to

buf2:XMLStringBuffer

the character buffer to append non-normalized chars to

Returns:int

the character value or (-1) on conversion failure

scanCommentback to summary
protected void scanComment(XMLStringBuffer text) throws IOException, XNIException

Scans a comment.

[15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'

Note

Called after scanning past '<!--'

Note

This method uses fString, anything in it at the time of calling is lost.

Parameters
text:XMLStringBuffer

The buffer to fill in with the text.

scanExternalIDback to summary
protected void scanExternalID(String[] identifiers, boolean optionalSystemId) throws IOException, XNIException

Scans External ID and return the public and system IDs.

Parameters
identifiers:String[]

An array of size 2 to return the system id, and public id (in that order).

optionalSystemId:boolean

Specifies whether the system id is optional

Note

This method uses fString and fStringBuffer, anything in them at the time of calling is lost.

scanPIback to summary
protected void scanPI() throws IOException, XNIException

Scans a processing instruction.

[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
[17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))

Note

This method uses fString, anything in it at the time of calling is lost.

scanPIDataback to summary
protected void scanPIData(String target, XMLString data) throws IOException, XNIException

Scans a processing data. This is needed to handle the situation where a document starts with a processing instruction whose target name starts with "xml". (e.g. xmlfoo)

Note

This method uses fStringBuffer, anything in it at the time of calling is lost.

Parameters
target:String

The PI target

data:XMLString

The string to fill in with the data

scanPseudoAttributeback to summary
public String scanPseudoAttribute(boolean scanningTextDecl, XMLString value) throws IOException, XNIException

Scans a pseudo attribute.

Parameters
scanningTextDecl:boolean

True if scanning this pseudo-attribute for a TextDecl; false if scanning XMLDecl. This flag is needed to report the correct type of error.

value:XMLString

The string to fill in with the attribute value.

Returns:String

The name of the attribute

Note

This method uses fStringBuffer2, anything in it at the time of calling is lost.

scanPseudoAttributeNameback to summary
private String scanPseudoAttributeName() throws IOException, XNIException

Scans the name of a pseudo attribute. The only legal names in XML 1.0/1.1 documents are 'version', 'encoding' and 'standalone'.

Returns:String

the name of the pseudo attribute or null if a legal pseudo attribute name could not be scanned.

scanPubidLiteralback to summary
protected boolean scanPubidLiteral(XMLString literal) throws IOException, XNIException

Scans public ID literal. [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" [13] PubidChar::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] The returned string is normalized according to the following rule, from http://www.w3.org/TR/REC-xml#dt-pubid: Before a match is attempted, all strings of white space in the public identifier must be normalized to single space characters (#x20), and leading and trailing white space must be removed.

Parameters
literal:XMLString

The string to fill in with the public ID literal.

Returns:boolean

True on success

Note

This method uses fStringBuffer, anything in it at the time of calling is lost.

scanSurrogatesback to summary
protected boolean scanSurrogates(XMLStringBuffer buf) throws IOException, XNIException

Scans surrogates and append them to the specified buffer.

Note

This assumes the current char has already been identified as a high surrogate.

Parameters
buf:XMLStringBuffer

The StringBuffer to append the read surrogates to.

Returns:boolean

True if it succeeded.

scanXMLDeclOrTextDeclback to summary
protected void scanXMLDeclOrTextDecl(boolean scanningTextDecl, String[] pseudoAttributeValues) throws IOException, XNIException

Scans an XML or text declaration.

[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
[24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")
[80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' |  "'" EncName "'" )
[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
[32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'")
                | ('"' ('yes' | 'no') '"'))

[77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
Parameters
scanningTextDecl:boolean

True if a text declaration is to be scanned instead of an XML declaration.

pseudoAttributeValues:String[]

An array of size 3 to return the version, encoding and standalone pseudo attribute values (in that order)

Note

This method uses fString, anything in it at the time of calling is lost.

setFeatureback to summary
public void setFeature(String featureId, boolean value) throws XMLConfigurationException

Implements org.apache.xerces.xni.parser.XMLComponent.setFeature.

Doc from org.apache.xerces.xni.parser.XMLComponent.setFeature.

Sets the state of a feature. This method is called by the component manager any time after reset when a feature changes state.

Note

Components should silently ignore features that do not affect the operation of the component.

Parameters
featureId:String

The feature identifier.

value:boolean

The state of the feature.

Exceptions
XMLConfigurationException:
Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.
setPropertyback to summary
public void setProperty(String propertyId, Object value) throws XMLConfigurationException

Implements org.apache.xerces.xni.parser.XMLComponent.setProperty.

Sets the value of a property during parsing.

Exceptions
XMLConfigurationException:

Doc from org.apache.xerces.xni.parser.XMLComponent.setProperty.

Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.

startEntityback to summary
public void startEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException

This method notifies of the start of an entity. The document entity has the pseudo-name of "[xml]" the DTD has the pseudo-name of "[dtd]" parameter entity names start with '%'; and general entities are just specified by their name.

Parameters
name:String

The name of the entity.

identifier:XMLResourceIdentifier

The resource identifier.

encoding:String

The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).

augs:Augmentations

Additional information that may include infoset augmentations

Exceptions
XNIException:
Thrown by handler to signal an error.
versionSupportedback to summary
protected boolean versionSupported(String version)