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);
}
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 });
}
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());
}
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());
}
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();
}
Aggregations