public class DocumentLoader extends Object implements LexicalHandler, DeclHandler, DTDHandler, ContentHandler, EntityResolver2, ErrorHandler, LoadOptions
Automatically added properties (unless setOptions(int)
is used to
influence added properties):
Constants.NAMESPACE_PREFIX_MAP_PROPERTY
.
Constants.SOURCE_URL_PROPERTY
.
Constants.ENTITIES_PROPERTY
,
for a document having an implicit or explicit <!DOCTYPE>.
Constants.INCLUSION_PROPERTY
,
Constants.READ_ONLY_PROPERTY
,
for topmost nodes included using a reference to an internal
or external entities.
The same DocumentLoader may be reused several times (though it is not specially recommended to do so).
LoadDocument
Modifier and Type | Class and Description |
---|---|
protected static class |
DocumentLoader.StackItem |
Modifier and Type | Field and Description |
---|---|
protected static char[] |
cdataMark |
protected int |
charCount |
protected char[] |
chars |
protected PrefixEntry[] |
declaredPrefixes |
protected int |
dtdEntityNesting |
protected DTDSpec |
dtdSpec |
protected String |
encoding |
protected Entities |
entities |
protected String |
externalSubsetOrigin |
protected boolean |
firstElement |
protected boolean |
insideDTD |
protected boolean |
insideExternalSubset |
protected StringBuilder |
internalSubset |
protected String |
internalSubsetOrigin |
protected boolean |
isCharEntity |
protected Locator2 |
locator |
protected PrefixPreferences |
nsPrefixMap |
protected int |
options |
protected XMLReader |
parser |
protected DocumentLoader.StackItem[] |
stack |
protected int |
stackSize |
protected String |
standalone |
protected String |
version |
protected boolean |
wasCDATA |
ADD_ANY_DOCUMENT_TYPE, ADD_AUTO_DOCUMENT_TYPE, ADD_DECLARED_PREFIXES, ADD_LINE_COLUMN, ADD_XML_DECLARATION, DONT_INCLUDE, DONT_STRIP_WHITESPACE, GUESS_IGNORABLE_WHITESPACE, XINCLUDE
Constructor and Description |
---|
DocumentLoader()
Constructs a low-level document loader having no options.
|
Modifier and Type | Method and Description |
---|---|
void |
attributeDecl(String eName,
String aName,
String type,
String mode,
String value) |
protected URL |
baseURL() |
void |
characters(char[] ch,
int start,
int length) |
protected void |
checkChars(DocumentLoader.StackItem top) |
protected void |
checkEntityRef(DocumentLoader.StackItem top,
Node node) |
void |
comment(char[] ch,
int start,
int length) |
protected DocumentTypeDeclaration |
createDocumentTypeDeclaration() |
void |
elementDecl(String name,
String model) |
void |
endCDATA() |
void |
endDocument() |
void |
endDTD() |
void |
endElement(String uri,
String localName,
String qName) |
void |
endEntity(String name) |
void |
endPrefixMapping(String prefix) |
protected String |
entityOrigin() |
void |
error(SAXParseException e) |
void |
externalEntityDecl(String name,
String publicId,
String systemId) |
void |
fatalError(SAXParseException e) |
static String |
format(SAXParseException e)
Helper: returns a formatted string representing specified
SAXParseException . |
protected URL |
getDocumentURL() |
DTDSpec |
getDTDSpec()
Returns a representation of the DTD specified in the implicit
or explicit <!
|
String |
getEncoding()
Returns the value of the encoding pseudo-attribute as found
in the XML declaration (that is, <?
|
InputSource |
getExternalSubset(String name,
String baseURI) |
int |
getOptions()
Returns current document load options.
|
String |
getStandalone()
Returns the value of the standalone pseudo-attribute as found
in the XML declaration (that is, <?
|
String |
getVersion()
Returns the value of the version pseudo-attribute as found
in the XML declaration (that is, <?
|
void |
ignorableWhitespace(char[] ch,
int start,
int length) |
void |
internalEntityDecl(String name,
String value) |
Document |
load(File file)
Loads document from specified file.
|
Document |
load(InputSource source)
Loads document from specified source.
|
Document |
load(URL url)
Equivalent to
load(url, false) . |
Document |
load(URL url,
boolean useCache)
Loads document from specified file.
|
void |
notationDecl(String name,
String publicId,
String systemId) |
protected void |
pop() |
void |
processingInstruction(String target,
String data) |
protected void |
push(Tree tree,
int entityNesting,
EntityRef entityRef,
URL entityURL) |
InputSource |
resolveEntity(String publicId,
String systemId) |
InputSource |
resolveEntity(String name,
String publicId,
String baseURI,
String systemId) |
protected void |
rootElement(Element element) |
void |
setDocumentLocator(Locator locator) |
void |
setOptions(int options)
Specifies document load options, an OR-ed mask of
LoadOptions.ADD_DECLARED_PREFIXES ,
LoadOptions.ADD_LINE_COLUMN , etc. |
void |
skippedEntity(String name) |
void |
startCDATA() |
void |
startDocument() |
void |
startDTD(String name,
String publicId,
String systemId) |
void |
startElement(String uri,
String localName,
String qName,
Attributes atts) |
void |
startEntity(String name) |
void |
startPrefixMapping(String prefix,
String uri) |
protected DocumentLoader.StackItem |
top() |
void |
unparsedEntityDecl(String name,
String publicId,
String systemId,
String notationName) |
void |
warning(SAXParseException e) |
protected int options
protected XMLReader parser
protected DocumentLoader.StackItem[] stack
protected int stackSize
protected Locator2 locator
protected boolean insideDTD
protected DTDSpec dtdSpec
protected StringBuilder internalSubset
protected int dtdEntityNesting
protected boolean insideExternalSubset
protected Entities entities
protected String internalSubsetOrigin
protected String externalSubsetOrigin
protected boolean firstElement
protected PrefixPreferences nsPrefixMap
protected PrefixEntry[] declaredPrefixes
protected boolean isCharEntity
protected char[] chars
protected int charCount
protected boolean wasCDATA
protected static final char[] cdataMark
protected String version
protected String encoding
protected String standalone
public DocumentLoader()
setOptions(int)
public void setOptions(int options)
LoadOptions.ADD_DECLARED_PREFIXES
,
LoadOptions.ADD_LINE_COLUMN
, etc.
By default, the options mask is 0x0
.
public int getOptions()
public Document load(File file) throws SAXException, IOException
file
- filename of the XML source fileIOException
- if an I/O error occurs during this operationSAXException
- for any other problem: for example,
if the source file does not contain well-formed XMLpublic Document load(URL url) throws SAXException, IOException
load(url, false)
.SAXException
IOException
public Document load(URL url, boolean useCache) throws SAXException, IOException
url
- URL of the XML source fileuseCache
- if true
the loaded document
may be a cached copyIOException
- if an I/O error occurs during this operationSAXException
- for any other problem: for example,
if the source file does not contain well-formed XMLpublic Document load(InputSource source) throws SAXException, IOException
source
- the XML sourceIOException
- if an I/O error occurs during this operationSAXException
- for any other problem: for example,
if the source does not contain well-formed XMLpublic String getVersion()
null
if this value cannot be determined.public String getEncoding()
null
if this value cannot be determined or
is unspecified.public String getStandalone()
null
if this value cannot be determined or
is unspecified.public DTDSpec getDTDSpec()
null
if loaded document had no
implicit or explicit <!DOCTYPE>.public static String format(SAXParseException e)
SAXParseException
.protected void pop()
protected DocumentLoader.StackItem top()
protected URL getDocumentURL()
public void startDTD(String name, String publicId, String systemId) throws SAXException
startDTD
in interface LexicalHandler
SAXException
protected URL baseURL()
public void endDTD() throws SAXException
endDTD
in interface LexicalHandler
SAXException
protected DocumentTypeDeclaration createDocumentTypeDeclaration()
public void startEntity(String name) throws SAXException
startEntity
in interface LexicalHandler
SAXException
public void endEntity(String name) throws SAXException
endEntity
in interface LexicalHandler
SAXException
public void startCDATA() throws SAXException
startCDATA
in interface LexicalHandler
SAXException
public void endCDATA() throws SAXException
endCDATA
in interface LexicalHandler
SAXException
public void comment(char[] ch, int start, int length) throws SAXException
comment
in interface LexicalHandler
SAXException
protected void checkChars(DocumentLoader.StackItem top)
protected void checkEntityRef(DocumentLoader.StackItem top, Node node)
public void elementDecl(String name, String model) throws SAXException
elementDecl
in interface DeclHandler
SAXException
public void attributeDecl(String eName, String aName, String type, String mode, String value) throws SAXException
attributeDecl
in interface DeclHandler
SAXException
public void internalEntityDecl(String name, String value) throws SAXException
internalEntityDecl
in interface DeclHandler
SAXException
protected String entityOrigin()
public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException
externalEntityDecl
in interface DeclHandler
SAXException
public void notationDecl(String name, String publicId, String systemId) throws SAXException
notationDecl
in interface DTDHandler
SAXException
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException
unparsedEntityDecl
in interface DTDHandler
SAXException
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
public void startDocument() throws SAXException
startDocument
in interface ContentHandler
SAXException
public void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping
in interface ContentHandler
SAXException
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
startElement
in interface ContentHandler
SAXException
protected void rootElement(Element element)
public void characters(char[] ch, int start, int length) throws SAXException
characters
in interface ContentHandler
SAXException
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
ignorableWhitespace
in interface ContentHandler
SAXException
public void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
SAXException
public void skippedEntity(String name) throws SAXException
skippedEntity
in interface ContentHandler
SAXException
public void endElement(String uri, String localName, String qName) throws SAXException
endElement
in interface ContentHandler
SAXException
public void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
SAXException
public void endDocument() throws SAXException
endDocument
in interface ContentHandler
SAXException
public InputSource getExternalSubset(String name, String baseURI) throws SAXException, IOException
getExternalSubset
in interface EntityResolver2
SAXException
IOException
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException
resolveEntity
in interface EntityResolver2
SAXException
IOException
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
resolveEntity
in interface EntityResolver
SAXException
IOException
public void warning(SAXParseException e) throws SAXException
warning
in interface ErrorHandler
SAXException
public void error(SAXParseException e) throws SAXException
error
in interface ErrorHandler
SAXException
public void fatalError(SAXParseException e) throws SAXException
fatalError
in interface ErrorHandler
SAXException