public void setParameter(String name,
Object value) throws DOMException {
// set features
if (value instanceof Boolean) {
boolean state = ((Boolean)value).booleanValue();
try {
if (name.equalsIgnoreCase (Constants.DOM_COMMENTS)) {
fConfiguration.setFeature (INCLUDE_COMMENTS_FEATURE, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature (NORMALIZE_DATA, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_ENTITIES)) {
fConfiguration.setFeature (CREATE_ENTITY_REF_NODES, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature (DISALLOW_DOCTYPE_DECL_FEATURE, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY)
|| name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
|| name.equalsIgnoreCase (Constants.DOM_CHECK_CHAR_NORMALIZATION)
|| name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM)) {
if (state) { // true is not supported
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"FEATURE_NOT_SUPPORTED",
new Object[] { name });
throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
}
else if (name.equalsIgnoreCase (Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature (NAMESPACES, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
}
else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_WELLFORMED)
|| name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) { // false is not supported
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"FEATURE_NOT_SUPPORTED",
new Object[] { name });
throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
}
else if (name.equalsIgnoreCase (Constants.DOM_VALIDATE)) {
fConfiguration.setFeature (VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature (XMLSCHEMA, state);
fConfiguration.setFeature (XMLSCHEMA_FULL_CHECKING, state);
}
if (state){
fConfiguration.setFeature (DYNAMIC_VALIDATION, false);
}
}
else if (name.equalsIgnoreCase (Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature (DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state){
fConfiguration.setFeature (VALIDATION_FEATURE, false);
}
}
else if (name.equalsIgnoreCase (Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature (INCLUDE_IGNORABLE_WHITESPACE, state);
}
else if (name.equalsIgnoreCase (Constants.DOM_PSVI)){
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature (PSVI_AUGMENT, true);
fConfiguration.setProperty (DOCUMENT_CLASS_NAME,
"org.apache.xerces.dom.PSVIDocumentImpl");
}
else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
String normalizedName;
// The honour-all-schemaLocations feature is
// mixed case so requires special treatment.
if (name.equalsIgnoreCase(HONOUR_ALL_SCHEMALOCATIONS)) {
normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
}
else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
fConfiguration.setFeature(normalizedName, state);
}
}
catch (XMLConfigurationException e) {
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"FEATURE_NOT_FOUND",
new Object[] { name });
throw new DOMException (DOMException.NOT_FOUND_ERR, msg);
}
}
else { // set properties
if (name.equalsIgnoreCase (Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper ((DOMErrorHandler) value);
fConfiguration.setProperty (ERROR_HANDLER, fErrorHandler);
}
catch (XMLConfigurationException e) {}
}
else {
// REVISIT: type mismatch
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"TYPE_MISMATCH_ERR",
new Object[] { name });
throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
}
}
else if (name.equalsIgnoreCase (Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty (ENTITY_RESOLVER, new DOMEntityResolverWrapper ((LSResourceResolver) value));
}
catch (XMLConfigurationException e) {}
}
else {
// REVISIT: type mismatch
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"TYPE_MISMATCH_ERR",
new Object[] { name });
throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
}
}
else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty (
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE,
null);
}
else {
fSchemaLocation = (String)value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer (fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens ()){
fSchemaLocations.clear ();
fSchemaLocations.add (t.nextToken ());
while (t.hasMoreTokens ()) {
fSchemaLocations.add (t.nextToken ());
}
fConfiguration.setProperty (
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE,
fSchemaLocations.toArray ());
}
else {
fConfiguration.setProperty (
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE,
value);
}
}
}
catch (XMLConfigurationException e) {}
}
else {
// REVISIT: type mismatch
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"TYPE_MISMATCH_ERR",
new Object[] { name });
throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
}
}
else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature (XMLSCHEMA, false);
fConfiguration.setFeature (XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty ( Constants.JAXP_PROPERTY_PREFIX
+ Constants.SCHEMA_LANGUAGE,
null);
fSchemaType = null;
}
else if (value.equals (Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature (XMLSCHEMA, true);
fConfiguration.setFeature (XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty ( Constants.JAXP_PROPERTY_PREFIX
+ Constants.SCHEMA_LANGUAGE,
Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
}
else if (value.equals (Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature (XMLSCHEMA, false);
fConfiguration.setFeature (XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty ( Constants.JAXP_PROPERTY_PREFIX
+ Constants.SCHEMA_LANGUAGE,
Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
}
catch (XMLConfigurationException e) {}
}
else {
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"TYPE_MISMATCH_ERR",
new Object[] { name });
throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
}
}
else if (name.equalsIgnoreCase (DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty (DOCUMENT_CLASS_NAME, value);
}
else {
// Try to set the property.
String normalizedName = name.toLowerCase(Locale.ENGLISH);
try {
fConfiguration.setProperty(normalizedName, value);
return;
}
catch (XMLConfigurationException e) {}
// If this is a boolean parameter a type mismatch should be thrown.
try {
// The honour-all-schemaLocations feature is
// mixed case so requires special treatment.
if (name.equalsIgnoreCase(HONOUR_ALL_SCHEMALOCATIONS)) {
normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
}
fConfiguration.getFeature(normalizedName);
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"TYPE_MISMATCH_ERR",
new Object[] { name });
throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
}
catch (XMLConfigurationException e) {}
// Parameter is not recognized
String msg =
DOMMessageFormatter.formatMessage (
DOMMessageFormatter.DOM_DOMAIN,
"FEATURE_NOT_FOUND",
new Object[] { name });
throw new DOMException (DOMException.NOT_FOUND_ERR, msg);
}
}
}
Set parameters and properties |