repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/ISearch.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/ISearch.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model; import java.io.Serializable; import java.util.List; import org.apache.directory.api.ldap.model.constants.LdapConstants; import org.apache.directory.api.ldap.model.message.Control; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionPropertyPageProvider; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.model.impl.SearchContinuation; import org.apache.directory.studio.ldapbrowser.core.propertypageproviders.SearchPropertyPageProvider; import org.eclipse.core.runtime.IAdaptable; /** * An ISearch holds all search parameters and search results of an * LDAP search. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface ISearch extends Serializable, IAdaptable, SearchPropertyPageProvider, ConnectionPropertyPageProvider { /** Constant for empty search base */ Dn EMPTY_SEARCH_BASE = new Dn(); //$NON-NLS-1$ /** Constant for no returning attributes, an empty array */ String[] NO_ATTRIBUTES = new String[0]; /** True filter (objectClass=*) */ String FILTER_TRUE = LdapConstants.OBJECT_CLASS_STAR; /** False filter (!(objectClass=*)) */ String FILTER_FALSE = "(!(objectClass=*))"; //$NON-NLS-1$ /** Filter for fetching subentries (|(objectClass=subentry)(objectClass=ldapSubentry)) */ String FILTER_SUBENTRY = "(|(objectClass=subentry)(objectClass=ldapSubentry))"; //$NON-NLS-1$ /** Filter for fetching aliases (objectClass=alias) */ String FILTER_ALIAS = "(objectClass=alias)"; //$NON-NLS-1$ /** Filter for fetching referrals (objectClass=referral) */ String FILTER_REFERRAL = "(objectClass=referral)"; //$NON-NLS-1$ /** Filter for fetching aliases and referrals (|(objectClass=alias)(objectClass=referral)) */ String FILTER_ALIAS_OR_REFERRAL = "(|(objectClass=alias)(objectClass=referral))"; //$NON-NLS-1$ /** * Gets the LDAP URL of this search. * * @return the LDAP URL of this search */ LdapUrl getUrl(); /** * Checks if the hasChildren flag should be initialized. * * @return true, if the hasChildren flag should be initialized */ boolean isInitHasChildrenFlag(); /** * Gets the controls. * * @return the controls */ List<Control> getControls(); /** * Gets the response controls. * * @return the response controls */ List<Control> getResponseControls(); /** * Gets the count limit, 0 means no limit. * * @return the count limit */ int getCountLimit(); /** * Sets the count limit, 0 means no limit. * * @param countLimit the count limit */ void setCountLimit( int countLimit ); /** * Gets the filter. * * @return the filter */ String getFilter(); /** * Sets the filter, a null or empty filter will be * transformed to (objectClass=*). * * Calling this method causes firing a search update event. * * @param filter the filter */ void setFilter( String filter ); /** * Gets the returning attributes. * * @return the returning attributes */ String[] getReturningAttributes(); /** * Sets the returning attributes, an empty array indicates none, * null will be transformed to '*' (all user attributes). * * Calling this method causes firing a search update event. * * @param returningAttributes the returning attributes */ void setReturningAttributes( String[] returningAttributes ); /** * Gets the search scope. * * @return the search scope */ SearchScope getScope(); /** * Sets the search scope. * * Calling this method causes firing a search update event. * * @param scope the search scope */ void setScope( SearchScope scope ); /** * Gets the aliases dereferencing method. * * * @return the aliases dereferencing method */ Connection.AliasDereferencingMethod getAliasesDereferencingMethod(); /** * Sets the aliases dereferencing method. * * Calling this method causes firing a search update event. * * @param aliasesDereferencingMethod the aliases dereferencing method */ void setAliasesDereferencingMethod( Connection.AliasDereferencingMethod aliasesDereferencingMethod ); /** * Gets the referrals handling method. * * @return the referrals handling method */ Connection.ReferralHandlingMethod getReferralsHandlingMethod(); /** * Sets the referrals handling method. * * Calling this method causes firing a search update event. * * @param referralsHandlingMethod the referrals handling method */ void setReferralsHandlingMethod( Connection.ReferralHandlingMethod referralsHandlingMethod ); /** * Gets the search base. * * @return the search base */ Dn getSearchBase(); /** * Sets the search base, a null search base will be * transformed to an empty Dn. * * Calling this method causes firing a search update event. * * @param searchBase the search base */ void setSearchBase( Dn searchBase ); /** * Gets the time limit in seconds, 0 means no limit. * * @return the time limit */ int getTimeLimit(); /** * Sets the time limit in seconds, 0 means no limit. * * Calling this method causes firing a search update event. * * @param timeLimit the time limit */ void setTimeLimit( int timeLimit ); /** * Gets the symbolic name. * * @return the name */ String getName(); /** * Sets the symbolic name. * * Calling this method causes firing a search update event. * * @param name the name */ void setName( String name ); /** * Gets the search results, null indicates that the * search wasn't performed yet. * * @return the search results */ ISearchResult[] getSearchResults(); /** * Sets the search results. * * Calling this method causes firing a search update event. * * @param searchResults the search results */ void setSearchResults( ISearchResult[] searchResults ); /** * Checks if the count limit exceeded. * * @return true, if the count limit exceeded */ boolean isCountLimitExceeded(); /** * Sets the count limit exceeded flag. * * Calling this method causes firing a search update event. * * @param countLimitExceeded the count limit exceeded flag */ void setCountLimitExceeded( boolean countLimitExceeded ); /** * Gets the browser connection. * * @return the browser connection */ IBrowserConnection getBrowserConnection(); /** * Sets the browser connection. * * Calling this method causes firing a search update event. * * @param browserConnection the browser connection */ void setBrowserConnection( IBrowserConnection browserConnection ); /** * Clones this search. * * @return the cloned search */ ISearch clone(); /** * Gets the search parameter. * * @return the search parameter */ SearchParameter getSearchParameter(); /** * Sets the search parameter. * * @param searchParameter the search parameter */ void setSearchParameter( SearchParameter searchParameter ); /** * Gets the paged search scroll mode flag. * * @return the paged search scroll mode flag */ boolean isPagedSearchScrollMode(); /** * Sets the paged search scroll mode flag. * * @param isPagedSearchScrollMode paged search scroll mode flag */ void setPagedSearchScrollMode( boolean isPagedSearchScrollMode ); /** * Gets the next search runnable. * * @return the next search runnable, null if none */ StudioConnectionBulkRunnableWithProgress getNextSearchRunnable(); /** * Sets the next search runnable. * * @param nextSearchRunnable the next search runnable */ void setNextPageSearchRunnable( StudioConnectionBulkRunnableWithProgress nextSearchRunnable ); /** * Gets the top search runnable. * * @return the top search runnable, null if none */ StudioConnectionBulkRunnableWithProgress getTopSearchRunnable(); /** * Sets the top search runnable. * * @param nextSearchRunnable the top search runnable */ void setTopPageSearchRunnable( StudioConnectionBulkRunnableWithProgress nextSearchRunnable ); /** * Gets the search continuations. * * @return the search continuations */ SearchContinuation[] getSearchContinuations(); /** * Sets the search continuations * * @param the search continuations */ void setSearchContinuations( SearchContinuation[] searchContinuations ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapAndFilterComponent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapAndFilterComponent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapAndFilterComponent represents an AND filter branch. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapAndFilterComponent extends LdapFilterComponent { /** * Creates a new instance of LdapAndFilterComponent. * * @param parent the parent filter */ public LdapAndFilterComponent( LdapFilter parent ) { super( parent ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#setStartToken(org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken) */ public boolean setStartToken( LdapFilterToken andToken ) { if ( andToken != null && andToken.getType() == LdapFilterToken.AND ) { return super.setStartToken( andToken ); } else { return false; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidCause() */ public String getInvalidCause() { if ( startToken == null ) { return Messages.LdapAndFilterComponent_MissingAndCharacter; } else if ( filterList.isEmpty() ) { return Messages.LdapAndFilterComponent_MissingFilters; } else { return Messages.LdapAndFilterComponent_InvalidAndFilter; } } /** * @see java.lang.Object#toString() */ public String toString() { String s = startToken != null ? "&" : ""; //$NON-NLS-1$ //$NON-NLS-2$ for ( LdapFilter filter : filterList ) { if ( filter != null ) { s += filter.toString(); } } return s; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapNotFilterComponent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapNotFilterComponent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapNotFilterComponent represents an NOT filter branch. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapNotFilterComponent extends LdapFilterComponent { /** * Creates a new instance of LdapNotFilterComponent. * * @param parent the parent filter */ public LdapNotFilterComponent( LdapFilter parent ) { super( parent ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#setStartToken(org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken) */ public boolean setStartToken( LdapFilterToken notToken ) { if ( notToken != null && notToken.getType() == LdapFilterToken.NOT ) { return super.setStartToken( notToken ); } else { return false; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#addFilter(org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter) */ public boolean addFilter( LdapFilter filter ) { if ( filterList.isEmpty() ) { return super.addFilter( filter ); } else { // There is already a filter in the list. A NOT filter // can only contain one filter. return false; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidCause() */ public String getInvalidCause() { if ( startToken == null ) { return Messages.LdapNotFilterComponent_MissingNotCharacter; } else if ( filterList.isEmpty() ) { return Messages.LdapNotFilterComponent_MissingFilterExpression; } else { return Messages.LdapNotFilterComponent_InvalidNotFilter; } } /** * @see java.lang.Object#toString() */ public String toString() { return ( startToken != null ? "!" : "" ) + ( !filterList.isEmpty() ? filterList.get( 0 ).toString() : "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapOrFilterComponent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapOrFilterComponent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapOrFilterComponent represents an OR filter branch. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapOrFilterComponent extends LdapFilterComponent { /** * Creates a new instance of LdapOrFilterComponent. * * @param parent the parent filter */ public LdapOrFilterComponent( LdapFilter parent ) { super( parent ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#setStartToken(org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken) */ public boolean setStartToken( LdapFilterToken orToken ) { if ( orToken != null && orToken.getType() == LdapFilterToken.OR ) { return super.setStartToken( orToken ); } else { return false; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidCause() */ public String getInvalidCause() { if ( startToken == null ) { return Messages.LdapOrFilterComponent_MissingOrCharacter; } else if ( filterList.isEmpty() ) { return Messages.LdapOrFilterComponent_MissingFilters; } else { return Messages.LdapOrFilterComponent_InvalidOrFilter; } } /** * @see java.lang.Object#toString() */ public String toString() { String s = startToken != null ? "|" : ""; //$NON-NLS-1$ //$NON-NLS-2$ for ( LdapFilter filter : filterList ) { if ( filter != null ) { s += filter.toString(); } } return s; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterExtensibleComponent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterExtensibleComponent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapFilterExtensibleComponent represents an extensible filter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilterExtensibleComponent extends LdapFilterComponent { private LdapFilterToken attributeToken; private LdapFilterToken dnAttrColonToken; private LdapFilterToken dnAttrToken; private LdapFilterToken matchingRuleColonToken; private LdapFilterToken matchingRuleToken; private LdapFilterToken equalsColonToken; private LdapFilterToken equalsToken; private LdapFilterToken valueToken; /** * Creates a new instance of LdapFilterExtensibleComponent. * * @param parent the parent filter */ public LdapFilterExtensibleComponent( LdapFilter parent ) { super( parent ); } /** * Sets the attribute token. * * @param attributeToken the attribute token * * @return true, if setting the attribute token was successful,false otherwise. */ public boolean setAttributeToken( LdapFilterToken attributeToken ) { if ( this.attributeToken == null && attributeToken != null && attributeToken.getType() == LdapFilterToken.EXTENSIBLE_ATTRIBUTE ) { if ( super.getStartToken() == null ) { super.setStartToken( attributeToken ); } this.attributeToken = attributeToken; return true; } else { return false; } } /** * Gets the attribute token. * * @return the attribute token, or null if not set */ public LdapFilterToken getAttributeToken() { return attributeToken; } /** * Sets the dn attr colon token. * * @param dnAttrColonToken the dn attr colon token * * @return true, if setting the dn attr colon token was sucessful, false otherwise */ public boolean setDnAttrColonToken( LdapFilterToken dnAttrColonToken ) { if ( this.dnAttrColonToken == null && dnAttrColonToken != null && dnAttrColonToken.getType() == LdapFilterToken.EXTENSIBLE_DNATTR_COLON ) { if ( super.getStartToken() == null ) { super.setStartToken( dnAttrColonToken ); } this.dnAttrColonToken = dnAttrColonToken; return true; } else { return false; } } /** * Gets the dn attr colon token. * * @return the dn attr colon token, or null if not set */ public LdapFilterToken getDnAttrColonToken() { return dnAttrColonToken; } /** * Sets the dn attr token. * * @param dnAttrToken the dn attr token * * @return true, if setting the dn attr token was successful, false otherwise */ public boolean setDnAttrToken( LdapFilterToken dnAttrToken ) { if ( this.dnAttrToken == null && dnAttrToken != null && dnAttrToken.getType() == LdapFilterToken.EXTENSIBLE_DNATTR ) { this.dnAttrToken = dnAttrToken; return true; } else { return false; } } /** * Gets the dn attr token. * * @return the dn attr token, or null if not set */ public LdapFilterToken getDnAttrToken() { return dnAttrToken; } /** * Sets the matching rule colon token. * * @param matchingRuleColonToken the matching rule colon token * * @return true, if setting the matching rule colon token was successful, false otherwise */ public boolean setMatchingRuleColonToken( LdapFilterToken matchingRuleColonToken ) { if ( this.matchingRuleColonToken == null && matchingRuleColonToken != null && matchingRuleColonToken.getType() == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON ) { if ( super.getStartToken() == null ) { super.setStartToken( matchingRuleColonToken ); } this.matchingRuleColonToken = matchingRuleColonToken; return true; } else { return false; } } /** * Gets the matching rule colon token. * * @return the matching rule colon token, or null if not set */ public LdapFilterToken getMatchingRuleColonToken() { return matchingRuleColonToken; } /** * Sets the matching rule token. * * @param matchingRuleToken the matching rule token * * @return true, if setting the matching rule token was successful, false otherwise */ public boolean setMatchingRuleToken( LdapFilterToken matchingRuleToken ) { if ( this.matchingRuleToken == null && matchingRuleToken != null && matchingRuleToken.getType() == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID ) { this.matchingRuleToken = matchingRuleToken; return true; } else { return false; } } /** * Gets the matching rule token. * * @return the matching rule token, or null if not set */ public LdapFilterToken getMatchingRuleToken() { return matchingRuleToken; } /** * Sets the equals colon token. * * @param equalsColonToken the equals colon token * * @return true, if setting the equals colon token was sucessful, false otherwise */ public boolean setEqualsColonToken( LdapFilterToken equalsColonToken ) { if ( this.equalsColonToken == null && equalsColonToken != null && equalsColonToken.getType() == LdapFilterToken.EXTENSIBLE_EQUALS_COLON ) { this.equalsColonToken = equalsColonToken; return true; } else { return false; } } /** * Gets the equals colon token. * * @return the equals colon token, or null if not set */ public LdapFilterToken getEqualsColonToken() { return equalsColonToken; } /** * Sets the equals token. * * @param equalsToken the equals token * * @return true, if setting the equals token was successful, false otherwise */ public boolean setEqualsToken( LdapFilterToken equalsToken ) { if ( this.equalsToken == null && equalsToken != null && equalsToken.getType() == LdapFilterToken.EQUAL ) { this.equalsToken = equalsToken; return true; } else { return false; } } /** * Gets the equals token. * * @return the equals token, or null if not set */ public LdapFilterToken getEqualsToken() { return equalsToken; } /** * Sets the value token. * * @param valueToken the value token * * @return true, if setting the value token was successful, false otherwise */ public boolean setValueToken( LdapFilterToken valueToken ) { if ( this.valueToken == null && valueToken != null && valueToken.getType() == LdapFilterToken.VALUE ) { this.valueToken = valueToken; return true; } else { return false; } } /** * Gets the value token. * * @return the value token, or null if not set */ public LdapFilterToken getValueToken() { return this.valueToken; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#isValid() */ public boolean isValid() { return startToken != null && equalsColonToken != null & equalsToken != null && valueToken != null && ( ( attributeToken != null && ( ( dnAttrColonToken == null && dnAttrToken == null ) || ( dnAttrColonToken != null && dnAttrToken != null ) ) && ( ( matchingRuleColonToken == null && matchingRuleToken == null ) || ( matchingRuleColonToken != null && matchingRuleToken != null ) ) ) || ( attributeToken == null && ( ( dnAttrColonToken == null && dnAttrToken == null ) || ( dnAttrColonToken != null && dnAttrToken != null ) ) && matchingRuleColonToken != null && matchingRuleToken != null ) ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getTokens() */ public LdapFilterToken[] getTokens() { // collect tokens List<LdapFilterToken> tokenList = new ArrayList<LdapFilterToken>(); if ( attributeToken != null ) { tokenList.add( attributeToken ); } if ( dnAttrColonToken != null ) { tokenList.add( dnAttrColonToken ); } if ( dnAttrToken != null ) { tokenList.add( dnAttrToken ); } if ( matchingRuleColonToken != null ) { tokenList.add( matchingRuleColonToken ); } if ( matchingRuleToken != null ) { tokenList.add( matchingRuleToken ); } if ( equalsColonToken != null ) { tokenList.add( equalsColonToken ); } if ( equalsToken != null ) { tokenList.add( equalsToken ); } if ( valueToken != null ) { tokenList.add( valueToken ); } // sort tokens LdapFilterToken[] tokens = tokenList.toArray( new LdapFilterToken[tokenList.size()] ); Arrays.sort( tokens ); // return return tokens; } /** * @see java.lang.Object#toString() */ public String toString() { return ( attributeToken != null ? startToken.getValue() : "" ) //$NON-NLS-1$ + ( dnAttrColonToken != null ? dnAttrColonToken.getValue() : "" ) //$NON-NLS-1$ + ( dnAttrToken != null ? dnAttrToken.getValue() : "" ) //$NON-NLS-1$ + ( matchingRuleColonToken != null ? matchingRuleColonToken.getValue() : "" ) //$NON-NLS-1$ + ( matchingRuleToken != null ? matchingRuleToken.getValue() : "" ) //$NON-NLS-1$ + ( equalsColonToken != null ? equalsColonToken.getValue() : "" ) //$NON-NLS-1$ + ( equalsToken != null ? equalsToken.getValue() : "" ) //$NON-NLS-1$ + ( valueToken != null ? valueToken.getValue() : "" ); //$NON-NLS-1$ } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#addFilter(org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter) */ public boolean addFilter( LdapFilter filter ) { return false; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidFilters() */ public LdapFilter[] getInvalidFilters() { if ( isValid() ) { return new LdapFilter[0]; } else { return new LdapFilter[] { parent }; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getFilter(int) */ public LdapFilter getFilter( int offset ) { if ( startToken != null && startToken.getOffset() <= offset && offset < startToken.getOffset() + toString().length() ) { return parent; } else { return null; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidCause() */ public String getInvalidCause() { if ( dnAttrColonToken != null && dnAttrToken == null ) { return Messages.LdapFilterExtensibleComponent_MissingDn; } else if ( matchingRuleColonToken != null && matchingRuleToken == null ) { return Messages.LdapFilterExtensibleComponent_MissingMatchingRule; } else if ( equalsColonToken == null ) { return Messages.LdapFilterExtensibleComponent_MissingColon; } else if ( equalsToken == null ) { return Messages.LdapFilterExtensibleComponent_MissingEquals; } else if ( attributeToken == null ) { return Messages.LdapFilterExtensibleComponent_MissingAttributeType; } else if ( valueToken != null ) { return Messages.LdapFilterExtensibleComponent_MissingValue; } else { return null; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterComponent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterComponent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapFilterComponent is the base class for all filter components. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class LdapFilterComponent { /** The parent filter. */ protected final LdapFilter parent; /** The start token. */ protected LdapFilterToken startToken; /** The filter list. */ protected final List<LdapFilter> filterList; /** * The Constructor. * * @param parent the parent filter, not null */ protected LdapFilterComponent( LdapFilter parent ) { if ( parent == null ) { throw new IllegalArgumentException( Messages.LdapFilterComponent_ParentIsNull ); } this.parent = parent; this.startToken = null; this.filterList = new ArrayList<LdapFilter>( 2 ); } /** * Returns the parent filter of this filter component. * * @return the parent filter, never null. */ public final LdapFilter getParent() { return parent; } /** * Sets the start token of the filter component. Checks if start token * isn't set yet and if the given start token isn't null. * * @param startToken * * @return true if setting the start token was successful, false * otherwise. */ public boolean setStartToken( LdapFilterToken startToken ) { if ( this.startToken == null && startToken != null ) { this.startToken = startToken; return true; } else { return false; } } /** * Returns the start token of this filter component. * * @return the start token or null if not set. */ public final LdapFilterToken getStartToken() { return startToken; } /** * Adds a filter to the list of subfilters. Checks if the start token * was set before and if the filter isn't null. * * @param filter * * @return true if adding the filter was successful, false otherwise. */ public boolean addFilter( LdapFilter filter ) { if ( startToken != null && filter != null ) { filterList.add( filter ); return true; } else { return false; } } /** * Returns the subfilters of this filter component. * * @return an array of subfilters or an empty array. */ public LdapFilter[] getFilters() { LdapFilter[] filters = new LdapFilter[filterList.size()]; filterList.toArray( filters ); return filters; } /** * Checks if this filter component including all subfilters is valid. * * @return true if this filter component is valid. */ public boolean isValid() { if ( startToken == null ) { return false; } if ( filterList.isEmpty() ) { return false; } for ( LdapFilter filter : filterList ) { if ( filter == null || !filter.isValid() ) { return false; } } return true; } /** * Returns the invalid cause. * * @return the invalid cause, or null if this filter is valid. */ public abstract String getInvalidCause(); /** * Returns the invalid filters. This may be the whole parent filter or * any of the subfilters. * * @return an array of invalid filters or an empty array if all filters * are valid. */ public LdapFilter[] getInvalidFilters() { if ( startToken == null || filterList.isEmpty() ) { return new LdapFilter[] { parent }; } else { List<LdapFilter> invalidFilterList = new ArrayList<LdapFilter>(); for ( LdapFilter filter : filterList ) { if ( filter != null ) { invalidFilterList.addAll( Arrays.asList( filter.getInvalidFilters() ) ); } } return invalidFilterList.toArray( new LdapFilter[invalidFilterList.size()] ); } } /** * Returns all tokens of the filter component including all subfilters. * * @return an array of tokens of an empty array. */ public LdapFilterToken[] getTokens() { // collect tokens List<LdapFilterToken> tokenList = new ArrayList<LdapFilterToken>(); if ( startToken != null ) { tokenList.add( startToken ); } for ( LdapFilter filter : filterList ) { if ( filter != null ) { tokenList.addAll( Arrays.asList( filter.getTokens() ) ); } } // sort tokens LdapFilterToken[] tokens = tokenList.toArray( new LdapFilterToken[tokenList.size()] ); Arrays.sort( tokens ); // return return tokens; } /** * Returns the filter at the given offset. This may be the whole parent * filter or one of the subfilters. * * @param offset the offset * * @return the filter at the given offset or null is offset is out of * range. */ public LdapFilter getFilter( int offset ) { if ( startToken != null && startToken.getOffset() == offset ) { return parent; } else if ( !filterList.isEmpty() ) { for ( LdapFilter filter : filterList ) { if ( filter != null && filter.getFilter( offset ) != null ) { return filter.getFilter( offset ); } } return null; } else { return null; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/Messages.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import org.eclipse.osgi.util.NLS; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.apache.directory.studio.ldapbrowser.core.model.filter.messages"; //$NON-NLS-1$ public static String LdapAndFilterComponent_InvalidAndFilter; public static String LdapAndFilterComponent_MissingAndCharacter; public static String LdapAndFilterComponent_MissingFilters; public static String LdapFilterComponent_ParentIsNull; public static String LdapFilterExtensibleComponent_MissingAttributeType; public static String LdapFilterExtensibleComponent_MissingColon; public static String LdapFilterExtensibleComponent_MissingDn; public static String LdapFilterExtensibleComponent_MissingEquals; public static String LdapFilterExtensibleComponent_MissingMatchingRule; public static String LdapFilterExtensibleComponent_MissingValue; public static String LdapFilterItemComponent_MissingAttributeName; public static String LdapFilterItemComponent_MissingFilterType; public static String LdapFilterItemComponent_MissingValue; public static String LdapNotFilterComponent_InvalidNotFilter; public static String LdapNotFilterComponent_MissingFilterExpression; public static String LdapNotFilterComponent_MissingNotCharacter; public static String LdapOrFilterComponent_InvalidOrFilter; public static String LdapOrFilterComponent_MissingFilters; public static String LdapOrFilterComponent_MissingOrCharacter; static { // initialize resource bundle NLS.initializeMessages( BUNDLE_NAME, Messages.class ); } private Messages() { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapFilter class represents an LDAP filter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilter { private LdapFilterToken startToken; private LdapFilterComponent filterComponent; private LdapFilterToken stopToken; private List<LdapFilterToken> otherTokens; /** * Creates a new instance of LdapFilter. */ public LdapFilter() { this.startToken = null; this.filterComponent = null; this.stopToken = null; this.otherTokens = new ArrayList<LdapFilterToken>( 2 ); } /** * Sets the start token. * * @param startToken the start token * * @return true, if setting the start token was successful, false otherwise */ public boolean setStartToken( LdapFilterToken startToken ) { if ( this.startToken == null && startToken != null && startToken.getType() == LdapFilterToken.LPAR ) { this.startToken = startToken; return true; } else { return false; } } /** * Sets the filter component. * * @param filterComponent the filter component * * @return true, if setting the filter component was successful, false otherwise */ public boolean setFilterComponent( LdapFilterComponent filterComponent ) { if ( this.startToken != null && this.filterComponent == null && filterComponent != null ) { this.filterComponent = filterComponent; return true; } else { return false; } } /** * Sets the stop token. * * @param stopToken the stop token * * @return true, if setting the stop token was successful, false otherwise */ public boolean setStopToken( LdapFilterToken stopToken ) { if ( this.startToken != null && this.stopToken == null && stopToken != null && stopToken.getType() == LdapFilterToken.RPAR ) { this.stopToken = stopToken; return true; } else { return false; } } /** * Adds another token. * * @param otherToken the other token */ public void addOtherToken( LdapFilterToken otherToken ) { otherTokens.add( otherToken ); } /** * Gets the start token. * * @return the start token, or null if not set */ public LdapFilterToken getStartToken() { return startToken; } /** * Gets the filter component. * * @return the filter component, or null if not set */ public LdapFilterComponent getFilterComponent() { return filterComponent; } /** * Gets the stop token. * * @return the stop token or null if not set */ public LdapFilterToken getStopToken() { return stopToken; } /** * Gets all the tokens. * * @return the tokens */ public LdapFilterToken[] getTokens() { // collect tokens List<LdapFilterToken> tokenList = new ArrayList<LdapFilterToken>(); if ( startToken != null ) { tokenList.add( startToken ); } if ( stopToken != null ) { tokenList.add( stopToken ); } if ( filterComponent != null ) { tokenList.addAll( Arrays.asList( filterComponent.getTokens() ) ); } tokenList.addAll( otherTokens ); // sort tokens LdapFilterToken[] tokens = tokenList.toArray( new LdapFilterToken[tokenList.size()] ); Arrays.sort( tokens ); // return return tokens; } /** * Checks if this filter and all its subfilters are valid. * * @return true, if this filter and all its subfilters is valid */ public boolean isValid() { return startToken != null && filterComponent != null && filterComponent.isValid() && stopToken != null && otherTokens.isEmpty(); } /** * Gets the invalid filters. This may be this filter itself or any of the subfilters. * * @return an array of invalid filters or an empty array if all subfilters * are valid. */ public LdapFilter[] getInvalidFilters() { if ( startToken == null || filterComponent == null || stopToken == null ) { return new LdapFilter[] { this }; } else { return filterComponent.getInvalidFilters(); } } /** * Gets the filter at the given offset. This may be this filter * or one of the subfilters. * * @param offset the offset * * @return the filter at the given offset or null is offset is out of * range. */ public LdapFilter getFilter( int offset ) { if ( startToken != null && startToken.getOffset() == offset ) { return this; } else if ( stopToken != null && stopToken.getOffset() == offset ) { return this; } if ( otherTokens != null && otherTokens.size() > 0 ) { for ( int i = 0; i < otherTokens.size(); i++ ) { LdapFilterToken otherToken = otherTokens.get( i ); if ( otherToken != null && otherToken.getOffset() <= offset && offset < otherToken.getOffset() + otherToken.getLength() ) { return this; } } } if ( filterComponent != null ) { return filterComponent.getFilter( offset ); } return this; } /** * Gets the invalid cause. * * @return the invalid cause, or null if this filter is valid. */ public String getInvalidCause() { if ( stopToken == null ) { return BrowserCoreMessages.model_filter_missing_closing_parenthesis; } else if ( filterComponent == null ) { return BrowserCoreMessages.model_filter_missing_filter_expression; } else { return filterComponent.getInvalidCause(); } } /** * Gets the string representation of this LDAP filter. Invalid tokens and * white spaces are removed, but incomplete filter parts are kept. */ public String toString() { StringBuffer sb = new StringBuffer(); LdapFilterToken[] tokens = getTokens(); for ( LdapFilterToken token : tokens ) { if ( token.getType() != LdapFilterToken.UNKNOWN && token.getType() != LdapFilterToken.WHITESPACE && token.getType() != LdapFilterToken.ERROR && token.getType() != LdapFilterToken.EOF ) { sb.append( token.getValue() ); } } return sb.toString(); } /** * Gets the string representation of this LDAP filter, as provided by the user. * It may contain white spaces and invalid tokens. */ public String toUserProvidedString() { // add _all_ tokens to the string, including invalid tokens and whitespace tokens StringBuffer sb = new StringBuffer(); LdapFilterToken[] tokens = getTokens(); for ( LdapFilterToken token : tokens ) { sb.append( token.getValue() ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/LdapFilterItemComponent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken; /** * The LdapFilterExtensibleComponent represents an simple filter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilterItemComponent extends LdapFilterComponent { /** The filtertype token. */ private LdapFilterToken filtertypeToken; /** The value token. */ private LdapFilterToken valueToken; /** * Creates a new instance of LdapFilterItemComponent. * * @param parent the parent filter */ public LdapFilterItemComponent( LdapFilter parent ) { super( parent ); this.filtertypeToken = null; this.valueToken = null; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#setStartToken(org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterToken) */ public boolean setStartToken( LdapFilterToken attributeToken ) { if ( attributeToken != null && attributeToken.getType() == LdapFilterToken.ATTRIBUTE ) { super.setStartToken( attributeToken ); return true; } else { return false; } } /** * Sets the attribute token. * * @param attributeToken the attribute token * * @return true, if setting the attribute token was successful, false otherwise */ public boolean setAttributeToken( LdapFilterToken attributeToken ) { return this.setStartToken( attributeToken ); } /** * Gets the attribute token. * * @return the attribute token, null if not set */ public LdapFilterToken getAttributeToken() { return getStartToken(); } /** * Sets the filtertype token. * * @param filtertypeToken the filtertype token * * @return true, if setting the filtertype token was successful, false otherwise */ public boolean setFiltertypeToken( LdapFilterToken filtertypeToken ) { if ( this.filtertypeToken == null && filtertypeToken != null && ( filtertypeToken.getType() == LdapFilterToken.EQUAL || filtertypeToken.getType() == LdapFilterToken.GREATER || filtertypeToken.getType() == LdapFilterToken.LESS || filtertypeToken.getType() == LdapFilterToken.APROX || filtertypeToken.getType() == LdapFilterToken.PRESENT || filtertypeToken.getType() == LdapFilterToken.SUBSTRING ) ) { this.filtertypeToken = filtertypeToken; return true; } else { return false; } } /** * Gets the filter token. * * @return the filter token, null if not set */ public LdapFilterToken getFilterToken() { return filtertypeToken; } /** * Sets the value token. * * @param valueToken the value token * * @return true, if setting the value token was successful, false otherwise */ public boolean setValueToken( LdapFilterToken valueToken ) { if ( this.valueToken == null && valueToken != null && valueToken.getType() == LdapFilterToken.VALUE ) { this.valueToken = valueToken; return true; } else { return false; } } /** * Gets the value token. * * @return the value token, null if not set */ public LdapFilterToken getValueToken() { return valueToken; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#isValid() */ public boolean isValid() { return startToken != null && filtertypeToken != null && ( valueToken != null || filtertypeToken.getType() == LdapFilterToken.PRESENT ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getTokens() */ public LdapFilterToken[] getTokens() { // collect tokens List<LdapFilterToken> tokenList = new ArrayList<LdapFilterToken>(); if ( startToken != null ) { tokenList.add( startToken ); } if ( filtertypeToken != null ) { tokenList.add( filtertypeToken ); } if ( valueToken != null ) { tokenList.add( valueToken ); } // sort tokens LdapFilterToken[] tokens = tokenList.toArray( new LdapFilterToken[tokenList.size()] ); Arrays.sort( tokens ); // return return tokens; } /** * @see java.lang.Object#toString() */ public String toString() { return ( startToken != null ? startToken.getValue() : "" ) //$NON-NLS-1$ + ( filtertypeToken != null ? filtertypeToken.getValue() : "" ) //$NON-NLS-1$ + ( valueToken != null ? valueToken.getValue() : "" ); //$NON-NLS-1$ } /** * This implementation does nothing and returns always false. * * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#addFilter(org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter) */ public boolean addFilter( LdapFilter filter ) { return false; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidFilters() */ public LdapFilter[] getInvalidFilters() { if ( isValid() ) { return new LdapFilter[0]; } else { return new LdapFilter[] { parent }; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getFilter(int) */ public LdapFilter getFilter( int offset ) { if ( startToken != null && startToken.getOffset() <= offset && offset < startToken.getOffset() + startToken.getLength() ) { return parent; } else if ( filtertypeToken != null && filtertypeToken.getOffset() <= offset && offset < filtertypeToken.getOffset() + filtertypeToken.getLength() ) { return parent; } else if ( valueToken != null && valueToken.getOffset() <= offset && offset < valueToken.getOffset() + valueToken.getLength() ) { return parent; } else { return null; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent#getInvalidCause() */ public String getInvalidCause() { if ( startToken == null ) { return Messages.LdapFilterItemComponent_MissingAttributeName; } else if ( filtertypeToken == null ) { return Messages.LdapFilterItemComponent_MissingFilterType; } else if ( valueToken == null ) { return Messages.LdapFilterItemComponent_MissingValue; } else { return null; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterScanner.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter.parser; /** * The LdapFilterScanner is a scanner for LDAP filters. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilterScanner { // From RFC 2254: // ------------- // The string representation of an LDAP search filter is defined by the // following grammar, following the ABNF notation defined in [5]. The // filter format uses a prefix notation. // // filter = "(" filtercomp ")" // filtercomp = and / or / not / item // and = "&" filterlist // or = "|" filterlist // not = "!" filter // filterlist = 1*filter // item = simple / present / substring / extensible // simple = attr filtertype value // filtertype = equal / approx / greater / less // equal = "=" // approx = "~=" // greater = ">=" // less = "<=" // extensible = attr [":dn"] [":" matchingrule] ":=" value // / [":dn"] ":" matchingrule ":=" value // present = attr "=*" // substring = attr "=" [initial] any [final] // initial = value // any = "*" *(value "*") // final = value // attr = AttributeDescription from Section 4.1.5 of [1] // matchingrule = MatchingRuleId from Section 4.1.9 of [1] // value = AttributeValue from Section 4.1.6 of [1] // // The attr, matchingrule, and value constructs are as described in the // corresponding section of [1] given above. // // If a value should contain any of the following characters // // Character ASCII value // --------------------------- // * 0x2a // ( 0x28 // ) 0x29 // \ 0x5c // NUL 0x00 // // the character must be encoded as the backslash '\' character (ASCII // 0x5c) followed by the two hexadecimal digits representing the ASCII // value of the encoded character. The case of the two hexadecimal // digits is not significant. /** The filter to scan */ private String filter; /** The current position */ private int pos; /** The last token type. */ private int lastTokenType; /** * Creates a new instance of LdapFilterScanner. */ public LdapFilterScanner() { super(); this.filter = ""; //$NON-NLS-1$ } /** * Resets this scanner. * * @param filter the new filter to scan */ public void reset( String filter ) { this.filter = filter; this.pos = -1; this.lastTokenType = LdapFilterToken.NEW; } /** * Gets the character at the current position. * * @return the character at the current position */ private char currentChar() { return 0 <= pos && pos < filter.length() ? filter.charAt( pos ) : '\u0000'; } /** * Increments the position counter and gets * the character at that positon. * * @return the character at the next position */ private char nextChar() { pos++; return currentChar(); } /** * Decrements the position counter and gets * the character at that positon. * * @return the character at the previous position */ private char prevChar() { pos--; return currentChar(); } /** * Increments the position counter as long as there are * line breaks and gets the character at that positon. * * @return the character at the next position */ private char nextNonLinebreakChar() { while ( nextChar() == '\n' ); return currentChar(); } /** * Decrements the position counter as long as there are * line breaks and gets the character at that positon. * * @return the character at the previous position */ private char prevNonLinebreakChar() { while ( prevChar() == '\n' ); return currentChar(); } /** * Gets the next token. * * @return the next token */ public LdapFilterToken nextToken() { char c; // check for EOF c = nextChar(); if ( c == '\u0000' ) { return new LdapFilterToken( LdapFilterToken.EOF, "", pos ); //$NON-NLS-1$ } else { prevChar(); } // check for ignorable whitespaces c = nextChar(); if ( Character.isWhitespace( c ) && ( lastTokenType == LdapFilterToken.RPAR || lastTokenType == LdapFilterToken.AND || lastTokenType == LdapFilterToken.OR || lastTokenType == LdapFilterToken.NOT ) ) { StringBuffer sb = new StringBuffer(); while ( Character.isWhitespace( c ) ) { sb.append( c ); c = nextChar(); } prevChar(); return new LdapFilterToken( LdapFilterToken.WHITESPACE, sb.toString(), pos - sb.length() + 1 ); } else { prevChar(); } // check special characters c = nextChar(); switch ( c ) { case '(': this.lastTokenType = LdapFilterToken.LPAR; return new LdapFilterToken( this.lastTokenType, "(", pos ); //$NON-NLS-1$ case ')': if ( lastTokenType != LdapFilterToken.EQUAL && lastTokenType != LdapFilterToken.GREATER && lastTokenType != LdapFilterToken.LESS && lastTokenType != LdapFilterToken.APROX && lastTokenType != LdapFilterToken.SUBSTRING ) { this.lastTokenType = LdapFilterToken.RPAR; return new LdapFilterToken( this.lastTokenType, ")", pos ); //$NON-NLS-1$ } case '&': if ( lastTokenType == LdapFilterToken.LPAR ) { // if(nextNonWhitespaceChar()=='(') { // prevNonWhitespaceChar(); this.lastTokenType = LdapFilterToken.AND; return new LdapFilterToken( this.lastTokenType, "&", pos ); //$NON-NLS-1$ // } // else { // prevNonWhitespaceChar(); // } } break; case '|': if ( lastTokenType == LdapFilterToken.LPAR ) { // if(nextNonWhitespaceChar()=='(') { // prevNonWhitespaceChar(); this.lastTokenType = LdapFilterToken.OR; return new LdapFilterToken( this.lastTokenType, "|", pos ); //$NON-NLS-1$ // } // else { // prevNonWhitespaceChar(); // } } break; case '!': if ( lastTokenType == LdapFilterToken.LPAR ) { // if(nextNonWhitespaceChar()=='(') { // prevNonWhitespaceChar(); this.lastTokenType = LdapFilterToken.NOT; return new LdapFilterToken( this.lastTokenType, "!", pos ); //$NON-NLS-1$ // } // else { // prevNonWhitespaceChar(); // } } break; case '=': if ( lastTokenType == LdapFilterToken.ATTRIBUTE ) { if ( nextChar() == '*' ) { char t = nextChar(); if ( t == ')' || t == '\u0000' ) { prevChar(); this.lastTokenType = LdapFilterToken.PRESENT; return new LdapFilterToken( this.lastTokenType, "=*", pos - 1 ); //$NON-NLS-1$ } else { prevChar(); prevChar(); } } else { prevChar(); } // substring or equal // read till ) or eof, if we found an * we have an substring boolean asteriskFound = false; c = nextNonLinebreakChar(); int count = 1; while ( c != ')' && c != '\u0000' ) { if ( c == '*' ) { asteriskFound = true; break; } c = nextNonLinebreakChar(); count++; } while ( count > 0 ) { prevNonLinebreakChar(); count--; } if ( asteriskFound ) { this.lastTokenType = LdapFilterToken.SUBSTRING; return new LdapFilterToken( this.lastTokenType, "=", pos ); //$NON-NLS-1$ } else { this.lastTokenType = LdapFilterToken.EQUAL; return new LdapFilterToken( this.lastTokenType, "=", pos ); //$NON-NLS-1$ } } else if ( lastTokenType == LdapFilterToken.EXTENSIBLE_EQUALS_COLON ) { this.lastTokenType = LdapFilterToken.EQUAL; return new LdapFilterToken( this.lastTokenType, "=", pos ); //$NON-NLS-1$ } break; case '>': if ( lastTokenType == LdapFilterToken.ATTRIBUTE ) { if ( nextChar() == '=' ) { this.lastTokenType = LdapFilterToken.GREATER; return new LdapFilterToken( this.lastTokenType, ">=", pos - 1 ); //$NON-NLS-1$ } else { prevChar(); } } break; case '<': if ( lastTokenType == LdapFilterToken.ATTRIBUTE ) { if ( nextChar() == '=' ) { this.lastTokenType = LdapFilterToken.LESS; return new LdapFilterToken( this.lastTokenType, "<=", pos - 1 ); //$NON-NLS-1$ } else { prevChar(); } } break; case '~': if ( lastTokenType == LdapFilterToken.ATTRIBUTE ) { if ( nextChar() == '=' ) { this.lastTokenType = LdapFilterToken.APROX; return new LdapFilterToken( this.lastTokenType, "~=", pos - 1 ); //$NON-NLS-1$ } else { prevChar(); } } break; case ':': char t1 = nextChar(); char t2 = nextChar(); char t3 = nextChar(); prevChar(); prevChar(); prevChar(); if ( ( lastTokenType == LdapFilterToken.LPAR || lastTokenType == LdapFilterToken.EXTENSIBLE_ATTRIBUTE ) && ( // ( t1 == ':' && t2 != '=' ) // || // ( ( t1 == 'd' || t1 == 'D' ) && t2 == ':' && t3 == ':' ) // || ( ( t1 == 'd' || t1 == 'D' ) && ( t2 == 'n' || t2 == 'N' ) && ( t3 == ':' ) ) ) ) { this.lastTokenType = LdapFilterToken.EXTENSIBLE_DNATTR_COLON; return new LdapFilterToken( this.lastTokenType, ":", pos ); //$NON-NLS-1$ } else if ( ( lastTokenType == LdapFilterToken.EXTENSIBLE_ATTRIBUTE || lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR || lastTokenType == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID || lastTokenType == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON ) && t1 == '=' ) { this.lastTokenType = LdapFilterToken.EXTENSIBLE_EQUALS_COLON; return new LdapFilterToken( this.lastTokenType, ":", pos ); //$NON-NLS-1$ } else if ( ( lastTokenType == LdapFilterToken.LPAR || lastTokenType == LdapFilterToken.EXTENSIBLE_ATTRIBUTE || lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR || lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR_COLON ) ) { this.lastTokenType = LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON; return new LdapFilterToken( this.lastTokenType, ":", pos ); //$NON-NLS-1$ } break; } // switch prevChar(); // check attribute or extensible attribute if ( this.lastTokenType == LdapFilterToken.LPAR ) { StringBuffer sb = new StringBuffer(); // first char must be non-whitespace c = nextChar(); while ( c != ':' && c != '=' && c != '<' && c != '>' && c != '~' && c != '(' && c != ')' && c != '\u0000' && !Character.isWhitespace( c ) ) { sb.append( c ); c = nextChar(); } prevChar(); if ( sb.length() > 0 ) { boolean isExtensible = ( c == ':' ); if ( isExtensible ) { this.lastTokenType = LdapFilterToken.EXTENSIBLE_ATTRIBUTE; return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length() + 1 ); } else { this.lastTokenType = LdapFilterToken.ATTRIBUTE; return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length() + 1 ); } } } // check value if ( lastTokenType == LdapFilterToken.EQUAL || lastTokenType == LdapFilterToken.GREATER || lastTokenType == LdapFilterToken.LESS || lastTokenType == LdapFilterToken.APROX ) { boolean forbiddenCharFound = false; StringBuffer sb = new StringBuffer(); c = nextNonLinebreakChar(); int count = 0; while ( c != ')' && c != '\u0000' ) { if ( c == '*' || c == '(' ) { forbiddenCharFound = true; break; } sb.append( c ); c = nextNonLinebreakChar(); count++; } prevNonLinebreakChar(); if ( forbiddenCharFound ) { while ( count > 0 ) { prevNonLinebreakChar(); count--; } } else //if ( sb.length() > 0 ) { this.lastTokenType = LdapFilterToken.VALUE; return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length() + 1 ); } } if ( lastTokenType == LdapFilterToken.SUBSTRING ) { boolean forbiddenCharFound = false; StringBuffer sb = new StringBuffer(); c = nextNonLinebreakChar(); int count = 0; while ( c != ')' && c != '\u0000' ) { if ( c == '(' ) { forbiddenCharFound = true; break; } sb.append( c ); c = nextNonLinebreakChar(); count++; } prevNonLinebreakChar(); if ( forbiddenCharFound ) { while ( count > 0 ) { prevNonLinebreakChar(); count--; } } else if ( sb.length() > 0 ) { this.lastTokenType = LdapFilterToken.VALUE; return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length() + 1 ); } } // check extensible dn if ( lastTokenType == LdapFilterToken.EXTENSIBLE_DNATTR_COLON ) { char t1 = nextChar(); char t2 = nextChar(); char t3 = nextChar(); prevChar(); if ( ( t1 == 'd' || t1 == 'D' ) && ( t2 == 'n' || t2 == 'N' ) && ( t3 == ':' || t3 == '\u0000' ) ) { this.lastTokenType = LdapFilterToken.EXTENSIBLE_DNATTR; return new LdapFilterToken( this.lastTokenType, "" + t1 + t2, pos - 1 ); //$NON-NLS-1$ } prevChar(); prevChar(); } // check extensible matchingrule if ( lastTokenType == LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON ) { StringBuffer sb = new StringBuffer(); // first char must be non-whitespace c = nextChar(); while ( c != ':' && c != '=' && c != '<' && c != '>' && c != '~' && c != '(' && c != ')' && c != '\u0000' && !Character.isWhitespace( c ) ) { sb.append( c ); c = nextChar(); } prevChar(); if ( sb.length() > 0 ) { this.lastTokenType = LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID; return new LdapFilterToken( this.lastTokenType, sb.toString(), pos - sb.length() + 1 ); } } // no match StringBuffer sb = new StringBuffer(); c = nextChar(); while ( c != '(' && c != ')' && c != '\u0000' ) { sb.append( c ); c = nextChar(); } prevChar(); // this.lastTokenType = LdapFilterToken.UNKNOWN; // return new LdapFilterToken(this.lastTokenType, sb.toString(), // pos-sb.length()); return new LdapFilterToken( LdapFilterToken.UNKNOWN, sb.toString(), pos - sb.length() + 1 ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterParser.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter.parser; import java.util.Stack; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapAndFilterComponent; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterExtensibleComponent; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterItemComponent; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapNotFilterComponent; import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapOrFilterComponent; /** * The LdapFilterParser implements a parser for LDAP filters. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilterParser { /** The scanner. */ private LdapFilterScanner scanner; /** The filter stack. */ private Stack<LdapFilter> filterStack; /** The parsed LDAP filter model. */ private LdapFilter model; /** * Creates a new instance of LdapFilterParser. */ public LdapFilterParser() { this.scanner = new LdapFilterScanner(); this.model = new LdapFilter(); } /** * Gets the parsed LDAP filter model. * * @return the parsed model */ public LdapFilter getModel() { return model; } /** * Parses the given LDAP filter. * * @param ldapFilter the LDAP filter */ public void parse( String ldapFilter ) { // reset state filterStack = new Stack<LdapFilter>(); scanner.reset( ldapFilter ); model = new LdapFilter(); // handle error tokens before filter LdapFilterToken token = scanner.nextToken(); while ( token.getType() != LdapFilterToken.LPAR && token.getType() != LdapFilterToken.EOF ) { handleError( false, token, model ); token = scanner.nextToken(); } // check filter start if ( token.getType() == LdapFilterToken.LPAR ) { // start top level filter model.setStartToken( token ); filterStack.push( model ); // loop till filter end or EOF do { // next token token = scanner.nextToken(); switch ( token.getType() ) { case LdapFilterToken.LPAR: { LdapFilter newFilter = new LdapFilter(); newFilter.setStartToken( token ); LdapFilter currentFilter = filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); if ( filterComponent != null && filterComponent.addFilter( newFilter ) ) { filterStack.push( newFilter ); } else { currentFilter.addOtherToken( token ); } break; } case LdapFilterToken.RPAR: { LdapFilter currentFilter = filterStack.pop(); handleError( currentFilter.setStopToken( token ), token, currentFilter ); /* * if(!filterStack.isEmpty()) { LdapFilter parentFilter = * (LdapFilter) filterStack.peek(); LdapFilterComponent * filterComponent = parentFilter.getFilterComponent(); * filterComponent.addFilter(currentFilter); } */ break; } case LdapFilterToken.AND: { LdapFilter currentFilter = filterStack.peek(); LdapAndFilterComponent filterComponent = new LdapAndFilterComponent( currentFilter ); filterComponent.setStartToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); break; } case LdapFilterToken.OR: { LdapFilter currentFilter = filterStack.peek(); LdapOrFilterComponent filterComponent = new LdapOrFilterComponent( currentFilter ); filterComponent.setStartToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); break; } case LdapFilterToken.NOT: { LdapFilter currentFilter = filterStack.peek(); LdapNotFilterComponent filterComponent = new LdapNotFilterComponent( currentFilter ); filterComponent.setStartToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); break; } case LdapFilterToken.ATTRIBUTE: { LdapFilter currentFilter = filterStack.peek(); LdapFilterItemComponent filterComponent = new LdapFilterItemComponent( currentFilter ); filterComponent.setAttributeToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); break; } case LdapFilterToken.VALUE: { LdapFilter currentFilter = filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); if ( filterComponent instanceof LdapFilterItemComponent ) { handleError( ( filterComponent instanceof LdapFilterItemComponent ) && ( ( LdapFilterItemComponent ) filterComponent ).setValueToken( token ), token, currentFilter ); } else if ( filterComponent instanceof LdapFilterExtensibleComponent ) { handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ).setValueToken( token ), token, currentFilter ); } else { handleError( false, token, currentFilter ); } break; } case LdapFilterToken.EQUAL: case LdapFilterToken.GREATER: case LdapFilterToken.LESS: case LdapFilterToken.APROX: case LdapFilterToken.PRESENT: case LdapFilterToken.SUBSTRING: { LdapFilter currentFilter = filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); if ( filterComponent instanceof LdapFilterItemComponent ) { handleError( ( filterComponent instanceof LdapFilterItemComponent ) && ( ( LdapFilterItemComponent ) filterComponent ).setFiltertypeToken( token ), token, currentFilter ); } else if ( filterComponent instanceof LdapFilterExtensibleComponent ) { handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ).setEqualsToken( token ), token, currentFilter ); } else { handleError( false, token, currentFilter ); } break; } case LdapFilterToken.WHITESPACE: { LdapFilter currentFilter = filterStack.peek(); currentFilter.addOtherToken( token ); break; } case LdapFilterToken.EXTENSIBLE_ATTRIBUTE: { LdapFilter currentFilter = ( LdapFilter ) filterStack.peek(); LdapFilterExtensibleComponent filterComponent = new LdapFilterExtensibleComponent( currentFilter ); filterComponent.setAttributeToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); break; } case LdapFilterToken.EXTENSIBLE_DNATTR_COLON: { LdapFilter currentFilter = ( LdapFilter ) filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); if ( filterComponent == null ) { filterComponent = new LdapFilterExtensibleComponent( currentFilter ); ( ( LdapFilterExtensibleComponent ) filterComponent ).setDnAttrColonToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); } else { handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ).setDnAttrColonToken( token ), token, currentFilter ); } break; } case LdapFilterToken.EXTENSIBLE_DNATTR: { LdapFilter currentFilter = ( LdapFilter ) filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ).setDnAttrToken( token ), token, currentFilter ); break; } case LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID_COLON: { LdapFilter currentFilter = ( LdapFilter ) filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); if ( filterComponent == null ) { filterComponent = new LdapFilterExtensibleComponent( currentFilter ); ( ( LdapFilterExtensibleComponent ) filterComponent ).setMatchingRuleColonToken( token ); handleError( currentFilter.setFilterComponent( filterComponent ), token, currentFilter ); } else { handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ) .setMatchingRuleColonToken( token ), token, currentFilter ); } break; } case LdapFilterToken.EXTENSIBLE_MATCHINGRULEOID: { LdapFilter currentFilter = ( LdapFilter ) filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ).setMatchingRuleToken( token ), token, currentFilter ); break; } case LdapFilterToken.EXTENSIBLE_EQUALS_COLON: { LdapFilter currentFilter = ( LdapFilter ) filterStack.peek(); LdapFilterComponent filterComponent = currentFilter.getFilterComponent(); handleError( ( filterComponent instanceof LdapFilterExtensibleComponent ) && ( ( LdapFilterExtensibleComponent ) filterComponent ).setEqualsColonToken( token ), token, currentFilter ); break; } case LdapFilterToken.EOF: { model.addOtherToken( token ); break; } default: { LdapFilter currentFilter = filterStack.peek(); handleError( false, token, currentFilter ); } } } while ( !filterStack.isEmpty() && token.getType() != LdapFilterToken.EOF ); } // handle error token after filter token = scanner.nextToken(); while ( token.getType() != LdapFilterToken.EOF ) { handleError( false, token, model ); token = scanner.nextToken(); } } /** * Helper method to handle parse errors. * * @param success the success flag * @param filter the filter * @param token the token */ private void handleError( boolean success, LdapFilterToken token, LdapFilter filter ) { if ( !success ) { filter.addOtherToken( new LdapFilterToken( LdapFilterToken.ERROR, token.getValue(), token.getOffset() ) ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/filter/parser/LdapFilterToken.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.filter.parser; /** * The LdapFilterToken is used to exchange tokens from the scanner to the parser. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilterToken implements Comparable<LdapFilterToken> { /** The token identifier for a new filter */ public static final int NEW = Integer.MIN_VALUE; /** The token identifier for an error token */ public static final int ERROR = -2; /** The token identifier for end of file */ public static final int EOF = -1; /** The token identifier for an unknown token */ public static final int UNKNOWN = 0; /** The token identifier for a whitespace */ public static final int WHITESPACE = 1; /** The token identifier for the left parenthesis ( */ public static final int LPAR = 11; /** The token identifier for the right parenthesis ) */ public static final int RPAR = 12; /** The token identifier for the and operator & */ public static final int AND = 21; /** The token identifier for the or operator | */ public static final int OR = 22; /** The token identifier for the not operator ! */ public static final int NOT = 23; /** The token identifier for the attribute = */ public static final int ATTRIBUTE = 31; /** The token identifier for the equal filter type = */ public static final int EQUAL = 41; /** The token identifier for the approx filter type ~= */ public static final int APROX = 42; /** The token identifier for the greater or equal filter type >= */ public static final int GREATER = 43; /** The token identifier for the less or equal filter type <= */ public static final int LESS = 44; /** The token identifier for the present filter type =* */ public static final int PRESENT = 45; /** The token identifier for the substring filter type =* */ public static final int SUBSTRING = 46; /** The token identifier for a value. */ public static final int VALUE = 51; /** The token identifier for the asterisk. */ public static final int ASTERISK = 52; /** The token identifier for the attribute type in extensible filters. */ public static final int EXTENSIBLE_ATTRIBUTE = 61; /** The token identifier for the colon before the Dn flag in extensible filters. */ public static final int EXTENSIBLE_DNATTR_COLON = 62; /** The token identifier for the Dn flag in extensible filters. */ public static final int EXTENSIBLE_DNATTR = 63; /** The token identifier for the colon before the matching rule OID in extensible filters. */ public static final int EXTENSIBLE_MATCHINGRULEOID_COLON = 64; /** The token identifier for the matching rule OID in extensible filters. */ public static final int EXTENSIBLE_MATCHINGRULEOID = 65; /** The token identifier for the colon before the equals in extensible filters. */ public static final int EXTENSIBLE_EQUALS_COLON = 66; /** The offset. */ private int offset; /** The type. */ private int type; /** The value. */ private String value; /** * Creates a new instance of LdapFilterToken. * * @param type the type * @param value the value * @param offset the offset */ public LdapFilterToken( int type, String value, int offset ) { this.type = type; this.value = value; this.offset = offset; } /** * Returns the start position of the token in the original filter * * @return the start positon of the token */ public int getOffset() { return offset; } /** * Returns the length of the token in the original filter * * @return the length of the token */ public int getLength() { return value.length(); } /** * Gets the token type. * * @return the token type */ public int getType() { return type; } /** * Gets the value of the token in the original filter. * * @return the value of the token */ public String getValue() { return value; } /** * @see java.lang.Object#toString() */ public String toString() { return "(" + offset + ") " + "(" + type + ") " + value; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } /** * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo( LdapFilterToken o ) { if ( o instanceof LdapFilterToken ) { LdapFilterToken token = ( LdapFilterToken ) o; return this.offset - token.offset; } else { throw new ClassCastException( "Not instanceof LapFilterToken: " + o.getClass().getName() ); //$NON-NLS-1$ } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.ldapbrowser.core.BookmarkManager; import org.apache.directory.studio.ldapbrowser.core.SearchManager; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; /** * Connection without any operation. It could be used to make model modifications * without committing these modifications to the directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DummyConnection implements IBrowserConnection { private static final long serialVersionUID = 3671686808330691741L; /** The schema. */ private Schema schema; /** * Creates a new instance of DummyConnection. * * @param schema the schema */ public DummyConnection( Schema schema ) { this.schema = schema; } /** * {@inheritDoc} */ public Dn getBaseDN() { return Dn.EMPTY_DN; } /** * {@inheritDoc} */ public BookmarkManager getBookmarkManager() { return null; } /** * {@inheritDoc} */ public int getCountLimit() { return 0; } /** * {@inheritDoc} */ public Connection.AliasDereferencingMethod getAliasesDereferencingMethod() { return Connection.AliasDereferencingMethod.NEVER; } /** * {@inheritDoc} */ public IEntry getEntryFromCache( Dn dn ) { return null; } /** * {@inheritDoc} */ public IRootDSE getRootDSE() { return null; } /** * {@inheritDoc} */ public Schema getSchema() { return schema; } /** * {@inheritDoc} */ public SearchManager getSearchManager() { return null; } /** * {@inheritDoc} */ public int getTimeLimit() { return 0; } /** * {@inheritDoc} */ public boolean isFetchBaseDNs() { return false; } /** * {@inheritDoc} */ public void setBaseDN( Dn baseDn ) { } /** * {@inheritDoc} */ public void setCountLimit( int countLimit ) { } /** * {@inheritDoc} */ public void setAliasesDereferencingMethod( Connection.AliasDereferencingMethod aliasesDereferencingMethod ) { } /** * {@inheritDoc} */ public void setFetchBaseDNs( boolean fetchBaseDNs ) { } /** * {@inheritDoc} */ public void setSchema( Schema schema ) { this.schema = schema; } /** * {@inheritDoc} */ public void setTimeLimit( int timeLimit ) { } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { return null; } /** * {@inheritDoc} */ public Object clone() { return this; } /** * {@inheritDoc} */ public Connection.ReferralHandlingMethod getReferralsHandlingMethod() { return Connection.ReferralHandlingMethod.IGNORE; } /** * {@inheritDoc} */ public void setReferralsHandlingMethod( Connection.ReferralHandlingMethod referralsHandlingMethod ) { } /** * {@inheritDoc} */ public boolean isManageDsaIT() { return false; } /** * {@inheritDoc} */ public void setManageDsaIT( boolean manageDsaIT ) { } /** * {@inheritDoc} */ public boolean isFetchSubentries() { return false; } /** * {@inheritDoc} */ public void setFetchSubentries( boolean fetchSubentries ) { } /** * {@inheritDoc} */ public boolean isFetchOperationalAttributes() { return false; } /** * {@inheritDoc} */ public void setFetchOperationalAttributes( boolean fetchOperationalAttributes ) { } /** * {@inheritDoc} */ public boolean isPagedSearch() { return false; } /** * {@inheritDoc} */ public void setPagedSearch( boolean pagedSearch ) { } /** * {@inheritDoc} */ public int getPagedSearchSize() { return 0; } /** * {@inheritDoc} */ public void setPagedSearchSize( int pagedSearchSize ) { } /** * {@inheritDoc} */ public ModifyMode getModifyMode() { return ModifyMode.DEFAULT; } /** * {@inheritDoc} */ public void setModifyMode( ModifyMode mode ) { } /** * {@inheritDoc} */ public ModifyMode getModifyModeNoEMR() { return ModifyMode.DEFAULT; } /** * {@inheritDoc} */ public void setModifyModeNoEMR( ModifyMode mode ) { } /** * {@inheritDoc} */ public ModifyOrder getModifyAddDeleteOrder() { return ModifyOrder.DELETE_FIRST; } /** * {@inheritDoc} */ public void setModifyAddDeleteOrder( ModifyOrder mode ) { } /** * {@inheritDoc} */ public boolean isPagedSearchScrollMode() { return false; } /** * {@inheritDoc} */ public void setPagedSearchScrollMode( boolean pagedSearchScrollMode ) { } /** * {@inheritDoc} */ public void setQuickSearch( IQuickSearch quickSearch ) { } /** * {@inheritDoc} */ public IQuickSearch getQuickSearch() { return null; } /** * {@inheritDoc} */ public LdapUrl getUrl() { return null; } /** * {@inheritDoc} */ public Connection getConnection() { return null; } /** * {@inheritDoc} */ public void cacheEntry( IEntry entry ) { } /** * {@inheritDoc} */ public void uncacheEntryRecursive( IEntry entry ) { } /** * {@inheritDoc} */ public void clearCaches() { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Value.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.Iterator; import org.apache.directory.api.ldap.model.name.Ava; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.apache.directory.studio.ldifparser.LdifUtils; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Default implementation of IValue. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Value implements IValue { /** The serialVersionUID. */ private static final long serialVersionUID = -9039209604742682740L; /** The attribute this value belongs to */ private IAttribute attribute; /** The raw value, either a String or a byte[] */ private Object rawValue; /** * Creates a new instance of Value. * * @param attribute the attribute this value belongs to * @param rawValue the raw value, either a String or a byte[] */ public Value( IAttribute attribute, Object rawValue ) { this.init( attribute, rawValue ); assert rawValue != null; } /** * Creates a new instance of Value with an empty value. * * @param attribute the attribute this value belongs to */ public Value( IAttribute attribute ) { this.init( attribute, null ); } /** * Initializes this Value. * * @param attribute the attribute this value belongs to * @param rawValue the raw value, either a String or a byte[] or null */ private void init( IAttribute attribute, Object rawValue ) { assert attribute != null; this.attribute = attribute; if ( rawValue == null ) { if ( attribute.isString() ) { this.rawValue = IValue.EMPTY_STRING_VALUE; } else { this.rawValue = IValue.EMPTY_BINARY_VALUE; } } else { this.rawValue = rawValue; } } /** * {@inheritDoc} */ public IAttribute getAttribute() { return attribute; } /** * {@inheritDoc} */ public Object getRawValue() { return rawValue; } /** * {@inheritDoc} */ public String getStringValue() { if ( rawValue == EMPTY_STRING_VALUE ) { return EMPTY_STRING_VALUE.getStringValue(); } else if ( rawValue == EMPTY_BINARY_VALUE ) { return EMPTY_BINARY_VALUE.getStringValue(); } else if ( rawValue instanceof String ) { return ( String ) rawValue; } else if ( rawValue instanceof byte[] ) { return LdifUtils.utf8decode( ( byte[] ) rawValue ); } else { return Messages.Value_Unknown; } } /** * {@inheritDoc} */ public byte[] getBinaryValue() { if ( rawValue == EMPTY_STRING_VALUE ) { return EMPTY_STRING_VALUE.getBinaryValue(); } else if ( rawValue == EMPTY_BINARY_VALUE ) { return EMPTY_BINARY_VALUE.getBinaryValue(); } else if ( rawValue instanceof byte[] ) { return ( byte[] ) rawValue; } else if ( rawValue instanceof String ) { return LdifUtils.utf8encode( ( String ) rawValue ); } else { return LdifUtils.utf8encode( Messages.Value_Unknown ); } } /** * {@inheritDoc} */ public boolean isString() { return rawValue == EMPTY_STRING_VALUE || attribute.isString(); } /** * {@inheritDoc} */ public boolean isBinary() { return rawValue == EMPTY_BINARY_VALUE || attribute.isBinary(); } /** * {@inheritDoc} */ public boolean isEmpty() { return rawValue == EMPTY_STRING_VALUE || rawValue == EMPTY_BINARY_VALUE; } /** * {@inheritDoc} */ public boolean equals( Object o ) { // check argument if ( !( o instanceof IValue ) ) { return false; } IValue vc = ( IValue ) o; // compare attributes if ( !vc.getAttribute().equals( this.getAttribute() ) ) { return false; } // compare values if ( this.isEmpty() && vc.isEmpty() ) { return true; } else if ( this.isBinary() && vc.isBinary() ) { return Utils.equals( this.getBinaryValue(), vc.getBinaryValue() ); } else if ( this.isString() && vc.isString() ) { return ( this.getStringValue().equals( vc.getStringValue() ) ); } else { return false; } } /** * {@inheritDoc} */ public int hashCode() { return rawValue.hashCode(); } /** * {@inheritDoc} */ public String toString() { return attribute + ":" + ( isString() ? getStringValue() : "BINARY" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( Connection.class ) ) { return getAttribute().getEntry().getBrowserConnection().getConnection(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return getAttribute().getEntry().getBrowserConnection(); } if ( clazz.isAssignableFrom( IEntry.class ) ) { return getAttribute().getEntry(); } if ( clazz.isAssignableFrom( IAttribute.class ) ) { return getAttribute(); } if ( clazz.isAssignableFrom( IValue.class ) ) { return this; } return null; } /** * {@inheritDoc} */ public boolean isRdnPart() { Iterator<Ava> atavIterator = getAttribute().getEntry().getRdn().iterator(); while ( atavIterator.hasNext() ) { Ava ava = atavIterator.next(); if ( getAttribute().getDescription().equals( ava.getNormType() ) && getStringValue().equals( ava.getValue().getNormalized() ) ) { return true; } } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ContinuedSearchResultEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ContinuedSearchResultEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; /** * An {@link ContinuedSearchResultEntry} represents a result entry of a search continuation. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ContinuedSearchResultEntry extends DelegateEntry implements IContinuation { private static final long serialVersionUID = -6351277968774226912L; /** The search continuation URL. */ private LdapUrl url; /** The state. */ private State state; /** The dummy connection. */ private DummyConnection dummyConnection; protected ContinuedSearchResultEntry() { } /** * Creates a new instance of ContinuedSearchResultEntry. * * Sets the internal state of the target connection to "resolved". * * @param connection the connection of the continued search * @param dn the Dn of the entry */ public ContinuedSearchResultEntry( IBrowserConnection connection, Dn dn ) { super( connection, dn ); this.state = State.RESOLVED; } /** * Sets the internal state of the target connection to "unresolved". * This means, when calling {@link #getAttributes()} or {@link #getChildren()} * the user is asked for the target connection to use. * * @param url the new unresolved */ public void setUnresolved( LdapUrl url ) { this.state = State.UNRESOLVED; this.url = url; super.connectionId = null; } @Override public IBrowserConnection getBrowserConnection() { if ( state == State.RESOLVED ) { return super.getBrowserConnection(); } else { if ( dummyConnection == null ) { dummyConnection = new DummyConnection( Schema.DEFAULT_SCHEMA ); } return dummyConnection; } } @Override protected IEntry getDelegate() { if ( state == State.RESOLVED ) { return super.getDelegate(); } else { return null; } } /** * {@inheritDoc} */ public State getState() { return state; } /** * {@inheritDoc} */ public LdapUrl getUrl() { return url != null ? url : super.getUrl(); } /** * {@inheritDoc} */ public void resolve() { // get referral connection, exit if canceled List<String> urls = new ArrayList<String>(); urls.add( url.toString() ); Connection referralConnection = ConnectionCorePlugin.getDefault().getReferralHandler().getReferralConnection( urls ); if ( referralConnection == null ) { state = State.CANCELED; entryDoesNotExist = true; } else { state = State.RESOLVED; super.connectionId = referralConnection.getId(); InitializeAttributesRunnable iar = new InitializeAttributesRunnable( this ); new StudioBrowserJob( iar ).execute(); } } /** * {@inheritDoc} */ public int hashCode() { return getDn().hashCode(); } /** * {@inheritDoc} */ public boolean equals( Object o ) { // check argument if ( !( o instanceof ContinuedSearchResultEntry ) ) { return false; } ContinuedSearchResultEntry e = ( ContinuedSearchResultEntry ) o; // compare dn and connection return getDn() == null ? e.getDn() == null : ( getDn().equals( e.getDn() ) && getBrowserConnection().equals( e.getBrowserConnection() ) ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Entry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Entry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * The Entry class represents an entry with a logical parent entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Entry extends AbstractEntry { private static final long serialVersionUID = -4718107307581983276L; /** The Rdn. */ protected Rdn rdn; /** The parent entry. */ protected IEntry parent; protected Entry() { } /** * Creates a new instance of Entry. * * @param parent the parent entry * @param rdn the Rdn */ public Entry( IEntry parent, Rdn rdn ) { assert parent != null; assert rdn != null; assert !"".equals( rdn.toString() ); //$NON-NLS-1$ this.parent = parent; this.rdn = rdn; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#getRdn() */ public Rdn getRdn() { // performance opt. return rdn; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getDn() */ public Dn getDn() { try { Dn dn = parent.getDn().add( rdn ); return dn; } catch ( LdapInvalidDnException lide ) { return null; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getParententry() */ public IEntry getParententry() { return parent; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getBrowserConnection() */ public IBrowserConnection getBrowserConnection() { return getParententry().getBrowserConnection(); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#setRdn(org.apache.directory.studio.ldapbrowser.core.model.RDN) */ protected void setRdn( Rdn newRdn ) { this.rdn = newRdn; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#setParent(org.apache.directory.studio.ldapbrowser.core.model.IEntry) */ protected void setParent( IEntry newParent ) { this.parent = newParent; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod; import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod; import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry; import org.apache.directory.studio.ldapbrowser.core.BookmarkManager; import org.apache.directory.studio.ldapbrowser.core.SearchManager; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * The default implementation of {@link IBrowserConnection}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserConnection implements IBrowserConnection, Serializable { private static final long serialVersionUID = 2987596234755856270L; /** The connection. */ private Connection connection; /** The root DSE. */ private IRootDSE rootDSE; /** The schema. */ private Schema schema; /** The search manager. */ private SearchManager searchManager; /** The bookmark manager. */ private BookmarkManager bookmarkManager; /** The quick search. */ private IQuickSearch quickSearch; /** The dn to entry cache. */ private volatile Map<String, IEntry> dnToEntryCache; /** The entry to children filter map. */ private volatile Map<IEntry, String> entryToChildrenFilterMap; /** The entry to attribute info map. */ private volatile Map<IEntry, AttributeInfo> entryToAttributeInfoMap; /** The entry to children info map. */ private volatile Map<IEntry, ChildrenInfo> entryToChildrenInfoMap; /** * Creates a new instance of BrowserConnection. * * @param connection the connection */ public BrowserConnection( Connection connection ) { this.connection = connection; if ( connection.getConnectionParameter().getExtendedProperty( CONNECTION_PARAMETER_COUNT_LIMIT ) == null ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_COUNT_LIMIT, 1000 ); connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_TIME_LIMIT, 0 ); connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD, AliasDereferencingMethod.ALWAYS.getOrdinal() ); connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD, ReferralHandlingMethod.FOLLOW_MANUALLY.getOrdinal() ); connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_BASE_DNS, true ); connection.getConnectionParameter().setExtendedProperty( CONNECTION_PARAMETER_BASE_DN, "" ); //$NON-NLS-1$ connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_SUBENTRIES, false ); connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_PAGED_SEARCH, false ); connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_PAGED_SEARCH_SIZE, 100 ); connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE, true ); } if ( connection.getConnectionParameter().getExtendedProperty( CONNECTION_PARAMETER_MODIFY_MODE ) == null ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_MODE, ModifyMode.DEFAULT.getOrdinal() ); connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR, ModifyMode.DEFAULT.getOrdinal() ); connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_ORDER, ModifyOrder.DELETE_FIRST.getOrdinal() ); } this.searchManager = new SearchManager( this ); this.bookmarkManager = new BookmarkManager( this ); this.entryToChildrenFilterMap = new HashMap<IEntry, String>(); this.dnToEntryCache = new HashMap<String, IEntry>(); this.entryToAttributeInfoMap = new HashMap<IEntry, AttributeInfo>(); this.entryToChildrenInfoMap = new HashMap<IEntry, ChildrenInfo>(); this.schema = Schema.DEFAULT_SCHEMA; this.rootDSE = new RootDSE( this ); cacheEntry( this.rootDSE ); } /** * {@inheritDoc} */ public LdapUrl getUrl() { return Utils.getLdapURL( this ); } /** * {@inheritDoc} */ public void clearCaches() { for ( ISearch search : getSearchManager().getSearches() ) { search.setSearchResults( null ); } dnToEntryCache.clear(); entryToAttributeInfoMap.clear(); entryToChildrenInfoMap.clear(); entryToChildrenFilterMap.clear(); // searchManager.setQuickSearch( null ); TODO rootDSE = new RootDSE( this ); cacheEntry( rootDSE ); } /** * {@inheritDoc} */ public IEntry getEntryFromCache( Dn dn ) { if ( dn == null ) { return null; } String oidDn = Utils.getNormalizedOidString( dn, getSchema() ); if ( dnToEntryCache != null && dnToEntryCache.containsKey( oidDn ) ) { return dnToEntryCache.get( oidDn ); } if ( getRootDSE().getDn().equals( dn ) ) { return getRootDSE(); } return null; } /** * {@inheritDoc} */ public boolean isFetchBaseDNs() { return connection.getConnectionParameter().getExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_BASE_DNS ); } /** * {@inheritDoc} */ public void setFetchBaseDNs( boolean fetchBaseDNs ) { connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_BASE_DNS, fetchBaseDNs ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public Dn getBaseDN() { try { return new Dn( connection.getConnectionParameter().getExtendedProperty( CONNECTION_PARAMETER_BASE_DN ) ); } catch ( LdapInvalidDnException e ) { return null; } } /** * {@inheritDoc} */ public void setBaseDN( Dn baseDn ) { connection.getConnectionParameter().setExtendedProperty( CONNECTION_PARAMETER_BASE_DN, baseDn.toString() ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public int getCountLimit() { return connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_COUNT_LIMIT ); } /** * {@inheritDoc} */ public void setCountLimit( int countLimit ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_COUNT_LIMIT, countLimit ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public AliasDereferencingMethod getAliasesDereferencingMethod() { int ordinal = connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD ); return AliasDereferencingMethod.getByOrdinal( ordinal ); } /** * {@inheritDoc} */ public void setAliasesDereferencingMethod( AliasDereferencingMethod aliasesDereferencingMethod ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD, aliasesDereferencingMethod.getOrdinal() ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public ReferralHandlingMethod getReferralsHandlingMethod() { int ordinal = connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD ); return ReferralHandlingMethod.getByOrdinal( ordinal ); } /** * {@inheritDoc} */ public void setReferralsHandlingMethod( ReferralHandlingMethod referralsHandlingMethod ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD, referralsHandlingMethod.getOrdinal() ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public int getTimeLimit() { return connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_TIME_LIMIT ); } /** * {@inheritDoc} */ public void setTimeLimit( int timeLimit ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_TIME_LIMIT, timeLimit ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public boolean isManageDsaIT() { return connection.getConnectionParameter().getExtendedBoolProperty( CONNECTION_PARAMETER_MANAGE_DSA_IT ); } /** * {@inheritDoc} */ public void setManageDsaIT( boolean manageDsaIT ) { connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_MANAGE_DSA_IT, manageDsaIT ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public boolean isFetchSubentries() { return connection.getConnectionParameter().getExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_SUBENTRIES ); } /** * {@inheritDoc} */ public void setFetchSubentries( boolean fetchSubentries ) { connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_SUBENTRIES, fetchSubentries ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public boolean isFetchOperationalAttributes() { return connection.getConnectionParameter().getExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_OPERATIONAL_ATTRIBUTES ); } /** * {@inheritDoc} */ public void setFetchOperationalAttributes( boolean fetchOperationalAttribures ) { connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_FETCH_OPERATIONAL_ATTRIBUTES, fetchOperationalAttribures ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public boolean isPagedSearch() { return connection.getConnectionParameter().getExtendedBoolProperty( CONNECTION_PARAMETER_PAGED_SEARCH ); } /** * {@inheritDoc} */ public void setPagedSearch( boolean pagedSearch ) { connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_PAGED_SEARCH, pagedSearch ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public int getPagedSearchSize() { return connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_PAGED_SEARCH_SIZE ); } /** * {@inheritDoc} */ public void setPagedSearchSize( int pagedSearchSize ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_PAGED_SEARCH_SIZE, pagedSearchSize ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public boolean isPagedSearchScrollMode() { return connection.getConnectionParameter().getExtendedBoolProperty( CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE ); } /** * {@inheritDoc} */ public void setPagedSearchScrollMode( boolean pagedSearchScrollMode ) { connection.getConnectionParameter().setExtendedBoolProperty( CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE, pagedSearchScrollMode ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public ModifyMode getModifyMode() { int ordinal = connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_MODE ); return ModifyMode.getByOrdinal( ordinal ); } /** * {@inheritDoc} */ public void setModifyMode( ModifyMode mode ) { connection.getConnectionParameter() .setExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_MODE, mode.getOrdinal() ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public ModifyMode getModifyModeNoEMR() { int ordinal = connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR ); return ModifyMode.getByOrdinal( ordinal ); } /** * {@inheritDoc} */ public void setModifyModeNoEMR( ModifyMode mode ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR, mode.getOrdinal() ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public ModifyOrder getModifyAddDeleteOrder() { int ordinal = connection.getConnectionParameter().getExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_ORDER ); return ModifyOrder.getByOrdinal( ordinal ); } /** * {@inheritDoc} */ public void setModifyAddDeleteOrder( ModifyOrder mode ) { connection.getConnectionParameter().setExtendedIntProperty( CONNECTION_PARAMETER_MODIFY_ORDER, mode.getOrdinal() ); ConnectionEventRegistry.fireConnectionUpdated( connection, this ); } /** * {@inheritDoc} */ public void setQuickSearch( IQuickSearch quickSearch ) { this.quickSearch = quickSearch; } /** * {@inheritDoc} */ public IQuickSearch getQuickSearch() { return quickSearch; } /** * {@inheritDoc} */ public final IRootDSE getRootDSE() { return rootDSE; } /** * {@inheritDoc} */ public Schema getSchema() { return schema; } /** * {@inheritDoc} */ public void setSchema( Schema schema ) { this.schema = schema; } /** * This implementation returns the connection name */ public String toString() { return getConnection() != null ? getConnection().getName() : "null"; //$NON-NLS-1$ } /** * {@inheritDoc} */ public SearchManager getSearchManager() { return searchManager; } /** * {@inheritDoc} */ public BookmarkManager getBookmarkManager() { return bookmarkManager; } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return this; } return null; } /** * {@inheritDoc} */ public synchronized void cacheEntry( IEntry entry ) { dnToEntryCache.put( Utils.getNormalizedOidString( entry.getDn(), getSchema() ), entry ); } /** * Removes the entry from the cache. * * @param entry the entry to remove from cache */ protected synchronized void uncacheEntry( IEntry entry ) { dnToEntryCache.remove( Utils.getNormalizedOidString( entry.getDn(), getSchema() ) ); setAttributeInfo( entry, null ); setChildrenInfo( entry, null ); setChildrenFilter(entry, null); } /** * {@inheritDoc} */ public synchronized void uncacheEntryRecursive( IEntry entry ) { IEntry[] children = entry.getChildren(); if ( entry.getChildren() != null ) { for ( int i = 0; i < children.length; i++ ) { uncacheEntryRecursive( children[i] ); } } uncacheEntry( entry ); } /** * Gets the children filter of the entry. * * @param entry the entry * * @return the children filter of the entry, or null if no children filter is set */ protected String getChildrenFilter( IEntry entry ) { return entryToChildrenFilterMap == null ? null : entryToChildrenFilterMap.get( entry ); } /** * Sets the children filter. * * @param entry the entry * @param childrenFilter the children filter, null to remove the children filter */ protected void setChildrenFilter( IEntry entry, String childrenFilter ) { if ( childrenFilter == null || "".equals( childrenFilter ) ) //$NON-NLS-1$ { entryToChildrenFilterMap.remove( entry ); } else { entryToChildrenFilterMap.put( entry, childrenFilter ); } } /** * Gets the attribute info. * * @param entry the entry * * @return the attribute info, null if no attribute info exists */ protected AttributeInfo getAttributeInfo( IEntry entry ) { return entryToAttributeInfoMap == null ? null : entryToAttributeInfoMap.get( entry ); } /** * Sets the attribute info. * * @param entry the entry * @param ai the attribute info, null to remove the attribute info */ protected void setAttributeInfo( IEntry entry, AttributeInfo ai ) { if ( ai == null ) { entryToAttributeInfoMap.remove( entry ); } else { entryToAttributeInfoMap.put( entry, ai ); } } /** * Gets the children info. * * @param entry the entry * * @return the children info, null if no children info exists */ protected ChildrenInfo getChildrenInfo( IEntry entry ) { return entryToChildrenInfoMap == null ? null : entryToChildrenInfoMap.get( entry ); } /** * Sets the children info. * * @param entry the entry * @param ci the children info, null to remove the children info */ protected void setChildrenInfo( IEntry entry, ChildrenInfo ci ) { if ( ci == null ) { entryToChildrenInfoMap.remove( entry ); } else { entryToChildrenInfoMap.put( entry, ci ); } } /** * {@inheritDoc} */ public Connection getConnection() { return connection; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.events.AttributeAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.AttributeDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.ICompareableEntry; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; /** * An {@link DummyEntry} is an implementation if {@link IEntry} that doesn't * represent a directory entry. * * Most methods do nothing. It isn't possible to add child entries. * It only contains a map for attributes and a connection to retrieve * schema information. * * It is used for temporary {@link IEntry} objects, e.g. in the new entry wizard. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DummyEntry implements IEntry, ICompareableEntry { private static final long serialVersionUID = 4833907766031149971L; /** The Dn. */ private Dn dn; /** The browser connection. */ private IBrowserConnection browserConnection; /** The attribute map. */ private Map<String, IAttribute> attributeMap; protected DummyEntry() { } /** * Creates a new instance of DummyEntry. * * @param dn the Dn * @param browserConnection the browser connection */ public DummyEntry( Dn dn, IBrowserConnection browserConnection ) { this.dn = dn; this.browserConnection = browserConnection; attributeMap = new LinkedHashMap<String, IAttribute>(); } /** * Sets the Dn. * * @param dn the new Dn */ public void setDn( Dn dn ) { this.dn = dn; } /** * {@inheritDoc} */ public void addAttribute( IAttribute attributeToAdd ) { String oidString = attributeToAdd.getAttributeDescription().toOidString( getBrowserConnection().getSchema() ); attributeMap.put( Strings.toLowerCase( oidString ), attributeToAdd ); EventRegistry.fireEntryUpdated( new AttributeAddedEvent( attributeToAdd.getEntry().getBrowserConnection(), this, attributeToAdd ), this ); } /** * This implementation does nothing. */ public void addChild( IEntry childrenToAdd ) { } /** * {@inheritDoc} */ public void deleteAttribute( IAttribute attributeToDelete ) { String oidString = attributeToDelete.getAttributeDescription().toOidString( getBrowserConnection().getSchema() ); attributeMap.remove( Strings.toLowerCase( oidString ) ); EventRegistry.fireEntryUpdated( new AttributeDeletedEvent( attributeToDelete.getEntry().getBrowserConnection(), this, attributeToDelete ), this ); } public void deleteChild( IEntry childrenToDelete ) { } /** * {@inheritDoc} */ public IAttribute getAttribute( String attributeDescription ) { AttributeDescription ad = new AttributeDescription( attributeDescription ); String oidString = ad.toOidString( getBrowserConnection().getSchema() ); return attributeMap.get( Strings.toLowerCase( oidString ) ); } /** * {@inheritDoc} */ public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) { List<IAttribute> attributeList = new ArrayList<IAttribute>(); IAttribute myAttribute = getAttribute( attributeDescription ); if ( myAttribute != null ) { attributeList.add( myAttribute ); } AttributeDescription ad = new AttributeDescription( attributeDescription ); for ( IAttribute attribute : attributeMap.values() ) { AttributeDescription other = attribute.getAttributeDescription(); if ( other.isSubtypeOf( ad, getBrowserConnection().getSchema() ) ) { attributeList.add( attribute ); } } if ( attributeList.isEmpty() ) { return null; } else { AttributeHierarchy ah = new AttributeHierarchy( this, attributeDescription, attributeList .toArray( new IAttribute[attributeList.size()] ) ); return ah; } } /** * {@inheritDoc} */ public IAttribute[] getAttributes() { return attributeMap.values().toArray( new IAttribute[attributeMap.size()] ); } /** * {@inheritDoc} */ public IBrowserConnection getBrowserConnection() { return browserConnection; } /** * {@inheritDoc} */ public Dn getDn() { return dn; } /** * {@inheritDoc} */ public LdapUrl getUrl() { return Utils.getLdapURL( this ); } /** * This implementation always returns null. */ public IEntry getParententry() { return null; } /** * {@inheritDoc} */ public Rdn getRdn() { Rdn rdn = dn.getRdn(); return rdn == null ? new Rdn() : rdn; } /** * This implementation always returns null. */ public IEntry[] getChildren() { return null; } /** * This implementation always returns -1. */ public int getChildrenCount() { return -1; } /** * This implementation always returns the empty string. */ public String getChildrenFilter() { return ""; //$NON-NLS-1$ } /** * This implementation always returns false. */ public boolean hasMoreChildren() { return false; } /** * This implementation always returns null. */ public StudioConnectionBulkRunnableWithProgress getNextPageChildrenRunnable() { return null; } /** * This implementation always returns null. */ public StudioConnectionBulkRunnableWithProgress getTopPageChildrenRunnable() { return null; } /** * This implementation always returns false. */ public boolean hasParententry() { return false; } /** * This implementation always returns false. */ public boolean hasChildren() { return false; } /** * {@inheritDoc} */ public boolean isAlias() { return getObjectClassDescriptions().contains( getBrowserConnection().getSchema().getObjectClassDescription( SchemaConstants.ALIAS_OC ) ); } /** * This implementation always returns true. */ public boolean isAttributesInitialized() { return true; } /** * This implementation always returns true. */ public boolean isInitOperationalAttributes() { return true; } /** * This implementation always returns false. */ public boolean isFetchAliases() { return false; } /** * This implementation always returns false. */ public boolean isFetchReferrals() { return false; } /** * This implementation always returns false. */ public boolean isFetchSubentries() { return false; } /** * {@inheritDoc} */ public boolean isReferral() { return getObjectClassDescriptions().contains( getBrowserConnection().getSchema().getObjectClassDescription( SchemaConstants.REFERRAL_OC ) ); } /** * {@inheritDoc} */ public boolean isSubentry() { return getObjectClassDescriptions().contains( getBrowserConnection().getSchema().getObjectClassDescription( SchemaConstants.SUBENTRY_OC ) ); } /** * This implementation always returns false. */ public boolean isChildrenInitialized() { return false; } /** * This implementation does nothing. */ public void setAlias( boolean b ) { } /** * This implementation does nothing. */ public void setAttributesInitialized( boolean b ) { } /** * This implementation does nothing. */ public void setInitOperationalAttributes( boolean b ) { } /** * This implementation does nothing. */ public void setFetchAliases( boolean b ) { } /** * This implementation does nothing. */ public void setFetchReferrals( boolean b ) { } /** * This implementation does nothing. */ public void setFetchSubentries( boolean b ) { } /** * This implementation does nothing. */ public void setDirectoryEntry( boolean isDirectoryEntry ) { } /** * This implementation does nothing. */ public void setHasMoreChildren( boolean b ) { } /** * This implementation does nothing. */ public void setTopPageChildrenRunnable( StudioConnectionBulkRunnableWithProgress topPageChildrenRunnable ) { } /** * This implementation does nothing. */ public void setNextPageChildrenRunnable( StudioConnectionBulkRunnableWithProgress nextPageChildrenRunnable ) { } /** * This implementation does nothing. */ public void setHasChildrenHint( boolean b ) { } /** * This implementation does nothing. */ public void setReferral( boolean b ) { } /** * This implementation does nothing. */ public void setSubentry( boolean b ) { } /** * This implementation does nothing. */ public void setChildrenFilter( String filter ) { } /** * This implementation does nothing. */ public void setChildrenInitialized( boolean b ) { } /** * This implementation always returns null. */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { return null; } public Collection<ObjectClass> getObjectClassDescriptions() { Collection<ObjectClass> ocds = new ArrayList<ObjectClass>(); IAttribute ocAttribute = getAttribute( SchemaConstants.OBJECT_CLASS_AT ); if ( ocAttribute != null ) { String[] ocNames = ocAttribute.getStringValues(); Schema schema = getBrowserConnection().getSchema(); for ( String ocName : ocNames ) { ObjectClass ocd = schema.getObjectClassDescription( ocName ); ocds.add( ocd ); } } return ocds; } @Override public int hashCode() { return getDn().hashCode(); } @Override public boolean equals( Object o ) { // check argument if ( !( o instanceof ICompareableEntry ) ) { return false; } ICompareableEntry e = ( ICompareableEntry ) o; // compare dn and connection return getDn() == null ? e.getDn() == null : ( getDn().equals( e.getDn() ) && getBrowserConnection().equals( e.getBrowserConnection() ) ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DirectoryMetadataEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DirectoryMetadataEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; /** * The DirectoryMetadataEntry class represents entries that are listed in the root DSE. * Examples are the schema sub-entry, the monitorContext or the configContext entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DirectoryMetadataEntry extends BaseDNEntry { private static final long serialVersionUID = 1340597532850853276L; /** The schema entry flag. */ private boolean schemaEntry; protected DirectoryMetadataEntry() { } /** * Creates a new instance of DirectoryMetadataEntry. * * @param dn the Dn * @param browserConnection the browser connection */ public DirectoryMetadataEntry( Dn dn, IBrowserConnection browserConnection ) { super(); this.baseDn = dn; this.browserConnection = browserConnection; this.schemaEntry = false; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#hasChildren() */ public boolean hasChildren() { if ( getDn().equals( getBrowserConnection().getSchema().getDn() ) ) { return false; } else { return super.hasChildren(); } } /** * Checks if is schema entry. * * @return true, if is schema entry */ public boolean isSchemaEntry() { return schemaEntry; } /** * Sets the schema entry flag. * * @param schemaEntry the schema entry flag */ public void setSchemaEntry( boolean schemaEntry ) { this.schemaEntry = schemaEntry; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/QuickSearch.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/QuickSearch.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; /** * Default implementation of IQuickSearch. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class QuickSearch extends Search implements IQuickSearch { private static final long serialVersionUID = 4387604973869066354L; /** The search base entry. */ private IEntry searchBaseEntry; /** * Instantiates a new quick search. * * @param searchBaseEntry the search base entry */ public QuickSearch( IEntry searchBaseEntry ) { this.searchBaseEntry = searchBaseEntry; } /** * Instantiates a new quick search. * * @param searchBaseEntry the search base entry * @param connection the connection */ public QuickSearch( IEntry searchBaseEntry, IBrowserConnection connection ) { this.searchBaseEntry = searchBaseEntry; this.connection = connection; // set default parameter getSearchParameter().setName( BrowserCoreMessages.model__quick_search_name ); getSearchParameter().setSearchBase( searchBaseEntry.getDn() ); getSearchParameter().setReturningAttributes( ISearch.NO_ATTRIBUTES ); getSearchParameter().setAliasesDereferencingMethod( connection.getAliasesDereferencingMethod() ); getSearchParameter().setReferralsHandlingMethod( connection.getReferralsHandlingMethod() ); getSearchParameter().setCountLimit( connection.getCountLimit() ); getSearchParameter().setTimeLimit( connection.getTimeLimit() ); getSearchParameter().setScope( SearchScope.SUBTREE ); } public IEntry getSearchBaseEntry() { return searchBaseEntry; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Bookmark.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Bookmark.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.ldapbrowser.core.events.BookmarkUpdateEvent; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.BookmarkParameter; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Default implementation if IBookmark. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Bookmark implements IBookmark { /** The serialVersionUID. */ private static final long serialVersionUID = 2914726541167255499L; /** The connection. */ private IBrowserConnection connection; /** The bookmark parameter. */ private BookmarkParameter bookmarkParameter; /** The bookmark entry. */ private DelegateEntry bookmarkEntry; /** * Creates a new instance of Bookmark. */ protected Bookmark() { } /** * Creates a new instance of Bookmark. * * @param connection the connection * @param bookmarkParameter the bookmark parameter */ public Bookmark( IBrowserConnection connection, BookmarkParameter bookmarkParameter ) { this.connection = connection; this.bookmarkParameter = bookmarkParameter; this.bookmarkEntry = new BookmarkEntry( connection, bookmarkParameter.getDn() ); } /** * Creates a new instance of Bookmark. * * @param connection the connection * @param dn the target Dn * @param name the symbolic name */ public Bookmark( IBrowserConnection connection, Dn dn, String name ) { this.connection = connection; this.bookmarkParameter = new BookmarkParameter( dn, name ); this.bookmarkEntry = new BookmarkEntry( connection, dn ); } /** * {@inheritDoc} */ public Dn getDn() { return this.bookmarkParameter.getDn(); } /** * {@inheritDoc} */ public void setDn( Dn dn ) { this.bookmarkParameter.setDn( dn ); this.fireBookmarkUpdated( BookmarkUpdateEvent.Detail.BOOKMARK_UPDATED ); } /** * {@inheritDoc} */ public String getName() { return this.bookmarkParameter.getName(); } /** * {@inheritDoc} */ public void setName( String name ) { this.bookmarkParameter.setName( name ); this.fireBookmarkUpdated( BookmarkUpdateEvent.Detail.BOOKMARK_UPDATED ); } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( Connection.class ) ) { return getBrowserConnection().getConnection(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return getBrowserConnection(); } if ( clazz.isAssignableFrom( IEntry.class ) ) { return getEntry(); } if ( clazz.isAssignableFrom( IBookmark.class ) ) { return this; } return null; } private void fireBookmarkUpdated( BookmarkUpdateEvent.Detail detail ) { if ( this.getName() != null && !"".equals( this.getName() ) ) { //$NON-NLS-1$ EventRegistry.fireBookmarkUpdated( new BookmarkUpdateEvent( this, detail ), this ); } } /** * {@inheritDoc} */ public BookmarkParameter getBookmarkParameter() { return bookmarkParameter; } /** * {@inheritDoc} */ public void setBookmarkParameter( BookmarkParameter bookmarkParameter ) { this.bookmarkParameter = bookmarkParameter; } /** * {@inheritDoc} */ public IBrowserConnection getBrowserConnection() { return this.connection; } /** * {@inheritDoc} */ public IEntry getEntry() { return this.bookmarkEntry; } /** * {@inheritDoc} */ public String toString() { return this.getName(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Attribute.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Attribute.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.ValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Default implementation of IAttribute. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Attribute implements IAttribute { /** The serialVersionUID. */ private static final long serialVersionUID = -5679384884002589786L; /** The attribute description */ private AttributeDescription attributeDescription; /** The entry this attribute belongs to */ private IEntry entry; /** The values */ private List<IValue> valueList; /** * Creates an new instance of Attribute with the given description * and no value. * * @param entry * The entry of this attribute, mustn't be null * @param description * The attribute descrption, mustn't be null. */ public Attribute( IEntry entry, String description ) { assert entry != null; assert description != null; this.entry = entry; this.attributeDescription = new AttributeDescription( description ); this.valueList = new ArrayList<IValue>(); } /** * {@inheritDoc} */ public IEntry getEntry() { return entry; } /** * {@inheritDoc} */ public boolean isConsistent() { if ( valueList.isEmpty() ) { return false; } for ( IValue value : valueList ) { if ( value.isEmpty() ) { return false; } } return true; } /** * {@inheritDoc} */ public boolean isMustAttribute() { if ( isObjectClassAttribute() ) { return true; } else { Collection<AttributeType> mustAtds = SchemaUtils.getMustAttributeTypeDescriptions( entry ); return mustAtds.contains( getAttributeTypeDescription() ); } } /** * {@inheritDoc} */ public boolean isMayAttribute() { return !isObjectClassAttribute() && !isMustAttribute() && !isOperationalAttribute(); } /** * {@inheritDoc} */ public boolean isOperationalAttribute() { return getAttributeTypeDescription() == null || SchemaUtils.isOperational( getAttributeTypeDescription() ); } /** * {@inheritDoc} */ public boolean isObjectClassAttribute() { return SchemaConstants.OBJECT_CLASS_AT.equalsIgnoreCase( getDescription() ); } /** * {@inheritDoc} */ public boolean isString() { return !isBinary(); } /** * {@inheritDoc} */ public boolean isBinary() { return SchemaUtils.isBinary( getAttributeTypeDescription(), getEntry().getBrowserConnection().getSchema() ); } /** * {@inheritDoc} */ public void addEmptyValue() { IValue emptyValue = new Value( this ); valueList.add( emptyValue ); attributeModified( new EmptyValueAddedEvent( getEntry().getBrowserConnection(), getEntry(), this, emptyValue ) ); } /** * {@inheritDoc} */ public void deleteEmptyValue() { for ( Iterator<IValue> it = this.valueList.iterator(); it.hasNext(); ) { IValue value = it.next(); if ( value.isEmpty() ) { it.remove(); attributeModified( new EmptyValueDeletedEvent( getEntry().getBrowserConnection(), getEntry(), this, value ) ); return; } } } /** * Fires an EntryModificationEvent. * * @param event the EntryModificationEvent */ private void attributeModified( EntryModificationEvent event ) { EventRegistry.fireEntryUpdated( event, getEntry() ); } /** * Checks if the given value is valid. * * @param value the value to check * @throws IllegalArgumentException if the value is not valid */ private void checkValue( IValue value ) throws IllegalArgumentException { if ( value == null ) { throw new IllegalArgumentException( BrowserCoreMessages.model__empty_value ); } if ( !value.getAttribute().equals( this ) ) { throw new IllegalArgumentException( BrowserCoreMessages.model__values_attribute_is_not_myself ); } } /** * Deletes the given value from value list. * * @param valueToDelete the value to delete * @return true if deleted */ private boolean internalDeleteValue( IValue valueToDelete ) { for ( Iterator<IValue> it = valueList.iterator(); it.hasNext(); ) { IValue value = it.next(); if ( value.equals( valueToDelete ) ) { it.remove(); return true; } } return false; } /** * {@inheritDoc} */ public void addValue( IValue valueToAdd ) throws IllegalArgumentException { checkValue( valueToAdd ); valueList.add( valueToAdd ); attributeModified( new ValueAddedEvent( getEntry().getBrowserConnection(), getEntry(), this, valueToAdd ) ); } /** * {@inheritDoc} */ public void deleteValue( IValue valueToDelete ) throws IllegalArgumentException { checkValue( valueToDelete ); if ( internalDeleteValue( valueToDelete ) ) { attributeModified( new ValueDeletedEvent( getEntry().getBrowserConnection(), getEntry(), this, valueToDelete ) ); } } /** * {@inheritDoc} */ public void modifyValue( IValue oldValue, IValue newValue ) throws IllegalArgumentException { checkValue( oldValue ); checkValue( newValue ); internalDeleteValue( oldValue ); valueList.add( newValue ); attributeModified( new ValueModifiedEvent( getEntry().getBrowserConnection(), getEntry(), this, oldValue, newValue ) ); } /** * {@inheritDoc} */ public IValue[] getValues() { return ( IValue[] ) valueList.toArray( new IValue[0] ); } /** * {@inheritDoc} */ public int getValueSize() { return valueList.size(); } /** * {@inheritDoc} */ public String getDescription() { return getAttributeDescription().getDescription(); } /** * {@inheritDoc} */ public String getType() { return getAttributeDescription().getParsedAttributeType(); } /** * {@inheritDoc} */ public String toString() { return getDescription(); } /** * {@inheritDoc} */ public boolean equals( Object o ) { // check argument if ( !( o instanceof IAttribute ) ) { return false; } IAttribute a = ( IAttribute ) o; // compare entries if ( !getEntry().equals( a.getEntry() ) ) { return false; } // compare attribute description return getDescription().equals( a.getDescription() ); } /** * {@inheritDoc} */ public int hashCode() { return getDescription().hashCode(); } /** * {@inheritDoc} */ public byte[][] getBinaryValues() { List<byte[]> binaryValueList = new ArrayList<byte[]>(); IValue[] values = getValues(); for ( IValue value : values ) { binaryValueList.add( value.getBinaryValue() ); } return binaryValueList.toArray( new byte[0][] ); } /** * {@inheritDoc} */ public String getStringValue() { if ( getValueSize() > 0 ) { return ( ( IValue ) valueList.get( 0 ) ).getStringValue(); } else { return null; } } /** * {@inheritDoc} */ public String[] getStringValues() { List<String> stringValueList = new ArrayList<String>(); IValue[] values = getValues(); for ( IValue value : values ) { stringValueList.add( value.getStringValue() ); } return stringValueList.toArray( new String[stringValueList.size()] ); } /** * {@inheritDoc} */ public AttributeType getAttributeTypeDescription() { return getEntry().getBrowserConnection().getSchema().getAttributeTypeDescription( getType() ); } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( Connection.class ) ) { return getEntry().getBrowserConnection().getConnection(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return getEntry().getBrowserConnection(); } if ( clazz.isAssignableFrom( IEntry.class ) ) { return getEntry(); } if ( clazz.isAssignableFrom( IAttribute.class ) ) { return this; } return null; } /** * {@inheritDoc} */ public AttributeDescription getAttributeDescription() { return attributeDescription; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Messages.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.eclipse.osgi.util.NLS; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.apache.directory.studio.ldapbrowser.core.model.impl.messages"; //$NON-NLS-1$ public static String Value_Unknown; static { // initialize resource bundle NLS.initializeMessages( BUNDLE_NAME, Messages.class ); } private Messages() { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/RootDSE.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.Arrays; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; /** * The RootDSE class represents a root DSE entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class RootDSE extends BaseDNEntry implements IRootDSE { private static final long serialVersionUID = -8445018787232919754L; protected RootDSE() { } /** * Creates a new instance of RootDSE. * * @param browserConnection the browser connection */ public RootDSE( IBrowserConnection browserConnection ) { super( Dn.EMPTY_DN, browserConnection ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry#getParententry() */ public IEntry getParententry() { return null; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#getSupportedExtensions() */ public String[] getSupportedExtensions() { return getAttributeValues( SchemaConstants.SUPPORTED_EXTENSION_AT ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#getSupportedControls() */ public String[] getSupportedControls() { return getAttributeValues( SchemaConstants.SUPPORTED_CONTROL_AT ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#getSupportedFeatures() */ public String[] getSupportedFeatures() { return getAttributeValues( SchemaConstants.SUPPORTED_FEATURES_AT ); } /** * Gets the attribute values. * * @param attributeDescription the attribute description * * @return the attribute values */ private String[] getAttributeValues( String attributeDescription ) { IAttribute supportedFeaturesAttr = getAttribute( attributeDescription ); if ( supportedFeaturesAttr != null ) { String[] stringValues = supportedFeaturesAttr.getStringValues(); Arrays.sort( stringValues ); return stringValues; } else { return new String[0]; } } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#isSubentry() */ public boolean isSubentry() { return false; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#isExtensionSupported(java.lang.String) */ public boolean isExtensionSupported( String oid ) { String[] supportedExtensions = getSupportedExtensions(); return Arrays.asList( supportedExtensions ).contains( oid ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#isControlSupported(java.lang.String) */ public boolean isControlSupported( String oid ) { String[] supportedControls = getSupportedControls(); return Arrays.asList( supportedControls ).contains( oid ); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IRootDSE#isFeatureSupported(java.lang.String) */ public boolean isFeatureSupported( String oid ) { String[] supportedFeatures = getSupportedFeatures(); return Arrays.asList( supportedFeatures ).contains( oid ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BookmarkEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BookmarkEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.ICompareableEntry; /** * An {@link BookmarkEntry} represents the target of a {@link Bookmark}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BookmarkEntry extends DelegateEntry implements ICompareableEntry { private static final long serialVersionUID = -6351277968774226912L; protected BookmarkEntry() { } /** * Creates a new instance of BookmarkEntry. * * @param connection the connection of the bookmark target * @param dn the Dn of the bookmark target */ public BookmarkEntry( IBrowserConnection connection, Dn dn ) { super( connection, dn ); } /** * {@inheritDoc} */ public int hashCode() { return getDn().hashCode(); } /** * {@inheritDoc} */ public boolean equals( Object o ) { // check argument if (!( o instanceof ICompareableEntry ) ) { return false; } ICompareableEntry e = ( ICompareableEntry ) o; // compare dn and connection return getDn() == null ? e.getDn() == null : ( getDn().equals( e.getDn() ) && getBrowserConnection().equals( e.getBrowserConnection() ) ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BaseDNEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BaseDNEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * The BaseDNEntry class represents an entry without a logical parent entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BaseDNEntry extends AbstractEntry { private static final long serialVersionUID = -5444229580355372176L; /** The base Dn. */ protected Dn baseDn; /** The browser connection. */ protected IBrowserConnection browserConnection; protected BaseDNEntry() { } /** * Creates a new instance of BaseDNEntry. * * @param baseDn the base Dn * @param browserConnection the browser connection */ public BaseDNEntry( Dn baseDn, IBrowserConnection browserConnection ) { assert baseDn != null; assert browserConnection != null; this.setDirectoryEntry( true ); this.baseDn = baseDn; this.browserConnection = browserConnection; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getDn() */ public Dn getDn() { return baseDn; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getParententry() */ public IEntry getParententry() { return getBrowserConnection().getRootDSE(); } /** * @see org.apache.directory.studio.ldapbrowser.core.model.IEntry#getBrowserConnection() */ public IBrowserConnection getBrowserConnection() { return browserConnection; } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#setRdn(org.apache.directory.studio.ldapbrowser.core.model.RDN) */ protected void setRdn( Rdn newRdn ) { } /** * @see org.apache.directory.studio.ldapbrowser.core.model.impl.AbstractEntry#setParent(org.apache.directory.studio.ldapbrowser.core.model.IEntry) */ protected void setParent( IEntry newParent ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/AttributeInfo.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/AttributeInfo.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.io.Serializable; import java.util.LinkedHashMap; import java.util.Map; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; /** * A ChildrenInfo is used to hold the list of attributes of an entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeInfo implements Serializable { private static final long serialVersionUID = -298229262461058833L; /** The attributes initialized flag. */ protected volatile boolean attributesInitialized = false; /** The attribute map. */ protected volatile Map<String, IAttribute> attributeMap = new LinkedHashMap<String, IAttribute>(); /** * Creates a new instance of AttributeInfo. */ public AttributeInfo() { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Search.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/Search.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.apache.directory.api.ldap.model.message.Control; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod; import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Default implementation of ISearch. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Search implements ISearch { /** The serialVersionUID. */ private static final long serialVersionUID = -3482673086666351174L; /** The connection. */ protected IBrowserConnection connection; /** The search results. */ protected ISearchResult[] searchResults; /** The search parameter. */ protected SearchParameter searchParameter; /** The count limit exceeded flag. */ protected boolean countLimitExceeded; /** The next search runnable. */ protected StudioConnectionBulkRunnableWithProgress nextSearchRunnable; /** The top search runnable. */ protected StudioConnectionBulkRunnableWithProgress topSearchRunnable; /** The search continuations. */ protected SearchContinuation[] searchContinuations; /** * Creates a new search with the following parameters: * <ul> * <li>searchName: current date * <li>connection: null * <li>empty search base * <li>default filter (objectClass=*) * <li>no returning attributes * <li>search scope one level * <li>no count limit * <li>no time limit * <li>always dereference aliases * <li>follow referrals * <li>no initialization of hasChildren flag * <li>no controls * <li>no response controls * </ul> */ public Search() { this( new SimpleDateFormat( "yyyy-MM-dd HH-mm-ss" ).format( new Date() ), //$NON-NLS-1$ null, EMPTY_SEARCH_BASE, FILTER_TRUE, NO_ATTRIBUTES, SearchScope.ONELEVEL, 0, 0, AliasDereferencingMethod.ALWAYS, ReferralHandlingMethod.FOLLOW, false, null, true ); } /** * Creates a new Search with the given connection and search parameters. * * @param conn the connection * @param searchParameter the search parameters */ public Search( IBrowserConnection conn, SearchParameter searchParameter ) { this.connection = conn; this.searchResults = null; this.searchParameter = searchParameter; this.countLimitExceeded = false; this.nextSearchRunnable = null; this.searchContinuations = null; } /** * Creates a new search with the given search parameters * * @param searchName * the name of the search * @param conn * the connection of the search * @param searchBase * the base Dn of the search, a null search base will be * transformed to an empty Dn. * @param filter * the filter to use, null or empty filters will be * transformed to (objectClass=*) * @param returningAttributes * the attributes to return, an empty array indicates none, * null will be transformed to '*' (all user attributes) * @param scope * the search scope * @param countLimit * the count limit, 0 indicates no limit * @param timeLimit * the time limit in seconds, 0 indicates no limit * @param aliasesDereferencingMethod * the aliases dereferencing method * @param referralsHandlingMethod * the referrals handling method * @param initHasChildrenFlag * the init hasChildren flag * @param controls * the controls */ public Search( String searchName, IBrowserConnection conn, Dn searchBase, String filter, String[] returningAttributes, SearchScope scope, int countLimit, int timeLimit, AliasDereferencingMethod aliasesDereferencingMethod, ReferralHandlingMethod referralsHandlingMethod, boolean initHasChildrenFlag, List<Control> controls, boolean pagedSearchScrollModeFlag ) { this.connection = conn; this.searchResults = null; this.countLimitExceeded = false; this.nextSearchRunnable = null; this.searchParameter = new SearchParameter(); this.searchParameter.setName( searchName ); this.searchParameter.setSearchBase( searchBase ); this.searchParameter.setFilter( filter ); this.searchParameter.setReturningAttributes( returningAttributes ); this.searchParameter.setScope( scope ); this.searchParameter.setTimeLimit( timeLimit ); this.searchParameter.setCountLimit( countLimit ); this.searchParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod ); this.searchParameter.setReferralsHandlingMethod( referralsHandlingMethod ); this.searchParameter.setInitHasChildrenFlag( initHasChildrenFlag ); if ( controls != null ) { this.searchParameter.getControls().addAll( controls ); } this.searchParameter.setPagedSearchScrollMode( pagedSearchScrollModeFlag ); } /** * {@inheritDoc} */ public LdapUrl getUrl() { return Utils.getLdapURL( this ); } /** * Fires a search update event if the search name is set. * * @param detail the SearchUpdateEvent detail */ protected void fireSearchUpdated( SearchUpdateEvent.EventDetail detail ) { if ( getName() != null && !"".equals( getName() ) ) { //$NON-NLS-1$ EventRegistry.fireSearchUpdated( new SearchUpdateEvent( this, detail ), this ); } } /** * {@inheritDoc} */ public boolean isInitHasChildrenFlag() { return searchParameter.isInitHasChildrenFlag(); } /** * {@inheritDoc} */ public List<Control> getControls() { return searchParameter.getControls(); } /** * {@inheritDoc} */ public List<Control> getResponseControls() { return searchParameter.getResponseControls(); } /** * {@inheritDoc} */ public int getCountLimit() { return searchParameter.getCountLimit(); } /** * {@inheritDoc} */ public void setCountLimit( int countLimit ) { searchParameter.setCountLimit( countLimit ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public String getFilter() { return searchParameter.getFilter(); } /** * {@inheritDoc} */ public void setFilter( String filter ) { searchParameter.setFilter( filter ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public String[] getReturningAttributes() { return searchParameter.getReturningAttributes(); } /** * {@inheritDoc} */ public void setReturningAttributes( String[] returningAttributes ) { searchParameter.setReturningAttributes( returningAttributes ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public SearchScope getScope() { return searchParameter.getScope(); } /** * {@inheritDoc} */ public void setScope( SearchScope scope ) { searchParameter.setScope( scope ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public AliasDereferencingMethod getAliasesDereferencingMethod() { return searchParameter.getAliasesDereferencingMethod(); } /** * {@inheritDoc} */ public void setAliasesDereferencingMethod( Connection.AliasDereferencingMethod aliasesDereferencingMethod ) { searchParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public ReferralHandlingMethod getReferralsHandlingMethod() { return searchParameter.getReferralsHandlingMethod(); } /** * {@inheritDoc} */ public void setReferralsHandlingMethod( Connection.ReferralHandlingMethod referralsHandlingMethod ) { searchParameter.setReferralsHandlingMethod( referralsHandlingMethod ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public Dn getSearchBase() { return searchParameter.getSearchBase(); } /** * {@inheritDoc} */ public void setSearchBase( Dn searchBase ) { searchParameter.setSearchBase( searchBase ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public int getTimeLimit() { return searchParameter.getTimeLimit(); } /** * {@inheritDoc} */ public void setTimeLimit( int timeLimit ) { searchParameter.setTimeLimit( timeLimit ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } /** * {@inheritDoc} */ public String getName() { return searchParameter.getName(); } /** * {@inheritDoc} */ public void setName( String searchName ) { searchParameter.setName( searchName ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_RENAMED ); } /** * {@inheritDoc} */ public ISearchResult[] getSearchResults() { return searchResults; } /** * {@inheritDoc} */ public void setSearchResults( ISearchResult[] searchResults ) { this.searchResults = searchResults; if ( searchResults != null && getName() != null ) { fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ); } } /** * {@inheritDoc} */ public boolean isCountLimitExceeded() { return countLimitExceeded; } /** * {@inheritDoc} */ public void setCountLimitExceeded( boolean countLimitExceeded ) { this.countLimitExceeded = countLimitExceeded; fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ); } /** * {@inheritDoc} */ public IBrowserConnection getBrowserConnection() { return connection; } /** * {@inheritDoc} */ public void setBrowserConnection( IBrowserConnection connection ) { this.connection = connection; searchParameter.setCountLimit( connection.getCountLimit() ); searchParameter.setTimeLimit( connection.getTimeLimit() ); searchParameter.setAliasesDereferencingMethod( connection.getAliasesDereferencingMethod() ); searchParameter.setReferralsHandlingMethod( connection.getReferralsHandlingMethod() ); fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); } public boolean isPagedSearchScrollMode() { return searchParameter.isPagedSearchScrollMode(); } public void setPagedSearchScrollMode( boolean isPagedSearchScrollMode ) { searchParameter.setPagedSearchScrollMode( isPagedSearchScrollMode ); } /** * {@inheritDoc} */ public StudioConnectionBulkRunnableWithProgress getNextSearchRunnable() { return nextSearchRunnable; } /** * {@inheritDoc} */ public void setNextPageSearchRunnable( StudioConnectionBulkRunnableWithProgress nextSearchRunnable ) { this.nextSearchRunnable = nextSearchRunnable; } /** * {@inheritDoc} */ public StudioConnectionBulkRunnableWithProgress getTopSearchRunnable() { return topSearchRunnable; } /** * {@inheritDoc} */ public void setTopPageSearchRunnable( StudioConnectionBulkRunnableWithProgress topSearchRunnable ) { this.topSearchRunnable = topSearchRunnable; } /** * {@inheritDoc} */ public SearchContinuation[] getSearchContinuations() { return searchContinuations; } /** * {@inheritDoc} */ public void setSearchContinuations( SearchContinuation[] searchContinuations ) { this.searchContinuations = searchContinuations; if ( searchContinuations != null && getName() != null ) { fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ); } } /** * {@inheritDoc} */ public String toString() { return getName() + " (" + getBrowserConnection() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } /** * {@inheritDoc} */ public ISearch clone() { return new Search( getName(), getBrowserConnection(), getSearchBase(), getFilter(), getReturningAttributes(), getScope(), getCountLimit(), getTimeLimit(), getAliasesDereferencingMethod(), getReferralsHandlingMethod(), isInitHasChildrenFlag(), getControls(), isPagedSearchScrollMode() ); } /** * {@inheritDoc} */ public SearchParameter getSearchParameter() { return searchParameter; } /** * {@inheritDoc} */ public void setSearchParameter( SearchParameter searchParameter ) { this.searchParameter = searchParameter; } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( Connection.class ) ) { return getBrowserConnection().getConnection(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return getBrowserConnection(); } if ( clazz.isAssignableFrom( ISearch.class ) ) { return this; } return null; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ( ( connection == null ) ? 0 : connection.hashCode() ); result = prime * result + ( ( searchParameter == null || searchParameter.getName() == null ) ? 0 : searchParameter.getName() .hashCode() ); return result; } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof Search ) ) { return false; } Search other = ( Search ) obj; if ( connection == null ) { if ( other.connection != null ) { return false; } } else if ( !connection.equals( other.connection ) ) { return false; } if ( searchParameter == null || searchParameter.getName() == null ) { if ( other.searchParameter != null && other.searchParameter.getName() != null ) { return false; } } else if ( !searchParameter.getName().equals( other.searchParameter.getName() ) ) { return false; } return true; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/SearchContinuation.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/SearchContinuation.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; /** * An {@link SearchContinuation} represents a search continuation. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchContinuation extends Search implements IContinuation { private static final long serialVersionUID = 9039452279802784225L; /** The search continuation URL */ private LdapUrl searchContinuationURL; /** The state */ private State state; /** The dummy connection. */ private DummyConnection dummyConnection; /** * Creates a new instance of ContinuedSearchResultEntry. * * @param dn the Dn * @param resultBrowserConnection the connection * @param connection the connection of the continued search * @param dn the Dn of the entry */ public SearchContinuation( ISearch originalSearch, LdapUrl searchContinuationURL ) { super( null, ( SearchParameter ) originalSearch.getSearchParameter().clone() ); this.searchContinuationURL = searchContinuationURL; this.state = State.UNRESOLVED; getSearchParameter().setName( searchContinuationURL.toString() ); // apply parameters from URL if ( searchContinuationURL.getDn() != null && !searchContinuationURL.getDn().isEmpty() ) { getSearchParameter().setSearchBase( searchContinuationURL.getDn() ); } if ( searchContinuationURL.getFilter() != null && getSearchParameter().getFilter().length() > 0 ) { getSearchParameter().setFilter( searchContinuationURL.getFilter() ); } if ( searchContinuationURL.getScope().getScope() > -1 ) { switch ( searchContinuationURL.getScope() ) { case OBJECT: getSearchParameter().setScope( SearchScope.OBJECT ); break; case ONELEVEL: getSearchParameter().setScope( SearchScope.ONELEVEL ); break; case SUBTREE: getSearchParameter().setScope( SearchScope.SUBTREE ); break; } } if ( searchContinuationURL.getAttributes() != null && !searchContinuationURL.getAttributes().isEmpty() ) { getSearchParameter() .setReturningAttributes( searchContinuationURL.getAttributes().toArray( new String[0] ) ); } } @Override public IBrowserConnection getBrowserConnection() { if ( state == State.RESOLVED ) { return super.getBrowserConnection(); } else { if ( dummyConnection == null ) { dummyConnection = new DummyConnection( Schema.DEFAULT_SCHEMA ); } return dummyConnection; } } @Override public ISearchResult[] getSearchResults() { if ( state == State.RESOLVED ) { return super.getSearchResults(); } else { return null; } } /** * {@inheritDoc} */ public State getState() { return state; } /** * {@inheritDoc} */ public void resolve() { // get referral connection, exit if canceled List<String> urls = new ArrayList<String>(); urls.add( searchContinuationURL.toString() ); Connection referralConnection = ConnectionCorePlugin.getDefault().getReferralHandler().getReferralConnection( urls ); if ( referralConnection == null ) { state = State.CANCELED; return; } else { super.connection = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnection( referralConnection ); state = State.RESOLVED; } } /** * {@inheritDoc} */ public LdapUrl getUrl() { return searchContinuationURL; } /** * {@inheritDoc} */ public SearchContinuation clone() { SearchContinuation clone = new SearchContinuation( this, getUrl() ); clone.state = this.state; clone.dummyConnection = this.dummyConnection; clone.connection = super.connection; return clone; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ChildrenInfo.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/ChildrenInfo.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.io.Serializable; import java.util.Set; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * A ChildrenInfo is used to hold the list of children entries * of a parent entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ChildrenInfo implements Serializable { private static final long serialVersionUID = -4642987611142312896L; /** The children initialized flag. */ protected volatile boolean childrenInitialized = false; /** The children set. */ protected volatile Set<IEntry> childrenSet = null; /** The has more children flag. */ protected volatile boolean hasMoreChildren = false; /** The runnable used to fetch the top page of children. */ protected StudioConnectionBulkRunnableWithProgress topPageChildrenRunnable; /** The runnable used to fetch the next page of children. */ protected StudioConnectionBulkRunnableWithProgress nextPageChildrenRunnable; /** * Creates a new instance of ChildrenInfo. */ public ChildrenInfo() { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.Collection; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * An implementation of {@link IEntry} that just holds another instance * of {@link IEntry} and delegates all method calls to this instance. * It is used for bookmarks, alias and referral entries. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class DelegateEntry implements IEntry { private static final long serialVersionUID = -4488685394817691963L; /** The connection id. */ protected String connectionId; /** The Dn. */ protected Dn dn; /** The entry does not exist flag. */ protected boolean entryDoesNotExist; /** The delegate. */ protected IEntry delegate; protected DelegateEntry() { } /** * Creates a new instance of DelegateEntry. * * @param browserConnection the browser connection of the delegate * @param dn the Dn of the delegate */ protected DelegateEntry( IBrowserConnection browserConnection, Dn dn ) { this.connectionId = browserConnection.getConnection() != null ? browserConnection.getConnection().getId() : null; this.dn = dn; this.entryDoesNotExist = false; this.delegate = null; } /** * Gets the delegate. * * @return the delegate, may be null if the delegate doesn't exist. */ protected IEntry getDelegate() { IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnectionById( connectionId ); if ( browserConnection == null ) { browserConnection = new DummyConnection( Schema.DEFAULT_SCHEMA ); } // always get the fresh entry from cache delegate = browserConnection.getEntryFromCache( dn ); if ( delegate != null && !delegate.getBrowserConnection().getConnection().getConnectionWrapper().isConnected() ) { entryDoesNotExist = false; delegate = null; } return delegate; } /** * Sets the delegate. * * @param delegate the new delegate */ protected void setDelegate( IEntry delegate ) { this.delegate = delegate; } /** * {@inheritDoc} */ public IBrowserConnection getBrowserConnection() { if ( getDelegate() != null ) { return getDelegate().getBrowserConnection(); } else { IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnectionById( connectionId ); if ( browserConnection == null ) { browserConnection = new DummyConnection( Schema.DEFAULT_SCHEMA ); } return browserConnection; } } /** * {@inheritDoc} */ public Dn getDn() { if ( getDelegate() != null ) { return getDelegate().getDn(); } else { return dn; } } /** * {@inheritDoc} */ public LdapUrl getUrl() { if ( getDelegate() != null ) { return getDelegate().getUrl(); } else { return Utils.getLdapURL( this ); } } /** * {@inheritDoc} */ public boolean isAttributesInitialized() { if ( getDelegate() != null ) { return getDelegate().isAttributesInitialized(); } else if ( entryDoesNotExist ) { return true; } else { return false; } } /** * {@inheritDoc} */ public boolean isInitOperationalAttributes() { if ( getDelegate() != null ) { return getDelegate().isInitOperationalAttributes(); } else { return false; } } /** * {@inheritDoc} */ public boolean isFetchAliases() { if ( getDelegate() != null ) { return getDelegate().isFetchAliases(); } else { return false; } } /** * {@inheritDoc} */ public boolean isFetchReferrals() { if ( getDelegate() != null ) { return getDelegate().isFetchReferrals(); } else { return false; } } /** * {@inheritDoc} */ public boolean isFetchSubentries() { if ( getDelegate() != null ) { return getDelegate().isFetchSubentries(); } else { return false; } } /** * {@inheritDoc} */ public boolean isChildrenInitialized() { if ( getDelegate() != null ) { return getDelegate().isChildrenInitialized(); } else if ( entryDoesNotExist ) { return true; } else { return false; } } /** * {@inheritDoc} */ public void addAttribute( IAttribute attributeToAdd ) { if ( getDelegate() != null ) { getDelegate().addAttribute( attributeToAdd ); } } /** * {@inheritDoc} */ public void addChild( IEntry childrenToAdd ) { if ( getDelegate() != null ) { getDelegate().addChild( childrenToAdd ); } } /** * {@inheritDoc} */ public void deleteAttribute( IAttribute attributeToDelete ) { if ( getDelegate() != null ) { getDelegate().deleteAttribute( attributeToDelete ); } } /** * {@inheritDoc} */ public void deleteChild( IEntry childrenToDelete ) { if ( getDelegate() != null ) { getDelegate().deleteChild( childrenToDelete ); } } /** * {@inheritDoc} */ public IAttribute getAttribute( String attributeDescription ) { if ( getDelegate() != null ) { return getDelegate().getAttribute( attributeDescription ); } else { return null; } } /** * {@inheritDoc} */ public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) { if ( getDelegate() != null ) { return getDelegate().getAttributeWithSubtypes( attributeDescription ); } else { return null; } } /** * {@inheritDoc} */ public IAttribute[] getAttributes() { if ( getDelegate() != null ) { return getDelegate().getAttributes(); } else { return new IAttribute[0]; } } /** * {@inheritDoc} */ public IEntry getParententry() { if ( getDelegate() != null ) { return getDelegate().getParententry(); } else { return null; } } /** * {@inheritDoc} */ public Rdn getRdn() { if ( getDelegate() != null ) { return getDelegate().getRdn(); } else { Rdn rdn = dn.getRdn(); return rdn == null ? new Rdn() : rdn; } } /** * {@inheritDoc} */ public IEntry[] getChildren() { if ( getDelegate() != null ) { return getDelegate().getChildren(); } else { return new IEntry[0]; } } /** * {@inheritDoc} */ public int getChildrenCount() { if ( getDelegate() != null ) { return getDelegate().getChildrenCount(); } else { return -1; } } /** * {@inheritDoc} */ public String getChildrenFilter() { if ( getDelegate() != null ) { return getDelegate().getChildrenFilter(); } else { return null; } } /** * {@inheritDoc} */ public boolean hasMoreChildren() { if ( getDelegate() != null ) { return getDelegate().hasMoreChildren(); } else { return false; } } /** * {@inheritDoc} */ public StudioConnectionBulkRunnableWithProgress getTopPageChildrenRunnable() { if ( getDelegate() != null ) { return getDelegate().getTopPageChildrenRunnable(); } else { return null; } } /** * {@inheritDoc} */ public StudioConnectionBulkRunnableWithProgress getNextPageChildrenRunnable() { if ( getDelegate() != null ) { return getDelegate().getNextPageChildrenRunnable(); } else { return null; } } /** * {@inheritDoc} */ public boolean hasParententry() { if ( getDelegate() != null ) { return getDelegate().hasParententry(); } else { return false; } } /** * {@inheritDoc} */ public boolean hasChildren() { if ( getDelegate() != null ) { return getDelegate().hasChildren(); } else { return true; } } /** * {@inheritDoc} */ public void setAttributesInitialized( boolean b ) { if ( !b ) { if ( getDelegate() != null ) { getDelegate().setAttributesInitialized( b ); } setDelegate( null ); entryDoesNotExist = false; } else { if ( getDelegate() == null ) { setDelegate( getBrowserConnection().getEntryFromCache( dn ) ); if ( getDelegate() == null ) { // entry doesn't exist! entryDoesNotExist = true; } } if ( getDelegate() != null ) { getDelegate().setAttributesInitialized( b ); } } } /** * {@inheritDoc} */ public void setInitOperationalAttributes( boolean b ) { if ( !b ) { if ( getDelegate() != null ) { getDelegate().setInitOperationalAttributes( b ); } setDelegate( null ); entryDoesNotExist = false; } else { if ( getDelegate() == null ) { setDelegate( getBrowserConnection().getEntryFromCache( dn ) ); if ( getDelegate() == null ) { // entry doesn't exist! entryDoesNotExist = true; } } if ( getDelegate() != null ) { getDelegate().setInitOperationalAttributes( b ); } } } /** * {@inheritDoc} */ public void setFetchAliases( boolean b ) { if ( !b ) { if ( getDelegate() != null ) { getDelegate().setFetchAliases( b ); } setDelegate( null ); entryDoesNotExist = false; } else { if ( getDelegate() == null ) { setDelegate( getBrowserConnection().getEntryFromCache( dn ) ); if ( getDelegate() == null ) { // entry doesn't exist! entryDoesNotExist = true; } } if ( getDelegate() != null ) { getDelegate().setFetchAliases( b ); } } } /** * {@inheritDoc} */ public void setFetchReferrals( boolean b ) { if ( !b ) { if ( getDelegate() != null ) { getDelegate().setFetchReferrals( b ); } setDelegate( null ); entryDoesNotExist = false; } else { if ( getDelegate() == null ) { setDelegate( getBrowserConnection().getEntryFromCache( dn ) ); if ( getDelegate() == null ) { // entry doesn't exist! entryDoesNotExist = true; } } if ( getDelegate() != null ) { getDelegate().setFetchReferrals( b ); } } } /** * {@inheritDoc} */ public void setFetchSubentries( boolean b ) { if ( !b ) { if ( getDelegate() != null ) { getDelegate().setFetchSubentries( b ); } setDelegate( null ); entryDoesNotExist = false; } else { if ( getDelegate() == null ) { setDelegate( getBrowserConnection().getEntryFromCache( dn ) ); if ( getDelegate() == null ) { // entry doesn't exist! entryDoesNotExist = true; } } if ( getDelegate() != null ) { getDelegate().setFetchSubentries( b ); } } } /** * {@inheritDoc} */ public void setDirectoryEntry( boolean b ) { if ( getDelegate() != null ) { getDelegate().setDirectoryEntry( b ); } } /** * {@inheritDoc} */ public void setHasMoreChildren( boolean b ) { if ( getDelegate() != null ) { getDelegate().setHasMoreChildren( b ); } } /** * {@inheritDoc} */ public void setTopPageChildrenRunnable( StudioConnectionBulkRunnableWithProgress topPageChildrenRunnable ) { if ( getDelegate() != null ) { getDelegate().setTopPageChildrenRunnable( topPageChildrenRunnable ); } } /** * {@inheritDoc} */ public void setNextPageChildrenRunnable( StudioConnectionBulkRunnableWithProgress nextPageChildrenRunnable ) { if ( getDelegate() != null ) { getDelegate().setNextPageChildrenRunnable( nextPageChildrenRunnable ); } } /** * {@inheritDoc} */ public void setHasChildrenHint( boolean b ) { if ( getDelegate() != null ) { getDelegate().setHasChildrenHint( b ); } } /** * {@inheritDoc} */ public void setChildrenFilter( String filter ) { if ( getDelegate() != null ) { getDelegate().setChildrenFilter( filter ); } } /** * {@inheritDoc} */ public void setChildrenInitialized( boolean b ) { if ( !b ) { if ( getDelegate() != null ) { getDelegate().setChildrenInitialized( b ); } entryDoesNotExist = false; } else { if ( this.getDelegate() == null ) { setDelegate( getBrowserConnection().getEntryFromCache( dn ) ); if ( this.getDelegate() == null ) { // entry doesn't exist! entryDoesNotExist = true; } } if ( getDelegate() != null ) { getDelegate().setChildrenInitialized( b ); } } } /** * {@inheritDoc} */ public boolean isAlias() { if ( getDelegate() != null ) { return getDelegate().isAlias(); } else { return false; } } /** * {@inheritDoc} */ public void setAlias( boolean b ) { if ( getDelegate() != null ) { getDelegate().setAlias( b ); } } /** * {@inheritDoc} */ public boolean isReferral() { if ( getDelegate() != null ) { return getDelegate().isReferral(); } else { return false; } } /** * {@inheritDoc} */ public void setReferral( boolean b ) { if ( getDelegate() != null ) { getDelegate().setReferral( b ); } } /** * {@inheritDoc} */ public boolean isSubentry() { if ( getDelegate() != null ) { return getDelegate().isSubentry(); } else { return false; } } /** * {@inheritDoc} */ public void setSubentry( boolean b ) { if ( getDelegate() != null ) { getDelegate().setSubentry( b ); } } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( adapter == IBrowserConnection.class ) { return this.getBrowserConnection(); } if ( adapter == IEntry.class ) { return this; } return null; } /** * {@inheritDoc} */ public Collection<ObjectClass> getObjectClassDescriptions() { if ( getDelegate() != null ) { return getDelegate().getObjectClassDescriptions(); } else { return null; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/AbstractEntry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/AbstractEntry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.jobs.StudioConnectionBulkRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.events.AttributeAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.AttributeDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.ICompareableEntry; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Base implementation of the {@link IEntry} interface. * * The class is optimized to save memory. It doesn't hold members to * its children or attributes. Instead the {@link ChildrenInfo} and * {@link AttributeInfo} instances are stored in a map in the * {@link BrowserConnection} instance. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractEntry implements IEntry, ICompareableEntry { private static final long serialVersionUID = -2431637532526418774L; private static final int HAS_CHILDREN_HINT_FLAG = 1 << 0; private static final int IS_DIRECTORY_ENTRY_FLAG = 1 << 1; private static final int IS_ALIAS_FLAG = 1 << 2; private static final int IS_REFERRAL_FLAG = 1 << 3; private static final int IS_SUBENTRY_FLAG = 1 << 4; private static final int IS_INIT_OPERATIONAL_ATTRIBUTES_FLAG = 1 << 5; private static final int IS_FETCH_ALIASES_FLAG = 1 << 6; private static final int IS_FETCH_REFERRALS_FLAG = 1 << 7; private static final int IS_FETCH_SUBENTRIES_FLAG = 1 << 8; private volatile int flags; protected IAttribute objectClassAttribute; /** * Creates a new instance of AbstractEntry. */ protected AbstractEntry() { this.flags = HAS_CHILDREN_HINT_FLAG; } /** * Sets the parent entry. * * @param newParent the new parent entry */ protected abstract void setParent( IEntry newParent ); /** * Sets the Rdn. * * @param newRdn the new Rdn */ protected abstract void setRdn( Rdn newRdn ); /** * {@inheritDoc} */ public void addChild( IEntry childToAdd ) { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci == null ) { ci = new ChildrenInfo(); getBrowserConnectionImpl().setChildrenInfo( this, ci ); } if ( ci.childrenSet == null ) { ci.childrenSet = new LinkedHashSet<IEntry>(); } ci.childrenSet.add( childToAdd ); entryModified( new EntryAddedEvent( childToAdd.getBrowserConnection(), childToAdd ) ); } /** * {@inheritDoc} */ public void deleteChild( IEntry childToDelete ) { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci != null ) { if ( ci.childrenSet != null ) { ci.childrenSet.remove( childToDelete ); } if ( ci.childrenSet == null || ci.childrenSet.isEmpty() ) { getBrowserConnectionImpl().setChildrenInfo( this, null ); } entryModified( new EntryDeletedEvent( getBrowserConnectionImpl(), childToDelete ) ); } } /** * {@inheritDoc} */ public void addAttribute( IAttribute attributeToAdd ) throws IllegalArgumentException { if ( !equals( attributeToAdd.getEntry() ) ) { throw new IllegalArgumentException( BrowserCoreMessages.model__attributes_entry_is_not_myself ); } if ( attributeToAdd.isObjectClassAttribute() ) { if ( objectClassAttribute != null ) { throw new IllegalArgumentException( BrowserCoreMessages.model__attribute_already_exists ); } objectClassAttribute = attributeToAdd; } else { String oidString = attributeToAdd.getAttributeDescription() .toOidString( getBrowserConnection().getSchema() ); AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai == null ) { ai = new AttributeInfo(); getBrowserConnectionImpl().setAttributeInfo( this, ai ); } if ( ai.attributeMap.containsKey( Strings.toLowerCase( oidString ) ) ) { throw new IllegalArgumentException( BrowserCoreMessages.model__attribute_already_exists ); } ai.attributeMap.put( Strings.toLowerCase( oidString ), attributeToAdd ); } entryModified( new AttributeAddedEvent( getBrowserConnectionImpl(), this, attributeToAdd ) ); } /** * {@inheritDoc} */ public void deleteAttribute( IAttribute attributeToDelete ) throws IllegalArgumentException { if ( attributeToDelete.isObjectClassAttribute() ) { if ( objectClassAttribute == null ) { throw new IllegalArgumentException( BrowserCoreMessages.model__attribute_does_not_exist + ": " //$NON-NLS-1$ + attributeToDelete ); } objectClassAttribute = null; } else { String oidString = attributeToDelete.getAttributeDescription().toOidString( getBrowserConnection().getSchema() ); AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai != null && ai.attributeMap != null && ai.attributeMap.containsKey( Strings.toLowerCase( oidString ) ) ) { attributeToDelete = ( IAttribute ) ai.attributeMap.get( Strings.toLowerCase( oidString ) ); ai.attributeMap.remove( Strings.toLowerCase( oidString ) ); if ( ai.attributeMap.isEmpty() ) { getBrowserConnectionImpl().setAttributeInfo( this, null ); } } else { throw new IllegalArgumentException( BrowserCoreMessages.model__attribute_does_not_exist + ": " //$NON-NLS-1$ + attributeToDelete ); } } entryModified( new AttributeDeletedEvent( getBrowserConnectionImpl(), this, attributeToDelete ) ); } /** * {@inheritDoc} */ public void setDirectoryEntry( boolean isDirectoryEntry ) { if ( isDirectoryEntry ) { flags = flags | IS_DIRECTORY_ENTRY_FLAG; } else { flags = flags & ~IS_DIRECTORY_ENTRY_FLAG; } } /** * {@inheritDoc} */ public boolean isAlias() { if ( ( flags & IS_ALIAS_FLAG ) != 0 ) { return true; } AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai != null ) { return getObjectClassDescriptions().contains( getBrowserConnection().getSchema().getObjectClassDescription( SchemaConstants.ALIAS_OC ) ); } return false; } /** * {@inheritDoc} */ public void setAlias( boolean b ) { if ( b ) { flags = flags | IS_ALIAS_FLAG; } else { flags = flags & ~IS_ALIAS_FLAG; } } /** * {@inheritDoc} */ public boolean isReferral() { if ( ( flags & IS_REFERRAL_FLAG ) != 0 ) { return true; } AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai != null ) { return getObjectClassDescriptions().contains( getBrowserConnection().getSchema().getObjectClassDescription( SchemaConstants.REFERRAL_OC ) ); } return false; } /** * {@inheritDoc} */ public void setReferral( boolean b ) { if ( b ) { flags = flags | IS_REFERRAL_FLAG; } else { flags = flags & ~IS_REFERRAL_FLAG; } } /** * {@inheritDoc} */ public boolean isSubentry() { if ( ( flags & IS_SUBENTRY_FLAG ) != 0 ) { return true; } AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai != null ) { return getObjectClassDescriptions().contains( getBrowserConnection().getSchema().getObjectClassDescription( SchemaConstants.SUBENTRY_OC ) ); } return false; } /** * {@inheritDoc} */ public void setSubentry( boolean b ) { if ( b ) { flags = flags | IS_SUBENTRY_FLAG; } else { flags = flags & ~IS_SUBENTRY_FLAG; } } /** * Triggers firing of the modification event. * * @param event */ private void entryModified( EntryModificationEvent event ) { EventRegistry.fireEntryUpdated( event, this ); } /** * {@inheritDoc} */ public Rdn getRdn() { Rdn rdn = getDn().getRdn(); return rdn == null ? new Rdn() : rdn; } /** * {@inheritDoc} */ public boolean isAttributesInitialized() { AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); return ai != null && ai.attributesInitialized; } /** * {@inheritDoc} */ public void setAttributesInitialized( boolean b ) { AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai == null && b ) { ai = new AttributeInfo(); getBrowserConnectionImpl().setAttributeInfo( this, ai ); } if ( ai != null ) { ai.attributesInitialized = b; } if ( ai != null && !b ) { ai.attributeMap.clear(); getBrowserConnectionImpl().setAttributeInfo( this, null ); } entryModified( new AttributesInitializedEvent( this ) ); } /** * {@inheritDoc} */ public boolean isInitOperationalAttributes() { return ( flags & IS_INIT_OPERATIONAL_ATTRIBUTES_FLAG ) != 0; } /** * {@inheritDoc} */ public void setInitOperationalAttributes( boolean b ) { if ( b ) { flags = flags | IS_INIT_OPERATIONAL_ATTRIBUTES_FLAG; } else { flags = flags & ~IS_INIT_OPERATIONAL_ATTRIBUTES_FLAG; } } /** * {@inheritDoc} */ public boolean isFetchAliases() { return ( flags & IS_FETCH_ALIASES_FLAG ) != 0; } /** * {@inheritDoc} */ public void setFetchAliases( boolean b ) { if ( b ) { flags = flags | IS_FETCH_ALIASES_FLAG; } else { flags = flags & ~IS_FETCH_ALIASES_FLAG; } } /** * {@inheritDoc} */ public boolean isFetchReferrals() { return ( flags & IS_FETCH_REFERRALS_FLAG ) != 0; } /** * {@inheritDoc} */ public void setFetchReferrals( boolean b ) { if ( b ) { flags = flags | IS_FETCH_REFERRALS_FLAG; } else { flags = flags & ~IS_FETCH_REFERRALS_FLAG; } } /** * {@inheritDoc} */ public boolean isFetchSubentries() { return ( flags & IS_FETCH_SUBENTRIES_FLAG ) != 0; } /** * {@inheritDoc} */ public void setFetchSubentries( boolean b ) { if ( b ) { flags = flags | IS_FETCH_SUBENTRIES_FLAG; } else { flags = flags & ~IS_FETCH_SUBENTRIES_FLAG; } } /** * {@inheritDoc} */ public IAttribute[] getAttributes() { Collection<IAttribute> attributes = new HashSet<IAttribute>(); AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai != null && ai.attributeMap != null ) { attributes.addAll( ai.attributeMap.values() ); } if ( objectClassAttribute != null ) { attributes.add( objectClassAttribute ); } return attributes.toArray( new IAttribute[0] ); } /** * {@inheritDoc} */ public IAttribute getAttribute( String attributeDescription ) { AttributeDescription ad = new AttributeDescription( attributeDescription ); String oidString = ad.toOidString( getBrowserConnection().getSchema() ); if ( oidString.equals( SchemaConstants.OBJECT_CLASS_AT_OID ) || ( SchemaConstants.OBJECT_CLASS_AT.equalsIgnoreCase( attributeDescription ) ) ) { return objectClassAttribute; } else { AttributeInfo ai = getBrowserConnectionImpl().getAttributeInfo( this ); if ( ai == null || ai.attributeMap == null ) { return null; } else { return ( IAttribute ) ai.attributeMap.get( Strings.toLowerCase( oidString ) ); } } } /** * {@inheritDoc} */ public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) { List<IAttribute> attributeList = new ArrayList<IAttribute>(); IAttribute myAttribute = getAttribute( attributeDescription ); if ( myAttribute != null ) { attributeList.add( myAttribute ); } AttributeDescription ad = new AttributeDescription( attributeDescription ); IAttribute[] allAttributes = getAttributes(); for ( IAttribute attribute : allAttributes ) { AttributeDescription other = attribute.getAttributeDescription(); if ( other.isSubtypeOf( ad, getBrowserConnection().getSchema() ) ) { attributeList.add( attribute ); } } if ( attributeList.isEmpty() ) { return null; } else { IAttribute[] attributes = attributeList.toArray( new IAttribute[attributeList.size()] ); AttributeHierarchy ah = new AttributeHierarchy( this, attributeDescription, attributes ); return ah; } } /** * {@inheritDoc} */ public void setChildrenInitialized( boolean b ) { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci == null && b ) { ci = new ChildrenInfo(); getBrowserConnectionImpl().setChildrenInfo( this, ci ); } if ( ci != null ) { ci.childrenInitialized = b; } if ( ci != null && !b ) { if ( ci.childrenSet != null ) { ci.childrenSet.clear(); } getBrowserConnectionImpl().setChildrenInfo( this, null ); } entryModified( new ChildrenInitializedEvent( this ) ); } /** * {@inheritDoc} */ public boolean isChildrenInitialized() { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); return ci != null && ci.childrenInitialized; } /** * {@inheritDoc} */ public IEntry[] getChildren() { int count = getChildrenCount(); if ( count < 0 ) { return null; } else if ( count == 0 ) { return new IEntry[0]; } else { IEntry[] children = new IEntry[count]; ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); int i = 0; if ( ci.childrenSet != null ) { for ( IEntry child : ci.childrenSet ) { children[i] = child; i++; } } return children; } } /** * {@inheritDoc} */ public int getChildrenCount() { if ( isSubentry() ) { return 0; } ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci == null ) { return -1; } else { return ci.childrenSet == null ? 0 : ci.childrenSet.size(); } } /** * {@inheritDoc} */ public void setHasMoreChildren( boolean b ) { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci == null ) { ci = new ChildrenInfo(); getBrowserConnectionImpl().setChildrenInfo( this, ci ); } ci.hasMoreChildren = b; entryModified( new ChildrenInitializedEvent( this ) ); } /** * {@inheritDoc} */ public boolean hasMoreChildren() { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); return ci != null && ci.hasMoreChildren; } /** * {@inheritDoc} */ public void setTopPageChildrenRunnable( StudioConnectionBulkRunnableWithProgress topPageChildrenRunnable ) { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci == null && topPageChildrenRunnable != null ) { ci = new ChildrenInfo(); getBrowserConnectionImpl().setChildrenInfo( this, ci ); } if ( ci != null ) { ci.topPageChildrenRunnable = topPageChildrenRunnable; } } /** * {@inheritDoc} */ public StudioConnectionBulkRunnableWithProgress getTopPageChildrenRunnable() { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); return ci != null ? ci.topPageChildrenRunnable : null; } /** * {@inheritDoc} */ public void setNextPageChildrenRunnable( StudioConnectionBulkRunnableWithProgress nextPageChildrenRunnable ) { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); if ( ci == null && nextPageChildrenRunnable != null ) { ci = new ChildrenInfo(); getBrowserConnectionImpl().setChildrenInfo( this, ci ); } if ( ci != null ) { ci.nextPageChildrenRunnable = nextPageChildrenRunnable; } } /** * {@inheritDoc} */ public StudioConnectionBulkRunnableWithProgress getNextPageChildrenRunnable() { ChildrenInfo ci = getBrowserConnectionImpl().getChildrenInfo( this ); return ci != null ? ci.nextPageChildrenRunnable : null; } /** * {@inheritDoc} */ public void setHasChildrenHint( boolean b ) { if ( b ) { flags = flags | HAS_CHILDREN_HINT_FLAG; } else { flags = flags & ~HAS_CHILDREN_HINT_FLAG; } } /** * {@inheritDoc} */ public boolean hasChildren() { return ( flags & HAS_CHILDREN_HINT_FLAG ) != 0 || getChildrenCount() > 0; } /** * {@inheritDoc} */ public String getChildrenFilter() { return getBrowserConnectionImpl().getChildrenFilter( this ); } /** * {@inheritDoc} */ public void setChildrenFilter( String childrenFilter ) { getBrowserConnectionImpl().setChildrenFilter( this, childrenFilter ); } /** * {@inheritDoc} */ public boolean hasParententry() { return getParententry() != null; } /** * Gets the browser connection implementation. * * @return the browser connection implementation */ private BrowserConnection getBrowserConnectionImpl() { return ( BrowserConnection ) getBrowserConnection(); } /** * {@inheritDoc} */ public String toString() { return getDn().getName(); } /** * {@inheritDoc} */ public int hashCode() { return getDn().hashCode(); } /** * {@inheritDoc} */ public boolean equals( Object o ) { // check argument if ( !( o instanceof ICompareableEntry ) ) { return false; } ICompareableEntry e = ( ICompareableEntry ) o; // compare dn and connection if ( getDn() == null ) { return e.getDn() == null; } else { return getDn().equals( e.getDn() ) && getBrowserConnection().equals( e.getBrowserConnection() ); } } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( Connection.class ) ) { return getBrowserConnection().getConnection(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return getBrowserConnection(); } if ( clazz.isAssignableFrom( IEntry.class ) ) { return this; } return null; } /** * {@inheritDoc} */ public LdapUrl getUrl() { return Utils.getLdapURL( this ); } /** * {@inheritDoc} */ public Collection<ObjectClass> getObjectClassDescriptions() { Collection<ObjectClass> ocds = new ArrayList<ObjectClass>(); IAttribute ocAttribute = getAttribute( SchemaConstants.OBJECT_CLASS_AT ); if ( ocAttribute != null ) { String[] ocNames = ocAttribute.getStringValues(); Schema schema = getBrowserConnection().getSchema(); for ( String ocName : ocNames ) { ObjectClass ocd = schema.getObjectClassDescription( ocName ); ocds.add( ocd ); } } return ocds; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/SearchResult.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/SearchResult.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.impl; import java.util.ArrayList; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Default implementation of ISearchResult. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchResult implements ISearchResult { private static final long serialVersionUID = -5658803569872619432L; /** The search. */ private ISearch search; /** The entry. */ private IEntry entry; protected SearchResult() { } /** * Creates a new instance of SearchResult. * * @param entry the entry * @param search the search */ public SearchResult( IEntry entry, ISearch search ) { this.entry = entry; this.search = search; } /** * {@inheritDoc} */ public Dn getDn() { return entry.getDn(); } /** * {@inheritDoc} */ public IAttribute[] getAttributes() { ArrayList<IAttribute> attributeList = new ArrayList<IAttribute>(); for ( int i = 0; i < search.getReturningAttributes().length; i++ ) { if ( entry.getAttribute( search.getReturningAttributes()[i] ) != null ) { attributeList.add( entry.getAttribute( search.getReturningAttributes()[i] ) ); } } return attributeList.toArray( new IAttribute[attributeList.size()] ); } /** * {@inheritDoc} */ public IAttribute getAttribute( String attributeDescription ) { return entry.getAttribute( attributeDescription ); } /** * {@inheritDoc} */ public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) { return entry.getAttributeWithSubtypes( attributeDescription ); } /** * {@inheritDoc} */ public IEntry getEntry() { return entry; } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object getAdapter( Class adapter ) { Class<?> clazz = ( Class<?> ) adapter; if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) { return new LdapSearchPageScoreComputer(); } if ( clazz.isAssignableFrom( Connection.class ) ) { return search.getBrowserConnection().getConnection(); } if ( clazz.isAssignableFrom( IBrowserConnection.class ) ) { return search.getBrowserConnection(); } if ( clazz.isAssignableFrom( IEntry.class ) ) { return getEntry(); } return null; } /** * {@inheritDoc} */ public ISearch getSearch() { return search; } /** * {@inheritDoc} */ public void setSearch( ISearch search ) { this.search = search; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ( ( entry == null ) ? 0 : entry.getDn().hashCode() ); result = prime * result + ( ( search == null ) ? 0 : search.hashCode() ); return result; } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } if ( !( obj instanceof SearchResult ) ) { return false; } SearchResult other = ( SearchResult ) obj; if ( entry == null ) { if ( other.entry != null ) { return false; } } else if ( !entry.equals( other.entry ) ) { return false; } if ( search == null ) { if ( other.search != null ) { return false; } } else if ( !search.equals( other.search ) ) { return false; } return true; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; public class BinarySyntax { private String syntaxNumericOid; public BinarySyntax() { } public BinarySyntax( String syntaxNumericOid ) { this.syntaxNumericOid = syntaxNumericOid; } public String getSyntaxNumericOid() { return syntaxNumericOid; } public void setSyntaxNumericOid( String syntaxNumericOid ) { this.syntaxNumericOid = syntaxNumericOid; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassIconPair.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassIconPair.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; /** * A pair of object classes to the related icon. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassIconPair { /** The object classes numeric OIDs. */ private String[] objectClassNumericOIDs; /** The path to the icon. */ private String iconPath; /** * Creates a new instance of ObjectClassIconPair. */ public ObjectClassIconPair() { } /** * Creates a new instance of ObjectClassIconPair. * * @param objectClassNumericOIDs the object class numeric OIDs * @param iconPath the icon path */ public ObjectClassIconPair( String[] objectClassNumericOIDs, String iconPath ) { super(); this.objectClassNumericOIDs = objectClassNumericOIDs; this.iconPath = iconPath; } /** * Gets the object class numeric OIDs. * * @return the object class numeric OIDs */ public String[] getOcNumericOids() { return objectClassNumericOIDs; } /** * Sets the object class numeric OIDs. * * @param objectClassNumericOIDs the object class numeric OIDs */ public void setOcNumericOids( String[] objectClassNumericOIDs ) { this.objectClassNumericOIDs = objectClassNumericOIDs; } /** * Gets the icon path. * * @return the icon path */ public String getIconPath() { return iconPath; } /** * Sets the icon path. * * @param iconPath the new icon path */ public void setIconPath( String iconPath ) { this.iconPath = iconPath; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.Writer; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.MatchingRuleUse; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.UsageEnum; import org.apache.directory.api.ldap.model.schema.parsers.AttributeTypeDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.LdapSyntaxDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleUseDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.connection.core.Utils; import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription; import org.apache.directory.studio.ldifparser.LdifFormatParameters; import org.apache.directory.studio.ldifparser.model.LdifEnumeration; import org.apache.directory.studio.ldifparser.model.container.LdifContainer; import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord; import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine; import org.apache.directory.studio.ldifparser.parser.LdifParser; /** * The schema is the central access point to all schema information. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Schema { public static final String SCHEMA_FILTER = "(objectClass=subschema)"; //$NON-NLS-1$ public static final String RAW_SCHEMA_DEFINITION_LDIF_VALUE = "X-RAW-SCHEMA-DEFINITION"; //$NON-NLS-1$ public static final String DN_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.12"; //$NON-NLS-1$ public static final LdapSyntax DUMMY_LDAP_SYNTAX; static { DUMMY_LDAP_SYNTAX = new LdapSyntax( "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ } public static final HashMap<String, List<String>> DUMMY_EXTENSIONS; static { DUMMY_EXTENSIONS = new HashMap<String, List<String>>(); List<String> dummyValues = new ArrayList<String>(); dummyValues.add( "DUMMY" ); //$NON-NLS-1$ DUMMY_EXTENSIONS.put( "X-DUMMY", dummyValues ); //$NON-NLS-1$ } public static final Schema DEFAULT_SCHEMA; static { Schema defaultSchema = null; try { URL url = Schema.class.getClassLoader().getResource( "default_schema.ldif" ); //$NON-NLS-1$ InputStream is = url.openStream(); Reader reader = new InputStreamReader( is ); defaultSchema = new Schema(); defaultSchema.defaultSchema = true; defaultSchema.loadFromLdif( reader ); } catch ( Exception e ) { e.printStackTrace(); } DEFAULT_SCHEMA = defaultSchema; } private boolean defaultSchema = false; public boolean isDefault() { return this.defaultSchema; } private LdifContentRecord schemaRecord; private Dn dn; private String createTimestamp; private String modifyTimestamp; private Map<String, ObjectClass> ocdMapByNameOrNumericOid; private Map<String, AttributeType> atdMapByNameOrNumericOid; private Map<String, LdapSyntax> lsdMapByNumericOid; private Map<String, MatchingRule> mrdMapByNameOrNumericOid; private Map<String, MatchingRuleUse> mrudMapByNameOrNumericOid; /** * Creates a new instance of Schema. */ public Schema() { this.schemaRecord = null; this.dn = null; this.createTimestamp = null; this.modifyTimestamp = null; this.ocdMapByNameOrNumericOid = new HashMap<String, ObjectClass>(); this.atdMapByNameOrNumericOid = new HashMap<String, AttributeType>(); this.lsdMapByNumericOid = new HashMap<String, LdapSyntax>(); this.mrdMapByNameOrNumericOid = new HashMap<String, MatchingRule>(); this.mrudMapByNameOrNumericOid = new HashMap<String, MatchingRuleUse>(); } /** * Loads all schema elements from the given reader. The input must be in * LDIF format. * * @param reader the reader */ public void loadFromLdif( Reader reader ) { try { LdifParser parser = new LdifParser(); LdifEnumeration enumeration = parser.parse( reader ); while ( enumeration.hasNext() ) { LdifContainer container = enumeration.next(); if ( container instanceof LdifContentRecord ) { LdifContentRecord schemaRecord = ( LdifContentRecord ) container; parseSchemaRecord( schemaRecord ); } } } catch ( Exception e ) { // TODO: exception handling System.out.println( "Schema#loadFromLdif: " + e.toString() ); //$NON-NLS-1$ } } /** * Load all schema elements from the given schema record. * * @param schemaRecord the schema record */ public void loadFromRecord( LdifContentRecord schemaRecord ) { try { parseSchemaRecord( schemaRecord ); } catch ( Exception e ) { // TODO: exception handling System.out.println( "Schema#loadFromRecord: " + e.toString() ); //$NON-NLS-1$ } } /** * Saves the schema in LDIF format to the given writer. * * @param writer */ public void saveToLdif( Writer writer ) { try { writer.write( getSchemaRecord().toFormattedString( LdifFormatParameters.DEFAULT ) ); } catch ( Exception e ) { // TODO: exception handling System.out.println( "Schema#saveToLdif: " + e.toString() ); //$NON-NLS-1$ } } /** * Parses the schema record. * * @param schemaRecord the schema record * * @throws Exception the exception */ private void parseSchemaRecord( LdifContentRecord schemaRecord ) throws Exception { setSchemaRecord( schemaRecord ); setDn( new Dn( schemaRecord.getDnLine().getValueAsString() ) ); ObjectClassDescriptionSchemaParser ocdPparser = new ObjectClassDescriptionSchemaParser(); ocdPparser.setQuirksMode( true ); AttributeTypeDescriptionSchemaParser atdParser = new AttributeTypeDescriptionSchemaParser(); atdParser.setQuirksMode( true ); LdapSyntaxDescriptionSchemaParser lsdParser = new LdapSyntaxDescriptionSchemaParser(); lsdParser.setQuirksMode( true ); MatchingRuleDescriptionSchemaParser mrdParser = new MatchingRuleDescriptionSchemaParser(); mrdParser.setQuirksMode( true ); MatchingRuleUseDescriptionSchemaParser mrudParser = new MatchingRuleUseDescriptionSchemaParser(); mrudParser.setQuirksMode( true ); LdifAttrValLine[] lines = schemaRecord.getAttrVals(); for ( int i = 0; i < lines.length; i++ ) { LdifAttrValLine line = lines[i]; String attributeName = line.getUnfoldedAttributeDescription(); String value = line.getValueAsString(); List<String> ldifValues = new ArrayList<String>( 1 ); ldifValues.add( value ); try { if ( attributeName.equalsIgnoreCase( SchemaConstants.OBJECT_CLASSES_AT ) ) { ObjectClass ocd = ocdPparser.parse( value ); ocd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues ); addObjectClass( ocd ); } else if ( attributeName.equalsIgnoreCase( SchemaConstants.ATTRIBUTE_TYPES_AT ) ) { AttributeType atd = atdParser.parse( value ); atd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues ); addAttributeType( atd ); } else if ( attributeName.equalsIgnoreCase( SchemaConstants.LDAP_SYNTAXES_AT ) ) { LdapSyntax lsd = lsdParser.parse( value ); if ( StringUtils.isEmpty( lsd.getDescription() ) && Utils.getOidDescription( lsd.getOid() ) != null ) { lsd.setDescription( Utils.getOidDescription( lsd.getOid() ) ); } lsd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues ); addLdapSyntax( lsd ); } else if ( attributeName.equalsIgnoreCase( SchemaConstants.MATCHING_RULES_AT ) ) { MatchingRule mrd = mrdParser.parse( value ); mrd.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues ); addMatchingRule( mrd ); } else if ( attributeName.equalsIgnoreCase( SchemaConstants.MATCHING_RULE_USE_AT ) ) { MatchingRuleUse mrud = mrudParser.parse( value ); mrud.addExtension( RAW_SCHEMA_DEFINITION_LDIF_VALUE, ldifValues ); addMatchingRuleUse( mrud ); } else if ( attributeName.equalsIgnoreCase( SchemaConstants.CREATE_TIMESTAMP_AT ) ) { setCreateTimestamp( value ); } else if ( attributeName.equalsIgnoreCase( SchemaConstants.MODIFY_TIMESTAMP_AT ) ) { setModifyTimestamp( value ); } } catch ( Exception e ) { // TODO: exception handling System.out.println( "Error reading schema: " + attributeName + " = " + value ); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println( e.getMessage() ); } } for ( AttributeType atd : getAttributeTypeDescriptions() ) { // assume all received syntaxes in attributes are valid -> create pseudo syntaxes if missing String syntaxOid = atd.getSyntaxOid(); if ( syntaxOid != null && !hasLdapSyntaxDescription( syntaxOid ) ) { LdapSyntax lsd = new LdapSyntax( syntaxOid ); lsd.setDescription( Utils.getOidDescription( syntaxOid ) ); addLdapSyntax( lsd ); } // assume all received matching rules in attributes are valid -> create pseudo matching rules if missing String emr = atd.getEqualityOid(); String omr = atd.getOrderingOid(); String smr = atd.getSubstringOid(); checkMatchingRules( emr, omr, smr ); } // set extensibleObject may attributes ObjectClass extensibleObjectOcd = this.getObjectClassDescription( SchemaConstants.EXTENSIBLE_OBJECT_OC ); Collection<AttributeType> userAtds = SchemaUtils.getUserAttributeDescriptions( this ); Collection<String> atdNames = SchemaUtils.getNames( userAtds ); List<String> atdNames2 = new ArrayList<String>( atdNames ); extensibleObjectOcd.setMayAttributeTypeOids( atdNames2 ); } private void checkMatchingRules( String... matchingRules ) { for ( String matchingRule : matchingRules ) { if ( matchingRule != null && !hasMatchingRuleDescription( matchingRule ) ) { MatchingRule mrd = new MatchingRule( matchingRule ); mrd.addName( matchingRule ); addMatchingRule( mrd ); } } } /** * Gets the schema record. * * @return the schema record when the schema was created using the * loadFromLdif() method, null otherwise */ public LdifContentRecord getSchemaRecord() { return schemaRecord; } /** * Sets the schema record. * * @param schemaRecord the new schema record */ public void setSchemaRecord( LdifContentRecord schemaRecord ) { this.schemaRecord = schemaRecord; } /** * Gets the Dn of the schema record, may be null. * * @return the Dn of the schema record, may be null */ public Dn getDn() { return dn; } /** * Sets the Dn. * * @param dn the new Dn */ public void setDn( Dn dn ) { this.dn = dn; } /** * Gets the create timestamp of the schema record, may be null. * * @return the create timestamp of the schema record, may be null */ public String getCreateTimestamp() { return createTimestamp; } /** * Sets the creates the timestamp. * * @param createTimestamp the new creates the timestamp */ public void setCreateTimestamp( String createTimestamp ) { this.createTimestamp = createTimestamp; } /** * Gets the modify timestamp of the schema record, may be null. * * @return the modify timestamp of the schema record, may be null */ public String getModifyTimestamp() { return modifyTimestamp; } /** * Sets the modify timestamp. * * @param modifyTimestamp the new modify timestamp */ public void setModifyTimestamp( String modifyTimestamp ) { this.modifyTimestamp = modifyTimestamp; } ////////////////////// Object Class Description ////////////////////// /** * Adds the object class description. * * @param ocd the object class description */ private void addObjectClass( ObjectClass ocd ) { if ( ocd.getOid() != null ) { ocdMapByNameOrNumericOid.put( Strings.toLowerCase( ocd.getOid() ), ocd ); } if ( ocd.getNames() != null && !ocd.getNames().isEmpty() ) { for ( String ocdName : ocd.getNames() ) { ocdMapByNameOrNumericOid.put( Strings.toLowerCase( ocdName ), ocd ); } } } /** * Gets the object class descriptions. * * @return the object class descriptions */ public Collection<ObjectClass> getObjectClassDescriptions() { Set<ObjectClass> set = new HashSet<ObjectClass>( ocdMapByNameOrNumericOid.values() ); return set; } /** * Checks if an object class descriptions with the given name or OID exists. * * @param nameOrOid the name numeric OID of the object class description * * @return true if an object class description with the given name * or OID exists. */ public boolean hasObjectClassDescription( String nameOrOid ) { if ( nameOrOid != null ) { return ocdMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ); } return false; } /** * Returns the object class description of the given name. If no such * object exists the default or a dummy object class description is * returned. * * @param nameOrOid the name numeric OID of the object class description * * @return the object class description, or the default or a dummy */ public ObjectClass getObjectClassDescription( String nameOrOid ) { if ( ocdMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ) ) { return ocdMapByNameOrNumericOid.get( Strings.toLowerCase( nameOrOid ) ); } else if ( !isDefault() ) { return DEFAULT_SCHEMA.getObjectClassDescription( nameOrOid ); } else { // DUMMY List<String> names = new ArrayList<String>(); names.add( nameOrOid ); ObjectClass ocd = new ObjectClass( nameOrOid ); ocd.setNames( names ); ocd.setExtensions( DUMMY_EXTENSIONS ); return ocd; } } ////////////////////// Attribute Type Description ////////////////////// /** * Adds the attribute type description. * * @param atd the attribute type description */ private void addAttributeType( AttributeType atd ) { if ( atd.getOid() != null ) { atdMapByNameOrNumericOid.put( Strings.toLowerCase( atd.getOid() ), atd ); } if ( atd.getNames() != null && !atd.getNames().isEmpty() ) { for ( String atdName : atd.getNames() ) { atdMapByNameOrNumericOid.put( Strings.toLowerCase( atdName ), atd ); } } } /** * Gets the attribute type descriptions. * * @return the attribute type descriptions */ public Collection<AttributeType> getAttributeTypeDescriptions() { Set<AttributeType> set = new HashSet<AttributeType>( atdMapByNameOrNumericOid.values() ); return set; } /** * Checks if an attribute type descriptions with the given name or OID exists. * * @param nameOrOid the name numeric OID of the attribute type description * * @return true if an attribute type description with the given name * or OID exists. */ public boolean hasAttributeTypeDescription( String nameOrOid ) { if ( nameOrOid != null ) { return atdMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ); } return false; } /** * Returns the attribute type description of the given name. If no such * object exists the default or a dummy attribute type description is * returned. * * @param nameOrOid the name numeric OID of the attribute type description * * @return the attribute type description, or the default or a dummy */ public AttributeType getAttributeTypeDescription( String nameOrOid ) { AttributeDescription ad = new AttributeDescription( nameOrOid ); String attributeType = ad.getParsedAttributeType(); if ( atdMapByNameOrNumericOid.containsKey( Strings.toLowerCase( attributeType ) ) ) { return atdMapByNameOrNumericOid.get( Strings.toLowerCase( attributeType ) ); } else if ( !isDefault() ) { return DEFAULT_SCHEMA.getAttributeTypeDescription( attributeType ); } else { // DUMMY List<String> attributeTypes = new ArrayList<String>(); attributeTypes.add( attributeType ); AttributeType atd = new AttributeType( attributeType ); atd.setNames( attributeTypes ); atd.setUserModifiable( true ); atd.setUsage( UsageEnum.USER_APPLICATIONS ); atd.setExtensions( DUMMY_EXTENSIONS ); return atd; } } //////////////////////// LDAP Syntax Description //////////////////////// /** * Adds the LDAP syntax description. * * @param lsd the LDAP syntax description */ private void addLdapSyntax( LdapSyntax lsd ) { if ( lsd.getOid() != null ) { lsdMapByNumericOid.put( Strings.toLowerCase( lsd.getOid() ), lsd ); } } /** * Gets the LDAP syntax descriptions. * * @return the LDAP syntax descriptions */ public Collection<LdapSyntax> getLdapSyntaxDescriptions() { Set<LdapSyntax> set = new HashSet<LdapSyntax>( lsdMapByNumericOid.values() ); return set; } /** * Checks if an LDAP syntax descriptions with the given OID exists. * * @param numericOid the numeric OID of the LDAP syntax description * * @return true if an LDAP syntax description with the given OID exists. */ public boolean hasLdapSyntaxDescription( String numericOid ) { if ( numericOid != null ) { return lsdMapByNumericOid.containsKey( Strings.toLowerCase( numericOid ) ); } return false; } /** * Returns the syntax description of the given OID. If no such object * exists the default or a dummy syntax description is returned. * * @param numericOid the numeric OID of the LDAP syntax description * * @return the attribute type description or the default or a dummy */ public LdapSyntax getLdapSyntaxDescription( String numericOid ) { if ( numericOid == null ) { return DUMMY_LDAP_SYNTAX; } else if ( lsdMapByNumericOid.containsKey( Strings.toLowerCase( numericOid ) ) ) { return lsdMapByNumericOid.get( Strings.toLowerCase( numericOid ) ); } else if ( !isDefault() ) { return DEFAULT_SCHEMA.getLdapSyntaxDescription( numericOid ); } else { // DUMMY LdapSyntax lsd = new LdapSyntax( numericOid ); lsd.setExtensions( DUMMY_EXTENSIONS ); return lsd; } } ////////////////////////// Matching Rule Description ////////////////////////// /** * Adds the matching rule description. * * @param mrud the matching rule description */ private void addMatchingRule( MatchingRule mrd ) { if ( mrd.getOid() != null ) { mrdMapByNameOrNumericOid.put( Strings.toLowerCase( mrd.getOid() ), mrd ); } if ( mrd.getNames() != null && !mrd.getNames().isEmpty() ) { for ( String mrdName : mrd.getNames() ) { mrdMapByNameOrNumericOid.put( Strings.toLowerCase( mrdName ), mrd ); } } } /** * Gets the matching rule descriptions. * * @return the matching rule descriptions */ public Collection<MatchingRule> getMatchingRuleDescriptions() { Set<MatchingRule> set = new HashSet<MatchingRule>( mrdMapByNameOrNumericOid.values() ); return set; } /** * Checks if an matching rule descriptions with the given name or OID exists. * * @param nameOrOid the name numeric OID of the matching rule description * * @return true if a matching rule description with the given name * or OID exists. */ public boolean hasMatchingRuleDescription( String nameOrOid ) { if ( nameOrOid != null ) { return mrdMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ); } return false; } /** * Returns the matching rule description of the given name or OID. If no * such object exists the default or a dummy matching rule description * is returned. * * @param nameOrOid the name or numeric OID of the matching rule description * * @return the matching rule description or the default or a dummy */ public MatchingRule getMatchingRuleDescription( String nameOrOid ) { if ( mrdMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ) ) { return mrdMapByNameOrNumericOid.get( Strings.toLowerCase( nameOrOid ) ); } else if ( !isDefault() ) { return DEFAULT_SCHEMA.getMatchingRuleDescription( nameOrOid ); } else { // DUMMY MatchingRule mrd = new MatchingRule( nameOrOid ); mrd.setExtensions( DUMMY_EXTENSIONS ); return mrd; } } //////////////////////// Matching Rule Use Description //////////////////////// /** * Adds the matching rule use description. * * @param mrud the matching rule use description */ private void addMatchingRuleUse( MatchingRuleUse mrud ) { if ( mrud.getOid() != null ) { mrudMapByNameOrNumericOid.put( Strings.toLowerCase( mrud.getOid() ), mrud ); } if ( mrud.getNames() != null && !mrud.getNames().isEmpty() ) { for ( String mrudName : mrud.getNames() ) { mrudMapByNameOrNumericOid.put( Strings.toLowerCase( mrudName ), mrud ); } } } /** * Gets the matching rule use descriptions. * * @return the matching rule use descriptions */ public Collection<MatchingRuleUse> getMatchingRuleUseDescriptions() { Set<MatchingRuleUse> set = new HashSet<MatchingRuleUse>( mrudMapByNameOrNumericOid .values() ); return set; } /** * Checks if an matching rule use descriptions with the given name or OID exists. * * @param nameOrOid the name numeric OID of the matching rule use description * * @return true if a matching rule use description with the given name * or OID exists. */ public boolean hasMatchingRuleUseDescription( String nameOrOid ) { if ( nameOrOid != null ) { return mrudMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ); } return false; } /** * Returns the matching rule use description of the given name or OID. If no * such object exists the default or a dummy matching rule use description * is returned. * * @param nameOrOid the name or numeric OID of the matching rule use description * * @return the matching rule use description or the default or a dummy */ public MatchingRuleUse getMatchingRuleUseDescription( String nameOrOid ) { if ( mrudMapByNameOrNumericOid.containsKey( Strings.toLowerCase( nameOrOid ) ) ) { return mrudMapByNameOrNumericOid.get( Strings.toLowerCase( nameOrOid ) ); } else if ( !isDefault() ) { return DEFAULT_SCHEMA.getMatchingRuleUseDescription( nameOrOid ); } else { // DUMMY MatchingRuleUse mrud = new MatchingRuleUse( nameOrOid ); mrud.setExtensions( DUMMY_EXTENSIONS ); return mrud; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; /** * Bean class to store the numeric OID or the name of a binary attribute. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BinaryAttribute { private String attributeNumericOidOrName; /** * Creates a new instance of BinaryAttribute. */ public BinaryAttribute() { } /** * Creates a new instance of BinaryAttribute. * * @param attributeNumericOidOrName the attribute numeric oid or name */ public BinaryAttribute( String attributeNumericOidOrName ) { this.attributeNumericOidOrName = attributeNumericOidOrName; } /** * Gets the attribute numeric OID or name. * * @return the attribute numeric OID or name */ public String getAttributeNumericOidOrName() { return attributeNumericOidOrName; } /** * Sets the attribute numeric OID or name. * * @param attributeNumericOidOrName the new attribute numeric OID or name */ public void setAttributeNumericOidOrName( String attributeNumericOidOrName ) { this.attributeNumericOidOrName = attributeNumericOidOrName; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Messages.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SyntaxValueEditorRelation.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SyntaxValueEditorRelation.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; /** * A SyntaxValueEditorRelation is used to set the relation * from a syntax to its value editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SyntaxValueEditorRelation { /** The syntax OID. */ private String syntaxOID; private String valueEditorClassName; /** * Creates a new instance of SyntaxValueEditorRelation. */ public SyntaxValueEditorRelation() { } /** * Creates a new instance of SyntaxValueEditorRelation. * * @param syntaxOID the syntax OID * @param valueEditorClassName the value editor class name */ public SyntaxValueEditorRelation( String syntaxOID, String valueEditorClassName ) { this.syntaxOID = syntaxOID; this.valueEditorClassName = valueEditorClassName; } /** * Gets the syntax OID. * * @return the syntax OID */ public String getSyntaxOID() { return syntaxOID; } /** * Sets the syntax OID. * * @param syntaxOID the new syntax OID */ public void setSyntaxOID( String syntaxOID ) { this.syntaxOID = syntaxOID; } /** * Gets the value editor class name. * * @return the value editor class name */ public String getValueEditorClassName() { return valueEditorClassName; } /** * Sets the value editor class name. * * @param valueEditorClassName the new value editor class name */ public void setValueEditorClassName( String valueEditorClassName ) { this.valueEditorClassName = valueEditorClassName; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueEditorRelation.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueEditorRelation.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; /** * An AttributeValueEditorRelation is used to set the relation * from an attribute type to its value editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeValueEditorRelation { /** The attribute, either the numeric OID or type. */ private String attributeNumericOidOrType; /** The value editor class name. */ private String valueEditorClassName; /** * Creates a new instance of AttributeValueEditorRelation. */ public AttributeValueEditorRelation() { } /** * Creates a new instance of AttributeValueEditorRelation. * * @param attributeNumericOidOrName the attribute numeric OID or name * @param valueEditorClassName the value editor class name */ public AttributeValueEditorRelation( String attributeNumericOidOrName, String valueEditorClassName ) { this.attributeNumericOidOrType = attributeNumericOidOrName; this.valueEditorClassName = valueEditorClassName; } /** * Gets the attribute numeric OID or type. * * @return the attribute numeric OID or type */ public String getAttributeNumericOidOrType() { return attributeNumericOidOrType; } /** * Sets the attribute numeric OID or type. * * @param attributeNumericOidOrType the new attribute numeric OID or type */ public void setAttributeNumericOidOrType( String attributeNumericOidOrType ) { this.attributeNumericOidOrType = attributeNumericOidOrType; } /** * Gets the value editor class name. * * @return the value editor class name */ public String getValueEditorClassName() { return valueEditorClassName; } /** * Sets the value editor class name. * * @param valueEditorClassName the new value editor class name */ public void setValueEditorClassName( String valueEditorClassName ) { this.valueEditorClassName = valueEditorClassName; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaUtils.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.model.schema; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; import org.apache.commons.collections4.CollectionUtils; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.schema.AbstractSchemaObject; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.MatchingRuleUse; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum; import org.apache.directory.api.ldap.model.schema.UsageEnum; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.eclipse.osgi.util.NLS; /** * Utility class for Schema. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaUtils { /** The well-known operational attributes */ public static final Set<String> OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES = new HashSet<String>(); static { OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATE_TIMESTAMP_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATE_TIMESTAMP_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATORS_NAME_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATORS_NAME_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFY_TIMESTAMP_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFY_TIMESTAMP_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFIERS_NAME_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFIERS_NAME_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.SUBSCHEMA_SUBENTRY_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.STRUCTURAL_OBJECT_CLASS_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES .add( Strings.toLowerCase( SchemaConstants.STRUCTURAL_OBJECT_CLASS_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.GOVERNING_STRUCTURE_RULE_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings .toLowerCase( SchemaConstants.GOVERNING_STRUCTURE_RULE_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_UUID_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_UUID_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_CSN_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_CSN_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_DN_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_DN_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.OBJECT_CLASSES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.OBJECT_CLASSES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ATTRIBUTE_TYPES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ATTRIBUTE_TYPES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.LDAP_SYNTAXES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.LDAP_SYNTAXES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MATCHING_RULES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MATCHING_RULES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MATCHING_RULE_USE_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MATCHING_RULE_USE_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.DIT_CONTENT_RULES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.DIT_CONTENT_RULES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.DIT_STRUCTURE_RULES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.DIT_STRUCTURE_RULES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.NAME_FORMS_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.NAME_FORMS_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.HAS_SUBORDINATES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.HAS_SUBORDINATES_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.NUM_SUBORDINATES_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.SUBORDINATE_COUNT_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_NAME_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_NAME_AT_OID ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_VERSION_AT ) ); OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_VERSION_AT_OID ) ); } /** The well-known non-modifiable attributes */ public static final Set<String> NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES = new HashSet<String>(); static { NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATE_TIMESTAMP_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATE_TIMESTAMP_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATORS_NAME_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.CREATORS_NAME_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFY_TIMESTAMP_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFY_TIMESTAMP_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFIERS_NAME_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.MODIFIERS_NAME_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.SUBSCHEMA_SUBENTRY_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.STRUCTURAL_OBJECT_CLASS_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES .add( Strings.toLowerCase( SchemaConstants.STRUCTURAL_OBJECT_CLASS_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.GOVERNING_STRUCTURE_RULE_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings .toLowerCase( SchemaConstants.GOVERNING_STRUCTURE_RULE_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_UUID_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_UUID_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_CSN_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_CSN_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_DN_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.ENTRY_DN_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.HAS_SUBORDINATES_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.HAS_SUBORDINATES_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.NUM_SUBORDINATES_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.SUBORDINATE_COUNT_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_NAME_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_NAME_AT_OID ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_VERSION_AT ) ); NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES.add( Strings.toLowerCase( SchemaConstants.VENDOR_VERSION_AT_OID ) ); } private static final Comparator<String> nameAndOidComparator = new Comparator<String>() { public int compare( String s1, String s2 ) { return s1.compareToIgnoreCase( s2 ); } }; private static final Comparator<AbstractSchemaObject> schemaElementNameComparator = new Comparator<AbstractSchemaObject>() { public int compare( AbstractSchemaObject s1, AbstractSchemaObject s2 ) { return SchemaUtils.toString( s1 ).compareToIgnoreCase( SchemaUtils.toString( s2 ) ); } }; /** * Gets the names of the given schema elements. * * @param asds the schema elements * * @return the names */ public static Collection<String> getNames( Collection<? extends AbstractSchemaObject> asds ) { Set<String> nameSet = new TreeSet<String>( nameAndOidComparator ); for ( AbstractSchemaObject asd : asds ) { nameSet.addAll( asd.getNames() ); } return nameSet; } /** * Gets the names of the given schema elements. * * @param asds the schema elements * * @return the names */ public static String[] getNamesAsArray( Collection<? extends AbstractSchemaObject> asds ) { return getNames( asds ).toArray( new String[0] ); } /** * Get the numeric OIDs of the given schema descriptions. * * @return the numeric OIDs of the given schema descriptions */ public static Collection<String> getNumericOids( Collection<? extends AbstractSchemaObject> descriptions ) { Set<String> oids = new HashSet<String>(); for ( AbstractSchemaObject asd : descriptions ) { oids.add( asd.getOid() ); } return oids; } /** * Gets the identifiers of the given schema descriptions. * * @param asd the schema descriptions * * @return the identifiers */ public static Collection<String> getLowerCaseIdentifiers( AbstractSchemaObject asd ) { Set<String> identiers = new HashSet<String>(); if ( asd.getOid() != null ) { identiers.add( Strings.toLowerCase( asd.getOid() ) ); } if ( asd.getNames() != null && !asd.getNames().isEmpty() ) { for ( String name : asd.getNames() ) { if ( name != null ) { identiers.add( Strings.toLowerCase( name ) ); } } } return identiers; } /** * Gets the friendly identifier of the given schema description. * This is the first name, if there is no name the numeric OID is returned. * * @param asd the schema description * * @return the friendly identifier */ public static String getFriendlyIdentifier( AbstractSchemaObject asd ) { if ( asd.getNames() != null && !asd.getNames().isEmpty() ) { return asd.getNames().get( 0 ); } return asd.getOid(); } /** * Gets all operational attribute type descriptions. * * @param schema the schema * * @return all operational attributes types */ public static Collection<AttributeType> getOperationalAttributeDescriptions( Schema schema ) { Set<AttributeType> operationalAtds = new HashSet<AttributeType>(); for ( AttributeType atd : schema.getAttributeTypeDescriptions() ) { if ( isOperational( atd ) ) { operationalAtds.add( atd ); } } return operationalAtds; } /** * Gets all user (non-operational) attribute type descriptions. * * @param schema the schema * * @return all user attributes type descriptions */ public static Collection<AttributeType> getUserAttributeDescriptions( Schema schema ) { Set<AttributeType> userAtds = new HashSet<AttributeType>(); for ( AttributeType atd : schema.getAttributeTypeDescriptions() ) { if ( !isOperational( atd ) ) { userAtds.add( atd ); } } return userAtds; } /** * An attribute type is marked as operational if either * <ul> * <li>the usage differs from userApplications or</li> * <li>it is a well-known operational attribute or * (we need this because M$ AD and Samba4 don't set the USAGE flag)</li> * <li>it is not declared in the schema and contains the dummy extension</li> * </ul> * * @param atd the attribute type description * * @return true, if is operational */ public static boolean isOperational( AttributeType atd ) { return !UsageEnum.USER_APPLICATIONS.equals( atd.getUsage() ) || Schema.DUMMY_EXTENSIONS.equals( atd.getExtensions() ) || CollectionUtils.containsAny( OPERATIONAL_ATTRIBUTES_OIDS_AND_NAMES, getLowerCaseIdentifiers( atd ) ); } public static boolean isModifiable( AttributeType atd ) { if ( atd == null ) { return false; } if ( !atd.isUserModifiable() ) { return false; } // Check some default no-user-modification attributes // e.g. Siemens DirX doesn't provide a good schema. // TODO: make default no-user-modification attributes configurable if ( CollectionUtils.containsAny( NON_MODIFIABLE_ATTRIBUTE_OIDS_AND_NAMES, getLowerCaseIdentifiers( atd ) ) ) { return false; } return true; } /** * Gets the must attribute type descriptions of all object class descriptions of the given entry. * * param entry the entry * * @return the must attribute type descriptions of all object class descriptions of the given entry. */ public static Collection<AttributeType> getMustAttributeTypeDescriptions( IEntry entry ) { Schema schema = entry.getBrowserConnection().getSchema(); Collection<AttributeType> atds = new HashSet<AttributeType>(); Collection<ObjectClass> ocds = entry.getObjectClassDescriptions(); if ( ocds != null ) { for ( ObjectClass ocd : entry.getObjectClassDescriptions() ) { Collection<String> musts = getMustAttributeTypeDescriptionNamesTransitive( ocd, schema ); for ( String must : musts ) { AttributeType atd = schema.getAttributeTypeDescription( must ); atds.add( atd ); } } } return atds; } /** * Gets the may attribute type descriptions of all object class descriptions of the given entry. * * @param entry the entry * * @return the may attribute type descriptions of all object class descriptions of the given entry. */ public static Collection<AttributeType> getMayAttributeTypeDescriptions( IEntry entry ) { Schema schema = entry.getBrowserConnection().getSchema(); Collection<AttributeType> atds = new HashSet<AttributeType>(); Collection<ObjectClass> ocds = entry.getObjectClassDescriptions(); if ( ocds != null ) { for ( ObjectClass ocd : entry.getObjectClassDescriptions() ) { Collection<String> mays = getMayAttributeTypeDescriptionNamesTransitive( ocd, schema ); for ( String may : mays ) { AttributeType atd = schema.getAttributeTypeDescription( may ); atds.add( atd ); } } } return atds; } /** * Gets all attribute type descriptions of all object class descriptions of the given entry. * * @param entry the entry * * @return all attribute type descriptions of all object class descriptions of the given entry. */ public static Collection<AttributeType> getAllAttributeTypeDescriptions( IEntry entry ) { Collection<AttributeType> atds = new HashSet<AttributeType>(); atds.addAll( getMustAttributeTypeDescriptions( entry ) ); atds.addAll( getMayAttributeTypeDescriptions( entry ) ); return atds; } //////////////////////////////////////////////////////// /** * Checks the pre-defined and user-defined binary syntax OIDs. If this * syntax OID is defined as binary, false is returned.. * * @param lsd the LDAP syntax description * * @return false if the syntax is defined as binary */ public static boolean isString( LdapSyntax lsd ) { return !isBinary( lsd ); } /** * Checks the pre-defined and user-defined binary syntax OIDs. If this * syntax OID is defined as binary, true is returned.. * * @param lsd the LDAP syntax description * * @return true if the syntax is defined as binary */ public static boolean isBinary( LdapSyntax lsd ) { // check user-defined binary syntaxes Set<String> binarySyntaxOids = BrowserCorePlugin.getDefault().getCorePreferences() .getUpperCasedBinarySyntaxOids(); return binarySyntaxOids.contains( lsd.getOid().toUpperCase() ); } /** * Checks the pre-defined and user-defined binary attribute types. If this * attribute type is defined as binary, false is returned.. * * @param atd the attribute type description * @param schema the schema * * @return false if the attribute type is defined as binary */ public static boolean isString( AttributeType atd, Schema schema ) { return !isBinary( atd, schema ); } /** * Checks the pre-defined and user-defined binary attribute types. If this * attribute type is defined as binary, true is returned.. * * @param atd the attribute type description * @param schema the schema * * @return true if the attribute type is defined as binary */ public static boolean isBinary( AttributeType atd, Schema schema ) { // check user-defined binary attribute types Set<String> binaryAttributeOidsAndNames = BrowserCorePlugin.getDefault().getCorePreferences() .getUpperCasedBinaryAttributeOidsAndNames(); if ( binaryAttributeOidsAndNames.contains( atd.getOid().toUpperCase() ) ) { return true; } for ( String name : atd.getNames() ) { if ( binaryAttributeOidsAndNames.contains( name.toUpperCase() ) ) { return true; } } // check user-defined binary syntaxes String syntax = getSyntaxNumericOidTransitive( atd, schema ); if ( syntax != null && schema.hasLdapSyntaxDescription( syntax ) ) { LdapSyntax lsd = schema.getLdapSyntaxDescription( syntax ); return isBinary( lsd ); } return false; } /** * Gets all attribute type descriptions using the given syntax description. * * @param lsd the LDAP syntax description * @param schema the schema * * @return all attribute type description using this syntax description */ public static Collection<AttributeType> getUsedFromAttributeTypeDescriptions( LdapSyntax lsd, Schema schema ) { Set<AttributeType> usedFroms = new TreeSet<AttributeType>( schemaElementNameComparator ); for ( AttributeType atd : schema.getAttributeTypeDescriptions() ) { String syntax = getSyntaxNumericOidTransitive( atd, schema ); if ( syntax != null && lsd.getOid() != null && Strings.toLowerCase( syntax ).equals( Strings.toLowerCase( lsd.getOid() ) ) ) { usedFroms.add( atd ); } } return usedFroms; } /** * Gets all attribute type descriptions using the given matching rule description. * * @param mrd the matching rule description * @param schema the schema * * @return all attribute type descriptions using this matching rule for * equality, substring or ordering matching */ public static Collection<AttributeType> getUsedFromAttributeTypeDescriptions( MatchingRule mrd, Schema schema ) { Set<AttributeType> usedFromSet = new TreeSet<AttributeType>( schemaElementNameComparator ); for ( AttributeType atd : schema.getAttributeTypeDescriptions() ) { Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers( mrd ); String emr = getEqualityMatchingRuleNameOrNumericOidTransitive( atd, schema ); String smr = getSubstringMatchingRuleNameOrNumericOidTransitive( atd, schema ); String omr = getOrderingMatchingRuleNameOrNumericOidTransitive( atd, schema ); if ( emr != null && lowerCaseIdentifiers.contains( Strings.toLowerCase( emr ) ) ) { usedFromSet.add( atd ); } if ( smr != null && lowerCaseIdentifiers.contains( Strings.toLowerCase( smr ) ) ) { usedFromSet.add( atd ); } if ( omr != null && lowerCaseIdentifiers.contains( Strings.toLowerCase( omr ) ) ) { usedFromSet.add( atd ); } } return usedFromSet; } /** * Gets the equality matching rule description name or OID of the given or the * superior attribute type description. * * @param atd the attribute type description * @param schema the schema * * @return the equality matching rule description name or OID of the given or the * superior attribute type description, may be null */ public static String getEqualityMatchingRuleNameOrNumericOidTransitive( AttributeType atd, Schema schema ) { if ( atd.getEqualityOid() != null ) { return atd.getEqualityOid(); } if ( atd.getSuperiorOid() != null && schema.hasAttributeTypeDescription( atd.getSuperiorOid() ) ) { AttributeType superior = schema.getAttributeTypeDescription( atd.getSuperiorOid() ); return getEqualityMatchingRuleNameOrNumericOidTransitive( superior, schema ); } return null; } /** * Gets the substring matching rule description name or OID of the given or the * superior attribute type description. * * @param atd the attribute type description * @param schema the schema * * @return the substring matching rule description name or OID of the given or the * superior attribute type description, may be null */ public static String getSubstringMatchingRuleNameOrNumericOidTransitive( AttributeType atd, Schema schema ) { if ( atd.getSubstringOid() != null ) { return atd.getSubstringOid(); } if ( atd.getSuperiorOid() != null && schema.hasAttributeTypeDescription( atd.getSubstringOid() ) ) { AttributeType superior = schema.getAttributeTypeDescription( atd.getSubstringOid() ); return getSubstringMatchingRuleNameOrNumericOidTransitive( superior, schema ); } return null; } /** * Gets the ordering matching rule description name or OID of the given or the * superior attribute type description. * * @param atd the attribute type description * @param schema the schema * * @return the ordering matching rule description name or OID of the given or the * superior attribute type description, may be null */ public static String getOrderingMatchingRuleNameOrNumericOidTransitive( AttributeType atd, Schema schema ) { if ( atd.getOrderingOid() != null ) { return atd.getOrderingOid(); } if ( atd.getSuperiorOid() != null && schema.hasAttributeTypeDescription( atd.getSuperiorOid() ) ) { AttributeType superior = schema.getAttributeTypeDescription( atd.getSuperiorOid() ); return getOrderingMatchingRuleNameOrNumericOidTransitive( superior, schema ); } return null; } /** * Gets the syntax description OID of the given or the * superior attribute type description. * * @param atd the attribute type description * @param schema the schema * * @return the syntax description OID of the given or the * superior attribute type description, may be null */ public static String getSyntaxNumericOidTransitive( AttributeType atd, Schema schema ) { if ( atd.getSyntaxOid() != null ) { return atd.getSyntaxOid(); } if ( atd.getSuperiorOid() != null && schema.hasAttributeTypeDescription( atd.getSuperiorOid() ) ) { AttributeType superior = schema.getAttributeTypeDescription( atd.getSuperiorOid() ); return getSyntaxNumericOidTransitive( superior, schema ); } return null; } /** * Gets the syntax length of the given or the * superior attribute type description. * * @param atd the attribute type description * @param schema the schema * * @return the syntax length of the given or the * superior attribute type description, may be null */ public static long getSyntaxLengthTransitive( AttributeType atd, Schema schema ) { if ( atd.getSyntaxLength() != 0 ) { return atd.getSyntaxLength(); } if ( atd.getSuperiorOid() != null && schema.hasAttributeTypeDescription( atd.getSuperiorOid() ) ) { AttributeType superior = schema.getAttributeTypeDescription( atd.getSuperiorOid() ); return getSyntaxLengthTransitive( superior, schema ); } return -1; } /** * Gets all matching rule description names the given attribute type * description applies to according to the schema's matchin rul use * descritpions. * * @param atd the attribute type description * @param schema the schema * * @return all matching rule description names this attribute type * description applies to according to the schema's matching * rule use descriptions */ public static Collection<String> getOtherMatchingRuleDescriptionNames( AttributeType atd, Schema schema ) { Set<String> otherMatchingRules = new TreeSet<String>( nameAndOidComparator ); for ( MatchingRuleUse mrud : schema.getMatchingRuleUseDescriptions() ) { Collection<String> atdSet = toLowerCaseSet( mrud.getApplicableAttributeOids() ); if ( atdSet.removeAll( getLowerCaseIdentifiers( atd ) ) ) { otherMatchingRules.addAll( mrud.getNames() ); } } return otherMatchingRules; } /** * Gets all attribute type descriptions using the given attribute type * descriptions as superior. * * @param atd the attribute type description * @param schema the schema * * @return all attribute type descriptions using this attribute type * description as superior */ public static Collection<AttributeType> getDerivedAttributeTypeDescriptions( AttributeType atd, Schema schema ) { Set<AttributeType> derivedAtds = new TreeSet<AttributeType>( schemaElementNameComparator ); for ( AttributeType derivedAtd : schema.getAttributeTypeDescriptions() ) { String superType = derivedAtd.getSuperiorOid(); if ( superType != null && getLowerCaseIdentifiers( atd ).contains( Strings.toLowerCase( superType ) ) ) { derivedAtds.add( derivedAtd ); } } return derivedAtds; } /** * Gets all object class description using the given attribute type * description as must attribute. * * @param atd the attribute type description * @param schema the schema * * @return all object class description using the given attribute type * description as must attribute */ public static Collection<ObjectClass> getUsedAsMust( AttributeType atd, Schema schema ) { Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers( atd ); Set<ObjectClass> ocds = new TreeSet<ObjectClass>( schemaElementNameComparator ); for ( ObjectClass ocd : schema.getObjectClassDescriptions() ) { Collection<String> mustSet = toLowerCaseSet( getMustAttributeTypeDescriptionNamesTransitive( ocd, schema ) ); if ( mustSet.removeAll( lowerCaseIdentifiers ) ) { ocds.add( ocd ); } } return ocds; } /** * Gets all object class description using the given attribute type * description as may attribute. * * @param atd the attribute type description * @param schema the schema * * @return all object class description using the given attribute type * description as may attribute */ public static Collection<ObjectClass> getUsedAsMay( AttributeType atd, Schema schema ) { Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers( atd ); Set<ObjectClass> ocds = new TreeSet<ObjectClass>( schemaElementNameComparator );
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/SchemaObjectLoader.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/SchemaObjectLoader.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; /** * A class exposing some common methods on the schema. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaObjectLoader { /** The browser connection */ private IBrowserConnection browserConnection; /** The array of attributes names and OIDs */ private String[] attributeNamesAndOids; /** The array of ObjectClasses and OIDs */ private String[] objectClassesAndOids; /** * An interface to allow the getSchemaObjectNamesAndOid() to be called for any schema object */ private interface SchemaAdder { /** * Adds the schema object names and OIDs to the given set. * * @param schema the schema * @param schemaObjectNamesList the schema object names list * @param oidsList the OIDs name list */ void add( Schema schema, List<String> schemaObjectNamesList, List<String> oidsList ); } /** * Gets the array containing the objectClass names and OIDs. * * @return the array containing the objectClass names and OIDs */ public String[] getObjectClassNamesAndOids() { objectClassesAndOids = getSchemaObjectsAnddOids( objectClassesAndOids, new SchemaAdder() { @Override public void add( Schema schema, List<String> objectClassNamesList, List<String> oidsList ) { if ( schema != null ) { for ( ObjectClass ocd : schema.getObjectClassDescriptions() ) { // OID if ( !oidsList.contains( ocd.getOid() ) ) { oidsList.add( ocd.getOid() ); } // Names for ( String name : ocd.getNames() ) { if ( !objectClassNamesList.contains( name ) ) { objectClassNamesList.add( name ); } } } } } }); return objectClassesAndOids; } /** * Gets the array containing the attribute names and OIDs. * * @return the array containing the attribute names and OIDs */ public String[] getAttributeNamesAndOids() { attributeNamesAndOids = getSchemaObjectsAnddOids( attributeNamesAndOids, new SchemaAdder() { @Override public void add( Schema schema, List<String> attributeNamesList, List<String> oidsList ) { if ( schema != null ) { for ( AttributeType atd : schema.getAttributeTypeDescriptions() ) { // OID if ( !oidsList.contains( atd.getOid() ) ) { oidsList.add( atd.getOid() ); } // Names for ( String name : atd.getNames() ) { if ( !attributeNamesList.contains( name ) ) { attributeNamesList.add( name ); } } } } } }); return attributeNamesAndOids; } /** * Gets the array containing the schemaObjects and OIDs. * * @return the array containing the Schema objects and OIDs */ private String[] getSchemaObjectsAnddOids( String[] schemaObjects, SchemaAdder schemaAdder ) { // Checking if the array has already be generated if ( ( schemaObjects == null ) || ( schemaObjects.length == 0 ) ) { List<String> schemaObjectNamesList = new ArrayList<String>(); List<String> oidsList = new ArrayList<String>(); if ( browserConnection == null ) { // Getting all connections in the case where no connection is found IBrowserConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnections(); for ( IBrowserConnection connection : connections ) { schemaAdder.add( connection.getSchema(), schemaObjectNamesList, oidsList ); } } else { // Only adding schema object names and OIDs from the associated connection schemaAdder.add( browserConnection.getSchema(), schemaObjectNamesList, oidsList ); } // Also adding schemaObject names and OIDs from the default schema schemaAdder.add( Schema.DEFAULT_SCHEMA, schemaObjectNamesList, oidsList ); // Sorting the set Collections.sort( schemaObjectNamesList ); Collections.sort( oidsList ); schemaObjects = new String[schemaObjectNamesList.size() + oidsList.size()]; System.arraycopy( schemaObjectNamesList.toArray(), 0, schemaObjects, 0, schemaObjectNamesList .size() ); System.arraycopy( oidsList.toArray(), 0, schemaObjects, schemaObjectNamesList .size(), oidsList.size() ); } return schemaObjects; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * Utilies for filter handling. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapFilterUtils { /** * Creates a filter from the given value. * * @param value the value * * @return the filter */ public static String getFilter( IValue value ) { if ( value.isString() ) { return "(" + value.getAttribute().getDescription() + "=" + getEncodedValue( value.getStringValue() ) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else { StringBuffer filter = new StringBuffer(); filter.append( "(" ); //$NON-NLS-1$ filter.append( value.getAttribute().getDescription() ); filter.append( "=" ); //$NON-NLS-1$ byte[] bytes = value.getBinaryValue(); for ( int i = 0; i < bytes.length; i++ ) { int b = ( int ) bytes[i]; if ( b < 0 ) { b = 256 + b; } String s = Integer.toHexString( b ); filter.append( "\\" ); //$NON-NLS-1$ if ( s.length() == 1 ) { filter.append( "0" ); //$NON-NLS-1$ } filter.append( s ); } filter.append( ")" ); //$NON-NLS-1$ return filter.toString(); } } /** * Encodes the given value according RFC2254. * * <pre> * If a value should contain any of the following characters * Character ASCII value * --------------------------- * * 0x2a * ( 0x28 * ) 0x29 * \ 0x5c * NUL 0x00 * the character must be encoded as the backslash '\' character (ASCII * 0x5c) followed by the two hexadecimal digits representing the ASCII * value of the encoded character. The case of the two hexadecimal * digits is not significant. * </pre> * * @param value the value * * @return the encoded value */ public static String getEncodedValue( String value ) { value = value.replaceAll( "\\\\", "\\\\5c" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "" + '\u0000', "\\\\00" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "\\*", "\\\\2a" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "\\(", "\\\\28" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "\\)", "\\\\29" ); //$NON-NLS-1$ //$NON-NLS-2$ return value; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import org.apache.directory.api.ldap.model.exception.LdapOperationException; /** * Utility class for JNDI specific stuff. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class JNDIUtils { /** * Gets the LDAP status code from the exception. * * @param exception the exception * * @return the LDAP status code, -1 if none */ public static int getLdapStatusCode( Exception exception ) { int ldapStatusCode = -1; if ( exception instanceof LdapOperationException ) { LdapOperationException loe = ( LdapOperationException ) exception; loe.getResultCode().getValue(); } // get LDAP status code // [LDAP: error code 21 - telephoneNumber: value #0 invalid per syntax] String message = exception.getMessage(); if ( message != null && message.startsWith( "[LDAP: error code " ) ) { //$NON-NLS-1$ int begin = "[LDAP: error code ".length(); //$NON-NLS-1$ int end = begin + 2; try { ldapStatusCode = Integer.parseInt( message.substring( begin, end ).trim() ); } catch ( NumberFormatException nfe ) { } } return ldapStatusCode; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import java.beans.XMLDecoder; import java.beans.XMLEncoder; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.text.translate.CharSequenceTranslator; import org.apache.commons.text.translate.LookupTranslator; import org.apache.directory.api.ldap.model.name.Ava; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod; import org.apache.directory.studio.connection.core.StudioControl; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ModifyMode; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ModifyOrder; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.apache.directory.studio.ldifparser.LdifFormatParameters; import org.apache.directory.studio.ldifparser.LdifUtils; import org.apache.directory.studio.ldifparser.model.LdifFile; import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord; import org.apache.directory.studio.ldifparser.model.container.LdifModSpec; import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine; import org.apache.directory.studio.ldifparser.model.lines.LdifChangeTypeLine; import org.apache.directory.studio.ldifparser.model.lines.LdifControlLine; import org.apache.directory.studio.ldifparser.model.lines.LdifDnLine; import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecSepLine; import org.apache.directory.studio.ldifparser.model.lines.LdifSepLine; import org.eclipse.core.runtime.Preferences; public class Utils { /** * Transforms the given Dn into a normalized String, usable by the schema cache. * The following transformations are performed: * <ul> * <li>The attribute type is replaced by the OID * <li>The attribute value is trimmed and lowercased * </ul> * Example: the surname=Bar will be transformed to * 2.5.4.4=bar * * * @param dn the Dn * @param schema the schema * * @return the oid string */ public static String getNormalizedOidString( Dn dn, Schema schema ) { StringBuilder sb = new StringBuilder(); boolean isFirst = true; for ( Rdn rdn : dn ) { if ( isFirst ) { isFirst = false; } else { sb.append( ',' ); } sb.append( getOidString( rdn, schema ) ); } return sb.toString(); } private static String getOidString( Rdn rdn, Schema schema ) { StringBuilder sb = new StringBuilder(); boolean isFirst = true; for ( Ava ava : rdn ) { if ( isFirst ) { isFirst = false; } else { sb.append( '+' ); } sb.append( getOidString( ava, schema ) ); } return sb.toString(); } private static String getOidString( Ava ava, Schema schema ) { String oid = schema != null ? schema.getAttributeTypeDescription( ava.getNormType() ).getOid() : ava .getNormType(); return Strings.toLowerCaseAscii( Strings.trim( oid ) ) + "=" + Strings.trim( ava.getValue().getString() ).toLowerCase(); //$NON-NLS-1$ } public static String arrayToString( String[] array ) { if ( array == null || array.length == 0 ) { return ""; //$NON-NLS-1$ } else { StringBuilder sb = new StringBuilder( array[0] ); for ( int i = 1; i < array.length; i++ ) { sb.append( ", " ); //$NON-NLS-1$ sb.append( array[i] ); } return sb.toString(); } } public static boolean equals( byte[] data1, byte[] data2 ) { if ( data1 == data2 ) return true; if ( data1 == null || data2 == null ) return false; if ( data1.length != data2.length ) return false; for ( int i = 0; i < data1.length; i++ ) { if ( data1[i] != data2[i] ) return false; } return true; } public static String getShortenedString( String value, int length ) { StringBuilder sb = new StringBuilder(); if ( ( value != null ) && ( value.length() > length ) ) { sb.append( value.substring( 0, length ) ).append( "..." ); //$NON-NLS-1$ } return sb.toString(); } public static String serialize( Object o ) { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder( baos ); encoder.writeObject( o ); encoder.close(); return LdifUtils.utf8decode( baos.toByteArray() ); } finally { Thread.currentThread().setContextClassLoader( ccl ); } } public static Object deserialize( String s ) { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() ); ByteArrayInputStream bais = new ByteArrayInputStream( LdifUtils.utf8encode( s ) ); XMLDecoder decoder = new XMLDecoder( bais ); Object o = decoder.readObject(); decoder.close(); return o; } finally { Thread.currentThread().setContextClassLoader( ccl ); } } public static String getNonNullString( Object o ) { return o == null ? "-" : o.toString(); //$NON-NLS-1$ } public static String formatBytes( long bytes ) { String size = ""; //$NON-NLS-1$ if ( bytes > 1024 * 1024 ) { size += ( bytes / 1024 / 1024 ) + " " + Messages.Utils_MegaBytes + " (" + bytes + " " + Messages.Utils_Bytes + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-6$ } else if ( bytes > 1024 ) { size += ( bytes / 1024 ) + " " + Messages.Utils_KiloBytes + " (" + bytes + " " + Messages.Utils_Bytes + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-6$ } else if ( bytes > 1 ) { size += bytes + " " + Messages.Utils_Bytes; //$NON-NLS-1$ } else { size += bytes + " " + Messages.Utils_Byte; //$NON-NLS-1$ } return size; } public static boolean containsIgnoreCase( Collection<String> c, String s ) { if ( c == null || s == null ) { return false; } for ( String string : c ) { if ( string.equalsIgnoreCase( s ) ) { return true; } } return false; } public static LdifFormatParameters getLdifFormatParameters() { Preferences store = BrowserCorePlugin.getDefault().getPluginPreferences(); boolean spaceAfterColon = store.getBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON ); int lineWidth = store.getInt( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH ); String lineSeparator = store.getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR ); return new LdifFormatParameters( spaceAfterColon, lineWidth, lineSeparator ); } /** * Transforms an IBrowserConnection to an LdapURL. The following parameters are * used to create the LDAP URL: * <ul> * <li>scheme * <li>host * <li>port * </ul> * * @param entry the entry * @return the LDAP URL */ public static LdapUrl getLdapURL( IBrowserConnection browserConnection ) { LdapUrl url = new LdapUrl(); if ( browserConnection.getConnection() != null ) { if ( browserConnection.getConnection().getEncryptionMethod() == EncryptionMethod.LDAPS ) { url.setScheme( LdapUrl.LDAPS_SCHEME ); } else { url.setScheme( LdapUrl.LDAP_SCHEME ); } url.setHost( browserConnection.getConnection().getHost() ); url.setPort( browserConnection.getConnection().getPort() ); } return url; } /** * Transforms an IEntry to an LdapURL. The following parameters are * used to create the LDAP URL: * <ul> * <li>scheme * <li>host * <li>port * <li>dn * </ul> * * @param entry the entry * @return the LDAP URL */ public static LdapUrl getLdapURL( IEntry entry ) { LdapUrl url = getLdapURL( entry.getBrowserConnection() ); url.setDn( entry.getDn() ); return url; } /** * Transforms an ISearch to an LdapURL. The following search parameters are * used to create the LDAP URL: * <ul> * <li>scheme * <li>host * <li>port * <li>search base * <li>returning attributes * <li>scope * <li>filter * </ul> * * @param search the search * @return the LDAP URL */ public static LdapUrl getLdapURL( ISearch search ) { LdapUrl url = getLdapURL( search.getBrowserConnection() ); url.setDn( search.getSearchBase() ); if ( search.getReturningAttributes() != null ) { url.setAttributes( Arrays.asList( search.getReturningAttributes() ) ); } url.setScope( search.getScope().getScope() ); url.setFilter( search.getFilter() ); return url; } /** * Computes the difference between the old and the new entry * and returns an LDIF that could be applied to the old entry * to get new entry. * * @param oldEntry the old entry * @param newEntry the new entry * @return the change modify record or null if there is no difference * between the two entries */ public static LdifFile computeDiff( IEntry oldEntry, IEntry newEntry ) { // get connection parameters ModifyMode modifyMode = oldEntry.getBrowserConnection().getModifyMode(); ModifyMode modifyModeNoEMR = oldEntry.getBrowserConnection().getModifyModeNoEMR(); ModifyOrder modifyAddDeleteOrder = oldEntry.getBrowserConnection().getModifyAddDeleteOrder(); // get all attribute descriptions Set<String> attributeDescriptions = new LinkedHashSet<>(); for ( IAttribute oldAttr : oldEntry.getAttributes() ) { attributeDescriptions.add( oldAttr.getDescription() ); } for ( IAttribute newAttr : newEntry.getAttributes() ) { attributeDescriptions.add( newAttr.getDescription() ); } // prepare the LDIF record containing the modifications LdifChangeModifyRecord record = new LdifChangeModifyRecord( LdifDnLine.create( newEntry.getDn().getName() ) ); if ( newEntry.isReferral() ) { record.addControl( LdifControlLine.create( StudioControl.MANAGEDSAIT_CONTROL.getOid(), StudioControl.MANAGEDSAIT_CONTROL.isCritical(), StudioControl.MANAGEDSAIT_CONTROL.getControlValue() ) ); } record.setChangeType( LdifChangeTypeLine.createModify() ); // check all the attributes for ( String attributeDescription : attributeDescriptions ) { // get attribute type schema information Schema schema = oldEntry.getBrowserConnection().getSchema(); AttributeType atd = schema.getAttributeTypeDescription( attributeDescription ); boolean hasEMR = SchemaUtils.getEqualityMatchingRuleNameOrNumericOidTransitive( atd, schema ) != null; boolean isReplaceForced = ( hasEMR && modifyMode == ModifyMode.REPLACE ) || ( !hasEMR && modifyModeNoEMR == ModifyMode.REPLACE ); boolean isAddDelForced = ( hasEMR && modifyMode == ModifyMode.ADD_DELETE ) || ( !hasEMR && modifyModeNoEMR == ModifyMode.ADD_DELETE ); boolean isOrderedValue = atd.getExtensions().containsKey( "X-ORDERED" ) //$NON-NLS-1$ && atd.getExtensions().get( "X-ORDERED" ).contains( "VALUES" ); //$NON-NLS-1$ //$NON-NLS-2$ // get old an new values for comparison IAttribute oldAttribute = oldEntry.getAttribute( attributeDescription ); Set<String> oldValues = new HashSet<>(); Map<String, LdifAttrValLine> oldAttrValLines = new LinkedHashMap<>(); if ( oldAttribute != null ) { for ( IValue value : oldAttribute.getValues() ) { LdifAttrValLine attrValLine = computeDiffCreateAttrValLine( value ); oldValues.add( attrValLine.getUnfoldedValue() ); oldAttrValLines.put( attrValLine.getUnfoldedValue(), attrValLine ); } } IAttribute newAttribute = newEntry.getAttribute( attributeDescription ); Set<String> newValues = new HashSet<>(); Map<String, LdifAttrValLine> newAttrValLines = new LinkedHashMap<>(); if ( newAttribute != null ) { for ( IValue value : newAttribute.getValues() ) { LdifAttrValLine attrValLine = computeDiffCreateAttrValLine( value ); newValues.add( attrValLine.getUnfoldedValue() ); newAttrValLines.put( attrValLine.getUnfoldedValue(), attrValLine ); } } // check what to do if ( oldAttribute != null && newAttribute == null ) { // attribute only exists in the old entry: delete all values LdifModSpec modSpec; if ( isReplaceForced ) { // replace (empty value list) modSpec = LdifModSpec.createReplace( attributeDescription ); } else // addDelForced or default { // delete all modSpec = LdifModSpec.createDelete( attributeDescription ); for ( IValue value : oldAttribute.getValues() ) { modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) ); } } modSpec.finish( LdifModSpecSepLine.create() ); record.addModSpec( modSpec ); } else if ( oldAttribute == null && newAttribute != null ) { // attribute only exists in the new entry: add all values LdifModSpec modSpec; if ( isReplaceForced ) { // replace (all values) modSpec = LdifModSpec.createReplace( attributeDescription ); } else // addDelForced or default { // add (all new values) modSpec = LdifModSpec.createAdd( attributeDescription ); } for ( IValue value : newAttribute.getValues() ) { modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) ); } modSpec.finish( LdifModSpecSepLine.create() ); record.addModSpec( modSpec ); } else if ( oldAttribute != null && newAttribute != null && !oldValues.equals( newValues ) ) { // attribute exists in both entries, check modifications if ( isReplaceForced ) { // replace (all new values) LdifModSpec modSpec = LdifModSpec.createReplace( attributeDescription ); for ( IValue value : newAttribute.getValues() ) { modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) ); } modSpec.finish( LdifModSpecSepLine.create() ); record.addModSpec( modSpec ); } else { // compute diff List<LdifAttrValLine> toDel = new ArrayList<>(); List<LdifAttrValLine> toAdd = new ArrayList<>(); for ( Map.Entry<String, LdifAttrValLine> entry : oldAttrValLines.entrySet() ) { if ( !newValues.contains( entry.getKey() ) ) { toDel.add( entry.getValue() ); } } for ( Map.Entry<String, LdifAttrValLine> entry : newAttrValLines.entrySet() ) { if ( !oldValues.contains( entry.getKey() ) ) { toAdd.add( entry.getValue() ); } } /* * we use add/del in the following cases: * - add/del is forced in the connection configuration * - for attributes w/o X-ORDERED 'VALUES' * * we use replace in the following cases: * - for attributes with X-ORDERED 'VALUES' */ if ( isAddDelForced || !isOrderedValue ) { // add/del del/add LdifModSpec addModSpec = LdifModSpec.createAdd( attributeDescription ); for ( LdifAttrValLine attrValLine : toAdd ) { addModSpec.addAttrVal( attrValLine ); } addModSpec.finish( LdifModSpecSepLine.create() ); LdifModSpec delModSpec = LdifModSpec.createDelete( attributeDescription ); for ( LdifAttrValLine attrValLine : toDel ) { delModSpec.addAttrVal( attrValLine ); } delModSpec.finish( LdifModSpecSepLine.create() ); if ( modifyAddDeleteOrder == ModifyOrder.DELETE_FIRST ) { if ( delModSpec.getAttrVals().length > 0 ) { record.addModSpec( delModSpec ); } if ( addModSpec.getAttrVals().length > 0 ) { record.addModSpec( addModSpec ); } } else { if ( addModSpec.getAttrVals().length > 0 ) { record.addModSpec( addModSpec ); } if ( delModSpec.getAttrVals().length > 0 ) { record.addModSpec( delModSpec ); } } } else { // replace (all new values) LdifModSpec modSpec = LdifModSpec.createReplace( attributeDescription ); for ( LdifAttrValLine attrValLine : newAttrValLines.values() ) { modSpec.addAttrVal( attrValLine ); } modSpec.finish( LdifModSpecSepLine.create() ); record.addModSpec( modSpec ); } } } } record.finish( LdifSepLine.create() ); LdifFile model = new LdifFile(); if ( record.isValid() && record.getModSpecs().length > 0 ) { model.addContainer( record ); } return model.getRecords().length > 0 ? model : null; } private static LdifAttrValLine computeDiffCreateAttrValLine( IValue value ) { IAttribute attribute = value.getAttribute(); if ( attribute.isBinary() ) { return LdifAttrValLine.create( attribute.getDescription(), value.getBinaryValue() ); } else { return LdifAttrValLine.create( attribute.getDescription(), value.getStringValue() ); } } /** * Decodes the RFC 4517 Postal Address syntax. * * <pre> * PostalAddress = line *( DOLLAR line ) * line = 1*line-char * line-char = %x00-23 * / (%x5C "24") ; escaped "$" * / %x25-5B * / (%x5C "5C") ; escaped "\" * / %x5D-7F * / UTFMB * </pre> * * @param separator the separator to output between address lines * @return a translator object for decoding */ public static CharSequenceTranslator createPostalAddressDecoder( String separator ) { return new LookupTranslator( Map.of( "$", separator, //$NON-NLS-1$ "\\24", "$", //$NON-NLS-1$ //$NON-NLS-2$ "\\5C", "\\", //$NON-NLS-1$ //$NON-NLS-2$ "\\5c", "\\" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Encodes the RFC 4517 Postal Address syntax. * * @param separator the separator used between address lines * @return a translator object for encoding */ public static CharSequenceTranslator createPostalAddressEncoder( String separator ) { return new LookupTranslator( Map.of( "\\", "\\5C", //$NON-NLS-1$ //$NON-NLS-2$ "$", "\\24", //$NON-NLS-1$ //$NON-NLS-2$ separator, "$" ) ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Messages.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import org.eclipse.osgi.util.NLS; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.apache.directory.studio.ldapbrowser.core.utils.messages"; //$NON-NLS-1$ public static String Utils_10; public static String Utils_Byte; public static String Utils_Bytes; public static String Utils_KiloBytes; public static String Utils_MegaBytes; static { // initialize resource bundle NLS.initializeMessages( BUNDLE_NAME, Messages.class ); } private Messages() { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import java.util.Collection; import java.util.stream.Collectors; import org.apache.directory.api.ldap.model.entry.DefaultEntry; import org.apache.directory.api.ldap.model.entry.DefaultModification; import org.apache.directory.api.ldap.model.entry.Entry; import org.apache.directory.api.ldap.model.entry.Modification; import org.apache.directory.api.ldap.model.entry.ModificationOperation; import org.apache.directory.api.ldap.model.exception.LdapException; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.connection.core.StudioControl; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute; import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.Value; import org.apache.directory.studio.ldifparser.LdifUtils; import org.apache.directory.studio.ldifparser.model.LdifEOFPart; import org.apache.directory.studio.ldifparser.model.LdifPart; import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord; import org.apache.directory.studio.ldifparser.model.container.LdifChangeRecord; import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord; import org.apache.directory.studio.ldifparser.model.container.LdifRecord; import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine; import org.apache.directory.studio.ldifparser.model.lines.LdifChangeTypeLine; import org.apache.directory.studio.ldifparser.model.lines.LdifCommentLine; import org.apache.directory.studio.ldifparser.model.lines.LdifControlLine; import org.apache.directory.studio.ldifparser.model.lines.LdifDnLine; import org.apache.directory.studio.ldifparser.model.lines.LdifSepLine; public class ModelConverter { /** * Converts the given {@link LdifContentRecord} to an {@link DummyEntry}. * * @param ldifContentRecord the ldif content record to convert * @param connection the connection * * @return the resulting dummy entry * * @throws org.apache.directory.api.ldap.model.exception.LdapInvalidDnException */ public static DummyEntry ldifContentRecordToEntry( LdifContentRecord ldifContentRecord, IBrowserConnection connection ) throws LdapInvalidDnException { return createIntern( ldifContentRecord, connection ); } /** * Converts the given {@link LdifChangeAddRecord} to an {@link DummyEntry}. * * @param ldifChangeAddRecord the ldif change add record to convert * @param connection the connection * * @return the resulting dummy entry * * @throws org.apache.directory.api.ldap.model.exception.LdapInvalidDnException */ public static DummyEntry ldifChangeAddRecordToEntry( LdifChangeAddRecord ldifChangeAddRecord, IBrowserConnection connection ) throws LdapInvalidDnException { return createIntern( ldifChangeAddRecord, connection ); } /** * Creates an {@link DummyEntry} from the given {@link LdifRecord}. * * @param connection the connection * @param ldifRecord the ldif record * * @return the dummy entry * * @throws LdapInvalidDnException */ private static DummyEntry createIntern( LdifRecord ldifRecord, IBrowserConnection connection ) throws LdapInvalidDnException { LdifPart[] parts = ldifRecord.getParts(); EventRegistry.suspendEventFiringInCurrentThread(); DummyEntry entry = new DummyEntry( new Dn( ldifRecord.getDnLine().getValueAsString() ), connection ); for ( int i = 0; i < parts.length; i++ ) { if ( parts[i] instanceof LdifAttrValLine ) { LdifAttrValLine line = ( LdifAttrValLine ) parts[i]; String attributeName = line.getUnfoldedAttributeDescription(); Object value = line.getValueAsObject(); IAttribute attribute = entry.getAttribute( attributeName ); if ( attribute == null ) { attribute = new Attribute( entry, attributeName ); entry.addAttribute( attribute ); } attribute.addValue( new Value( attribute, value ) ); } else if ( !( parts[i] instanceof LdifDnLine ) && !( parts[i] instanceof LdifSepLine ) && !( parts[i] instanceof LdifEOFPart ) && !( parts[i] instanceof LdifChangeTypeLine ) ) { String name = parts[i].toRawString(); name = name.replaceAll( "\n", "" ); //$NON-NLS-1$ //$NON-NLS-2$ name = name.replaceAll( "\r", "" ); //$NON-NLS-1$ //$NON-NLS-2$ IAttribute attribute = new Attribute( entry, name ); attribute.addValue( new Value( attribute, parts[i] ) ); entry.addAttribute( attribute ); } } EventRegistry.resumeEventFiringInCurrentThread(); return entry; } public static LdifChangeAddRecord entryToLdifChangeAddRecord( IEntry entry ) { boolean mustCreateChangeTypeLine = true; for ( IAttribute attribute : entry.getAttributes() ) { for ( IValue value : attribute.getValues() ) { if ( value.getRawValue() instanceof LdifPart ) { mustCreateChangeTypeLine = false; } } } LdifChangeAddRecord record = new LdifChangeAddRecord( LdifDnLine.create( entry.getDn().getName() ) ); if ( mustCreateChangeTypeLine ) { addControls( record, entry ); record.setChangeType( LdifChangeTypeLine.createAdd() ); } for ( IAttribute attribute : entry.getAttributes() ) { String name = attribute.getDescription(); for ( IValue value : attribute.getValues() ) { if ( !value.isEmpty() ) { if ( value.getRawValue() instanceof LdifPart ) { LdifPart part = ( LdifPart ) value.getRawValue(); if ( part instanceof LdifChangeTypeLine ) { record.setChangeType( ( LdifChangeTypeLine ) part ); } else if ( part instanceof LdifCommentLine ) { record.addComment( ( LdifCommentLine ) part ); } else if ( part instanceof LdifControlLine ) { record.addControl( ( LdifControlLine ) part ); } } else if ( value.isString() ) { record.addAttrVal( LdifAttrValLine.create( name, value.getStringValue() ) ); } else { record.addAttrVal( LdifAttrValLine.create( name, value.getBinaryValue() ) ); } } } } record.finish( LdifSepLine.create() ); return record; } public static LdifContentRecord entryToLdifContentRecord( IEntry entry ) { LdifContentRecord record = LdifContentRecord.create( entry.getDn().getName() ); if ( entry.getAttributes() != null ) { for ( IAttribute attribute : entry.getAttributes() ) { String name = attribute.getDescription(); for ( IValue value : attribute.getValues() ) { if ( !value.isEmpty() ) { if ( value.getRawValue() instanceof LdifPart ) { LdifPart part = ( LdifPart ) value.getRawValue(); if ( part instanceof LdifCommentLine ) { record.addComment( ( LdifCommentLine ) part ); } } else if ( value.isString() ) { record.addAttrVal( LdifAttrValLine.create( name, value.getStringValue() ) ); } else { record.addAttrVal( LdifAttrValLine.create( name, value.getBinaryValue() ) ); } } } } } record.finish( LdifSepLine.create() ); return record; } public static LdifAttrValLine valueToLdifAttrValLine( IValue value ) { LdifAttrValLine line; if ( value.isString() ) { line = LdifAttrValLine.create( value.getAttribute().getDescription(), value.getStringValue() ); } else { line = LdifAttrValLine.create( value.getAttribute().getDescription(), value.getBinaryValue() ); } return line; } public static IValue ldifAttrValLineToValue( LdifAttrValLine line, IEntry entry ) { try { IAttribute attribute = new Attribute( entry, line.getUnfoldedAttributeDescription() ); IValue value = new Value( attribute, line.getValueAsObject() ); return value; } catch ( Exception e ) { return null; } } public static LdifDnLine dnToLdifDnLine( Dn dn ) { LdifDnLine line = LdifDnLine.create( dn.getName() ); return line; } public static void addControls( LdifChangeRecord cr, IEntry entry ) { if ( entry.isReferral() ) { cr.addControl( LdifControlLine.create( StudioControl.MANAGEDSAIT_CONTROL.getOid(), StudioControl.MANAGEDSAIT_CONTROL.isCritical(), StudioControl.MANAGEDSAIT_CONTROL.getControlValue() ) ); } } /** * Gets the string value from the given {@link IValue}. If the given * {@link IValue} is binary is is encoded according to the regquested * encoding type. * * @param value the value * @param binaryEncoding the binary encoding type * * @return the string value */ public static String getStringValue( IValue value, int binaryEncoding ) { String s = value.getStringValue(); if ( value.isBinary() && LdifUtils.mustEncode( s ) ) { byte[] binary = value.getBinaryValue(); if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_BASE64 ) { s = LdifUtils.base64encode( binary ); } else if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_HEX ) { s = LdifUtils.hexEncode( binary ); } else { s = BrowserCoreConstants.BINARY; } } return s; } public static Entry toLdapApiEntry( IEntry entry ) throws LdapException { Entry ldapApiEntry = new DefaultEntry( entry.getDn() ); for ( IAttribute iAttribute : entry.getAttributes() ) { for ( IValue value : iAttribute.getValues() ) { String attributeDescription = value.getAttribute().getDescription(); if ( value.isString() ) { ldapApiEntry.add( attributeDescription, value.getStringValue() ); } else { ldapApiEntry.add( attributeDescription, value.getBinaryValue() ); } } } return ldapApiEntry; } public static Collection<Modification> toReplaceModifications( Entry entry ) { Collection<Modification> modifications = entry.getAttributes() .stream() .map( attribute -> new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute ) ) .collect( Collectors.toList() ); return modifications; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; public class AttributeComparator implements Comparator<Object> { private final int sortBy; private final int defaultSortBy; private final int sortOrder; private final int defaultSortOrder; private final boolean objectClassAndMustAttributesFirst; private final boolean operationalAttributesLast; public AttributeComparator() { this.sortBy = BrowserCoreConstants.SORT_BY_NONE; this.defaultSortBy =BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION; this.sortOrder = BrowserCoreConstants.SORT_ORDER_NONE; this.defaultSortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING; this.objectClassAndMustAttributesFirst = true; this.operationalAttributesLast = true; } public AttributeComparator( int sortBy, int defaultSortBy, int sortOrder, int defaultSortOrder, boolean objectClassAndMustAttributesFirst, boolean operationalAttributesLast ) { this.sortBy = sortBy; this.defaultSortBy = defaultSortBy; this.sortOrder = sortOrder; this.defaultSortOrder = defaultSortOrder; this.objectClassAndMustAttributesFirst = objectClassAndMustAttributesFirst; this.operationalAttributesLast = operationalAttributesLast; } public int compare( Object o1, Object o2 ) { IAttribute attribute1 = null; IValue value1 = null; if ( o1 instanceof IAttribute ) { attribute1 = ( IAttribute ) o1; } else if ( o1 instanceof IValue ) { value1 = ( IValue ) o1; attribute1 = value1.getAttribute(); } IAttribute attribute2 = null; IValue value2 = null; if ( o2 instanceof IAttribute ) { attribute2 = ( IAttribute ) o2; } else if ( o2 instanceof IValue ) { value2 = ( IValue ) o2; attribute2 = value2.getAttribute(); } if ( value1 != null && value2 != null ) { if ( getSortByOrDefault() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION ) { if ( value1.getAttribute() != value2.getAttribute() ) { return this.compareAttributes( value1.getAttribute(), value2.getAttribute() ); } else { return this.compareValues( value1, value2 ); } } else if ( getSortByOrDefault() == BrowserCoreConstants.SORT_BY_VALUE ) { return this.compareValues( value1, value2 ); } else { return this.equal(); } } else if ( attribute1 != null && attribute2 != null ) { return this.compareAttributes( attribute1, attribute2 ); } else { throw new ClassCastException( "Can only compare two values or two attributes" ); } } private int compareAttributes( IAttribute attribute1, IAttribute attribute2 ) { if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ) { if ( objectClassAndMustAttributesFirst ) { if ( attribute1.isObjectClassAttribute() && !attribute2.isObjectClassAttribute() ) { return lessThan(); } else if ( attribute2.isObjectClassAttribute() && !attribute1.isObjectClassAttribute() ) { return greaterThan(); } if ( attribute1.isMustAttribute() && !attribute2.isMustAttribute() ) { return lessThan(); } else if ( attribute2.isMustAttribute() && !attribute1.isMustAttribute() ) { return greaterThan(); } } if ( operationalAttributesLast ) { if ( attribute1.isOperationalAttribute() && !attribute2.isOperationalAttribute() ) { return greaterThan(); } else if ( attribute2.isOperationalAttribute() && !attribute1.isOperationalAttribute() ) { return lessThan(); } } } return compare( attribute1.getDescription(), attribute2.getDescription() ); } private int compareValues( IValue value1, IValue value2 ) { if ( value1.isEmpty() && value2.isEmpty() ) { return equal(); } if ( value1.isEmpty() && !value2.isEmpty() ) { return greaterThan(); } if ( !value1.isEmpty() && value2.isEmpty() ) { return lessThan(); } return compare( value1.getStringValue(), value2.getStringValue() ); } /** * Gets the current sort by property or the default sort by property (from the preferences). */ private int getSortByOrDefault() { if ( sortBy == BrowserCoreConstants.SORT_BY_NONE ) { return defaultSortBy; } else { return sortBy; } } /** * Gets the current sort order or the default sort order (from the preferences). */ private int getSortOrderOrDefault() { if ( sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ) { return defaultSortOrder; } else { return sortOrder; } } private int lessThan() { return getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1; } private int equal() { return 0; } private int greaterThan() { return getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1; } /** * Compares the two strings using the Strings's compareToIgnoreCase method, * pays attention for the sort order. * * @param s1 the first string to compare * @param s2 the second string to compare * @return a negative integer, zero, or a positive integer * @see java.lang.String#compareToIgnoreCase(String) */ private int compare( String s1, String s2 ) { return getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1.compareToIgnoreCase( s2 ) : s2.compareToIgnoreCase( s1 ); } public static List<IValue> toSortedValues( IEntry entry ) { return Arrays.stream( entry.getAttributes() ).flatMap( a -> Arrays.stream( a.getValues() ) ) .sorted( new AttributeComparator() ) .collect( Collectors.toList() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/CompoundModification.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.utils; import java.util.Collection; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.ValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueMultiModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueRenamedEvent; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute; import org.apache.directory.studio.ldapbrowser.core.model.impl.Value; import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord; /** * Performs compound operations to model classes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CompoundModification { /** * Rename the values by removing the old attribute from the entry and adding * a new attribute to the entry. Only one event (an {@link ValueRenamedEvent}) is fired. * * @param oldValues the old values * @param newAttributeDescription the new attribute description */ public void renameValues( IValue[] oldValues, String newAttributeDescription ) { if ( ArrayUtils.isEmpty( oldValues ) ) { throw new IllegalArgumentException( "Expected non-null and non-empty values array." ); //$NON-NLS-1$ } if ( StringUtils.isEmpty( newAttributeDescription ) ) { throw new IllegalArgumentException( "Expected non-null and non-empty attribute description." ); //$NON-NLS-1$ } if ( newAttributeDescription != null && !"".equals( newAttributeDescription ) //$NON-NLS-1$ && !newAttributeDescription.equals( oldValues[0].getAttribute().getDescription() ) ) { ValueRenamedEvent event = null; try { EventRegistry.suspendEventFiringInCurrentThread(); for ( IValue oldValue : oldValues ) { if ( !newAttributeDescription.equals( oldValue.getAttribute().getDescription() ) ) { IAttribute oldAttribute = oldValue.getAttribute(); IEntry entry = oldAttribute.getEntry(); IValue newValue = null; // delete old value oldAttribute.deleteValue( oldValue ); if ( oldAttribute.getValueSize() == 0 ) { entry.deleteAttribute( oldAttribute ); } // add new value IAttribute attribute = entry.getAttribute( newAttributeDescription ); if ( attribute == null ) { attribute = new Attribute( entry, newAttributeDescription ); entry.addAttribute( attribute ); } newValue = new Value( attribute, oldValue.getRawValue() ); attribute.addValue( newValue ); // prepare event if ( event == null ) { event = new ValueRenamedEvent( entry.getBrowserConnection(), entry, oldValue, newValue ); } } } } finally { EventRegistry.resumeEventFiringInCurrentThread(); } // fire events EventRegistry.fireEntryUpdated( event, this ); } } /** * Deletes the values and the attribute if no values remain. * Only one event (an {@link ValueDeletedEvent}) is fired. * * @param values * the Values to delete */ public void deleteValues( Collection<IValue> values ) { if ( CollectionUtils.isEmpty( values ) ) { throw new IllegalArgumentException( "Expected non-null and non-empty values collection." ); //$NON-NLS-1$ } ValueDeletedEvent event = null; try { EventRegistry.suspendEventFiringInCurrentThread(); for ( IValue value : values ) { IAttribute attribute = value.getAttribute(); IEntry entry = attribute.getEntry(); attribute.deleteValue( value ); if ( event == null ) { event = new ValueDeletedEvent( entry.getBrowserConnection(), entry, attribute, value ); } if ( attribute.getValueSize() == 0 ) { attribute.getEntry().deleteAttribute( attribute ); } } } finally { EventRegistry.resumeEventFiringInCurrentThread(); } // fire event EventRegistry.fireEntryUpdated( event, this ); } /** * Modifies the value and sets the given raw value. * Only one event (an {@link ValueAddEvent} or an {@link ValueModifiedEvent}) is fired. * * @param oldValue the old value * @param newRawValue the new raw value */ public void modifyValue( IValue oldValue, Object newRawValue ) { if ( oldValue == null || newRawValue == null ) { throw new IllegalArgumentException( "Expected non-null value." ); //$NON-NLS-1$ } IAttribute attribute = oldValue.getAttribute(); boolean modify = false; if ( oldValue != null && newRawValue instanceof byte[] ) { byte[] newValue = ( byte[] ) newRawValue; if ( !Utils.equals( oldValue.getBinaryValue(), newValue ) ) { modify = true; } } else if ( oldValue != null && newRawValue instanceof String ) { String newValue = ( String ) newRawValue; if ( !oldValue.getStringValue().equals( newValue ) ) { modify = true; } } if ( modify ) { if ( oldValue.isEmpty() ) { EventRegistry.suspendEventFiringInCurrentThread(); attribute.deleteEmptyValue(); EventRegistry.resumeEventFiringInCurrentThread(); Value value = new Value( attribute, newRawValue ); attribute.addValue( value ); } else { IValue newValue = new Value( attribute, newRawValue ); attribute.modifyValue( oldValue, newValue ); } } } /** * Creates the attribute with the given value in the entry. * Only one event (an {@link ValueAddedEvent}) is fired. * * @param entry the entry * @param attributeDescription the attribute description * @param newRawValue the new raw value * * @throws ModelModificationException the model modification exception */ public void createValue( IEntry entry, String attributeDescription, Object newRawValue ) { if ( entry == null ) { throw new IllegalArgumentException( "Expected non-null entry." ); //$NON-NLS-1$ } if ( StringUtils.isEmpty( attributeDescription ) ) { throw new IllegalArgumentException( "Expected non-null and non-empty attribute description." ); //$NON-NLS-1$ } if ( newRawValue == null ) { throw new IllegalArgumentException( "Expected non-null value." ); //$NON-NLS-1$ } IAttribute attribute = entry.getAttribute( attributeDescription ); if ( attribute == null ) { EventRegistry.suspendEventFiringInCurrentThread(); attribute = new Attribute( entry, attributeDescription ); entry.addAttribute( attribute ); EventRegistry.resumeEventFiringInCurrentThread(); } Value value = new Value( attribute, newRawValue ); attribute.addValue( value ); } /** * Creates the attribute with the given value in the entry. * Only one event (an {@link ValueAddedEvent}) is fired. * * @param entry the entry * @param values the values * * @throws ModelModificationException the model modification exception */ public void createValues( IEntry entry, IValue... values ) { if ( entry == null ) { throw new IllegalArgumentException( "Expected non-null entry." ); //$NON-NLS-1$ } if ( ArrayUtils.isEmpty( values ) ) { throw new IllegalArgumentException( "Expected non-null and non-empty values array." ); //$NON-NLS-1$ } ValueAddedEvent event = null; EventRegistry.suspendEventFiringInCurrentThread(); for ( IValue value : values ) { String attributeDescription = value.getAttribute().getDescription(); IAttribute attribute = entry.getAttribute( attributeDescription ); if ( attribute == null ) { attribute = new Attribute( entry, attributeDescription ); entry.addAttribute( attribute ); } Value newValue = new Value( attribute, value.getRawValue() ); attribute.addValue( newValue ); if ( event == null ) { event = new ValueAddedEvent( entry.getBrowserConnection(), entry, attribute, newValue ); } } EventRegistry.resumeEventFiringInCurrentThread(); // fire event EventRegistry.fireEntryUpdated( event, this ); } /** * Copies all attributes and values from the 1st entry to the second entry. * Clears all existing attributes from the 2nd entry. * Only one event (an {@link ValueMultiModificationEvent}) is fired. * * @param fromEntry * @param toEntry */ public void replaceAttributes( IEntry fromEntry, IEntry toEntry, Object source ) { EventRegistry.suspendEventFiringInCurrentThread(); for ( IAttribute attribute : toEntry.getAttributes() ) { toEntry.deleteAttribute( attribute ); } // create new attributes for ( IAttribute attribute : fromEntry.getAttributes() ) { IAttribute newAttribute = new Attribute( toEntry, attribute.getDescription() ); for ( IValue value : attribute.getValues() ) { IValue newValue = new Value( newAttribute, value.getRawValue() ); newAttribute.addValue( newValue ); } toEntry.addAttribute( newAttribute ); } EventRegistry.resumeEventFiringInCurrentThread(); ValueMultiModificationEvent event = new ValueMultiModificationEvent( toEntry.getBrowserConnection(), toEntry ); EventRegistry.fireEntryUpdated( event, source ); } /** * Clones an entry, no event is fired. * * @param entry the entry * * @return the cloned entry */ public IEntry cloneEntry( IEntry entry ) { try { EventRegistry.suspendEventFiringInCurrentThread(); IBrowserConnection browserConnection = entry.getBrowserConnection(); LdifContentRecord record = ModelConverter.entryToLdifContentRecord( entry ); IEntry clonedEntry = ModelConverter.ldifContentRecordToEntry( record, browserConnection ); return clonedEntry; } catch ( LdapInvalidDnException e ) { throw new RuntimeException( e ); } finally { EventRegistry.resumeEventFiringInCurrentThread(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryModificationEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * The root of all events that indecate an {@link IEntry} modification. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryModificationEvent { /** The event source */ protected Object source; /** The connection. */ protected IBrowserConnection connection; /** The entry. */ protected IEntry modifiedEntry; /** * Creates a new instance of EntryModificationEvent. * * @param modifiedEntry the modified entry * @param connection the connection */ public EntryModificationEvent( IBrowserConnection connection, IEntry modifiedEntry ) { this.connection = connection; this.modifiedEntry = modifiedEntry; } /** * Gets the connection. * * @return the connection */ public IBrowserConnection getConnection() { return connection; } /** * Gets the modified entry. * * @return the modified entry */ public IEntry getModifiedEntry() { return modifiedEntry; } /** * Gets the event source. * * @return the event source, may be null */ public Object getSource() { return source; } /** * Sets the source. * * @param source the new source */ public void setSource( Object source ) { this.source = source; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/AttributeDeletedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/AttributeDeletedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An AttributeDeletedEvent indicates that an {@link IAttribute} was deleted from an {@link IEntry}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeDeletedEvent extends EntryModificationEvent { /** The deleted attribute. */ private IAttribute deletedAttribute; /** * Creates a new instance of AttributeDeletedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param deletedAttribute the deleted attribute */ public AttributeDeletedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute deletedAttribute ) { super( connection, modifiedEntry ); this.deletedAttribute = deletedAttribute; } /** * Gets the deleted attribute. * * @return the deleted attribute */ public IAttribute getDeletedAttribute() { return deletedAttribute; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__deleted_att_from_dn, new String[] { getDeletedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BrowserConnectionUpdateListener.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BrowserConnectionUpdateListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import java.util.EventListener; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; /** * A listener for {@link BrowserConnectionUpdateEvent}s * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface BrowserConnectionUpdateListener extends EventListener { /** * Called when an {@link IBrowserConnection} was updated. * * @param browserConnectionUpdateEvent the browser connection update event */ void browserConnectionUpdated( BrowserConnectionUpdateEvent browserConnectionUpdateEvent ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EventRegistry.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry; import org.apache.directory.studio.connection.core.event.EventRunnable; import org.apache.directory.studio.connection.core.event.EventRunnableFactory; import org.apache.directory.studio.connection.core.event.EventRunner; /** * The EventRegistry is a central point to register for Apache Directory Studio specific * events and to fire events to registered listeners. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EventRegistry extends ConnectionEventRegistry { static final EventManager<SearchUpdateListener, EventRunner> searchUpdateEventManager = new EventManager<SearchUpdateListener, EventRunner>(); /** * Adds the search update listener. * * @param listener the listener * @param runner the runner */ public static void addSearchUpdateListener( SearchUpdateListener listener, EventRunner runner ) { searchUpdateEventManager.addListener( listener, runner ); } /** * Removes the search update listener. * * @param listener the listener */ public static void removeSearchUpdateListener( SearchUpdateListener listener ) { searchUpdateEventManager.removeListener( listener ); } /** * Notifies each {@link SearchUpdateListener} about the the given {@link SearchUpdateEvent}. * Uses the {@link EventRunner}s. * * @param searchUpdateEvent the search update event * @param source the source */ public static void fireSearchUpdated( final SearchUpdateEvent searchUpdateEvent, final Object source ) { EventRunnableFactory<SearchUpdateListener> factory = new EventRunnableFactory<SearchUpdateListener>() { public EventRunnable createEventRunnable( final SearchUpdateListener listener ) { return new EventRunnable() { public void run() { listener.searchUpdated( searchUpdateEvent ); } }; } }; searchUpdateEventManager.fire( factory ); } static final EventManager<BookmarkUpdateListener, EventRunner> bookmarkUpdateEventManager = new EventManager<BookmarkUpdateListener, EventRunner>(); /** * Adds the bookmark update listener. * * @param listener the listener * @param runner the runner */ public static void addBookmarkUpdateListener( BookmarkUpdateListener listener, EventRunner runner ) { bookmarkUpdateEventManager.addListener( listener, runner ); } /** * Removes the bookmark update listener. * * @param listener the listener */ public static void removeBookmarkUpdateListener( BookmarkUpdateListener listener ) { bookmarkUpdateEventManager.removeListener( listener ); } /** * Notifies each {@link BookmarkUpdateListener} about the the given {@link BookmarkUpdateEvent}. * Uses the {@link EventRunner}s. * * @param bookmarkUpdateEvent the bookmark update event * @param source the source */ public static void fireBookmarkUpdated( final BookmarkUpdateEvent bookmarkUpdateEvent, final Object source ) { EventRunnableFactory<BookmarkUpdateListener> factory = new EventRunnableFactory<BookmarkUpdateListener>() { public EventRunnable createEventRunnable( final BookmarkUpdateListener listener ) { return new EventRunnable() { public void run() { listener.bookmarkUpdated( bookmarkUpdateEvent ); } }; } }; bookmarkUpdateEventManager.fire( factory ); } static final EventManager<BrowserConnectionUpdateListener, EventRunner> browserConnectionUpdateEventManager = new EventManager<BrowserConnectionUpdateListener, EventRunner>(); /** * Adds the browser connection update listener. * * @param listener the listener * @param runner the runner */ public static void addBrowserConnectionUpdateListener( BrowserConnectionUpdateListener listener, EventRunner runner ) { browserConnectionUpdateEventManager.addListener( listener, runner ); } /** * Removes the browser connection update listener. * * @param listener the listener */ public static void removeBrowserConnectionUpdateListener( BrowserConnectionUpdateListener listener ) { browserConnectionUpdateEventManager.removeListener( listener ); } /** * Notifies each {@link BrowserConnectionUpdateListener} about the the given {@link BrowserConnectionUpdateEvent}. * Uses the {@link EventRunner}s. * * @param browserConnectionUpdateEvent the browser connection update event * @param source the source */ public static void fireBrowserConnectionUpdated( final BrowserConnectionUpdateEvent browserConnectionUpdateEvent, final Object source ) { EventRunnableFactory<BrowserConnectionUpdateListener> factory = new EventRunnableFactory<BrowserConnectionUpdateListener>() { public EventRunnable createEventRunnable( final BrowserConnectionUpdateListener listener ) { return new EventRunnable() { public void run() { listener.browserConnectionUpdated( browserConnectionUpdateEvent ); } }; } }; browserConnectionUpdateEventManager.fire( factory ); } static final EventManager<EntryUpdateListener, EventRunner> entryUpdateEventManager = new EventManager<EntryUpdateListener, EventRunner>(); /** * Adds the entry update listener. * * @param listener the listener * @param runner the runner */ public static void addEntryUpdateListener( EntryUpdateListener listener, EventRunner runner ) { entryUpdateEventManager.addListener( listener, runner ); } /** * Removes the entry update listener. * * @param listener the listener */ public static void removeEntryUpdateListener( EntryUpdateListener listener ) { entryUpdateEventManager.removeListener( listener ); } /** * Notifies each {@link EntryUpdateListener} about the the given {@link EntryModificationEvent}. * Uses the {@link EventRunner}s. * * @param entryUpdateEvent the entry update event * @param source the source */ public static void fireEntryUpdated( final EntryModificationEvent entryUpdateEvent, final Object source ) { entryUpdateEvent.setSource( source ); EventRunnableFactory<EntryUpdateListener> factory = new EventRunnableFactory<EntryUpdateListener>() { public EventRunnable createEventRunnable( final EntryUpdateListener listener ) { return new EventRunnable() { public void run() { listener.entryUpdated( entryUpdateEvent ); } }; } public String toString() { return "EventRunnableFactory [entryUpdateEvent=" + entryUpdateEvent + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } }; entryUpdateEventManager.fire( factory ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueRenamedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueRenamedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An ValueRenamedEvent indicates that an {@link IValue} was renamed. This * means that the attribute type was modified. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueRenamedEvent extends EntryModificationEvent { /** The old value with the old attribute type. */ private IValue oldValue; /** The new value with the new attribute type. */ private IValue newValue; /** * Creates a new instance of ValueRenamedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param oldValue the old value with the old attribute type * @param newValue the new value with the new attribute type */ public ValueRenamedEvent( IBrowserConnection connection, IEntry modifiedEntry, IValue oldValue, IValue newValue ) { super( connection, modifiedEntry ); this.oldValue = oldValue; this.newValue = newValue; } /** * Gets the new value with the new attribute type. * * @return the new value with the new attribute type */ public IValue getNewValue() { return newValue; } /** * Gets the old value with the old attribute type. * * @return the old value with the old attribute type */ public IValue getOldValue() { return oldValue; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__renamed_oldval_by_newval_at_dn, new String[] { getOldValue().toString(), getNewValue().toString(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/SearchUpdateListener.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/SearchUpdateListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import java.util.EventListener; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; /** * A listener for {@link SearchUpdateEvent}s * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface SearchUpdateListener extends EventListener { /** * Called when an {@link ISearch} was updated. * * @param searchUpdateEvent the search update event */ void searchUpdated( SearchUpdateEvent searchUpdateEvent ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BrowserConnectionUpdateEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BrowserConnectionUpdateEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; /** * An BrowserConnectionUpdateEvent indicates that an {@link IBrowserConnection} was modified. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserConnectionUpdateEvent { /** * Contains constants to specify the event detail. */ public enum Detail { /** Indicates that the browser connection was opened. */ BROWSER_CONNECTION_OPENED, /** Indicates that the browser connection was closed. */ BROWSER_CONNECTION_CLOSED, /** Indicates that the schema was updated. */ SCHEMA_UPDATED } /** The event detail. */ private Detail detail; /** The updated browser connection. */ private IBrowserConnection browserConnection; /** * Creates a new instance of BrowserConnectionUpdateEvent. * * @param browserConnection the updated browser connection * @param detail the event detail */ public BrowserConnectionUpdateEvent( IBrowserConnection browserConnection, Detail detail ) { this.browserConnection = browserConnection; this.detail = detail; } /** * Gets the updated browser connection. * * @return the updated browser connection */ public IBrowserConnection getBrowserConnection() { return browserConnection; } /** * Gets the event detail. * * @return the event detail */ public Detail getDetail() { return detail; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueMultiModificationEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueMultiModificationEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An ValueMultiModificationEvent indicates that multiple {@link IValue}s of an * {@link IEntry} were added, modified, deleted and/or renamed. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueMultiModificationEvent extends EntryModificationEvent { /** * Creates a new instance of ValueMultiModificationEvent. * * @param connection the connection * @param modifiedEntry the modified entry */ public ValueMultiModificationEvent( IBrowserConnection connection, IEntry modifiedEntry ) { super( connection, modifiedEntry ); } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.event__bulk_modification; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueDeletedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueDeletedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An ValueDeletedEvent indicates that an {@link IValue} was deleted from an {@link IEntry}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueDeletedEvent extends EntryModificationEvent { /** The modified attribute. */ private IAttribute modifiedAttribute; /** The deleted value. */ private IValue deletedValue; /** * Creates a new instance of ValueDeletedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param modifiedAttribute the modified attribute * @param deletedValue the deleted value */ public ValueDeletedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute modifiedAttribute, IValue deletedValue ) { super( connection, modifiedEntry ); this.modifiedAttribute = modifiedAttribute; this.deletedValue = deletedValue; } /** * Gets the modified attribute. * * @return the modified attribute */ public IAttribute getModifiedAttribute() { return modifiedAttribute; } /** * Gets the deleted value. * * @return the deleted value */ public IValue getDeletedValue() { return deletedValue; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__deleted_val_from_att_at_dn, new String[] { getDeletedValue().getStringValue(), getModifiedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryRenamedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryRenamedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An EntryRenamedEvent indicates that an {@link IEntry} was renamed in the underlying directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryRenamedEvent extends EntryModificationEvent { /** The old entry. */ private IEntry oldEntry; /** The new entry. */ private IEntry newEntry; /** * Creates a new instance of EntryRenamedEvent. * * @param oldEntry the old entry * @param newEntry the new entry */ public EntryRenamedEvent( IEntry oldEntry, IEntry newEntry ) { super( newEntry.getBrowserConnection(), newEntry.getParententry() ); this.oldEntry = oldEntry; this.newEntry = newEntry; } /** * Gets the new entry with the new Dn. * * @return the new entry */ public IEntry getNewEntry() { return newEntry; } /** * Gets the old entry with the old Dn. * * @return the old entry */ public IEntry getOldEntry() { return oldEntry; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__renamed_olddn_to_newdn, new String[] { getOldEntry().getDn().getName(), getNewEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryUpdateListener.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryUpdateListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import java.util.EventListener; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * A listener for {@link EntryModificationEvent}s * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface EntryUpdateListener extends EventListener { /** * Called when an {@link IEntry} was updated. * * @param event the event */ void entryUpdated( EntryModificationEvent event ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/AttributeAddedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/AttributeAddedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An AttributeAddedEvent indicates that an {@link IAttribute} was added to an {@link IEntry}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeAddedEvent extends EntryModificationEvent { /** The added attribute. */ private IAttribute addedAttribute; /** * Creates a new instance of AttributeAddedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param addedAttribute the added attribute */ public AttributeAddedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute addedAttribute ) { super( connection, modifiedEntry ); this.addedAttribute = addedAttribute; } /** * Gets the added attribute. * * @return the added attribute */ public IAttribute getAddedAttribute() { return addedAttribute; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__added_att_to_dn, new String[] { getAddedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryDeletedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryDeletedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An EntryDeletedEvent indicates that an {@link IEntry} was deleted from the underlying directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryDeletedEvent extends EntryModificationEvent { /** * Creates a new instance of EntryDeletedEvent. * * @param connection the connection * @param deletedEntry the deleted entry */ public EntryDeletedEvent( IBrowserConnection connection, IEntry deletedEntry ) { super( connection, deletedEntry ); } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__deleted_dn, new String[] { getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BulkModificationEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BulkModificationEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; /** * A BulkModificationEvent indicates that a bulk modification has occurred. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BulkModificationEvent extends EntryModificationEvent { /** * Creates a new instance of BulkModificationEvent. * * @param connection the connection */ public BulkModificationEvent( IBrowserConnection connection ) { super( connection, connection.getRootDSE() ); } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.event__bulk_modification; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EmptyValueDeletedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EmptyValueDeletedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An EmptyValueDeletedEvent indicates that an empty {@link IValue} was deleted from an {@link IEntry}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EmptyValueDeletedEvent extends EntryModificationEvent { /** The modified attribute. */ private IAttribute modifiedAttribute; /** The deleted value. */ private IValue deletedValue; /** * Creates a new instance of EmptyValueDeletedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param modifiedAttribute the modified attribute * @param deletedValue the deleted value */ public EmptyValueDeletedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute modifiedAttribute, IValue deletedValue ) { super( connection, modifiedEntry ); this.modifiedAttribute = modifiedAttribute; this.deletedValue = deletedValue; } /** * Gets the modified attribute. * * @return the modified attribute */ public IAttribute getModifiedAttribute() { return this.modifiedAttribute; } /** * Gets the deleted value. * * @return the deleted value */ public IValue getDeletedValue() { return this.deletedValue; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__empty_value_deleted_from_att_at_dn, new String[] { getModifiedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EmptyValueAddedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EmptyValueAddedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An EmptyValueAddedEvent indicates that an empty {@link IValue} was added to an {@link IEntry}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EmptyValueAddedEvent extends EntryModificationEvent { /** The modified attribute. */ private IAttribute modifiedAttribute; /** The added value. */ private IValue addedValue; /** * Creates a new instance of EmptyValueAddedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param modifiedAttribute the modified attribute * @param addedValue the added value */ public EmptyValueAddedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute modifiedAttribute, IValue addedValue ) { super( connection, modifiedEntry ); this.modifiedAttribute = modifiedAttribute; this.addedValue = addedValue; } /** * Gets the modified attribute. * * @return the modified attribute */ public IAttribute getModifiedAttribute() { return this.modifiedAttribute; } /** * Gets the added value. * * @return the added value */ public IValue getAddedValue() { return this.addedValue; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__empty_value_added_to_att_at_dn, new String[] { getModifiedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BookmarkUpdateListener.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BookmarkUpdateListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import java.util.EventListener; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; /** * A listener for {@link BookmarkUpdateEvent}s * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface BookmarkUpdateListener extends EventListener { /** * Called when an {@link IBookmark} was updated. * * @param bookmarkUpdateEvent the bookmark update event */ void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryAddedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryAddedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An EntryAddedEvent indicates that an {@link IEntry} was added to the underlying directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryAddedEvent extends EntryModificationEvent { /** * Creates a new instance of EntryAddedEvent. * * @param connection the connection * @param addedEntry the added entry */ public EntryAddedEvent( IBrowserConnection connection, IEntry addedEntry ) { super( connection, addedEntry ); } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__added_dn, new String[] { getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/AttributesInitializedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/AttributesInitializedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An AttributesInitializedEvent indicates that the {@link IAttribute}s * of an {@link IEntry} were newly initialized from the underlying * directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributesInitializedEvent extends EntryModificationEvent { /** * Creates a new instance of AttributesInitializedEvent. * * @param initializedEntry the initialized entry */ public AttributesInitializedEvent( IEntry initializedEntry ) { super( initializedEntry.getBrowserConnection(), initializedEntry ); } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__dn_attributes_initialized, new String[] { getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryMovedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/EntryMovedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * An EntryMovedEvent indicates that an {@link IEntry} was moved in the underlying directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryMovedEvent extends EntryModificationEvent { /** The old entry. */ private IEntry oldEntry; /** The new entry. */ private IEntry newEntry; /** * Creates a new instance of EntryMovedEvent. * * @param oldEntry the old entry * @param newEntry the new entry */ public EntryMovedEvent( IEntry oldEntry, IEntry newEntry ) { super( newEntry.getBrowserConnection(), newEntry.getParententry() ); this.oldEntry = oldEntry; this.newEntry = newEntry; } /** * Gets the new entry with the new Dn. * * @return the new entry */ public IEntry getNewEntry() { return newEntry; } /** * Gets the old entry with the old Dn. * * @return the old entry */ public IEntry getOldEntry() { return oldEntry; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__moved_oldrdn_from_oldparent_to_newparent, new String[] { getOldEntry().getDn().getRdn().getName(), getOldEntry().getParententry().getDn().getName(), getNewEntry().getParententry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BookmarkUpdateEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/BookmarkUpdateEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; /** * An BookmarkUpdateEvent indicates that an {@link IBookmark} was modified. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BookmarkUpdateEvent { /** * Contains constants to specify the event detail. */ public enum Detail { /** Indicates that the bookmark was added. */ BOOKMARK_ADDED, /** Indicates that the bookmark was updated. */ BOOKMARK_UPDATED, /** Indicates that the bookmark was removed. */ BOOKMARK_REMOVED } /** The event detail. */ private Detail detail; /** The updated bookmark. */ private IBookmark bookmark; /** * Creates a new instance of BookmarkUpdateEvent. * * @param bookmark the updated bookmark * @param detail the event detail */ public BookmarkUpdateEvent( IBookmark bookmark, Detail detail ) { this.bookmark = bookmark; this.detail = detail; } /** * Gets the updated bookmark. * * @return the updated bookmark */ public IBookmark getBookmark() { return bookmark; } /** * Gets the event detail. * * @return the event detail */ public Detail getDetail() { return detail; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueModifiedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueModifiedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An ValueModifiedEvent indicates that an {@link IValue} was modified. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueModifiedEvent extends EntryModificationEvent { /** The modified attribute. */ private IAttribute modifiedAttribute; /** The old value. */ private IValue oldValue; /** The new value. */ private IValue newValue; /** * Creates a new instance of ValueModifiedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param modifiedAttribute the modified attribute * @param oldValue the old value * @param newValue the new value */ public ValueModifiedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute modifiedAttribute, IValue oldValue, IValue newValue ) { super( connection, modifiedEntry ); this.modifiedAttribute = modifiedAttribute; this.oldValue = oldValue; this.newValue = newValue; } /** * Gets the modified attribute. * * @return the modified attribute */ public IAttribute getModifiedAttribute() { return modifiedAttribute; } /** * Gets the old value. * * @return the old value */ public IValue getOldValue() { return oldValue; } /** * Gets the new value. * * @return the new value */ public IValue getNewValue() { return newValue; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__replaced_oldval_by_newval_at_att_at_dn, new String[] { getOldValue().getStringValue(), getNewValue().getStringValue(), getModifiedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/SearchUpdateEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/SearchUpdateEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; /** * An SearchUpdateEvent indicates that an {@link ISearch} was updated. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchUpdateEvent { /** * Contains constants to specify the event detail. */ public enum EventDetail { /** Indicates that the search was added. */ SEARCH_ADDED, /** Indicates that the search was removed. */ SEARCH_REMOVED, /** Indicates that the search was performed. */ SEARCH_PERFORMED, /** * Indicates that the search parameters were updated. * Note: This event detail doesn't include the renaming of a search! */ SEARCH_PARAMETER_UPDATED, /** Indicates that the search was renamed. */ SEARCH_RENAMED } /** The event detail. */ private EventDetail detail; /** The updated search. */ private ISearch search; /** * Creates a new instance of SearchUpdateEvent. * * @param search the updated search * @param detail the event detail */ public SearchUpdateEvent( ISearch search, EventDetail detail ) { this.search = search; this.detail = detail; } /** * Gets the updated search. * * @return the updated search */ public ISearch getSearch() { return search; } /** * Gets the event detail. * * @return the event detail */ public EventDetail getDetail() { return detail; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueAddedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ValueAddedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; /** * An ValueAddedEvent indicates that an {@link IValue} was added to an {@link IEntry}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueAddedEvent extends EntryModificationEvent { /** The modified attribute. */ private IAttribute modifiedAttribute; /** The added value. */ private IValue addedValue; /** * Creates a new instance of ValueAddedEvent. * * @param connection the connection * @param modifiedEntry the modified entry * @param modifiedAttribute the modified attribute * @param addedValue the added value */ public ValueAddedEvent( IBrowserConnection connection, IEntry modifiedEntry, IAttribute modifiedAttribute, IValue addedValue ) { super( connection, modifiedEntry ); this.modifiedAttribute = modifiedAttribute; this.addedValue = addedValue; } /** * Gets the modified attribute. * * @return the modified attribute */ public IAttribute getModifiedAttribute() { return modifiedAttribute; } /** * Gets the added value. * * @return the added value */ public IValue getAddedValue() { return addedValue; } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__added_val_to_att_at_dn, new String[] { getAddedValue().getStringValue(), getModifiedAttribute().getDescription(), getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ChildrenInitializedEvent.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/events/ChildrenInitializedEvent.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.events; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * A ChildrenInitializedEvent indicates that the children * of an {@link IEntry} were newly initialized from the underlying * directory. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ChildrenInitializedEvent extends EntryModificationEvent { /** * Creates a new instance of ChildrenInitializedEvent. * * @param initializedEntry the initialized entry */ public ChildrenInitializedEvent( IEntry initializedEntry ) { super( initializedEntry.getBrowserConnection(), initializedEntry ); } /** * {@inheritDoc} */ public String toString() { return BrowserCoreMessages.bind( BrowserCoreMessages.event__dn_children_initialized, new String[] { getModifiedEntry().getDn().getName() } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/search/LdapSearchPageScoreComputer.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/search/LdapSearchPageScoreComputer.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.internal.search; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.search.ui.ISearchPageScoreComputer; public class LdapSearchPageScoreComputer implements ISearchPageScoreComputer { public static final String LDAP_SEARCH_PAGE_ID = BrowserCoreConstants.LDAP_SEARCH_PAGE_ID; public int computeScore( String pageId, Object input ) { if ( pageId.equals( LDAP_SEARCH_PAGE_ID ) ) { return 90; } return 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/EntryPropertyPageProvider.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/EntryPropertyPageProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.propertypageproviders; public interface EntryPropertyPageProvider { }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/BookmarkPropertyPageProvider.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/BookmarkPropertyPageProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.propertypageproviders; public interface BookmarkPropertyPageProvider { }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/ValuePropertyPageProvider.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/ValuePropertyPageProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.propertypageproviders; public interface ValuePropertyPageProvider { }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/AttributePropertyPageProvider.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/AttributePropertyPageProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.propertypageproviders; public interface AttributePropertyPageProvider { }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/SearchPropertyPageProvider.java
plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/propertypageproviders/SearchPropertyPageProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.core.propertypageproviders; public interface SearchPropertyPageProvider { }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/test/java/org/apache/directory/studio/schemaeditor/model/difference/DifferenceEngineTest.java
plugins/schemaeditor/src/test/java/org/apache/directory/studio/schemaeditor/model/difference/DifferenceEngineTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.model.difference; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum; import org.apache.directory.api.ldap.model.schema.UsageEnum; import org.junit.jupiter.api.Test; /** * This class tests the DifferenceEngine class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DifferenceEngineTest { /** * Tests the AddAliasDifference. * * @throws Exception */ @Test public void testAddAliasDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setNames( new String[] { "alias" } ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof AliasDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "alias", ( ( AliasDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddDescriptionDifference. * * @throws Exception */ @Test public void testAddDescriptionDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setDescription( "Description" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof DescriptionDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "Description", ( ( DescriptionDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddEqualityDifference. * * @throws Exception */ @Test public void testAddEqualityDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setEqualityOid( "Equality" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof EqualityDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "Equality", ( ( EqualityDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddMandatoryATDifference. * * @throws Exception */ @Test public void testAddMandatoryATDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setMustAttributeTypeOids( Arrays.asList( new String[] { "must" } ) ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof MandatoryATDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "must", ( ( MandatoryATDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddOptionalATDifference. * * @throws Exception */ @Test public void testAddOptionalATDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setMayAttributeTypeOids( Arrays.asList( new String[] { "may" } ) ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof OptionalATDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "may", ( ( OptionalATDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddOrderingDifference. * * @throws Exception */ @Test public void testAddOrderingDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setOrderingOid( "Ordering" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof OrderingDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "Ordering", ( ( OrderingDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddSubstringDifference. * * @throws Exception */ @Test public void testAddSubstringDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSubstringOid( "Substring" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SubstringDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "Substring", ( ( SubstringDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddSuperiorATDifference. * * @throws Exception */ @Test public void testAddSuperiorATDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSuperiorOid( "superiorAT" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SuperiorATDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "superiorAT", ( ( SuperiorATDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddSuperiorOCDifference. * * @throws Exception */ @Test public void testAddSuperiorOCDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setSuperiorOids( Arrays.asList( new String[] { "superiorOC" } ) ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SuperiorOCDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "superiorOC", ( ( SuperiorOCDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddSyntaxDifference. * * @throws Exception */ @Test public void testAddSyntaxDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSyntaxOid( "1.2.3.4.5" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SyntaxDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( "1.2.3.4.5", ( ( SyntaxDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the AddSyntaxLengthDifference. * * @throws Exception */ @Test public void testAddSyntaxLengthDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSyntaxLength( 1234 ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SyntaxLengthDifference ) || ( !difference.getType().equals( DifferenceType.ADDED ) ) ) { fail(); } assertEquals( 1234L, ( ( SyntaxLengthDifference ) difference ).getNewValue() ); } /** * Tests the ModifyClassTypeDifference. * * @throws Exception */ @Test public void testModifyClassTypeDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o1.setType( ObjectClassTypeEnum.STRUCTURAL ); ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setType( ObjectClassTypeEnum.ABSTRACT ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof ClassTypeDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( ObjectClassTypeEnum.STRUCTURAL, ( ( ClassTypeDifference ) difference ).getOldValue() ); assertEquals( ObjectClassTypeEnum.ABSTRACT, ( ( ClassTypeDifference ) difference ).getNewValue() ); } /** * Tests the ModifyCollectiveDifference. * * @throws Exception */ @Test public void testModifyCollectiveDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setCollective( true ); AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setCollective( false ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof CollectiveDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( true, ( ( CollectiveDifference ) difference ).getOldValue() ); assertEquals( false, ( ( CollectiveDifference ) difference ).getNewValue() ); } /** * Tests the ModifyDescriptionDifference. * * @throws Exception */ @Test public void testModifyDescriptionDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setDescription( "Description" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setDescription( "New Description" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof DescriptionDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( "Description", ( ( DescriptionDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertEquals( "New Description", ( ( DescriptionDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the ModifyEqualityDifference. * * @throws Exception */ @Test public void testModifyEqualityDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setEqualityOid( "equalityName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setEqualityOid( "newEqualityName" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof EqualityDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( "equalityName", ( ( EqualityDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertEquals( "newEqualityName", ( ( EqualityDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the ModifyNoUserModificationDifference. * * @throws Exception */ @Test public void testModifyNoUserModificationDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setUserModifiable( true ); AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setUserModifiable( false ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof NoUserModificationDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( true, ( ( NoUserModificationDifference ) difference ).getOldValue() ); assertEquals( false, ( ( NoUserModificationDifference ) difference ).getNewValue() ); } /** * Tests the ModifyObsoleteDifference. * * @throws Exception */ @Test public void testModifyObsoleteDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setObsolete( true ); AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setObsolete( false ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof ObsoleteDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( true, ( ( ObsoleteDifference ) difference ).getOldValue() ); assertEquals( false, ( ( ObsoleteDifference ) difference ).getNewValue() ); } /** * Tests the ModifyOrderingDifference. * * @throws Exception */ @Test public void testModifyOrderingDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setOrderingOid( "orderingName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setOrderingOid( "newOrderingName" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof OrderingDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( "orderingName", ( ( OrderingDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertEquals( "newOrderingName", ( ( OrderingDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the ModifySingleValueDifference. * * @throws Exception */ @Test public void testModifySingleValueDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSingleValued( true ); AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSingleValued( false ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SingleValueDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( true, ( ( SingleValueDifference ) difference ).getOldValue() ); assertEquals( false, ( ( SingleValueDifference ) difference ).getNewValue() ); } /** * Tests the ModifySubstringDifference. * * @throws Exception */ @Test public void testModifySubstringDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSubstringOid( "substrName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSubstringOid( "newSubstrName" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SubstringDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( "substrName", ( ( SubstringDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertEquals( "newSubstrName", ( ( SubstringDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the ModifySuperiorATDifference. * * @throws Exception */ @Test public void testModifySuperiorATDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSuperiorOid( "superiorName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSuperiorOid( "newSuperiorName" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SuperiorATDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( "superiorName", ( ( SuperiorATDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertEquals( "newSuperiorName", ( ( SuperiorATDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the ModifySyntaxDifference. * * @throws Exception */ @Test public void testModifySyntaxDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSyntaxOid( "1.2.3.4.5" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSyntaxOid( "1.2.3.4.6" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SyntaxDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( "1.2.3.4.5", ( ( SyntaxDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertEquals( "1.2.3.4.6", ( ( SyntaxDifference ) difference ).getNewValue() ); //$NON-NLS-1$ } /** * Tests the ModifySyntaxLengthDifference. * * @throws Exception */ @Test public void testModifySyntaxLengthDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSyntaxLength( 1234 ); AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setSyntaxLength( 12345 ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SyntaxLengthDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( 1234L, ( ( SyntaxLengthDifference ) difference ).getOldValue() ); assertEquals( 12345L, ( ( SyntaxLengthDifference ) difference ).getNewValue() ); } /** * Tests the ModifyUsageDifference. * * @throws Exception */ @Test public void testModifyUsageDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setUsage( UsageEnum.DIRECTORY_OPERATION ); List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof UsageDifference ) || ( !difference.getType().equals( DifferenceType.MODIFIED ) ) ) { fail(); } assertEquals( UsageEnum.DISTRIBUTED_OPERATION, ( ( UsageDifference ) difference ).getOldValue() ); assertEquals( UsageEnum.DIRECTORY_OPERATION, ( ( UsageDifference ) difference ).getNewValue() ); } /** * Tests the RemoveAliasDifference. * * @throws Exception */ @Test public void testRemoveAliasDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setNames( new String[] { "name1", "name2" } ); //$NON-NLS-1$ //$NON-NLS-2$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o2.setNames( new String[] { "name2" } ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof AliasDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "name1", ( ( AliasDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( AliasDifference ) difference ).getNewValue() ); } /** * Tests the RemoveDescriptionDifference. * * @throws Exception */ @Test public void testRemoveDescriptionDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setDescription( "Description" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof DescriptionDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "Description", ( ( DescriptionDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( DescriptionDifference ) difference ).getNewValue() ); } /** * Tests the RemoveEqualityDifference. * * @throws Exception */ @Test public void testRemoveEqualityDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setEqualityOid( "equalityName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof EqualityDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "equalityName", ( ( EqualityDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( EqualityDifference ) difference ).getNewValue() ); } /** * Tests the RemoveMandatoryATDifference. * * @throws Exception */ @Test public void testRemoveMandatoryATDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o1.setMustAttributeTypeOids( Arrays.asList( new String[] { "must1", "must2" } ) ); //$NON-NLS-1$ //$NON-NLS-2$ ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setMustAttributeTypeOids( Arrays.asList( new String[] { "must2" } ) ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof MandatoryATDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "must1", ( ( MandatoryATDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( MandatoryATDifference ) difference ).getNewValue() ); } /** * Tests the RemoveOptionalATDifference. * * @throws Exception */ @Test public void testRemoveOptionalATDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o1.setMayAttributeTypeOids( Arrays.asList( new String[] { "may1", "may2" } ) ); //$NON-NLS-1$ //$NON-NLS-2$ ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setMayAttributeTypeOids( Arrays.asList( new String[] { "may2" } ) ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof OptionalATDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "may1", ( ( OptionalATDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( OptionalATDifference ) difference ).getNewValue() ); } /** * Tests the RemoveOrderingDifference. * * @throws Exception */ @Test public void testRemoveOrderingDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setOrderingOid( "orderingName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof OrderingDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "orderingName", ( ( OrderingDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( OrderingDifference ) difference ).getNewValue() ); } /** * Tests the RemoveSubstringDifference. * * @throws Exception */ @Test public void testRemoveSubstringDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSubstringOid( "substrName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SubstringDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "substrName", ( ( SubstringDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( SubstringDifference ) difference ).getNewValue() ); } /** * Tests the RemoveSuperiorATDifference. * * @throws Exception */ @Test public void testRemoveSuperiorATDifference() throws Exception { AttributeType o1 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ o1.setSuperiorOid( "superiorName" ); //$NON-NLS-1$ AttributeType o2 = new AttributeType( "1.2.3.4" ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SuperiorATDifference ) || ( !difference.getType().equals( DifferenceType.REMOVED ) ) ) { fail(); } assertEquals( "superiorName", ( ( SuperiorATDifference ) difference ).getOldValue() ); //$NON-NLS-1$ assertNull( ( ( SuperiorATDifference ) difference ).getNewValue() ); } /** * Tests the RemoveSuperiorOCDifference. * * @throws Exception */ @Test public void testRemoveSuperiorOCDifference() throws Exception { ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o1.setSuperiorOids( Arrays.asList( new String[] { "sup1", "sup2" } ) ); //$NON-NLS-1$ //$NON-NLS-2$ ObjectClass o2 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$ o2.setSuperiorOids( Arrays.asList( new String[] { "sup2" } ) ); //$NON-NLS-1$ List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 ); assertEquals( 1, differences.size() ); Difference difference = differences.get( 0 ); if ( !( difference instanceof SuperiorOCDifference )
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/test/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParserTest.java
plugins/schemaeditor/src/test/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParserTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.model.alias; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; import org.junit.jupiter.api.Test; /** * This class tests the {@link AliasesStringParser} class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AliasesStringParserTest { @Test public void testNoAlias() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 0, aliases.size() ); } @Test public void testOneAlias() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "test" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 1, aliases.size() ); assertEquals( "test", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ } @Test public void testTwoAliases() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "test1, test2" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 2, aliases.size() ); assertEquals( "test1", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( "test2", aliases.get( 1 ).getAlias() ); //$NON-NLS-1$ } @Test public void testThreeAliases() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "test1, test2, test3" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 3, aliases.size() ); assertEquals( "test1", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( "test2", aliases.get( 1 ).getAlias() ); //$NON-NLS-1$ assertEquals( "test3", aliases.get( 2 ).getAlias() ); //$NON-NLS-1$ } @Test public void testMultipleCommasNoAlias() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( ",,,,,,,,,,,," ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 0, aliases.size() ); } @Test public void testMultipleCommasAndWhiteSpacesNoAlias() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( ", , , , , ,,,," ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 0, aliases.size() ); } @Test public void testTwoAliasesMultipleCommas() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( ",,test1,,,,,,test2,,,," ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 2, aliases.size() ); assertEquals( "test1", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( "test2", aliases.get( 1 ).getAlias() ); //$NON-NLS-1$ } @Test public void testOneAliasWithStartError() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "1test" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 1, aliases.size() ); assertEquals( "1test", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithStartError.class, aliases.get( 0 ).getClass() ); } @Test public void testOneAliasWithStartError2() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "1" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 1, aliases.size() ); assertEquals( "1", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithStartError.class, aliases.get( 0 ).getClass() ); } @Test public void testOneAliasWithPartError() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "tes/t" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 1, aliases.size() ); assertEquals( "tes/t", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithPartError.class, aliases.get( 0 ).getClass() ); } @Test public void testOneAliasWithPartError2() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "tes/" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 1, aliases.size() ); assertEquals( "tes/", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithPartError.class, aliases.get( 0 ).getClass() ); } @Test public void testOneAliasWithPartErrorAndOneAliasWithStartError() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "tes/t, 1test" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 2, aliases.size() ); assertEquals( "tes/t", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithPartError.class, aliases.get( 0 ).getClass() ); assertEquals( "1test", aliases.get( 1 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithStartError.class, aliases.get( 1 ).getClass() ); } @Test public void testOneAliasWithPartErrorAndOneAliasWithStartError2() throws Exception { AliasesStringParser parser = new AliasesStringParser(); parser.parse( "tes/, 1" ); //$NON-NLS-1$ List<Alias> aliases = parser.getAliases(); assertEquals( 2, aliases.size() ); assertEquals( "tes/", aliases.get( 0 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithPartError.class, aliases.get( 0 ).getClass() ); assertEquals( "1", aliases.get( 1 ).getAlias() ); //$NON-NLS-1$ assertEquals( AliasWithStartError.class, aliases.get( 1 ).getClass() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/test/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileExporterTest.java
plugins/schemaeditor/src/test/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileExporterTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.model.io; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.Collections; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum; import org.apache.directory.api.ldap.model.schema.UsageEnum; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapSchemaFileExporterTest { private ObjectClass objectClassSimple; private ObjectClass objectClassComplex; private AttributeType attributeTypeSimple; private AttributeType attributeTypeComplex; @BeforeEach public void setUp() { objectClassSimple = new ObjectClass( "1.2.3.4" ); objectClassSimple.setNames( "name0" ); objectClassSimple.setMustAttributeTypeOids( Arrays.asList( "att0" ) ); objectClassSimple.setSchemaName( "dummy" ); objectClassComplex = new ObjectClass( "1.2.3.4" ); objectClassComplex.setNames( "name1", "name2" ); objectClassComplex.setDescription( "description with 'quotes'" ); objectClassComplex.setObsolete( true ); objectClassComplex.setSuperiorOids( Collections.singletonList( "1.3.5.7" ) ); objectClassComplex.setType( ObjectClassTypeEnum.AUXILIARY ); objectClassComplex.setMustAttributeTypeOids( Arrays.asList( "att1", "att2" ) ); objectClassComplex.setMayAttributeTypeOids( Arrays.asList( "att3", "att4" ) ); objectClassComplex.setSchemaName( "dummy" ); attributeTypeSimple = new AttributeType( "1.2.3.4" ); attributeTypeSimple.setNames( "name0" ); attributeTypeSimple.setEqualityOid( "matchingRule0" ); attributeTypeSimple.setSyntaxOid( "2.3.4.5" ); attributeTypeSimple.setSyntaxLength( 512 ); attributeTypeSimple.setCollective( true ); attributeTypeSimple.setSchemaName( "dummy" ); attributeTypeComplex = new AttributeType( "1.2.3.4" ); attributeTypeComplex.setNames( "name1", "name2" ); attributeTypeComplex.setDescription( "description with 'quotes'" ); attributeTypeComplex.setObsolete( true ); attributeTypeComplex.setSuperiorOid( "superAttr" ); attributeTypeComplex.setEqualityOid( "matchingRule1" ); attributeTypeComplex.setOrderingOid( "matchingRule2" ); attributeTypeComplex.setSubstringOid( "matchingRule3" ); attributeTypeComplex.setSingleValued( true ); attributeTypeComplex.setUserModifiable( false ); attributeTypeComplex.setUsage( UsageEnum.DIRECTORY_OPERATION ); attributeTypeComplex.setSchemaName( "dummy" ); } @Test public void testOpenLdapSchemaRendererObjectClassSimple() { String actual = OpenLdapSchemaFileExporter.toSourceCode( objectClassSimple ); String expected = "objectclass ( 1.2.3.4 NAME 'name0'\n\tSTRUCTURAL\n\tMUST att0 )"; assertEquals( expected, actual ); } @Test public void testOpenLdapSchemaRendererObjectClassComplex() { String actual = OpenLdapSchemaFileExporter.toSourceCode( objectClassComplex ); String expected = "objectclass ( 1.2.3.4 NAME ( 'name1' 'name2' )\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tSUP 1.3.5.7\n\tAUXILIARY\n\tMUST ( att1 $ att2 )\n\tMAY ( att3 $ att4 ) )"; assertEquals( expected, actual ); } @Test public void testOpenLdapSchemaRendererAttributeTypeSimple() { String actual = OpenLdapSchemaFileExporter.toSourceCode( attributeTypeSimple ); String expected = "attributetype ( 1.2.3.4 NAME 'name0'\n\tEQUALITY matchingRule0\n\tSYNTAX 2.3.4.5{512}\n\tCOLLECTIVE\n\tUSAGE userApplications )"; assertEquals( expected, actual ); } @Test public void testOpenLdapSchemaRendererAttributeTypeComplex() { String actual = OpenLdapSchemaFileExporter.toSourceCode( attributeTypeComplex ); String expected = "attributetype ( 1.2.3.4 NAME ( 'name1' 'name2' )\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tSUP superAttr\n\tEQUALITY matchingRule1\n\tORDERING matchingRule2\n\tSUBSTR matchingRule3\n\tSINGLE-VALUE\n\tNO-USER-MODIFICATION\n\tUSAGE directoryOperation )"; assertEquals( expected, actual ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.util.FileUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.schemaeditor.controller.ProjectsHandler; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.io.ProjectsExporter; import org.apache.directory.studio.schemaeditor.model.io.ProjectsImportException; import org.apache.directory.studio.schemaeditor.model.io.ProjectsImporter; import org.apache.directory.studio.schemaeditor.model.io.SchemaConnector; import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImportException; import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImporter; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; /** * This class contains helper methods. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PluginUtils { /** * Verifies that the given name is syntaxely correct according to the RFC 2252 * (Lightweight Directory Access Protocol (v3): Attribute Syntax Definitions). * * @param name * the name to test * @return * true if the name is correct, false if the name is not correct. */ public static boolean verifyName( String name ) { return name.matches( "[a-zA-Z]+[a-zA-Z0-9;-]*" ); //$NON-NLS-1$ } /** * Returns a clone of the given attribute type. * * @param at * the attribute type to clone * @return * a clone of the given attribute type */ public static AttributeType getClone( AttributeType at ) { AttributeType clone = new AttributeType( at.getOid() ); clone.setNames( at.getNames() ); clone.setSchemaName( at.getSchemaName() ); clone.setDescription( at.getDescription() ); clone.setSuperiorOid( at.getSuperiorOid() ); clone.setUsage( at.getUsage() ); clone.setSyntaxOid( at.getSyntaxOid() ); clone.setSyntaxLength( at.getSyntaxLength() ); clone.setObsolete( at.isObsolete() ); clone.setSingleValued( at.isSingleValued() ); clone.setCollective( at.isCollective() ); clone.setUserModifiable( at.isUserModifiable() ); clone.setEqualityOid( at.getEqualityOid() ); clone.setOrderingOid( at.getOrderingOid() ); clone.setSubstringOid( at.getSubstringOid() ); return clone; } /** * Returns a clone of the given object class. * * @param oc * the object class to clone * @return * a clone of the given object class */ public static ObjectClass getClone( ObjectClass oc ) { ObjectClass clone = new ObjectClass( oc.getOid() ); clone.setNames( oc.getNames() ); clone.setSchemaName( oc.getSchemaName() ); clone.setDescription( oc.getDescription() ); clone.setSuperiorOids( oc.getSuperiorOids() ); clone.setType( oc.getType() ); clone.setObsolete( oc.isObsolete() ); clone.setMustAttributeTypeOids( oc.getMustAttributeTypeOids() ); clone.setMayAttributeTypeOids( oc.getMayAttributeTypeOids() ); return clone; } /** * Gets the projects file (where is stored information about the loaded projects). * * @return * the projects File */ private static File getProjectsFile() { return Activator.getDefault().getStateLocation().append( "projects.xml" ).toFile(); //$NON-NLS-1$ } /** * Gets the temporary projects file. * * @return * the temporary projects file */ private static File getTempProjectsFile() { return Activator.getDefault().getStateLocation().append( "projects-temp.xml" ).toFile(); //$NON-NLS-1$ } /** * Loads the projects saved in the Projects File. */ public static void loadProjects() { ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler(); File projectsFile = getProjectsFile(); boolean loadFailed = false; Project[] projects = null; // We try to load the projects file if ( projectsFile.exists() ) { try { projects = ProjectsImporter.getProjects( new FileInputStream( projectsFile ), projectsFile .getAbsolutePath() ); } catch ( ProjectsImportException e ) { loadFailed = true; } catch ( FileNotFoundException e ) { loadFailed = true; } if ( !loadFailed ) { // If everything went fine, we add the projects for ( Project project : projects ) { projectsHandler.addProject( project ); } } else { // If something went wrong, we try to load the temp projects file File tempProjectsFile = getTempProjectsFile(); if ( tempProjectsFile.exists() ) { try { projects = ProjectsImporter.getProjects( new FileInputStream( tempProjectsFile ), projectsFile .getAbsolutePath() ); loadFailed = false; } catch ( ProjectsImportException e ) { reportError( Messages.getString( "PluginUtils.ErrorLoadingProject" ), e, Messages //$NON-NLS-1$ .getString( "PluginUtils.ProjectsLoadingError" ), Messages //$NON-NLS-1$ .getString( "PluginUtils.ErrorLoadingProject" ) ); //$NON-NLS-1$ return; } catch ( FileNotFoundException e ) { reportError( Messages.getString( "PluginUtils.ErrorLoadingProject" ), e, Messages //$NON-NLS-1$ .getString( "PluginUtils.ProjectsLoadingError" ), Messages //$NON-NLS-1$ .getString( "PluginUtils.ErrorLoadingProject" ) ); //$NON-NLS-1$ return; } // We add the projects for ( Project project : projects ) { projectsHandler.addProject( project ); } } else { reportError( Messages.getString( "PluginUtils.ErrorLoadingProject" ), null, Messages //$NON-NLS-1$ .getString( "PluginUtils.ProjectsLoadingError" ), Messages //$NON-NLS-1$ .getString( "PluginUtils.ErrorLoadingProject" ) ); //$NON-NLS-1$ } } } } /** * Saves the projects in the Projects File. */ public static void saveProjects() { try { // Saving the projects to the temp projects file OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$ XMLWriter writer = new XMLWriter( new FileOutputStream( getTempProjectsFile() ), outformat ); writer.write( ProjectsExporter.toDocument( Activator.getDefault().getProjectsHandler().getProjects() .toArray( new Project[0] ) ) ); writer.flush(); // Copying the temp projects file to the final location String content = FileUtils.readFileToString( getTempProjectsFile(), "UTF-8" ); //$NON-NLS-1$ FileUtils.writeStringToFile( getProjectsFile(), content, "UTF-8" ); //$NON-NLS-1$ } catch ( IOException e ) { // If an error occurs when saving to the temp projects file or // when copying the temp projects file to the final location, // we try to save the projects directly to the final location. try { OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$ XMLWriter writer = new XMLWriter( new FileOutputStream( getProjectsFile() ), outformat ); writer.write( ProjectsExporter.toDocument( Activator.getDefault().getProjectsHandler().getProjects() .toArray( new Project[0] ) ) ); writer.flush(); } catch ( IOException e2 ) { // If another error occur, we display an error reportError( Messages.getString( "PluginUtils.ErrorSavingProject" ), e2, Messages //$NON-NLS-1$ .getString( "PluginUtils.ProjectsSavingError" ), Messages //$NON-NLS-1$ .getString( "PluginUtils.ErrorSavingProject" ) ); //$NON-NLS-1$ } } } /** * Logs the given message and exception with the ERROR status level. * * @param message * the message * @param exception * the exception */ public static void logError( String message, Throwable exception ) { Activator.getDefault().getLog().log( new Status( Status.ERROR, Activator.getDefault().getBundle().getSymbolicName(), Status.OK, message, exception ) ); } /** * Logs the given message and exception with the INFO status level. * * @param message * the message * @param exception * the exception */ public static void logInfo( Throwable exception, String message, Object... args ) { String msg = MessageFormat.format( message, args ); Activator.getDefault().getLog().log( new Status( Status.INFO, Activator.getDefault().getBundle().getSymbolicName(), Status.OK, msg, exception ) ); } /** * Logs the given message and exception with the WARNING status level. * * @param message * the message * @param exception * the exception */ public static void logWarning( String message, Throwable exception ) { Activator.getDefault().getLog().log( new Status( Status.WARNING, Activator.getDefault().getBundle().getSymbolicName(), Status.OK, message, exception ) ); } /** * Loads the 'core' corresponding to the given name. * * @param schemaName * the name of the 'core' schema * @return * the corresponding schema, or null if no schema has been found */ public static Schema loadCoreSchema( ServerTypeEnum serverType, String schemaName ) { Schema schema = null; try { URL url = Activator.getDefault().getBundle().getResource( "resources/schemas/" + getFolderName( serverType ) + "/" + schemaName + ".xml" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if ( url == null ) { reportError( Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + ".", null, //$NON-NLS-1$//$NON-NLS-2$ Messages.getString( "PluginUtils.ProjectsLoadingError" ), Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + "." ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ } else { schema = XMLSchemaFileImporter.getSchema( url.openStream(), url.toString() ); } } catch ( XMLSchemaFileImportException e ) { reportError( Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + ".", e, Messages.getString( "PluginUtils.ProjectsLoadingError" ), //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + "." ); //$NON-NLS-1$//$NON-NLS-2$ } catch ( FileNotFoundException e ) { reportError( Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + ".", e, Messages.getString( "PluginUtils.ProjectsLoadingError" ), //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + "." ); //$NON-NLS-1$//$NON-NLS-2$ } catch ( IOException e ) { reportError( Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + ".", e, Messages.getString( "PluginUtils.ProjectsLoadingError" ), //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Messages.getString( "PluginUtils.SchemaLoadingError" ) + schemaName + "." ); //$NON-NLS-1$//$NON-NLS-2$ } return schema; } /** * Reports an error. * <p> * Logs a message and an exception, and displays a Error Dialog with title and message. * * @param loggerMessage * the message for the logger * @param e * the exception to log * @param dialogTitle * the title of the Error Dialog (empty string used if <code>null</code>) * @param dialogMessage * the message to display in the Error Dialog */ private static void reportError( String loggerMessage, Exception e, String dialogTitle, String dialogMessage ) { if ( ( loggerMessage != null ) || ( e != null ) ) { PluginUtils.logError( loggerMessage, e ); } if ( dialogMessage != null ) { ViewUtils.displayErrorMessageDialog( ( ( dialogTitle == null ) ? "" : dialogTitle ), dialogMessage ); //$NON-NLS-1$ } } /** * The name of the folder for the given Server Type. * * @param serverType * the Server Type * @return * the name of the folder for the given Server Type */ private static String getFolderName( ServerTypeEnum serverType ) { if ( ServerTypeEnum.APACHE_DS.equals( serverType ) ) { return "apacheds"; //$NON-NLS-1$ } else if ( ServerTypeEnum.OPENLDAP.equals( serverType ) ) { return "openldap"; //$NON-NLS-1$ } // Default return null; } /** * Gets a Connection from the given id. * * @param id * the id of the Connection * @return * the corresponding Connection, or null if no connection was found. */ public static Connection getConnection( String id ) { Connection[] connectionsArray = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections(); HashMap<String, Connection> connections = new HashMap<String, Connection>(); for ( Connection connection : connectionsArray ) { connections.put( connection.getId(), connection ); } return connections.get( id ); } /** * Gets the List of SchemaConnectors defined using the ExtensionPoint. * * @return * the List of SchemaConnectors defined using the ExtensionPoint */ public static List<SchemaConnector> getSchemaConnectors() { List<SchemaConnector> schemaConnectors = new ArrayList<SchemaConnector>(); IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint( "org.apache.directory.studio.schemaeditor.schemaConnectors" ); //$NON-NLS-1$ IConfigurationElement[] members = extensionPoint.getConfigurationElements(); if ( members != null ) { // Creating each SchemaConnector for ( IConfigurationElement member : members ) { try { SchemaConnector schemaConnector = ( SchemaConnector ) member.createExecutableExtension( "class" ); //$NON-NLS-1$ schemaConnector.setName( member.getAttribute( "name" ) ); //$NON-NLS-1$ schemaConnector.setId( member.getAttribute( "id" ) ); //$NON-NLS-1$ schemaConnector.setDescription( member.getAttribute( "description" ) ); //$NON-NLS-1$ schemaConnectors.add( schemaConnector ); } catch ( CoreException e ) { PluginUtils.logError( Messages.getString( "PluginUtils.ConnectorsLoadingError" ), e ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "PluginUtils.Error" ), Messages //$NON-NLS-1$ .getString( "PluginUtils.ConnectorsLoadingError" ) ); //$NON-NLS-1$ } } } return schemaConnectors; } /** * Saves the the given value under the given key in the dialog settings. * * @param key * the key * @param value * the value */ public static void saveDialogSettingsHistory( String key, String value ) { // get current history String[] history = loadDialogSettingsHistory( key ); List<String> list = new ArrayList<String>( Arrays.asList( history ) ); // add new value or move to first position if ( list.contains( value ) ) { list.remove( value ); } list.add( 0, value ); // check history size while ( list.size() > 20 ) { list.remove( list.size() - 1 ); } // save history = list.toArray( new String[list.size()] ); Activator.getDefault().getDialogSettings().put( key, history ); } /** * Loads the value of the given key from the dialog settings. * * @param key the key * @return the value */ public static String[] loadDialogSettingsHistory( String key ) { String[] history = Activator.getDefault().getDialogSettings().getArray( key ); if ( history == null ) { history = new String[0]; } return history; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginConstants.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginConstants.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor; import org.apache.directory.studio.schemaeditor.view.preferences.HierarchyViewPreferencePage; import org.apache.directory.studio.schemaeditor.view.preferences.SchemaViewPreferencePage; import org.apache.directory.studio.schemaeditor.view.preferences.SearchViewPreferencePage; /** * This class contains all the Constants used in the Plugin. * Final reference -> class shouldn't be extended * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class PluginConstants { /** * Ensures no construction of this class, also ensures there is no need for final keyword above * (Implicit super constructor is not visible for default constructor), * but is still self documenting. */ private PluginConstants() { } /** The plug-in ID */ public static final String PLUGIN_ID = PluginConstants.class.getPackage().getName(); /** The Schema Editor perspective ID */ public static final String PERSPECTIVE_SCHEMA_EDITOR_ID = Activator.getDefault().getPluginProperties() .getString( "Perspective_SchemaEditor_id" ); //$NON-NLS-1$ /** The LDAP Browser perspective ID */ public static final String PERSPECTIVE_LDAP_BROWSER_ID = "org.apache.directory.studio.ldapbrowser.ui.perspective.BrowserPerspective"; //$NON-NLS-1$ /** The top left folder ID */ public static final String PERSPECTIVE_TOP_LEFT_FOLDER_ID = "org.apache.directory.studio.schemaeditor.topleftfolder"; //$NON-NLS-1$ /** The bottom folder ID */ public static final String PERSPECTIVE_BOTTOM_FOLDER_ID = "org.apache.directory.studio.schemaeditor.bottomfolder"; //$NON-NLS-1$ /** The Attribute Type Editor ID */ public static final String EDITOR_ATTRIBUTE_TYPE_ID = Activator.getDefault().getPluginProperties() .getString( "Editor_AttributeTypeEditor_id" ); //$NON-NLS-1$ /** The Object Class Editor ID */ public static final String EDITOR_OBJECT_CLASS_ID = Activator.getDefault().getPluginProperties() .getString( "Editor_ObjectClassEditor_id" ); //$NON-NLS-1$ /** The Schema Editor ID */ public static final String EDITOR_SCHEMA_ID = Activator.getDefault().getPluginProperties() .getString( "Editor_SchemaEditor_id" ); //$NON-NLS-1$ /** The Hierarchy View Preference Page ID */ public static final String PREF_PAGE_HIERARCHY_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "PrefPage_HierarchyView_id" ); //$NON-NLS-1$ /** The Schema View Preference Page ID */ public static final String PREF_PAGE_SCHEMA_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "PrefPage_SchemaView_id" ); //$NON-NLS-1$ /** The Search View Preference Page ID */ public static final String PREF_PAGE_SEARCH_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "PrefPage_SearchView_id" ); //$NON-NLS-1$ /** The Hierarchy View ID */ public static final String VIEW_HIERARCHY_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "View_HierarchyView_id" ); //$NON-NLS-1$ /** The Problems View ID */ public static final String VIEW_PROBLEMS_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "View_ProblemsView_id" ); //$NON-NLS-1$ /** The Projects View ID */ public static final String VIEW_PROJECTS_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "View_ProjectsView_id" ); //$NON-NLS-1$ /** The Schema View ID */ public static final String VIEW_SCHEMA_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "View_SchemaView_id" ); //$NON-NLS-1$ /** The Search View ID */ public static final String VIEW_SEARCH_VIEW_ID = Activator.getDefault().getPluginProperties() .getString( "View_SearchView_id" ); //$NON-NLS-1$ /** The New Attribute Type Wizard ID */ public static final String NEW_WIZARD_NEW_ATTRIBUTE_TYPE_WIZARD = Activator.getDefault().getPluginProperties() .getString( "NewWizard_NewAttributeTypeWizard_id" ); //$NON-NLS-1$ /** The New Object Class Wizard ID */ public static final String NEW_WIZARD_NEW_OBJECT_CLASS_WIZARD = Activator.getDefault().getPluginProperties() .getString( "NewWizard_NewObjectClassWizard_id" ); //$NON-NLS-1$ /** The New Project Wizard ID */ public static final String NEW_WIZARD_NEW_PROJECT_WIZARD = Activator.getDefault().getPluginProperties() .getString( "NewWizard_NewProjectWizard_id" ); //$NON-NLS-1$ /** The New Schema Wizard ID */ public static final String NEW_WIZARD_NEW_SCHEMA_WIZARD = Activator.getDefault().getPluginProperties() .getString( "NewWizard_NewSchemaWizard_id" ); //$NON-NLS-1$ // Images public static final String IMG_ATTRIBUTE_TYPE = "resources/icons/attribute_type.gif"; //$NON-NLS-1$ public static final String IMG_ATTRIBUTE_TYPE_HIERARCHY_SELECTED = "resources/icons/attribute_type_hierarchy_selected.gif"; //$NON-NLS-1$ public static final String IMG_ATTRIBUTE_TYPE_NEW = "resources/icons/attribute_type_new.gif"; //$NON-NLS-1$ public static final String IMG_ATTRIBUTE_TYPE_NEW_WIZARD = "resources/icons/attribute_type_new_wizard.png"; //$NON-NLS-1$ public static final String IMG_ATTRIBUTE_TYPE_OVERLAY_OPERATION = "resources/icons/attribute_type_overlay_operation.gif"; //$NON-NLS-1$ public static final String IMG_ATTRIBUTE_TYPE_OVERLAY_USER_APPLICATION = "resources/icons/attribute_type_overlay_userApplication.gif"; //$NON-NLS-1$ public static final String IMG_CONNECT = "resources/icons/connect.gif"; //$NON-NLS-1$ public static final String IMG_COMMIT_CHANGES = "resources/icons/commit_changes.gif"; //$NON-NLS-1$ public static final String IMG_COMMIT_CHANGES_WIZARD = "resources/icons/commit_changes_wizard.png"; //$NON-NLS-1$ public static final String IMG_COLLAPSE_ALL = "resources/icons/collapse_all.gif"; //$NON-NLS-1$ public static final String IMG_DELETE = "resources/icons/delete.gif"; //$NON-NLS-1$ public static final String IMG_DISCONNECT = "resources/icons/disconnect.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_ATTRIBUTE_TYPE_ADD = "resources/icons/difference_attribute_type_add.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_ATTRIBUTE_TYPE_MODIFY = "resources/icons/difference_attribute_type_modify.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_ATTRIBUTE_TYPE_REMOVE = "resources/icons/difference_attribute_type_remove.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_OBJECT_CLASS_ADD = "resources/icons/difference_object_class_add.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_OBJECT_CLASS_MODIFY = "resources/icons/difference_object_class_modify.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_OBJECT_CLASS_REMOVE = "resources/icons/difference_object_class_remove.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_PROPERTY_ADD = "resources/icons/difference_property_add.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_PROPERTY_MODIFY = "resources/icons/difference_property_modify.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_PROPERTY_REMOVE = "resources/icons/difference_property_remove.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_SCHEMA_ADD = "resources/icons/difference_schema_add.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_SCHEMA_MODIFY = "resources/icons/difference_schema_modify.gif"; //$NON-NLS-1$ public static final String IMG_DIFFERENCE_SCHEMA_REMOVE = "resources/icons/difference_schema_remove.gif"; //$NON-NLS-1$ public static final String IMG_FOLDER = "resources/icons/folder.gif"; //$NON-NLS-1$ public static final String IMG_FOLDER_AT = "resources/icons/folder_at.gif"; //$NON-NLS-1$ public static final String IMG_FOLDER_OC = "resources/icons/folder_oc.gif"; //$NON-NLS-1$ public static final String IMG_LINK_WITH_EDITOR = "resources/icons/link_with_editor.gif"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS = "resources/icons/object_class.gif"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS_HIERARCHY_SELECTED = "resources/icons/object_class_hierarchy_selected.gif"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS_NEW = "resources/icons/object_class_new.gif"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS_NEW_WIZARD = "resources/icons/object_class_new_wizard.png"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS_OVERLAY_ABSTRACT = "resources/icons/object_class_overlay_abstract.gif"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS_OVERLAY_AUXILIARY = "resources/icons/object_class_overlay_auxiliary.gif"; //$NON-NLS-1$ public static final String IMG_OBJECT_CLASS_OVERLAY_STRUCTURAL = "resources/icons/object_class_overlay_structural.gif"; //$NON-NLS-1$ public static final String IMG_OVERLAY_ERROR = "resources/icons/overlay_error.gif"; //$NON-NLS-1$ public static final String IMG_OVERLAY_WARNING = "resources/icons/overlay_warning.gif"; //$NON-NLS-1$ public static final String IMG_PROBLEMS_ERROR = "resources/icons/problems_error.gif"; //$NON-NLS-1$ public static final String IMG_PROBLEMS_GROUP = "resources/icons/problems_group.gif"; //$NON-NLS-1$ public static final String IMG_PROBLEMS_WARNING = "resources/icons/problems_warning.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_EXPORT = "resources/icons/project_export.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_EXPORT_WIZARD = "resources/icons/project_export_wizard.png"; //$NON-NLS-1$ public static final String IMG_PROJECT_FILE = "resources/icons/project_file.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_IMPORT = "resources/icons/project_import.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_IMPORT_WIZARD = "resources/icons/project_import_wizard.png"; //$NON-NLS-1$ public static final String IMG_PROJECT_NEW = "resources/icons/project_new.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_NEW_WIZARD = "resources/icons/project_new_wizard.png"; //$NON-NLS-1$ public static final String IMG_PROJECT_OFFLINE = "resources/icons/project_offline.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_OFFLINE_CLOSED = "resources/icons/project_offline_closed.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_ONLINE = "resources/icons/project_online.gif"; //$NON-NLS-1$ public static final String IMG_PROJECT_ONLINE_CLOSED = "resources/icons/project_online_closed.gif"; //$NON-NLS-1$ public static final String IMG_RENAME = "resources/icons/rename.gif"; //$NON-NLS-1$ public static final String IMG_RUN_CURRENT_SEARCH_AGAIN = "resources/icons/run_current_search_again.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMA = "resources/icons/schema.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMA_CONNECTOR = "resources/icons/schema_connector.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMA_NEW = "resources/icons/schema_new.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMA_NEW_WIZARD = "resources/icons/schema_new_wizard.png"; //$NON-NLS-1$ public static final String IMG_SCHEMAS_EXPORT = "resources/icons/schemas_export.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMAS_EXPORT_FOR_ADS = "resources/icons/schemas_export_for_ads.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMAS_EXPORT_FOR_ADS_WIZARD = "resources/icons/schemas_export_for_ads_wizard.png"; //$NON-NLS-1$ public static final String IMG_SCHEMAS_EXPORT_WIZARD = "resources/icons/schemas_export_wizard.png"; //$NON-NLS-1$ public static final String IMG_SCHEMAS_IMPORT = "resources/icons/schemas_import.gif"; //$NON-NLS-1$ public static final String IMG_SCHEMAS_IMPORT_WIZARD = "resources/icons/schemas_import_wizard.png"; //$NON-NLS-1$ public static final String IMG_SEARCH = "resources/icons/search.gif"; //$NON-NLS-1$ public static final String IMG_SEARCH_HISTORY_ITEM = "resources/icons/search_history_item.gif"; //$NON-NLS-1$ public static final String IMG_SHOW_SEARCH_FIELD = "resources/icons/show_search_field.gif"; //$NON-NLS-1$ public static final String IMG_SHOW_SEARCH_HISTORY = "resources/icons/show_search_history.gif"; //$NON-NLS-1$ public static final String IMG_SHOW_SUBTYPE_HIERARCHY = "resources/icons/hierarchy_subtype.gif"; //$NON-NLS-1$ public static final String IMG_SHOW_SUPERTYPE_HIERARCHY = "resources/icons/hierarchy_supertype.gif"; //$NON-NLS-1$ public static final String IMG_SHOW_TYPE_HIERARCHY = "resources/icons/hierarchy_type.gif"; //$NON-NLS-1$ public static final String IMG_SORTING = "resources/icons/sorting.gif"; //$NON-NLS-1$ public static final String IMG_TOOLBAR_MENU = "resources/icons/toolbar_menu.gif"; //$NON-NLS-1$ public static final String IMG_TRANSPARENT_16X16 = "resources/icons/transparent_16x16.gif"; //$NON-NLS-1$ public static final String IMG_WARNING_32X32 = "resources/icons/warning_32x32.png"; //$NON-NLS-1$ // Commands public static final String CMD_DELETE_PROJECT = Activator.getDefault().getPluginProperties() .getString( "Cmd_DeleteProject_id" ); //$NON-NLS-1$ public static final String CMD_DELETE_SCHEMA_ELEMENT = Activator.getDefault().getPluginProperties() .getString( "Cmd_DeleteSchemaElement_id" ); //$NON-NLS-1$ public static final String CMD_OPEN_ELEMENT = Activator.getDefault().getPluginProperties() .getString( "Cmd_OpenElement_id" ); //$NON-NLS-1$ public static final String CMD_OPEN_TYPE_HIERARCHY = Activator.getDefault().getPluginProperties() .getString( "Cmd_OpenTypeHierarchy_id" ); //$NON-NLS-1$ public static final String CMD_NEW_ATTRIBUTE_TYPE = Activator.getDefault().getPluginProperties() .getString( "Cmd_NewAttributeType_id" ); //$NON-NLS-1$ public static final String CMD_NEW_OBJECT_CLASS = Activator.getDefault().getPluginProperties() .getString( "Cmd_NewObjectClass_id" ); //$NON-NLS-1$ public static final String CMD_NEW_PROJECT = Activator.getDefault().getPluginProperties() .getString( "Cmd_NewProject_id" ); //$NON-NLS-1$ public static final String CMD_NEW_SCHEMA = Activator.getDefault().getPluginProperties() .getString( "Cmd_NewSchema_id" ); //$NON-NLS-1$ public static final String CMD_RENAME_PROJECT = Activator.getDefault().getPluginProperties() .getString( "Cmd_RenameProject_id" ); //$NON-NLS-1$ public static final String CMD_RENAME_SCHEMA_ELEMENT = Activator.getDefault().getPluginProperties() .getString( "Cmd_RenameSchemaElement_id" ); //$NON-NLS-1$ // Preferences - DifferencesWidget /** The preferences ID for DifferencesWidget Grouping */ public static final String PREFS_DIFFERENCES_WIDGET_GROUPING = PluginConstants.PLUGIN_ID + ".prefs.DifferencesWidget.grouping"; //$NON-NLS-1$ /** The preference value for DifferencesWidget Grouping 'Property' */ public static final int PREFS_DIFFERENCES_WIDGET_GROUPING_PROPERTY = 0; /** The preference value for DifferencesWidget Grouping 'Property' */ public static final int PREFS_DIFFERENCES_WIDGET_GROUPING_TYPE = 1; // Preferences - SchemaView /** The preference ID for Schema View Schema Presentation */ public static final String PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION = SchemaViewPreferencePage.ID + ".schemaPresentation"; //$NON-NLS-1$ /** The preference value for Schema View Schema Presentation 'Flat' */ public static final int PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT = 0; /** The preference value for Schema View Schema Presentation 'Hierarchical' */ public static final int PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL = 1; /** The preference ID for Schema View Label */ public static final String PREFS_SCHEMA_VIEW_LABEL = SchemaViewPreferencePage.ID + ".label.labelValue"; //$NON-NLS-1$ /** The preference value for Schema View First Name label */ public static final int PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME = 0; /** The preference value for Schema View All Aliases label */ public static final int PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES = 1; /** The preference value for Schema View OID label */ public static final int PREFS_SCHEMA_VIEW_LABEL_OID = 2; /** The preference ID for Schema View Abbreviate */ public static final String PREFS_SCHEMA_VIEW_ABBREVIATE = SchemaViewPreferencePage.ID + ".label.abbreviate"; //$NON-NLS-1$ /** The preference ID for Schema View Abbreviate Max Length*/ public static final String PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH = SchemaViewPreferencePage.ID + ".label.abbreviate.maxLength"; //$NON-NLS-1$ /** The preference ID for Schema View Display Secondary Label */ public static final String PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY = SchemaViewPreferencePage.ID + ".secondaryLabel.display"; //$NON-NLS-1$ /** The preference ID for Schema View Secondary Label */ public static final String PREFS_SCHEMA_VIEW_SECONDARY_LABEL = SchemaViewPreferencePage.ID + ".secondaryLabel.labelValue"; //$NON-NLS-1$ /** The preference ID for Schema View Abbreviate Secondary Label */ public static final String PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE = SchemaViewPreferencePage.ID + ".secondaryLabel.abbreviate"; //$NON-NLS-1$ /** The preference ID for Schema View Abbreviate Secondary Label Max Length*/ public static final String PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH = SchemaViewPreferencePage.ID + ".secondaryLabel.abbreviate.maxLength"; //$NON-NLS-1$ public static final String PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY = SchemaViewPreferencePage.ID + ".schemaLabel.display"; //$NON-NLS-1$ /** The preference ID for Schema View Grouping */ public static final String PREFS_SCHEMA_VIEW_GROUPING = PluginConstants.PLUGIN_ID + ".preferences.SchemaView.grouping"; //$NON-NLS-1$ /** The preference value for Schema View Grouping 'group ATs and OCs in folders' */ public static final int PREFS_SCHEMA_VIEW_GROUPING_FOLDERS = 0; /** The preference value for Schema View Grouping 'mixed' */ public static final int PREFS_SCHEMA_VIEW_GROUPING_MIXED = 1; /** The preference ID for Schema View Sorting By */ public static final String PREFS_SCHEMA_VIEW_SORTING_BY = PluginConstants.PLUGIN_ID + ".preferences.SchemaView.sortingBy"; //$NON-NLS-1$ /** The preference value for Schema View Sorting 'First Name' */ public static final int PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME = 0; /** The preference value for Schema View Sorting 'OID' */ public static final int PREFS_SCHEMA_VIEW_SORTING_BY_OID = 1; /** The preference ID for Sorting Order */ public static final String PREFS_SCHEMA_VIEW_SORTING_ORDER = PluginConstants.PLUGIN_ID + ".preferences.SchemaView.sortingOrder"; //$NON-NLS-1$ /** The preference value for Schema View Sorting 'ascending' */ public static final int PREFS_SCHEMA_VIEW_SORTING_ORDER_ASCENDING = 0; /** The preference value for Schema View Sorting 'descending' */ public static final int PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING = 1; // Preferences - Hierarchy View /** The preference ID for Mode of the Hierarchy View */ public static final String PREFS_HIERARCHY_VIEW_MODE = PluginConstants.PLUGIN_ID + ".preferences.HierarchyView.mode"; //$NON-NLS-1$ /** The preference value for Hierarchy View Mode 'Supertype' */ public static final int PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE = 0; /** The preference value for Hierarchy View Mode 'Subtype' */ public static final int PREFS_HIERARCHY_VIEW_MODE_SUBTYPE = 1; /** The preference value for Hierarchy View Mode 'Type' */ public static final int PREFS_HIERARCHY_VIEW_MODE_TYPE = 2; /** The preference ID for Hierarchy View Label */ public static final String PREFS_HIERARCHY_VIEW_LABEL = HierarchyViewPreferencePage.ID + ".label.labelValue"; //$NON-NLS-1$ /** The preference value for Hierarchy View First Name label */ public static final int PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME = 0; /** The preference value for Hierarchy View All Aliases label */ public static final int PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES = 1; /** The preference value for Hierarchy View OID label */ public static final int PREFS_HIERARCHY_VIEW_LABEL_OID = 2; /** The preference ID for Hierarchy View Abbreviate */ public static final String PREFS_HIERARCHY_VIEW_ABBREVIATE = HierarchyViewPreferencePage.ID + ".label.abbreviate"; //$NON-NLS-1$ /** The preference ID for Hierarchy View Abbreviate Max Length*/ public static final String PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH = HierarchyViewPreferencePage.ID + ".label.abbreviate.maxLength"; //$NON-NLS-1$ /** The preference ID for Hierarchy View Display Secondary Label */ public static final String PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY = HierarchyViewPreferencePage.ID + ".secondaryLabel.display"; //$NON-NLS-1$ /** The preference ID for Hierarchy View Secondary Label */ public static final String PREFS_HIERARCHY_VIEW_SECONDARY_LABEL = HierarchyViewPreferencePage.ID + ".secondaryLabel.labelValue"; //$NON-NLS-1$ /** The preference ID for Hierarchy View Abbreviate Secondary Label */ public static final String PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE = HierarchyViewPreferencePage.ID + ".secondaryLabel.abbreviate"; //$NON-NLS-1$ /** The preference ID for Hierarchy View Abbreviate Secondary Label Max Length*/ public static final String PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH = HierarchyViewPreferencePage.ID + ".secondaryLabel.abbreviate.maxLength"; //$NON-NLS-1$ // Search - SearchPage /** The preference ID for Search History of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_HISTORY = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.searchHistory"; //$NON-NLS-1$ /** The preference ID for Search In 'Aliases' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeAliases"; //$NON-NLS-1$ /** The preference ID for Search In 'OID' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_OID = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeOid"; //$NON-NLS-1$ /** The preference ID for Search In 'Description' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeDescription"; //$NON-NLS-1$ /** The preference ID for Search In 'Superior' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeSuperior"; //$NON-NLS-1$ /** The preference ID for Search In 'Syntax' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeSyntax"; //$NON-NLS-1$ /** The preference ID for Search In 'Matching Rules' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeMatchingRules"; //$NON-NLS-1$ /** The preference ID for Search In 'Superiors' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeSuperiors"; //$NON-NLS-1$ /** The preference ID for Search In 'Mandatory Attributes' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeMandatoryAttributes"; //$NON-NLS-1$ /** The preference ID for Search In 'Optional Attributes' of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scopeOptionalAttributes"; //$NON-NLS-1$ /** The preference ID for Scope of the SearchPage */ public static final String PREFS_SEARCH_PAGE_SCOPE = PluginConstants.PLUGIN_ID + ".preferences.SearchPage.scope"; //$NON-NLS-1$ /** The preference value for Scope Attribute Types And Object Classes of the SearchPage */ public static final int PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC = 0; /** The preference value for Scope Attribute Types only of the SearchPage */ public static final int PREFS_SEARCH_PAGE_SCOPE_AT_ONLY = 1; /** The preference value for Scope Object Classes only of the SearchPage */ public static final int PREFS_SEARCH_PAGE_SCOPE_OC_ONLY = 2; // Preferences - SearchView /** The preference ID for Search View Label */ public static final String PREFS_SEARCH_VIEW_LABEL = SearchViewPreferencePage.ID + ".label.labelValue"; //$NON-NLS-1$ /** The preference value for Search View First Name label */ public static final int PREFS_SEARCH_VIEW_LABEL_FIRST_NAME = 0; /** The preference value for Search View All Aliases label */ public static final int PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES = 1; /** The preference value for Search View OID label */ public static final int PREFS_SEARCH_VIEW_LABEL_OID = 2; /** The preference ID for Search View Abbreviate */ public static final String PREFS_SEARCH_VIEW_ABBREVIATE = SearchViewPreferencePage.ID + ".label.abbreviate"; //$NON-NLS-1$ /** The preference ID for Search View Abbreviate Max Length*/ public static final String PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH = SearchViewPreferencePage.ID + ".label.abbreviate.maxLength"; //$NON-NLS-1$ /** The preference ID for Search View Display Secondary Label */ public static final String PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY = SearchViewPreferencePage.ID + ".secondaryLabel.display"; //$NON-NLS-1$ /** The preference ID for Search View Secondary Label */ public static final String PREFS_SEARCH_VIEW_SECONDARY_LABEL = SearchViewPreferencePage.ID + ".secondaryLabel.labelValue"; //$NON-NLS-1$ /** The preference ID for Search View Abbreviate Secondary Label */ public static final String PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE = SearchViewPreferencePage.ID + ".secondaryLabel.abbreviate"; //$NON-NLS-1$ /** The preference ID for Search View Abbreviate Secondary Label Max Length*/ public static final String PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH = SearchViewPreferencePage.ID + ".secondaryLabel.abbreviate.maxLength"; //$NON-NLS-1$ /** The preference ID for Search View Grouping */ public static final String PREFS_SEARCH_VIEW_GROUPING = PluginConstants.PLUGIN_ID + ".preferences.SearchView.grouping"; //$NON-NLS-1$ /** The preference value for Search View Grouping 'Display ATs first' */ public static final int PREFS_SEARCH_VIEW_GROUPING_ATTRIBUTE_TYPES_FIRST = 0; /** The preference value for Search View Grouping 'Display OCs first' */ public static final int PREFS_SEARCH_VIEW_GROUPING_OBJECT_CLASSES_FIRST = 1; /** The preference value for Search View Grouping 'mixed' */ public static final int PREFS_SEARCH_VIEW_GROUPING_MIXED = 2; /** The preference ID for Search View Sorting By */ public static final String PREFS_SEARCH_VIEW_SORTING_BY = PluginConstants.PLUGIN_ID + ".preferences.SearchView.sortingBy"; //$NON-NLS-1$ /** The preference value for Search View Sorting 'First Name' */ public static final int PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME = 0; /** The preference value for Search View Sorting 'OID' */ public static final int PREFS_SEARCH_VIEW_SORTING_BY_OID = 1; /** The preference ID for Sorting Order */ public static final String PREFS_SEARCH_VIEW_SORTING_ORDER = PluginConstants.PLUGIN_ID + ".preferences.SchemaView.sortingOrder"; //$NON-NLS-1$ /** The preference value for Search View Sorting 'ascending' */ public static final int PREFS_SEARCH_VIEW_SORTING_ORDER_ASCENDING = 0; /** The preference value for Search View Sorting 'descending' */ public static final int PREFS_SEARCH_VIEW_SORTING_ORDER_DESCENDING = 1; /** The preference ID for Search View Display Secondary Label */ public static final String PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY = SearchViewPreferencePage.ID + ".schemaLabel.display"; //$NON-NLS-1$ // Contexts /** The Context for the SchemaView */ public static final String CONTEXT_SCHEMA_VIEW = PluginConstants.PLUGIN_ID + ".contexts.schemaView"; //$NON-NLS-1$ /** The Context for the SchemaView */ public static final String CONTEXT_PROJECTS_VIEW = PluginConstants.PLUGIN_ID + ".contexts.projectsView"; //$NON-NLS-1$ // File Dialogs /** The File Dialog path for 'Export Schema Projects' */ public static final String FILE_DIALOG_EXPORT_PROJECTS = PluginConstants.PLUGIN_ID + ".fileDialog.exportProjects"; //$NON-NLS-1$ /** The File Dialog path for 'Export Schemas to OpenLDAP files' */ public static final String FILE_DIALOG_EXPORT_SCHEMAS_OPENLDAP = PluginConstants.PLUGIN_ID + ".fileDialog.exportSchemasOpenLDAP"; //$NON-NLS-1$ /** The File Dialog path for 'Export Schemas to XML files' */ public static final String FILE_DIALOG_EXPORT_SCHEMAS_XML = PluginConstants.PLUGIN_ID + ".fileDialog.exportSchemasXML"; //$NON-NLS-1$ /** The File Dialog path for 'Export Schemas for ApacheDS' */ public static final String FILE_DIALOG_EXPORT_SCHEMAS_APACHE_DS = PluginConstants.PLUGIN_ID + ".fileDialog.exportSchemasApacheDS"; //$NON-NLS-1$ /** The File Dialog path for 'Import Schema Projects' */ public static final String FILE_DIALOG_IMPORT_PROJECTS = PluginConstants.PLUGIN_ID + ".fileDialog.importProjects"; //$NON-NLS-1$ /** The File Dialog path for 'Import Schemas from OpenLDAP files' */ public static final String FILE_DIALOG_IMPORT_SCHEMAS_OPENLDAP = PluginConstants.PLUGIN_ID + ".fileDialog.importSchemasOpenLDAP"; //$NON-NLS-1$ /** The File Dialog path for 'Import Schemas from XML files' */ public static final String FILE_DIALOG_IMPORT_SCHEMAS_XML = PluginConstants.PLUGIN_ID + ".fileDialog.importSchemasXML"; //$NON-NLS-1$ // Dialog Settings public static final String DIALOG_SETTINGS_OID_HISTORY = PluginConstants.PLUGIN_ID + ".dialogSettings.oidHistory"; //$NON-NLS-1$ }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PreferenceInitializer.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PreferenceInitializer.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; /** * This class initializes the preferences of the plug-in. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PreferenceInitializer extends AbstractPreferenceInitializer { /** * {@inheritDoc} */ public void initializeDefaultPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); // DifferencesWidget store.setDefault( PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING, PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_PROPERTY ); // SchemaView Preference Page store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION, PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE, true ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH, "50" ); //$NON-NLS-1$ store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY, true ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE, false ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, "50" ); //$NON-NLS-1$ store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY, false ); // SchemaView Sorting store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING, PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY, PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ); store.setDefault( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER, PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_ASCENDING ); // HierarchyView Preference Page store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ); store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE, true ); store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH, "50" ); //$NON-NLS-1$ store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY, true ); store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ); store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE, false ); store.setDefault( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, "50" ); //$NON-NLS-1$ // SearchView Preference Page store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE, true ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH, "50" ); //$NON-NLS-1$ store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY, true ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE, false ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, "50" ); //$NON-NLS-1$ store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY, true ); // SearchView Sorting store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_GROUPING, PluginConstants.PREFS_SEARCH_VIEW_GROUPING_MIXED ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY, PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME ); store.setDefault( PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER, PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_ASCENDING ); // File Dialogs store.setDefault( PluginConstants.FILE_DIALOG_EXPORT_PROJECTS, System.getProperty( "user.home" ) ); //$NON-NLS-1$ store.setDefault( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_OPENLDAP, System.getProperty( "user.home" ) ); //$NON-NLS-1$ store.setDefault( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_XML, System.getProperty( "user.home" ) ); //$NON-NLS-1$ store.setDefault( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_APACHE_DS, System.getProperty( "user.home" ) ); //$NON-NLS-1$ store.setDefault( PluginConstants.FILE_DIALOG_IMPORT_PROJECTS, System.getProperty( "user.home" ) ); //$NON-NLS-1$ store.setDefault( PluginConstants.FILE_DIALOG_IMPORT_SCHEMAS_OPENLDAP, System.getProperty( "user.home" ) ); //$NON-NLS-1$ store.setDefault( PluginConstants.FILE_DIALOG_IMPORT_SCHEMAS_XML, System.getProperty( "user.home" ) ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/Activator.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/Activator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.PropertyResourceBundle; import org.apache.directory.studio.schemaeditor.controller.ProjectsHandler; import org.apache.directory.studio.schemaeditor.controller.ProjectsHandlerListener; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.schema.SchemaEditor; import org.apache.directory.studio.schemaeditor.view.widget.SchemaCodeScanner; import org.apache.directory.studio.schemaeditor.view.widget.SchemaTextAttributeProvider; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.rules.ITokenScanner; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Activator extends AbstractUIPlugin { /** The shared instance */ private static Activator plugin; /** the Schema Code Scanner */ private ITokenScanner schemaCodeScanner; /** The Schema Text Attribute Provider */ private SchemaTextAttributeProvider schemaTextAttributeProvider; /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The SchemaCheker */ private SchemaChecker schemaChecker; /** The ProjectsHandler */ private ProjectsHandler projectsHandler; /** The plugin properties */ private PropertyResourceBundle properties; /** * Creates a new instance of Activator. */ public Activator() { plugin = this; projectsHandler = ProjectsHandler.getInstance(); schemaChecker = SchemaChecker.getInstance(); } /** * Closes the project editors. */ private void closeProjectEditors() { // Listing all the editors from the Schema Editor Plugin. List<IEditorReference> editors = new ArrayList<IEditorReference>(); for ( IEditorReference editorReference : getWorkbench().getActiveWorkbenchWindow().getActivePage() .getEditorReferences() ) { if ( ( editorReference.getId().equals( AttributeTypeEditor.ID ) ) || ( editorReference.getId().equals( ObjectClassEditor.ID ) ) || ( editorReference.getId().equals( SchemaEditor.ID ) ) ) { editors.add( editorReference ); } } // Closing the opened editors if ( !getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors( editors.toArray( new IEditorReference[0] ), true ) ) { // If all the editors have not been closed, we force them to be closed. getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors( editors.toArray( new IEditorReference[0] ), false ); } } /** * {@inheritDoc} */ public void start( BundleContext context ) throws Exception { super.start( context ); // Loading the projects PluginUtils.loadProjects(); projectsHandler.addListener( new ProjectsHandlerListener() { public void openProjectChanged( Project oldProject, Project newProject ) { closeProjectEditors(); if ( newProject == null ) { schemaHandler = null; } else { schemaHandler = newProject.getSchemaHandler(); } schemaChecker.reload(); PluginUtils.saveProjects(); } public void projectAdded( Project project ) { PluginUtils.saveProjects(); } public void projectRemoved( Project project ) { PluginUtils.saveProjects(); } } ); } /** * {@inheritDoc} */ public void stop( BundleContext context ) throws Exception { // Saving the projects PluginUtils.saveProjects(); super.stop( context ); plugin = null; } /** * Returns the shared instance. * * @return * the shared instance */ public static Activator getDefault() { return plugin; } /** * Gets the SchemaHandler * * @return * the SchemaHandler */ public SchemaHandler getSchemaHandler() { return schemaHandler; } /** * Gets the SchemaChecker * * @return * the SchemaChecker */ public SchemaChecker getSchemaChecker() { return schemaChecker; } /** * Gets the ProjectsHandler * * @return * the ProjectsHandler */ public ProjectsHandler getProjectsHandler() { return projectsHandler; } /** * Returns the Schema Code Scanner. * * @return * the Schema Code Scanner */ public ITokenScanner getSchemaCodeScanner() { if ( schemaCodeScanner == null ) { schemaCodeScanner = new SchemaCodeScanner( getSchemaTextAttributeProvider() ); } return schemaCodeScanner; } /** * Returns the Schema Text Attribute Provider. * * @return * the Schema Text Attribute Provider */ private SchemaTextAttributeProvider getSchemaTextAttributeProvider() { if ( schemaTextAttributeProvider == null ) { schemaTextAttributeProvider = new SchemaTextAttributeProvider(); } return schemaTextAttributeProvider; } /** * Use this method to get SWT images. Use the IMG_ constants from * PluginConstants for the key. * * @param key * The key (relative path to the image in filesystem) * @return The image descriptor or null */ public ImageDescriptor getImageDescriptor( String key ) { if ( key != null ) { URL url = FileLocator.find( getBundle(), new Path( key ), null ); if ( url != null ) return ImageDescriptor.createFromURL( url ); else return null; } else { return null; } } /** * Use this method to get SWT images. Use the IMG_ constants from * PluginConstants for the key. A ImageRegistry is used to manage the * the key->Image mapping. * <p> * Note: Don't dispose the returned SWT Image. It is disposed * automatically when the plugin is stopped. * * @param key * The key (relative path to the image in filesystem) * @return The SWT Image or null */ public Image getImage( String key ) { Image image = getImageRegistry().get( key ); if ( image == null ) { ImageDescriptor id = getImageDescriptor( key ); if ( id != null ) { image = id.createImage(); getImageRegistry().put( key, image ); } } return image; } /** * Gets the plugin properties. * * @return * the plugin properties */ public PropertyResourceBundle getPluginProperties() { if ( properties == null ) { try { properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path( "plugin.properties" ), false ) ); //$NON-NLS-1$ } catch ( IOException e ) { // We can't use the PLUGIN_ID constant since loading the plugin.properties file has failed, // So we're using a default plugin id. getLog().log( new Status( Status.ERROR, "org.apache.directory.studio.schemaeditor", Status.OK, //$NON-NLS-1$ Messages.getString( "Activator.UnablePluginProperties" ), e ) ); //$NON-NLS-1$ } } return properties; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandlerAdapter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandlerAdapter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.model.Schema; /** * This adapter class provides default implementations for the methods * described by the SchemaHandlerListener interface. * <p> * Classes that wish to deal with schema handling events can extend this class * and override only the methods which they are interested in. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class SchemaHandlerAdapter implements SchemaHandlerListener { /** * {@inheritDoc} */ public void attributeTypeAdded( AttributeType at ) { } /** * {@inheritDoc} */ public void attributeTypeModified( AttributeType at ) { } /** * {@inheritDoc} */ public void attributeTypeRemoved( AttributeType at ) { } /** * {@inheritDoc} */ public void matchingRuleAdded( MatchingRule mr ) { } /** * {@inheritDoc} */ public void matchingRuleModified( MatchingRule mr ) { } /** * {@inheritDoc} */ public void matchingRuleRemoved( MatchingRule mr ) { } /** * {@inheritDoc} */ public void objectClassAdded( ObjectClass oc ) { } /** * {@inheritDoc} */ public void objectClassModified( ObjectClass oc ) { } /** * {@inheritDoc} */ public void objectClassRemoved( ObjectClass oc ) { } /** * {@inheritDoc} */ public void schemaAdded( Schema schema ) { } /** * {@inheritDoc} */ public void schemaRemoved( Schema schema ) { } /** * {@inheritDoc} */ public void schemaRenamed( Schema schema ) { } /** * {@inheritDoc} */ public void syntaxAdded( LdapSyntax syntax ) { } /** * {@inheritDoc} */ public void syntaxModified( LdapSyntax syntax ) { } /** * {@inheritDoc} */ public void syntaxRemoved( LdapSyntax syntax ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandlerListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import org.apache.directory.studio.schemaeditor.model.Project; /** * Classes which implement this interface provide methods that deal with the * events that are generated when the ProjectsHandler is modified. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface ProjectsHandlerListener { /** * This method is called when a project is added. * * @param project * the added project */ void projectAdded( Project project ); /** * This method is called when a project is removed. * * @param project * the removed project */ void projectRemoved( Project project ); /** * This method is called when a project is opened. * * @param oldProject * the old opened project * @param newProject * the new opened project */ void openProjectChanged( Project oldProject, Project newProject ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/HierarchyViewController.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/HierarchyViewController.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.actions.LinkWithEditorHierarchyViewAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenHierarchyViewPreferencesAction; import org.apache.directory.studio.schemaeditor.controller.actions.ShowSubtypeHierarchyAction; import org.apache.directory.studio.schemaeditor.controller.actions.ShowSupertypeHierarchyAction; import org.apache.directory.studio.schemaeditor.controller.actions.ShowTypeHierarchyAction; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; import org.apache.directory.studio.schemaeditor.view.views.HierarchyView; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; /** * This class implements the Controller for the Hierarchy View * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class HierarchyViewController { /** The associated view */ private HierarchyView view; /** The authorized Preferences keys*/ List<String> authorizedPrefs; /** The ProjectsHandlerListener */ private ProjectsHandlerListener projectsHandlerListener = new ProjectsHandlerAdapter() { public void openProjectChanged( Project oldProject, Project newProject ) { // Since we're changing of project, let's set the input as null view.setInput( null ); if ( newProject != null ) { view.getViewer().getTree().setEnabled( true ); showTypeHierarchy.setEnabled( true ); showSupertypeHierarchy.setEnabled( true ); showSubtypeHierarchy.setEnabled( true ); linkWithEditor.setEnabled( true ); openPreferencePage.setEnabled( true ); } else { view.getViewer().getTree().setEnabled( false ); showTypeHierarchy.setEnabled( false ); showSupertypeHierarchy.setEnabled( false ); showSubtypeHierarchy.setEnabled( false ); linkWithEditor.setEnabled( false ); openPreferencePage.setEnabled( false ); } } }; /** The IDoubleClickListener */ private IDoubleClickListener doubleClickListener = new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { // What we get from the treeViewer is a StructuredSelection StructuredSelection selection = ( StructuredSelection ) event.getSelection(); // Here's the real object (an AttributeTypeWrapper, ObjectClassWrapper or IntermediateNode) Object objectSelection = selection.getFirstElement(); IEditorInput input = null; String editorId = null; // Selecting the right editor and input if ( objectSelection instanceof AttributeTypeWrapper ) { input = new AttributeTypeEditorInput( ( ( AttributeTypeWrapper ) objectSelection ).getAttributeType() ); editorId = AttributeTypeEditor.ID; } else if ( objectSelection instanceof ObjectClassWrapper ) { input = new ObjectClassEditorInput( ( ( ObjectClassWrapper ) objectSelection ).getObjectClass() ); editorId = ObjectClassEditor.ID; } // Let's open the editor if ( input != null ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor( input, editorId ); } catch ( PartInitException e ) { PluginUtils.logError( Messages.getString( "HierarchyViewController.ErrorOpeningEditor" ), e ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "HierarchyViewController.Error" ), Messages //$NON-NLS-1$ .getString( "HierarchyViewController.ErrorOpeningEditor" ) ); //$NON-NLS-1$ } } } }; /** The IPropertyChangeListener */ private IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange( PropertyChangeEvent event ) { if ( authorizedPrefs.contains( event.getProperty() ) ) { view.refresh(); } } }; // The Actions private Action showTypeHierarchy; private Action showSupertypeHierarchy; private Action showSubtypeHierarchy; private Action linkWithEditor; private Action openPreferencePage; /** * Creates a new instance of SchemasViewController. * * @param view * the associated view */ public HierarchyViewController( HierarchyView view ) { this.view = view; initAuthorizedPrefs(); initActions(); initToolbar(); initMenu(); initProjectsHandlerListener(); initDoubleClickListener(); initPreferencesListener(); initState(); } /** * Initializes the values for the authorized preferences. */ private void initAuthorizedPrefs() { authorizedPrefs = new ArrayList<String>(); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); } /** * Initializes the Actions. */ private void initActions() { // Setting up the default key value (if needed) if ( Activator.getDefault().getDialogSettings().get( PluginConstants.PREFS_HIERARCHY_VIEW_MODE ) == null ) { Activator.getDefault().getDialogSettings().put( PluginConstants.PREFS_HIERARCHY_VIEW_MODE, PluginConstants.PREFS_HIERARCHY_VIEW_MODE_TYPE ); } showTypeHierarchy = new ShowTypeHierarchyAction( view ); showSupertypeHierarchy = new ShowSupertypeHierarchyAction( view ); showSubtypeHierarchy = new ShowSubtypeHierarchyAction( view ); linkWithEditor = new LinkWithEditorHierarchyViewAction( view ); openPreferencePage = new OpenHierarchyViewPreferencesAction(); } /** * Initializes the Toolbar. */ private void initToolbar() { IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); toolbar.add( showTypeHierarchy ); toolbar.add( showSupertypeHierarchy ); toolbar.add( showSubtypeHierarchy ); toolbar.add( new Separator() ); toolbar.add( linkWithEditor ); } /** * Initializes the Menu. */ private void initMenu() { IMenuManager menu = view.getViewSite().getActionBars().getMenuManager(); menu.add( showTypeHierarchy ); menu.add( showSupertypeHierarchy ); menu.add( showSubtypeHierarchy ); menu.add( new Separator() ); menu.add( linkWithEditor ); menu.add( new Separator() ); menu.add( openPreferencePage ); } /** * Initializes the ProjectsHandlerListener. */ private void initProjectsHandlerListener() { Activator.getDefault().getProjectsHandler().addListener( projectsHandlerListener ); } /** * Initializes the DoubleClickListener. */ private void initDoubleClickListener() { view.getViewer().addDoubleClickListener( doubleClickListener ); } /** * Initializes the listener on the preferences store. */ private void initPreferencesListener() { Activator.getDefault().getPreferenceStore().addPropertyChangeListener( propertyChangeListener ); } /** * Initializes the state of the View. */ private void initState() { if ( Activator.getDefault().getProjectsHandler().getOpenProject() != null ) { view.getViewer().getTree().setEnabled( true ); showTypeHierarchy.setEnabled( true ); showSupertypeHierarchy.setEnabled( true ); showSubtypeHierarchy.setEnabled( true ); linkWithEditor.setEnabled( true ); openPreferencePage.setEnabled( true ); } else { view.getViewer().getTree().setEnabled( false ); showTypeHierarchy.setEnabled( false ); showSupertypeHierarchy.setEnabled( false ); showSubtypeHierarchy.setEnabled( false ); linkWithEditor.setEnabled( false ); openPreferencePage.setEnabled( false ); } } /** * This method is called when the view is disposed. */ public void dispose() { Activator.getDefault().getProjectsHandler().removeListener( projectsHandlerListener ); view.getViewer().removeDoubleClickListener( doubleClickListener ); Activator.getDefault().getPreferenceStore().removePropertyChangeListener( propertyChangeListener ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandlerListener.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandlerListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.model.Schema; /** * Classes which implement this interface provide methods that deal with the * events that are generated when an event occurs on a schema. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface SchemaHandlerListener { /** * Sent when the attribute type is added. * * @param at * the added attribute type */ void attributeTypeAdded( AttributeType at ); /** * Sent when the attribute type is modified. * * @param at * the modified attribute type */ void attributeTypeModified( AttributeType at ); /** * Sent when an attribute type is removed. * * @param at * the removed attribute type */ void attributeTypeRemoved( AttributeType at ); /** * Sent when a matching rule is added. * * @param mr * the added matching rule */ void matchingRuleAdded( MatchingRule mr ); /** * Sent when a matching rule is modified. * * @param mr * the modified matching rule */ void matchingRuleModified( MatchingRule mr ); /** * Sent when a matching rule is removed. * * @param mr * the removed matching rule */ void matchingRuleRemoved( MatchingRule mr ); /** * Sent when an object class is added. * * @param oc * the added object class */ void objectClassAdded( ObjectClass oc ); /** * Sent when an object class is modified. * * @param oc * the modified object class */ void objectClassModified( ObjectClass oc ); /** * Sent when an object class is removed. * * @param oc * the removed attribute type */ void objectClassRemoved( ObjectClass oc ); /** * Sent when a schema is added. * * @param schema * the added syntax */ void schemaAdded( Schema schema ); /** * Sent when a schema is removed. * * @param schema * the removed syntax */ void schemaRemoved( Schema schema ); /** * Sent when a schema is renamed. * * @param schema * the removed syntax */ void schemaRenamed( Schema schema ); /** * Sent when a syntax is added. * * @param syntax * the added syntax */ void syntaxAdded( LdapSyntax syntax ); /** * Sent when a syntax is modified. * * @param syntax * the modified syntax */ void syntaxModified( LdapSyntax syntax ); /** * Sent when a syntax is removed. * * @param syntax * the removed syntax */ void syntaxRemoved( LdapSyntax syntax ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsViewController.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.actions.CloseProjectAction; import org.apache.directory.studio.schemaeditor.controller.actions.DeleteProjectAction; import org.apache.directory.studio.schemaeditor.controller.actions.ExportProjectsAction; import org.apache.directory.studio.schemaeditor.controller.actions.ImportProjectsAction; import org.apache.directory.studio.schemaeditor.controller.actions.NewProjectAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenProjectAction; import org.apache.directory.studio.schemaeditor.controller.actions.RenameProjectAction; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Project.ProjectState; import org.apache.directory.studio.schemaeditor.view.views.ProjectsView; import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectsViewRoot; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.commands.ActionHandler; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextService; /** * This class implements the Controller for the SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsViewController { /** The associated view */ private ProjectsView view; /** The Context Menu */ private MenuManager contextMenu; /** The TableViewer */ private TableViewer viewer; /** The ProjectsHandler */ private ProjectsHandler projectsHandler; /** Token used to activate and deactivate shortcuts in the view */ private IContextActivation contextActivation; // The Actions private NewProjectAction newProject; private OpenProjectAction openProject; private CloseProjectAction closeProject; private RenameProjectAction renameProject; private DeleteProjectAction deleteProject; private ImportProjectsAction importProjects; private ExportProjectsAction exportProjects; /** * Creates a new instance of SchemasViewController. * * @param view * the associated view */ public ProjectsViewController( ProjectsView view ) { this.view = view; viewer = view.getViewer(); projectsHandler = Activator.getDefault().getProjectsHandler(); initActions(); initToolbar(); initContextMenu(); initViewer(); initDoubleClickListener(); initPartListener(); } /** * Initializes the Actions. */ private void initActions() { newProject = new NewProjectAction(); openProject = new OpenProjectAction( view.getViewer() ); closeProject = new CloseProjectAction( view.getViewer() ); renameProject = new RenameProjectAction( view.getViewer() ); deleteProject = new DeleteProjectAction( view.getViewer() ); importProjects = new ImportProjectsAction(); exportProjects = new ExportProjectsAction( view.getViewer() ); } /** * Initializes the Toolbar. */ private void initToolbar() { IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); toolbar.add( newProject ); } /** * Initializes the ContextMenu. */ private void initContextMenu() { contextMenu = new MenuManager( "" ); //$NON-NLS-1$ contextMenu.setRemoveAllWhenShown( true ); contextMenu.addMenuListener( new IMenuListener() { public void menuAboutToShow( IMenuManager manager ) { MenuManager importManager = new MenuManager( Messages.getString( "ProjectsViewController.ImportAction" ) ); //$NON-NLS-1$ MenuManager exportManager = new MenuManager( Messages.getString( "ProjectsViewController.ExportAction" ) ); //$NON-NLS-1$ manager.add( newProject ); manager.add( new Separator() ); manager.add( openProject ); manager.add( closeProject ); manager.add( new Separator() ); manager.add( renameProject ); manager.add( new Separator() ); manager.add( deleteProject ); manager.add( new Separator() ); manager.add( importManager ); importManager.add( importProjects ); manager.add( exportManager ); exportManager.add( exportProjects ); manager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); } } ); // set the context menu to the table viewer viewer.getControl().setMenu( contextMenu.createContextMenu( viewer.getControl() ) ); // register the context menu to enable extension actions view.getSite().registerContextMenu( contextMenu, viewer ); } /** * Initializes the Viewer. */ private void initViewer() { viewer.setInput( new ProjectsViewRoot( viewer ) ); viewer.getTable().addKeyListener( new KeyAdapter() { public void keyReleased( KeyEvent e ) { if ( ( e.keyCode == Action.findKeyCode( "BACKSPACE" ) ) //$NON-NLS-1$ || ( e.keyCode == Action.findKeyCode( "DELETE" ) ) ) //$NON-NLS-1$ { deleteProject.run(); } } } ); } /** * Initializes the DoubleClickListener. */ private void initDoubleClickListener() { viewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { StructuredSelection selection = ( StructuredSelection ) viewer.getSelection(); if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) ) { Project project = ( ( ProjectWrapper ) selection.getFirstElement() ).getProject(); if ( project.getState().equals( ProjectState.CLOSED ) ) { projectsHandler.openProject( project ); } } } } ); } /** * Initializes the PartListener. */ private void initPartListener() { view.getSite().getPage().addPartListener( new IPartListener2() { /** * This implementation deactivates the shortcuts when the part is deactivated. */ public void partDeactivated( IWorkbenchPartReference partRef ) { if ( partRef.getPart( false ) == view && contextActivation != null ) { ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { commandService.getCommand( newProject.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( renameProject.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( deleteProject.getActionDefinitionId() ).setHandler( null ); } IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextService.deactivateContext( contextActivation ); contextActivation = null; } } /** * This implementation activates the shortcuts when the part is activated. */ public void partActivated( IWorkbenchPartReference partRef ) { if ( partRef.getPart( false ) == view ) { IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextActivation = contextService.activateContext( PluginConstants.CONTEXT_PROJECTS_VIEW ); ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { commandService.getCommand( newProject.getActionDefinitionId() ).setHandler( new ActionHandler( newProject ) ); commandService.getCommand( renameProject.getActionDefinitionId() ).setHandler( new ActionHandler( renameProject ) ); commandService.getCommand( deleteProject.getActionDefinitionId() ).setHandler( new ActionHandler( deleteProject ) ); } } } public void partBroughtToTop( IWorkbenchPartReference partRef ) { } public void partClosed( IWorkbenchPartReference partRef ) { } public void partHidden( IWorkbenchPartReference partRef ) { } public void partInputChanged( IWorkbenchPartReference partRef ) { } public void partOpened( IWorkbenchPartReference partRef ) { } public void partVisible( IWorkbenchPartReference partRef ) { } } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; /** * Classes which implement this interface provide methods that deal with the * events that are generated when an event occurs on a project. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface ProjectListener { /** * This method is called when the project is renamed. */ public void projectRenamed(); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaViewController.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaViewController.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.actions.CollapseAllAction; import org.apache.directory.studio.schemaeditor.controller.actions.DeleteSchemaElementAction; import org.apache.directory.studio.schemaeditor.controller.actions.ExportSchemasAsOpenLdapAction; import org.apache.directory.studio.schemaeditor.controller.actions.ExportSchemasAsXmlAction; import org.apache.directory.studio.schemaeditor.controller.actions.ExportSchemasForADSAction; import org.apache.directory.studio.schemaeditor.controller.actions.ImportCoreSchemasAction; import org.apache.directory.studio.schemaeditor.controller.actions.ImportSchemasFromOpenLdapAction; import org.apache.directory.studio.schemaeditor.controller.actions.ImportSchemasFromXmlAction; import org.apache.directory.studio.schemaeditor.controller.actions.LinkWithEditorSchemaViewAction; import org.apache.directory.studio.schemaeditor.controller.actions.MergeSchemasAction; import org.apache.directory.studio.schemaeditor.controller.actions.NewAttributeTypeAction; import org.apache.directory.studio.schemaeditor.controller.actions.NewObjectClassAction; import org.apache.directory.studio.schemaeditor.controller.actions.NewSchemaAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenElementAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenSchemaViewPreferenceAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenSchemaViewSortingDialogAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenTypeHierarchyAction; import org.apache.directory.studio.schemaeditor.controller.actions.RenameSchemaElementAction; import org.apache.directory.studio.schemaeditor.controller.actions.SwitchSchemaPresentationToFlatAction; import org.apache.directory.studio.schemaeditor.controller.actions.SwitchSchemaPresentationToHierarchicalAction; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaCheckerListener; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; import org.apache.directory.studio.schemaeditor.view.views.SchemaView; import org.apache.directory.studio.schemaeditor.view.views.SchemaViewContentProvider; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.commands.ActionHandler; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextService; /** * This class implements the Controller for the SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaViewController { /** The associated view */ private SchemaView view; /** The TreeViewer */ private TreeViewer viewer; /** The authorized Preferences keys*/ private List<String> authorizedPrefs; /** The Context Menu */ private MenuManager contextMenu; /** The selection */ private ISelection selection; /** The SchemaHandlerListener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { /** * {@inheritDoc} */ public void attributeTypeAdded( AttributeType at ) { SchemaViewContentProvider contentProvider = ( SchemaViewContentProvider ) viewer.getContentProvider(); contentProvider.attributeTypeAdded( at ); TreeNode wrapper = contentProvider.getWrapper( at ); if ( wrapper != null ) { selection = new StructuredSelection( wrapper ); } } /** * {@inheritDoc} */ public void attributeTypeModified( AttributeType at ) { ( ( SchemaViewContentProvider ) viewer.getContentProvider() ).attributeTypeModified( at ); } /** * {@inheritDoc} */ public void attributeTypeRemoved( AttributeType at ) { ( ( SchemaViewContentProvider ) viewer.getContentProvider() ).attributeTypeRemoved( at ); } /** * {@inheritDoc} */ public void objectClassAdded( ObjectClass oc ) { SchemaViewContentProvider contentProvider = ( SchemaViewContentProvider ) viewer.getContentProvider(); contentProvider.objectClassAdded( oc ); TreeNode wrapper = contentProvider.getWrapper( oc ); if ( wrapper != null ) { selection = new StructuredSelection( wrapper ); } } /** * {@inheritDoc} */ public void objectClassModified( ObjectClass oc ) { ( ( SchemaViewContentProvider ) viewer.getContentProvider() ).objectClassModified( oc ); } /** * {@inheritDoc} */ public void objectClassRemoved( ObjectClass oc ) { ( ( SchemaViewContentProvider ) viewer.getContentProvider() ).objectClassRemoved( oc ); } /** * {@inheritDoc} */ public void schemaAdded( Schema schema ) { SchemaViewContentProvider contentProvider = ( SchemaViewContentProvider ) viewer.getContentProvider(); contentProvider.schemaAdded( schema ); TreeNode wrapper = contentProvider.getWrapper( schema ); if ( wrapper != null ) { selection = new StructuredSelection( wrapper ); } } /** * {@inheritDoc} */ public void schemaRemoved( Schema schema ) { ( ( SchemaViewContentProvider ) viewer.getContentProvider() ).schemaRemoved( schema ); } /** * {@inheritDoc} */ public void schemaRenamed( Schema schema ) { view.refresh(); } }; /** The SchemaCheckerListener */ private SchemaCheckerListener schemaCheckerListener = new SchemaCheckerListener() { public void schemaCheckerUpdated() { Display.getDefault().asyncExec( new Runnable() { public void run() { if ( selection != null ) { view.refresh( selection ); selection = null; } else { view.refresh(); } } } ); } }; /** Token used to activate and deactivate shortcuts in the view */ private IContextActivation contextActivation; // The Actions private NewSchemaAction newSchema; private NewAttributeTypeAction newAttributeType; private NewObjectClassAction newObjectClass; private OpenElementAction openElement; private OpenTypeHierarchyAction openTypeHierarchy; private DeleteSchemaElementAction deleteSchemaElement; private RenameSchemaElementAction renameSchemaElement; private ImportCoreSchemasAction importCoreSchemas; private ImportSchemasFromOpenLdapAction importSchemasFromOpenLdap; private ImportSchemasFromXmlAction importSchemasFromXml; private ExportSchemasAsOpenLdapAction exportSchemasAsOpenLdap; private ExportSchemasAsXmlAction exportSchemasAsXml; private ExportSchemasForADSAction exportSchemasForADS; private CollapseAllAction collapseAll; private OpenSchemaViewSortingDialogAction openSchemaViewSortingDialog; private SwitchSchemaPresentationToFlatAction switchSchemaPresentationToFlat; private SwitchSchemaPresentationToHierarchicalAction switchSchemaPresentationToHierarchical; private OpenSchemaViewPreferenceAction openSchemaViewPreference; private LinkWithEditorSchemaViewAction linkWithEditor; private MergeSchemasAction mergeSchema; // private CommitChangesAction commitChanges; /** * Creates a new instance of SchemasViewController. * * @param view * the associated view */ public SchemaViewController( SchemaView view ) { this.view = view; viewer = view.getViewer(); initActions(); initToolbar(); initMenu(); initContextMenu(); initProjectsHandlerListener(); initSchemaCheckerListener(); initDoubleClickListener(); initAuthorizedPrefs(); initPreferencesListener(); initState(); initPartListener(); } /** * Initializes the Actions. */ private void initActions() { newSchema = new NewSchemaAction(); newAttributeType = new NewAttributeTypeAction( viewer ); newObjectClass = new NewObjectClassAction( viewer ); openElement = new OpenElementAction( viewer ); openTypeHierarchy = new OpenTypeHierarchyAction( viewer ); deleteSchemaElement = new DeleteSchemaElementAction( viewer ); renameSchemaElement = new RenameSchemaElementAction( viewer ); importCoreSchemas = new ImportCoreSchemasAction(); importSchemasFromOpenLdap = new ImportSchemasFromOpenLdapAction(); importSchemasFromXml = new ImportSchemasFromXmlAction(); exportSchemasAsOpenLdap = new ExportSchemasAsOpenLdapAction( viewer ); exportSchemasAsXml = new ExportSchemasAsXmlAction( viewer ); exportSchemasForADS = new ExportSchemasForADSAction( viewer ); collapseAll = new CollapseAllAction( viewer ); openSchemaViewSortingDialog = new OpenSchemaViewSortingDialogAction(); switchSchemaPresentationToFlat = new SwitchSchemaPresentationToFlatAction(); switchSchemaPresentationToHierarchical = new SwitchSchemaPresentationToHierarchicalAction(); openSchemaViewPreference = new OpenSchemaViewPreferenceAction(); linkWithEditor = new LinkWithEditorSchemaViewAction( view ); mergeSchema = new MergeSchemasAction(); // commitChanges = new CommitChangesAction(); } /** * Initializes the Toolbar. */ private void initToolbar() { IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); toolbar.add( newSchema ); toolbar.add( newAttributeType ); toolbar.add( newObjectClass ); // toolbar.add( new Separator() ); // toolbar.add( commitChanges ); toolbar.add( new Separator() ); toolbar.add( collapseAll ); toolbar.add( linkWithEditor ); } /** * Initializes the Menu. */ private void initMenu() { IMenuManager menu = view.getViewSite().getActionBars().getMenuManager(); menu.add( openSchemaViewSortingDialog ); menu.add( new Separator() ); IMenuManager schemaPresentationMenu = new MenuManager( Messages .getString( "SchemaViewController.SchemaPresentationAction" ) ); //$NON-NLS-1$ schemaPresentationMenu.add( switchSchemaPresentationToFlat ); schemaPresentationMenu.add( switchSchemaPresentationToHierarchical ); menu.add( schemaPresentationMenu ); menu.add( new Separator() ); menu.add( linkWithEditor ); menu.add( new Separator() ); menu.add( openSchemaViewPreference ); } /** * Initializes the ContextMenu. */ private void initContextMenu() { contextMenu = new MenuManager( "" ); //$NON-NLS-1$ contextMenu.setRemoveAllWhenShown( true ); contextMenu.addMenuListener( new IMenuListener() { public void menuAboutToShow( IMenuManager manager ) { MenuManager newManager = new MenuManager( Messages.getString( "SchemaViewController.NewAction" ) ); //$NON-NLS-1$ MenuManager importManager = new MenuManager( Messages.getString( "SchemaViewController.ImportAction" ) ); //$NON-NLS-1$ MenuManager exportManager = new MenuManager( Messages.getString( "SchemaViewController.ExportAction" ) ); //$NON-NLS-1$ manager.add( newManager ); newManager.add( newSchema ); newManager.add( newAttributeType ); newManager.add( newObjectClass ); manager.add( new Separator() ); manager.add( openElement ); manager.add( openTypeHierarchy ); manager.add( new Separator() ); manager.add( deleteSchemaElement ); manager.add( new Separator() ); manager.add( renameSchemaElement ); manager.add( new Separator() ); manager.add( importManager ); importManager.add( importCoreSchemas ); importManager.add( new Separator() ); importManager.add( importSchemasFromOpenLdap ); importManager.add( importSchemasFromXml ); importManager.add( new Separator() ); importManager.add( mergeSchema ); manager.add( exportManager ); exportManager.add( exportSchemasAsOpenLdap ); exportManager.add( exportSchemasAsXml ); exportManager.add( new Separator() ); exportManager.add( exportSchemasForADS ); manager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); } } ); // set the context menu to the table viewer viewer.getControl().setMenu( contextMenu.createContextMenu( viewer.getControl() ) ); // register the context menu to enable extension actions view.getSite().registerContextMenu( contextMenu, viewer ); } /** * Initializes the ProjectsHandlerListener. */ private void initProjectsHandlerListener() { Activator.getDefault().getProjectsHandler().addListener( new ProjectsHandlerAdapter() { public void openProjectChanged( Project oldProject, Project newProject ) { if ( oldProject != null ) { removeSchemaHandlerListener( oldProject ); } if ( newProject != null ) { viewer.getTree().setEnabled( true ); newSchema.setEnabled( true ); newAttributeType.setEnabled( true ); newObjectClass.setEnabled( true ); collapseAll.setEnabled( true ); linkWithEditor.setEnabled( true ); openSchemaViewSortingDialog.setEnabled( true ); switchSchemaPresentationToFlat.setEnabled( true ); switchSchemaPresentationToHierarchical.setEnabled( true ); openSchemaViewPreference.setEnabled( true ); // commitChanges.setEnabled( true ); addSchemaHandlerListener( newProject ); view.reloadViewer(); } else { viewer.setInput( null ); viewer.getTree().setEnabled( false ); newSchema.setEnabled( false ); newAttributeType.setEnabled( false ); newObjectClass.setEnabled( false ); collapseAll.setEnabled( false ); linkWithEditor.setEnabled( false ); openSchemaViewSortingDialog.setEnabled( false ); switchSchemaPresentationToFlat.setEnabled( false ); switchSchemaPresentationToHierarchical.setEnabled( false ); openSchemaViewPreference.setEnabled( false ); // commitChanges.setEnabled( false ); } } } ); } /** * Adds the SchemaHandlerListener. * * @param project * the project */ private void addSchemaHandlerListener( Project project ) { SchemaHandler schemaHandler = project.getSchemaHandler(); if ( schemaHandler != null ) { schemaHandler.addListener( schemaHandlerListener ); } } /** * Removes the SchemaHandlerListener. * * @param project * the project */ private void removeSchemaHandlerListener( Project project ) { SchemaHandler schemaHandler = project.getSchemaHandler(); if ( schemaHandler != null ) { schemaHandler.removeListener( schemaHandlerListener ); } } /** * Intializes the schema checker listener. */ private void initSchemaCheckerListener() { Activator.getDefault().getSchemaChecker().addListener( schemaCheckerListener ); } /** * Initializes the DoubleClickListener. */ private void initDoubleClickListener() { viewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); TreeViewer viewer = view.getViewer(); // What we get from the viewer is a StructuredSelection StructuredSelection selection = ( StructuredSelection ) event.getSelection(); // Here's the real object (an AttributeTypeWrapper, ObjectClassWrapper or IntermediateNode) Object objectSelection = selection.getFirstElement(); IEditorInput input = null; String editorId = null; // Selecting the right editor and input if ( objectSelection instanceof AttributeTypeWrapper ) { input = new AttributeTypeEditorInput( ( ( AttributeTypeWrapper ) objectSelection ) .getAttributeType() ); editorId = AttributeTypeEditor.ID; } else if ( objectSelection instanceof ObjectClassWrapper ) { input = new ObjectClassEditorInput( ( ( ObjectClassWrapper ) objectSelection ).getObjectClass() ); editorId = ObjectClassEditor.ID; } else if ( ( objectSelection instanceof Folder ) || ( objectSelection instanceof SchemaWrapper ) ) { // Here we don't open an editor, we just expand the node. viewer.setExpandedState( objectSelection, !viewer.getExpandedState( objectSelection ) ); } // Let's open the editor if ( input != null ) { try { page.openEditor( input, editorId ); } catch ( PartInitException e ) { PluginUtils.logError( Messages.getString( "SchemaViewController.ErrorOpeningEditor" ), e ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "SchemaViewController.error" ), Messages //$NON-NLS-1$ .getString( "SchemaViewController.ErrorOpeningEditor" ) ); //$NON-NLS-1$ } } } } ); } /** * Initializes the Authorized Prefs IDs. */ private void initAuthorizedPrefs() { authorizedPrefs = new ArrayList<String>(); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY ); } /** * Initializes the listener on the preferences store */ private void initPreferencesListener() { Activator.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener() { /** * {@inheritDoc} */ public void propertyChange( PropertyChangeEvent event ) { if ( authorizedPrefs.contains( event.getProperty() ) ) { if ( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING.equals( event.getProperty() ) || PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION.equals( event.getProperty() ) ) { view.reloadViewer(); } else { view.refresh(); } } } } ); } /** * Initializes the state of the View. */ private void initState() { Project project = Activator.getDefault().getProjectsHandler().getOpenProject(); if ( project != null ) { viewer.getTree().setEnabled( true ); newSchema.setEnabled( true ); newAttributeType.setEnabled( true ); newObjectClass.setEnabled( true ); collapseAll.setEnabled( true ); linkWithEditor.setEnabled( true ); openSchemaViewSortingDialog.setEnabled( true ); switchSchemaPresentationToFlat.setEnabled( true ); switchSchemaPresentationToHierarchical.setEnabled( true ); openSchemaViewPreference.setEnabled( true ); // commitChanges.setEnabled( true ); addSchemaHandlerListener( project ); view.reloadViewer(); } else { viewer.getTree().setEnabled( false ); newSchema.setEnabled( false ); newAttributeType.setEnabled( false ); newObjectClass.setEnabled( false ); collapseAll.setEnabled( false ); linkWithEditor.setEnabled( false ); openSchemaViewSortingDialog.setEnabled( false ); switchSchemaPresentationToFlat.setEnabled( false ); switchSchemaPresentationToHierarchical.setEnabled( false ); openSchemaViewPreference.setEnabled( false ); // commitChanges.setEnabled( false ); } } /** * Initializes the PartListener. */ private void initPartListener() { view.getSite().getPage().addPartListener( new IPartListener2() { /** * This implementation deactivates the shortcuts when the part is deactivated. */ public void partDeactivated( IWorkbenchPartReference partRef ) { if ( partRef.getPart( false ) == view && contextActivation != null ) { ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { commandService.getCommand( newSchema.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( newAttributeType.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( newObjectClass.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( openElement.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( openTypeHierarchy.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( deleteSchemaElement.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( renameSchemaElement.getActionDefinitionId() ).setHandler( null ); } IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextService.deactivateContext( contextActivation ); contextActivation = null; } } /** * This implementation activates the shortcuts when the part is activated. */ public void partActivated( IWorkbenchPartReference partRef ) { if ( partRef.getPart( false ) == view ) { IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextActivation = contextService.activateContext( PluginConstants.CONTEXT_SCHEMA_VIEW ); ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { commandService.getCommand( newSchema.getActionDefinitionId() ).setHandler( new ActionHandler( newSchema ) ); commandService.getCommand( newAttributeType.getActionDefinitionId() ).setHandler( new ActionHandler( newAttributeType ) ); commandService.getCommand( newObjectClass.getActionDefinitionId() ).setHandler( new ActionHandler( newObjectClass ) ); commandService.getCommand( openElement.getActionDefinitionId() ).setHandler( new ActionHandler( openElement ) ); commandService.getCommand( openTypeHierarchy.getActionDefinitionId() ).setHandler( new ActionHandler( openTypeHierarchy ) ); commandService.getCommand( deleteSchemaElement.getActionDefinitionId() ).setHandler( new ActionHandler( deleteSchemaElement ) ); commandService.getCommand( renameSchemaElement.getActionDefinitionId() ).setHandler( new ActionHandler( renameSchemaElement ) ); } } } public void partBroughtToTop( IWorkbenchPartReference partRef ) { } public void partClosed( IWorkbenchPartReference partRef ) { } public void partHidden( IWorkbenchPartReference partRef ) { } public void partInputChanged( IWorkbenchPartReference partRef ) { } public void partOpened( IWorkbenchPartReference partRef ) { } public void partVisible( IWorkbenchPartReference partRef ) { } } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SchemaHandler.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import java.util.ArrayList; import java.util.List; import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.schemaeditor.model.Schema; /** * This class represents the SchemaHandler. * <p> * It used to handle the whole Schema (including schemas, attribute types, * object classes, matching rules and syntaxes). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaHandler { // // The Lists // /** The schemas List */ private List<Schema> schemasList; /** The attribute types List */ private List<AttributeType> attributeTypesList; /** The matching rules List */ private List<MatchingRule> matchingRulesList; /** The object classes List */ private List<ObjectClass> objectClassesList; /** The syntaxes List */ private List<LdapSyntax> syntaxesList; // // The MultiMap (for fast searching) // /** The schemas MultiMap */ private MultiValuedMap<String, Schema> schemasMap; /** The attribute types MultiMap */ private MultiValuedMap<String, AttributeType> attributeTypesMap; /** The matching rules MultiMap */ private MultiValuedMap<String, MatchingRule> matchingRulesMap; /** The object classes MultiMap */ private MultiValuedMap<String, ObjectClass> objectClassesMap; /** The syntaxes MultiMap */ private MultiValuedMap<String, LdapSyntax> syntaxesMap; // // The Listeners Lists // private List<SchemaHandlerListener> schemaHandlerListeners; /** * Creates a new instance of SchemaHandler. */ public SchemaHandler() { // Lists schemasList = new ArrayList<Schema>(); attributeTypesList = new ArrayList<AttributeType>(); matchingRulesList = new ArrayList<MatchingRule>();; objectClassesList = new ArrayList<ObjectClass>(); syntaxesList = new ArrayList<LdapSyntax>(); // Maps schemasMap = new ArrayListValuedHashMap<>(); attributeTypesMap = new ArrayListValuedHashMap<>(); matchingRulesMap = new ArrayListValuedHashMap<>(); objectClassesMap = new ArrayListValuedHashMap<>(); syntaxesMap = new ArrayListValuedHashMap<>(); // Listeners schemaHandlerListeners = new ArrayList<SchemaHandlerListener>(); } /** * Gets the List of all the attribute types. * * @return * the List of all the attribute types */ public List<AttributeType> getAttributeTypes() { return attributeTypesList; } /** * Gets the List of all the matching rules. * * @return * the List of all the matching rules */ public List<MatchingRule> getMatchingRules() { return matchingRulesList; } /** * Gets the List of all the object classes. * * @return * the List of all the object classes */ public List<ObjectClass> getObjectClasses() { return objectClassesList; } /** * Gets the List of all the schemas. * * @return * the List of all the schemas */ public List<Schema> getSchemas() { return schemasList; } /** * Gets the List of all the matching rules. * * @return * the List of all the matching rules */ public List<LdapSyntax> getSyntaxes() { return syntaxesList; } /** * Gets an attribute type identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding attribute type, or null if no one is found */ public AttributeType getAttributeType( String id ) { List<?> list = getAttributeTypeList( Strings.toLowerCase( id ) ); if ( ( list != null ) && ( list.size() >= 1 ) ) { return ( AttributeType ) list.get( 0 ); } else { return null; } } /** * Get the attribute type(s) List identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding attribute type(s) List or null if no one is found */ public List<?> getAttributeTypeList( String id ) { return ( List<?> ) attributeTypesMap.get( Strings.toLowerCase( id ) ); } /** * Gets a matching rule identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding matching rule, or null if no one is found */ public MatchingRule getMatchingRule( String id ) { List<?> list = getMatchingRuleList( Strings.toLowerCase( id ) ); if ( ( list != null ) && ( list.size() >= 1 ) ) { return ( MatchingRule ) list.get( 0 ); } else { return null; } } /** * Gets a matching rule(s) List identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding matching rule(s) List, or null if no one is found */ public List<?> getMatchingRuleList( String id ) { return ( List<?> ) matchingRulesMap.get( Strings.toLowerCase( id ) ); } /** * Gets an object class identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding object class, or null if no one is found */ public ObjectClass getObjectClass( String id ) { List<?> list = getObjectClassList( Strings.toLowerCase( id ) ); if ( ( list != null ) && ( list.size() >= 1 ) ) { return ( ObjectClass ) list.get( 0 ); } else { return null; } } /** * Gets an object class(es) List identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding object class(es) List, or null if no one is found */ public List<?> getObjectClassList( String id ) { return ( List<?> ) objectClassesMap.get( Strings.toLowerCase( id ) ); } /** * Gets a schema identified by a name. * * @param name * a name * @return * the corresponding schema, or null if no one is found */ public Schema getSchema( String name ) { List<?> list = getSchemaList( Strings.toLowerCase( name ) ); if ( ( list != null ) && ( list.size() >= 1 ) ) { return ( Schema ) list.get( 0 ); } else { return null; } } /** * Gets a schema(s) List identified by a name. * * @param name * a name * @return * the corresponding schema(s) List, or null if no one is found */ public List<?> getSchemaList( String name ) { return ( List<?> ) schemasMap.get( Strings.toLowerCase( name ) ); } /** * Gets a syntax identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding syntax, or null if no one is found */ public LdapSyntax getSyntax( String id ) { List<?> list = getSyntaxList( Strings.toLowerCase( id ) ); if ( ( list != null ) && ( list.size() >= 1 ) ) { return ( LdapSyntax ) list.get( 0 ); } else { return null; } } /** * Gets a syntax(es) List identified by an OID, or an alias. * * @param id * an OID or an alias * @return * the corresponding syntax(es) List, or null if no one is found */ public List<?> getSyntaxList( String id ) { return ( List<?> ) syntaxesMap.get( Strings.toLowerCase( id ) ); } /** * Adds a SchemaHandlerListener. * * @param listener * the listener */ public void addListener( SchemaHandlerListener listener ) { if ( !schemaHandlerListeners.contains( listener ) ) { schemaHandlerListeners.add( listener ); } } /** * Removes a SchemaHandlerListener. * * @param listener * the listener */ public void removeListener( SchemaHandlerListener listener ) { schemaHandlerListeners.remove( listener ); } /** * Adds a schema * * @param schema * the schema */ public void addSchema( Schema schema ) { // Adding the schema schemasList.add( schema ); schemasMap.put( Strings.toLowerCase( schema.getSchemaName() ), schema ); // Adding its attribute types for ( AttributeType at : schema.getAttributeTypes() ) { addSchemaObject( at ); } // Adding its matching rules for ( MatchingRule mr : schema.getMatchingRules() ) { addSchemaObject( mr ); } // Adding its object classes for ( ObjectClass oc : schema.getObjectClasses() ) { addSchemaObject( oc ); } // Adding its syntaxes for ( LdapSyntax syntax : schema.getSyntaxes() ) { addSchemaObject( syntax ); } notifySchemaAdded( schema ); } /** * Adds the given SchemaObject to the corresponding List and Map * * @param object * the SchemaObject */ private void addSchemaObject( SchemaObject object ) { if ( object instanceof AttributeType ) { AttributeType at = ( AttributeType ) object; attributeTypesList.add( at ); List<String> names = at.getNames(); if ( names != null ) { for ( String name : names ) { attributeTypesMap.put( Strings.toLowerCase( name ), at ); } } attributeTypesMap.put( at.getOid(), at ); } else if ( object instanceof MatchingRule ) { MatchingRule mr = ( MatchingRule ) object; matchingRulesList.add( mr ); List<String> names = mr.getNames(); if ( names != null ) { for ( String name : names ) { matchingRulesMap.put( Strings.toLowerCase( name ), mr ); } } matchingRulesMap.put( mr.getOid(), mr ); } else if ( object instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) object; objectClassesList.add( oc ); List<String> names = oc.getNames(); if ( names != null ) { for ( String name : names ) { objectClassesMap.put( Strings.toLowerCase( name ), oc ); } } objectClassesMap.put( oc.getOid(), oc ); } else if ( object instanceof LdapSyntax ) { LdapSyntax syntax = ( LdapSyntax ) object; syntaxesList.add( syntax ); List<String> names = syntax.getNames(); if ( names != null ) { for ( String name : names ) { syntaxesMap.put( Strings.toLowerCase( name ), syntax ); } } syntaxesMap.put( syntax.getOid(), syntax ); } } /** * Removes the given schema. * * @param schema * the schema */ public void removeSchema( Schema schema ) { // Removing the schema schemasList.remove( schema ); schemasMap.remove( Strings.toLowerCase( schema.getSchemaName() ) ); // Removing its attribute types for ( AttributeType at : schema.getAttributeTypes() ) { removeSchemaObject( at ); } // Removing its matching rules for ( MatchingRule mr : schema.getMatchingRules() ) { removeSchemaObject( mr ); } // Removing its object classes for ( ObjectClass oc : schema.getObjectClasses() ) { removeSchemaObject( oc ); } // Removing its syntaxes for ( LdapSyntax syntax : schema.getSyntaxes() ) { removeSchemaObject( syntax ); } notifySchemaRemoved( schema ); } /** * Removes the given SchemaObject to the corresponding List and Map * * @param object * the SchemaObject */ private void removeSchemaObject( SchemaObject object ) { if ( object instanceof AttributeType ) { AttributeType at = ( AttributeType ) object; attributeTypesList.remove( at ); List<String> names = at.getNames(); if ( names != null ) { for ( String name : names ) { attributeTypesMap.remove( Strings.toLowerCase( name ) ); } } attributeTypesMap.remove( at.getOid() ); } else if ( object instanceof MatchingRule ) { MatchingRule mr = ( MatchingRule ) object; matchingRulesList.remove( mr ); List<String> names = mr.getNames(); if ( names != null ) { for ( String name : names ) { matchingRulesMap.remove( Strings.toLowerCase( name ) ); } } matchingRulesMap.remove( mr.getOid() ); } else if ( object instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) object; objectClassesList.remove( oc ); List<String> names = oc.getNames(); if ( names != null ) { for ( String name : names ) { objectClassesMap.remove( Strings.toLowerCase( name ) ); } } objectClassesMap.remove( oc.getOid() ); } else if ( object instanceof LdapSyntax ) { LdapSyntax syntax = ( LdapSyntax ) object; syntaxesList.remove( syntax ); List<String> names = syntax.getNames(); if ( names != null ) { for ( String name : names ) { syntaxesMap.remove( Strings.toLowerCase( name ) ); } } syntaxesMap.remove( syntax.getOid() ); } } /** * Renames the given schema. * * @param schema the schema * @param newName the new name */ public void renameSchema( Schema schema, String newName ) { schemasMap.remove( Strings.toLowerCase( schema.getSchemaName() ) ); schema.setSchemaName( newName ); schemasMap.put( Strings.toLowerCase( schema.getSchemaName() ), schema ); // Removing its attribute types for ( AttributeType at : schema.getAttributeTypes() ) { at.setSchemaName( newName ); } // Removing its matching rules for ( MatchingRule mr : schema.getMatchingRules() ) { mr.setSchemaName( newName ); } // Removing its object classes for ( ObjectClass oc : schema.getObjectClasses() ) { oc.setSchemaName( newName ); } // Removing its syntaxes for ( LdapSyntax syntax : schema.getSyntaxes() ) { syntax.setSchemaName( newName ); } notifySchemaRenamed( schema ); } /** * Adds the given attribute type. * * @param at * the attribute type */ public void addAttributeType( AttributeType at ) { Schema schema = getSchema( at.getSchemaName() ); schema.addAttributeType( at ); addSchemaObject( at ); // Notifying the listeners notifyAttributeTypeAdded( at ); } /** * Update the source attribute type with the values of the * destination attribute type. * * @param at1 * the source attribute type * @param at2 * the destination attribute type */ public void modifyAttributeType( AttributeType at1, AttributeType at2 ) { // Removing the references (in case of the names or oid have changed) removeSchemaObject( at1 ); // Updating the attribute type at1.setNames( at2.getNames() ); at1.setOid( at2.getOid() ); at1.setDescription( at2.getDescription() ); at1.setSuperiorOid( at2.getSuperiorOid() ); at1.setUsage( at2.getUsage() ); at1.setSyntaxOid( at2.getSyntaxOid() ); at1.setSyntaxLength( at2.getSyntaxLength() ); at1.setObsolete( at2.isObsolete() ); at1.setSingleValued( at2.isSingleValued() ); at1.setCollective( at2.isCollective() ); at1.setUserModifiable( at2.isUserModifiable() ); at1.setEqualityOid( at2.getEqualityOid() ); at1.setOrderingOid( at2.getOrderingOid() ); at1.setSubstringOid( at2.getSubstringOid() ); // Adding the references (in case of the names or oid have changed) addSchemaObject( at1 ); // Notifying the listeners notifyAttributeTypeModified( at1 ); } /** * Removes the given attribute type. * * @param at * the attribute type */ public void removeAttributeType( AttributeType at ) { Schema schema = getSchema( at.getSchemaName() ); schema.removeAttributeType( at ); removeSchemaObject( at ); // Notifying the listeners notifyAttributeTypeRemoved( at ); } /** * Adds the given object class. * * @param oc * the object class */ public void addObjectClass( ObjectClass oc ) { Schema schema = getSchema( oc.getSchemaName() ); schema.addObjectClass( oc ); addSchemaObject( oc ); // Notifying the listeners notifyObjectClassAdded( oc ); } /** * Update the source object class with the values of the * destination object class. * * @param oc1 * the source object class * @param oc2 * the destination object class */ public void modifyObjectClass( ObjectClass oc1, ObjectClass oc2 ) { // Removing the references (in case of the names or oid have changed) removeSchemaObject( oc1 ); // Updating the object class oc1.setNames( oc2.getNames() ); oc1.setOid( oc2.getOid() ); oc1.setDescription( oc2.getDescription() ); oc1.setSuperiorOids( oc2.getSuperiorOids() ); oc1.setType( oc2.getType() ); oc1.setObsolete( oc2.isObsolete() ); oc1.setMustAttributeTypeOids( oc2.getMustAttributeTypeOids() ); oc1.setMayAttributeTypeOids( oc2.getMayAttributeTypeOids() ); // Adding the references (in case of the names or oid have changed) addSchemaObject( oc1 ); // Notifying the listeners notifyObjectClassModified( oc1 ); } /** * Removes the given object class. * * @param oc * the object class */ public void removeObjectClass( ObjectClass oc ) { Schema schema = getSchema( oc.getSchemaName() ); schema.removeObjectClass( oc ); removeSchemaObject( oc ); notifyObjectClassRemoved( oc ); } /** * Notifies the SchemaHandler listeners that a schema has been added. * * @param schema * the added schema */ private void notifySchemaAdded( Schema schema ) { for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.schemaAdded( schema ); } } /** * Notifies the given listeners that a schema has been removed. * * @param schema * the removed schema */ private void notifySchemaRemoved( Schema schema ) { for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.schemaRemoved( schema ); } } /** * Notifies the given listeners that a schema has been renamed. * * @param schema * the renamed schema */ private void notifySchemaRenamed( Schema schema ) { for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.schemaRenamed( schema ); } } /** * Notifies the SchemaHandler listeners that an attribute type has been added. * * @param at * the added attribute type */ private void notifyAttributeTypeAdded( AttributeType at ) { // SchemaHandler Listeners for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.attributeTypeAdded( at ); } } /** * Notifies the SchemaHandler listeners that an attribute type has been modified. * * @param at * the modified attribute type */ private void notifyAttributeTypeModified( AttributeType at ) { // SchemaHandler Listeners for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.attributeTypeModified( at ); } } /** * Notifies the SchemaHandler listeners that an attribute type has been removed. * * @param at * the removed attribute type */ private void notifyAttributeTypeRemoved( AttributeType at ) { // SchemaHandler Listeners for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.attributeTypeRemoved( at ); } } /** * Notifies the SchemaHandler listeners that an object class has been added. * * @param oc * the added object class */ private void notifyObjectClassAdded( ObjectClass oc ) { // SchemaHandler Listeners for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.objectClassAdded( oc ); } } /** * Notifies the SchemaHandler listeners that an object class has been modified. * * @param oc * the modified object class */ private void notifyObjectClassModified( ObjectClass oc ) { // SchemaHandler Listeners for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.objectClassModified( oc ); } } /** * Notifies the SchemaHandler listeners that an object class has been removed. * * @param oc * the removed object class */ private void notifyObjectClassRemoved( ObjectClass oc ) { // SchemaHandler Listeners for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0] ) ) { listener.objectClassRemoved( oc ); } } /** * Verifies if the given oid is already taken by a schema object. * * @param oid the oid * @return <code>true</code> if the the oid is already taken */ public boolean isOidAlreadyTaken( String oid ) { String lowerCasedOid = Strings.toLowerCase( oid ); if ( attributeTypesMap.containsKey( lowerCasedOid ) ) { return true; } else if ( objectClassesMap.containsKey( lowerCasedOid ) ) { return true; } else if ( matchingRulesMap.containsKey( lowerCasedOid ) ) { return true; } else if ( syntaxesMap.containsKey( lowerCasedOid ) ) { return true; } return false; } /** * Verifies if the given alias is already taken by an attribute type. * * @param alias the alias * @return <code>true</code> if the the alias is already taken */ public boolean isAliasAlreadyTakenForAttributeType( String alias ) { return attributeTypesMap.containsKey( Strings.toLowerCase( alias ) ); } /** * Verifies if the given alias is already taken by an object class. * * @param alias the alias * @return <code>true</code> if the the alias is already taken */ public boolean isAliasAlreadyTakenForObjectClass( String alias ) { return objectClassesMap.containsKey( Strings.toLowerCase( alias ) ); } /** * Verifies if the given name for a schema is already taken by another schema. * * @param name * the name * @return * true if the the name is already taken */ public boolean isSchemaNameAlreadyTaken( String name ) { return schemasMap.containsKey( Strings.toLowerCase( name ) ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProblemsViewController.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaCheckerListener; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; import org.apache.directory.studio.schemaeditor.view.views.ProblemsView; import org.apache.directory.studio.schemaeditor.view.widget.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaErrorWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWarningWrapper; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; /** * This class implements the Controller for the ProblemsView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProblemsViewController { /** The associated view */ private ProblemsView view; /** The SchemaCheckerListener */ private SchemaCheckerListener schemaCheckerListener = new SchemaCheckerListener() { public void schemaCheckerUpdated() { Display.getDefault().asyncExec( new Runnable() { public void run() { view.reloadViewer(); } } ); } }; /** * Creates a new instance of SchemasViewController. * * @param view * the associated view */ public ProblemsViewController( ProblemsView view ) { this.view = view; // SchemaCheckerListener Activator.getDefault().getSchemaChecker().addListener( schemaCheckerListener ); initDoubleClickListener(); } /** * Initializes the DoubleClickListener. */ private void initDoubleClickListener() { view.getViewer().addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); TreeViewer viewer = view.getViewer(); // What we get from the treeViewer is a StructuredSelection StructuredSelection selection = ( StructuredSelection ) event.getSelection(); // Here's the real object (an AttributeTypeWrapper, ObjectClassWrapper or IntermediateNode) Object objectSelection = selection.getFirstElement(); IEditorInput input = null; String editorId = null; // Selecting the right editor and input if ( objectSelection instanceof SchemaErrorWrapper ) { SchemaObject object = ( ( SchemaErrorWrapper ) objectSelection ).getLdapSchemaException() .getSourceObject(); if ( object instanceof AttributeType ) { input = new AttributeTypeEditorInput( Activator.getDefault().getSchemaHandler() .getAttributeType( object.getOid() ) ); editorId = AttributeTypeEditor.ID; } else if ( object instanceof ObjectClass ) { input = new ObjectClassEditorInput( Activator.getDefault().getSchemaHandler() .getObjectClass( object.getOid() ) ); editorId = ObjectClassEditor.ID; } } else if ( objectSelection instanceof SchemaWarningWrapper ) { SchemaObject object = ( ( SchemaWarningWrapper ) objectSelection ).getSchemaWarning().getSource(); if ( object instanceof AttributeType ) { input = new AttributeTypeEditorInput( ( AttributeType ) object ); editorId = AttributeTypeEditor.ID; } else if ( object instanceof ObjectClass ) { input = new ObjectClassEditorInput( ( ObjectClass ) object ); editorId = ObjectClassEditor.ID; } } else if ( ( objectSelection instanceof Folder ) ) { // Here we don't open an editor, we just expand the node. viewer.setExpandedState( objectSelection, !viewer.getExpandedState( objectSelection ) ); } // Let's open the editor if ( input != null ) { try { page.openEditor( input, editorId ); } catch ( PartInitException e ) { PluginUtils.logError( Messages.getString( "ProblemsViewController.ErrorOpeningEditor" ), e ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "ProblemsViewController.Error" ), //$NON-NLS-1$ Messages.getString( "ProblemsViewController.ErrorOpeningEditor" ) ); //$NON-NLS-1$ } } } } ); } /** * Disposes the listeners. */ public void dispose() { // SchemaCheckerListener Activator.getDefault().getSchemaChecker().removeListener( schemaCheckerListener ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/ProjectsHandler.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Project.ProjectState; /** * This class represents the ProjectsHandler. * <p> * It used to handle the schema projects. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsHandler { /** The ProjectsHandler instance */ private static ProjectsHandler instance; /** The projects List */ private List<Project> projectsList; /** The projects Map */ private Map<String, Project> projectsMap; /** The ProjectsHandler listeners */ private List<ProjectsHandlerListener> projectsHandlerListeners; /** The projects listeners */ private MultiValuedMap<Project, ProjectListener> projectsListeners; /** The open project */ private Project openProject; /** * Gets the singleton instance of the ProjectsHandler. * * @return * the singleton instance of the ProjectsHandler */ public static ProjectsHandler getInstance() { if ( instance == null ) { instance = new ProjectsHandler(); } return instance; } /** * Private Constructor. */ private ProjectsHandler() { projectsList = new ArrayList<Project>(); projectsMap = new HashMap<String, Project>(); projectsHandlerListeners = new ArrayList<ProjectsHandlerListener>(); projectsListeners = new ArrayListValuedHashMap(); } /** * Adds a project. * * @param project * a project */ public void addProject( Project project ) { projectsList.add( project ); projectsMap.put( Strings.toLowerCase( project.getName() ), project ); notifyProjectAdded( project ); } /** * Removes the given project. * * @param project * the project */ public void removeProject( Project project ) { projectsList.remove( project ); projectsMap.remove( Strings.toLowerCase( project.getName() ) ); notifyProjectRemoved( project ); } /** * Gets the project identified by the given name. * * @param name * the name of the project * @return * the corresponding project */ public Project getProject( String name ) { return projectsMap.get( Strings.toLowerCase( name ) ); } /** * Gets the projects List. * * @return * the projects List */ public List<Project> getProjects() { return projectsList; } /** * Renames the given project. * * @param project * the project * @param name * the new name */ public void renameProject( Project project, String name ) { projectsMap.remove( Strings.toLowerCase( project.getName() ) ); project.setName( name ); projectsMap.put( Strings.toLowerCase( name ), project ); notifyProjectRenamed( project ); } /** * Return whether or not the given name is already taken by another project * * @param name * the name * @return * true if the given name is already taken, false if not */ public boolean isProjectNameAlreadyTaken( String name ) { return projectsMap.containsKey( Strings.toLowerCase( name ) ); } /** * Opens the given project (and closes the previously opened project) * * @param project * the project */ public void openProject( Project project ) { Project oldOpenProject = openProject; if ( oldOpenProject != null ) { oldOpenProject.setState( ProjectState.CLOSED ); } openProject = project; openProject.setState( ProjectState.OPEN ); notifyOpenProjectChanged( oldOpenProject, openProject ); } /** * Closes the given project * * @param project * the project */ public void closeProject( Project project ) { Project oldOpenProject = openProject; if ( oldOpenProject.equals( project ) ) { oldOpenProject.setState( ProjectState.CLOSED ); openProject = null; } notifyOpenProjectChanged( oldOpenProject, openProject ); } /** * Gets the 'Open' project. * * @return * the 'Open' project */ public Project getOpenProject() { return openProject; } /** * Sets the 'Open' project * * @param project * the project */ public void setOpenProject( Project project ) { openProject = project; } /** * Adds a ProjectsHandlerListener to the ProjectsHandler. * * @param listener * the listener */ public void addListener( ProjectsHandlerListener listener ) { projectsHandlerListeners.add( listener ); } /** * Remove the given ProjectsHandlerListener. * * @param listener * the listener */ public void removeListener( ProjectsHandlerListener listener ) { projectsHandlerListeners.remove( listener ); } /** * Adds a ProjectListener to the given Project. * * @param project * the project * @param listener * the listener */ public void addListener( Project project, ProjectListener listener ) { if ( !projectsListeners.containsMapping( project, listener ) ) { projectsListeners.put( project, listener ); } } /** * Removes the given ProjectListener. * * @param project * the project * @param listener * the listener */ public void removeListener( Project project, ProjectListener listener ) { projectsListeners.removeMapping( project, listener ); } /** * Notifies the ProjectsHandler's listener that a project has been added. * * @param project * the added project */ private void notifyProjectAdded( Project project ) { for ( ProjectsHandlerListener listener : projectsHandlerListeners ) { listener.projectAdded( project ); } } /** * Notifies the ProjectsHandler's listener that a project has been removed. * * @param project * the removed project */ private void notifyProjectRemoved( Project project ) { for ( ProjectsHandlerListener listener : projectsHandlerListeners ) { listener.projectRemoved( project ); } } /** * Notifies the project's Listeners that the project has been renamed. * * @param project * the renamed project */ @SuppressWarnings("unchecked") private void notifyProjectRenamed( Project project ) { List<ProjectListener> listeners = ( List<ProjectListener> ) projectsListeners.get( project ); for ( ProjectListener listener : listeners ) { listener.projectRenamed(); } } /** * Notifies the ProjectsHandler's listener that a new project has been opened. * * @param oldProject * the old opened project * @param newProject * the new opened project */ private void notifyOpenProjectChanged( Project oldProject, Project newProject ) { for ( ProjectsHandlerListener listener : projectsHandlerListeners ) { listener.openProjectChanged( oldProject, newProject ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SearchViewController.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/controller/SearchViewController.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.schemaeditor.controller; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.actions.OpenSearchViewPreferenceAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenSearchViewSortingDialogAction; import org.apache.directory.studio.schemaeditor.controller.actions.RunCurrentSearchAgainAction; import org.apache.directory.studio.schemaeditor.controller.actions.ShowSearchFieldAction; import org.apache.directory.studio.schemaeditor.controller.actions.ShowSearchHistoryAction; import org.apache.directory.studio.schemaeditor.view.views.SearchView; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; /** * This class implements the Controller for the SearchView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchViewController { /** The associated view */ private SearchView view; /** The authorized Preferences keys*/ private List<String> authorizedPrefs; // The Actions private ShowSearchFieldAction showSearchField; private RunCurrentSearchAgainAction runCurrentSearchAgain; private ShowSearchHistoryAction searchHistory; private OpenSearchViewSortingDialogAction openSearchViewSortingDialog; private OpenSearchViewPreferenceAction openSearchViewPreference; /** * Creates a new instance of SearchViewController. * * @param view * the associated view */ public SearchViewController( SearchView view ) { this.view = view; initActions(); initToolbar(); initMenu(); initAuthorizedPrefs(); initPreferencesListener(); } /** * Initializes the Actions. */ private void initActions() { showSearchField = new ShowSearchFieldAction( view ); runCurrentSearchAgain = new RunCurrentSearchAgainAction( view ); searchHistory = new ShowSearchHistoryAction( view ); openSearchViewSortingDialog = new OpenSearchViewSortingDialogAction(); openSearchViewPreference = new OpenSearchViewPreferenceAction(); } /** * Initializes the Toolbar. */ private void initToolbar() { IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); toolbar.add( showSearchField ); toolbar.add( new Separator() ); toolbar.add( runCurrentSearchAgain ); toolbar.add( searchHistory ); } /** * Initializes the Menu. */ private void initMenu() { IMenuManager menu = view.getViewSite().getActionBars().getMenuManager(); menu.add( openSearchViewSortingDialog ); menu.add( new Separator() ); menu.add( openSearchViewPreference ); } /** * Initializes the Authorized Prefs IDs. */ private void initAuthorizedPrefs() { authorizedPrefs = new ArrayList<String>(); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_GROUPING ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY ); authorizedPrefs.add( PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER ); } /** * Initializes the listener on the preferences store */ private void initPreferencesListener() { Activator.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener() { /** * {@inheritDoc} */ public void propertyChange( PropertyChangeEvent event ) { if ( authorizedPrefs.contains( event.getProperty() ) ) { view.refresh(); } } } ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false