Package org.apache.directory.studio.ldapbrowser.core.model

Examples of org.apache.directory.studio.ldapbrowser.core.model.SearchParameter


    }


    private static SearchParameter getSearchParameter( ISearch search )
    {
        SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();

        // add children detetion attributes
        if ( search.isInitHasChildrenFlag() )
        {
            if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
                SchemaConstants.HAS_SUBORDINATES_AT )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    SchemaConstants.HAS_SUBORDINATES_AT ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = SchemaConstants.HAS_SUBORDINATES_AT;
                searchParameter.setReturningAttributes( returningAttributes );
            }
            else if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
                SchemaConstants.NUM_SUBORDINATES_AT )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    SchemaConstants.NUM_SUBORDINATES_AT ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = SchemaConstants.NUM_SUBORDINATES_AT;
                searchParameter.setReturningAttributes( returningAttributes );
            }
            else if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
                SchemaConstants.SUBORDINATE_COUNT_AT )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    SchemaConstants.SUBORDINATE_COUNT_AT ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = SchemaConstants.SUBORDINATE_COUNT_AT;
                searchParameter.setReturningAttributes( returningAttributes );
            }
        }

        // always add the objectClass attribute, we need it 
        // - to detect alias and referral entries
        // - to determine the entry's icon
        // - to determine must and may attributes
        if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
            SchemaConstants.OBJECT_CLASS_AT )
            && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                SchemaConstants.ALL_USER_ATTRIBUTES ) )
        {
            String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
            System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                .getReturningAttributes().length );
            returningAttributes[returningAttributes.length - 1] = SchemaConstants.OBJECT_CLASS_AT;
            searchParameter.setReturningAttributes( returningAttributes );
        }

        // filter controls if not supported by server
        if ( searchParameter.getControls() != null )
        {
            IBrowserConnection connection = search.getBrowserConnection();
            Set<String> supportedConrolSet = new HashSet<String>();
            if ( connection.getRootDSE() != null
                && connection.getRootDSE().getAttribute( SchemaConstants.SUPPORTED_CONTROL_AT ) != null )
            {
                IAttribute scAttribute = connection.getRootDSE().getAttribute( SchemaConstants.SUPPORTED_CONTROL_AT );
                String[] supportedControls = scAttribute.getStringValues();
                for ( int i = 0; i < supportedControls.length; i++ )
                {
                    supportedConrolSet.add( supportedControls[i].toLowerCase() );
                }
            }

            List<StudioControl> controls = searchParameter.getControls();
            for ( Iterator<StudioControl> it = controls.iterator(); it.hasNext(); )
            {
                StudioControl control = it.next();
                if ( !supportedConrolSet.contains( control.getOid().toLowerCase() ) )
                {
View Full Code Here


        if ( browserConnection != null )
        {
            ISearch clone = null;
            for ( ISearch search : searches )
            {
                SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();
                clone = new Search( browserConnection, searchParameter );
                browserConnection.getSearchManager().addSearch( clone );
            }

            if ( searches.length == 1 )
View Full Code Here

                if ( searchesElement != null )
                {
                    for ( Iterator<?> i = searchesElement.elementIterator( SEARCH_PARAMETER_TAG ); i.hasNext(); )
                    {
                        Element searchParameterElement = ( Element ) i.next();
                        SearchParameter searchParameter = readSearch( searchParameterElement, browserConnection );
                        ISearch search = new Search( browserConnection, searchParameter );
                        browserConnection.getSearchManager().addSearch( search );
                    }
                }
View Full Code Here


    private static SearchParameter readSearch( Element searchParameterElement, IBrowserConnection browserConnection )
        throws ConnectionIOException
    {
        SearchParameter searchParameter = new SearchParameter();

        // Name
        Attribute nameAttribute = searchParameterElement.attribute( NAME_TAG );
        if ( nameAttribute != null )
        {
            searchParameter.setName( nameAttribute.getValue() );
        }

        // Search base
        Attribute searchBaseAttribute = searchParameterElement.attribute( SEARCH_BASE_TAG );
        if ( searchBaseAttribute != null )
        {
            try
            {
                searchParameter.setSearchBase( new LdapDN( searchBaseAttribute.getValue() ) );
            }
            catch ( InvalidNameException e )
            {
                throw new ConnectionIOException( "Unable to parse 'Search Base' of search '"
                    + searchParameter.getName() + "' :" + searchBaseAttribute.getValue() );
            }
        }

        // Filter
        Attribute filterAttribute = searchParameterElement.attribute( FILTER_TAG );
        if ( filterAttribute != null )
        {
            searchParameter.setFilter( filterAttribute.getValue() );
        }

        // Returning Attributes
        Element returningAttributesElement = searchParameterElement.element( RETURNING_ATTRIBUTES_TAG );
        if ( returningAttributesElement != null )
        {
            List<String> returningAttributes = new ArrayList<String>();
            for ( Iterator<?> i = returningAttributesElement.elementIterator( RETURNING_ATTRIBUTE_TAG ); i.hasNext(); )
            {
                Element returningAttributeElement = ( Element ) i.next();

                Attribute valueAttribute = returningAttributeElement.attribute( VALUE_TAG );
                if ( valueAttribute != null )
                {
                    returningAttributes.add( valueAttribute.getValue() );
                }
            }
            searchParameter.setReturningAttributes( returningAttributes
                .toArray( new String[returningAttributes.size()] ) );
        }

        // Scope
        Attribute scopeAttribute = searchParameterElement.attribute( SCOPE_TAG );
        if ( scopeAttribute != null )
        {
            try
            {
                searchParameter.setScope( SearchScope.valueOf( scopeAttribute.getValue() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new ConnectionIOException( "Unable to parse 'Scope' of search '" + searchParameter.getName()
                    + "' as int value. Scope value :" + scopeAttribute.getValue() );
            }
        }

        // Time limit
        Attribute timeLimitAttribute = searchParameterElement.attribute( TIME_LIMIT_TAG );
        if ( timeLimitAttribute != null )
        {
            try
            {
                searchParameter.setTimeLimit( Integer.parseInt( timeLimitAttribute.getValue() ) );
            }
            catch ( NumberFormatException e )
            {
                throw new ConnectionIOException( "Unable to parse 'Time limit' of search '" + searchParameter.getName()
                    + "' as int value. Time limit value :" + timeLimitAttribute.getValue() );
            }
        }

        // Count limit
        Attribute countLimitAttribute = searchParameterElement.attribute( COUNT_LIMIT_TAG );
        if ( countLimitAttribute != null )
        {
            try
            {
                searchParameter.setCountLimit( Integer.parseInt( countLimitAttribute.getValue() ) );
            }
            catch ( NumberFormatException e )
            {
                throw new ConnectionIOException( "Unable to parse 'Count limit' of search '"
                    + searchParameter.getName() + "' as int value. Count limit value :"
                    + countLimitAttribute.getValue() );
            }
        }

        // Alias dereferencing method
        Attribute aliasesDereferencingMethodAttribute = searchParameterElement
            .attribute( ALIASES_DEREFERENCING_METHOD_TAG );
        if ( aliasesDereferencingMethodAttribute != null )
        {
            try
            {
                searchParameter.setAliasesDereferencingMethod( Connection.AliasDereferencingMethod
                    .valueOf( aliasesDereferencingMethodAttribute.getValue() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new ConnectionIOException( "Unable to parse 'Aliases Dereferencing Method' of search '"
                    + searchParameter.getName() + "' as int value. Aliases Dereferencing Method value :"
                    + aliasesDereferencingMethodAttribute.getValue() );
            }
        }

        // Referrals handling method
        Attribute referralsHandlingMethodAttribute = searchParameterElement.attribute( REFERRALS_HANDLING_METHOD_TAG );
        if ( referralsHandlingMethodAttribute != null )
        {
            try
            {
                searchParameter.setReferralsHandlingMethod( Connection.ReferralHandlingMethod
                    .valueOf( referralsHandlingMethodAttribute.getValue() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new ConnectionIOException( "Unable to parse 'Referrals Handling Method' of search '"
                    + searchParameter.getName() + "' as int value. Referrals Handling Method value :"
                    + referralsHandlingMethodAttribute.getValue() );
            }
        }

        // Controls
        Element controlsElement = searchParameterElement.element( CONTROLS_TAG );
        if ( controlsElement != null )
        {
            for ( Iterator<?> i = controlsElement.elementIterator( CONTROL_TAG ); i.hasNext(); )
            {
                Element controlElement = ( Element ) i.next();

                Attribute valueAttribute = controlElement.attribute( VALUE_TAG );
                if ( valueAttribute != null )
                {
                    byte[] bytes = Base64.decode( valueAttribute.getValue().toCharArray() );
                    ByteArrayInputStream bais = null;
                    ObjectInputStream ois = null;
                    try
                    {
                        bais = new ByteArrayInputStream( bytes );
                        ois = new ObjectInputStream( bais );
                        StudioControl control = ( StudioControl ) ois.readObject();
                        searchParameter.getControls().add( control );
                        ois.close();
                    }
                    catch ( Exception e )
                    {
                        throw new ConnectionIOException( "Unable to parse 'Control' of search '"
                            + searchParameter.getName() + "'. Control value :" + valueAttribute.getValue() );
                    }
                }
            }
        }
View Full Code Here

                    ReloadSchemasJob.reloadSchema( browserConnection, monitor );
                }
                else if ( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
                {
                    // check if schema is up-to-date
                    SearchParameter sp = new SearchParameter();
                    sp.setSearchBase( new LdapDN( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
                        .getStringValue() ) );
                    sp.setFilter( Schema.SCHEMA_FILTER );
                    sp.setScope( SearchScope.OBJECT );
                    sp.setReturningAttributes( new String[]
                        { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
                            IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
                    ISearch search = new Search( browserConnection, sp );

                    SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
View Full Code Here

    {
        this.connection = conn;
        this.searchResults = null;
        this.countLimitExceeded = false;

        this.searchParameter = new SearchParameter();
        this.searchParameter.setName( searchName );
        this.searchParameter.setSearchBase( searchBase );
        this.searchParameter.setFilter( filter );
        this.searchParameter.setReturningAttributes( returningAttributes );
        this.searchParameter.setScope( scope );
View Full Code Here

        try
        {
            if ( !monitor.isCanceled() )
            {
                // add returning attributes for children and alias detection
                SearchParameter searchParameter = getSearchParameter( search );
                ArrayList<ISearchResult> searchResultList = new ArrayList<ISearchResult>();

                try
                {
                    // search
View Full Code Here

    }


    private static SearchParameter getSearchParameter( ISearch search )
    {
        SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();

        // add children detetion attributes
        if ( search.isInitHasChildrenFlag() )
        {
            if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
                IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES;
                searchParameter.setReturningAttributes( returningAttributes );
            }
            else if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
                IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES;
                searchParameter.setReturningAttributes( returningAttributes );
            }
            else if ( search.getBrowserConnection().getSchema().hasAttributeTypeDescription(
                IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT )
                && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                    IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT ) )
            {
                String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
                System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                    .getReturningAttributes().length );
                returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT;
                searchParameter.setReturningAttributes( returningAttributes );
            }
        }

        // always add the objectClass attribute, we need it 
        // - to detect alias and referral entries
        // - to determine the entry's icon
        // - to determine must and may attributes
        if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
            IAttribute.OBJECTCLASS_ATTRIBUTE )
            && !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
                ISearch.ALL_USER_ATTRIBUTES ) )
        {
            String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
            System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
                .getReturningAttributes().length );
            returningAttributes[returningAttributes.length - 1] = IAttribute.OBJECTCLASS_ATTRIBUTE;
            searchParameter.setReturningAttributes( returningAttributes );
        }

        // filter controls if not supported by server
        if ( searchParameter.getControls() != null )
        {
            IBrowserConnection connection = search.getBrowserConnection();
            Set<String> suppportedConrolSet = new HashSet<String>();
            if ( connection.getRootDSE() != null
                && connection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ) != null )
            {
                IAttribute scAttribute = connection.getRootDSE().getAttribute(
                    IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL );
                String[] supportedControls = scAttribute.getStringValues();
                for ( int i = 0; i < supportedControls.length; i++ )
                {
                    suppportedConrolSet.add( supportedControls[i].toLowerCase() );
                }
            }

            org.apache.directory.studio.ldapbrowser.core.model.Control[] controls = searchParameter.getControls();
            List<org.apache.directory.studio.ldapbrowser.core.model.Control> controlList = new ArrayList<org.apache.directory.studio.ldapbrowser.core.model.Control>();
            for ( int i = 0; i < controls.length; i++ )
            {
                if ( suppportedConrolSet.contains( controls[i].getOid().toLowerCase() ) )
                {
                    controlList.add( controls[i] );
                }
            }
            searchParameter.setControls( controlList
                .toArray( new org.apache.directory.studio.ldapbrowser.core.model.Control[controlList.size()] ) );
        }

        return searchParameter;
    }
View Full Code Here

    {
        this.connection = conn;
        this.searchResults = null;
        this.countLimitExceeded = false;

        this.searchParameter = new SearchParameter();
        this.searchParameter.setName( searchName );
        this.searchParameter.setSearchBase( searchBase );
        this.searchParameter.setFilter( filter );
        this.searchParameter.setReturningAttributes( returningAttributes );
        this.searchParameter.setScope( scope );
View Full Code Here

                if ( searchesElement != null )
                {
                    for ( Iterator<?> i = searchesElement.elementIterator( SEARCH_PARAMETER_TAG ); i.hasNext(); )
                    {
                        Element searchParameterElement = ( Element ) i.next();
                        SearchParameter searchParameter = readSearch( searchParameterElement, browserConnection );
                        ISearch search = new Search( browserConnection, searchParameter );
                        browserConnection.getSearchManager().addSearch( search );
                    }
                }
               
View Full Code Here

TOP

Related Classes of org.apache.directory.studio.ldapbrowser.core.model.SearchParameter

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.