use of org.w3c.dom.DOMErrorHandler in project robovm by robovm.
the class LSSerializerImpl method setParameter.
/**
* This method sets the value of the named parameter.
*
* @see org.w3c.dom.DOMConfiguration#setParameter(java.lang.String, java.lang.Object)
*
* @param name A String containing the DOMConfiguration parameter name.
* @param value An Object contaiing the parameters value to set.
*/
public void setParameter(String name, Object value) throws DOMException {
// If the value is a boolean
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)) {
fFeatures = state ? fFeatures | COMMENTS : fFeatures & ~COMMENTS;
// comments
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)) {
fFeatures = state ? fFeatures | CDATA : fFeatures & ~CDATA;
// cdata-sections
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)) {
fFeatures = state ? fFeatures | ENTITIES : fFeatures & ~ENTITIES;
// entities
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)) {
fFeatures = state ? fFeatures | NAMESPACES : fFeatures & ~NAMESPACES;
// namespaces
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)) {
fFeatures = state ? fFeatures | NAMESPACEDECLS : fFeatures & ~NAMESPACEDECLS;
// namespace-declarations
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)) {
fFeatures = state ? fFeatures | SPLITCDATA : fFeatures & ~SPLITCDATA;
// split-cdata-sections
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)) {
fFeatures = state ? fFeatures | WELLFORMED : fFeatures & ~WELLFORMED;
// well-formed
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)) {
fFeatures = state ? fFeatures | DISCARDDEFAULT : fFeatures & ~DISCARDDEFAULT;
// discard-default-content
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)) {
fFeatures = state ? fFeatures | PRETTY_PRINT : fFeatures & ~PRETTY_PRINT;
// format-pretty-print
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_FORMAT_PRETTY_PRINT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_FORMAT_PRETTY_PRINT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
fFeatures = state ? fFeatures | XMLDECL : fFeatures & ~XMLDECL;
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "yes");
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fFeatures = state ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures & ~ELEM_CONTENT_WHITESPACE;
// element-content-whitespace
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
if (!state) {
// Here we have to add the Xalan specific DOM Message Formatter
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE) || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
{
// true is not supported
if (state) {
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
} else {
if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CANONICAL_FORM, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
fDOMConfigProperties.setProperty(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION + DOMConstants.DOM_CHECK_CHAR_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
}
/* else if (name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_NORMALIZE_CHARACTERS, DOMConstants.DOM3_EXPLICIT_FALSE);
} */
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
// infoset
if (state) {
fFeatures &= ~ENTITIES;
fFeatures &= ~CDATA;
fFeatures &= ~SCHEMAVALIDATE;
fFeatures &= ~DTNORMALIZE;
fFeatures |= NAMESPACES;
fFeatures |= NAMESPACEDECLS;
fFeatures |= WELLFORMED;
fFeatures |= ELEM_CONTENT_WHITESPACE;
fFeatures |= COMMENTS;
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else {
// If this is a non-boolean parameter a type mismatch should be thrown.
if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
// Parameter is not recognized
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_FOUND, new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else // If the parameter value is not a boolean
if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER)) {
if (value == null || value instanceof DOMErrorHandler) {
fDOMErrorHandler = (DOMErrorHandler) value;
} else {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
if (value != null) {
if (!(value instanceof String)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
} else {
// If this is a boolean parameter a type mismatch should be thrown.
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS) || name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS) || name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES) || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES) || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS) || name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA) || name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED) || name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT) || name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT) || name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL) || name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE) || name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS) || name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE) || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
// Parameter is not recognized
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_FOUND, new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
use of org.w3c.dom.DOMErrorHandler in project j2objc by google.
the class LSSerializerImpl method setParameter.
/**
* This method sets the value of the named parameter.
*
* @see org.w3c.dom.DOMConfiguration#setParameter(java.lang.String, java.lang.Object)
*
* @param name A String containing the DOMConfiguration parameter name.
* @param value An Object contaiing the parameters value to set.
*/
public void setParameter(String name, Object value) throws DOMException {
// If the value is a boolean
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)) {
fFeatures = state ? fFeatures | COMMENTS : fFeatures & ~COMMENTS;
// comments
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)) {
fFeatures = state ? fFeatures | CDATA : fFeatures & ~CDATA;
// cdata-sections
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)) {
fFeatures = state ? fFeatures | ENTITIES : fFeatures & ~ENTITIES;
// entities
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)) {
fFeatures = state ? fFeatures | NAMESPACES : fFeatures & ~NAMESPACES;
// namespaces
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)) {
fFeatures = state ? fFeatures | NAMESPACEDECLS : fFeatures & ~NAMESPACEDECLS;
// namespace-declarations
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)) {
fFeatures = state ? fFeatures | SPLITCDATA : fFeatures & ~SPLITCDATA;
// split-cdata-sections
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)) {
fFeatures = state ? fFeatures | WELLFORMED : fFeatures & ~WELLFORMED;
// well-formed
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)) {
fFeatures = state ? fFeatures | DISCARDDEFAULT : fFeatures & ~DISCARDDEFAULT;
// discard-default-content
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)) {
fFeatures = state ? fFeatures | PRETTY_PRINT : fFeatures & ~PRETTY_PRINT;
// format-pretty-print
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_FORMAT_PRETTY_PRINT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_FORMAT_PRETTY_PRINT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
fFeatures = state ? fFeatures | XMLDECL : fFeatures & ~XMLDECL;
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "yes");
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fFeatures = state ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures & ~ELEM_CONTENT_WHITESPACE;
// element-content-whitespace
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
if (!state) {
// Here we have to add the Xalan specific DOM Message Formatter
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE) || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
{
// true is not supported
if (state) {
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
} else {
if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CANONICAL_FORM, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
fDOMConfigProperties.setProperty(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION + DOMConstants.DOM_CHECK_CHAR_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
}
/* else if (name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_NORMALIZE_CHARACTERS, DOMConstants.DOM3_EXPLICIT_FALSE);
} */
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
// infoset
if (state) {
fFeatures &= ~ENTITIES;
fFeatures &= ~CDATA;
fFeatures &= ~SCHEMAVALIDATE;
fFeatures &= ~DTNORMALIZE;
fFeatures |= NAMESPACES;
fFeatures |= NAMESPACEDECLS;
fFeatures |= WELLFORMED;
fFeatures |= ELEM_CONTENT_WHITESPACE;
fFeatures |= COMMENTS;
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else {
// If this is a non-boolean parameter a type mismatch should be thrown.
if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
// Parameter is not recognized
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_FOUND, new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else // If the parameter value is not a boolean
if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER)) {
if (value == null || value instanceof DOMErrorHandler) {
fDOMErrorHandler = (DOMErrorHandler) value;
} else {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
if (value != null) {
if (!(value instanceof String)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
} else {
// If this is a boolean parameter a type mismatch should be thrown.
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS) || name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS) || name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES) || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES) || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS) || name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA) || name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED) || name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT) || name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT) || name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL) || name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE) || name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS) || name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE) || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
// Parameter is not recognized
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_FOUND, new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
use of org.w3c.dom.DOMErrorHandler in project robovm by robovm.
the class NormalizeTest method testErrorHandler.
public void testErrorHandler() {
assertEquals(null, domConfiguration.getParameter("error-handler"));
assertSupported("error-handler", null);
assertSupported("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
return true;
}
});
}
use of org.w3c.dom.DOMErrorHandler in project intellij-community by JetBrains.
the class XSDModelLoader method loadSchema.
private XSModel loadSchema(File schemaFile, XMLEntityResolver resolver) throws Exception {
// get DOM Implementation using DOM Registry
System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
DOMConfiguration config = schemaLoader.getConfig();
// create Error Handler
DOMErrorHandler errorHandler = new DOMErrorHandler() {
public boolean handleError(DOMError domError) {
Util.log("DOMError: " + domError.getMessage());
Object relatedException = domError.getRelatedException();
if (relatedException != null) {
Util.log("DOMError: " + relatedException);
if (relatedException instanceof Throwable) {
((Throwable) relatedException).printStackTrace(System.out);
}
}
return false;
}
};
// set error handler
config.setParameter("error-handler", errorHandler);
// set validation feature
config.setParameter("validate", Boolean.TRUE);
// parse document
config.setParameter("error-handler", errorHandler);
config.setParameter("http://apache.org/xml/properties/internal/entity-resolver", resolver);
XSModel model = schemaLoader.loadURI(schemaFile.getAbsolutePath());
if (model == null)
return null;
XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int i = 0; i < components.getLength(); i++) {
XSObject obj = components.item(i);
QName qname = new QName(obj.getNamespace(), obj.getName());
String file = this.model.qname2FileMap.get(qname);
this.model.qname2FileMap.put(qname, (file == null ? "" : file + ";") + schemaFile.getName());
}
components = model.getComponents(XSConstants.TYPE_DEFINITION);
for (int i = 0; i < components.getLength(); i++) {
XSObject obj = components.item(i);
QName qname = new QName(obj.getNamespace(), obj.getName());
String file = this.model.qname2FileMap.get(qname);
this.model.qname2FileMap.put(qname, (file == null ? "" : file) + ":" + schemaFile.getName() + ":");
}
return model;
}
use of org.w3c.dom.DOMErrorHandler in project ACS by ACS-Community.
the class HibernateWDALImpl method initializeParser.
private void initializeParser() throws RuntimeException {
try {
System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
domImplementationLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
parser = domImplementationLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, "http://www.w3.org/2001/XMLSchema");
//parser.getDomConfig().setParameter("http://apache.org/xml/features/xinclude", Boolean.TRUE);
schemaResourceResolverLoader = new SchemaResourceResolverLoader(null, domImplementationLS, m_logger);
parser.getDomConfig().setParameter("resource-resolver", schemaResourceResolverLoader);
parser.getDomConfig().setParameter("http://apache.org/xml/features/validation/schema", Boolean.TRUE);
parser.getDomConfig().setParameter("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
//((Exception) error.getRelatedException()).printStackTrace();
throw new LSException(LSException.PARSE_ERR, error.getMessage());
}
});
input = domImplementationLS.createLSInput();
output = domImplementationLS.createLSOutput();
// SAX parser (non-validating)
SAXParserFactory factory = SAXParserFactory.newInstance();
saxParser = factory.newSAXParser();
} catch (Throwable th) {
throw new RuntimeException("Failed to initialize parser.", th);
}
}
Aggregations