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);
}
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
fConfiguration.setFeature (name.toLowerCase(Locale.ENGLISH), 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 feature
fConfiguration.setFeature (
Constants.XERCES_FEATURE_PREFIX
+ Constants.SCHEMA_VALIDATION_FEATURE,
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 feature
fConfiguration.setFeature (Constants.XERCES_FEATURE_PREFIX
+ Constants.SCHEMA_VALIDATION_FEATURE,
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 feature
fConfiguration.setFeature (
Constants.XERCES_FEATURE_PREFIX
+ Constants.SCHEMA_VALIDATION_FEATURE,
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 {
// REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
//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);
}
}
}