ownerDocument.checkNameValidXML(getNodeName());
} catch (DOMException e) {
if (ownerDocument.getDomConfig() != null) {
if (!errorNode.contains(this)) {
errorNode.add(this);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_ERROR,
new CDOMLocator(this, null),
"wf-invalid-character-in-node-name");
if (!err.handleError(error)) {
throw error;
}
}
}
}
}
}
}
if ((!((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.ENTITIES)).booleanValue())) {
if (getNodeType() == Node.ENTITY_REFERENCE_NODE) {
if (nl.getLength() == 0)
return;
for (int i = 0; i < nl.getLength(); i++) {
getParentNode().insertBefore(nl.item(i).cloneNode(true),
this);
}
Node parent = getParentNode();
parent.removeChild(this);
}
}
if ((((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.NAMESPACES)).booleanValue())) {
if (getNodeType() == Node.ATTRIBUTE_NODE) {
if (isDom1()) {
if (!errorNode.contains(this)) {
errorNode.add(this);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_ERROR, new CDOMLocator(
this, null), "1_o/* paf !");
if (!err.handleError(error)) {
throw error;
}
}
}
}
} else if (getNodeType() == Node.ELEMENT_NODE
|| getNodeType() == Node.DOCUMENT_NODE) {
if (isDom1()
&& (getNodeType() == Node.ELEMENT_NODE || getNodeType() == Node.ATTRIBUTE_NODE)) {
if (!errorNode.contains(this)) {
errorNode.add(this);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_ERROR, new CDOMLocator(
this, null), "2_o/* paf !");
if (!err.handleError(error)) {
throw error;
}
}
}
}
boolean isReadOnly = false;
try {
isReadOnly();
} catch (DOMException e) {
isReadOnly = true;
}
if (!isReadOnly) {
List toRemove = new ArrayList();
NamedNodeMap nnm = getAttributes();
if (!((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.NAMESPACE_DECLARATIONS))
.booleanValue()) {
if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) {
CAttr at = (CAttr) nnm.item(i);
toRemove.add(at);
}
}
for (int i = 0; i < toRemove.size(); i++) {
((Element) this)
.removeAttributeNode((Attr) toRemove.get(i));
}
setNamespaceURI(" ");
// this.nsList = null;
} else {
if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) {
CAttr at = (CAttr) nnm.item(i);
if (at.isDefaults()) {
at.setSpecified(true);
}
if ("xmlns".equals(at.getPrefix())) {
String ns = at.lookupNamespaceURI(at
.getLocalName());
if (ns == null) {
toRemove.add(at);
} else {
NodeList nlns = at
.getOwnerElement()
.getElementsByTagNameNS(ns, "*");
if (nlns.getLength() == 0) {
toRemove.add(at);
}
}
}
}
}
for (int i = 0; i < toRemove.size(); i++) {
((Element) this)
.removeAttributeNode((Attr) toRemove.get(i));
}
}
}
}
}
if ((!((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.SPLIT_CDATA_SECTIONS)).booleanValue())) {
if (getNodeType() == Node.CDATA_SECTION_NODE) {
String value = getNodeValue();
if (value.indexOf("]]>") != -1) {
if (!errorNode.contains(this)) {
errorNode.add(this);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_ERROR, new CDOMLocator(
this, null),
"cdata-sections-not-split");
if (!err.handleError(error)) {
throw error;
}
}
}
}
}
}
if ((((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.SPLIT_CDATA_SECTIONS)).booleanValue())) {
if (getNodeType() == Node.CDATA_SECTION_NODE) {
Node parent = getParentNode();
String value = getNodeValue();
if (value.indexOf("]]>", 0) != -1) {
CDATASection first = null;
while (value.indexOf("]]>", 0) != -1) {
// need to split
String pre = value
.substring(0, value.indexOf("]]>", 0));
CDATASection section = ownerDocument
.createCDATASection(pre);
if (first == null)
first = section;
parent.insertBefore(section, this);
Text t = ownerDocument.createTextNode("]]>");
parent.insertBefore(t, this);
value = value.substring(value.indexOf("]]>", 0) + 3);
}
if (value.length() > 0) {
CDATASection section = ownerDocument
.createCDATASection(value);
parent.insertBefore(section, this);
}
if (!errorNode.contains(this)) {
errorNode.add(this);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_WARNING, new CDOMLocator(
first, null),
"cdata-sections-splitted");
if (!err.handleError(error)) {
throw error;
}
}
}
parent.removeChild(this);
((ANode) parent)._normalizeDocument(errorNode);
return;
}
}
}
if ((!((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.CDATA_SECTIONS)).booleanValue())) {
if (getNodeType() == Node.CDATA_SECTION_NODE) {
Text t = ownerDocument.createTextNode(getNodeValue());
Node parent = getParentNode();
parent.insertBefore(t, this);
parent.removeChild(this);
((ANode) parent)._normalizeDocument(errorNode);
return;
}
}
if ((!((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.COMMENTS)).booleanValue())) {
if (getNodeType() == Node.COMMENT_NODE) {
Node parent = getParentNode();
parent.removeChild(this);
((ANode) parent)._normalizeDocument(errorNode);
return;
}
}
if (((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.CHECK_CHARACTER_NORMALIZATION))
.booleanValue()
|| ((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.NORMALIZE_CHARACTERS)).booleanValue()) {
if (getNodeType() == TEXT_NODE) {
String value = getNodeValue();
String nvalue = Normalizer
.normalize(value, Normalizer.Form.NFC);
try {
setNodeValue(nvalue);
} catch (DOMException ignore) {
}
if (((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.CHECK_CHARACTER_NORMALIZATION))
.booleanValue()) {
if (nvalue.toCharArray().length != value.toCharArray().length) {
if (!errorNode.contains(this)) {
errorNode.add(this);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_ERROR,
new CDOMLocator(this, null),
"check-character-normalization-failure");
if (!err.handleError(error)) {
throw error;
}
}
}
}
}
}
}
if ((!((Boolean) ownerDocument.getDomConfig().getParameter(
CDOMConfiguration.ELEMENT_CONTENT_WHITESPACE)).booleanValue())) {
if (getNodeType() == TEXT_NODE || getNodeType() == ATTRIBUTE_NODE) {
String value = getNodeValue().trim();
value = value.replace('\n', ' ');
value = value.replace('\r', ' ');
value = value.replace('\t', ' ');
value = value.replace((char) 65279, ' ');
char[] array = value.toCharArray();
char last = ' ';
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < array.length; i++) {
if (array[i] == last && last == ' ')
continue;
last = array[i];
buffer.append(array[i]);
}
try {
setNodeValue(buffer.toString().trim());
} catch (DOMException ignore) {
}
}
}
List toRemove = new ArrayList();
Text n = null;
boolean dom1 = isDom1();
for (int i = 0; i < nl.getLength(); i++) {
ANode node = (ANode) nl.item(i);
if (node == null)
continue;
node._normalizeDocument(errorNode);
if (node.getNodeType() == Node.TEXT_NODE) {
if (n == null) {
n = (Text) node;
try {
if (i == nl.getLength() - 1
&& (nl.getLength() > 1 || getNodeType() == Node.DOCUMENT_FRAGMENT_NODE)) {
if (n.getData().trim().length() == 0) {
if (n.getData().length() > 0) {
n.setData(" ");
} else {
toRemove.add(node);
}
} else {
if (n.getNextSibling() != null
&& n.getNextSibling().getNodeType() != Node.TEXT_NODE
&& (n.getData().endsWith(" ")
|| n.getData().endsWith("\t")
|| n.getData().endsWith("\n") || n
.getData().endsWith("\r"))) {
if (n.getPreviousSibling() != null
&& (n.getData().startsWith(" ")
|| n.getData().startsWith(
"\t")
|| n.getData().startsWith(
"\n") || n
.getData().startsWith("\r"))) {
n.setData(" " + n.getData().trim()
+ " ");
} else {
n.setData(n.getData().trim() + " ");
}
} else if (n.getPreviousSibling() != null
&& (n.getData().startsWith(" ")
|| n.getData().startsWith("\t")
|| n.getData().startsWith("\n") || n
.getData().startsWith("\r"))) {
n.setData(" " + n.getData().trim());
} else {
n.setData(n.getData().trim());
}
}
} else if (n.getData().trim().length() > 0) {
if (n.getNextSibling() != null
&& n.getNextSibling().getNodeType() != Node.TEXT_NODE
&& (n.getData().endsWith(" ")
|| n.getData().endsWith("\t")
|| n.getData().endsWith("\n") || n
.getData().endsWith("\r"))) {
if (n.getPreviousSibling() != null
&& (n.getData().startsWith(" ")
|| n.getData().startsWith("\t")
|| n.getData().startsWith("\n") || n
.getData().startsWith("\r"))) {
n.setData(" " + n.getData().trim() + " ");
} else {
n.setData(n.getData().trim() + " ");
}
} else if (n.getPreviousSibling() != null
&& (n.getData().startsWith(" ")
|| n.getData().startsWith("\t")
|| n.getData().startsWith("\n") || n
.getData().startsWith("\r"))) {
n.setData(" " + n.getData().trim());
} else {
n.setData(n.getData().trim());
}
} else {
if (n.getData().length() > 0) {
n.setData(" ");
} else {
toRemove.add(node);
}
}
} catch (DOMException ignore) {
}
} else {
if (node.getNextSibling() != null
&& node.getNextSibling().getNodeType() != Node.TEXT_NODE
&& (node.getNodeValue().endsWith(" ")
|| node.getNodeValue().endsWith("\t")
|| node.getNodeValue().endsWith("\n") || node
.getNodeValue().endsWith("\r"))) {
if (node.getPreviousSibling() != null
&& (node.getNodeValue().startsWith(" ")
|| node.getNodeValue().startsWith("\t")
|| node.getNodeValue().startsWith("\n") || node
.getNodeValue().startsWith("\r"))) {
n
.appendData(" "
+ node.getNodeValue().trim() + " ");
} else {
n.appendData(node.getNodeValue().trim() + " ");
}
} else if (node.getPreviousSibling() != null
&& (node.getNodeValue().startsWith(" ")
|| node.getNodeValue().startsWith("\t")
|| node.getNodeValue().startsWith("\n") || node
.getNodeValue().startsWith("\r"))) {
n.appendData(" " + node.getNodeValue().trim());
} else {
n.appendData(node.getNodeValue().trim());
}
toRemove.add(node);
}
} else {
n = null;
if (node.getNodeType() == Node.ELEMENT_NODE
&& this.getNodeType() == Node.ELEMENT_NODE
&& dom1 != node.isDom1()) {
if (ownerDocument.getDomConfig() != null) {
if (errorNode.contains(node))
continue;
errorNode.add(node);
DOMErrorHandler err = (DOMErrorHandler) ownerDocument
.getDomConfig().getParameter(
CDOMConfiguration.ERROR_HANDLER);
if (err != null) {
CDOMError error = new CDOMError(
DOMError.SEVERITY_ERROR, new CDOMLocator(nl
.item(i), null), null);
if (!err.handleError(error)) {
throw error;
}
}
}
}