Search in sources :

Example 1 with TextFilter

use of org.sirix.axis.filter.TextFilter in project sirix by sirixdb.

the class NestedFilterTest method testFilterConvetions.

@Test
public void testFilterConvetions() throws SirixException {
    holder.getReader().moveTo(9L);
    FilterTest.testFilterConventions(new NestedFilter(holder.getReader(), new ItemFilter(holder.getReader()), new ElementFilter(holder.getReader()), new NameFilter(holder.getReader(), "b")), true);
    FilterTest.testFilterConventions(new NestedFilter(holder.getReader(), new ItemFilter(holder.getReader()), new AttributeFilter(holder.getReader()), new NameFilter(holder.getReader(), "b")), false);
    holder.getReader().moveTo(4L);
    FilterTest.testFilterConventions(new NestedFilter(holder.getReader(), new NodeFilter(holder.getReader()), new ElementFilter(holder.getReader())), false);
    FilterTest.testFilterConventions(new NestedFilter(holder.getReader(), new NodeFilter(holder.getReader()), new TextFilter(holder.getReader())), true);
    holder.getReader().moveTo(1L);
    holder.getReader().moveToAttribute(0);
    FilterTest.testFilterConventions(new NestedFilter(holder.getReader(), new AttributeFilter(holder.getReader()), new NameFilter(holder.getReader(), "i")), true);
}
Also used : NestedFilter(org.sirix.axis.filter.NestedFilter) NameFilter(org.sirix.axis.filter.NameFilter) TextFilter(org.sirix.axis.filter.TextFilter) ItemFilter(org.sirix.axis.filter.ItemFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) NodeFilter(org.sirix.axis.filter.NodeFilter) FilterTest(org.sirix.axis.filter.FilterTest) Test(org.junit.Test)

Example 2 with TextFilter

use of org.sirix.axis.filter.TextFilter in project sirix by sirixdb.

the class NestedAxisTest method testNestedAxisTest.

@Test
public void testNestedAxisTest() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    // Find descendants starting from nodeKey 0L (root).
    rtx.moveToDocumentRoot();
    // XPath expression /p:a/b/text()
    // Part: /p:a
    final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
    // Part: /b
    final Axis childB = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "b"));
    // Part: /text()
    final Axis text = new FilterAxis(new ChildAxis(rtx), new TextFilter(rtx));
    // Part: /p:a/b/text()
    final Axis axis = new NestedAxis(new NestedAxis(childA, childB), text);
    AbsAxisTest.testIAxisConventions(axis, new long[] { 6L, 12L });
}
Also used : NameFilter(org.sirix.axis.filter.NameFilter) TextFilter(org.sirix.axis.filter.TextFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) FilterAxis(org.sirix.axis.filter.FilterAxis) Axis(org.sirix.api.Axis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 3 with TextFilter

use of org.sirix.axis.filter.TextFilter in project sirix by sirixdb.

the class StAXSerializer method getElementText.

@Override
public String getElementText() throws XMLStreamException {
    final XdmNodeReadTrx rtx = mAxis.getTrx();
    final long nodeKey = rtx.getNodeKey();
    /*
     * The cursor has to move back (once) after determining, that a closing tag would be the next
     * event (precond: closeElement and either goBack or goUp is true).
     */
    if (mCloseElements && mToLastKey) {
        rtx.moveTo(mLastKey);
    }
    if (mEvent.getEventType() != XMLStreamConstants.START_ELEMENT) {
        rtx.moveTo(nodeKey);
        throw new XMLStreamException("getElementText() only can be called on a start element");
    }
    final FilterAxis textFilterAxis = new FilterAxis(new DescendantAxis(rtx), new TextFilter(rtx));
    final StringBuilder strBuilder = new StringBuilder();
    while (textFilterAxis.hasNext()) {
        textFilterAxis.next();
        strBuilder.append(rtx.getValue());
    }
    rtx.moveTo(nodeKey);
    return XMLToken.escapeContent(strBuilder.toString());
}
Also used : TextFilter(org.sirix.axis.filter.TextFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) DescendantAxis(org.sirix.axis.DescendantAxis) FilterAxis(org.sirix.axis.filter.FilterAxis)

Example 4 with TextFilter

use of org.sirix.axis.filter.TextFilter in project sirix by sirixdb.

the class StAXDiffSerializer method getElementText.

@Override
public String getElementText() throws XMLStreamException {
    final NodeReadTrx rtx = mAxis.getTransaction();
    final long nodeKey = rtx.getNodeKey();
    /*
		 * The cursor has to move back (once) after determining, that a closing tag
		 * would be the next event (precond: closeElement and either goBack or goUp
		 * is true).
		 */
    if (mCloseElements && mToLastKey) {
        rtx.moveTo(mLastKey);
    }
    if (mEvent.getEventType() != XMLStreamConstants.START_ELEMENT) {
        rtx.moveTo(nodeKey);
        throw new XMLStreamException("getElementText() only can be called on a start element");
    }
    final FilterAxis textFilterAxis = new FilterAxis(new DescendantAxis(rtx), new TextFilter(rtx));
    final StringBuilder strBuilder = new StringBuilder();
    while (textFilterAxis.hasNext()) {
        textFilterAxis.next();
        strBuilder.append(mAxis.getTransaction().getValue());
    }
    rtx.moveTo(nodeKey);
    return XMLToken.escapeContent(strBuilder.toString());
}
Also used : TextFilter(org.sirix.axis.filter.TextFilter) NodeReadTrx(org.sirix.api.NodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) DescendantAxis(org.sirix.axis.DescendantAxis) FilterAxis(org.sirix.axis.filter.FilterAxis)

Example 5 with TextFilter

use of org.sirix.axis.filter.TextFilter in project sirix by sirixdb.

the class NodeWrapper method expandString.

/**
 * Filter text nodes.
 *
 * @return concatenated String of text node values
 */
private String expandString() {
    final FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.SMALL);
    try {
        final NodeReadTrx rtx = createRtxAndMove();
        final FilterAxis axis = new FilterAxis(new DescendantAxis(rtx), new TextFilter(rtx));
        while (axis.hasNext()) {
            axis.next();
            fsb.append(rtx.getValue());
        }
        rtx.close();
    } catch (final SirixException exc) {
        LOGGER.error(exc.toString());
    }
    return fsb.condense().toString();
}
Also used : TextFilter(org.sirix.axis.filter.TextFilter) FastStringBuffer(net.sf.saxon.tree.util.FastStringBuffer) NodeReadTrx(org.sirix.api.NodeReadTrx) SirixException(org.sirix.exception.SirixException) DescendantAxis(org.sirix.axis.DescendantAxis) FilterAxis(org.sirix.axis.filter.FilterAxis)

Aggregations

TextFilter (org.sirix.axis.filter.TextFilter)5 FilterAxis (org.sirix.axis.filter.FilterAxis)4 DescendantAxis (org.sirix.axis.DescendantAxis)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 Test (org.junit.Test)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)2 NameFilter (org.sirix.axis.filter.NameFilter)2 FastStringBuffer (net.sf.saxon.tree.util.FastStringBuffer)1 Axis (org.sirix.api.Axis)1 AttributeFilter (org.sirix.axis.filter.AttributeFilter)1 ElementFilter (org.sirix.axis.filter.ElementFilter)1 FilterTest (org.sirix.axis.filter.FilterTest)1 ItemFilter (org.sirix.axis.filter.ItemFilter)1 NestedFilter (org.sirix.axis.filter.NestedFilter)1 NodeFilter (org.sirix.axis.filter.NodeFilter)1 SirixException (org.sirix.exception.SirixException)1