attrQName = attributes.getQName(i);
if (attrQName.startsWith("xmlns")
|| attrNS.equals(Namespaces.EXIST_NS))
{--attrLength;}
}
ElementImpl last;
ElementImpl node;
int p = qname.indexOf(':');
final String prefix = (p != Constants.STRING_NOT_FOUND) ?
qname.substring(0, p) : "";
final QName qn = broker.getBrokerPool().getSymbols().getQName(
Node.ELEMENT_NODE, namespace, name, prefix);
if (!stack.empty()) {
last = stack.peek();
if (charBuf != null) {
if (charBuf.isWhitespaceOnly()) {
if (suppressWSmixed) {
if (charBuf.length() > 0 && !(last.getChildCount() == 0 && (normalize & XMLString.SUPPRESS_LEADING_WS) != 0)) {
text.setData(charBuf);
text.setOwnerDocument(document);
last.appendChildInternal(prevNode, text);
if (!validate)
{storeText();}
setPrevious(text);
}
}
} else if (charBuf.length() > 0) {
// mixed element content: don't normalize the text node,
// just check
// if there is any text at all
text.setData(charBuf);
text.setOwnerDocument(document);
last.appendChildInternal(prevNode, text);
if (!validate)
{storeText();}
setPrevious(text);
}
charBuf.reset();
}
try {
if (!usedElements.isEmpty()) {
node = usedElements.pop();
node.setNodeName(qn, broker.getBrokerPool().getSymbols());
} else {
node = new ElementImpl(qn, broker.getBrokerPool().getSymbols());
}
} catch (DOMException e) {
throw new SAXException(e.getMessage(), e);
}
// copy xml:space setting
node.setPreserveSpace(last.preserveSpace());
// append the node to its parent
// (computes the node id and updates the parent's child count)
last.appendChildInternal(prevNode, node);
setPrevious(null);
node.setOwnerDocument(document);
node.setAttributes((short) attrLength);
if (nsMappings != null && nsMappings.size() > 0) {
node.setNamespaceMappings(nsMappings);
nsMappings.clear();
}
stack.push(node);
currentPath.addComponent(qn);
node.setPosition(elementCnt++);
if (!validate) {
if (childCnt != null) {
node.setChildCount(childCnt[node.getPosition()]);
}
storeElement(node);
}
} else {
try {
node = new ElementImpl(qn, broker.getBrokerPool().getSymbols());
} catch (DOMException e) {
throw new SAXException(e.getMessage(), e);
}
rootNode = node;
setPrevious(null);
node.setOwnerDocument(document);
node.setNodeId(broker.getBrokerPool().getNodeFactory()
.createInstance(nodeFactoryInstanceCnt++));
node.setAttributes((short) attrLength);
if (nsMappings != null && nsMappings.size() > 0) {
node.setNamespaceMappings(nsMappings);
nsMappings.clear();
}
stack.push(node);
currentPath.addComponent(qn);
node.setPosition(elementCnt++);
if (!validate) {
if (childCnt != null) {
node.setChildCount(childCnt[node.getPosition()]);
}
storeElement(node);
}
document.appendChild(node);
}
level++;
String attrPrefix;
String attrLocalName;
for (int i = 0; i < attributes.getLength(); i++) {
attrNS = attributes.getURI(i);
attrLocalName = attributes.getLocalName(i);
attrQName = attributes.getQName(i);
// skip xmlns-attributes and attributes in eXist's namespace
if (attrQName.startsWith("xmlns")
|| attrNS.equals(Namespaces.EXIST_NS))
{--attrLength;}
else {
p = attrQName.indexOf(':');
attrPrefix = (p != Constants.STRING_NOT_FOUND) ?
attrQName.substring(0, p) : null;
final AttrImpl attr = (AttrImpl) NodePool.getInstance().borrowNode(Node.ATTRIBUTE_NODE);
final QName attrQN = broker.getBrokerPool().getSymbols().getQName(Node.ATTRIBUTE_NODE, attrNS, attrLocalName, attrPrefix);
try {
attr.setNodeName(attrQN, broker.getBrokerPool().getSymbols());
} catch (DOMException e) {
throw new SAXException(e.getMessage(), e);
}
attr.setValue(attributes.getValue(i));
attr.setOwnerDocument(document);
if (attributes.getType(i).equals(ATTR_ID_TYPE)) {
attr.setType(AttrImpl.ID);
} else if (attributes.getType(i).equals(ATTR_IDREF_TYPE)) {
attr.setType(AttrImpl.IDREF);
} else if (attributes.getType(i).equals(ATTR_IDREFS_TYPE)) {
attr.setType(AttrImpl.IDREFS);
} else if (attr.getQName().equalsSimple(Namespaces.XML_ID_QNAME)) {
// an xml:id attribute. Normalize the attribute and set its
// type to ID
attr.setValue(StringValue.trimWhitespace(StringValue
.collapseWhitespace(attr.getValue())));
if (!XMLChar.isValidNCName(attr.getValue()))
{throw new SAXException(
"Value of xml:id attribute is not a valid NCName: "
+ attr.getValue());}
attr.setType(AttrImpl.ID);
} else if (attr.getQName().equalsSimple(Namespaces.XML_SPACE_QNAME)) {
node.setPreserveSpace("preserve".equals(attr.getValue()));
}
node.appendChildInternal(prevNode, attr);
setPrevious(attr);
if (!validate) {
broker.storeNode(transaction, attr, currentPath, indexSpec);
if (indexListener != null)
{indexListener.attribute(transaction, attr, currentPath);}
}
}
}
if (attrLength > 0)
{node.setAttributes((short) attrLength);}
// notify observers about progress every 100 lines
if (locator != null) {
currentLine = locator.getLineNumber();
if (!validate) {
progress.setValue(currentLine);