Search in sources :

Example 1 with NestedFilter

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

the class XPathParser method parseAttributeTest.

/**
 * Parses the the rule AttributeTest according to the following production rule:
 * <p>
 * [59] AttributeTest ::= <"attribute" "("> (AttribNameOrWildcard ("," TypeName)?)? ")" .
 * </p>
 *
 * @return filter
 */
private Filter parseAttributeTest() {
    consume("attribute", true);
    consume(TokenType.OPEN_BR, true);
    Filter filter = new AttributeFilter(getTransaction());
    if (!(mToken.getType() == TokenType.CLOSE_BR)) {
        // add name filter
        final String name = parseAttributeNameOrWildcard();
        if (!name.equals("*")) {
            filter = new NestedFilter(getTransaction(), filter, new NameFilter(getTransaction(), name));
        }
        if (is(TokenType.COMMA, true)) {
            // add type filter
            filter = new NestedFilter(getTransaction(), filter, new TypeFilter(getTransaction(), parseTypeName()));
        }
    }
    consume(TokenType.CLOSE_BR, true);
    return filter;
}
Also used : NestedFilter(org.sirix.axis.filter.NestedFilter) NameFilter(org.sirix.axis.filter.NameFilter) ItemFilter(org.sirix.axis.filter.ItemFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) NameFilter(org.sirix.axis.filter.NameFilter) TypeFilter(org.sirix.axis.filter.TypeFilter) NestedFilter(org.sirix.axis.filter.NestedFilter) DocumentRootNodeFilter(org.sirix.axis.filter.DocumentRootNodeFilter) CommentFilter(org.sirix.axis.filter.CommentFilter) WildcardFilter(org.sirix.axis.filter.WildcardFilter) PIFilter(org.sirix.axis.filter.PIFilter) SchemaElementFilter(org.sirix.service.xml.xpath.filter.SchemaElementFilter) Filter(org.sirix.api.Filter) SchemaAttributeFilter(org.sirix.service.xml.xpath.filter.SchemaAttributeFilter) TextFilter(org.sirix.axis.filter.TextFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) NodeFilter(org.sirix.axis.filter.NodeFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) SchemaAttributeFilter(org.sirix.service.xml.xpath.filter.SchemaAttributeFilter) TypeFilter(org.sirix.axis.filter.TypeFilter)

Example 2 with NestedFilter

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

the class XPathParser method parsePITest.

/**
 * Parses the the rule PITest according to the following production rule:
 * <p>
 * [58] PITest ::= <"processing-instruction" "("> (NCName | StringLiteral)? ")" .
 * </p>
 *
 * @return filter
 */
private Filter parsePITest() {
    consume("processing-instruction", true);
    consume(TokenType.OPEN_BR, true);
    Filter filter = new PIFilter(getTransaction());
    if (!is(TokenType.CLOSE_BR, true)) {
        String stringLiteral;
        if (isQuote()) {
            final byte[] param = ((ValueNode) getTransaction().getItemList().getItem(parseStringLiteral()).get()).getRawValue();
            stringLiteral = Arrays.toString(param);
        } else {
            stringLiteral = parseNCName();
        }
        consume(TokenType.CLOSE_BR, true);
        filter = new NestedFilter(getTransaction(), filter, new NameFilter(getTransaction(), stringLiteral));
    }
    return filter;
}
Also used : NestedFilter(org.sirix.axis.filter.NestedFilter) NameFilter(org.sirix.axis.filter.NameFilter) PIFilter(org.sirix.axis.filter.PIFilter) ItemFilter(org.sirix.axis.filter.ItemFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) NameFilter(org.sirix.axis.filter.NameFilter) TypeFilter(org.sirix.axis.filter.TypeFilter) NestedFilter(org.sirix.axis.filter.NestedFilter) DocumentRootNodeFilter(org.sirix.axis.filter.DocumentRootNodeFilter) CommentFilter(org.sirix.axis.filter.CommentFilter) WildcardFilter(org.sirix.axis.filter.WildcardFilter) PIFilter(org.sirix.axis.filter.PIFilter) SchemaElementFilter(org.sirix.service.xml.xpath.filter.SchemaElementFilter) Filter(org.sirix.api.Filter) SchemaAttributeFilter(org.sirix.service.xml.xpath.filter.SchemaAttributeFilter) TextFilter(org.sirix.axis.filter.TextFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) NodeFilter(org.sirix.axis.filter.NodeFilter) ValueNode(org.sirix.node.interfaces.ValueNode)

Example 3 with NestedFilter

use of org.sirix.axis.filter.NestedFilter 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 4 with NestedFilter

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

the class XPathParser method parseElementTest.

// /**
// * Parses the the rule AttributeDeclaration according to the following
// * production rule:
// * <p>
// * [62] AttributeDeclaration ::= AttributeName .
// * </p>
// */
// private String parseAttributeDeclaration() {
// 
// return parseAttributeName();
// }
/**
 * Parses the the rule ElementTest according to the following production rule:
 * <p>
 * [63] ElementTest ::= <"element" "("> (ElementNameOrWildcard ("," TypeName "?"?)?)? ")" .
 * </p>
 *
 * @return filter
 */
private Filter parseElementTest() {
    consume("element", true);
    consume(TokenType.OPEN_BR, true);
    Filter filter = new ElementFilter(getTransaction());
    if (!(mToken.getType() == TokenType.CLOSE_BR)) {
        final String mName = parseElementNameOrWildcard();
        if (!mName.equals("*")) {
            filter = new NestedFilter(getTransaction(), filter, new NameFilter(getTransaction(), mName));
        }
        if (is(TokenType.COMMA, true)) {
            filter = new NestedFilter(getTransaction(), filter, new TypeFilter(getTransaction(), parseTypeName()));
            if (is(TokenType.INTERROGATION, true)) {
                // be false
                throw new NoSuchElementException("'?' is not supported yet.");
            }
        }
    }
    consume(TokenType.CLOSE_BR, true);
    return filter;
}
Also used : NestedFilter(org.sirix.axis.filter.NestedFilter) NameFilter(org.sirix.axis.filter.NameFilter) ItemFilter(org.sirix.axis.filter.ItemFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) NameFilter(org.sirix.axis.filter.NameFilter) TypeFilter(org.sirix.axis.filter.TypeFilter) NestedFilter(org.sirix.axis.filter.NestedFilter) DocumentRootNodeFilter(org.sirix.axis.filter.DocumentRootNodeFilter) CommentFilter(org.sirix.axis.filter.CommentFilter) WildcardFilter(org.sirix.axis.filter.WildcardFilter) PIFilter(org.sirix.axis.filter.PIFilter) SchemaElementFilter(org.sirix.service.xml.xpath.filter.SchemaElementFilter) Filter(org.sirix.api.Filter) SchemaAttributeFilter(org.sirix.service.xml.xpath.filter.SchemaAttributeFilter) TextFilter(org.sirix.axis.filter.TextFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) NodeFilter(org.sirix.axis.filter.NodeFilter) SchemaElementFilter(org.sirix.service.xml.xpath.filter.SchemaElementFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) TypeFilter(org.sirix.axis.filter.TypeFilter) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with NestedFilter

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

the class XPathParser method parseDocumentTest.

/**
 * Parses the the rule DocumentCreater according to the following production rule:
 * <p>
 * [55] DocumentCreater ::= <"document-node" "("> (ElementTest | SchemaElementTest)? ")" .
 * <p>
 *
 * @return filter
 */
private Filter parseDocumentTest() {
    consume("document-node", true);
    consume(TokenType.OPEN_BR, true);
    Filter filter = new DocumentRootNodeFilter(getTransaction());
    Filter innerFilter;
    if (mToken.getContent().equals("element")) {
        innerFilter = parseElementTest();
        filter = new NestedFilter(getTransaction(), filter, innerFilter);
    } else if (mToken.getContent().equals("schema-element")) {
        innerFilter = parseSchemaElementTest();
        filter = new NestedFilter(getTransaction(), filter, innerFilter);
    }
    consume(TokenType.CLOSE_BR, true);
    return filter;
}
Also used : NestedFilter(org.sirix.axis.filter.NestedFilter) ItemFilter(org.sirix.axis.filter.ItemFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) NameFilter(org.sirix.axis.filter.NameFilter) TypeFilter(org.sirix.axis.filter.TypeFilter) NestedFilter(org.sirix.axis.filter.NestedFilter) DocumentRootNodeFilter(org.sirix.axis.filter.DocumentRootNodeFilter) CommentFilter(org.sirix.axis.filter.CommentFilter) WildcardFilter(org.sirix.axis.filter.WildcardFilter) PIFilter(org.sirix.axis.filter.PIFilter) SchemaElementFilter(org.sirix.service.xml.xpath.filter.SchemaElementFilter) Filter(org.sirix.api.Filter) SchemaAttributeFilter(org.sirix.service.xml.xpath.filter.SchemaAttributeFilter) TextFilter(org.sirix.axis.filter.TextFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) NodeFilter(org.sirix.axis.filter.NodeFilter) DocumentRootNodeFilter(org.sirix.axis.filter.DocumentRootNodeFilter)

Aggregations

AttributeFilter (org.sirix.axis.filter.AttributeFilter)5 ElementFilter (org.sirix.axis.filter.ElementFilter)5 ItemFilter (org.sirix.axis.filter.ItemFilter)5 NameFilter (org.sirix.axis.filter.NameFilter)5 NestedFilter (org.sirix.axis.filter.NestedFilter)5 NodeFilter (org.sirix.axis.filter.NodeFilter)5 TextFilter (org.sirix.axis.filter.TextFilter)5 Filter (org.sirix.api.Filter)4 CommentFilter (org.sirix.axis.filter.CommentFilter)4 DocumentRootNodeFilter (org.sirix.axis.filter.DocumentRootNodeFilter)4 PIFilter (org.sirix.axis.filter.PIFilter)4 TypeFilter (org.sirix.axis.filter.TypeFilter)4 WildcardFilter (org.sirix.axis.filter.WildcardFilter)4 SchemaAttributeFilter (org.sirix.service.xml.xpath.filter.SchemaAttributeFilter)4 SchemaElementFilter (org.sirix.service.xml.xpath.filter.SchemaElementFilter)4 NoSuchElementException (java.util.NoSuchElementException)1 Test (org.junit.Test)1 FilterTest (org.sirix.axis.filter.FilterTest)1 ValueNode (org.sirix.node.interfaces.ValueNode)1