Methods Summary |
---|
public org.xml.sax.Parser | getParser()
return xmlReader;
|
public java.lang.Object | getProperty(java.lang.String name)returns the particular property requested for in the underlying
implementation of org.xml.sax.XMLReader.
// TODO: reroute those properties to use new JAXP1.3 API. -KK
if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
// JAXP 1.2 support
return schemaLanguage;
} else {
return xmlReader.getProperty(name);
}
|
public javax.xml.validation.Schema | getSchema()
return grammar;
|
public org.xml.sax.XMLReader | getXMLReader()Returns the XMLReader that is encapsulated by the implementation of
this class.
return xmlReader;
|
void | init()
schemaLanguage = null ;
this.isXIncludeAware = spf.isXIncludeAware();
if(features != null ){
Object tmpValue = features.get(Constants.FEATURE_SECURE_PROCESSING);
if( tmpValue != null )
enableSecureProcessing = ((Boolean)tmpValue).booleanValue();
}
if(enableSecureProcessing){
try {
setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, secureProcessing);
} catch (SAXNotRecognizedException sex) {
sex.printStackTrace();
} catch (SAXNotSupportedException se) {
se.printStackTrace();
}
}
xmlReader.setFeature(
Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_AWARE,
isXIncludeAware);
// If validating, provide a default ErrorHandler that prints
// validation errors with a warning telling the user to set an
// ErrorHandler.
if (spf.isValidating()) {
xmlReader.setErrorHandler(new DefaultValidationErrorHandler());
}
xmlReader.setFeature(Constants.SAX_FEATURE_PREFIX +
Constants.VALIDATION_FEATURE, spf.isValidating());
// JAXP "namespaceAware" == SAX Namespaces feature
// Note: there is a compatibility problem here with default values:
// JAXP default is false while SAX 2 default is true!
xmlReader.setFeature(Constants.SAX_FEATURE_PREFIX +
Constants.NAMESPACES_FEATURE,
spf.isNamespaceAware());
// SAX "namespaces" and "namespace-prefixes" features should not
// both be false. We make them opposite for backward compatibility
// since JAXP 1.0 apps may want to receive xmlns* attributes.
xmlReader.setFeature(Constants.SAX_FEATURE_PREFIX +
Constants.NAMESPACE_PREFIXES_FEATURE,
!spf.isNamespaceAware());
setFeatures(features);
|
public boolean | isNamespaceAware()
try {
return xmlReader.getFeature(Constants.SAX_FEATURE_PREFIX +
Constants.NAMESPACES_FEATURE);
} catch (SAXException x) {
throw new IllegalStateException(x.getMessage());
}
|
public boolean | isSecureProcessing()Return True if secure processing in effect.
Defaults to false .
return secureProcessing!=null;
|
public boolean | isValidating()
try {
return xmlReader.getFeature(Constants.SAX_FEATURE_PREFIX +
Constants.VALIDATION_FEATURE);
} catch (SAXException x) {
throw new IllegalStateException(x.getMessage());
}
|
public boolean | isXIncludeAware()
return isXIncludeAware;
|
public void | reset()Reset this DocumentBuilder to its original configuration.
DocumentBuilder is reset to the same state as when it was created with
{@link DocumentBuilderFactory#newDocumentBuilder()}.
reset() is designed to allow the reuse of existing DocumentBuilder s
thus saving resources associated with the creation of new DocumentBuilder s.
The reset DocumentBuilder is not guaranteed to have the same {@link EntityResolver} or {@link ErrorHandler}
Object s, e.g. {@link Object#equals(Object obj)}. It is guaranteed to have a functionally equal
EntityResolver and ErrorHandler .
if(xmlReader != null){
try{
xmlReader.reset();
//set the object back to its factory settings
resetSettings();
}
//xxx: underlying implementation reset throws XNIException what should we do in this case ?
//if there was any propery that is not being supported
//exception would have been thrown when setting it on the underlying implementation.
catch(XNIException ex){
//coninue.
}
catch(SAXException sax){}
}
|
void | resetSettings()Reset this instance back to factory settings
Enumeration keys = parserFeatures.keys();
while(keys.hasMoreElements()){
String propertyId = (String)keys.nextElement();
Object value = parserFeatures.get(propertyId);
if(value instanceof Boolean){
//System.out.println("Remvoing feature = " + propertyId + " with value = " + parserConfiguration.getFeatureDefaultValue(propertyId));
//this means it is a feature, we have to get default value from the configuration
xmlReader.setFeature(propertyId, parserConfiguration.getFeatureDefaultValue(propertyId));
}
else{//it's a property
//System.out.println("Remvoing property = " + propertyId);
//null value should delete the property from underlying implementation.
xmlReader.setProperty(propertyId, null);
}
}
//clear the hashtable once we have removed all the properties.
parserFeatures.clear();
|
private void | setFeatures(java.util.Hashtable features)Set any features of our XMLReader based on any features set on the
SAXParserFactory.
XXX Does not handle possible conflicts between SAX feature names and
JAXP specific feature names, eg. SAXParserFactory.isValidating()
if (features != null) {
for (Enumeration e = features.keys(); e.hasMoreElements();) {
String feature = (String)e.nextElement();
boolean value = ((Boolean)features.get(feature)).booleanValue();
if(!feature.equals(Constants.FEATURE_SECURE_PROCESSING))
xmlReader.setFeature(feature, value);
}
}
|
public void | setProperty(java.lang.String name, java.lang.Object value)Sets the particular property in the underlying implementation of
org.xml.sax.XMLReader.
// the spec says if a schema is given via SAXParserFactory
// the JAXP 1.2 properties shouldn't be allowed. So
// reject them first.
if(grammar!=null) {
if (JAXP_SCHEMA_LANGUAGE.equals(name)
|| JAXP_SCHEMA_SOURCE.equals(name)) {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(null, "schema-already-specified", null));
}
}
if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
// JAXP 1.2 support
if ( W3C_XML_SCHEMA.equals(value) ) {
//None of the properties will take effect till the setValidating(true) has been called
if( isValidating() ) {
schemaLanguage = W3C_XML_SCHEMA;
xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +
Constants.SCHEMA_VALIDATION_FEATURE,
true);
//also set the schema full checking to true.
xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +
Constants.SCHEMA_FULL_CHECKING,
true);
//add this among the list of parser features since this is added
//on the parser instance and should be set to default value during
//reset.
parserFeatures.put(Constants.XERCES_FEATURE_PREFIX +
Constants.SCHEMA_VALIDATION_FEATURE, new Boolean(true));
parserFeatures.put(Constants.XERCES_FEATURE_PREFIX +
Constants.SCHEMA_FULL_CHECKING, new Boolean(true));
// this will allow the parser not to emit DTD-related
// errors, as the spec demands
xmlReader.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
parserFeatures.put(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
}
else{
//System.out.println("Property = " + name + "is not set");
}
} else if (value == null) {
schemaLanguage = null;
xmlReader.setFeature(Constants.XERCES_FEATURE_PREFIX +
Constants.SCHEMA_VALIDATION_FEATURE,
false);
parserFeatures.put(Constants.XERCES_FEATURE_PREFIX +
Constants.SCHEMA_VALIDATION_FEATURE,
new Boolean(false));
} else {
// REVISIT: It would be nice if we could format this message
// using a user specified locale as we do in the underlying
// XMLReader -- mrglavas
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(null, "schema-not-supported", null));
}
}
else if(JAXP_SCHEMA_SOURCE.equals(name)) {
//If we are not validating then don't check for JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCED
if ( isValidating() ) {
String val = (String)getProperty(JAXP_SCHEMA_LANGUAGE);
if ( val != null && W3C_XML_SCHEMA.equals(val) ) {
xmlReader.setProperty(name, value);
parserFeatures.put(name, value);
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(null,
"jaxp-order-not-supported",
new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
}
}
}
/*else if(name.equlas(Constants.ENTITY_EXPANSION_LIMIT)){
String elimit = (String)value;
if(elimit != null && elimit != ""){
int val = Integer.parseInt(elimit);
secureProcessing.setEntityExpansionLimit(val);
}
}else if(name.equals(Constants.MAX_OCCUR_LIMIT)) {
String mlimit = (String)value;
if(mlimit != null && mlimit != ""){
int val = Integer.parseInt(mlimit);
secureProcessing.setMaxOccurNodeLimit(val);
}
}*/
else if(value instanceof Boolean){
//assume feature
xmlReader.setFeature(name,((Boolean)value).booleanValue());
parserFeatures.put(name, value);
}else{
xmlReader.setProperty(name, value);
parserFeatures.put(name, value);
}
|