Search in sources :

Example 6 with QNm

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;
}
Also used : QNm(org.brackit.xquery.atomic.QNm) Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) Namespace(javax.xml.stream.events.Namespace)

Example 7 with QNm

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);
}
Also used : QNm(org.brackit.xquery.atomic.QNm) QName(javax.xml.namespace.QName)

Example 8 with QNm

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();
}
Also used : QNm(org.brackit.xquery.atomic.QNm) FragmentHelper(org.brackit.xquery.node.parser.FragmentHelper) Una(org.brackit.xquery.atomic.Una)

Example 9 with QNm

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!");
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Example 10 with QNm

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);
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) Type(org.brackit.xquery.xdm.Type) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Int32(org.brackit.xquery.atomic.Int32) IndexController(org.sirix.access.IndexController) IndexDef(org.sirix.index.IndexDef)

Aggregations

QNm (org.brackit.xquery.atomic.QNm)89 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)20 Test (org.junit.Test)18 QueryException (org.brackit.xquery.QueryException)15 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)15 DBNode (org.sirix.xquery.node.DBNode)12 QName (javax.xml.namespace.QName)11 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Axis (org.sirix.api.Axis)7 DescendantAxis (org.sirix.axis.DescendantAxis)7 SirixException (org.sirix.exception.SirixException)7 Attribute (javax.xml.stream.events.Attribute)5 Namespace (javax.xml.stream.events.Namespace)5 DocumentException (org.brackit.xquery.xdm.DocumentException)5 SirixIOException (org.sirix.exception.SirixIOException)5 Ignore (org.junit.Ignore)4 SirixUsageException (org.sirix.exception.SirixUsageException)4