public class

XMLDocumentFragmentScannerImpl

extends XMLScanner
implements XMLEntityHandler XMLComponent XMLDocumentScanner
java.lang.Object
   ↳ org.apache.xerces.impl.XMLScanner
     ↳ org.apache.xerces.impl.XMLDocumentFragmentScannerImpl
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

This class is responsible for scanning the structure and content of document fragments. The scanner acts as the source for the document information which is communicated to the document handler.

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

  • http://xml.org/sax/features/validation
  • http://apache.org/xml/features/scanner/notify-char-refs
  • http://apache.org/xml/features/scanner/notify-builtin-refs
  • http://apache.org/xml/properties/internal/symbol-table
  • http://apache.org/xml/properties/internal/error-reporter
  • http://apache.org/xml/properties/internal/entity-manager
@xerces.internal

Summary

Nested Classes
interface XMLDocumentFragmentScannerImpl.Dispatcher This interface defines an XML "event" dispatching model. 
class XMLDocumentFragmentScannerImpl.ElementStack Element stack. 
class XMLDocumentFragmentScannerImpl.FragmentContentDispatcher Dispatcher to handle content scanning. 
Constants
boolean DEBUG_CONTENT_SCANNING Debug content dispatcher scanning.
String ENTITY_RESOLVER Property identifier: entity resolver.
String NAMESPACES Feature identifier: namespaces.
String NOTIFY_BUILTIN_REFS Feature identifier: notify built-in refereces.
int SCANNER_STATE_CDATA Scanner state: CDATA section.
int SCANNER_STATE_COMMENT Scanner state: comment.
int SCANNER_STATE_CONTENT Scanner state: content.
int SCANNER_STATE_DOCTYPE Scanner state: DOCTYPE.
int SCANNER_STATE_END_OF_INPUT Scanner state: end of input.
int SCANNER_STATE_PI Scanner state: processing instruction.
int SCANNER_STATE_REFERENCE Scanner state: reference.
int SCANNER_STATE_ROOT_ELEMENT Scanner state: root element.
int SCANNER_STATE_START_OF_MARKUP Scanner state: start of markup.
int SCANNER_STATE_TERMINATED Scanner state: terminated.
int SCANNER_STATE_TEXT_DECL Scanner state: Text declaration.
[Expand]
Inherited Constants
From class org.apache.xerces.impl.XMLScanner
Fields
protected final QName fAttributeQName Attribute QName.
protected final XMLAttributesImpl fAttributes Element attributes.
protected XMLDocumentFragmentScannerImpl.Dispatcher fContentDispatcher Content dispatcher.
protected QName fCurrentElement Current element.
protected XMLDocumentFragmentScannerImpl.Dispatcher fDispatcher Active dispatcher.
protected XMLDocumentHandler fDocumentHandler Document handler.
protected final QName fElementQName Element QName.
protected XMLDocumentFragmentScannerImpl.ElementStack fElementStack Element stack.
protected int[] fEntityStack Entity stack.
protected ExternalSubsetResolver fExternalSubsetResolver External subset resolver.
protected boolean fHasExternalDTD has external dtd
protected boolean fInScanContent SubScanner state: inside scanContent method.
protected int fMarkupDepth Markup depth.
protected boolean fNotifyBuiltInRefs Notify built-in references.
protected int fScannerState Scanner state.
protected boolean fStandalone Standalone.
protected final XMLString fTempString String.
protected final XMLString fTempString2 String.
[Expand]
Inherited Fields
From class org.apache.xerces.impl.XMLScanner
Public Constructors
XMLDocumentFragmentScannerImpl()
Default constructor.
Public Methods
void endEntity(String name, Augmentations augs)
This method notifies the end of an entity.
String getDispatcherName(XMLDocumentFragmentScannerImpl.Dispatcher dispatcher)
Returns the dispatcher name.
XMLDocumentHandler getDocumentHandler()
Returns the document handler
Boolean getFeatureDefault(String featureId)
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
Object getPropertyDefault(String propertyId)
Returns the default state for a property, or null if this component does not want to report a default value for this property.
String[] getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this component.
String[] getRecognizedProperties()
Returns a list of property identifiers that are recognized by this component.
void reset(XMLComponentManager componentManager)
Resets the component.
boolean scanDocument(boolean complete)
Scans a document.
void setDocumentHandler(XMLDocumentHandler documentHandler)
setDocumentHandler
void setFeature(String featureId, boolean state)
Sets the state of a feature.
void setInputSource(XMLInputSource inputSource)
Sets the input source.
void setProperty(String propertyId, Object value)
Sets the value of a property.
void startEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs)
This method notifies of the start of an entity.
Protected Methods
XMLDocumentFragmentScannerImpl.Dispatcher createContentDispatcher()
Creates a content dispatcher.
String getScannerStateName(int state)
Returns the scanner state name.
int handleEndElement(QName element, boolean isEmpty)
Handles the end element.
void scanAttribute(XMLAttributes attributes)
Scans an attribute.
boolean scanCDATASection(boolean complete)
Scans a CDATA section.
void scanCharReference()
Scans a character reference.
void scanComment()
Scans a comment.
int scanContent()
Scans element content.
int scanEndElement()
Scans an end element.
void scanEntityReference()
Scans an entity reference.
void scanPIData(String target, XMLString data)
Scans a processing data.
boolean scanStartElement()
Scans a start element.
boolean scanStartElementAfterName()
Scans the remainder of a start or empty tag after the element name.
void scanStartElementName()
Scans the name of an element in a start or empty tag.
void scanXMLDeclOrTextDecl(boolean scanningTextDecl)
Scans an XML or text declaration.
final void setDispatcher(XMLDocumentFragmentScannerImpl.Dispatcher dispatcher)
Sets the dispatcher.
final void setScannerState(int state)
Sets the scanner state.
[Expand]
Inherited Methods
From class org.apache.xerces.impl.XMLScanner
From class java.lang.Object
From interface org.apache.xerces.impl.XMLEntityHandler
From interface org.apache.xerces.xni.parser.XMLComponent
From interface org.apache.xerces.xni.parser.XMLDocumentScanner
From interface org.apache.xerces.xni.parser.XMLDocumentSource

Constants

protected static final boolean DEBUG_CONTENT_SCANNING

Debug content dispatcher scanning.

Constant Value: false

protected static final String ENTITY_RESOLVER

Property identifier: entity resolver.

Constant Value: "http://apache.org/xml/properties/internal/entity-resolver"

protected static final String NAMESPACES

Feature identifier: namespaces.

Constant Value: "http://xml.org/sax/features/namespaces"

protected static final String NOTIFY_BUILTIN_REFS

Feature identifier: notify built-in refereces.

Constant Value: "http://apache.org/xml/features/scanner/notify-builtin-refs"

protected static final int SCANNER_STATE_CDATA

Scanner state: CDATA section.

Constant Value: 15 (0x0000000f)

protected static final int SCANNER_STATE_COMMENT

Scanner state: comment.

Constant Value: 2 (0x00000002)

protected static final int SCANNER_STATE_CONTENT

Scanner state: content.

Constant Value: 7 (0x00000007)

protected static final int SCANNER_STATE_DOCTYPE

Scanner state: DOCTYPE.

Constant Value: 4 (0x00000004)

protected static final int SCANNER_STATE_END_OF_INPUT

Scanner state: end of input.

Constant Value: 13 (0x0000000d)

protected static final int SCANNER_STATE_PI

Scanner state: processing instruction.

Constant Value: 3 (0x00000003)

protected static final int SCANNER_STATE_REFERENCE

Scanner state: reference.

Constant Value: 8 (0x00000008)

protected static final int SCANNER_STATE_ROOT_ELEMENT

Scanner state: root element.

Constant Value: 6 (0x00000006)

protected static final int SCANNER_STATE_START_OF_MARKUP

Scanner state: start of markup.

Constant Value: 1 (0x00000001)

protected static final int SCANNER_STATE_TERMINATED

Scanner state: terminated.

Constant Value: 14 (0x0000000e)

protected static final int SCANNER_STATE_TEXT_DECL

Scanner state: Text declaration.

Constant Value: 16 (0x00000010)

Fields

protected final QName fAttributeQName

Attribute QName.

protected final XMLAttributesImpl fAttributes

Element attributes.

protected XMLDocumentFragmentScannerImpl.Dispatcher fContentDispatcher

Content dispatcher.

protected QName fCurrentElement

Current element.

protected XMLDocumentFragmentScannerImpl.Dispatcher fDispatcher

Active dispatcher.

protected XMLDocumentHandler fDocumentHandler

Document handler.

protected final QName fElementQName

Element QName.

protected XMLDocumentFragmentScannerImpl.ElementStack fElementStack

Element stack.

protected int[] fEntityStack

Entity stack.

protected ExternalSubsetResolver fExternalSubsetResolver

External subset resolver.

protected boolean fHasExternalDTD

has external dtd

protected boolean fInScanContent

SubScanner state: inside scanContent method.

protected int fMarkupDepth

Markup depth.

protected boolean fNotifyBuiltInRefs

Notify built-in references.

protected int fScannerState

Scanner state.

protected boolean fStandalone

Standalone.

protected final XMLString fTempString

String.

protected final XMLString fTempString2

String.

Public Constructors

public XMLDocumentFragmentScannerImpl ()

Default constructor.

Public Methods

public void endEntity (String name, Augmentations augs)

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

Parameters
name The name of the entity.
augs Additional information that may include infoset augmentations
Throws
XNIException Thrown by handler to signal an error.

public String getDispatcherName (XMLDocumentFragmentScannerImpl.Dispatcher dispatcher)

Returns the dispatcher name.

public XMLDocumentHandler getDocumentHandler ()

Returns the document handler

public Boolean getFeatureDefault (String featureId)

Returns the default state for a feature, or null if this component does not want to report a default value for this feature.

Parameters
featureId The feature identifier.

public Object getPropertyDefault (String propertyId)

Returns the default state for a property, or null if this component does not want to report a default value for this property.

Parameters
propertyId The property identifier.

public String[] getRecognizedFeatures ()

Returns a list of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.

public String[] getRecognizedProperties ()

Returns a list of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.

public void reset (XMLComponentManager componentManager)

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

Parameters
componentManager The component manager.
Throws
Thrown by component on initialization error. For example, if a feature or property is required for the operation of the component, the component manager may throw a SAXNotRecognizedException or a SAXNotSupportedException.
XMLConfigurationException

public boolean scanDocument (boolean complete)

Scans a document.

Parameters
complete True if the scanner should scan the document completely, pushing all events to the registered document handler. A value of false indicates that that the scanner should only scan the next portion of the document and return. A scanner instance is permitted to completely scan a document if it does not support this "pull" scanning model.
Returns
  • True if there is more to scan, false otherwise.

public void setDocumentHandler (XMLDocumentHandler documentHandler)

setDocumentHandler

public void setFeature (String featureId, boolean state)

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 The feature identifier.
state The state of the feature.
Throws
The component should not throw this exception.
The component should not throw this exception.
XMLConfigurationException

public void setInputSource (XMLInputSource inputSource)

Sets the input source.

Parameters
inputSource The input source.
Throws
IOException Thrown on i/o error.

public void setProperty (String propertyId, Object value)

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

Note: Components should silently ignore properties that do not affect the operation of the component.

Parameters
propertyId The property identifier.
value The value of the property.
Throws
The component should not throw this exception.
The component should not throw this exception.
XMLConfigurationException

public void startEntity (String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs)

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

Parameters
name The name of the entity.
identifier The resource identifier.
encoding 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 Additional information that may include infoset augmentations
Throws
XNIException Thrown by handler to signal an error.

Protected Methods

protected XMLDocumentFragmentScannerImpl.Dispatcher createContentDispatcher ()

Creates a content dispatcher.

protected String getScannerStateName (int state)

Returns the scanner state name.

protected int handleEndElement (QName element, boolean isEmpty)

Handles the end element. This method will make sure that the end element name matches the current element and notify the handler about the end of the element and the end of any relevent prefix mappings.

Note: This method uses the fQName variable. The contents of this variable will be destroyed.

Parameters
element The element.
Returns
  • The element depth.
Throws
XNIException Thrown if the handler throws a SAX exception upon notification.

protected void scanAttribute (XMLAttributes attributes)

Scans an attribute.

 [41] Attribute ::= Name Eq AttValue
 

Note: This method assumes that the next character on the stream is the first character of the attribute name.

Note: This method uses the fAttributeQName and fQName variables. The contents of these variables will be destroyed.

Parameters
attributes The attributes list for the scanned attribute.

protected boolean scanCDATASection (boolean complete)

Scans a CDATA section.

Note: This method uses the fTempString and fStringBuffer variables.

Parameters
complete True if the CDATA section is to be scanned completely.
Returns
  • True if CDATA is completely scanned.

protected void scanCharReference ()

Scans a character reference.

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

protected void scanComment ()

Scans a comment.

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

Note: Called after scanning past '<!--'

protected int scanContent ()

Scans element content.

Returns
  • Returns the next character on the stream.

protected int scanEndElement ()

Scans an end element.

 [42] ETag ::= '</' Name S? '>'
 

Note: This method uses the fElementQName variable. The contents of this variable will be destroyed. The caller should copy the needed information out of this variable before calling this method.

Returns
  • The element depth.

protected void scanEntityReference ()

Scans an entity reference.

Throws
IOException Thrown if i/o error occurs.
XNIException Thrown if handler throws exception upon notification.

protected void scanPIData (String target, XMLString data)

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)

Parameters
target The PI target
data The string to fill in with the data

protected boolean scanStartElement ()

Scans a start element. This method will handle the binding of namespace information and notifying the handler of the start of the element.

 [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
 [40] STag ::= '<' Name (S Attribute)* S? '>'
 

Note: This method assumes that the leading '<' character has been consumed.

Note: This method uses the fElementQName and fAttributes variables. The contents of these variables will be destroyed. The caller should copy important information out of these variables before calling this method.

Returns
  • True if element is empty. (i.e. It matches production [44].

protected boolean scanStartElementAfterName ()

Scans the remainder of a start or empty tag after the element name.

Returns
  • True if element is empty.

protected void scanStartElementName ()

Scans the name of an element in a start or empty tag.

protected void scanXMLDeclOrTextDecl (boolean scanningTextDecl)

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 True if a text declaration is to be scanned instead of an XML declaration.

protected final void setDispatcher (XMLDocumentFragmentScannerImpl.Dispatcher dispatcher)

Sets the dispatcher.

Parameters
dispatcher The new dispatcher.

protected final void setScannerState (int state)

Sets the scanner state.

Parameters
state The new scanner state.