Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
acdf61e1
Commit
acdf61e1
authored
Mar 24, 2005
by
Tom Tromey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverted erroneous commit
From-SVN: r96966
parent
5fb0e509
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1468 additions
and
1776 deletions
+1468
-1776
libjava/gnu/xml/aelfred2/JAXPFactory.java
+119
-154
libjava/gnu/xml/aelfred2/SAXDriver.java
+1121
-1335
libjava/gnu/xml/aelfred2/XmlParser.java
+0
-0
libjava/gnu/xml/aelfred2/XmlReader.java
+228
-287
No files found.
libjava/gnu/xml/aelfred2/JAXPFactory.java
View file @
acdf61e1
...
@@ -60,172 +60,137 @@ import javax.xml.parsers.SAXParserFactory;
...
@@ -60,172 +60,137 @@ import javax.xml.parsers.SAXParserFactory;
*
*
* @author David Brownell
* @author David Brownell
*/
*/
public
final
class
JAXPFactory
public
final
class
JAXPFactory
extends
SAXParserFactory
extends
SAXParserFactory
{
{
private
Hashtable
flags
=
new
Hashtable
();
private
Hashtable
flags
=
new
Hashtable
();
/**
* Constructs a factory which normally returns a non-validating
* parser.
*/
public
JAXPFactory
()
{
}
public
SAXParser
newSAXParser
()
throws
ParserConfigurationException
,
SAXException
{
JaxpParser
jaxp
=
new
JaxpParser
();
Enumeration
e
=
flags
.
keys
();
XMLReader
parser
=
jaxp
.
getXMLReader
();
parser
.
setFeature
(
SAXDriver
.
FEATURE
+
"namespaces"
,
isNamespaceAware
());
parser
.
setFeature
(
SAXDriver
.
FEATURE
+
"validation"
,
isValidating
());
// that makes SAX2 feature flags trump JAXP
while
(
e
.
hasMoreElements
())
{
String
uri
=
(
String
)
e
.
nextElement
();
Boolean
value
=
(
Boolean
)
flags
.
get
(
uri
);
parser
.
setFeature
(
uri
,
value
.
booleanValue
());
}
return
jaxp
;
}
// yes, this "feature transfer" mechanism doesn't play well
public
void
setFeature
(
String
name
,
boolean
value
)
throws
ParserConfigurationException
,
SAXNotRecognizedException
,
SAXNotSupportedException
{
try
{
// force "early" detection of errors where possible
// (flags can't necessarily be set before parsing)
new
JaxpParser
().
getXMLReader
().
setFeature
(
name
,
value
);
flags
.
put
(
name
,
new
Boolean
(
value
));
}
catch
(
SAXNotRecognizedException
e
)
{
throw
new
SAXNotRecognizedException
(
name
);
}
catch
(
SAXNotSupportedException
e
)
{
throw
new
SAXNotSupportedException
(
name
);
}
catch
(
Exception
e
)
{
throw
new
ParserConfigurationException
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
public
boolean
getFeature
(
String
name
)
throws
ParserConfigurationException
,
SAXNotRecognizedException
,
SAXNotSupportedException
{
Boolean
value
=
(
Boolean
)
flags
.
get
(
name
);
if
(
value
!=
null
)
{
return
value
.
booleanValue
();
}
else
{
try
{
return
new
JaxpParser
().
getXMLReader
().
getFeature
(
name
);
}
catch
(
SAXNotRecognizedException
e
)
{
throw
new
SAXNotRecognizedException
(
name
);
}
catch
(
SAXNotSupportedException
e
)
{
throw
new
SAXNotSupportedException
(
name
);
}
catch
(
SAXException
e
)
{
throw
new
ParserConfigurationException
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
}
private
static
class
JaxpParser
extends
SAXParser
{
private
XmlReader
ae2
=
new
XmlReader
();
private
XMLReaderAdapter
parser
=
null
;
JaxpParser
()
{
}
public
void
setProperty
(
String
id
,
Object
value
)
/**
throws
SAXNotRecognizedException
,
SAXNotSupportedException
* Constructs a factory which normally returns a non-validating
{
* parser.
ae2
.
setProperty
(
id
,
value
);
*/
}
public
JAXPFactory
()
{
}
public
Object
getProperty
(
String
id
)
public
SAXParser
newSAXParser
()
throws
SAXNotRecognizedException
,
SAXNotSupported
Exception
throws
ParserConfigurationException
,
SAX
Exception
{
{
return
ae2
.
getProperty
(
id
);
JaxpParser
jaxp
=
new
JaxpParser
();
Enumeration
e
=
flags
.
keys
();
XMLReader
parser
=
jaxp
.
getXMLReader
();
parser
.
setFeature
(
SAXDriver
.
FEATURE
+
"namespaces"
,
isNamespaceAware
());
parser
.
setFeature
(
SAXDriver
.
FEATURE
+
"validation"
,
isValidating
());
// that makes SAX2 feature flags trump JAXP
while
(
e
.
hasMoreElements
())
{
String
uri
=
(
String
)
e
.
nextElement
();
Boolean
value
=
(
Boolean
)
flags
.
get
(
uri
);
parser
.
setFeature
(
uri
,
value
.
booleanValue
());
}
return
jaxp
;
}
}
public
Parser
getParser
()
// yes, this "feature transfer" mechanism doesn't play well
throws
SAXException
{
if
(
parser
==
null
)
{
parser
=
new
XMLReaderAdapter
(
ae2
);
}
return
parser
;
}
public
XMLReader
getXMLReader
()
public
void
setFeature
(
String
name
,
boolean
value
)
throws
SAXException
throws
ParserConfigurationException
,
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
return
ae2
;
try
{
// force "early" detection of errors where possible
// (flags can't necessarily be set before parsing)
new
JaxpParser
().
getXMLReader
().
setFeature
(
name
,
value
);
flags
.
put
(
name
,
new
Boolean
(
value
));
}
catch
(
SAXNotRecognizedException
e
)
{
throw
new
SAXNotRecognizedException
(
name
);
}
catch
(
SAXNotSupportedException
e
)
{
throw
new
SAXNotSupportedException
(
name
);
}
catch
(
Exception
e
)
{
throw
new
ParserConfigurationException
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
}
public
boolean
isNamespaceAware
()
public
boolean
getFeature
(
String
name
)
throws
ParserConfigurationException
,
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
try
Boolean
value
=
(
Boolean
)
flags
.
get
(
name
);
{
return
ae2
.
getFeature
(
SAXDriver
.
FEATURE
+
"namespaces"
);
if
(
value
!=
null
)
}
return
value
.
booleanValue
();
catch
(
Exception
e
)
else
{
try
{
throw
new
Error
();
return
new
JaxpParser
().
getXMLReader
().
getFeature
(
name
);
}
}
catch
(
SAXNotRecognizedException
e
)
{
throw
new
SAXNotRecognizedException
(
name
);
}
catch
(
SAXNotSupportedException
e
)
{
throw
new
SAXNotSupportedException
(
name
);
}
catch
(
SAXException
e
)
{
throw
new
ParserConfigurationException
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
}
p
ublic
boolean
isValidating
()
p
rivate
static
class
JaxpParser
extends
SAXParser
{
{
try
private
XmlReader
ae2
=
new
XmlReader
();
{
private
XMLReaderAdapter
parser
=
null
;
return
ae2
.
getFeature
(
SAXDriver
.
FEATURE
+
"validation"
);
}
JaxpParser
()
{
}
catch
(
Exception
e
)
{
public
void
setProperty
(
String
id
,
Object
value
)
throw
new
Error
();
throws
SAXNotRecognizedException
,
SAXNotSupportedException
}
{
ae2
.
setProperty
(
id
,
value
);
}
public
Object
getProperty
(
String
id
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
return
ae2
.
getProperty
(
id
);
}
public
Parser
getParser
()
throws
SAXException
{
if
(
parser
==
null
)
parser
=
new
XMLReaderAdapter
(
ae2
);
return
parser
;
}
public
XMLReader
getXMLReader
()
throws
SAXException
{
return
ae2
;
}
public
boolean
isNamespaceAware
()
{
try
{
return
ae2
.
getFeature
(
SAXDriver
.
FEATURE
+
"namespaces"
);
}
catch
(
Exception
e
)
{
throw
new
Error
();
}
}
public
boolean
isValidating
()
{
try
{
return
ae2
.
getFeature
(
SAXDriver
.
FEATURE
+
"validation"
);
}
catch
(
Exception
e
)
{
throw
new
Error
();
}
}
// TODO isXIncludeAware()
}
}
// TODO isXIncludeAware()
}
}
}
libjava/gnu/xml/aelfred2/SAXDriver.java
View file @
acdf61e1
...
@@ -60,11 +60,15 @@ import java.net.URL;
...
@@ -60,11 +60,15 @@ import java.net.URL;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Stack
;
import
java.util.Stack
;
// maintaining 1.1 compatibility for now ... more portable, PJava, etc
// Iterator, Hashmap and ArrayList ought to be faster
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.Hashtable
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Vector
;
import
org.xml.sax.*
;
import
org.xml.sax.*
;
import
org.xml.sax.ext.*
;
import
org.xml.sax.ext.*
;
...
@@ -129,1494 +133,1276 @@ import org.xml.sax.helpers.NamespaceSupport;
...
@@ -129,1494 +133,1276 @@ import org.xml.sax.helpers.NamespaceSupport;
* @see org.xml.sax.Parser
* @see org.xml.sax.Parser
*/
*/
final
public
class
SAXDriver
final
public
class
SAXDriver
implements
Locator
,
Attributes2
,
XMLReader
,
Parser
,
AttributeList
implements
Locator
,
Attributes2
,
XMLReader
,
Parser
,
AttributeList
{
{
private
final
DefaultHandler2
base
=
new
DefaultHandler2
();
private
final
DefaultHandler2
base
=
new
DefaultHandler2
();
private
XmlParser
parser
;
private
XmlParser
parser
;
private
EntityResolver
entityResolver
=
base
;
private
EntityResolver
entityResolver
=
base
;
private
EntityResolver2
resolver2
=
null
;
private
EntityResolver2
resolver2
=
null
;
private
ContentHandler
contentHandler
=
base
;
private
ContentHandler
contentHandler
=
base
;
private
DTDHandler
dtdHandler
=
base
;
private
DTDHandler
dtdHandler
=
base
;
private
ErrorHandler
errorHandler
=
base
;
private
ErrorHandler
errorHandler
=
base
;
private
DeclHandler
declHandler
=
base
;
private
DeclHandler
declHandler
=
base
;
private
LexicalHandler
lexicalHandler
=
base
;
private
LexicalHandler
lexicalHandler
=
base
;
private
String
elementName
;
private
String
elementName
;
private
Stack
entityStack
;
private
Stack
entityStack
;
// one vector (of object/struct): faster, smaller
// one vector (of object/struct): faster, smaller
private
List
attributesList
;
private
List
attributesList
;
private
boolean
namespaces
=
true
;
private
boolean
namespaces
=
true
;
private
boolean
xmlNames
=
false
;
private
boolean
xmlNames
=
false
;
private
boolean
extGE
=
true
;
private
boolean
extGE
=
true
;
private
boolean
extPE
=
true
;
private
boolean
extPE
=
true
;
private
boolean
resolveAll
=
true
;
private
boolean
resolveAll
=
true
;
private
boolean
useResolver2
=
true
;
private
boolean
useResolver2
=
true
;
private
boolean
stringInterning
=
true
;
// package private to allow (read-only) access in XmlParser
private
int
attributeCount
;
boolean
stringInterning
=
true
;
private
boolean
attributes
;
private
String
nsTemp
[];
private
int
attributeCount
;
private
NamespaceSupport
prefixStack
;
private
boolean
attributes
;
private
String
[]
nsTemp
;
private
NamespaceSupport
prefixStack
;
//
// Constructor.
//
/**
* Constructs a SAX Parser.
*/
public
SAXDriver
()
{
reset
();
}
private
void
reset
()
//
{
// Constructor.
elementName
=
null
;
//
entityStack
=
new
Stack
();
attributesList
=
Collections
.
synchronizedList
(
new
ArrayList
());
attributeCount
=
0
;
attributes
=
false
;
nsTemp
=
new
String
[
3
];
prefixStack
=
null
;
}
/** Constructs a SAX Parser. */
public
SAXDriver
()
{
reset
();
}
//
private
void
reset
()
// Implementation of org.xml.sax.Parser.
{
//
elementName
=
null
;
entityStack
=
new
Stack
();
attributesList
=
Collections
.
synchronizedList
(
new
ArrayList
());
attributeCount
=
0
;
attributes
=
false
;
nsTemp
=
new
String
[
3
];
prefixStack
=
null
;
}
/**
* <b>SAX1</b>: Sets the locale used for diagnostics; currently,
* only locales using the English language are supported.
* @param locale The locale for which diagnostics will be generated
*/
public
void
setLocale
(
Locale
locale
)
throws
SAXException
{
if
(
"en"
.
equals
(
locale
.
getLanguage
()))
{
return
;
}
throw
new
SAXException
(
"AElfred2 only supports English locales."
);
}
/**
//
* <b>SAX2</b>: Returns the object used when resolving external
// Implementation of org.xml.sax.Parser.
* entities during parsing (both general and parameter entities).
//
*/
public
EntityResolver
getEntityResolver
()
{
return
(
entityResolver
==
base
)
?
null
:
entityResolver
;
}
/**
/**
* <b>SAX1, SAX2</b>: Set the entity resolver for this parser.
* <b>SAX1</b>: Sets the locale used for diagnostics; currently,
* @param handler The object to receive entity events.
* only locales using the English language are supported.
*/
* @param locale The locale for which diagnostics will be generated
public
void
setEntityResolver
(
EntityResolver
resolver
)
*/
{
public
void
setLocale
(
Locale
locale
)
if
(
resolver
instanceof
EntityResolver2
)
throws
SAXException
{
{
resolver2
=
(
EntityResolver2
)
resolver
;
if
(
"en"
.
equals
(
locale
.
getLanguage
()))
}
return
;
else
{
resolver2
=
null
;
}
if
(
resolver
==
null
)
{
resolver
=
base
;
}
entityResolver
=
resolver
;
}
/**
throw
new
SAXException
(
"AElfred2 only supports English locales."
);
* <b>SAX2</b>: Returns the object used to process declarations related
}
* to notations and unparsed entities.
*/
public
DTDHandler
getDTDHandler
()
{
return
(
dtdHandler
==
base
)
?
null
:
dtdHandler
;
}
/**
* <b>SAX1, SAX2</b>: Set the DTD handler for this parser.
* @param handler The object to receive DTD events.
*/
public
void
setDTDHandler
(
DTDHandler
handler
)
{
if
(
handler
==
null
)
{
handler
=
base
;
}
this
.
dtdHandler
=
handler
;
}
/**
* <b>SAX2</b>: Returns the object used when resolving external
* entities during parsing (both general and parameter entities).
*/
public
EntityResolver
getEntityResolver
()
{
return
(
entityResolver
==
base
)
?
null
:
entityResolver
;
}
/**
/**
* <b>SAX1</b>: Set the document handler for this parser. If a
* <b>SAX1, SAX2</b>: Set the entity resolver for this parser.
* content handler was set, this document handler will supplant it.
* @param handler The object to receive entity events.
* The parser is set to report all XML 1.0 names rather than to
*/
* filter out "xmlns" attributes (the "namespace-prefixes" feature
public
void
setEntityResolver
(
EntityResolver
resolver
)
* is set to true).
{
*
if
(
resolver
instanceof
EntityResolver2
)
* @deprecated SAX2 programs should use the XMLReader interface
resolver2
=
(
EntityResolver2
)
resolver
;
* and a ContentHandler.
else
*
resolver2
=
null
;
* @param handler The object to receive document events.
if
(
resolver
==
null
)
*/
resolver
=
base
;
public
void
setDocumentHandler
(
DocumentHandler
handler
)
entityResolver
=
resolver
;
{
}
contentHandler
=
new
Adapter
(
handler
);
xmlNames
=
true
;
}
/**
* <b>SAX2</b>: Returns the object used to report the logical
* content of an XML document.
*/
public
ContentHandler
getContentHandler
()
{
return
(
contentHandler
==
base
)
?
null
:
contentHandler
;
}
/**
/**
* <b>SAX2</b>: Assigns the object used to report the logical
* <b>SAX2</b>: Returns the object used to process declarations related
* content of an XML document. If a document handler was set,
* to notations and unparsed entities.
* this content handler will supplant it (but XML 1.0 style name
*/
* reporting may remain enabled).
public
DTDHandler
getDTDHandler
()
*/
{
public
void
setContentHandler
(
ContentHandler
handler
)
return
(
dtdHandler
==
base
)
?
null
:
dtdHandler
;
{
}
if
(
handler
==
null
)
{
handler
=
base
;
}
contentHandler
=
handler
;
}
/**
/**
* <b>SAX1, SAX2</b>: Set the error handler for this parser.
* <b>SAX1, SAX2</b>: Set the DTD handler for this parser.
* @param handler The object to receive error events.
* @param handler The object to receive DTD events.
*/
*/
public
void
setErrorHandler
(
ErrorHandler
handler
)
public
void
setDTDHandler
(
DTDHandler
handler
)
{
{
if
(
handler
==
null
)
if
(
handler
==
null
)
{
handler
=
base
;
handler
=
base
;
this
.
dtdHandler
=
handler
;
}
}
this
.
errorHandler
=
handler
;
}
/**
* <b>SAX2</b>: Returns the object used to receive callbacks for XML
* errors of all levels (fatal, nonfatal, warning); this is never null;
*/
public
ErrorHandler
getErrorHandler
()
{
return
(
errorHandler
==
base
)
?
null
:
errorHandler
;
}
/**
/**
* <b>SAX1, SAX2</b>: Auxiliary API to parse an XML document, used mostly
* <b>SAX1</b>: Set the document handler for this parser. If a
* when no URI is available.
* content handler was set, this document handler will supplant it.
* If you want anything useful to happen, you should set
* The parser is set to report all XML 1.0 names rather than to
* at least one type of handler.
* filter out "xmlns" attributes (the "namespace-prefixes" feature
* @param source The XML input source. Don't set 'encoding' unless
* is set to true).
* you know for a fact that it's correct.
*
* @see #setEntityResolver
* @deprecated SAX2 programs should use the XMLReader interface
* @see #setDTDHandler
* and a ContentHandler.
* @see #setContentHandler
*
* @see #setErrorHandler
* @param handler The object to receive document events.
* @exception SAXException The handlers may throw any SAXException,
*/
* and the parser normally throws SAXParseException objects.
public
void
setDocumentHandler
(
DocumentHandler
handler
)
* @exception IOException IOExceptions are normally through through
{
* the parser if there are problems reading the source document.
contentHandler
=
new
Adapter
(
handler
);
*/
xmlNames
=
true
;
public
void
parse
(
InputSource
source
)
}
throws
SAXException
,
IOException
{
synchronized
(
base
)
{
parser
=
new
XmlParser
();
if
(
namespaces
)
{
prefixStack
=
new
NamespaceSupport
();
}
else
if
(!
xmlNames
)
{
throw
new
IllegalStateException
();
}
parser
.
setHandler
(
this
);
try
{
Reader
r
=
source
.
getCharacterStream
();
InputStream
in
=
source
.
getByteStream
();
parser
.
doParse
(
source
.
getSystemId
(),
source
.
getPublicId
(),
r
,
in
,
source
.
getEncoding
());
}
catch
(
SAXException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
e
;
}
catch
(
RuntimeException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
throw
new
SAXParseException
(
e
.
getMessage
(),
this
,
e
);
}
finally
{
contentHandler
.
endDocument
();
reset
();
}
}
}
/**
* <b>SAX1, SAX2</b>: Preferred API to parse an XML document, using a
* system identifier (URI).
*/
public
void
parse
(
String
systemId
)
throws
SAXException
,
IOException
{
parse
(
new
InputSource
(
systemId
));
}
//
/**
// Implementation of SAX2 "XMLReader" interface
* <b>SAX2</b>: Returns the object used to report the logical
//
* content of an XML document.
static
final
String
FEATURE
=
"http://xml.org/sax/features/"
;
*/
static
final
String
PROPERTY
=
"http://xml.org/sax/properties/"
;
public
ContentHandler
getContentHandler
()
{
/**
return
contentHandler
==
base
?
null
:
contentHandler
;
* <b>SAX2</b>: Tells the value of the specified feature flag.
}
*
* @exception SAXNotRecognizedException thrown if the feature flag
* is neither built in, nor yet assigned.
*/
public
boolean
getFeature
(
String
featureId
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
((
FEATURE
+
"validation"
).
equals
(
featureId
))
{
return
false
;
}
// external entities (both types) are optionally included
/**
if
((
FEATURE
+
"external-general-entities"
).
equals
(
featureId
))
* <b>SAX2</b>: Assigns the object used to report the logical
{
* content of an XML document. If a document handler was set,
return
extGE
;
* this content handler will supplant it (but XML 1.0 style name
}
* reporting may remain enabled).
if
((
FEATURE
+
"external-parameter-entities"
).
equals
(
featureId
))
*/
{
public
void
setContentHandler
(
ContentHandler
handler
)
return
extPE
;
{
}
if
(
handler
==
null
)
handler
=
base
;
// element/attribute names are as written in document; no mangling
contentHandler
=
handler
;
if
((
FEATURE
+
"namespace-prefixes"
).
equals
(
featureId
))
}
{
return
xmlNames
;
}
// report element/attribute namespaces?
/**
if
((
FEATURE
+
"namespaces"
).
equals
(
featureId
))
* <b>SAX1, SAX2</b>: Set the error handler for this parser.
{
* @param handler The object to receive error events.
return
namespaces
;
*/
}
public
void
setErrorHandler
(
ErrorHandler
handler
)
{
if
(
handler
==
null
)
handler
=
base
;
this
.
errorHandler
=
handler
;
}
// all PEs and GEs are reported
/**
if
((
FEATURE
+
"lexical-handler/parameter-entities"
).
equals
(
featureId
))
* <b>SAX2</b>: Returns the object used to receive callbacks for XML
{
* errors of all levels (fatal, nonfatal, warning); this is never null;
return
true
;
*/
}
public
ErrorHandler
getErrorHandler
()
{
return
errorHandler
==
base
?
null
:
errorHandler
;
}
/**
* <b>SAX1, SAX2</b>: Auxiliary API to parse an XML document, used mostly
* when no URI is available.
* If you want anything useful to happen, you should set
* at least one type of handler.
* @param source The XML input source. Don't set 'encoding' unless
* you know for a fact that it's correct.
* @see #setEntityResolver
* @see #setDTDHandler
* @see #setContentHandler
* @see #setErrorHandler
* @exception SAXException The handlers may throw any SAXException,
* and the parser normally throws SAXParseException objects.
* @exception IOException IOExceptions are normally through through
* the parser if there are problems reading the source document.
*/
public
void
parse
(
InputSource
source
)
throws
SAXException
,
IOException
{
synchronized
(
base
)
{
parser
=
new
XmlParser
();
if
(
namespaces
)
prefixStack
=
new
NamespaceSupport
();
else
if
(!
xmlNames
)
throw
new
IllegalStateException
();
parser
.
setHandler
(
this
);
try
{
Reader
r
=
source
.
getCharacterStream
();
InputStream
in
=
source
.
getByteStream
();
parser
.
doParse
(
source
.
getSystemId
(),
source
.
getPublicId
(),
r
,
in
,
source
.
getEncoding
());
}
catch
(
SAXException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
e
;
}
catch
(
RuntimeException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
throw
new
SAXParseException
(
e
.
getMessage
(),
this
,
e
);
}
finally
{
contentHandler
.
endDocument
();
reset
();
}
}
}
// default is true
if
((
FEATURE
+
"string-interning"
).
equals
(
featureId
))
{
return
stringInterning
;
}
// EXTENSIONS 1.1
// always returns isSpecified info
if
((
FEATURE
+
"use-attributes2"
).
equals
(
featureId
))
{
return
true
;
}
// meaningful between startDocument/endDocument
if
((
FEATURE
+
"is-standalone"
).
equals
(
featureId
))
{
if
(
parser
==
null
)
{
throw
new
SAXNotSupportedException
(
featureId
);
}
return
parser
.
isStandalone
();
}
// optionally don't absolutize URIs in declarations
/**
if
((
FEATURE
+
"resolve-dtd-uris"
).
equals
(
featureId
))
* <b>SAX1, SAX2</b>: Preferred API to parse an XML document, using a
{
* system identifier (URI).
return
resolveAll
;
*/
}
public
void
parse
(
String
systemId
)
throws
SAXException
,
IOException
{
parse
(
new
InputSource
(
systemId
));
}
// optionally use resolver2 interface methods, if possible
//
if
((
FEATURE
+
"use-entity-resolver2"
).
equals
(
featureId
))
// Implementation of SAX2 "XMLReader" interface
{
//
return
useResolver2
;
static
final
String
FEATURE
=
"http://xml.org/sax/features/"
;
}
static
final
String
PROPERTY
=
"http://xml.org/sax/properties/"
;
throw
new
SAXNotRecognizedException
(
featureId
);
/**
}
* <b>SAX2</b>: Tells the value of the specified feature flag.
*
* @exception SAXNotRecognizedException thrown if the feature flag
* is neither built in, nor yet assigned.
*/
public
boolean
getFeature
(
String
featureId
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
((
FEATURE
+
"validation"
).
equals
(
featureId
))
return
false
;
// external entities (both types) are optionally included
if
((
FEATURE
+
"external-general-entities"
).
equals
(
featureId
))
return
extGE
;
if
((
FEATURE
+
"external-parameter-entities"
)
.
equals
(
featureId
))
return
extPE
;
// element/attribute names are as written in document; no mangling
if
((
FEATURE
+
"namespace-prefixes"
).
equals
(
featureId
))
return
xmlNames
;
// report element/attribute namespaces?
if
((
FEATURE
+
"namespaces"
).
equals
(
featureId
))
return
namespaces
;
// all PEs and GEs are reported
if
((
FEATURE
+
"lexical-handler/parameter-entities"
).
equals
(
featureId
))
return
true
;
// default is true
if
((
FEATURE
+
"string-interning"
).
equals
(
featureId
))
return
stringInterning
;
// EXTENSIONS 1.1
// always returns isSpecified info
if
((
FEATURE
+
"use-attributes2"
).
equals
(
featureId
))
return
true
;
// meaningful between startDocument/endDocument
if
((
FEATURE
+
"is-standalone"
).
equals
(
featureId
))
{
if
(
parser
==
null
)
throw
new
SAXNotSupportedException
(
featureId
);
return
parser
.
isStandalone
();
}
// optionally don't absolutize URIs in declarations
if
((
FEATURE
+
"resolve-dtd-uris"
).
equals
(
featureId
))
return
resolveAll
;
// optionally use resolver2 interface methods, if possible
if
((
FEATURE
+
"use-entity-resolver2"
).
equals
(
featureId
))
return
useResolver2
;
throw
new
SAXNotRecognizedException
(
featureId
);
}
// package private
// package private
DeclHandler
getDeclHandler
()
DeclHandler
getDeclHandler
()
{
return
declHandler
;
}
{
return
declHandler
;
}
// package private
// package private
boolean
resolveURIs
()
boolean
resolveURIs
()
{
return
resolveAll
;
}
{
return
resolveAll
;
}
/**
/**
* <b>SAX2</b>: Returns the specified property.
* <b>SAX2</b>: Returns the specified property.
*
*
* @exception SAXNotRecognizedException thrown if the property value
* @exception SAXNotRecognizedException thrown if the property value
*
is neither built in, nor yet stored.
*
is neither built in, nor yet stored.
*/
*/
public
Object
getProperty
(
String
propertyId
)
public
Object
getProperty
(
String
propertyId
)
throws
SAXNotRecognizedException
throws
SAXNotRecognizedException
{
{
if
((
PROPERTY
+
"declaration-handler"
).
equals
(
propertyId
))
if
((
PROPERTY
+
"declaration-handler"
).
equals
(
propertyId
))
{
return
declHandler
==
base
?
null
:
declHandler
;
return
(
declHandler
==
base
)
?
null
:
declHandler
;
}
if
((
PROPERTY
+
"lexical-handler"
).
equals
(
propertyId
))
return
lexicalHandler
==
base
?
null
:
lexicalHandler
;
if
((
PROPERTY
+
"lexical-handler"
).
equals
(
propertyId
))
{
// unknown properties
return
(
lexicalHandler
==
base
)
?
null
:
lexicalHandler
;
throw
new
SAXNotRecognizedException
(
propertyId
);
}
}
// unknown properties
throw
new
SAXNotRecognizedException
(
propertyId
);
}
/**
/**
* <b>SAX2</b>: Sets the state of feature flags in this parser. Some
* <b>SAX2</b>: Sets the state of feature flags in this parser. Some
* built-in feature flags are mutable.
* built-in feature flags are mutable.
*/
*/
public
void
setFeature
(
String
featureId
,
boolean
value
)
public
void
setFeature
(
String
featureId
,
boolean
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
boolean
state
;
boolean
state
;
// Features with a defined value, we just change it if we can.
// Features with a defined value, we just change it if we can.
state
=
getFeature
(
featureId
);
state
=
getFeature
(
featureId
);
if
(
state
==
value
)
if
(
state
==
value
)
{
return
;
return
;
if
(
parser
!=
null
)
}
throw
new
SAXNotSupportedException
(
"not while parsing"
);
if
(
parser
!=
null
)
{
if
((
FEATURE
+
"namespace-prefixes"
).
equals
(
featureId
))
{
throw
new
SAXNotSupportedException
(
"not while parsing"
);
// in this implementation, this only affects xmlns reporting
}
xmlNames
=
value
;
// forcibly prevent illegal parser state
if
((
FEATURE
+
"namespace-prefixes"
).
equals
(
featureId
))
if
(!
xmlNames
)
{
namespaces
=
true
;
// in this implementation, this only affects xmlns reporting
return
;
xmlNames
=
value
;
}
// forcibly prevent illegal parser state
if
(!
xmlNames
)
if
((
FEATURE
+
"namespaces"
).
equals
(
featureId
))
{
{
namespaces
=
value
;
namespaces
=
true
;
// forcibly prevent illegal parser state
}
if
(!
namespaces
)
return
;
xmlNames
=
true
;
}
return
;
}
if
((
FEATURE
+
"namespaces"
).
equals
(
featureId
))
{
if
((
FEATURE
+
"external-general-entities"
).
equals
(
featureId
))
{
namespaces
=
value
;
extGE
=
value
;
// forcibly prevent illegal parser state
return
;
if
(!
namespaces
)
}
{
if
((
FEATURE
+
"external-parameter-entities"
)
.
equals
(
featureId
))
{
xmlNames
=
true
;
extPE
=
value
;
}
return
;
return
;
}
}
if
((
FEATURE
+
"resolve-dtd-uris"
).
equals
(
featureId
))
{
resolveAll
=
value
;
if
((
FEATURE
+
"external-general-entities"
).
equals
(
featureId
))
return
;
{
}
extGE
=
value
;
return
;
if
((
FEATURE
+
"use-entity-resolver2"
).
equals
(
featureId
))
{
}
useResolver2
=
value
;
if
((
FEATURE
+
"external-parameter-entities"
).
equals
(
featureId
))
return
;
{
}
extPE
=
value
;
return
;
throw
new
SAXNotRecognizedException
(
featureId
);
}
}
if
((
FEATURE
+
"resolve-dtd-uris"
).
equals
(
featureId
))
{
resolveAll
=
value
;
return
;
}
if
((
FEATURE
+
"use-entity-resolver2"
).
equals
(
featureId
))
{
useResolver2
=
value
;
return
;
}
throw
new
SAXNotRecognizedException
(
featureId
);
}
/**
/**
* <b>SAX2</b>: Assigns the specified property. Like SAX1 handlers,
* <b>SAX2</b>: Assigns the specified property. Like SAX1 handlers,
* these may be changed at any time.
* these may be changed at any time.
*/
*/
public
void
setProperty
(
String
propertyId
,
Object
value
)
public
void
setProperty
(
String
propertyId
,
Object
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
// see if the property is recognized
// see if the property is recognized
getProperty
(
propertyId
);
getProperty
(
propertyId
);
// Properties with a defined value, we just change it if we can.
// Properties with a defined value, we just change it if we can.
if
((
PROPERTY
+
"declaration-handler"
).
equals
(
propertyId
))
if
((
PROPERTY
+
"declaration-handler"
).
equals
(
propertyId
))
{
{
if
(
value
==
null
)
if
(
value
==
null
)
declHandler
=
base
;
{
else
if
(!
(
value
instanceof
DeclHandler
))
declHandler
=
base
;
throw
new
SAXNotSupportedException
(
propertyId
);
}
else
else
if
(!(
value
instanceof
DeclHandler
))
declHandler
=
(
DeclHandler
)
value
;
{
return
;
throw
new
SAXNotSupportedException
(
propertyId
);
}
}
else
if
((
PROPERTY
+
"lexical-handler"
).
equals
(
propertyId
))
{
{
if
(
value
==
null
)
declHandler
=
(
DeclHandler
)
value
;
lexicalHandler
=
base
;
}
else
if
(!
(
value
instanceof
LexicalHandler
))
return
;
throw
new
SAXNotSupportedException
(
propertyId
);
}
else
lexicalHandler
=
(
LexicalHandler
)
value
;
if
((
PROPERTY
+
"lexical-handler"
).
equals
(
propertyId
))
return
;
{
}
if
(
value
==
null
)
{
throw
new
SAXNotSupportedException
(
propertyId
);
lexicalHandler
=
base
;
}
}
else
if
(!(
value
instanceof
LexicalHandler
))
{
throw
new
SAXNotSupportedException
(
propertyId
);
}
else
{
lexicalHandler
=
(
LexicalHandler
)
value
;
}
return
;
}
throw
new
SAXNotSupportedException
(
propertyId
);
}
//
// This is where the driver receives XmlParser callbacks and translates
// them into SAX callbacks. Some more callbacks have been added for
// SAX2 support.
//
void
startDocument
()
//
throws
SAXException
// This is where the driver receives XmlParser callbacks and translates
{
// them into SAX callbacks. Some more callbacks have been added for
contentHandler
.
setDocumentLocator
(
this
);
// SAX2 support.
contentHandler
.
startDocument
();
//
attributesList
.
clear
();
}
void
xmlDecl
(
String
version
,
void
startDocument
()
String
encoding
,
boolean
standalone
,
String
inputEncoding
)
throws
SAXException
throws
SAXException
{
{
if
(
contentHandler
instanceof
ContentHandler2
)
contentHandler
.
setDocumentLocator
(
this
);
{
contentHandler
.
startDocument
();
((
ContentHandler2
)
contentHandler
).
xmlDecl
(
version
,
attributesList
.
clear
();
encoding
,
}
standalone
,
inputEncoding
);
void
xmlDecl
(
String
version
,
}
String
encoding
,
}
boolean
standalone
,
String
inputEncoding
)
throws
SAXException
{
if
(
contentHandler
instanceof
ContentHandler2
)
{
((
ContentHandler2
)
contentHandler
).
xmlDecl
(
version
,
encoding
,
standalone
,
inputEncoding
);
}
}
void
skippedEntity
(
String
name
)
void
skippedEntity
(
String
name
)
throws
SAXException
throws
SAXException
{
{
contentHandler
.
skippedEntity
(
name
);
}
contentHandler
.
skippedEntity
(
name
);
}
InputSource
getExternalSubset
(
String
name
,
String
baseURI
)
InputSource
getExternalSubset
(
String
name
,
String
baseURI
)
throws
SAXException
,
IOException
throws
SAXException
,
IOException
{
{
if
(
resolver2
==
null
||
!
useResolver2
||
!
extPE
)
if
(
resolver2
==
null
||
!
useResolver2
||
!
extPE
)
{
return
null
;
return
null
;
return
resolver2
.
getExternalSubset
(
name
,
baseURI
);
}
}
return
resolver2
.
getExternalSubset
(
name
,
baseURI
);
}
InputSource
resolveEntity
(
boolean
isPE
,
String
name
,
InputSource
resolveEntity
(
boolean
isPE
,
String
name
,
InputSource
in
,
String
baseURI
)
InputSource
in
,
String
baseURI
)
throws
SAXException
,
IOException
throws
SAXException
,
IOException
{
{
InputSource
source
;
InputSource
source
;
// external entities might be skipped
// external entities might be skipped
if
(
isPE
&&
!
extPE
)
if
(
isPE
&&
!
extPE
)
{
return
null
;
return
null
;
if
(!
isPE
&&
!
extGE
)
}
return
null
;
if
(!
isPE
&&
!
extGE
)
{
// ... or not
return
null
;
lexicalHandler
.
startEntity
(
name
);
}
if
(
resolver2
!=
null
&&
useResolver2
)
{
source
=
resolver2
.
resolveEntity
(
name
,
in
.
getPublicId
(),
// ... or not
baseURI
,
in
.
getSystemId
());
lexicalHandler
.
startEntity
(
name
);
if
(
source
==
null
)
{
if
(
resolver2
!=
null
&&
useResolver2
)
in
.
setSystemId
(
absolutize
(
baseURI
,
{
in
.
getSystemId
(),
false
));
source
=
resolver2
.
resolveEntity
(
name
,
in
.
getPublicId
(),
source
=
in
;
baseURI
,
in
.
getSystemId
());
}
if
(
source
==
null
)
}
else
{
{
in
.
setSystemId
(
absolutize
(
baseURI
,
in
.
getSystemId
(),
false
));
in
.
setSystemId
(
absolutize
(
baseURI
,
source
=
entityResolver
.
resolveEntity
(
in
.
getPublicId
(),
in
.
getSystemId
(),
false
));
in
.
getSystemId
());
source
=
in
;
if
(
source
==
null
)
}
source
=
in
;
}
}
else
startExternalEntity
(
name
,
source
.
getSystemId
(),
true
);
{
return
source
;
in
.
setSystemId
(
absolutize
(
baseURI
,
in
.
getSystemId
(),
false
));
}
source
=
entityResolver
.
resolveEntity
(
in
.
getPublicId
(),
in
.
getSystemId
());
if
(
source
==
null
)
{
source
=
in
;
}
}
startExternalEntity
(
name
,
source
.
getSystemId
(),
true
);
return
source
;
}
// absolutize a system ID relative to the specified base URI
// absolutize a system ID relative to the specified base URI
// (temporarily) package-visible for external entity decls
// (temporarily) package-visible for external entity decls
String
absolutize
(
String
baseURI
,
String
systemId
,
boolean
nice
)
String
absolutize
(
String
baseURI
,
String
systemId
,
boolean
nice
)
throws
MalformedURLException
,
SAXException
throws
MalformedURLException
,
SAXException
{
{
// FIXME normalize system IDs -- when?
// FIXME normalize system IDs -- when?
// - Convert to UTF-8
// - Convert to UTF-8
// - Map reserved and non-ASCII characters to %HH
// - Map reserved and non-ASCII characters to %HH
try
try
{
{
if
(
baseURI
==
null
)
{
if
(
baseURI
==
null
)
warn
(
"No base URI; hope this SYSTEM id is absolute: "
{
+
systemId
);
if
(
XmlParser
.
uriWarnings
)
return
new
URL
(
systemId
).
toString
();
{
}
else
warn
(
"No base URI; hope this SYSTEM id is absolute: "
return
new
URL
(
new
URL
(
baseURI
),
systemId
).
toString
();
+
systemId
);
}
}
catch
(
MalformedURLException
e
)
{
return
new
URL
(
systemId
).
toString
();
}
// Let unknown URI schemes pass through unless we need
else
// the JVM to map them to i/o streams for us...
{
if
(!
nice
)
return
new
URL
(
new
URL
(
baseURI
),
systemId
).
toString
();
throw
e
;
}
}
// sometimes sysids for notations or unparsed entities
catch
(
MalformedURLException
e
)
// aren't really URIs...
{
warn
(
"Can't absolutize SYSTEM id: "
+
e
.
getMessage
());
// Let unknown URI schemes pass through unless we need
return
systemId
;
// the JVM to map them to i/o streams for us...
}
if
(!
nice
)
}
{
throw
e
;
}
// sometimes sysids for notations or unparsed entities
// aren't really URIs...
warn
(
"Can't absolutize SYSTEM id: "
+
e
.
getMessage
());
return
systemId
;
}
}
void
startExternalEntity
(
String
name
,
String
systemId
,
boolean
stackOnly
)
void
startExternalEntity
(
String
name
,
String
systemId
,
boolean
stackOnly
)
throws
SAXException
throws
SAXException
{
{
// The following warning was deleted because the application has the
// The following warning was deleted because the application has the
// option of not setting systemId. Sun's JAXP or Xerces seems to
// option of not setting systemId. Sun's JAXP or Xerces seems to
// ignore this case.
// ignore this case.
/*
/*
if (systemId == null)
if (systemId == null)
warn ("URI was not reported to parser for entity " + name);
warn ("URI was not reported to parser for entity " + name);
*/
*/
if
(!
stackOnly
)
// spliced [dtd] needs startEntity
if
(!
stackOnly
)
// spliced [dtd] needs startEntity
{
lexicalHandler
.
startEntity
(
name
);
lexicalHandler
.
startEntity
(
name
);
entityStack
.
push
(
systemId
);
}
}
entityStack
.
push
(
systemId
);
}
void
endExternalEntity
(
String
name
)
void
endExternalEntity
(
String
name
)
throws
SAXException
throws
SAXException
{
{
if
(!
"[document]"
.
equals
(
name
))
if
(!
"[document]"
.
equals
(
name
))
{
lexicalHandler
.
endEntity
(
name
);
lexicalHandler
.
endEntity
(
name
);
entityStack
.
pop
();
}
}
entityStack
.
pop
();
}
void
startInternalEntity
(
String
name
)
void
startInternalEntity
(
String
name
)
throws
SAXException
throws
SAXException
{
{
lexicalHandler
.
startEntity
(
name
);
lexicalHandler
.
startEntity
(
name
);
}
}
void
endInternalEntity
(
String
name
)
void
endInternalEntity
(
String
name
)
throws
SAXException
throws
SAXException
{
{
lexicalHandler
.
endEntity
(
name
);
lexicalHandler
.
endEntity
(
name
);
}
}
void
doctypeDecl
(
String
name
,
String
publicId
,
String
systemId
)
void
doctypeDecl
(
String
name
,
String
publicId
,
String
systemId
)
throws
SAXException
{
lexicalHandler
.
startDTD
(
name
,
publicId
,
systemId
);
// ... the "name" is a declaration and should be given
// to the DeclHandler (but sax2 doesn't).
// the IDs for the external subset are lexical details,
// as are the contents of the internal subset; but sax2
// doesn't provide the internal subset "pre-parse"
}
void
notationDecl
(
String
name
,
String
publicId
,
String
systemId
,
String
baseUri
)
throws
SAXException
throws
SAXException
{
{
try
lexicalHandler
.
startDTD
(
name
,
publicId
,
systemId
);
{
dtdHandler
.
notationDecl
(
name
,
publicId
,
// ... the "name" is a declaration and should be given
(
resolveAll
&&
systemId
!=
null
)
// to the DeclHandler (but sax2 doesn't).
?
absolutize
(
baseUri
,
systemId
,
true
)
:
systemId
);
// the IDs for the external subset are lexical details,
}
// as are the contents of the internal subset; but sax2
catch
(
IOException
e
)
// doesn't provide the internal subset "pre-parse"
{
}
// "can't happen"
throw
new
SAXParseException
(
e
.
getMessage
(),
this
,
e
);
}
}
void
unparsedEntityDecl
(
String
name
,
String
publicId
,
String
systemId
,
void
notationDecl
(
String
name
,
String
ids
[])
String
baseUri
,
String
notation
)
throws
SAXException
throws
SAXException
{
{
try
try
{
{
dtdHandler
.
notationDecl
(
name
,
ids
[
0
],
dtdHandler
.
unparsedEntityDecl
(
name
,
publicId
,
(
resolveAll
&&
ids
[
1
]
!=
null
)
resolveAll
?
absolutize
(
ids
[
2
],
ids
[
1
],
true
)
?
absolutize
(
baseUri
,
systemId
,
true
)
:
ids
[
1
]);
:
systemId
,
}
catch
(
IOException
e
)
{
notation
);
// "can't happen"
}
throw
new
SAXParseException
(
e
.
getMessage
(),
this
,
e
);
catch
(
IOException
e
)
}
{
}
// "can't happen"
throw
new
SAXParseException
(
e
.
getMessage
(),
this
,
e
);
}
}
void
endDoctype
(
)
void
unparsedEntityDecl
(
String
name
,
String
ids
[],
String
notation
)
throws
SAXException
throws
SAXException
{
{
lexicalHandler
.
endDTD
();
try
{
}
dtdHandler
.
unparsedEntityDecl
(
name
,
ids
[
0
],
resolveAll
?
absolutize
(
ids
[
2
],
ids
[
1
],
true
)
:
ids
[
1
],
notation
);
}
catch
(
IOException
e
)
{
// "can't happen"
throw
new
SAXParseException
(
e
.
getMessage
(),
this
,
e
);
}
}
private
void
declarePrefix
(
String
prefix
,
String
uri
)
void
endDoctype
(
)
throws
SAXException
throws
SAXException
{
{
int
index
=
uri
.
indexOf
(
':'
);
lexicalHandler
.
endDTD
();
}
// many versions of nwalsh docbook stylesheets
// have bogus URLs; so this can't be an error...
if
(
index
<
1
&&
uri
.
length
()
!=
0
)
{
warn
(
"relative URI for namespace: "
+
uri
);
}
// FIXME: char [0] must be ascii alpha; chars [1..index]
private
void
declarePrefix
(
String
prefix
,
String
uri
)
// must be ascii alphanumeric or in "+-." [RFC 2396]
throws
SAXException
{
//Namespace Constraints
int
index
=
uri
.
indexOf
(
':'
);
//name for xml prefix must be http://www.w3.org/XML/1998/namespace
boolean
prefixEquality
=
prefix
.
equals
(
"xml"
);
// many versions of nwalsh docbook stylesheets
boolean
uriEquality
=
uri
.
equals
(
"http://www.w3.org/XML/1998/namespace"
);
// have bogus URLs; so this can't be an error...
if
((
prefixEquality
||
uriEquality
)
&&
!(
prefixEquality
&&
uriEquality
))
if
(
index
<
1
&&
uri
.
length
()
!=
0
)
{
warn
(
"relative URI for namespace: "
+
uri
);
fatal
(
"xml is by definition bound to the namespace name "
+
"http://www.w3.org/XML/1998/namespace"
);
// FIXME: char [0] must be ascii alpha; chars [1..index]
}
// must be ascii alphanumeric or in "+-." [RFC 2396]
//xmlns prefix declaration is illegal but xml prefix declaration is llegal...
//Namespace Constraints
if
(
prefixEquality
&&
uriEquality
)
//name for xml prefix must be http://www.w3.org/XML/1998/namespace
{
boolean
prefixEquality
=
prefix
.
equals
(
"xml"
);
return
;
boolean
uriEquality
=
uri
.
equals
(
"http://www.w3.org/XML/1998/namespace"
);
}
if
((
prefixEquality
||
uriEquality
)
&&
!(
prefixEquality
&&
uriEquality
))
fatal
(
"xml is by definition bound to the namespace name "
+
//name for xmlns prefix must be http://www.w3.org/2000/xmlns/
"http://www.w3.org/XML/1998/namespace"
);
prefixEquality
=
prefix
.
equals
(
"xmlns"
);
uriEquality
=
uri
.
equals
(
"http://www.w3.org/2000/xmlns/"
);
//xmlns prefix declaration is illegal but xml prefix declaration is llegal...
if
((
prefixEquality
||
uriEquality
)
&&
!(
prefixEquality
&&
uriEquality
))
if
(
prefixEquality
&&
uriEquality
)
{
return
;
fatal
(
"http://www.w3.org/2000/xmlns/ is by definition bound"
+
" to prefix xmlns"
);
//name for xmlns prefix must be http://www.w3.org/2000/xmlns/
}
prefixEquality
=
prefix
.
equals
(
"xmlns"
);
uriEquality
=
uri
.
equals
(
"http://www.w3.org/2000/xmlns/"
);
//even if the uri is http://www.w3.org/2000/xmlns/
if
((
prefixEquality
||
uriEquality
)
&&
!(
prefixEquality
&&
uriEquality
))
// it is illegal to declare it
fatal
(
"http://www.w3.org/2000/xmlns/ is by definition bound"
+
if
(
prefixEquality
&&
uriEquality
)
" to prefix xmlns"
);
{
fatal
(
"declaring the xmlns prefix is illegal"
);
//even if the uri is http://www.w3.org/2000/xmlns/ it is illegal to declare it
}
if
(
prefixEquality
&&
uriEquality
)
fatal
(
"declaring the xmlns prefix is illegal"
);
uri
=
uri
.
intern
();
prefixStack
.
declarePrefix
(
prefix
,
uri
);
uri
=
uri
.
intern
();
contentHandler
.
startPrefixMapping
(
prefix
,
uri
);
prefixStack
.
declarePrefix
(
prefix
,
uri
);
}
contentHandler
.
startPrefixMapping
(
prefix
,
uri
);
}
void
attribute
(
String
qname
,
String
value
,
boolean
isSpecified
)
void
attribute
(
String
qname
,
String
value
,
boolean
isSpecified
)
throws
SAXException
throws
SAXException
{
{
if
(!
attributes
)
if
(!
attributes
)
{
{
attributes
=
true
;
attributes
=
true
;
if
(
namespaces
)
if
(
namespaces
)
prefixStack
.
pushContext
();
{
}
prefixStack
.
pushContext
();
}
// process namespace decls immediately;
}
// then maybe forget this as an attribute
if
(
namespaces
)
{
// process namespace decls immediately;
int
index
;
// then maybe forget this as an attribute
if
(
namespaces
)
// default NS declaration?
{
if
(
getFeature
(
FEATURE
+
"string-interning"
))
{
int
index
;
if
(
"xmlns"
==
qname
)
{
declarePrefix
(
""
,
value
);
// default NS declaration?
if
(!
xmlNames
)
if
(
stringInterning
)
return
;
{
}
if
(
"xmlns"
==
qname
)
// NS prefix declaration?
{
else
if
((
index
=
qname
.
indexOf
(
':'
))
==
5
declarePrefix
(
""
,
value
);
&&
qname
.
startsWith
(
"xmlns"
))
{
if
(!
xmlNames
)
String
prefix
=
qname
.
substring
(
6
);
{
return
;
if
(
prefix
.
equals
(
""
))
}
fatal
(
"missing prefix in namespace declaration attribute"
);
}
if
(
value
.
length
()
==
0
)
{
// NS prefix declaration?
verror
(
"missing URI in namespace declaration attribute: "
else
if
((
index
=
qname
.
indexOf
(
':'
))
==
5
+
qname
);
&&
qname
.
startsWith
(
"xmlns"
))
}
else
{
declarePrefix
(
prefix
,
value
);
String
prefix
=
qname
.
substring
(
6
);
if
(!
xmlNames
)
return
;
if
(
prefix
.
equals
(
""
))
}
{
}
else
{
fatal
(
"missing prefix "
+
if
(
"xmlns"
.
equals
(
qname
))
{
"in namespace declaration attribute"
);
declarePrefix
(
""
,
value
);
}
if
(!
xmlNames
)
if
(
value
.
length
()
==
0
)
return
;
{
}
verror
(
"missing URI in namespace declaration attribute: "
// NS prefix declaration?
+
qname
);
else
if
((
index
=
qname
.
indexOf
(
':'
))
==
5
}
&&
qname
.
startsWith
(
"xmlns"
))
{
else
String
prefix
=
qname
.
substring
(
6
);
{
declarePrefix
(
prefix
,
value
);
if
(
value
.
length
()
==
0
)
{
}
verror
(
"missing URI in namespace decl attribute: "
if
(!
xmlNames
)
+
qname
);
{
}
else
return
;
declarePrefix
(
prefix
,
value
);
}
if
(!
xmlNames
)
}
return
;
}
}
else
{
if
(
"xmlns"
.
equals
(
qname
))
{
declarePrefix
(
""
,
value
);
if
(!
xmlNames
)
{
return
;
}
}
// NS prefix declaration?
else
if
((
index
=
qname
.
indexOf
(
':'
))
==
5
&&
qname
.
startsWith
(
"xmlns"
))
{
String
prefix
=
qname
.
substring
(
6
);
if
(
value
.
length
()
==
0
)
{
verror
(
"missing URI in namespace decl attribute: "
+
qname
);
}
else
{
declarePrefix
(
prefix
,
value
);
}
if
(!
xmlNames
)
{
return
;
}
}
}
}
}
// remember this attribute ...
attributeCount
++;
// attribute type comes from querying parser's DTD records
attributesList
.
add
(
new
Attribute
(
qname
,
value
,
isSpecified
));
}
}
// remember this attribute ...
void
startElement
(
String
elname
)
attributeCount
++;
// attribute type comes from querying parser's DTD records
attributesList
.
add
(
new
Attribute
(
qname
,
value
,
isSpecified
));
}
void
startElement
(
String
elname
)
throws
SAXException
throws
SAXException
{
{
ContentHandler
handler
=
contentHandler
;
ContentHandler
handler
=
contentHandler
;
//
// NOTE: this implementation of namespace support adds something
// like six percent to parsing CPU time, in a large (~50 MB)
// document that doesn't use namespaces at all. (Measured by PC
// sampling, with a bug where endElement processing was omitted.)
// [Measurement referred to older implementation, older JVM ...]
//
// It ought to become notably faster in such cases. Most
// costs are the prefix stack calling Hashtable.get() (2%),
// String.hashCode() (1.5%) and about 1.3% each for pushing
// the context, and two chunks of name processing.
//
if
(!
attributes
)
{
if
(
namespaces
)
prefixStack
.
pushContext
();
}
else
if
(
namespaces
)
{
// now we can patch up namespace refs; we saw all the
// declarations, so now we'll do the Right Thing
Iterator
itt
=
attributesList
.
iterator
();
while
(
itt
.
hasNext
())
{
Attribute
attribute
=
(
Attribute
)
itt
.
next
();
String
qname
=
attribute
.
name
;
int
index
;
// default NS declaration?
if
(
getFeature
(
FEATURE
+
"string-interning"
))
{
if
(
"xmlns"
==
qname
)
continue
;
}
else
{
if
(
"xmlns"
.
equals
(
qname
))
continue
;
}
//Illegal in the new Namespaces Draft
//should it be only in 1.1 docs??
if
(
qname
.
equals
(
":"
))
fatal
(
"namespace names consisting of a single colon "
+
"character are invalid"
);
index
=
qname
.
indexOf
(
':'
);
// NS prefix declaration?
if
(
index
==
5
&&
qname
.
startsWith
(
"xmlns"
))
continue
;
// it's not a NS decl; patch namespace info items
if
(
prefixStack
.
processName
(
qname
,
nsTemp
,
true
)
==
null
)
fatal
(
"undeclared attribute prefix in: "
+
qname
);
else
{
attribute
.
nameSpace
=
nsTemp
[
0
];
attribute
.
localName
=
nsTemp
[
1
];
}
}
}
// save element name so attribute callbacks work
elementName
=
elname
;
if
(
namespaces
)
{
if
(
prefixStack
.
processName
(
elname
,
nsTemp
,
false
)
==
null
)
{
fatal
(
"undeclared element prefix in: "
+
elname
);
nsTemp
[
0
]
=
nsTemp
[
1
]
=
""
;
}
handler
.
startElement
(
nsTemp
[
0
],
nsTemp
[
1
],
elname
,
this
);
}
else
handler
.
startElement
(
""
,
""
,
elname
,
this
);
// elementName = null;
// elements with no attributes are pretty common!
if
(
attributes
)
{
attributesList
.
clear
();
attributeCount
=
0
;
attributes
=
false
;
}
}
//
void
endElement
(
String
elname
)
// NOTE: this implementation of namespace support adds something
// like six percent to parsing CPU time, in a large (~50 MB)
// document that doesn't use namespaces at all. (Measured by PC
// sampling, with a bug where endElement processing was omitted.)
// [Measurement referred to older implementation, older JVM ...]
//
// It ought to become notably faster in such cases. Most
// costs are the prefix stack calling Hashtable.get() (2%),
// String.hashCode() (1.5%) and about 1.3% each for pushing
// the context, and two chunks of name processing.
//
if
(!
attributes
)
{
if
(
namespaces
)
{
prefixStack
.
pushContext
();
}
}
else
if
(
namespaces
)
{
// now we can patch up namespace refs; we saw all the
// declarations, so now we'll do the Right Thing
Iterator
itt
=
attributesList
.
iterator
();
while
(
itt
.
hasNext
())
{
Attribute
attribute
=
(
Attribute
)
itt
.
next
();
String
qname
=
attribute
.
name
;
int
index
;
// default NS declaration?
if
(
stringInterning
)
{
if
(
"xmlns"
==
qname
)
{
continue
;
}
}
else
{
if
(
"xmlns"
.
equals
(
qname
))
{
continue
;
}
}
//Illegal in the new Namespaces Draft
//should it be only in 1.1 docs??
if
(
qname
.
equals
(
":"
))
{
fatal
(
"namespace names consisting of a single colon "
+
"character are invalid"
);
}
index
=
qname
.
indexOf
(
':'
);
// NS prefix declaration?
if
(
index
==
5
&&
qname
.
startsWith
(
"xmlns"
))
{
continue
;
}
// it's not a NS decl; patch namespace info items
if
(
prefixStack
.
processName
(
qname
,
nsTemp
,
true
)
==
null
)
{
fatal
(
"undeclared attribute prefix in: "
+
qname
);
}
else
{
attribute
.
nameSpace
=
nsTemp
[
0
];
attribute
.
localName
=
nsTemp
[
1
];
}
}
}
// save element name so attribute callbacks work
elementName
=
elname
;
if
(
namespaces
)
{
if
(
prefixStack
.
processName
(
elname
,
nsTemp
,
false
)
==
null
)
{
fatal
(
"undeclared element prefix in: "
+
elname
);
nsTemp
[
0
]
=
nsTemp
[
1
]
=
""
;
}
handler
.
startElement
(
nsTemp
[
0
],
nsTemp
[
1
],
elname
,
this
);
}
else
{
handler
.
startElement
(
""
,
""
,
elname
,
this
);
}
// elementName = null;
// elements with no attributes are pretty common!
if
(
attributes
)
{
attributesList
.
clear
();
attributeCount
=
0
;
attributes
=
false
;
}
}
void
endElement
(
String
elname
)
throws
SAXException
throws
SAXException
{
{
ContentHandler
handler
=
contentHandler
;
ContentHandler
handler
=
contentHandler
;
if
(!
namespaces
)
if
(!
namespaces
)
{
{
handler
.
endElement
(
""
,
""
,
elname
);
handler
.
endElement
(
""
,
""
,
elname
);
return
;
return
;
}
}
prefixStack
.
processName
(
elname
,
nsTemp
,
false
);
prefixStack
.
processName
(
elname
,
nsTemp
,
false
);
handler
.
endElement
(
nsTemp
[
0
],
nsTemp
[
1
],
elname
);
handler
.
endElement
(
nsTemp
[
0
],
nsTemp
[
1
],
elname
);
Enumeration
prefixes
=
prefixStack
.
getDeclaredPrefixes
();
Enumeration
prefixes
=
prefixStack
.
getDeclaredPrefixes
();
while
(
prefixes
.
hasMoreElements
())
{
handler
.
endPrefixMapping
((
String
)
prefixes
.
nextElement
());
}
prefixStack
.
popContext
();
}
void
startCDATA
()
while
(
prefixes
.
hasMoreElements
())
handler
.
endPrefixMapping
((
String
)
prefixes
.
nextElement
());
prefixStack
.
popContext
();
}
void
startCDATA
()
throws
SAXException
throws
SAXException
{
{
lexicalHandler
.
startCDATA
();
lexicalHandler
.
startCDATA
();
}
}
void
charData
(
char
[]
ch
,
int
start
,
int
length
)
void
charData
(
char
ch
[]
,
int
start
,
int
length
)
throws
SAXException
throws
SAXException
{
{
contentHandler
.
characters
(
ch
,
start
,
length
);
contentHandler
.
characters
(
ch
,
start
,
length
);
}
}
void
endCDATA
()
void
endCDATA
()
throws
SAXException
throws
SAXException
{
{
lexicalHandler
.
endCDATA
();
lexicalHandler
.
endCDATA
();
}
}
void
ignorableWhitespace
(
char
[]
ch
,
int
start
,
int
length
)
void
ignorableWhitespace
(
char
ch
[]
,
int
start
,
int
length
)
throws
SAXException
throws
SAXException
{
{
contentHandler
.
ignorableWhitespace
(
ch
,
start
,
length
);
contentHandler
.
ignorableWhitespace
(
ch
,
start
,
length
);
}
}
void
processingInstruction
(
String
target
,
String
data
)
void
processingInstruction
(
String
target
,
String
data
)
throws
SAXException
throws
SAXException
{
{
contentHandler
.
processingInstruction
(
target
,
data
);
contentHandler
.
processingInstruction
(
target
,
data
);
}
}
void
comment
(
char
[]
ch
,
int
start
,
int
length
)
void
comment
(
char
ch
[]
,
int
start
,
int
length
)
throws
SAXException
throws
SAXException
{
{
if
(
lexicalHandler
!=
base
)
if
(
lexicalHandler
!=
base
)
{
lexicalHandler
.
comment
(
ch
,
start
,
length
);
lexicalHandler
.
comment
(
ch
,
start
,
length
);
}
}
}
void
fatal
(
String
message
)
void
fatal
(
String
message
)
throws
SAXException
throws
SAXException
{
{
SAXParseException
fatal
;
SAXParseException
fatal
;
fatal
=
new
SAXParseException
(
message
,
this
);
fatal
=
new
SAXParseException
(
message
,
this
);
errorHandler
.
fatalError
(
fatal
);
errorHandler
.
fatalError
(
fatal
);
// Even if the application can continue ... we can't!
// Even if the application can continue ... we can't!
throw
fatal
;
throw
fatal
;
}
}
// We can safely report a few validity errors that
// We can safely report a few validity errors that
// make layered SAX2 DTD validation more conformant
// make layered SAX2 DTD validation more conformant
void
verror
(
String
message
)
void
verror
(
String
message
)
throws
SAXException
throws
SAXException
{
{
SAXParseException
err
;
SAXParseException
err
;
err
=
new
SAXParseException
(
message
,
this
);
err
=
new
SAXParseException
(
message
,
this
);
errorHandler
.
error
(
err
);
errorHandler
.
error
(
err
);
}
}
void
warn
(
String
message
)
void
warn
(
String
message
)
throws
SAXException
throws
SAXException
{
{
SAXParseException
err
;
SAXParseException
err
;
err
=
new
SAXParseException
(
message
,
this
);
err
=
new
SAXParseException
(
message
,
this
);
errorHandler
.
warning
(
err
);
errorHandler
.
warning
(
err
);
}
}
//
// Implementation of org.xml.sax.Attributes.
//
/**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser);
*/
public
int
getLength
()
{
return
attributesList
.
size
();
}
/**
//
* <b>SAX2 Attributes</b> method (don't invoke on parser);
// Implementation of org.xml.sax.Attributes.
*/
//
public
String
getURI
(
int
index
)
{
if
(
index
<
0
||
index
>=
attributesList
.
size
())
{
return
null
;
}
return
((
Attribute
)
attributesList
.
get
(
index
)).
nameSpace
;
}
/**
/**
* <b>SAX2 Attributes</b> method (don't invoke on parser);
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
*/
* (don't invoke on parser);
public
String
getLocalName
(
int
index
)
*/
{
public
int
getLength
()
if
(
index
<
0
||
index
>=
attributesList
.
size
())
{
{
return
attributesList
.
size
();
return
null
;
}
}
Attribute
attr
=
(
Attribute
)
attributesList
.
get
(
index
);
// FIXME attr.localName is sometimes null, why?
if
(
namespaces
&&
attr
.
localName
==
null
)
{
// XXX fix this here for now
int
ci
=
attr
.
name
.
indexOf
(
':'
);
attr
.
localName
=
(
ci
==
-
1
)
?
attr
.
name
:
attr
.
name
.
substring
(
ci
+
1
);
}
return
(
attr
.
localName
==
null
)
?
""
:
attr
.
localName
;
}
/**
/**
* <b>SAX2 Attributes</b> method (don't invoke on parser);
* <b>SAX2 Attributes</b> method (don't invoke on parser);
*/
*/
public
String
getQName
(
int
index
)
public
String
getURI
(
int
index
)
{
{
if
(
index
<
0
||
index
>=
attributesList
.
size
())
if
(
index
<
0
||
index
>=
attributesList
.
size
())
{
{
return
null
;
return
null
;
}
}
Attribute
attr
=
(
Attribute
)
attributesList
.
get
(
index
);
return
((
Attribute
)
attributesList
.
get
(
index
)).
nameSpace
;
return
(
attr
.
name
==
null
)
?
""
:
attr
.
name
;
}
}
/**
/**
* <b>SAX1 AttributeList</b> method (don't invoke on parser);
* <b>SAX2 Attributes</b> method (don't invoke on parser);
*/
*/
public
String
getName
(
int
index
)
public
String
getLocalName
(
int
index
)
{
{
return
getQName
(
index
);
if
(
index
<
0
||
index
>=
attributesList
.
size
())
}
{
return
null
;
}
Attribute
attr
=
(
Attribute
)
attributesList
.
get
(
index
);
// FIXME attr.localName is sometimes null, why?
if
(
namespaces
&&
attr
.
localName
==
null
)
{
// XXX fix this here for now
int
ci
=
attr
.
name
.
indexOf
(
':'
);
attr
.
localName
=
(
ci
==
-
1
)
?
attr
.
name
:
attr
.
name
.
substring
(
ci
+
1
);
}
return
(
attr
.
localName
==
null
)
?
""
:
attr
.
localName
;
}
/**
/**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
* <b>SAX2 Attributes</b> method (don't invoke on parser);
* (don't invoke on parser);
*/
*/
public
String
getQName
(
int
index
)
public
String
getType
(
int
index
)
{
{
if
(
index
<
0
||
index
>=
attributesList
.
size
())
if
(
index
<
0
||
index
>=
attributesList
.
size
())
{
{
return
null
;
return
null
;
}
}
Attribute
attr
=
(
Attribute
)
attributesList
.
get
(
index
);
String
type
=
parser
.
getAttributeType
(
elementName
,
getQName
(
index
));
return
(
attr
.
name
==
null
)
?
""
:
attr
.
name
;
if
(
type
==
null
)
}
{
return
"CDATA"
;
}
// ... use DeclHandler.attributeDecl to see enumerations
if
(
type
==
"ENUMERATION"
)
{
return
"NMTOKEN"
;
}
return
type
;
}
/**
/**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
* <b>SAX1 AttributeList</b> method (don't invoke on parser);
* (don't invoke on parser);
*/
*/
public
String
getName
(
int
index
)
public
String
getValue
(
int
index
)
{
{
return
getQName
(
index
);
if
(
index
<
0
||
index
>=
attributesList
.
size
())
}
{
return
null
;
}
return
((
Attribute
)
attributesList
.
get
(
index
)).
value
;
}
/**
/**
* <b>SAX2 Attributes</b> method (don't invoke on parser);
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
*/
* (don't invoke on parser);
public
int
getIndex
(
String
uri
,
String
local
)
*/
public
String
getType
(
int
index
)
{
{
int
length
=
getLength
();
if
(
index
<
0
||
index
>=
attributesList
.
size
())
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
return
null
;
{
}
if
(!
getURI
(
i
).
equals
(
uri
))
String
type
=
parser
.
getAttributeType
(
elementName
,
getQName
(
index
));
{
if
(
type
==
null
)
continue
;
{
}
return
"CDATA"
;
if
(
getLocalName
(
i
).
equals
(
local
))
}
{
// ... use DeclHandler.attributeDecl to see enumerations
return
i
;
if
(
type
==
"ENUMERATION"
)
}
{
}
return
"NMTOKEN"
;
return
-
1
;
}
}
return
type
;
}
/**
/**
* <b>SAX2 Attributes</b> method (don't invoke on parser);
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
*/
* (don't invoke on parser);
public
int
getIndex
(
String
xmlName
)
*/
{
public
String
getValue
(
int
index
)
int
length
=
getLength
();
{
if
(
index
<
0
||
index
>=
attributesList
.
size
())
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
getQName
(
i
).
equals
(
xmlName
))
{
{
return
i
;
return
null
;
}
}
}
return
((
Attribute
)
attributesList
.
get
(
index
)).
value
;
return
-
1
;
}
}
/**
* <b>SAX2 Attributes</b> method (don't invoke on parser);
*/
public
String
getType
(
String
uri
,
String
local
)
{
int
index
=
getIndex
(
uri
,
local
);
if
(
index
<
0
)
{
return
null
;
}
return
getType
(
index
);
}
/**
/**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
* <b>SAX2 Attributes</b> method (don't invoke on parser);
* (don't invoke on parser);
*/
*/
public
int
getIndex
(
String
uri
,
String
local
)
public
String
getType
(
String
xmlName
)
{
{
int
length
=
getLength
();
int
index
=
getIndex
(
xmlName
);
if
(
index
<
0
)
{
return
null
;
}
return
getType
(
index
);
}
/**
for
(
int
i
=
0
;
i
<
length
;
i
++)
* <b>SAX Attributes</b> method (don't invoke on parser);
{
*/
if
(!
getURI
(
i
).
equals
(
uri
))
public
String
getValue
(
String
uri
,
String
local
)
{
{
continue
;
int
index
=
getIndex
(
uri
,
local
);
}
if
(
getLocalName
(
i
).
equals
(
local
))
if
(
index
<
0
)
{
{
return
i
;
return
null
;
}
}
}
return
getValue
(
index
)
;
return
-
1
;
}
}
/**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser);
*/
public
String
getValue
(
String
xmlName
)
{
int
index
=
getIndex
(
xmlName
);
if
(
index
<
0
)
{
return
null
;
}
return
getValue
(
index
);
}
//
/**
// Implementation of org.xml.sax.ext.Attributes2
* <b>SAX2 Attributes</b> method (don't invoke on parser);
//
*/
public
int
getIndex
(
String
xmlName
)
/** @return false unless the attribute was declared in the DTD.
{
* @throws java.lang.ArrayIndexOutOfBoundsException
int
length
=
getLength
();
* When the supplied index does not identify an attribute.
*/
public
boolean
isDeclared
(
int
index
)
{
if
(
index
<
0
||
index
>=
attributeCount
)
{
throw
new
ArrayIndexOutOfBoundsException
();
}
String
type
=
parser
.
getAttributeType
(
elementName
,
getQName
(
index
));
return
(
type
!=
null
);
}
/** @return false unless the attribute was declared in the DTD.
for
(
int
i
=
0
;
i
<
length
;
i
++)
* @throws java.lang.IllegalArgumentException
{
* When the supplied names do not identify an attribute.
if
(
getQName
(
i
).
equals
(
xmlName
))
*/
{
public
boolean
isDeclared
(
String
qName
)
return
i
;
{
}
int
index
=
getIndex
(
qName
);
}
if
(
index
<
0
)
return
-
1
;
{
}
throw
new
IllegalArgumentException
();
}
String
type
=
parser
.
getAttributeType
(
elementName
,
qName
);
return
(
type
!=
null
);
}
/** @return false unless the attribute was declared in the DTD.
* @throws java.lang.IllegalArgumentException
* When the supplied names do not identify an attribute.
*/
public
boolean
isDeclared
(
String
uri
,
String
localName
)
{
int
index
=
getIndex
(
uri
,
localName
);
return
isDeclared
(
index
);
}
/**
/**
* <b>SAX-ext Attributes2</b> method (don't invoke on parser);
* <b>SAX2 Attributes</b> method (don't invoke on parser);
*/
*/
public
boolean
isSpecified
(
int
index
)
public
String
getType
(
String
uri
,
String
local
)
{
{
return
((
Attribute
)
attributesList
.
get
(
index
)).
specified
;
int
index
=
getIndex
(
uri
,
local
);
}
/**
if
(
index
<
0
)
* <b>SAX-ext Attributes2</b> method (don't invoke on parser);
{
*/
return
null
;
public
boolean
isSpecified
(
String
uri
,
String
local
)
}
{
return
getType
(
index
);
int
index
=
getIndex
(
uri
,
local
);
}
return
isSpecified
(
index
);
}
/**
* <b>SAX-ext Attributes2</b> method (don't invoke on parser);
*/
public
boolean
isSpecified
(
String
xmlName
)
{
int
index
=
getIndex
(
xmlName
);
return
isSpecified
(
index
);
}
//
/**
// Implementation of org.xml.sax.Locator.
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
//
* (don't invoke on parser);
*/
public
String
getType
(
String
xmlName
)
{
int
index
=
getIndex
(
xmlName
);
/**
if
(
index
<
0
)
* <b>SAX Locator</b> method (don't invoke on parser);
{
*/
return
null
;
public
String
getPublicId
()
}
{
return
getType
(
index
);
return
null
;
// FIXME track public IDs too
}
}
/**
* <b>SAX Locator</b> method (don't invoke on parser);
*/
public
String
getSystemId
()
{
if
(
entityStack
.
empty
())
{
return
null
;
}
else
{
return
(
String
)
entityStack
.
peek
();
}
}
/**
/**
* <b>SAX Locator</b> method (don't invoke on parser);
* <b>SAX Attributes</b> method (don't invoke on parser);
*/
*/
public
int
getLineNumber
()
public
String
getValue
(
String
uri
,
String
local
)
{
{
return
parser
.
getLineNumber
();
int
index
=
getIndex
(
uri
,
local
);
}
/**
if
(
index
<
0
)
* <b>SAX Locator</b> method (don't invoke on parser);
{
*/
return
null
;
public
int
getColumnNumber
()
}
{
return
getValue
(
index
);
return
parser
.
getColumnNumber
();
}
}
// adapter between SAX2 content handler and SAX1 document handler callbacks
private
static
class
Adapter
implements
ContentHandler
{
private
DocumentHandler
docHandler
;
Adapter
(
DocumentHandler
dh
)
/**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser);
*/
public
String
getValue
(
String
xmlName
)
{
{
docHandler
=
dh
;
int
index
=
getIndex
(
xmlName
);
if
(
index
<
0
)
{
return
null
;
}
return
getValue
(
index
);
}
}
public
void
setDocumentLocator
(
Locator
l
)
//
// Implementation of org.xml.sax.ext.Attributes2
//
/** @return false unless the attribute was declared in the DTD.
* @throws java.lang.ArrayIndexOutOfBoundsException
* When the supplied index does not identify an attribute.
*/
public
boolean
isDeclared
(
int
index
)
{
{
docHandler
.
setDocumentLocator
(
l
);
if
(
index
<
0
||
index
>=
attributeCount
)
throw
new
ArrayIndexOutOfBoundsException
();
String
type
=
parser
.
getAttributeType
(
elementName
,
getQName
(
index
));
return
(
type
!=
null
);
}
}
public
void
startDocument
()
/** @return false unless the attribute was declared in the DTD.
throws
SAXException
* @throws java.lang.IllegalArgumentException
* When the supplied names do not identify an attribute.
*/
public
boolean
isDeclared
(
String
qName
)
{
{
docHandler
.
startDocument
();
int
index
=
getIndex
(
qName
);
if
(
index
<
0
)
throw
new
IllegalArgumentException
();
String
type
=
parser
.
getAttributeType
(
elementName
,
qName
);
return
(
type
!=
null
);
}
}
public
void
processingInstruction
(
String
target
,
String
data
)
/** @return false unless the attribute was declared in the DTD.
throws
SAXException
* @throws java.lang.IllegalArgumentException
* When the supplied names do not identify an attribute.
*/
public
boolean
isDeclared
(
String
uri
,
String
localName
)
{
{
docHandler
.
processingInstruction
(
target
,
data
);
int
index
=
getIndex
(
uri
,
localName
);
return
isDeclared
(
index
);
}
}
public
void
startPrefixMapping
(
String
prefix
,
String
uri
)
/**
* <b>SAX-ext Attributes2</b> method (don't invoke on parser);
*/
public
boolean
isSpecified
(
int
index
)
{
{
/* ignored */
return
((
Attribute
)
attributesList
.
get
(
index
)).
specified
;
}
}
public
void
startElement
(
String
namespace
,
/**
String
local
,
* <b>SAX-ext Attributes2</b> method (don't invoke on parser);
String
name
,
*/
Attributes
attrs
)
public
boolean
isSpecified
(
String
uri
,
String
local
)
throws
SAXException
{
{
docHandler
.
startElement
(
name
,
(
AttributeList
)
attrs
);
int
index
=
getIndex
(
uri
,
local
);
return
isSpecified
(
index
);
}
}
public
void
characters
(
char
[]
buf
,
int
offset
,
int
len
)
/**
throws
SAXException
* <b>SAX-ext Attributes2</b> method (don't invoke on parser);
*/
public
boolean
isSpecified
(
String
xmlName
)
{
{
docHandler
.
characters
(
buf
,
offset
,
len
);
int
index
=
getIndex
(
xmlName
);
return
isSpecified
(
index
);
}
}
public
void
ignorableWhitespace
(
char
[]
buf
,
int
offset
,
int
len
)
throws
SAXException
//
// Implementation of org.xml.sax.Locator.
//
/**
* <b>SAX Locator</b> method (don't invoke on parser);
*/
public
String
getPublicId
()
{
{
docHandler
.
ignorableWhitespace
(
buf
,
offset
,
len
);
return
null
;
// FIXME track public IDs too
}
}
public
void
skippedEntity
(
String
name
)
/**
* <b>SAX Locator</b> method (don't invoke on parser);
*/
public
String
getSystemId
()
{
{
/* ignored */
if
(
entityStack
.
empty
())
return
null
;
else
return
(
String
)
entityStack
.
peek
();
}
}
public
void
endElement
(
String
u
,
String
l
,
String
name
)
/**
throws
SAXException
* <b>SAX Locator</b> method (don't invoke on parser);
*/
public
int
getLineNumber
()
{
{
docHandler
.
endElement
(
name
);
return
parser
.
getLineNumber
(
);
}
}
public
void
endPrefixMapping
(
String
prefix
)
/**
* <b>SAX Locator</b> method (don't invoke on parser);
*/
public
int
getColumnNumber
()
{
{
/* ignored */
return
parser
.
getColumnNumber
();
}
}
public
void
endDocument
()
// adapter between SAX2 content handler and SAX1 document handler callbacks
throws
SAXException
private
static
class
Adapter
implements
ContentHandler
{
{
docHandler
.
endDocument
();
private
DocumentHandler
docHandler
;
Adapter
(
DocumentHandler
dh
)
{
docHandler
=
dh
;
}
public
void
setDocumentLocator
(
Locator
l
)
{
docHandler
.
setDocumentLocator
(
l
);
}
public
void
startDocument
()
throws
SAXException
{
docHandler
.
startDocument
();
}
public
void
processingInstruction
(
String
target
,
String
data
)
throws
SAXException
{
docHandler
.
processingInstruction
(
target
,
data
);
}
public
void
startPrefixMapping
(
String
prefix
,
String
uri
)
{
/* ignored */
}
public
void
startElement
(
String
namespace
,
String
local
,
String
name
,
Attributes
attrs
)
throws
SAXException
{
docHandler
.
startElement
(
name
,
(
AttributeList
)
attrs
);
}
public
void
characters
(
char
buf
[],
int
offset
,
int
len
)
throws
SAXException
{
docHandler
.
characters
(
buf
,
offset
,
len
);
}
public
void
ignorableWhitespace
(
char
buf
[],
int
offset
,
int
len
)
throws
SAXException
{
docHandler
.
ignorableWhitespace
(
buf
,
offset
,
len
);
}
public
void
skippedEntity
(
String
name
)
{
/* ignored */
}
public
void
endElement
(
String
u
,
String
l
,
String
name
)
throws
SAXException
{
docHandler
.
endElement
(
name
);
}
public
void
endPrefixMapping
(
String
prefix
)
{
/* ignored */
}
public
void
endDocument
()
throws
SAXException
{
docHandler
.
endDocument
();
}
}
}
}
}
class
Attribute
{
private
static
class
Attribute
{
String
name
;
String
name
;
String
value
;
String
value
;
String
nameSpace
;
String
nameSpace
;
String
localName
;
String
localName
;
boolean
specified
;
boolean
specified
;
Attribute
(
String
name
,
String
value
,
boolean
specified
)
Attribute
(
String
name
,
String
value
,
boolean
specified
)
{
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
value
=
value
;
this
.
value
=
value
;
this
.
nameSpace
=
""
;
this
.
nameSpace
=
""
;
this
.
specified
=
specified
;
this
.
specified
=
specified
;
}
}
}
}
}
libjava/gnu/xml/aelfred2/XmlParser.java
View file @
acdf61e1
This source diff could not be displayed because it is too large. You can
view the blob
instead.
libjava/gnu/xml/aelfred2/XmlReader.java
View file @
acdf61e1
...
@@ -70,305 +70,246 @@ import gnu.xml.pipeline.ValidationConsumer;
...
@@ -70,305 +70,246 @@ import gnu.xml.pipeline.ValidationConsumer;
*
*
* @author David Brownell
* @author David Brownell
*/
*/
public
final
class
XmlReader
public
final
class
XmlReader
implements
XMLReader
implements
XMLReader
{
{
private
SAXDriver
aelfred2
=
new
SAXDriver
();
private
EventFilter
filter
=
new
EventFilter
();
private
boolean
isValidating
;
private
boolean
active
;
static
class
FatalErrorHandler
extends
DefaultHandler2
/** Constructs a SAX Parser. */
{
public
XmlReader
()
{
}
public
void
error
(
SAXParseException
e
)
throws
SAXException
/**
* Constructs a SAX Parser, optionally treating validity errors
* as if they were fatal errors.
*/
public
XmlReader
(
boolean
invalidIsFatal
)
{
if
(
invalidIsFatal
)
setErrorHandler
(
new
DefaultHandler2
()
{
public
void
error
(
SAXParseException
e
)
throws
SAXException
{
throw
e
;
}
});
}
/**
* <b>SAX2</b>: Returns the object used to report the logical
* content of an XML document.
*/
public
ContentHandler
getContentHandler
()
{
return
filter
.
getContentHandler
();
}
/**
* <b>SAX2</b>: Assigns the object used to report the logical
* content of an XML document.
* @exception IllegalStateException if called mid-parse
*/
public
void
setContentHandler
(
ContentHandler
handler
)
{
{
throw
e
;
if
(
active
)
throw
new
IllegalStateException
(
"already parsing"
);
filter
.
setContentHandler
(
handler
);
}
}
}
/**
* <b>SAX2</b>: Returns the object used to process declarations related
private
SAXDriver
aelfred2
=
new
SAXDriver
();
* to notations and unparsed entities.
private
EventFilter
filter
=
new
EventFilter
();
*/
private
boolean
isValidating
;
public
DTDHandler
getDTDHandler
()
private
boolean
active
;
{
return
filter
.
getDTDHandler
();
}
/**
/**
* Constructs a SAX Parser.
* <b>SAX1</b> Assigns DTD handler
*/
* @exception IllegalStateException if called mid-parse
public
XmlReader
()
*/
{
public
void
setDTDHandler
(
DTDHandler
handler
)
}
{
if
(
active
)
/**
throw
new
IllegalStateException
(
"already parsing"
);
* Constructs a SAX Parser, optionally treating validity errors
filter
.
setDTDHandler
(
handler
);
* as if they were fatal errors.
}
*/
public
XmlReader
(
boolean
invalidIsFatal
)
/**
{
* <b>SAX2</b>: Returns the object used when resolving external
if
(
invalidIsFatal
)
* entities during parsing (both general and parameter entities).
{
*/
setErrorHandler
(
new
FatalErrorHandler
());
public
EntityResolver
getEntityResolver
()
}
{
return
aelfred2
.
getEntityResolver
();
}
}
/** <b>SAX1</b> Assigns parser's entity resolver */
/**
public
void
setEntityResolver
(
EntityResolver
handler
)
* <b>SAX2</b>: Returns the object used to report the logical
{
aelfred2
.
setEntityResolver
(
handler
);
}
* content of an XML document.
*/
/**
public
ContentHandler
getContentHandler
()
* <b>SAX2</b>: Returns the object used to receive callbacks for XML
{
* errors of all levels (fatal, nonfatal, warning); this is never null;
return
filter
.
getContentHandler
();
*/
}
public
ErrorHandler
getErrorHandler
()
{
return
aelfred2
.
getErrorHandler
();
}
/**
* <b>SAX2</b>: Assigns the object used to report the logical
/**
* content of an XML document.
* <b>SAX1</b> Assigns error handler
* @exception IllegalStateException if called mid-parse
* @exception IllegalStateException if called mid-parse
*/
*/
public
void
setContentHandler
(
ContentHandler
handler
)
public
void
setErrorHandler
(
ErrorHandler
handler
)
{
{
if
(
active
)
if
(
active
)
{
throw
new
IllegalStateException
(
"already parsing"
);
throw
new
IllegalStateException
(
"already parsing"
);
aelfred2
.
setErrorHandler
(
handler
);
}
}
filter
.
setContentHandler
(
handler
);
}
/**
* <b>SAX2</b>: Assigns the specified property.
/**
* @exception IllegalStateException if called mid-parse
* <b>SAX2</b>: Returns the object used to process declarations related
*/
* to notations and unparsed entities.
public
void
setProperty
(
String
propertyId
,
Object
value
)
*/
public
DTDHandler
getDTDHandler
()
{
return
filter
.
getDTDHandler
();
}
/**
* <b>SAX1</b> Assigns DTD handler
* @exception IllegalStateException if called mid-parse
*/
public
void
setDTDHandler
(
DTDHandler
handler
)
{
if
(
active
)
{
throw
new
IllegalStateException
(
"already parsing"
);
}
filter
.
setDTDHandler
(
handler
);
}
/**
* <b>SAX2</b>: Returns the object used when resolving external
* entities during parsing (both general and parameter entities).
*/
public
EntityResolver
getEntityResolver
()
{
return
aelfred2
.
getEntityResolver
();
}
/**
* <b>SAX1</b> Assigns parser's entity resolver
*/
public
void
setEntityResolver
(
EntityResolver
handler
)
{
aelfred2
.
setEntityResolver
(
handler
);
}
/**
* <b>SAX2</b>: Returns the object used to receive callbacks for XML
* errors of all levels (fatal, nonfatal, warning); this is never null;
*/
public
ErrorHandler
getErrorHandler
()
{
return
aelfred2
.
getErrorHandler
();
}
/**
* <b>SAX1</b> Assigns error handler
* @exception IllegalStateException if called mid-parse
*/
public
void
setErrorHandler
(
ErrorHandler
handler
)
{
if
(
active
)
{
throw
new
IllegalStateException
(
"already parsing"
);
}
aelfred2
.
setErrorHandler
(
handler
);
}
/**
* <b>SAX2</b>: Assigns the specified property.
* @exception IllegalStateException if called mid-parse
*/
public
void
setProperty
(
String
propertyId
,
Object
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
if
(
active
)
if
(
active
)
{
throw
new
IllegalStateException
(
"already parsing"
);
throw
new
IllegalStateException
(
"already parsing"
);
if
(
getProperty
(
propertyId
)
!=
value
)
}
filter
.
setProperty
(
propertyId
,
value
);
if
(
getProperty
(
propertyId
)
!=
value
)
}
{
filter
.
setProperty
(
propertyId
,
value
);
/**
}
* <b>SAX2</b>: Returns the specified property.
}
*/
public
Object
getProperty
(
String
propertyId
)
/**
* <b>SAX2</b>: Returns the specified property.
*/
public
Object
getProperty
(
String
propertyId
)
throws
SAXNotRecognizedException
throws
SAXNotRecognizedException
{
{
if
((
SAXDriver
.
PROPERTY
+
"declaration-handler"
).
equals
(
propertyId
)
if
((
SAXDriver
.
PROPERTY
+
"declaration-handler"
)
||
(
SAXDriver
.
PROPERTY
+
"lexical-handler"
).
equals
(
propertyId
)
)
.
equals
(
propertyId
)
{
||
(
SAXDriver
.
PROPERTY
+
"lexical-handler"
)
return
filter
.
getProperty
(
propertyId
);
.
equals
(
propertyId
))
}
return
filter
.
getProperty
(
propertyId
);
throw
new
SAXNotRecognizedException
(
propertyId
);
throw
new
SAXNotRecognizedException
(
propertyId
);
}
}
private
void
forceValidating
()
private
void
forceValidating
()
throws
SAXNotRecognizedException
,
SAXNotSupportedException
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
aelfred2
.
setFeature
(
SAXDriver
.
FEATURE
+
"namespace-prefixes"
,
aelfred2
.
setFeature
(
true
);
SAXDriver
.
FEATURE
+
"namespace-prefixes"
,
aelfred2
.
setFeature
(
SAXDriver
.
FEATURE
+
"external-general-entities"
,
true
);
true
);
aelfred2
.
setFeature
(
aelfred2
.
setFeature
(
SAXDriver
.
FEATURE
+
"external-parameter-entities"
,
SAXDriver
.
FEATURE
+
"external-general-entities"
,
true
);
true
);
}
aelfred2
.
setFeature
(
SAXDriver
.
FEATURE
+
"external-parameter-entities"
,
/**
true
);
* <b>SAX2</b>: Sets the state of features supported in this parser.
}
* Note that this parser requires reporting of namespace prefixes when
* validating.
/**
*/
* <b>SAX2</b>: Sets the state of features supported in this parser.
public
void
setFeature
(
String
featureId
,
boolean
state
)
* Note that this parser requires reporting of namespace prefixes when
* validating.
*/
public
void
setFeature
(
String
featureId
,
boolean
state
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
boolean
value
=
getFeature
(
featureId
);
boolean
value
=
getFeature
(
featureId
);
if
(
state
==
value
)
if
(
state
==
value
)
{
return
;
return
;
}
if
((
SAXDriver
.
FEATURE
+
"validation"
).
equals
(
featureId
))
{
if
(
active
)
if
((
SAXDriver
.
FEATURE
+
"validation"
).
equals
(
featureId
))
throw
new
SAXNotSupportedException
(
"already parsing"
);
{
if
(
state
)
if
(
active
)
forceValidating
();
{
isValidating
=
state
;
throw
new
SAXNotSupportedException
(
"already parsing"
);
}
else
}
aelfred2
.
setFeature
(
featureId
,
state
);
if
(
state
)
}
{
forceValidating
();
/**
}
* <b>SAX2</b>: Tells whether this parser supports the specified feature.
isValidating
=
state
;
* At this time, this directly parallels the underlying SAXDriver,
}
* except that validation is optionally supported.
else
*
{
* @see SAXDriver
aelfred2
.
setFeature
(
featureId
,
state
);
*/
}
public
boolean
getFeature
(
String
featureId
)
}
/**
* <b>SAX2</b>: Tells whether this parser supports the specified feature.
* At this time, this directly parallels the underlying SAXDriver,
* except that validation is optionally supported.
*
* @see SAXDriver
*/
public
boolean
getFeature
(
String
featureId
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
{
if
((
SAXDriver
.
FEATURE
+
"validation"
).
equals
(
featureId
))
if
((
SAXDriver
.
FEATURE
+
"validation"
).
equals
(
featureId
))
{
return
isValidating
;
return
isValidating
;
}
return
aelfred2
.
getFeature
(
featureId
);
}
return
aelfred2
.
getFeature
(
featureId
);
}
/**
* <b>SAX1</b>: Sets the locale used for diagnostics; currently,
/**
* only locales using the English language are supported.
* <b>SAX1</b>: Sets the locale used for diagnostics; currently,
* @param locale The locale for which diagnostics will be generated
* only locales using the English language are supported.
*/
* @param locale The locale for which diagnostics will be generated
public
void
setLocale
(
Locale
locale
)
*/
public
void
setLocale
(
Locale
locale
)
throws
SAXException
throws
SAXException
{
{
aelfred2
.
setLocale
(
locale
);
}
aelfred2
.
setLocale
(
locale
);
}
/**
/**
* <b>SAX1</b>: Preferred API to parse an XML document, using a
* <b>SAX1</b>: Preferred API to parse an XML document, using a
* system identifier (URI).
* system identifier (URI).
*/
*/
public
void
parse
(
String
systemId
)
public
void
parse
(
String
systemId
)
throws
SAXException
,
IOException
{
parse
(
new
InputSource
(
systemId
));
}
/**
* <b>SAX1</b>: Underlying API to parse an XML document, used
* directly when no URI is available. When this is invoked,
* and the parser is set to validate, some features will be
* automatically reset to appropriate values: for reporting
* namespace prefixes, and incorporating external entities.
*
* @param source The XML input source.
*
* @exception IllegalStateException if called mid-parse
* @exception SAXException The handlers may throw any SAXException,
* and the parser normally throws SAXParseException objects.
* @exception IOException IOExceptions are normally through through
* the parser if there are problems reading the source document.
*/
public
void
parse
(
InputSource
source
)
throws
SAXException
,
IOException
throws
SAXException
,
IOException
{
{
EventFilter
next
;
parse
(
new
InputSource
(
systemId
));
boolean
nsdecls
;
}
synchronized
(
aelfred2
)
{
if
(
active
)
{
throw
new
IllegalStateException
(
"already parsing"
);
}
active
=
true
;
}
// set up the output pipeline
if
(
isValidating
)
{
forceValidating
();
next
=
new
ValidationConsumer
(
filter
);
}
else
{
next
=
filter
;
}
// connect pipeline and error handler
// don't let _this_ call to bind() affect xmlns* attributes
nsdecls
=
aelfred2
.
getFeature
(
SAXDriver
.
FEATURE
+
"namespace-prefixes"
);
EventFilter
.
bind
(
aelfred2
,
next
);
if
(!
nsdecls
)
{
aelfred2
.
setFeature
(
SAXDriver
.
FEATURE
+
"namespace-prefixes"
,
false
);
}
// parse, clean up
try
{
aelfred2
.
parse
(
source
);
}
finally
{
active
=
false
;
}
}
/**
* <b>SAX1</b>: Underlying API to parse an XML document, used
* directly when no URI is available. When this is invoked,
* and the parser is set to validate, some features will be
* automatically reset to appropriate values: for reporting
* namespace prefixes, and incorporating external entities.
*
* @param source The XML input source.
*
* @exception IllegalStateException if called mid-parse
* @exception SAXException The handlers may throw any SAXException,
* and the parser normally throws SAXParseException objects.
* @exception IOException IOExceptions are normally through through
* the parser if there are problems reading the source document.
*/
public
void
parse
(
InputSource
source
)
throws
SAXException
,
IOException
{
EventFilter
next
;
boolean
nsdecls
;
synchronized
(
aelfred2
)
{
if
(
active
)
throw
new
IllegalStateException
(
"already parsing"
);
active
=
true
;
}
// set up the output pipeline
if
(
isValidating
)
{
forceValidating
();
next
=
new
ValidationConsumer
(
filter
);
}
else
next
=
filter
;
// connect pipeline and error handler
// don't let _this_ call to bind() affect xmlns* attributes
nsdecls
=
aelfred2
.
getFeature
(
SAXDriver
.
FEATURE
+
"namespace-prefixes"
);
EventFilter
.
bind
(
aelfred2
,
next
);
if
(!
nsdecls
)
aelfred2
.
setFeature
(
SAXDriver
.
FEATURE
+
"namespace-prefixes"
,
false
);
// parse, clean up
try
{
aelfred2
.
parse
(
source
);
}
finally
{
active
=
false
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment