Package org.apache.directory.shared.ldap.model.filter

Examples of org.apache.directory.shared.ldap.model.filter.SubstringNode


        // SUBSTRING FILTER
        else if ( filter instanceof SubstringNode)
        {
            Element newElement = element.addElement( "substrings" );

            SubstringNode substringFilter = ( SubstringNode ) filter;

            newElement.addAttribute( "name", substringFilter.getAttribute() );

            String initial = substringFilter.getInitial();

            if ( ( initial != null ) && ( !"".equals( initial ) ) )
            {
                newElement.addElement( "initial" ).setText( initial );
            }

            List<String> anyList = substringFilter.getAny();

            for ( int i = 0; i < anyList.size(); i++ )
            {
                newElement.addElement( "any" ).setText( anyList.get( i ) );
            }

            String finalString = substringFilter.getFinal();

            if ( ( finalString != null ) && ( !"".equals( finalString ) ) )
            {
                newElement.addElement( "final" ).setText( finalString );
            }
View Full Code Here


     * {@inheritDoc}
     */
    public boolean evaluate( ExprNode node, Dn dn, Entry entry ) throws LdapException
    {
        Pattern regex = null;
        SubstringNode snode = ( SubstringNode ) node;
        AttributeType attributeType = snode.getAttributeType();
        MatchingRule matchingRule = attributeType.getSubstring();

        if ( matchingRule == null )
        {
            matchingRule = attributeType.getEquality();
        }

        Normalizer normalizer = matchingRule.getNormalizer();

        // get the attribute
        Attribute attr = entry.get( snode.getAttribute() );

        // if the attribute does not exist just return false
        if ( null == attr )
        {
            return false;
        }

        // compile the regular expression to search for a matching attribute
        try
        {
            regex = snode.getRegex( normalizer );
        }
        catch ( PatternSyntaxException pse )
        {
            LdapInvalidSearchFilterException ne = new LdapInvalidSearchFilterException( I18n.err( I18n.ERR_248, node ) );
            ne.initCause( pse );
View Full Code Here


    @Test
    public void testIndexedCnStartsWithJ() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "cn" ), "j", null );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        SubstringCursor cursor = new SubstringCursor( store, evaluator );

        assertEquals( node, evaluator.getExpression() );
View Full Code Here


    @Test
    public void testIndexedCnStartsWithJim() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "cn" ), "jim", null );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        SubstringCursor cursor = new SubstringCursor( store, evaluator );

        assertEquals( node, evaluator.getExpression() );
View Full Code Here


    @Test
    public void testIndexedCnEndsWithBean() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "cn" ), null, "bean" );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        SubstringCursor cursor = new SubstringCursor( store, evaluator );

        assertEquals( node, evaluator.getExpression() );
View Full Code Here


    @Test
    public void testNonIndexedSnStartsWithB() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "sn" ), "b", null );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        SubstringCursor cursor = new SubstringCursor( store, evaluator );

        assertEquals( node, evaluator.getExpression() );
View Full Code Here


    @Test
    public void testIndexedSnEndsWithEr() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "sn" ), null, "er" );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        SubstringCursor cursor = new SubstringCursor( store, evaluator );

        assertEquals( node, evaluator.getExpression() );
View Full Code Here


    @Test
    public void testNonIndexedAttributes() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "sn" ), "walk", null );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        IndexEntry<String, String> indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 5L ) );
        assertTrue( evaluator.evaluate( indexEntry ) );
        indexEntry.setId( Strings.getUUID( 3L ) );
        indexEntry.setEntry( null );
        assertFalse( evaluator.evaluate( indexEntry ) );
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( null );
        assertFalse( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "sn" ), "wa", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 5L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 5L ) ) );
        assertTrue( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "searchGuide" ), "j", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 6L ) ) );
        assertFalse( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "st" ), "j", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 6L ) ) );
        assertFalse( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "name" ), "j", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 6L ) ) );
        assertTrue( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "name" ), "s", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 6L ) ) );
        assertTrue( evaluator.evaluate( indexEntry ) );
View Full Code Here


    @Test
    public void testEvaluatorIndexed() throws Exception
    {
        SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "cn" ), "jim", null );
        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
        IndexEntry<String, String> indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        assertTrue( evaluator.evaluate( indexEntry ) );
        indexEntry.setId( Strings.getUUID( 3L ) );
        indexEntry.setEntry( null );
        assertFalse( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "cn" ), "j", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 6L ) ) );
        assertTrue( evaluator.evaluate( indexEntry ) );

        node = new SubstringNode( schemaManager.getAttributeType( "cn" ), "s", null );
        evaluator = new SubstringEvaluator( node, store, schemaManager );
        indexEntry = new IndexEntry<String, String>();
        indexEntry.setId( Strings.getUUID( 6L ) );
        indexEntry.setEntry( store.lookup( Strings.getUUID( 6L ) ) );
        assertFalse( evaluator.evaluate( indexEntry ) );
View Full Code Here

    {
        SubstringCursor cursor = null;

        try
        {
            SubstringNode node = new SubstringNode( schemaManager.getAttributeType( "sn" ), "b", null );
            SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
            cursor = new SubstringCursor( store, evaluator );
            cursor.get();
        }
        finally
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.filter.SubstringNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.