use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class XMLUpdateShredder method checkElement.
/**
* Check if current element matches the element in the shreddered file.
*
* @param mEvent StartElement event, from the XML file to shredder.
* @return true if they are equal, false otherwise.
*/
private boolean checkElement(final StartElement mEvent) {
assert mEvent != null;
boolean retVal = false;
// Matching element names?
final QName name = mEvent.getName();
final QNm currName = mWtx.getName();
if (mWtx.getKind() == Kind.ELEMENT && currName.getNamespaceURI().equals(name.getNamespaceURI()) && currName.getLocalName().equals(name.getLocalPart())) {
// Check if atts and namespaces are the same.
final long nodeKey = mWtx.getNodeKey();
// Check attributes.
boolean foundAtts = false;
boolean hasAtts = false;
for (final Iterator<?> it = mEvent.getAttributes(); it.hasNext(); ) {
hasAtts = true;
final Attribute attribute = (Attribute) it.next();
for (int i = 0, attCount = mWtx.getAttributeCount(); i < attCount; i++) {
mWtx.moveToAttribute(i);
final QName attName = attribute.getName();
final QNm currAttName = mWtx.getName();
if (attName.getNamespaceURI().equals(currAttName.getNamespaceURI()) && attName.getLocalPart().equals(currAttName.getLocalName()) && attribute.getValue().equals(mWtx.getValue())) {
foundAtts = true;
mWtx.moveTo(nodeKey);
break;
}
mWtx.moveTo(nodeKey);
}
if (!foundAtts) {
break;
}
}
if (!hasAtts && mWtx.getAttributeCount() == 0) {
foundAtts = true;
}
// Check namespaces.
boolean foundNamesps = false;
boolean hasNamesps = false;
for (final Iterator<?> namespIt = mEvent.getNamespaces(); namespIt.hasNext(); ) {
hasNamesps = true;
final Namespace namespace = (Namespace) namespIt.next();
for (int i = 0, namespCount = mWtx.getNamespaceCount(); i < namespCount; i++) {
mWtx.moveToNamespace(i);
if (namespace.getNamespaceURI().equals(mWtx.nameForKey(mWtx.getURIKey()))) {
final String prefix = namespace.getPrefix();
if (prefix.isEmpty()) {
foundNamesps = true;
mWtx.moveTo(nodeKey);
break;
} else if (prefix.equals(mWtx.nameForKey(mWtx.getPrefixKey()))) {
foundNamesps = true;
mWtx.moveTo(nodeKey);
break;
}
}
mWtx.moveTo(nodeKey);
}
if (!foundNamesps) {
break;
}
}
if (!hasNamesps && mWtx.getNamespaceCount() == 0) {
foundNamesps = true;
}
// Check if atts and namespaces are the same.
if (foundAtts && foundNamesps) {
retVal = true;
} else {
retVal = false;
}
}
return retVal;
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class StAXSerializer method emitEndTag.
/**
* Emit end tag.
*
* @param rtx Sirix reading transaction {@link XdmNodeReadTrx}
*/
private void emitEndTag(final XdmNodeReadTrx rtx) {
final long nodeKey = rtx.getNodeKey();
final QNm qName = rtx.getName();
mEvent = mFac.createEndElement(new QName(qName.getNamespaceURI(), qName.getLocalName(), qName.getPrefix()), new NamespaceIterator(rtx));
rtx.moveTo(nodeKey);
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class IndexDef method materialize.
@Override
public Node<?> materialize() throws DocumentException {
final FragmentHelper tmp = new FragmentHelper();
tmp.openElement(INDEX_TAG);
tmp.attribute(TYPE_ATTRIBUTE, new Una(mType.toString()));
tmp.attribute(ID_ATTRIBUTE, new Una(Integer.toString(mID)));
if (mContentType != null) {
tmp.attribute(CONTENT_TYPE_ATTRIBUTE, new Una(mContentType.toString()));
}
if (mUnique) {
tmp.attribute(UNIQUE_ATTRIBUTE, new Una(Boolean.toString(mUnique)));
}
if (mPaths != null && !mPaths.isEmpty()) {
for (final Path<QNm> path : mPaths) {
tmp.openElement(PATH_TAG);
// TODO
tmp.content(path.toString());
tmp.closeElement();
}
}
if (!mExcluded.isEmpty()) {
tmp.openElement(EXCLUDING_TAG);
final StringBuilder buf = new StringBuilder();
for (final QNm s : mExcluded) {
buf.append(s + ",");
}
// remove trailing ","
buf.deleteCharAt(buf.length() - 1);
tmp.content(buf.toString());
tmp.closeElement();
}
if (!mIncluded.isEmpty()) {
tmp.openElement(INCLUDING_TAG);
StringBuilder buf = new StringBuilder();
for (final QNm incl : mIncluded) {
buf.append(incl + ",");
}
// remove trailing ","
buf.deleteCharAt(buf.length() - 1);
tmp.content(buf.toString());
tmp.closeElement();
}
//
// if (indexStatistics != null) {
// tmp.insert(indexStatistics.materialize());
// }
tmp.closeElement();
return tmp.getRoot();
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class DBNode method setAttribute.
private DBNode setAttribute(XdmNodeWriteTrx wtx, Node<?> attribute) throws DocumentException {
if (wtx.isElement()) {
final String value = attribute.getValue().asStr().stringValue();
final QNm name = attribute.getName();
try {
wtx.insertAttribute(name, value);
} catch (final SirixException e) {
throw new DocumentException(e);
}
return new DBNode(mRtx, mCollection);
}
throw new DocumentException("No element node selected!");
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class FindCASIndex method execute.
@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
final DBNode doc = (DBNode) args[0];
final XdmNodeReadTrx rtx = doc.getTrx();
final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
if (controller == null) {
throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
}
final QNm name = new QNm(Namespaces.XS_NSURI, ((Str) args[1]).stringValue());
final Type type = sctx.getTypes().resolveAtomicType(name);
final Path<QNm> path = Path.parse(((Str) args[2]).stringValue());
final Optional<IndexDef> indexDef = controller.getIndexes().findCASIndex(path, type);
if (indexDef.isPresent())
return new Int32(indexDef.get().getID());
return new Int32(-1);
}
Aggregations