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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/dialogs/Messages.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/dialogs/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.ldapservers.dialogs;
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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/NewServerWizardConfigurationPage.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/NewServerWizardConfigurationPage.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.ldapservers.wizards;
import org.apache.directory.studio.ldapservers.model.LdapServer;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterConfigurationPage;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterConfigurationPageModifyListener;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* This class implements the wizard page for the new server wizard configuration page.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class NewServerWizardConfigurationPage extends WizardPage implements
LdapServerAdapterConfigurationPageModifyListener
{
/** The configuration page */
private LdapServerAdapterConfigurationPage configurationPage;
/**
* Creates a new instance of NewServerWizardConfigurationPage.
*/
public NewServerWizardConfigurationPage( LdapServerAdapterConfigurationPage configurationPage )
{
super( configurationPage.getId() );
setTitle( configurationPage.getTitle() );
setDescription( configurationPage.getDescription() );
setImageDescriptor( configurationPage.getImageDescriptor() );
setPageComplete( configurationPage.isPageComplete() );
this.configurationPage = configurationPage;
configurationPage.setModifyListener( this );
}
/**
* {@inheritDoc}
*/
public void createControl( Composite parent )
{
// Creating the control for the configuration page
Control control = configurationPage.createControl( parent );
// Setting the control and the focus
setControl( control );
control.setFocus();
}
/**
* Saves the configuration information to the given LDAP server.
*
* @param ldapServer the LDAP server
*/
public void saveConfiguration( LdapServer ldapServer )
{
configurationPage.saveConfiguration( ldapServer );
}
/**
* {@inheritDoc}
*/
public void configurationPageModified()
{
setErrorMessage( configurationPage.getErrorMessage() );
setPageComplete( configurationPage.isPageComplete() );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/Messages.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/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.ldapservers.wizards;
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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/NewServerWizard.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/NewServerWizard.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.ldapservers.wizards;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
import org.apache.directory.studio.ldapservers.LdapServerAdapterExtensionsManager;
import org.apache.directory.studio.ldapservers.LdapServersManager;
import org.apache.directory.studio.ldapservers.model.LdapServer;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterConfigurationPage;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
/**
* This class implements the new server wizard.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class NewServerWizard extends Wizard implements INewWizard
{
/** The wizard page */
private NewServerWizardSelectionPage adapterSelectionPage;
private Map<String, NewServerWizardConfigurationPage> configurationPages = new HashMap<String, NewServerWizardConfigurationPage>();
/**
* {@inheritDoc}
*/
public void addPages()
{
adapterSelectionPage = new NewServerWizardSelectionPage();
addPage( adapterSelectionPage );
List<LdapServerAdapterExtension> ldapServerAdapterExtensions = LdapServerAdapterExtensionsManager.getDefault()
.getLdapServerAdapterExtensions();
for ( LdapServerAdapterExtension ldapServerAdapterExtension : ldapServerAdapterExtensions )
{
String configurationPageClassName = ldapServerAdapterExtension.getConfigurationPageClassName();
if ( ( configurationPageClassName != null ) && ( !"".equals( configurationPageClassName ) ) ) //$NON-NLS-1$
{
try
{
LdapServerAdapterConfigurationPage configurationPage = ldapServerAdapterExtension
.getNewConfigurationPageInstance();
NewServerWizardConfigurationPage configurationWizardPage = new NewServerWizardConfigurationPage(
configurationPage );
configurationPages.put( ldapServerAdapterExtension.getId(), configurationWizardPage );
addPage( configurationWizardPage );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
}
/**
* {@inheritDoc}
*/
public boolean performFinish()
{
// Getting server name and adapter extension
final String serverName = adapterSelectionPage.getServerName();
final LdapServerAdapterExtension adapterExtension = adapterSelectionPage.getLdapServerAdapterExtension();
// Getting the configuration page (in any
NewServerWizardConfigurationPage configurationPage = getConfigurationPage();
// Creating the new server
final LdapServer server = new LdapServer();
server.setName( serverName );
server.setLdapServerAdapterExtension( adapterExtension );
// Saving the configuration page (is any)
if ( configurationPage != null )
{
configurationPage.saveConfiguration( server );
}
try
{
getContainer().run( true, false, new IRunnableWithProgress()
{
public void run( IProgressMonitor monitor )
{
// Creating a StudioProgressMonitor
StudioProgressMonitor spm = new StudioProgressMonitor( monitor );
// Setting the title
spm.beginTask( Messages.getString( "NewServerWizard.CreatingLdapServer" ), IProgressMonitor.UNKNOWN ); //$NON-NLS-1$
spm.subTask( Messages.getString( "NewServerWizard.CreatingServerFolder" ) ); //$NON-NLS-1$
// Adding the new server to the servers handler
LdapServersManager.getDefault().addServer( server );
// Creating the folder for the new server
LdapServersManager.createNewServerFolder( server );
try
{
// Letting the LDAP Server Adapter finish the creation of the server
adapterExtension.getInstance().add( server, spm );
}
catch ( Exception e )
{
// Reporting the error to the progress monitor
spm.reportError( e );
}
// Reporting to the monitors that we're done
spm.done();
}
} );
}
catch ( Exception e )
{
// Will never occur
}
return true;
}
/**
* {@inheritDoc}
*/
public void init( IWorkbench workbench, IStructuredSelection selection )
{
setWindowTitle( Messages.getString( "NewServerWizard.NewLdapServer" ) ); //$NON-NLS-1$
setNeedsProgressMonitor( true );
}
/**
* {@inheritDoc}
*/
public IWizardPage getNextPage( IWizardPage page )
{
IWizardPage configurationPage = getConfigurationPage();
if ( adapterSelectionPage.equals( page ) )
{
return configurationPage;
}
return null;
}
/**
* {@inheritDoc}
*/
public boolean canFinish()
{
if ( adapterSelectionPage.isPageComplete() )
{
IWizardPage configurationPage = getConfigurationPage();
if ( configurationPage != null )
{
return configurationPage.isPageComplete();
}
else
{
return true;
}
}
return false;
}
/**
* Gets the configuration page corresponding to the currently
* selected LDAP Server Adapter Extension.
*
* @return the configuration page corresponding to the currently
* selected LDAP Server Adapter Extension.
*/
private NewServerWizardConfigurationPage getConfigurationPage()
{
LdapServerAdapterExtension ldapServerAdapterExtension = adapterSelectionPage
.getLdapServerAdapterExtension();
if ( ldapServerAdapterExtension != null )
{
String configurationPageClassName = ldapServerAdapterExtension.getConfigurationPageClassName();
if ( ( configurationPageClassName != null ) && ( !"".equals( configurationPageClassName ) ) ) //$NON-NLS-1$
{
return configurationPages.get( ldapServerAdapterExtension.getId() );
}
}
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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/LdapServerAdapterExtensionsContentProvider.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/LdapServerAdapterExtensionsContentProvider.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.ldapservers.wizards;
import java.util.List;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.apache.directory.studio.ldapservers.LdapServerAdapterExtensionsManager;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
/**
* This class implements a {@link ITreeContentProvider} for LDAP Server Adapter Extensions {@link TreeViewer}.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdapServerAdapterExtensionsContentProvider implements ITreeContentProvider
{
/** The {@link MultiValueMap} used to store LDAP Server Adapter Extensions and order them by vendor (used as key) */
private MultiValuedMap<String, LdapServerAdapterExtension> ldapServerAdapterExtensionsMap = new ArrayListValuedHashMap<>();
/**
* Creates a new instance of LdapServerAdaptersContentProvider.
*/
public LdapServerAdapterExtensionsContentProvider()
{
for ( LdapServerAdapterExtension extension : LdapServerAdapterExtensionsManager.getDefault()
.getLdapServerAdapterExtensions() )
{
ldapServerAdapterExtensionsMap.put( extension.getVendor(), extension );
}
}
/**
* {@inheritDoc}
*/
public Object[] getElements( Object inputElement )
{
return ldapServerAdapterExtensionsMap.keySet().toArray();
}
/**
* {@inheritDoc}
*/
public Object[] getChildren( Object parentElement )
{
Object children = ldapServerAdapterExtensionsMap.get( (String) parentElement );
if ( children != null )
{
if ( children instanceof List )
{
return ( ( List<?> ) children ).toArray();
}
else
{
return new Object[]
{ children };
}
}
return null;
}
/**
* {@inheritDoc}
*/
public boolean hasChildren( Object element )
{
if ( element instanceof String )
{
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
public void dispose()
{
// Nothing to do
}
/**
* {@inheritDoc}
*/
public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
{
// Nothing to do
}
/**
* {@inheritDoc}
*/
public Object getParent( Object element )
{
// Hierarchy is only descending.
// Should not be used.
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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/LdapServerAdapterExtensionsLabelProvider.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/LdapServerAdapterExtensionsLabelProvider.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.ldapservers.wizards;
import org.apache.directory.studio.ldapservers.LdapServersPlugin;
import org.apache.directory.studio.ldapservers.LdapServersPluginConstants;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Image;
/**
* This class implements a {@link ILabelProvider} for LDAP Server Adapter Extensions {@link TreeViewer}.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdapServerAdapterExtensionsLabelProvider extends LabelProvider
{
/**
* {@inheritDoc}
*/
public Image getImage( Object element )
{
if ( element instanceof String )
{
return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_FOLDER );
}
else if ( element instanceof LdapServerAdapterExtension )
{
return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER );
}
return null;
}
/**
* {@inheritDoc}
*/
public String getText( Object element )
{
if ( element instanceof String )
{
return ( String ) element;
}
else if ( element instanceof LdapServerAdapterExtension )
{
LdapServerAdapterExtension extension = ( LdapServerAdapterExtension ) element;
String version = extension.getVersion();
if ( ( version != null ) && ( !version.equals( "" ) ) ) //$NON-NLS-1$
{
return extension.getName() + " " + version; //$NON-NLS-1$
}
else
{
return extension.getName();
}
}
return super.getText( element );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/NewServerWizardSelectionPage.java | plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/wizards/NewServerWizardSelectionPage.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.ldapservers.wizards;
import java.util.regex.Pattern;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapservers.LdapServersManager;
import org.apache.directory.studio.ldapservers.LdapServersPlugin;
import org.apache.directory.studio.ldapservers.LdapServersPluginConstants;
import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
/**
* This class implements the wizard page for the new server wizard selection page.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class NewServerWizardSelectionPage extends WizardPage
{
/** The servers handler */
private LdapServersManager ldapServersManager;
/** The content provider of the TreeViewer */
private LdapServerAdapterExtensionsContentProvider contentProvider;
/** The label provider of the TreeViewer */
private LdapServerAdapterExtensionsLabelProvider labelProvider;
// UI fields
private Label filterLabel;
private Text filterText;
private TreeViewer ldapServerAdaptersTreeViewer;
private Text serverNameText;
/**
* Creates a new instance of NewServerWizardSelectionPage.
*/
public NewServerWizardSelectionPage()
{
super( NewServerWizardSelectionPage.class.getCanonicalName() );
setTitle( Messages.getString( "NewServerWizardSelectionPage.CreateAnLdapServer" ) ); //$NON-NLS-1$
setDescription( Messages.getString( "NewServerWizardSelectionPage.ChooseTypeOfServerAndSpecifyName" ) ); //$NON-NLS-1$
setImageDescriptor( LdapServersPlugin.getDefault().getImageDescriptor(
LdapServersPluginConstants.IMG_SERVER_NEW_WIZARD ) );
setPageComplete( false );
ldapServersManager = LdapServersManager.getDefault();
}
/**
* {@inheritDoc}
*/
public void createControl( Composite parent )
{
// Creating the composite to hold the UI
Composite composite = new Composite( parent, SWT.NONE );
composite.setLayout( new GridLayout( 2, false ) );
// Filter Label
filterLabel = BaseWidgetUtils.createLabel( composite,
Messages.getString( "NewServerWizardSelectionPage.SelectServerType" ), 2 ); //$NON-NLS-1$
filterLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
// Filter Text
filterText = new Text( composite, SWT.BORDER | SWT.SEARCH | SWT.CANCEL );
filterText.setMessage( Messages.getString( "NewServerWizardSelectionPage.TypeFilterHere" ) ); //$NON-NLS-1$
filterText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
// LDAP Server Adapters Tree Viewer
ldapServerAdaptersTreeViewer = new TreeViewer( new Tree( composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL
| SWT.BORDER ) );
GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 2, 1 );
gd.heightHint = 90;
ldapServerAdaptersTreeViewer.getTree().setLayoutData( gd );
contentProvider = new LdapServerAdapterExtensionsContentProvider();
ldapServerAdaptersTreeViewer.setContentProvider( contentProvider );
labelProvider = new LdapServerAdapterExtensionsLabelProvider();
ldapServerAdaptersTreeViewer.setLabelProvider( labelProvider );
ldapServerAdaptersTreeViewer.setInput( "LDAP Server Adapters Tree Viewer Input" ); //$NON-NLS-1$
ldapServerAdaptersTreeViewer.expandAll();
ldapServerAdaptersTreeViewer.addFilter( new ViewerFilter()
{
public boolean select( Viewer viewer, Object parentElement, Object element )
{
// The current element is a Vendor
if ( element instanceof String )
{
Object[] children = contentProvider.getChildren( element );
for ( Object child : children )
{
String label = labelProvider.getText( child );
return getFilterPattern().matcher( label ).matches();
}
}
// The current element is an LdapServerAdapterExtension
else if ( element instanceof LdapServerAdapterExtension )
{
String label = labelProvider.getText( element );
return getFilterPattern().matcher( label ).matches();
}
return false;
}
/**
* Gets the filter pattern.
*
* @return
* the filter pattern
*/
private Pattern getFilterPattern()
{
String filter = filterText.getText();
return Pattern.compile( ( ( filter == null ) ? ".*" : ".*" + filter + ".*" ), Pattern.CASE_INSENSITIVE ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
} );
// Filler
Label filler = new Label( composite, SWT.NONE );
filler.setLayoutData( new GridData( SWT.NONE, SWT.NONE, true, false, 2, 1 ) );
// Server Name Label
BaseWidgetUtils.createLabel( composite, Messages.getString( "NewServerWizardSelectionPage.ServerName" ), 1 ); //$NON-NLS-1$
// Server Name Text
serverNameText = BaseWidgetUtils.createText( composite, "", 1 ); //$NON-NLS-1$
// Adding listeners
addListeners();
// Setting the control on the composite and setting focus
setControl( composite );
composite.setFocus();
}
/**
* Adding listeners to UI elements.
*/
private void addListeners()
{
// Filter Text
filterText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
// Refreshing the LDAP Server Adapters Tree Viewer
ldapServerAdaptersTreeViewer.refresh();
ldapServerAdaptersTreeViewer.expandAll();
}
} );
// LDAP Server Adapters Tree Viewer
ldapServerAdaptersTreeViewer.addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
// Assigning an automatic name to the LDAP Server based on the selected LDAP Server Adapter Extension
serverNameText.setText( getServerName( ( StructuredSelection ) ldapServerAdaptersTreeViewer
.getSelection() ) );
// getContainer().updateButtons();
validate();
}
/**
* Get a name for the server based on the current selection.
*
* @param selection
* the current selection
* @return
* a name for the server based on the current selection
*/
private String getServerName( StructuredSelection selection )
{
if ( !selection.isEmpty() )
{
Object selectedObject = selection.getFirstElement();
if ( selectedObject instanceof LdapServerAdapterExtension )
{
// Getting the name of the LDAP Server Adapter Extension
String serverName = labelProvider.getText( selection.getFirstElement() );
// Checking if the name if available
if ( ldapServersManager.isNameAvailable( serverName ) )
{
return serverName;
}
else
{
// The name is not available, looking for another name
String newServerName = serverName;
for ( int i = 2; !ldapServersManager.isNameAvailable( newServerName ); i++ )
{
newServerName = serverName + " (" + i + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
return newServerName;
}
}
}
// Returning an empty string if the selection is empty or if the current selection is a vendor
return ""; //$NON-NLS-1$
}
} );
// Server Name Text
serverNameText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
validate();
}
} );
}
/**
* Validates the page.
*/
private void validate()
{
displayErrorMessage( null );
// LDAP Server Adapters Tree Viewer
StructuredSelection selection = ( StructuredSelection ) ldapServerAdaptersTreeViewer.getSelection();
if ( selection.isEmpty() )
{
displayErrorMessage( Messages.getString( "NewServerWizardSelectionPage.ChooseTypeOfServerToCreate" ) ); //$NON-NLS-1$
return;
}
else
{
Object selectedObject = selection.getFirstElement();
if ( selectedObject instanceof String )
{
displayErrorMessage( Messages.getString( "NewServerWizardSelectionPage.ChooseTypeOfServerToCreate" ) ); //$NON-NLS-1$
return;
}
}
// Server Name Text
String name = serverNameText.getText();
if ( ( name != null ) )
{
if ( "".equals( name ) ) //$NON-NLS-1$
{
displayErrorMessage( Messages.getString( "NewServerWizardSelectionPage.EnterANameForLdapServer" ) ); //$NON-NLS-1$
return;
}
if ( !ldapServersManager.isNameAvailable( name ) )
{
displayErrorMessage( Messages
.getString( "NewServerWizardSelectionPage.LdapServerWithSameNameAlreadyExists" ) ); //$NON-NLS-1$
return;
}
}
}
/**
* Displays an error message and set the page status as incomplete
* if the message is not null.
*
* @param message
* the message to display
*/
protected void displayErrorMessage( String message )
{
setErrorMessage( message );
setPageComplete( message == null );
}
/**
* Gets the name of the server.
*
* @return
* the name of the server
*/
public String getServerName()
{
return serverNameText.getText();
}
/**
* Gets the Ldap Server Adapter Extension.
*
* @return
* the Ldap Server Adapter Extension
*/
public LdapServerAdapterExtension getLdapServerAdapterExtension()
{
StructuredSelection selection = ( StructuredSelection ) ldapServerAdaptersTreeViewer.getSelection();
if ( !selection.isEmpty() )
{
Object selectedObject = selection.getFirstElement();
if ( selectedObject instanceof LdapServerAdapterExtension )
{
return ( LdapServerAdapterExtension ) selectedObject;
}
}
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/valueeditors/src/test/java/org/apache/directory/studio/valueeditors/uuid/InPlaceUuidValueEditorTest.java | plugins/valueeditors/src/test/java/org/apache/directory/studio/valueeditors/uuid/InPlaceUuidValueEditorTest.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.valueeditors.uuid;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.Test;
public class InPlaceUuidValueEditorTest
{
@Test
public void testConvertToString1()
{
InPlaceUuidValueEditor editor = new InPlaceUuidValueEditor();
byte[] bytes = new byte[]
{
//
( byte ) 0x6b,
( byte ) 0xa7,
( byte ) 0xb8,
( byte ) 0x10, //
( byte ) 0x9d,
( byte ) 0xad, //
( byte ) 0x11,
( byte ) 0xd1, //
( byte ) 0x80,
( byte ) 0xb4, //
( byte ) 0x00,
( byte ) 0xc0,
( byte ) 0x4f,
( byte ) 0xd4,
( byte ) 0x30,
( byte ) 0xc8 };
String displayValue = editor.convertToString( bytes );
assertEquals( Strings.toLowerCaseAscii( "6ba7b810-9dad-11d1-80b4-00c04fd430c8" ), displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToString2()
{
InPlaceUuidValueEditor editor = new InPlaceUuidValueEditor();
byte[] bytes = new byte[]
{
//
( byte ) 0x00,
( byte ) 0x11,
( byte ) 0x22,
( byte ) 0x33, //
( byte ) 0x44,
( byte ) 0x55, //
( byte ) 0x66,
( byte ) 0x77, //
( byte ) 0x88,
( byte ) 0x99, //
( byte ) 0xAA,
( byte ) 0xBB,
( byte ) 0xCC,
( byte ) 0xDD,
( byte ) 0xEE,
( byte ) 0xFF };
String displayValue = editor.convertToString( bytes );
assertEquals( Strings.toLowerCaseAscii( "00112233-4455-6677-8899-AABBCCDDEEFF" ), displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToStringInvalid()
{
InPlaceUuidValueEditor editor = new InPlaceUuidValueEditor();
// test too short
byte[] bytes = new byte[]
{ ( byte ) 0x00, ( byte ) 0x11, ( byte ) 0x22, ( byte ) 0x33 };
String displayValue = editor.convertToString( bytes );
assertEquals( Messages.getString( "InPlaceUuidValueEditor.InvalidUuid" ), displayValue ); //$NON-NLS-1$
// test too long
byte[] bytes2 = new byte[]
{
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00, };
String displayValue2 = editor.convertToString( bytes2 );
assertEquals( Messages.getString( "InPlaceUuidValueEditor.InvalidUuid" ), displayValue2 ); //$NON-NLS-1$
}
@Test
public void testConvertToStringNull()
{
InPlaceUuidValueEditor editor = new InPlaceUuidValueEditor();
byte[] bytes = null;
String displayValue = editor.convertToString( bytes );
assertEquals( Messages.getString( "InPlaceUuidValueEditor.InvalidUuid" ), displayValue ); //$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/valueeditors/src/test/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectSidValueEditorTest.java | plugins/valueeditors/src/test/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectSidValueEditorTest.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.valueeditors.msad;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class InPlaceMsAdObjectSidValueEditorTest
{
@Test
public void testConvertToString1()
{
InPlaceMsAdObjectSidValueEditor editor = new InPlaceMsAdObjectSidValueEditor();
byte[] bytes = new byte[]
{
// 01 01 00 00 00 00 00 05 04 00 00 00
( byte ) 0x01, //
( byte ) 0x01, //
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x05, //
( byte ) 0x04,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00 //
};
String displayValue = editor.convertToString( bytes );
assertEquals( "S-1-5-4", displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToString2()
{
InPlaceMsAdObjectSidValueEditor editor = new InPlaceMsAdObjectSidValueEditor();
byte[] bytes = new byte[]
{
// 01 02 00 00 00 00 00 05 20 00 00 00 25 02 00 00
( byte ) 0x01, //
( byte ) 0x02, //
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x05, //
( byte ) 0x20,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00, //
( byte ) 0x25,
( byte ) 0x02,
( byte ) 0x00,
( byte ) 0x00 //
};
String displayValue = editor.convertToString( bytes );
assertEquals( "S-1-5-32-549", displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToString3()
{
InPlaceMsAdObjectSidValueEditor editor = new InPlaceMsAdObjectSidValueEditor();
byte[] bytes = new byte[]
{
// 01 05 00 00 00 00 00 05 15 00 00 00 af 6e b6 27
// 0c f5 77 a0 a7 10 df 6e f4 01 00 00
( byte ) 0x01, //
( byte ) 0x05, //
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x05, //
( byte ) 0x15,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00, //
( byte ) 0xaf,
( byte ) 0x6e,
( byte ) 0xb6,
( byte ) 0x27, //
( byte ) 0x0c,
( byte ) 0xf5,
( byte ) 0x77,
( byte ) 0xa0, //
( byte ) 0xa7,
( byte ) 0x10,
( byte ) 0xdf,
( byte ) 0x6e, //
( byte ) 0xf4,
( byte ) 0x01,
( byte ) 0x00,
( byte ) 0x00 //
};
String displayValue = editor.convertToString( bytes );
assertEquals( "S-1-5-21-666267311-2692216076-1860112551-500", displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToStringInvalid()
{
InPlaceMsAdObjectSidValueEditor editor = new InPlaceMsAdObjectSidValueEditor();
// test too short
byte[] bytes = new byte[]
{ ( byte ) 0x00 };
String displayValue = editor.convertToString( bytes );
assertEquals( Messages.getString( "InPlaceMsAdObjectSidValueEditor.InvalidSid" ), displayValue ); //$NON-NLS-1$
// test missing sub aurhority byte
byte[] bytes2 = new byte[]
{
// 01 05 00 00 00 00 00 05 15 00 00 00 af 6e b6 27
// 0c f5 77 a0 a7 10 df 6e f4 01 00 00
( byte ) 0x01, //
( byte ) 0x05, //
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x05, //
( byte ) 0x15,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00, //
( byte ) 0xaf,
( byte ) 0x6e,
( byte ) 0xb6,
( byte ) 0x27, //
( byte ) 0x0c,
( byte ) 0xf5,
( byte ) 0x77,
( byte ) 0xa0, //
( byte ) 0xa7,
( byte ) 0x10,
( byte ) 0xdf,
( byte ) 0x6e, //
( byte ) 0xf4,
( byte ) 0x01,
( byte ) 0x00, /*( byte ) 0x00*///
};
String displayValue2 = editor.convertToString( bytes2 );
assertEquals( Messages.getString( "InPlaceMsAdObjectSidValueEditor.InvalidSid" ), displayValue2 ); //$NON-NLS-1$
// test additional sub authority byte
byte[] bytes3 = new byte[]
{
// 01 05 00 00 00 00 00 05 15 00 00 00 af 6e b6 27
// 0c f5 77 a0 a7 10 df 6e f4 01 00 00
( byte ) 0x01, //
( byte ) 0x05, //
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x05, //
( byte ) 0x15,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00, //
( byte ) 0xaf,
( byte ) 0x6e,
( byte ) 0xb6,
( byte ) 0x27, //
( byte ) 0x0c,
( byte ) 0xf5,
( byte ) 0x77,
( byte ) 0xa0, //
( byte ) 0xa7,
( byte ) 0x10,
( byte ) 0xdf,
( byte ) 0x6e, //
( byte ) 0xf4,
( byte ) 0x01,
( byte ) 0x00,
( byte ) 0x00,
( byte ) 0x00 //
};
String displayValue3 = editor.convertToString( bytes3 );
assertEquals( Messages.getString( "InPlaceMsAdObjectSidValueEditor.InvalidSid" ), displayValue3 ); //$NON-NLS-1$
}
@Test
public void testConvertToStringNull()
{
InPlaceMsAdObjectSidValueEditor editor = new InPlaceMsAdObjectSidValueEditor();
byte[] bytes = null;
String displayValue = editor.convertToString( bytes );
assertEquals( Messages.getString( "InPlaceMsAdObjectSidValueEditor.InvalidSid" ), displayValue ); //$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/valueeditors/src/test/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectGuidValueEditorTest.java | plugins/valueeditors/src/test/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectGuidValueEditorTest.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.valueeditors.msad;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.directory.api.util.Strings;
import org.junit.jupiter.api.Test;
public class InPlaceMsAdObjectGuidValueEditorTest
{
@Test
public void testConvertToString1()
{
InPlaceMsAdObjectGuidValueEditor editor = new InPlaceMsAdObjectGuidValueEditor();
byte[] bytes = new byte[]
{
//
( byte ) 0x89,
( byte ) 0xBA,
( byte ) 0x78,
( byte ) 0xDB, //
( byte ) 0x5F,
( byte ) 0xB8, //
( byte ) 0x7F,
( byte ) 0x44, //
( byte ) 0xBD,
( byte ) 0x06, //
( byte ) 0xE3,
( byte ) 0xA4,
( byte ) 0x09,
( byte ) 0x96,
( byte ) 0xA9,
( byte ) 0xA8 };
String displayValue = editor.convertToString( bytes );
assertEquals( Strings.toLowerCaseAscii( "{db78ba89-b85f-447f-bd06-e3a40996a9a8}" ), displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToString2()
{
InPlaceMsAdObjectGuidValueEditor editor = new InPlaceMsAdObjectGuidValueEditor();
byte[] bytes = new byte[]
{
//
( byte ) 0x00,
( byte ) 0x11,
( byte ) 0x22,
( byte ) 0x33, //
( byte ) 0x44,
( byte ) 0x55, //
( byte ) 0x66,
( byte ) 0x77, //
( byte ) 0x88,
( byte ) 0x99, //
( byte ) 0xAA,
( byte ) 0xBB,
( byte ) 0xCC,
( byte ) 0xDD,
( byte ) 0xEE,
( byte ) 0xFF };
String displayValue = editor.convertToString( bytes );
assertEquals( Strings.toLowerCaseAscii( "{33221100-5544-7766-8899-AABBCCDDEEFF}" ), displayValue ); //$NON-NLS-1$
}
@Test
public void testConvertToStringInvalid()
{
InPlaceMsAdObjectGuidValueEditor editor = new InPlaceMsAdObjectGuidValueEditor();
// test too short
byte[] bytes = new byte[]
{ ( byte ) 0x00, ( byte ) 0x11, ( byte ) 0x22, ( byte ) 0x33 };
String displayValue = editor.convertToString( bytes );
assertEquals( Messages.getString( "InPlaceMsAdObjectGuidValueEditor.InvalidGuid" ), displayValue ); //$NON-NLS-1$
// test too long
byte[] bytes2 = new byte[]
{ ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, };
String displayValue2 = editor.convertToString( bytes2 );
assertEquals( Messages.getString( "InPlaceMsAdObjectGuidValueEditor.InvalidGuid" ), displayValue2 ); //$NON-NLS-1$
}
@Test
public void testConvertToStringNull()
{
InPlaceMsAdObjectGuidValueEditor editor = new InPlaceMsAdObjectGuidValueEditor();
byte[] bytes = null;
String displayValue = editor.convertToString( bytes );
assertEquals( Messages.getString( "InPlaceMsAdObjectGuidValueEditor.InvalidGuid" ), displayValue ); //$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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/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.valueeditors;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.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.valueeditors;
/**
* Contains constants for the value editors.
* Final reference -> class shouldn't be extended
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public final class ValueEditorsConstants
{
/**
* 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 ValueEditorsConstants()
{
}
/** The plug-in ID */
public static final String PLUGIN_ID = ValueEditorsConstants.class.getPackage().getName();
/** The relative path to the image editor icon */
public static final String IMG_IMAGEEDITOR = "resources/icons/imageeditor.gif"; //$NON-NLS-1$
/** The relative path to the address editor icon */
public static final String IMG_ADDRESSEDITOR = "resources/icons/addresseditor.gif"; //$NON-NLS-1$
/** The relative path to the Dn editor icon */
public static final String IMG_DNEDITOR = "resources/icons/dneditor.gif"; //$NON-NLS-1$
/** The relative path to the password editor icon */
public static final String IMG_PASSWORDEDITOR = "resources/icons/passwordeditor.gif"; //$NON-NLS-1$
/** The relative path to the generalized time editor icon */
public static final String IMG_GENERALIZEDTIMEEDITOR = "resources/icons/generalizedtimeeditor.gif"; //$NON-NLS-1$
/** The relative path to the object class editor icon */
public static final String IMG_OCDEDITOR = "resources/icons/objectclasseditor.png"; //$NON-NLS-1$
/** The relative path to the integer editor icon */
public static final String IMG_INTEGEREDITOR = "resources/icons/integereditor.gif"; //$NON-NLS-1$
/** The relative path to the administrative role editor icon */
public static final String IMG_ADMINISTRATIVEROLEEDITOR = "resources/icons/administrativeroleeditor.gif"; //$NON-NLS-1$
/** The relative path to the certificate editor icon */
public static final String IMG_CERTIFICATEEDITOR = "resources/icons/certificateeditor.png"; //$NON-NLS-1$
/** The relative path to the text field error icon */
public static final String IMG_TEXTFIELD_ERROR = "resources/icons/textfield_error.png"; //$NON-NLS-1$
/** The relative path to the text field ok icon */
public static final String IMG_TEXTFIELD_OK = "resources/icons/textfield_ok.png"; //$NON-NLS-1$
/** The dialogs settings for the Date Editor "Discard fraction" checkbox */
public static final String DIALOGSETTING_KEY_DATE_EDITOR_DISCARD_FRACTION = "dateEditorDiscardFraction"; //$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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.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.valueeditors;
import java.io.IOException;
import java.net.URL;
import java.util.PropertyResourceBundle;
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.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class ValueEditorsActivator extends AbstractUIPlugin
{
/** The shared instance */
private static ValueEditorsActivator plugin;
/** The plugin properties */
private PropertyResourceBundle properties;
/**
* The constructor
*/
public ValueEditorsActivator()
{
plugin = this;
}
/**
* {@inheritDoc}
*/
public void start( BundleContext context ) throws Exception
{
super.start( context );
}
/**
* {@inheritDoc}
*/
public void stop( BundleContext context ) throws Exception
{
plugin = null;
super.stop( context );
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ValueEditorsActivator getDefault()
{
return plugin;
}
/**
* Use this method to get SWT images. Use the IMG_ constants from
* ValueEditorConstants for the key.
*
* @param key The key (relative path to the image im filesystem)
* @return The image discriptor 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
* ValueEditorConstants 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 im filesystem)
* @return The SWT Image or null
* @see ValueEditorsConstants
*/
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.valueeditors", Status.OK, //$NON-NLS-1$
Messages.getString( "ValueEditorsActivator.UnableGetPluginProperties" ), 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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/address/AddressValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/address/AddressValueEditor.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.valueeditors.address;
import org.apache.commons.text.translate.CharSequenceTranslator;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.41
* (Postal Address). In the displayed value the $ separators are replaced
* by commas. In the opened AddressDialog the $ separators are replaced by
* line breaks.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AddressValueEditor extends AbstractDialogStringValueEditor
{
/** The postal address decoder. */
private CharSequenceTranslator decoder = Utils.createPostalAddressDecoder( ", " ); //$NON-NLS-1$
/**
* {@inheritDoc}
*
* This implementation opens the AddressDialog.
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof String )
{
AddressDialog dialog = new AddressDialog( shell, ( String ) value );
if ( ( dialog.open() == AddressDialog.OK ) && !EMPTY.equals( dialog.getAddress() ) ) //$NON-NLS-1$
{
setValue( dialog.getAddress() );
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*
* This implementation replaces the $ separators by commas.
*/
public String getDisplayValue( IValue value )
{
String displayValue = super.getDisplayValue( value );
if ( !showRawValues() )
{
displayValue = decoder.translate( displayValue );
}
return displayValue;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/address/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/address/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.valueeditors.address;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/address/AddressDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/address/AddressDialog.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.valueeditors.address;
import java.util.regex.Pattern;
import org.apache.commons.text.translate.CharSequenceTranslator;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* The AddressDialog is used from the address value editor to edit an address.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AddressDialog extends Dialog
{
/** The initial address. */
private String initialAddress;
/** The return address. */
private String returnAddress;
/** The text widget. */
private Text text;
/** The postal address decoder. */
private CharSequenceTranslator decoder;
/** The postal address encoder. */
private CharSequenceTranslator encoder;
/** The checkbox to strip trailing whitespace. */
private Button stripWhitespaceCheckbox;
/**
* Creates a new instance of AddressDialog.
*
* @param parentShell the parent shell
* @param initialAddress the initial address
*/
public AddressDialog( Shell parentShell, String initialAddress )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.initialAddress = initialAddress;
this.returnAddress = null;
this.decoder = Utils.createPostalAddressDecoder( BrowserCoreConstants.LINE_SEPARATOR );
this.encoder = Utils.createPostalAddressEncoder( BrowserCoreConstants.LINE_SEPARATOR );
}
/**
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "AddressDialog.AddressEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_ADDRESSEDITOR ) );
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
protected void createButtonsForButtonBar( Composite parent )
{
((GridLayout) parent.getLayout()).numColumns = 2;
stripWhitespaceCheckbox = BaseWidgetUtils.createCheckbox( parent, Messages.getString( "AddressDialog.StripWhitespace" ), 2 ); //$NON-NLS-1$
stripWhitespaceCheckbox.setSelection( true );
createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
}
private static final Pattern TRAILING_WHITESPACE = Pattern.compile( "\\s+$", Pattern.MULTILINE ); //$NON-NLS-1$
/**
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
protected void okPressed()
{
String lines = text.getText();
if ( stripWhitespaceCheckbox.getSelection() ) {
lines = TRAILING_WHITESPACE.matcher(lines).replaceAll( "" ); //$NON-NLS-1$
}
returnAddress = encoder.translate( lines );
super.okPressed();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent )
{
// create composite
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
composite.setLayoutData( gd );
// text widget
text = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL );
text.setText( decoder.translate( initialAddress ) );
// GridData gd = new GridData(GridData.GRAB_HORIZONTAL |
// GridData.HORIZONTAL_ALIGN_FILL);
gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
text.setLayoutData( gd );
applyDialogFont( composite );
return composite;
}
/**
* Gets the address.
*
* @return the address
*/
public String getAddress()
{
return returnAddress;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/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.valueeditors.password;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordDialog.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.valueeditors.password;
import org.apache.directory.api.ldap.model.constants.LdapSecurityConstants;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
import org.apache.directory.studio.connection.core.jobs.CheckBindRunnable;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.apache.directory.studio.connection.ui.RunnableContextRunner;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
import org.apache.directory.studio.ldapbrowser.core.model.Password;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
/**
* The PasswordDialog is used from the password value editor to view the current password
* and to enter a new password.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PasswordDialog extends Dialog
{
/** The constant for no hash method */
private static final String NO_HASH_METHOD = "NO-HASH-METHOD";
/** The supported hash methods */
private static final Object[] HASH_METHODS =
{
LdapSecurityConstants.HASH_METHOD_SHA,
LdapSecurityConstants.HASH_METHOD_SHA256,
LdapSecurityConstants.HASH_METHOD_SHA384,
LdapSecurityConstants.HASH_METHOD_SHA512,
LdapSecurityConstants.HASH_METHOD_SSHA,
LdapSecurityConstants.HASH_METHOD_SSHA256,
LdapSecurityConstants.HASH_METHOD_SSHA384,
LdapSecurityConstants.HASH_METHOD_SSHA512,
LdapSecurityConstants.HASH_METHOD_MD5,
LdapSecurityConstants.HASH_METHOD_SMD5,
LdapSecurityConstants.HASH_METHOD_PKCS5S2,
LdapSecurityConstants.HASH_METHOD_CRYPT,
LdapSecurityConstants.HASH_METHOD_CRYPT_MD5,
LdapSecurityConstants.HASH_METHOD_CRYPT_SHA256,
LdapSecurityConstants.HASH_METHOD_CRYPT_SHA512,
NO_HASH_METHOD };
/** Constant for the Current Password tab */
private static final int CURRENT_TAB = 0;
/** Constant for the New Password tab */
private static final int NEW_TAB = 1;
/** Constant for the selected tab dialog settings key */
private static final String SELECTED_TAB_DIALOGSETTINGS_KEY = PasswordDialog.class.getName() + ".tab"; //$NON-NLS-1$
/** Constant for the selected hash method dialog settings key */
private static final String SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY = PasswordDialog.class.getName()
+ ".hashMethod"; //$NON-NLS-1$
/** The display mode */
private DisplayMode displayMode;
/** The associated entry for binding */
private IEntry entry;
/** The current password */
private Password currentPassword;
/** The new password */
private Password newPassword;
/** The return password */
private byte[] returnPassword;
// UI widgets
private Button okButton;
private TabFolder tabFolder;
private TabItem currentPasswordTab;
private Composite currentPasswordComposite;
private Text currentPasswordText;
private Text currentPasswordHashMethodText;
private Text currentPasswordValueHexText;
private Text currentPasswordSaltHexText;
private Button showCurrentPasswordDetailsButton;
private Text testPasswordText;
private Text testBindDnText;
private Button showTestPasswordDetailsButton;
private Button verifyPasswordButton;
private Button bindPasswordButton;
private TabItem newPasswordTab;
private Composite newPasswordComposite;
private Text newPasswordText;
private Text confirmNewPasswordText;
private ComboViewer newPasswordHashMethodComboViewer;
private Text newPasswordPreviewText;
private Text newPasswordPreviewValueHexText;
private Text newPasswordPreviewSaltHexText;
private Button newSaltButton;
private Button showNewPasswordDetailsButton;
/**
* Creates a new instance of PasswordDialog.
*
* @param parentShell the parent shell
* @param currentPassword the current password, null if none
* @param entry the entry used to bind
*/
public PasswordDialog( Shell parentShell, byte[] currentPassword, IEntry entry )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
try
{
this.currentPassword = currentPassword != null ? new Password( currentPassword ) : null;
}
catch ( IllegalArgumentException e )
{
}
this.entry = entry;
this.returnPassword = null;
}
/**
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "PasswordDialog.PasswordEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_PASSWORDEDITOR ) );
}
/**
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
protected void okPressed()
{
// create password
if ( newPassword != null )
{
returnPassword = newPassword.toBytes();
}
else
{
returnPassword = null;
}
// save selected hash method to dialog settings, selected tab will be
// saved on close()
LdapSecurityConstants selectedHashMethod = getSelectedNewPasswordHashMethod();
if ( selectedHashMethod == null )
{
ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY,
NO_HASH_METHOD );
}
else
{
ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY,
selectedHashMethod.getName() );
}
super.okPressed();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#close()
*/
public boolean close()
{
// save selected tab to dialog settings
ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_TAB_DIALOGSETTINGS_KEY,
tabFolder.getSelectionIndex() );
return super.close();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
protected void createButtonsForButtonBar( Composite parent )
{
okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
// load dialog settings
try
{
int tabIndex = ValueEditorsActivator.getDefault().getDialogSettings().getInt(
SELECTED_TAB_DIALOGSETTINGS_KEY );
if ( currentPassword == null || currentPassword.toBytes().length == 0 )
{
tabIndex = NEW_TAB;
}
tabFolder.setSelection( tabIndex );
}
catch ( Exception e )
{
}
try
{
String hashMethodName = ValueEditorsActivator.getDefault().getDialogSettings().get(
SELECTED_HASH_METHOD_DIALOGSETTINGS_KEY );
LdapSecurityConstants hashMethod = LdapSecurityConstants.getAlgorithm( hashMethodName );
if ( ( hashMethod == null ) || NO_HASH_METHOD.equals( hashMethodName ) )
{
newPasswordHashMethodComboViewer.setSelection( new StructuredSelection( NO_HASH_METHOD ) );
}
else
{
newPasswordHashMethodComboViewer.setSelection( new StructuredSelection( hashMethod ) );
}
}
catch ( Exception e )
{
}
// update on load
updateTabFolder();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent )
{
// Composite
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 3 / 2;
gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 2 / 3;
composite.setLayoutData( gd );
// Tab folder
tabFolder = new TabFolder( composite, SWT.TOP );
tabFolder.setLayoutData( new GridData( GridData.FILL_BOTH ) );
tabFolder.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
updateTabFolder();
}
} );
// Checking the current password
if ( currentPassword != null && currentPassword.toBytes().length > 0 )
{
// Setting the display mode
displayMode = DisplayMode.CURRENT_AND_NEW_PASSWORD;
// Creating the current password tab
createCurrentPasswordTab();
}
else
{
// Setting the display mode
displayMode = DisplayMode.NEW_PASSWORD_ONLY;
}
// Creating the new password tab
createNewPasswordTab();
addListeners();
applyDialogFont( composite );
return composite;
}
/**
* Creates the current password tab.
*/
private void createCurrentPasswordTab()
{
// Current password composite
currentPasswordComposite = new Composite( tabFolder, SWT.NONE );
GridLayout currentLayout = new GridLayout( 2, false );
currentLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
currentLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
currentLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
currentLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
currentPasswordComposite.setLayout( currentLayout );
currentPasswordComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
// Current password text
BaseWidgetUtils.createLabel( currentPasswordComposite, Messages
.getString( "PasswordDialog.CurrentPassword" ) + ":", 1 ); //$NON-NLS-1$//$NON-NLS-2$
currentPasswordText = BaseWidgetUtils.createReadonlyText( currentPasswordComposite, "", 1 ); //$NON-NLS-1$
// Current password details composite
new Label( currentPasswordComposite, SWT.NONE );
Composite currentPasswordDetailsComposite = BaseWidgetUtils.createColumnContainer( currentPasswordComposite,
2, 1 );
// Current password hash method label
BaseWidgetUtils.createLabel( currentPasswordDetailsComposite,
Messages.getString( "PasswordDialog.HashMethod" ), 1 ); //$NON-NLS-1$
currentPasswordHashMethodText = BaseWidgetUtils.createLabeledText( currentPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Current password hex label
BaseWidgetUtils.createLabel( currentPasswordDetailsComposite, Messages
.getString( "PasswordDialog.PasswordHex" ), 1 ); //$NON-NLS-1$
currentPasswordValueHexText = BaseWidgetUtils.createLabeledText( currentPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Current password salt hex label
BaseWidgetUtils.createLabel( currentPasswordDetailsComposite,
Messages.getString( "PasswordDialog.SaltHex" ), 1 ); //$NON-NLS-1$
currentPasswordSaltHexText = BaseWidgetUtils.createLabeledText( currentPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Show current password details button
showCurrentPasswordDetailsButton = BaseWidgetUtils.createCheckbox( currentPasswordDetailsComposite, Messages
.getString( "PasswordDialog.ShowCurrentPasswordDetails" ), 2 ); //$NON-NLS-1$
// Verify password text
BaseWidgetUtils
.createLabel( currentPasswordComposite, Messages.getString( "PasswordDialog.VerifyPassword" ), 1 ); //$NON-NLS-1$
testPasswordText = BaseWidgetUtils.createText( currentPasswordComposite, "", 1 ); //$NON-NLS-1$
// Verify password details composite
new Label( currentPasswordComposite, SWT.NONE );
Composite testPasswordDetailsComposite = BaseWidgetUtils.createColumnContainer( currentPasswordComposite, 2,
1 );
// Bind DN label
BaseWidgetUtils.createLabel( testPasswordDetailsComposite, Messages.getString( "PasswordDialog.BindDn" ), 1 ); //$NON-NLS-1$
testBindDnText = BaseWidgetUtils.createLabeledText( testPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Show verify password details button
showTestPasswordDetailsButton = BaseWidgetUtils.createCheckbox( testPasswordDetailsComposite, Messages
.getString( "PasswordDialog.ShowTestPasswordDetails" ), 2 ); //$NON-NLS-1$
// Verify password buttons composite
new Label( currentPasswordComposite, SWT.NONE );
Composite verifyPasswordButtonsComposite = BaseWidgetUtils.createColumnContainer( currentPasswordComposite,
2, 1 );
// Verify button
verifyPasswordButton = BaseWidgetUtils.createButton( verifyPasswordButtonsComposite, Messages
.getString( "PasswordDialog.Verify" ), 1 ); //$NON-NLS-1$
verifyPasswordButton.setEnabled( false );
// Bind button
bindPasswordButton = BaseWidgetUtils.createButton( verifyPasswordButtonsComposite, Messages
.getString( "PasswordDialog.Bind" ), 1 ); //$NON-NLS-1$
bindPasswordButton.setEnabled( false );
// Current password tab
currentPasswordTab = new TabItem( tabFolder, SWT.NONE );
currentPasswordTab.setText( Messages.getString( "PasswordDialog.CurrentPassword" ) ); //$NON-NLS-1$
currentPasswordTab.setControl( currentPasswordComposite );
}
/**
* Creates the new password tab.
*/
private void createNewPasswordTab()
{
// New password composite
newPasswordComposite = new Composite( tabFolder, SWT.NONE );
GridLayout newLayout = new GridLayout( 2, false );
newLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
newLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
newLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
newLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
newPasswordComposite.setLayout( newLayout );
// New password text
BaseWidgetUtils.createLabel( newPasswordComposite, Messages.getString( "PasswordDialog.EnterNewPassword" ), 1 ); //$NON-NLS-1$
newPasswordText = BaseWidgetUtils.createText( newPasswordComposite, "", 1 ); //$NON-NLS-1$
// Confirm new password text
BaseWidgetUtils
.createLabel( newPasswordComposite, Messages.getString( "PasswordDialog.ConfirmNewPassword" ), 1 ); //$NON-NLS-1$
confirmNewPasswordText = BaseWidgetUtils.createText( newPasswordComposite, "", 1 ); //$NON-NLS-1$
// New password hashing method combo
BaseWidgetUtils.createLabel( newPasswordComposite, Messages.getString( "PasswordDialog.SelectHashMethod" ), 1 ); //$NON-NLS-1$
newPasswordHashMethodComboViewer = new ComboViewer( newPasswordComposite );
newPasswordHashMethodComboViewer.setContentProvider( new ArrayContentProvider() );
newPasswordHashMethodComboViewer.setLabelProvider( new LabelProvider()
{
public String getText( Object element )
{
String hashMethod = getHashMethodName( element );
if ( !"".equals( hashMethod ) )
{
return hashMethod;
}
return super.getText( element );
}
} );
newPasswordHashMethodComboViewer.setInput( HASH_METHODS );
newPasswordHashMethodComboViewer.getControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
// New password preview text
BaseWidgetUtils.createLabel( newPasswordComposite, Messages.getString( "PasswordDialog.PasswordPreview" ), 1 ); //$NON-NLS-1$
newPasswordPreviewText = BaseWidgetUtils.createReadonlyText( newPasswordComposite, "", 1 ); //$NON-NLS-1$
// New salt button
newSaltButton = BaseWidgetUtils.createButton( newPasswordComposite, Messages
.getString( "PasswordDialog.NewSalt" ), 1 ); //$NON-NLS-1$
newSaltButton.setLayoutData( new GridData() );
newSaltButton.setEnabled( false );
// New password preview details composite
Composite newPasswordPreviewDetailsComposite = BaseWidgetUtils.createColumnContainer( newPasswordComposite, 2,
1 );
// New password preview hex label
BaseWidgetUtils.createLabel( newPasswordPreviewDetailsComposite,
Messages.getString( "PasswordDialog.PasswordHex" ), 1 ); //$NON-NLS-1$
newPasswordPreviewValueHexText = BaseWidgetUtils.createLabeledText( newPasswordPreviewDetailsComposite, ":", 1 ); //$NON-NLS-1$
// New password preview salt hex label
BaseWidgetUtils.createLabel( newPasswordPreviewDetailsComposite,
Messages.getString( "PasswordDialog.SaltHex" ), 1 ); //$NON-NLS-1$
newPasswordPreviewSaltHexText = BaseWidgetUtils.createLabeledText( newPasswordPreviewDetailsComposite, "", 1 ); //$NON-NLS-1$
// Show new password details button
showNewPasswordDetailsButton = BaseWidgetUtils.createCheckbox( newPasswordPreviewDetailsComposite, Messages
.getString( "PasswordDialog.ShowNewPasswordDetails" ), 2 ); //$NON-NLS-1$
// New password tab
newPasswordTab = new TabItem( tabFolder, SWT.NONE );
newPasswordTab.setText( Messages.getString( "PasswordDialog.NewPassword" ) ); //$NON-NLS-1$
newPasswordTab.setControl( newPasswordComposite );
}
/**
* Adds the listeners.
*/
private void addListeners()
{
if ( displayMode == DisplayMode.CURRENT_AND_NEW_PASSWORD )
{
showCurrentPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent arg0 )
{
updateCurrentPasswordGroup();
}
} );
testPasswordText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateCurrentPasswordGroup();
}
} );
showTestPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent arg0 )
{
updateCurrentPasswordGroup();
}
} );
verifyPasswordButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
verifyCurrentPassword();
}
} );
bindPasswordButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
bindCurrentPassword();
}
} );
}
newPasswordText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateNewPasswordGroup();
}
} );
confirmNewPasswordText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateNewPasswordGroup();
}
} );
newPasswordHashMethodComboViewer.addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
updateNewPasswordGroup();
}
} );
newSaltButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
updateNewPasswordGroup();
}
} );
showNewPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent arg0 )
{
updateNewPasswordGroup();
}
} );
}
/**
* Updates the current password tab.
*/
private void updateCurrentPasswordGroup()
{
// set current password to the UI widgets
if ( currentPassword != null )
{
currentPasswordHashMethodText.setText( getCurrentPasswordHashMethodName() );
currentPasswordValueHexText.setText( Utils
.getNonNullString( currentPassword.getHashedPasswordAsHexString() ) );
currentPasswordSaltHexText.setText( Utils.getNonNullString( currentPassword.getSaltAsHexString() ) );
currentPasswordText.setText( currentPassword.toString() );
}
// show password details?
if ( showCurrentPasswordDetailsButton.getSelection() )
{
currentPasswordText.setEchoChar( '\0' );
currentPasswordValueHexText.setEchoChar( '\0' );
currentPasswordSaltHexText.setEchoChar( '\0' );
}
else
{
currentPasswordText.setEchoChar( '\u2022' );
currentPasswordValueHexText.setEchoChar( '\u2022' );
currentPasswordSaltHexText.setEchoChar( currentPasswordSaltHexText.getText().equals(
Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
}
// enable/disable test field and buttons
testPasswordText.setEnabled( currentPassword != null && currentPassword.getHashedPassword() != null
&& currentPassword.toBytes().length > 0 );
testBindDnText.setText( entry != null ? entry.getDn().getName() : Utils.getNonNullString( null ) );
if ( showTestPasswordDetailsButton.getSelection() )
{
testPasswordText.setEchoChar( '\0' );
}
else
{
testPasswordText.setEchoChar( '\u2022' );
}
verifyPasswordButton.setEnabled( testPasswordText.isEnabled() && !"".equals( testPasswordText.getText() ) ); //$NON-NLS-1$
bindPasswordButton.setEnabled( testPasswordText.isEnabled() && !"".equals( testPasswordText.getText() ) //$NON-NLS-1$
&& entry != null && entry.getBrowserConnection().getConnection() != null );
// default dialog button
if ( verifyPasswordButton.isEnabled() )
{
getShell().setDefaultButton( verifyPasswordButton );
}
else
{
getShell().setDefaultButton( okButton );
}
okButton.setEnabled( false );
}
/**
* Verifies the current password.
*/
private void verifyCurrentPassword()
{
String testPassword = testPasswordText.getText();
if ( currentPassword != null )
{
if ( currentPassword.verify( testPassword ) )
{
MessageDialog dialog = new MessageDialog(
getShell(),
Messages.getString( "PasswordDialog.PasswordVerification" ), getShell().getImage(), //$NON-NLS-1$
Messages.getString( "PasswordDialog.PasswordVerifiedSuccessfully" ), MessageDialog.INFORMATION, new String[] //$NON-NLS-1$
{ IDialogConstants.OK_LABEL }, 0 );
dialog.open();
}
else
{
IStatus status = new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, 1,
Messages.getString( "PasswordDialog.PasswordVerificationFailed" ), null ); //$NON-NLS-1$
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( status );
}
}
}
/**
* Binds to the directory using the test password.
*/
private void bindCurrentPassword()
{
if ( !"".equals( testPasswordText.getText() ) && entry != null //$NON-NLS-1$
&& entry.getBrowserConnection().getConnection() != null )
{
Connection connection = ( Connection ) entry.getBrowserConnection().getConnection().clone();
connection.getConnectionParameter().setName( null );
connection.getConnectionParameter().setBindPrincipal( entry.getDn().getName() );
connection.getConnectionParameter().setBindPassword( testPasswordText.getText() );
connection.getConnectionParameter().setAuthMethod( AuthenticationMethod.SIMPLE );
CheckBindRunnable runnable = new CheckBindRunnable( connection );
IStatus status = RunnableContextRunner.execute( runnable, null, true );
if ( status.isOK() )
{
MessageDialog.openInformation( Display.getDefault().getActiveShell(), Messages
.getString( "PasswordDialog.CheckAuthentication" ), //$NON-NLS-1$
Messages.getString( "PasswordDialog.AuthenticationSuccessful" ) ); //$NON-NLS-1$
}
}
}
/**
* Updates the new password tab.
*/
private void updateNewPasswordGroup()
{
// set new password to the UI widgets
newPassword = new Password( getSelectedNewPasswordHashMethod(), newPasswordText.getText() );
if ( !"".equals( newPasswordText.getText() ) //$NON-NLS-1$
&& newPasswordText.getText().equals( confirmNewPasswordText.getText() ) )
{
newPasswordPreviewValueHexText
.setText( Utils.getNonNullString( newPassword.getHashedPasswordAsHexString() ) );
newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( newPassword.getSaltAsHexString() ) );
newPasswordPreviewText.setText( newPassword.toString() );
newSaltButton.setEnabled( newPassword.getSalt() != null );
okButton.setEnabled( true );
getShell().setDefaultButton( okButton );
}
else
{
newPassword = null;
newPasswordPreviewValueHexText.setText( Utils.getNonNullString( null ) );
newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( null ) );
newPasswordPreviewText.setText( Utils.getNonNullString( null ) );
newSaltButton.setEnabled( false );
okButton.setEnabled( false );
}
// show password details?
if ( showNewPasswordDetailsButton.getSelection() )
{
newPasswordText.setEchoChar( '\0' );
confirmNewPasswordText.setEchoChar( '\0' );
newPasswordPreviewText.setEchoChar( '\0' );
newPasswordPreviewValueHexText.setEchoChar( '\0' );
newPasswordPreviewSaltHexText.setEchoChar( '\0' );
}
else
{
newPasswordText.setEchoChar( '\u2022' );
confirmNewPasswordText.setEchoChar( '\u2022' );
newPasswordPreviewText.setEchoChar( newPasswordPreviewText.getText()
.equals( Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
newPasswordPreviewValueHexText.setEchoChar( newPasswordPreviewValueHexText.getText().equals(
Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
newPasswordPreviewSaltHexText.setEchoChar( newPasswordPreviewSaltHexText.getText().equals(
Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
}
}
/**
* Updates the tab folder and the tabs.
*/
private void updateTabFolder()
{
if ( testPasswordText != null && newPasswordText != null )
{
if ( tabFolder.getSelectionIndex() == CURRENT_TAB )
{
updateCurrentPasswordGroup();
testPasswordText.setFocus();
}
else if ( tabFolder.getSelectionIndex() == NEW_TAB )
{
updateNewPasswordGroup();
newPasswordText.setFocus();
}
}
}
/**
* Gets the selected new password hash method.
*
* @return the selected new password hash method
*/
private LdapSecurityConstants getSelectedNewPasswordHashMethod()
{
StructuredSelection selection = ( StructuredSelection ) newPasswordHashMethodComboViewer.getSelection();
if ( !selection.isEmpty() )
{
Object selectedObject = selection.getFirstElement();
if ( selectedObject instanceof LdapSecurityConstants )
{
return ( LdapSecurityConstants ) selectedObject;
}
}
return null;
}
/**
* Gets the name of the hash method.
*
* @param o the hash method object
* @return the name of the hash method
*/
private String getHashMethodName( Object o )
{
if ( o instanceof LdapSecurityConstants )
{
LdapSecurityConstants hashMethod = ( LdapSecurityConstants ) o;
return hashMethod.getName();
}
else if ( ( o instanceof String ) && NO_HASH_METHOD.equals( o ) )
{
return BrowserCoreMessages.model__no_hash;
}
return null;
}
/**
* Gets the current password hash method name.
*
* @return the current password hash method name
*/
private String getCurrentPasswordHashMethodName()
{
LdapSecurityConstants hashMethod = currentPassword.getHashMethod();
if ( hashMethod != null )
{
return Utils.getNonNullString( getHashMethodName( hashMethod ) );
}
else
{
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | true |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/password/PasswordValueEditor.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.valueeditors.password;
import org.apache.directory.api.ldap.model.constants.LdapSecurityConstants;
import org.apache.directory.api.ldap.model.password.PasswordUtil;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
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.apache.directory.studio.valueeditors.AbstractDialogBinaryValueEditor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for attribute userPassword.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PasswordValueEditor extends AbstractDialogBinaryValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the PasswordDialog.
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof PasswordValueEditorRawValueWrapper )
{
PasswordValueEditorRawValueWrapper wrapper = ( PasswordValueEditorRawValueWrapper ) value;
if ( wrapper.password instanceof byte[] )
{
byte[] pw = ( byte[] ) wrapper.password;
PasswordDialog dialog = new PasswordDialog( shell, pw, wrapper.entry );
if ( dialog.open() == TextDialog.OK )
{
setValue( dialog.getNewPassword() );
return true;
}
}
}
return false;
}
/**
* {@inheritDoc}
*
* This implementation returns information about the
* used hash algorithm. The value stored in directory
* is only display when the showRawValues option is
* active.
*/
public String getDisplayValue( IValue value )
{
if ( showRawValues() )
{
return getPrintableString( value );
}
else
{
if ( value == null )
{
return NULL; //$NON-NLS-1$
}
String password = value.getStringValue();
if ( password == null )
{
return NULL; //$NON-NLS-1$
}
else
{
String text;
if ( EMPTY.equals( password ) ) //$NON-NLS-1$
{
text = Messages.getString( "PasswordValueEditor.EmptyPassword" ); //$NON-NLS-1$
}
else if ( ( password.indexOf( '{' ) == 0 )&& ( password.indexOf( '}' ) > 0 ) )
{
text = NLS.bind(
Messages.getString( "PasswordValueEditor.HashedPassword" ), getHashMethodName( password ) ); //$NON-NLS-1$
}
else
{
text = Messages.getString( "PasswordValueEditor.PlainTextPassword" ); //$NON-NLS-1$
}
return text;
}
}
}
/**
* Gets the name of the hash method.
*
* @param s the hash method string
* @return the name of the associated hash method or the given string
*/
private String getHashMethodName( String s )
{
LdapSecurityConstants hashMethod = PasswordUtil.findAlgorithm( Strings.getBytesUtf8( s ) );
if ( hashMethod != null )
{
return hashMethod.getName();
}
return s;
}
/**
* {@inheritDoc}
*
* Returns a PasswordValueEditorRawValueWrapper with empty
* password.
*/
protected Object getEmptyRawValue( IAttribute attribute )
{
return new PasswordValueEditorRawValueWrapper( new byte[0], attribute.getEntry() );
}
/**
* {@inheritDoc}
*
* Returns a PasswordValueEditorRawValueWrapper.
*/
public Object getRawValue( IValue value )
{
Object password = super.getRawValue( value );
return new PasswordValueEditorRawValueWrapper( password, value.getAttribute().getEntry() );
}
/**
* The PasswordValueEditorRawValueWrapper is used to pass contextual
* information to the opened PasswordDialog.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
private class PasswordValueEditorRawValueWrapper
{
/** The password, used as initial value in PasswordDialog */
private Object password;
/** The entry, used for the bind operation in PasswordDialog */
private IEntry entry;
/**
* Creates a new instance of PasswordValueEditorRawValueWrapper.
*
* @param password the password
* @param entry the entry
*/
private PasswordValueEditorRawValueWrapper( Object password, IEntry entry )
{
this.password = password;
this.entry = entry;
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.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.valueeditors.image;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractDialogBinaryValueEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.28
* (JPEG).
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ImageValueEditor extends AbstractDialogBinaryValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the ImageDialog.
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof byte[] )
{
byte[] currentImageData = ( byte[] ) value;
ImageDialog dialog = new ImageDialog( shell, currentImageData, SWT.IMAGE_JPEG );
if ( ( dialog.open() == ImageDialog.OK ) && ( dialog.getNewImageRawData() != null ) )
{
setValue( dialog.getNewImageRawData() );
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*
* Returns the image info text created by
* ImageDialog.getImageInfo().
*/
public String getDisplayValue( IValue value )
{
if ( showRawValues() )
{
return getPrintableString( value );
}
else
{
if ( value == null )
{
return NULL;
}
else if ( value.isBinary() )
{
byte[] data = value.getBinaryValue();
String text = ImageDialog.getImageInfo( data );
return text;
}
else
{
return Messages.getString( "ImageValueEditor.InvalidImageData" ); //$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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.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.valueeditors.image;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.apache.directory.studio.valueeditors.IValueEditor;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
/**
* The ImageDialog is used from the image value editor to view the current image
* and to select a new image.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ImageDialog extends Dialog
{
/** The dialog setting key for the currently selected tab item */
private static final String SELECTED_TAB_DIALOGSETTINGS_KEY = ImageDialog.class.getName() + ".tab"; //$NON-NLS-1$
/** The maximum width for the image */
private static final int MAX_WIDTH = 400;
/** The maximum height for the image */
private static final int MAX_HEIGHT = 400;
/** The current image tab item */
private static final int CURRENT_TAB = 0;
/** The new image tab item */
private static final int NEW_TAB = 1;
/** The current image bytes */
private byte[] currentImageRawData;
/** The required image type */
private int requiredImageType;
/** The new image bytes */
private byte[] newImageRawData;
/** The new image bytes in the required image format */
private byte[] newImageRawDataInRequiredFormat;
// UI widgets
private TabFolder tabFolder;
private TabItem currentTab;
private Composite currentImageContainer;
private Image currentImage;
private Label currentImageLabel;
private Text currentImageTypeText;
private Text currentImageWidthText;
private Text currentImageHeightText;
private Text currentImageSizeText;
private Button currentImageSaveButton;
private TabItem newTab;
private Composite newImageContainer;
private Image newImage;
private Label newImageLabel;
private Text newImageTypeText;
private Text newImageWidthText;
private Text newImageHeightText;
private Text newImageSizeText;
private Text newImageFilenameText;
private Button newImageBrowseButton;
private Button okButton;
/**
* Creates a new instance of ImageDialog.
*
* @param parentShell the parent shell
* @param currentImageRawData the current image raw data
* @param requiredImageType the required image type
*/
public ImageDialog( Shell parentShell, byte[] currentImageRawData, int requiredImageType )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.currentImageRawData = currentImageRawData;
this.requiredImageType = requiredImageType;
newImageRawDataInRequiredFormat = null;
}
/**
* @see org.eclipse.jface.dialogs.Dialog#close()
*/
public boolean close()
{
// Disposing the current image
if ( ( currentImage != null ) && !currentImage.isDisposed() )
{
currentImage.dispose();
}
// Disposing the new image
if ( ( newImage != null ) && !newImage.isDisposed() )
{
newImage.dispose();
}
// Saving the selected tab item to dialog settings
ValueEditorsActivator.getDefault().getDialogSettings().put( SELECTED_TAB_DIALOGSETTINGS_KEY,
tabFolder.getSelectionIndex() );
return super.close();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
*/
protected void buttonPressed( int buttonId )
{
if ( buttonId == IDialogConstants.OK_ID )
{
if ( newImageRawData != null )
{
// Preparing the new image bytes for the required format
try
{
ImageData imageData = new ImageData( new ByteArrayInputStream( newImageRawData ) );
if ( imageData.type != requiredImageType )
{
// Converting the new image in the required format
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[]
{ imageData };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageLoader.save( baos, requiredImageType );
newImageRawDataInRequiredFormat = baos.toByteArray();
}
else
{
// Directly using the new image bytes
newImageRawDataInRequiredFormat = newImageRawData;
}
}
catch ( SWTException swte )
{
newImageRawDataInRequiredFormat = null;
}
}
}
else
{
newImageRawDataInRequiredFormat = null;
}
super.buttonPressed( buttonId );
}
/**
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "ImageDialog.ImageEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_IMAGEEDITOR ) );
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
protected void createButtonsForButtonBar( Composite parent )
{
okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
// load dialog settings
try
{
int tabIndex = ValueEditorsActivator.getDefault().getDialogSettings().getInt(
SELECTED_TAB_DIALOGSETTINGS_KEY );
tabFolder.setSelection( tabIndex );
}
catch ( Exception e )
{
// Nothing to do
}
// Updating the tab folder on load
updateTabFolder();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
tabFolder = new TabFolder( composite, SWT.TOP );
tabFolder.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
tabFolder.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
updateTabFolder();
}
} );
// current image
if ( currentImageRawData != null && currentImageRawData.length > 0 )
{
currentTab = new TabItem( tabFolder, SWT.NONE );
currentTab.setText( Messages.getString( "ImageDialog.CurrentImage" ) ); //$NON-NLS-1$
currentImageContainer = createTabItemComposite();
currentImageLabel = createImageLabel( currentImageContainer );
Composite currentImageInfoContainer = createImageInfoContainer( currentImageContainer );
currentImageTypeText = createImageInfo( currentImageInfoContainer, Messages
.getString( "ImageDialog.ImageType" ) ); //$NON-NLS-1$
currentImageSizeText = createImageInfo( currentImageInfoContainer, Messages
.getString( "ImageDialog.ImageSize" ) ); //$NON-NLS-1$
currentImageWidthText = createImageInfo( currentImageInfoContainer, Messages
.getString( "ImageDialog.ImageWidth" ) ); //$NON-NLS-1$
currentImageHeightText = createImageInfo( currentImageInfoContainer, Messages
.getString( "ImageDialog.ImageHeight" ) ); //$NON-NLS-1$
Composite currentImageSaveContainer = createImageInfoContainer( currentImageContainer );
Label dummyLabel = BaseWidgetUtils.createLabel( currentImageSaveContainer, "", 1 ); //$NON-NLS-1$
GridData gd = new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL );
dummyLabel.setLayoutData( gd );
currentImageSaveButton = createButton( currentImageSaveContainer, Messages.getString( "ImageDialog.Save" ) ); //$NON-NLS-1$
currentImageSaveButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
FileDialog fileDialog = new FileDialog( ImageDialog.this.getShell(), SWT.SAVE );
fileDialog.setText( Messages.getString( "ImageDialog.SaveImage" ) ); //$NON-NLS-1$
fileDialog.setFilterExtensions( new String[]
{ "*.jpg" } ); //$NON-NLS-1$
String returnedFileName = fileDialog.open();
if ( returnedFileName != null )
{
try
{
File file = new File( returnedFileName );
FileOutputStream out = new FileOutputStream( file );
out.write( currentImageRawData );
out.flush();
out.close();
}
catch ( FileNotFoundException e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages
.getString( "ImageDialog.CantWriteFile" ), e ) ); //$NON-NLS-1$
}
catch ( IOException e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages
.getString( "ImageDialog.CantWriteFile" ), e ) ); //$NON-NLS-1$
}
}
}
} );
currentTab.setControl( currentImageContainer );
}
// new image
newTab = new TabItem( tabFolder, SWT.NONE );
newTab.setText( Messages.getString( "ImageDialog.NewImage" ) ); //$NON-NLS-1$
newImageContainer = createTabItemComposite();
newImageLabel = createImageLabel( newImageContainer );
Composite newImageInfoContainer = createImageInfoContainer( newImageContainer );
newImageTypeText = createImageInfo( newImageInfoContainer, Messages.getString( "ImageDialog.ImageType" ) ); //$NON-NLS-1$
newImageSizeText = createImageInfo( newImageInfoContainer, Messages.getString( "ImageDialog.ImageSize" ) ); //$NON-NLS-1$
newImageWidthText = createImageInfo( newImageInfoContainer, Messages.getString( "ImageDialog.ImageWidth" ) ); //$NON-NLS-1$
newImageHeightText = createImageInfo( newImageInfoContainer, Messages.getString( "ImageDialog.ImageHeight" ) ); //$NON-NLS-1$
Composite newImageSelectContainer = createImageInfoContainer( newImageContainer );
newImageFilenameText = new Text( newImageSelectContainer, SWT.SINGLE | SWT.BORDER );
GridData gd = new GridData( SWT.FILL, SWT.CENTER, true, false );
newImageFilenameText.setLayoutData( gd );
newImageFilenameText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateNewImageGroup();
}
} );
newImageBrowseButton = createButton( newImageSelectContainer, Messages.getString( "ImageDialog.Browse" ) ); //$NON-NLS-1$
newImageBrowseButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
FileDialog fileDialog = new FileDialog( ImageDialog.this.getShell(), SWT.OPEN );
fileDialog.setText( Messages.getString( "ImageDialog.SelectImage" ) ); //$NON-NLS-1$
fileDialog.setFileName( new File( newImageFilenameText.getText() ).getName() );
fileDialog.setFilterPath( new File( newImageFilenameText.getText() ).getParent() );
String returnedFileName = fileDialog.open();
if ( returnedFileName != null )
{
newImageFilenameText.setText( returnedFileName );
}
}
} );
newTab.setControl( newImageContainer );
applyDialogFont( composite );
return composite;
}
/**
* Creates a tab item composite.
*
* @return a tab item composite
*/
private Composite createTabItemComposite()
{
Composite composite = new Composite( tabFolder, SWT.NONE );
GridLayout compositeLayout = new GridLayout( 1, false );
compositeLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
compositeLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
compositeLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
compositeLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
composite.setLayout( compositeLayout );
composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
return composite;
}
/**
* Creates the image label.
*
* @param parent the parent
* @return the image label
*/
private Label createImageLabel( Composite parent )
{
Composite labelComposite = new Composite( parent, SWT.BORDER );
labelComposite.setLayout( new GridLayout() );
GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
labelComposite.setLayoutData( gd );
labelComposite.setBackground( getShell().getDisplay().getSystemColor( SWT.COLOR_WIDGET_NORMAL_SHADOW ) );
Label imageLabel = new Label( labelComposite, SWT.CENTER );
gd = new GridData( SWT.CENTER, SWT.CENTER, true, true );
imageLabel.setLayoutData( gd );
return imageLabel;
}
/**
* Update current image tab.
*/
private void updateCurrentImageGroup()
{
if ( currentTab != null )
{
if ( ( currentImage != null ) && !currentImage.isDisposed() )
{
currentImage.dispose();
currentImage = null;
}
if ( currentImageRawData != null && currentImageRawData.length > 0 )
{
try
{
ImageData imageData = new ImageData( new ByteArrayInputStream( currentImageRawData ) );
currentImage = new Image( getShell().getDisplay(), resizeImage( imageData ) );
currentImageLabel.setText( "" ); //$NON-NLS-1$
currentImageLabel.setImage( currentImage );
GridData currentImageLabelGridData = new GridData( SWT.CENTER, SWT.CENTER, true, true );
currentImageLabelGridData.widthHint = currentImage.getBounds().width;
currentImageLabelGridData.heightHint = currentImage.getBounds().height;
currentImageLabel.setLayoutData( currentImageLabelGridData );
currentImageTypeText.setText( getImageType( imageData.type ) );
currentImageSizeText.setText( getSizeString( currentImageRawData.length ) );
currentImageWidthText.setText( NLS
.bind( Messages.getString( "ImageDialog.Pixel" ), imageData.width ) ); //$NON-NLS-1$
currentImageHeightText.setText( NLS.bind(
Messages.getString( "ImageDialog.Pixel" ), imageData.height ) ); //$NON-NLS-1$
}
catch ( SWTException swte )
{
currentImageLabel.setImage( null );
currentImageLabel.setText( Messages.getString( "ImageDialog.UnsupportedFormatSpaces" ) ); //$NON-NLS-1$
currentImageTypeText.setText( Messages.getString( "ImageDialog.UnsupportedFormat" ) ); //$NON-NLS-1$
currentImageSizeText.setText( getSizeString( currentImageRawData.length ) );
currentImageWidthText.setText( "-" ); //$NON-NLS-1$
currentImageHeightText.setText( "-" ); //$NON-NLS-1$
}
}
else
{
currentImageLabel.setImage( null );
currentImageLabel.setText( Messages.getString( "ImageDialog.NoImageSpaces" ) ); //$NON-NLS-1$
currentImageTypeText.setText( Messages.getString( "ImageDialog.NoImage" ) ); //$NON-NLS-1$
currentImageSizeText.setText( "-" ); //$NON-NLS-1$
currentImageWidthText.setText( "-" ); //$NON-NLS-1$
currentImageHeightText.setText( "-" ); //$NON-NLS-1$
}
currentImageSaveButton.setEnabled( currentImageRawData != null && currentImageRawData.length > 0 );
}
}
/**
* Update new image tab.
*/
private void updateNewImageGroup()
{
if ( ( newImage != null ) && !newImage.isDisposed() )
{
newImage.dispose();
newImage = null;
}
String newImageFileName = newImageFilenameText.getText();
if ( !Strings.isEmpty( newImageFileName ) ) //$NON-NLS-1$
{
try
{
File file = new File( newImageFileName );
FileInputStream in = new FileInputStream( file );
ByteArrayOutputStream out = new ByteArrayOutputStream( ( int ) file.length() );
byte[] buf = new byte[4096];
int len;
while ( ( len = in.read( buf ) ) > 0 )
{
out.write( buf, 0, len );
}
newImageRawData = out.toByteArray();
out.close();
in.close();
}
catch ( FileNotFoundException e )
{
newImageRawData = null;
newImageLabel.setImage( null );
newImageLabel.setText( Messages.getString( "ImageDialog.ErrorFileNotFound" ) ); //$NON-NLS-1$
newImageTypeText.setText( "-" ); //$NON-NLS-1$
newImageSizeText.setText( "-" ); //$NON-NLS-1$
newImageWidthText.setText( "-" ); //$NON-NLS-1$
newImageHeightText.setText( "-" ); //$NON-NLS-1$
}
catch ( IOException e )
{
newImageRawData = null;
newImageLabel.setImage( null );
newImageLabel.setText( NLS.bind(
Messages.getString( "ImageDialog.CantReadFile" ), new String[] { e.getMessage() } ) ); //$NON-NLS-1$
newImageTypeText.setText( "-" ); //$NON-NLS-1$
newImageSizeText.setText( "-" ); //$NON-NLS-1$
newImageWidthText.setText( "-" ); //$NON-NLS-1$
newImageHeightText.setText( "-" ); //$NON-NLS-1$
}
}
else
{
newImageRawData = null;
newImageLabel.setImage( null );
newImageLabel.setText( Messages.getString( "ImageDialog.NoImageSelected" ) ); //$NON-NLS-1$
newImageTypeText.setText( "-" ); //$NON-NLS-1$
newImageSizeText.setText( "-" ); //$NON-NLS-1$
newImageWidthText.setText( "-" ); //$NON-NLS-1$
newImageHeightText.setText( "-" ); //$NON-NLS-1$
}
if ( ( newImageRawData != null ) && ( newImageRawData.length > 0 ) )
{
try
{
ImageData imageData = new ImageData( new ByteArrayInputStream( newImageRawData ) );
newImage = new Image( getShell().getDisplay(), resizeImage( imageData ) );
newImageLabel.setImage( newImage );
newImageTypeText.setText( getImageType( imageData.type ) );
if ( imageData.type != requiredImageType )
{
newImageTypeText
.setText( newImageTypeText.getText()
+ NLS
.bind(
Messages.getString( "ImageDialog.WillBeConverted" ), new String[] { getImageType( requiredImageType ) } ) ); //$NON-NLS-1$
}
newImageSizeText.setText( getSizeString( newImageRawData.length ) );
newImageWidthText.setText( NLS.bind( Messages.getString( "ImageDialog.Pixel" ), imageData.width ) ); //$NON-NLS-1$
newImageHeightText.setText( NLS.bind( Messages.getString( "ImageDialog.Pixel" ), imageData.height ) ); //$NON-NLS-1$
}
catch ( SWTException swte )
{
newImageLabel.setImage( null );
newImageLabel.setText( Messages.getString( "ImageDialog.UnsupportedFormatSpaces" ) ); //$NON-NLS-1$
newImageTypeText.setText( Messages.getString( "ImageDialog.UnsupportedFormat" ) ); //$NON-NLS-1$
newImageSizeText.setText( getSizeString( newImageRawData.length ) );
newImageWidthText.setText( "-" ); //$NON-NLS-1$
newImageHeightText.setText( "-" ); //$NON-NLS-1$
}
}
if ( okButton != null )
{
okButton.setEnabled( newImage != null );
}
newImageLabel.getParent().layout();
newImageTypeText.getParent().layout();
}
/**
* Update tab folder and the tabs.
*/
private void updateTabFolder()
{
if ( currentImageSaveButton != null )
{
if ( tabFolder.getSelectionIndex() == CURRENT_TAB )
{
currentImageSaveButton.setFocus();
}
updateCurrentImageGroup();
}
if ( newImageBrowseButton != null )
{
if ( ( tabFolder.getSelectionIndex() == NEW_TAB ) || ( currentImageSaveButton == null ) )
{
newImageBrowseButton.setFocus();
}
updateNewImageGroup();
}
}
/**
* Resizes the image.
*
* @param imageData the image data to resize
*
* @return the resized image data
*/
private ImageData resizeImage( ImageData imageData )
{
// Computing the width scale factor
double widthScaleFactor = 1.0;
if ( imageData.width > MAX_WIDTH )
{
widthScaleFactor = ( double ) MAX_WIDTH / imageData.width;
}
// Computing the height scale factor
double heightScaleFactor = 1.0;
if ( imageData.height > MAX_HEIGHT )
{
heightScaleFactor = ( double ) MAX_HEIGHT / imageData.height;
}
// Taking the minimum of both
double minScalefactor = Math.min( heightScaleFactor, widthScaleFactor );
// Resizing the image data
return resize( imageData, ( int ) ( imageData.width * minScalefactor ),
( int ) ( imageData.height * minScalefactor ) );
}
/**
* Resizes an image using the GC (for better quality).
*
* @param imageData the image data
* @param width the width
* @param height the height
* @return the resized image
*/
private ImageData resize( ImageData imageData, int width, int height )
{
Image image = new Image( Display.getDefault(), imageData );
Image resizedImage = new Image( Display.getDefault(), width, height );
try
{
GC gc = new GC( resizedImage );
try
{
gc.setAntialias( SWT.ON );
gc.setInterpolation( SWT.HIGH );
gc.drawImage( image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, width, height );
}
finally
{
gc.dispose();
}
ImageData resizedImageData = resizedImage.getImageData();
return resizedImageData;
}
finally
{
image.dispose();
resizedImage.dispose();
}
}
/**
* Creates the image info container.
*
* @param parent the parent
*
* @return the image info container
*/
private Composite createImageInfoContainer( Composite parent )
{
Composite imageInfoContainer = new Composite( parent, SWT.NONE );
GridLayout gl = new GridLayout( 2, false );
gl.marginHeight = gl.marginWidth = 0;
imageInfoContainer.setLayout( gl );
imageInfoContainer.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
return imageInfoContainer;
}
/**
* Creates the image info.
*
* @param label the label
* @param parent the parent
*
* @return the image info
*/
private Text createImageInfo( Composite parent, String label )
{
BaseWidgetUtils.createLabel( parent, label, 1 );
Text text = BaseWidgetUtils.createLabeledText( parent, "", 1 ); //$NON-NLS-1$
return text;
}
/**
* Creates the button.
*
* @param label the label
* @param parent the parent
*
* @return the button
*/
private Button createButton( Composite parent, String label )
{
Button button = BaseWidgetUtils.createButton( parent, label, 1 );
return button;
}
/**
* Gets the size string.
*
* @param length the length
*
* @return the size string
*/
private static String getSizeString( int length )
{
if ( length > 1000000 )
{
return ( length / 1000000 ) + NLS.bind( Messages.getString( "ImageDialog.MB" ), new Integer[] //$NON-NLS-1$
{ length } ); //$NON-NLS-1$
}
else if ( length > 1000 )
{
return ( length / 1000 ) + NLS.bind( Messages.getString( "ImageDialog.KB" ), new Integer[] //$NON-NLS-1$
{ length } ); //$NON-NLS-1$
}
else
{
return length + Messages.getString( "ImageDialog.Bytes" ); //$NON-NLS-1$
}
}
/**
* Gets the image info.
*
* @param imageRawData the image raw data
*
* @return the image info
*/
public static String getImageInfo( byte[] imageRawData )
{
if ( imageRawData == null )
{
return IValueEditor.NULL;
}
String text;
try
{
ByteArrayInputStream bais = new ByteArrayInputStream( imageRawData );
ImageData imageData = new ImageData( bais );
String typePrefix = getImageType( imageData.type );
if ( !Strings.isEmpty( typePrefix ) ) //$NON-NLS-1$
{
typePrefix += "-"; //$NON-NLS-1$
}
text = NLS
.bind(
Messages.getString( "ImageDialog.Image" ), new Object[] { typePrefix, imageData.width, imageData.height, imageRawData.length } ); //$NON-NLS-1$
}
catch ( SWTException swte )
{
text = NLS.bind( Messages.getString( "ImageDialog.InvalidImage" ), new Object[] { imageRawData.length } ); //$NON-NLS-1$
}
return text;
}
/**
* Gets the image type.
*
* @param swtCode the swt code
*
* @return the image type
*/
private static String getImageType( int swtCode )
{
switch ( swtCode )
{
case SWT.IMAGE_JPEG :
return "JPEG"; //$NON-NLS-1$
case SWT.IMAGE_GIF :
return "GIF"; //$NON-NLS-1$
case SWT.IMAGE_PNG :
return "PNG"; //$NON-NLS-1$
case SWT.IMAGE_BMP :
case SWT.IMAGE_BMP_RLE :
return "BMP"; //$NON-NLS-1$
default :
return "";
}
}
/**
* Gets the image data in required format.
*
* @return Returns the image data in required format or null.
*/
public byte[] getNewImageRawData()
{
return newImageRawDataInRequiredFormat;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/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.valueeditors.image;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/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.valueeditors.adtime;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.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.valueeditors.adtime;
import java.util.Calendar;
/**
* Helper class to work with Active Directory time values.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ActiveDirectoryTimeUtils
{
/**
* Converts the given Active Directory time value to an equivalent calendar.
*
* @param adTimeValue the Active Directory time value
* @return the equivalent calendar
*/
public static Calendar convertToCalendar( long adTimeValue )
{
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis( ( adTimeValue - 116444736000000000L ) / 10000L );
return calendar;
}
/**
* Converts the given calendar to the equivalent Active Directory time.
*
* @param calendar the calendard
* @return the equivalent Active Directory time
*/
public static long convertToActiveDirectoryTime( Calendar calendar )
{
return ( ( calendar.getTime().getTime() * 10000L ) + 116444736000000000L );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.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.valueeditors.adtime;
import java.util.Calendar;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
/**
* This class provides a dialog to edit an Active Directory Date & Time value.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ActiveDirectoryTimeValueDialog extends Dialog
{
/** The value */
private long value;
//
// UI Fields
//
// Time
private Spinner hoursSpinner;
private Spinner minutesSpinner;
private Spinner secondsSpinner;
// Date
private DateTime dateCalendar;
// Raw value
private Text rawValueText;
//
// Listeners
//
/**
* The modify listener of the hours field.
*/
private ModifyListener hoursModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The modify listener of the minutes field.
*/
private ModifyListener minutesModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The modify listener of the seconds field.
*/
private ModifyListener secondsModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The selection listener of the calendar.
*/
private SelectionListener dateSelectionListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The modify listener of the raw field.
*/
private ModifyListener rawValueModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
try
{
value = Long.parseLong( rawValueText.getText() );
removeListeners();
updateNonRawFields();
addListeners();
}
catch ( NumberFormatException e1 )
{
return;
}
}
};
private VerifyListener rawValueVerifyListener = new VerifyListener()
{
public void verifyText( VerifyEvent e )
{
// Prevent the user from entering anything but an integer
if ( !e.text.matches( "(-)?([0-9])*" ) ) //$NON-NLS-1$
{
e.doit = false;
}
}
};
/**
* Creates a new instance of ActiveDirectoryTimeValueDialog.
*
* @param parentShell
* the parent shell
* @param value
* the initial value
*/
public ActiveDirectoryTimeValueDialog( Shell parentShell, long value )
{
this( parentShell );
this.value = value;
}
/**
* Creates a new instance of ActiveDirectoryTimeValueDialog.
*
* @param parentShell
* the parent shell
* @param value
* the initial value
*/
public ActiveDirectoryTimeValueDialog( Shell parentShell )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.value = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( Calendar.getInstance() );
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "ActiveDirectoryTimeValueDialog.DateAndTimeEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_GENERALIZEDTIMEEDITOR ) );
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
// Main composites
Composite composite = ( Composite ) super.createDialogArea( parent );
Composite dualComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
// Creating dialog areas
createTimeDialogArea( dualComposite );
createDateDialogArea( dualComposite );
createRawValueDialogArea( dualComposite );
// Initializing with initial value
initWithInitialValue();
// Adding listeners
addListeners();
applyDialogFont( composite );
return composite;
}
/**
* Creates the "Time" dialog area.
*
* @param parent
* the parent composite
*/
private void createTimeDialogArea( Composite parent )
{
// Label
Label timeLabel = new Label( parent, SWT.NONE );
timeLabel.setText( Messages.getString( "ActiveDirectoryTimeValueDialog.Time" ) ); //$NON-NLS-1$
Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 5, 1 );
// Hours
hoursSpinner = new Spinner( rightComposite, SWT.BORDER );
hoursSpinner.setMinimum( 0 );
hoursSpinner.setMaximum( 23 );
hoursSpinner.setTextLimit( 2 );
hoursSpinner.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false ) );
Label label1 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
label1.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
// Minutes
minutesSpinner = new Spinner( rightComposite, SWT.BORDER );
minutesSpinner.setMinimum( 0 );
minutesSpinner.setMaximum( 59 );
minutesSpinner.setTextLimit( 2 );
minutesSpinner.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, false, false ) );
Label label2 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
label2.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
// Seconds
secondsSpinner = new Spinner( rightComposite, SWT.BORDER );
secondsSpinner.setMinimum( 0 );
secondsSpinner.setMaximum( 59 );
secondsSpinner.setTextLimit( 2 );
secondsSpinner.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, false, false ) );
}
/**
* Creates the "Date" dialog area.
*
* @param parent
* the parent composite
*/
private void createDateDialogArea( Composite parent )
{
// Label
Label dateLabel = BaseWidgetUtils.createLabel( parent,
Messages.getString( "ActiveDirectoryTimeValueDialog.Date" ), 1 ); //$NON-NLS-1$
dateLabel.setLayoutData( new GridData( SWT.NONE, SWT.TOP, false, false ) );
Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
// Calendar
dateCalendar = new DateTime( rightComposite, SWT.CALENDAR | SWT.BORDER );
dateCalendar.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
}
/**
* Creates the "Raw value" dialog area.
*
* @param parent
* the parent composite
*/
private void createRawValueDialogArea( Composite parent )
{
// Separator
Label separatorLabel = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) );
// Label
BaseWidgetUtils.createLabel( parent, Messages.getString( "ActiveDirectoryTimeValueDialog.RawValue" ), 1 ); //$NON-NLS-1$
// Text
rawValueText = BaseWidgetUtils.createText( parent, "", 1 ); //$NON-NLS-1$
}
/**
* Initializes the UI with the value.
*/
private void initWithInitialValue()
{
updateNonRawFields();
updateRawFields();
}
/**
* Update the non-raw UI fields.
*/
private void updateNonRawFields()
{
// Getting the calendar
Calendar calendar = getCalendarFromValue();
// Time
hoursSpinner.setSelection( calendar.get( Calendar.HOUR_OF_DAY ) );
minutesSpinner.setSelection( calendar.get( Calendar.MINUTE ) );
secondsSpinner.setSelection( calendar.get( Calendar.SECOND ) );
// Date
dateCalendar.setDate( calendar.get( Calendar.YEAR ), calendar.get( Calendar.MONTH ), calendar
.get( Calendar.DAY_OF_MONTH ) );
}
/**
* Update the raw UI fields.
*/
private void updateRawFields()
{
// Raw value
rawValueText.setText( "" + value ); //$NON-NLS-1$
}
/**
* Adds the listeners to the UI fields.
*/
private void addListeners()
{
// Hours
hoursSpinner.addModifyListener( hoursModifyListener );
// Minutes
minutesSpinner.addModifyListener( minutesModifyListener );
// Seconds
secondsSpinner.addModifyListener( secondsModifyListener );
// Calendar
dateCalendar.addSelectionListener( dateSelectionListener );
// Raw value
rawValueText.addModifyListener( rawValueModifyListener );
rawValueText.addVerifyListener( rawValueVerifyListener );
}
/**
* Removes the listeners from the UI fields.
*/
private void removeListeners()
{
// Hours
hoursSpinner.removeModifyListener( hoursModifyListener );
// Minutes
minutesSpinner.removeModifyListener( minutesModifyListener );
// Seconds
secondsSpinner.removeModifyListener( secondsModifyListener );
// Calendar
dateCalendar.removeSelectionListener( dateSelectionListener );
// Raw value
rawValueText.removeModifyListener( rawValueModifyListener );
rawValueText.removeVerifyListener( rawValueVerifyListener );
}
/**
* Updates the value using the non raw fields.
*/
private void updateValueFromNonRawFields()
{
// Getting the calendar
Calendar calendar = getCalendarFromValue();
// Time
calendar.set( Calendar.HOUR_OF_DAY, hoursSpinner.getSelection() );
calendar.set( Calendar.MINUTE, minutesSpinner.getSelection() );
calendar.set( Calendar.SECOND, secondsSpinner.getSelection() );
// Date
calendar.set( Calendar.YEAR, dateCalendar.getYear() );
calendar.set( Calendar.MONTH, dateCalendar.getMonth() );
calendar.set( Calendar.DAY_OF_MONTH, dateCalendar.getDay() );
value = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( calendar );
}
/**
* Gets a calendar from the current value.
*
* @return a calendar corresponding to the current value
*/
private Calendar getCalendarFromValue()
{
return ActiveDirectoryTimeUtils.convertToCalendar( value );
}
/**
* Gets the value.
*
* @return
* the value
*/
public long getValue()
{
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.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.valueeditors.adtime;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
/**
* Implementation of IValueEditor for attributes:
* - pwdLastSet
* - accountExpires
* - lastLogoff
* - lastLogon
* - lastLogonTimeStamp
* - badPasswordTime
*
* Currently only the getDisplayXXX() methods are implemented.
* For modification the raw string must be edited.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ActiveDirectoryTimeValueEditor extends AbstractDialogStringValueEditor
{
/**
* {@inheritDoc}
*
* Returns the proper formatted date and time, timezone is
* converted to the default locale.
*/
public String getDisplayValue( IValue value )
{
String displayValue = super.getDisplayValue( value );
if ( !showRawValues() )
{
// Special case for the "0" value where we don't want to display date
// that makes no sense ("0" being the default value, it happened a lot).
if ( "0".equals( displayValue ) ) //$NON-NLS-1$
{
return displayValue;
}
DateFormat targetFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.LONG );
try
{
long adTimeValue = Long.parseLong( displayValue );
Date date = ActiveDirectoryTimeUtils.convertToCalendar( adTimeValue ).getTime();
displayValue = targetFormat.format( date ) + " (" + displayValue + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
catch ( NumberFormatException e )
{
// show the raw value in that case
}
}
return displayValue;
}
/**
* {@inheritDoc}
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof String )
{
String s = ( String ) value;
long adTimeValue = 0;
if ( !EMPTY.equals( s ) ) //$NON-NLS-1$
{
// Trying to parse the value
try
{
adTimeValue = Long.parseLong( s );
}
catch ( NumberFormatException pe )
{
// The value could not be parsed correctly
// Displaying an error window indicating to the user that the value is bogus
// and asking him if he wants to continue to edit the value with current date and time selected
if ( MessageDialog.openConfirm( PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages
.getString( "ActiveDirectoryTimeValueEditor.BogusDateAndTimeValue" ), NLS.bind( //$NON-NLS-1$
Messages.getString( "ActiveDirectoryTimeValueEditor.TheValueIsBogus" ), new String[] //$NON-NLS-1$
{ s } ) ) )
{
// Generating today's date and time
adTimeValue = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( Calendar.getInstance() );
}
else
{
return false;
}
}
}
else
{
// Generating today's date and time
adTimeValue = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( Calendar.getInstance() );
}
// Creating and opening the dialog
ActiveDirectoryTimeValueDialog dialog = new ActiveDirectoryTimeValueDialog( shell, adTimeValue );
if ( dialog.open() == ActiveDirectoryTimeValueDialog.OK )
{
setValue( Long.toString( dialog.getValue() ) ); //$NON-NLS-1$
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateDialog.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.valueeditors.certificate;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import org.apache.directory.api.util.FileUtils;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.apache.directory.studio.connection.ui.widgets.CertificateInfoComposite;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* Dialog to display a X.509 certificate. It could be
* used to load and save the certificate from and to disk.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class CertificateDialog extends Dialog
{
public static final String LOAD_FILE_NAME_TOOLTIP = "LoadFileName";
/** The default title. */
private static final String DIALOG_TITLE = Messages.getString( "CertificateDialog.CertificateDialog" ); //$NON-NLS-1$
/** The button ID for the load button. */
private static final int LOAD_BUTTON_ID = 9998;
/** The button ID for the save button. */
private static final int SAVE_BUTTON_ID = 9999;
/** Hidden text to set the filename, used for UI tests. */
private Text loadFilenameText;
/** The current certificate binary data. */
private byte[] currentData;
/** The current certificate. */
private X509Certificate currentCertificate;
/** The return data, only set if OK button is pressed, null otherwise. */
private byte[] returnData;
/** The certificate info composite. */
private CertificateInfoComposite certificateInfoComposite;
/**
* Creates a new instance of CertificateDialog.
*
* @param parentShell the parent shell
* @param initialData the initial data
*/
public CertificateDialog( Shell parentShell, byte[] initialData )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.currentData = initialData;
}
/**
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
*/
protected void buttonPressed( int buttonId )
{
if ( buttonId == IDialogConstants.OK_ID )
{
returnData = currentData;
}
else if ( buttonId == SAVE_BUTTON_ID )
{
FileDialog fileDialog = new FileDialog( getShell(), SWT.SAVE );
fileDialog.setText( Messages.getString( "CertificateDialog.SaveCertificate" ) ); //$NON-NLS-1$
// fileDialog.setFilterExtensions(new String[]{"*.pem"});
String returnedFileName = fileDialog.open();
if ( returnedFileName != null )
{
try
{
File file = new File( returnedFileName );
FileUtils.writeByteArrayToFile( file, currentData );
}
catch ( IOException e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages
.getString( "CertificateDialog.CantWriteToFile" ), e ) ); //$NON-NLS-1$
}
}
}
else if ( buttonId == LOAD_BUTTON_ID )
{
FileDialog fileDialog = new FileDialog( getShell(), SWT.OPEN );
fileDialog.setText( Messages.getString( "CertificateDialog.LoadCertificate" ) ); //$NON-NLS-1$
String returnedFileName = fileDialog.open();
if ( returnedFileName != null )
{
loadFile( returnedFileName );
}
}
else
{
returnData = null;
}
super.buttonPressed( buttonId );
}
private void loadFile( String fileName )
{
try
{
File file = new File( fileName );
currentData = FileUtils.readFileToByteArray( file );
updateInput();
}
catch ( IOException e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages
.getString( "CertificateDialog.CantReadFile" ), e ) ); //$NON-NLS-1$
}
}
/**
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( DIALOG_TITLE );
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_CERTIFICATEEDITOR ) );
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
protected void createButtonsForButtonBar( Composite parent )
{
((GridLayout) parent.getLayout()).numColumns++;
loadFilenameText = new Text( parent, SWT.NONE );
loadFilenameText.setToolTipText( LOAD_FILE_NAME_TOOLTIP );
loadFilenameText.setBackground( parent.getBackground() );
loadFilenameText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
loadFile( loadFilenameText.getText() );
}
} );
createButton( parent, LOAD_BUTTON_ID, Messages.getString( "CertificateDialog.LoadCertificateButton" ), false ); //$NON-NLS-1$
createButton( parent, SAVE_BUTTON_ID, Messages.getString( "CertificateDialog.SaveCertificateButton" ), false ); //$NON-NLS-1$
createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent )
{
// create composite
Composite composite = ( Composite ) super.createDialogArea( parent );
Composite certificateInfoContainer = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH * 3 / 2 );
gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
certificateInfoContainer.setLayoutData( gd );
certificateInfoComposite = new CertificateInfoComposite( certificateInfoContainer, SWT.NONE );
if ( currentData != null && currentData.length > 0 )
{
updateInput();
}
applyDialogFont( composite );
return composite;
}
/**
* Parses the certificate binary data and updates the input.
*/
private void updateInput()
{
try
{
// parse the certificate
currentCertificate = generateCertificate( currentData );
// update the byte[], this must be done for the case that
// the certificate loaded from file is in PEM format
currentData = currentCertificate.getEncoded();
// set the input and update button
certificateInfoComposite.setInput( new X509Certificate[]
{ currentCertificate } );
if ( getButton( IDialogConstants.OK_ID ) != null )
{
getButton( IDialogConstants.OK_ID ).setEnabled( true );
}
}
catch ( Exception e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
new Status( IStatus.ERROR, ValueEditorsConstants.PLUGIN_ID, IStatus.ERROR, Messages
.getString( "CertificateDialog.CantParseCertificate" ), //$NON-NLS-1$
e ) );
if ( getButton( IDialogConstants.OK_ID ) != null )
{
getButton( IDialogConstants.OK_ID ).setEnabled( false );
}
}
}
/**
* Gets the data.
*
* @return the data
*/
public byte[] getData()
{
return returnData;
}
public static String getCertificateInfo( byte[] data )
{
try
{
X509Certificate certificate = generateCertificate( data );
if ( certificate != null )
{
String name = certificate.getSubjectX500Principal().getName();
int version = certificate.getVersion();
String type = certificate.getType();
return type + "v" + version + ": " + name; //$NON-NLS-1$ //$NON-NLS-2$
}
else
{
return NLS.bind( Messages.getString( "CertificateDialog.InvalidCertificate" ), data.length ); //$NON-NLS-1$
}
}
catch ( Exception e )
{
return NLS.bind( Messages.getString( "CertificateDialog.InvalidCertificate" ), data.length ); //$NON-NLS-1$
}
}
private static X509Certificate generateCertificate( byte[] data ) throws CertificateException
{
CertificateFactory cf = CertificateFactory.getInstance( "X.509" ); //$NON-NLS-1$
Certificate certificate = cf.generateCertificate( new ByteArrayInputStream( data ) );
if ( certificate instanceof X509Certificate )
{
return ( X509Certificate ) certificate;
}
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/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.valueeditors.certificate;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/certificate/CertificateValueEditor.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.valueeditors.certificate;
import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractDialogBinaryValueEditor;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.8
* (Certificate).
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class CertificateValueEditor extends AbstractDialogBinaryValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the CertificateDialog.
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof byte[] )
{
byte[] currentCertificateData = ( byte[] ) value;
CertificateDialog dialog = new CertificateDialog( shell, currentCertificateData );
if ( ( dialog.open() == TextDialog.OK ) && ( dialog.getData() != null ) )
{
setValue( dialog.getData() );
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*
* Returns the certificate info text created by
* CertificateDialog.getCertificateInfo().
*/
public String getDisplayValue( IValue value )
{
if ( showRawValues() )
{
return getPrintableString( value );
}
else
{
if ( value == null )
{
return NULL; //$NON-NLS-1$
}
else if ( value.isBinary() )
{
byte[] data = value.getBinaryValue();
String text = CertificateDialog.getCertificateInfo( data );
return text;
}
else
{
return Messages.getString( "CertificateValueEditor.InvalidCertificateData" ); //$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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerDialog.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.valueeditors.integer;
import java.math.BigDecimal;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* This class provides a dialog to enter or choose an integer.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class IntegerDialog extends Dialog
{
/** The initial value */
private BigDecimal initialValue;
/** The value */
private BigDecimal value;
/** The text */
private Text text;
/**
* Creates a new instance of IntegerDialog.
*
* @param parentShell the parent shell
* @param initialValue the initial value
*/
public IntegerDialog( Shell parentShell, BigDecimal initialValue )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.initialValue = initialValue;
this.value = new BigDecimal( initialValue.toString() );
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "IntegerDialog.IntegerEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_INTEGEREDITOR ) );
}
/**
* {@inheritDoc}
*/
protected void createButtonsForButtonBar( Composite parent )
{
createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
// returnValue = spinner.getSelection();
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
// Composite
Composite composite = ( Composite ) super.createDialogArea( parent );
composite.setLayout( new GridLayout( 3, false ) );
GridData gd = new GridData( GridData.FILL_BOTH );
composite.setLayoutData( gd );
// - Button
Button minusButton = new Button( composite, SWT.PUSH );
minusButton.setText( "-" ); //$NON-NLS-1$
minusButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
addToValue( -1 );
text.selectAll();
}
} );
// Text
text = new Text( composite, SWT.BORDER );
text.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
text.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromText();
}
} );
text.addVerifyListener( new VerifyListener()
{
public void verifyText( VerifyEvent e )
{
// Prevent the user from entering anything but an integer
if ( !e.text.matches( "(-)?([0-9])*" ) ) //$NON-NLS-1$
{
e.doit = false;
}
}
} );
text.addKeyListener( new KeyAdapter()
{
public void keyPressed( KeyEvent e )
{
if ( e.keyCode == SWT.ARROW_UP )
{
addToValue( 1 );
e.doit = false;
text.selectAll();
}
else if ( e.keyCode == SWT.ARROW_DOWN )
{
addToValue( -1 );
e.doit = false;
text.selectAll();
}
else if ( e.keyCode == SWT.PAGE_UP )
{
addToValue( 100 );
e.doit = false;
text.selectAll();
}
else if ( e.keyCode == SWT.PAGE_DOWN )
{
addToValue( -100 );
e.doit = false;
text.selectAll();
}
}
} );
// + Button
Button plusButton = new Button( composite, SWT.PUSH );
plusButton.setText( "+" ); //$NON-NLS-1$
plusButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
addToValue( 1 );
text.selectAll();
}
} );
updateTextValue();
// Setting focus
text.setFocus();
applyDialogFont( composite );
return composite;
}
/**
* Updates the text value.
*/
private void updateTextValue()
{
text.setText( value.toString() );
}
/**
* Adds the given integer to the value.
*
* @param i the integer
*/
private void addToValue( int i )
{
value = value.add( new BigDecimal( i ) );
updateTextValue();
}
/**
* Updates the value from the text's value.
*/
private void updateValueFromText()
{
try
{
BigDecimal newValue = new BigDecimal( text.getText() );
value = newValue;
}
catch ( NumberFormatException e )
{
// Nothing to do
}
}
/**
* Gets the integer.
*
* @return the integer
*/
public BigDecimal getInteger()
{
return value;
}
/**
* Indicates if the dialog is dirty.
*
* @return
* <code>true</code> if the dialog is dirty,
* <code>false</code> if not.
*/
public boolean isDirty()
{
return !initialValue.equals( 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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/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.valueeditors.integer;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/integer/IntegerValueEditor.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.valueeditors.integer;
import java.math.BigDecimal;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for integer values.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class IntegerValueEditor extends AbstractDialogStringValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the IntegerDialog.
*/
public boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof String )
{
BigDecimal integer = null;
boolean isNewOrMalformedValue = false;
try
{
integer = new BigDecimal( ( String ) value );
}
catch ( NumberFormatException e )
{
integer = new BigDecimal( 0 );
isNewOrMalformedValue = true;
}
IntegerDialog dialog = new IntegerDialog( shell, integer );
if ( dialog.open() == IntegerDialog.OK && ( dialog.isDirty() || isNewOrMalformedValue ) )
{
BigDecimal newValue = dialog.getInteger();
if ( newValue != null )
{
setValue( newValue.toString() );
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/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.valueeditors.time;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.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.valueeditors.time;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import org.apache.directory.api.util.GeneralizedTime;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.24
* (Generalized Time).
*
* Currently only the getDisplayXXX() methods are implemented.
* For modification the raw string must be edited.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class GeneralizedTimeValueEditor extends AbstractDialogStringValueEditor
{
/**
* {@inheritDoc}
*
* Returns the proper formatted date and time, timezone is
* converted to the default locale.
*/
public String getDisplayValue( IValue value )
{
String displayValue = super.getDisplayValue( value );
if ( !showRawValues() )
{
DateFormat targetFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.LONG );
try
{
GeneralizedTime generalizedTime = new GeneralizedTime( displayValue );
Date date = generalizedTime.getCalendar().getTime();
displayValue = targetFormat.format( date ) + " (" + displayValue + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
catch ( ParseException pe )
{
// show the raw value in that case
}
}
return displayValue;
}
/**
* {@inheritDoc}
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof String )
{
String s = ( String ) value;
// Trying to parse the value
GeneralizedTime generalizedTime = null;
try
{
generalizedTime = "".equals( s ) ? null : new GeneralizedTime( s ); //$NON-NLS-1$
}
catch ( ParseException pe )
{
// The value could not be parsed correctly
// Displaying an error window indicating to the user that the value is bogus
// and asking him if he wants to continue to edit the value with current date and time selected
if ( MessageDialog.openConfirm( PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages
.getString( "GeneralizedTimeValueEditor.BogusDateAndTimeValue" ), NLS.bind( //$NON-NLS-1$
Messages.getString( "GeneralizedTimeValueEditor.TheValueIsBogus" ), new String[] //$NON-NLS-1$
{ s } ) ) )
{
// Generating today's date and time
generalizedTime = new GeneralizedTime( Calendar.getInstance() );
}
else
{
return false;
}
}
// Creating and opening the dialog
GeneralizedTimeValueDialog dialog = new GeneralizedTimeValueDialog( shell, generalizedTime );
if ( dialog.open() == GeneralizedTimeValueDialog.OK )
{
GeneralizedTime newGeneralizedTime = dialog.getGeneralizedTime();
// Checking if we need to save the generalized time
// with or without fraction
if ( newGeneralizedTime.getFraction() == 0 )
{
setValue( newGeneralizedTime.toGeneralizedTimeWithoutFraction() );
}
else
{
setValue( newGeneralizedTime.toGeneralizedTime() );
}
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.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.valueeditors.time;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import org.apache.directory.api.util.GeneralizedTime;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
/**
* This class provides a dialog to define a generalized time.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class GeneralizedTimeValueDialog extends Dialog
{
/** The value */
private GeneralizedTime value;
/** The list, containing all time zones, bound to the combo viewer */
private ArrayList<TimeZone> allTimezonesList = new ArrayList<TimeZone>();
/** The UTC times zones map */
private Map<Integer, TimeZone> utcTimezonesMap = new HashMap<Integer, TimeZone>();
//
// UI Fields
//
// Time
private Spinner hoursSpinner;
private Spinner minutesSpinner;
private Spinner secondsSpinner;
// Date
private DateTime dateCalendar;
// Time zone
private ComboViewer timezoneComboViewer;
// Raw value
private Text rawValueText;
// Raw validator
private Label rawValueValidatorImage;
// Discard fraction checkbox
private Button discardFractionCheckbox;
/** The OK button of the dialog */
private Button okButton;
//
// Listeners
//
/**
* The modify listener of the hours field.
*/
private ModifyListener hoursModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The modify listener of the minutes field.
*/
private ModifyListener minutesModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The modify listener of the seconds field.
*/
private ModifyListener secondsModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The selection listener of the calendar.
*/
private SelectionListener dateSelectionListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The selection changed listener of the time zone combo.
*/
private ISelectionChangedListener timezoneSelectionChangedListener = new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
updateValueFromNonRawFields();
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* The modify listener of the raw field.
*/
private ModifyListener rawValueModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
try
{
value = new GeneralizedTime( rawValueText.getText() );
removeListeners();
updateNonRawFields();
addListeners();
validateRawValue( true );
}
catch ( ParseException e1 )
{
validateRawValue( false );
return;
}
}
};
private SelectionListener discardFractionCheckboxSelectionListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
removeListeners();
updateRawFields();
addListeners();
}
};
/**
* Creates a new instance of GeneralizedTimeValueDialog.
*
* @param parentShell
* the parent shell
* @param value
* the initial value
*/
public GeneralizedTimeValueDialog( Shell parentShell, GeneralizedTime value )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.value = value;
// If the initial value is null, we take the current date/time
if ( this.value == null )
{
this.value = new GeneralizedTime( Calendar.getInstance() );
}
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "GeneralizedTimeValueDialog.DateAndTimeEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_GENERALIZEDTIMEEDITOR ) );
}
/**
* {@inheritDoc}
*/
protected void createButtonsForButtonBar( Composite parent )
{
okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
// Checking if we need to discard the fraction
if ( discardFractionCheckbox.getSelection() )
{
// Removing the fraction from the value
Calendar calendar = value.getCalendar();
calendar.set( Calendar.MILLISECOND, 0 );
value = new GeneralizedTime( calendar );
}
// Saving the dialog settings
ValueEditorsActivator.getDefault().getDialogSettings()
.put( ValueEditorsConstants.DIALOGSETTING_KEY_DATE_EDITOR_DISCARD_FRACTION,
discardFractionCheckbox.getSelection() );
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
// Main composites
Composite composite = ( Composite ) super.createDialogArea( parent );
Composite dualComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
// Creating dialog areas
createTimeDialogArea( dualComposite );
createDateDialogArea( dualComposite );
createTimeZoneDialogArea( dualComposite );
createRawValueDialogArea( dualComposite );
// Getting the dialog settings
discardFractionCheckbox.setSelection( ValueEditorsActivator.getDefault().getDialogSettings()
.getBoolean( ValueEditorsConstants.DIALOGSETTING_KEY_DATE_EDITOR_DISCARD_FRACTION ) );
// Initializing with initial value
initWithInitialValue();
// Adding listeners
addListeners();
applyDialogFont( composite );
return composite;
}
/**
* Creates the "Time" dialog area.
*
* @param parent
* the parent composite
*/
private void createTimeDialogArea( Composite parent )
{
// Label
Label timeLabel = new Label( parent, SWT.NONE );
timeLabel.setText( Messages.getString( "GeneralizedTimeValueDialog.Time" ) ); //$NON-NLS-1$
Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 5, 1 );
// Hours
hoursSpinner = new Spinner( rightComposite, SWT.BORDER );
hoursSpinner.setMinimum( 0 );
hoursSpinner.setMaximum( 23 );
hoursSpinner.setTextLimit( 2 );
hoursSpinner.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false ) );
Label label1 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
label1.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
// Minutes
minutesSpinner = new Spinner( rightComposite, SWT.BORDER );
minutesSpinner.setMinimum( 0 );
minutesSpinner.setMaximum( 59 );
minutesSpinner.setTextLimit( 2 );
minutesSpinner.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, false, false ) );
Label label2 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
label2.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
// Seconds
secondsSpinner = new Spinner( rightComposite, SWT.BORDER );
secondsSpinner.setMinimum( 0 );
secondsSpinner.setMaximum( 59 );
secondsSpinner.setTextLimit( 2 );
secondsSpinner.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, false, false ) );
}
/**
* Creates the "Date" dialog area.
*
* @param parent
* the parent composite
*/
private void createDateDialogArea( Composite parent )
{
// Label
Label dateLabel = BaseWidgetUtils.createLabel( parent,
Messages.getString( "GeneralizedTimeValueDialog.Date" ), 1 ); //$NON-NLS-1$
dateLabel.setLayoutData( new GridData( SWT.NONE, SWT.TOP, false, false ) );
Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
// Calendar
dateCalendar = new DateTime( rightComposite, SWT.CALENDAR | SWT.BORDER );
dateCalendar.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
}
/**
* Creates the "Time Zone" dialog area.
*
* @param parent
* the parent composite
*/
private void createTimeZoneDialogArea( Composite parent )
{
// Label
BaseWidgetUtils.createLabel( parent, Messages.getString( "GeneralizedTimeValueDialog.Timezone" ), 1 ); //$NON-NLS-1$
// Combo viewer
timezoneComboViewer = new ComboViewer( parent );
GridData timezoneGridData = new GridData( SWT.FILL, SWT.CENTER, true, false );
timezoneGridData.widthHint = 50;
timezoneComboViewer.getCombo().setLayoutData( timezoneGridData );
// Adding ContentProvider, LabelProvider
timezoneComboViewer.setContentProvider( new ArrayContentProvider() );
timezoneComboViewer.setLabelProvider( new LabelProvider()
{
public String getText( Object element )
{
return ( ( TimeZone ) element ).getID();
}
} );
// Initializing the time zones list and map
initAllTimezones();
timezoneComboViewer.setInput( allTimezonesList );
}
/**
* Initializes all the time zones.
*/
private void initAllTimezones()
{
initUtcTimezones();
initContinentsAndCitiesTimezones();
}
/**
* Initializes all the "UTC+/-xxxx" time zones.
*/
private void initUtcTimezones()
{
addUtcTimezone( "UTC-12", -1 * ( 12 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-11", -1 * ( 11 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-10", -1 * ( 10 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-9:30", -1 * ( ( ( 9 * 60 ) + 30 ) * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-9", -1 * ( 9 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-8", -1 * ( 8 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-7", -1 * ( 7 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-6", -1 * ( 6 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-5", -1 * ( 5 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-4:30", -1 * ( ( ( 4 * 60 ) + 30 ) * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-4", -1 * ( 4 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-3:30", -1 * ( ( ( 3 * 60 ) + 30 ) * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-3", -1 * ( 3 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-2", -1 * ( 2 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC-1", -1 * ( 1 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
addUtcTimezone( "UTC", 0 ); //$NON-NLS-1$
addUtcTimezone( "UTC+1", 1 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+2", 2 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+3", 3 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+3:30", ( ( 3 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+4", 4 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+4:30", ( ( 4 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+5", 5 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+5:30", ( ( 5 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+5:45", ( ( 5 * 60 ) + 45 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+6", 6 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+6:30", ( ( 6 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+7", 7 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+8", 8 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+8:45", ( ( 8 * 60 ) + 45 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+9", 9 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+9:30", ( ( 9 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+10", 10 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+10:30", ( ( 10 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+11", 11 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+11:30", ( ( 11 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+12", 12 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+12:45", ( ( 12 * 60 ) + 45 ) * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+13", 13 * 60 * 60 * 1000 ); //$NON-NLS-1$
addUtcTimezone( "UTC+14", 14 * 60 * 60 * 1000 ); //$NON-NLS-1$
}
/**
* Adds an UTC time zone.
*
* @param tz
* a time zone to add
*/
private void addUtcTimezone( String id, int rawOffset )
{
TimeZone tz = rawOffset == 0 ? TimeZone.getTimeZone( "UTC" ) : new SimpleTimeZone( rawOffset, id ); //$NON-NLS-1$
allTimezonesList.add( tz );
utcTimezonesMap.put( rawOffset, tz );
}
/**
* Initializes all the continents and cities time zones.
*/
private void initContinentsAndCitiesTimezones()
{
List<TimeZone> continentsAndCitiesTimezonesList = new ArrayList<TimeZone>();
// Getting all e time zones from the following continents :
// * Africa
// * America
// * Asia
// * Atlantic
// * Australia
// * Europe
// * Indian
// * Pacific
for ( String timezoneId : TimeZone.getAvailableIDs() )
{
if ( timezoneId.matches( "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*" ) ) //$NON-NLS-1$
{
continentsAndCitiesTimezonesList.add( TimeZone.getTimeZone( timezoneId ) );
}
}
// Sorting the list by ID
Collections.sort( continentsAndCitiesTimezonesList, new Comparator<TimeZone>()
{
public int compare( final TimeZone a, final TimeZone b )
{
return a.getID().compareTo( b.getID() );
}
} );
allTimezonesList.addAll( continentsAndCitiesTimezonesList );
}
/**
* Creates the "Raw value" dialog area.
*
* @param parent
* the parent composite
*/
private void createRawValueDialogArea( Composite parent )
{
// Separator
Label separatorLabel = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) );
// Label
BaseWidgetUtils.createLabel( parent, Messages.getString( "GeneralizedTimeValueDialog.RawValue" ), 1 ); //$NON-NLS-1$
// Raw composite
Composite rawValueComposite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
// Text
rawValueText = BaseWidgetUtils.createText( rawValueComposite, "", 1 ); //$NON-NLS-1$
// Validator image
rawValueValidatorImage = new Label( rawValueComposite, SWT.NONE );
// Discard fraction checkbox
discardFractionCheckbox = BaseWidgetUtils.createCheckbox( parent,
Messages.getString( "GeneralizedTimeValueDialog.DiscardFraction" ), 2 );
validateRawValue( true );
}
/**
* Initializes the UI with the value.
*/
private void initWithInitialValue()
{
updateNonRawFields();
updateRawFields();
}
/**
* Update the non-raw UI fields.
*/
private void updateNonRawFields()
{
Calendar calendar = value.getCalendar();
// Time
hoursSpinner.setSelection( calendar.get( Calendar.HOUR_OF_DAY ) );
minutesSpinner.setSelection( calendar.get( Calendar.MINUTE ) );
secondsSpinner.setSelection( calendar.get( Calendar.SECOND ) );
// Date
dateCalendar.setDate( calendar.get( Calendar.YEAR ), calendar.get( Calendar.MONTH ), calendar
.get( Calendar.DAY_OF_MONTH ) );
// Time zone
TimeZone timezone = utcTimezonesMap.get( new Integer( calendar.getTimeZone().getRawOffset() ) );
if ( timezone == null )
{
timezoneComboViewer.setSelection( null );
}
else
{
timezoneComboViewer.setSelection( new StructuredSelection( timezone ) );
}
}
/**
* Update the raw UI fields.
*/
private void updateRawFields()
{
// Raw value
if ( discardFractionCheckbox.getSelection() )
{
rawValueText.setText( value.toGeneralizedTimeWithoutFraction() );
}
else
{
rawValueText.setText( value.toGeneralizedTime() );
}
validateRawValue( true );
}
/**
* Validates the raw value.
*
* @param bool
* <code>true</code> to set the raw value as valid
* <code>false</code> to set the raw value as invalid
*/
private void validateRawValue( boolean bool )
{
if ( bool )
{
rawValueValidatorImage.setImage( ValueEditorsActivator.getDefault().getImage(
ValueEditorsConstants.IMG_TEXTFIELD_OK ) );
}
else
{
rawValueValidatorImage.setImage( ValueEditorsActivator.getDefault().getImage(
ValueEditorsConstants.IMG_TEXTFIELD_ERROR ) );
}
if ( okButton != null && !okButton.isDisposed() )
{
okButton.setEnabled( bool );
}
}
/**
* Adds the listeners to the UI fields.
*/
private void addListeners()
{
// Hours
hoursSpinner.addModifyListener( hoursModifyListener );
// Minutes
minutesSpinner.addModifyListener( minutesModifyListener );
// Seconds
secondsSpinner.addModifyListener( secondsModifyListener );
// Calendar
dateCalendar.addSelectionListener( dateSelectionListener );
// Time zone
timezoneComboViewer.addSelectionChangedListener( timezoneSelectionChangedListener );
// Raw value
rawValueText.addModifyListener( rawValueModifyListener );
// Discard fraction checkbox
discardFractionCheckbox.addSelectionListener( discardFractionCheckboxSelectionListener );
}
/**
* Removes the listeners from the UI fields.
*/
private void removeListeners()
{
// Hours
hoursSpinner.removeModifyListener( hoursModifyListener );
// Minutes
minutesSpinner.removeModifyListener( minutesModifyListener );
// Seconds
secondsSpinner.removeModifyListener( secondsModifyListener );
// Calendar
dateCalendar.removeSelectionListener( dateSelectionListener );
// Time zone
timezoneComboViewer.removeSelectionChangedListener( timezoneSelectionChangedListener );
// Raw value
rawValueText.removeModifyListener( rawValueModifyListener );
// Discard fraction checkbox
discardFractionCheckbox.removeSelectionListener( discardFractionCheckboxSelectionListener );
}
/**
* Updates the value using the non raw fields.
*/
private void updateValueFromNonRawFields()
{
// Retain the format of the GeneralizedTime value
// by only updating its calendar object.
Calendar calendar = value.getCalendar();
// Time
calendar.set( Calendar.HOUR_OF_DAY, hoursSpinner.getSelection() );
calendar.set( Calendar.MINUTE, minutesSpinner.getSelection() );
calendar.set( Calendar.SECOND, secondsSpinner.getSelection() );
// Date
calendar.set( Calendar.YEAR, dateCalendar.getYear() );
calendar.set( Calendar.MONTH, dateCalendar.getMonth() );
calendar.set( Calendar.DAY_OF_MONTH, dateCalendar.getDay() );
// Time zone
StructuredSelection selection = ( StructuredSelection ) timezoneComboViewer.getSelection();
if ( ( selection != null ) && ( !selection.isEmpty() ) )
{
calendar.setTimeZone( ( TimeZone ) selection.getFirstElement() );
}
}
/**
* Gets the {@link GeneralizedTime} value.
*
* @return
* the {@link GeneralizedTime} value
*/
public GeneralizedTime getGeneralizedTime()
{
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/uuid/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/uuid/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.valueeditors.uuid;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
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
{
/** 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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/uuid/InPlaceUuidValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/uuid/InPlaceUuidValueEditor.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.valueeditors.uuid;
import org.apache.commons.codec.binary.Hex;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.HexValueEditor;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.1.16.1 (UUID), e.g. used by entryUUID.
*
* Currently only the getDisplayValue() method is implemented.
* For modification the raw string must be edited.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class InPlaceUuidValueEditor extends HexValueEditor
{
private static final String UUID_REGEX = "^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$"; //$NON-NLS-1$
/**
* {@inheritDoc}
*/
public String getDisplayValue( IValue value )
{
if ( !showRawValues() )
{
Object rawValue = super.getRawValue( value );
if ( rawValue instanceof byte[] )
{
byte[] bytes = ( byte[] ) rawValue;
String string = Strings.utf8ToString( bytes );
if ( string.matches( UUID_REGEX ) || Strings.isEmpty( string ) )
{
return string;
}
else
{
return convertToString( bytes );
}
}
}
return super.getDisplayValue( value );
}
String convertToString( byte[] bytes )
{
if ( bytes == null || bytes.length != 16 )
{
return Messages.getString( "InPlaceUuidValueEditor.InvalidUuid" ); //$NON-NLS-1$
}
char[] hex = Hex.encodeHex( bytes );
StringBuffer sb = new StringBuffer();
sb.append( hex, 0, 8 );
sb.append( '-' );
sb.append( hex, 8, 4 );
sb.append( '-' );
sb.append( hex, 12, 4 );
sb.append( '-' );
sb.append( hex, 16, 4 );
sb.append( '-' );
sb.append( hex, 20, 12 );
return Strings.toLowerCase( 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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectSidValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectSidValueEditor.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.valueeditors.msad;
import org.apache.commons.codec.binary.Hex;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.HexValueEditor;
/**
* Implementation of IValueEditor for Microsoft Active Directory attribute 'objectSid'.
*
* Currently only the getDisplayValue() method is implemented.
* For modification the raw string must be edited.
*
* See <a href="http://msdn.microsoft.com/en-us/library/cc230371(PROT.10).aspx">
* http://msdn.microsoft.com/en-us/library/cc230371(PROT.10).aspx</a> for details.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class InPlaceMsAdObjectSidValueEditor extends HexValueEditor
{
/**
* {@inheritDoc}
*/
public String getDisplayValue( IValue value )
{
if ( !showRawValues() )
{
Object rawValue = super.getRawValue( value );
if ( rawValue instanceof byte[] )
{
byte[] bytes = ( byte[] ) rawValue;
return convertToString( bytes );
}
}
return super.getDisplayValue( value );
}
protected String convertToString( byte[] bytes )
{
/*
* The binary data structure, from http://msdn.microsoft.com/en-us/library/cc230371(PROT.10).aspx:
* byte[0] - Revision (1 byte): An 8-bit unsigned integer that specifies the revision level of the SID structure. This value MUST be set to 0x01.
* byte[1] - SubAuthorityCount (1 byte): An 8-bit unsigned integer that specifies the number of elements in the SubAuthority array. The maximum number of elements allowed is 15.
* byte[2-7] - IdentifierAuthority (6 bytes): A SID_IDENTIFIER_AUTHORITY structure that contains information, which indicates the authority under which the SID was created. It describes the entity that created the SID and manages the account.
* Six element arrays of 8-bit unsigned integers that specify the top-level authority
* big-endian!
* and then - SubAuthority (variable): A variable length array of unsigned 32-bit integers that uniquely identifies a principal relative to the IdentifierAuthority. Its length is determined by SubAuthorityCount.
* little-endian!
*/
if ( ( bytes == null ) || ( bytes.length < 8 ) )
{
return Messages.getString( "InPlaceMsAdObjectSidValueEditor.InvalidSid" ); //$NON-NLS-1$
}
char[] hex = Hex.encodeHex( bytes );
StringBuffer sb = new StringBuffer();
// start with 'S'
sb.append( 'S' );
// revision
int revision = Integer.parseInt( new String( hex, 0, 2 ), 16 );
sb.append( '-' );
sb.append( revision );
// get count
int count = Integer.parseInt( new String( hex, 2, 2 ), 16 );
// check length
if ( bytes.length != ( 8 + count * 4 ) )
{
return Messages.getString( "InPlaceMsAdObjectSidValueEditor.InvalidSid" ); //$NON-NLS-1$
}
// get authority, big-endian
long authority = Long.parseLong( new String( hex, 4, 12 ), 16 );
sb.append( '-' );
sb.append( authority );
// sub-authorities, little-endian
for ( int i = 0; i < count; i++ )
{
StringBuffer rid = new StringBuffer();
for ( int k = 3; k >= 0; k-- )
{
rid.append( hex[16 + ( i * 8 ) + ( k * 2 )] );
rid.append( hex[16 + ( i * 8 ) + ( k * 2 ) + 1] );
}
long subAuthority = Long.parseLong( rid.toString(), 16 );
sb.append( '-' );
sb.append( subAuthority );
}
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/msad/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/msad/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.valueeditors.msad;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
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
{
/** 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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectGuidValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/msad/InPlaceMsAdObjectGuidValueEditor.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.valueeditors.msad;
import org.apache.commons.codec.binary.Hex;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.HexValueEditor;
/**
* Implementation of IValueEditor for Microsoft Active Directory attribute 'objectGUID'.
*
* Currently only the getDisplayValue() method is implemented.
* For modification the raw string must be edited.
*
* There are two special characteristics compared to the default UUID editor:
* <ul>
* <li>The first 64 bit of the MS AD GUID are little-endian, so we must reorder the bytes.
* See <a href="http://msdn.microsoft.com/en-us/library/dd302644(PROT.10).aspx">
* http://msdn.microsoft.com/en-us/library/dd302644(PROT.10).aspx</a> or
* <a href="http://en.wikipedia.org/wiki/Globally_Unique_Identifier">
* http://en.wikipedia.org/wiki/Globally_Unique_Identifier</a>.
* <li>The Curly Braced GUID String Syntax is used.
* See <a href="http://msdn.microsoft.com/en-us/library/cc230316(PROT.10).aspx">
* http://msdn.microsoft.com/en-us/library/cc230316(PROT.10).aspx</a>.
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class InPlaceMsAdObjectGuidValueEditor extends HexValueEditor
{
public String getDisplayValue( IValue value )
{
if ( !showRawValues() )
{
Object rawValue = super.getRawValue( value );
if ( rawValue instanceof byte[] )
{
byte[] bytes = ( byte[] ) rawValue;
return convertToString( bytes );
}
}
return super.getDisplayValue( value );
}
String convertToString( byte[] bytes )
{
if (( bytes == null ) || ( bytes.length != 16 ) )
{
return Messages.getString( "InPlaceMsAdObjectGuidValueEditor.InvalidGuid" ); //$NON-NLS-1$
}
char[] hex = Hex.encodeHex( bytes );
StringBuffer sb = new StringBuffer();
sb.append( '{' );
sb.append( hex, 6, 2 );
sb.append( hex, 4, 2 );
sb.append( hex, 2, 2 );
sb.append( hex, 0, 2 );
sb.append( '-' );
sb.append( hex, 10, 2 );
sb.append( hex, 8, 2 );
sb.append( '-' );
sb.append( hex, 14, 2 );
sb.append( hex, 12, 2 );
sb.append( '-' );
sb.append( hex, 16, 4 );
sb.append( '-' );
sb.append( hex, 20, 12 );
sb.append( '}' );
return Strings.toLowerCase( 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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/administrativerole/AdministrativeRoleDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/administrativerole/AdministrativeRoleDialog.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.valueeditors.administrativerole;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter;
import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ComboContentAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* This class provides a dialog to enter or select an administrative role.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AdministrativeRoleDialog extends Dialog
{
/** The possible administrative role values. */
private static final String[] administrativeRoleValues = new String[]
{ "autonomousArea", "accessControlSpecificArea", "accessControlInnerArea", "subschemaAdminSpecificArea", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"collectiveAttributeSpecificArea", "collectiveAttributeInnerArea", "triggerExecutionSpecificArea", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"triggerExecutionInnerArea" }; //$NON-NLS-1$
/** The initial value. */
private String initialValue;
/** The administrative role combo. */
private Combo administrativeRoleCombo;
/** The return value. */
private String returnValue;
/**
* Creates a new instance of AdministrativeRoleDialog.
*
* @param parentShell the parent shell
* @param initialValue the initial value
*/
public AdministrativeRoleDialog( Shell parentShell, String initialValue )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.initialValue = initialValue;
this.returnValue = null;
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "AdministrativeRoleDialog.AdministrativeRoleEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault()
.getImage( ValueEditorsConstants.IMG_ADMINISTRATIVEROLEEDITOR ) );
}
/**
* {@inheritDoc}
*/
protected void createButtonsForButtonBar( Composite parent )
{
super.createButtonsForButtonBar( parent );
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
returnValue = administrativeRoleCombo.getText();
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
// create composite
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
composite.setLayoutData( gd );
// attribute combo with field decoration and content proposal
administrativeRoleCombo = BaseWidgetUtils.createCombo( composite, new String[0], -1, 1 );
administrativeRoleCombo.setVisibleItemCount( 20 );
administrativeRoleCombo.setItems( administrativeRoleValues );
administrativeRoleCombo.setText( initialValue );
new ExtendedContentAssistCommandAdapter( administrativeRoleCombo, new ComboContentAdapter(),
new ListContentProposalProvider( administrativeRoleCombo.getItems() ), null, null, true );
applyDialogFont( composite );
return composite;
}
/**
* Gets the administrative role.
*
* @return the administrative role
*/
public String getAdministrativeRole()
{
return returnValue;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/administrativerole/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/administrativerole/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.valueeditors.administrativerole;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/administrativerole/AdministrativeRoleValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/administrativerole/AdministrativeRoleValueEditor.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.valueeditors.administrativerole;
import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for attribute administrativeRole.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AdministrativeRoleValueEditor extends AbstractDialogStringValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the AdministrativeRoleDialog.
*/
public boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof String )
{
AdministrativeRoleDialog dialog = new AdministrativeRoleDialog( shell, ( String ) value );
if ( ( dialog.open() == TextDialog.OK ) && !"".equals( dialog.getAdministrativeRole() ) ) //$NON-NLS-1$
{
setValue( dialog.getAdministrativeRole() );
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/dn/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/dn/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.valueeditors.dn;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/dn/DnValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/dn/DnValueEditor.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.valueeditors.dn;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.studio.ldapbrowser.common.dialogs.DnDialog;
import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.12
* (Distinguished Name).
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class DnValueEditor extends AbstractDialogStringValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the DnDialog.
*/
protected boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof DnValueEditorRawValueWrapper )
{
DnValueEditorRawValueWrapper wrapper = ( DnValueEditorRawValueWrapper ) value;
Dn dn;
try
{
dn = wrapper.dn != null ? new Dn( wrapper.dn ) : null;
}
catch ( LdapInvalidDnException e )
{
dn = null;
}
DnDialog dialog = new DnDialog( shell,
Messages.getString( "DnValueEditor.DNEditor" ), null, wrapper.connection, dn ); //$NON-NLS-1$
if ( dialog.open() == TextDialog.OK && dialog.getDn() != null )
{
setValue( dialog.getDn().getName() );
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*
* Returns a DnValueEditorRawValueWrapper with the connection of
* the attribute hierarchy and a null Dn if there are no values
* in attributeHierarchy.
*
* Returns a DnValueEditorRawValueWrapper with the connection of
* the attribute hierarchy and a Dn if there is one value
* in attributeHierarchy.
*/
public Object getRawValue( AttributeHierarchy attributeHierarchy )
{
if ( attributeHierarchy == null )
{
return null;
}
else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 0 )
{
IBrowserConnection connection = attributeHierarchy.getAttribute().getEntry().getBrowserConnection();
return new DnValueEditorRawValueWrapper( connection, null );
}
else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 1 )
{
IBrowserConnection connection = attributeHierarchy.getAttribute().getEntry().getBrowserConnection();
return new DnValueEditorRawValueWrapper( connection, getDisplayValue( attributeHierarchy ) );
}
else
{
return null;
}
}
/**
* {@inheritDoc}
*
* Returns a DnValueEditorRawValueWrapper with the connection of
* the value and a Dn build from the given value.
*/
public Object getRawValue( IValue value )
{
Object o = super.getRawValue( value );
if ( o instanceof String )
{
IBrowserConnection connection = value.getAttribute().getEntry().getBrowserConnection();
return new DnValueEditorRawValueWrapper( connection, ( String ) o );
}
return null;
}
/**
* The DnValueEditorRawValueWrapper is used to pass contextual
* information to the opened DnDialog.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
private class DnValueEditorRawValueWrapper
{
/** The connection, used in DnDialog to browse for an entry */
private IBrowserConnection connection;
/** The Dn, used as initial value in DnDialog */
private String dn;
/**
* Creates a new instance of DnValueEditorRawValueWrapper.
*
* @param connection the connection
* @param dn the Dn
*/
private DnValueEditorRawValueWrapper( IBrowserConnection connection, String dn )
{
this.connection = connection;
this.dn = dn;
}
/**
* {@inheritDoc}
*/
public String toString()
{
return dn == null ? "" : dn; //$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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.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.valueeditors.objectclass;
import org.apache.directory.api.ldap.model.schema.ObjectClass;
import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog;
import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
import org.eclipse.swt.widgets.Shell;
/**
* Implementation of IValueEditor for attribute objectClass.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ObjectClassValueEditor extends AbstractDialogStringValueEditor
{
/**
* {@inheritDoc}
*
* This implementation opens the ObjectClassDialog.
*/
public boolean openDialog( Shell shell )
{
Object value = getValue();
if ( value instanceof ObjectClassValueEditorRawValueWrapper )
{
ObjectClassValueEditorRawValueWrapper wrapper = ( ObjectClassValueEditorRawValueWrapper ) value;
ObjectClassDialog dialog = new ObjectClassDialog( shell, wrapper.schema, wrapper.objectClass );
if ( dialog.open() == TextDialog.OK && !"".equals( dialog.getObjectClass() ) ) //$NON-NLS-1$
{
setValue( dialog.getObjectClass() );
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*
* This implementation appends the kind of object class,
* on of structural, abstract, auxiliary or obsolete.
*/
public String getDisplayValue( IValue value )
{
if ( getRawValue( value ) == null )
{
return NULL;
}
String displayValue = value.getStringValue();
if ( !showRawValues() && !"".equals( displayValue ) ) //$NON-NLS-1$
{
Schema schema = value.getAttribute().getEntry().getBrowserConnection().getSchema();
ObjectClass ocd = schema.getObjectClassDescription( displayValue );
switch ( ocd.getType() )
{
case STRUCTURAL:
displayValue = displayValue + Messages.getString( "ObjectClassValueEditor.Structural" ); //$NON-NLS-1$
break;
case ABSTRACT:
displayValue = displayValue + Messages.getString( "ObjectClassValueEditor.Abstract" ); //$NON-NLS-1$
break;
case AUXILIARY:
displayValue = displayValue + Messages.getString( "ObjectClassValueEditor.Auxiliary" ); //$NON-NLS-1$
break;
}
if ( ocd.isObsolete() )
{
displayValue = displayValue + Messages.getString( "ObjectClassValueEditor.Obsolete" ); //$NON-NLS-1$
}
}
return displayValue;
}
/**
* {@inheritDoc}
*
* Returns null.
* Modification in search result editor not supported.
*/
public Object getRawValue( AttributeHierarchy attributeHierarchy )
{
return null;
}
/**
* {@inheritDoc}
*
* Returns a ObjectClassValueEditorRawValueWrapper.
*/
public Object getRawValue( IValue value )
{
if ( value == null || !value.isString() || !value.getAttribute().isObjectClassAttribute() )
{
return null;
}
else
{
return getRawValue( value.getAttribute().getEntry().getBrowserConnection(), value.getStringValue() );
}
}
private Object getRawValue( IBrowserConnection connection, Object value )
{
Schema schema = null;
if ( connection != null )
{
schema = connection.getSchema();
}
if ( !( value instanceof String ) )
{
return null;
}
String ocValue = ( String ) value;
ObjectClassValueEditorRawValueWrapper wrapper = new ObjectClassValueEditorRawValueWrapper( schema, ocValue );
return wrapper;
}
/**
* The ObjectClassValueEditorRawValueWrapper is used to pass contextual
* information to the opened ObjectClassDialog.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
private class ObjectClassValueEditorRawValueWrapper
{
/**
* The schema, used in ObjectClassDialog to build the list
* with possible object classes.
*/
private Schema schema;
/** The object class, used as initial value in ObjectClassDialog. */
private String objectClass;
/**
* Creates a new instance of ObjectClassValueEditorRawValueWrapper.
*
* @param schema the schema
* @param objectClass the object class
*/
private ObjectClassValueEditorRawValueWrapper( Schema schema, String objectClass )
{
super();
this.schema = schema;
this.objectClass = objectClass;
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/Messages.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/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.valueeditors.objectclass;
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassDialog.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.valueeditors.objectclass;
import java.util.Arrays;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter;
import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider;
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.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ComboContentAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* This class provides a dialog to enter or select an object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ObjectClassDialog extends Dialog
{
/** The schema. */
private Schema schema;
/** The initial value. */
private String initialValue;
/** The object class combo. */
private Combo objectClassCombo;
/** The return value. */
private String returnValue;
/**
* Creates a new instance of ObjectClassDialog.
*
* @param parentShell the parent shell
* @param schema the schema
* @param initialValue the initial value
*/
public ObjectClassDialog( Shell parentShell, Schema schema, String initialValue )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.initialValue = initialValue;
this.schema = schema;
this.returnValue = null;
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "ObjectClassDialog.ObjectClassEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_OCDEDITOR ) );
}
/**
* {@inheritDoc}
*/
protected void createButtonsForButtonBar( Composite parent )
{
super.createButtonsForButtonBar( parent );
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
returnValue = objectClassCombo.getText();
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
// create composite
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
composite.setLayoutData( gd );
// combo widget
String[] allOcNames = SchemaUtils.getNamesAsArray( schema.getObjectClassDescriptions() );
Arrays.sort( allOcNames );
// attribute combo with field decoration and content proposal
objectClassCombo = BaseWidgetUtils.createCombo( composite, new String[0], -1, 1 );
objectClassCombo.setVisibleItemCount( 20 );
objectClassCombo.setItems( allOcNames );
objectClassCombo.setText( initialValue );
new ExtendedContentAssistCommandAdapter( objectClassCombo, new ComboContentAdapter(),
new ListContentProposalProvider( objectClassCombo.getItems() ), null, null, true );
applyDialogFont( composite );
return composite;
}
/**
* Gets the object class.
*
* @return the object class, null if canceled
*/
public String getObjectClass()
{
return returnValue;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.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.valueeditors.oid;
import org.apache.directory.api.ldap.model.schema.syntaxCheckers.OidSyntaxChecker;
import org.apache.directory.studio.connection.core.Utils;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractInPlaceStringValueEditor;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.38
* (OID syntax).
*
* Currently only the getDisplayXXX() methods are implemented.
* For modification the raw string must be edited.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class InPlaceOidValueEditor extends AbstractInPlaceStringValueEditor
{
/**
* {@inheritDoc}
*/
public String getDisplayValue( IValue value )
{
String displayValue = super.getDisplayValue( value );
if ( !showRawValues() )
{
String description = Utils.getOidDescription( displayValue );
if ( description != null )
{
displayValue = displayValue + " (" + description + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
return displayValue;
}
@Override
public Object getRawValue( IValue value )
{
Object rawValue = super.getRawValue( value );
// DIRSTUDIO-1216: allows relaxed OID syntax with underscore, e.g. for Oracle or DirX
if ( rawValue instanceof String
&& OidSyntaxChecker.INSTANCE.isValidSyntax( ( ( String ) rawValue ).replace( "_", "-" ) ) )
{
return rawValue;
}
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/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java | plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.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.valueeditors.bool;
import org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker;
import org.apache.directory.studio.ldapbrowser.core.model.IValue;
import org.apache.directory.studio.valueeditors.AbstractInPlaceStringValueEditor;
import org.eclipse.jface.viewers.ICellEditorValidator;
/**
* Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.7
* (Boolean syntax).
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class InPlaceBooleanValueEditor extends AbstractInPlaceStringValueEditor
{
/** The 'TRUE' value */
private static final String TRUE = "TRUE";
/** The 'FALSE' value */
private static final String FALSE = "FALSE";
/**
* Create a new instance of a InPlaceBooleanValueEditor which sets
* a validator.
*/
public InPlaceBooleanValueEditor()
{
super();
setValidator(new ICellEditorValidator()
{
@Override
public String isValid( Object value )
{
if ( value instanceof String )
{
String stringValue = ( ( String ) value ).toUpperCase();
switch ( stringValue )
{
case "F" :
case "FALSE" :
case "N" :
case "NO" :
case "0" :
case "T" :
case "TRUE" :
case "Y" :
case "YES" :
case "1" :
case "" : // Special case : default to TRUE
return null;
default :
return "Invalid boolean";
}
}
else
{
return "Invalid boolean";
}
}
});
}
/**
* {@inheritDoc}
*/
@Override
protected Object doGetValue()
{
Object value = super.doGetValue();
if ( value instanceof String )
{
String stringValue = ( String ) value;
switch ( stringValue.toUpperCase() )
{
case "F" :
case "FALSE" :
case "N" :
case "NO" :
case "0" :
return FALSE;
case "T" :
case "TRUE" :
case "Y" :
case "YES" :
case "1" :
case "" : // Special case : default to TRUE
return TRUE;
default :
return stringValue;
}
}
return value;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isValueValid()
{
return doGetValue() != null;
}
/**
* {@inheritDoc}
*/
@Override
public Object getRawValue( IValue value )
{
Object rawValue = super.getRawValue( value );
if ( rawValue instanceof String )
{
String stringValue = ( String ) rawValue;
if ( ( stringValue.length() == 0 ) || ( BooleanSyntaxChecker.INSTANCE.isValidSyntax( stringValue ) ) )
{
return rawValue;
}
else
{
return null;
}
}
else if ( rawValue == null )
{
return TRUE;
}
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/openldap.common.ui/src/test/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsTest.java | plugins/openldap.common.ui/src/test/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsTest.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.openldap.common.ui.dialogs;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.apache.directory.studio.openldap.common.ui.model.UnixPermissions;
import org.junit.jupiter.api.Test;
public class UnixPermissionsTest
{
@Test
public void testEmpty() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testFail() throws Exception
{
try
{
new UnixPermissions( "0123456789" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testOctal1() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0157" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal2() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0266" );
assertFalse( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal3() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0375" );
assertFalse( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal4() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0404" );
assertTrue( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal5() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0513" );
assertTrue( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal6() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0622" );
assertTrue( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal7() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0731" );
assertTrue( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testOctal8() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "0040" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal1() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "111" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal2() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "182" );
assertFalse( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal3() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "253" );
assertFalse( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal4() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "260" );
assertTrue( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal5() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "331" );
assertTrue( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal6() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "402" );
assertTrue( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal7() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "473" );
assertTrue( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testDecimal8() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "32" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic1() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "---xr-xrwx" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic2() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "--w-rw-rw-" );
assertFalse( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic3() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "--wxrwxr-x" );
assertFalse( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic4() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "-r-----r--" );
assertTrue( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertTrue( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic5() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "-r-x--x-wx" );
assertTrue( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic6() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "-rw--w--w-" );
assertTrue( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertTrue( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic7() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "-rwx-wx--x" );
assertTrue( unixPermissions.isOwnerRead() );
assertTrue( unixPermissions.isOwnerWrite() );
assertTrue( unixPermissions.isOwnerExecute() );
assertFalse( unixPermissions.isGroupRead() );
assertTrue( unixPermissions.isGroupWrite() );
assertTrue( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertTrue( unixPermissions.isOthersExecute() );
}
@Test
public void testSymbolic8() throws Exception
{
UnixPermissions unixPermissions = new UnixPermissions( "----r-----" );
assertFalse( unixPermissions.isOwnerRead() );
assertFalse( unixPermissions.isOwnerWrite() );
assertFalse( unixPermissions.isOwnerExecute() );
assertTrue( unixPermissions.isGroupRead() );
assertFalse( unixPermissions.isGroupWrite() );
assertFalse( unixPermissions.isGroupExecute() );
assertFalse( unixPermissions.isOthersRead() );
assertFalse( unixPermissions.isOthersWrite() );
assertFalse( unixPermissions.isOthersExecute() );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/OpenLdapCommonUiConstants.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/OpenLdapCommonUiConstants.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.openldap.common.ui;
/**
* Contains constants for the value editors.
* Final reference -> class shouldn't be extended
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public final class OpenLdapCommonUiConstants
{
/**
* 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 OpenLdapCommonUiConstants()
{
}
/** The plug-in ID */
public static final String PLUGIN_ID = OpenLdapCommonUiConstants.class.getPackage().getName();
public static final String DIALOGSETTING_KEY_DIRECTORY_HISTORY = "directoryHistory"; //$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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/Messages.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/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.openldap.common.ui;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* The messages handling
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Messages
{
private static final ResourceBundle RESOURCE_BUNDLE =
ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" );
private Messages()
{
}
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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/OpenLdapCommonUiPlugin.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/OpenLdapCommonUiPlugin.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.openldap.common.ui;
import java.io.IOException;
import java.net.URL;
import java.util.PropertyResourceBundle;
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.swt.graphics.Image;
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 OpenLdapCommonUiPlugin extends AbstractUIPlugin
{
/** The shared instance */
private static OpenLdapCommonUiPlugin plugin;
/** The plugin properties */
private PropertyResourceBundle properties;
/**
* The constructor
*/
public OpenLdapCommonUiPlugin()
{
plugin = this;
}
/**
* {@inheritDoc}
*/
public void start( BundleContext context ) throws Exception
{
super.start( context );
}
/**
* {@inheritDoc}
*/
public void stop( BundleContext context ) throws Exception
{
plugin = null;
super.stop( context );
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static OpenLdapCommonUiPlugin getDefault()
{
return plugin;
}
/**
* Use this method to get SWT images. Use the IMG_ constants from
* ValueEditorConstants for the key.
*
* @param key The key (relative path to the image im filesystem)
* @return The image discriptor 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
* ValueEditorConstants 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 on filesystem)
* @return The SWT Image or null
* @see OpenLdapCommonUiConstants
*/
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( 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.openldap.common.ui", Status.OK, //$NON-NLS-1$
Messages.getString( "OpenLdapCommonUiPlugin.UnableGetPluginProperties" ), 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LimitSelectorEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LimitSelectorEnum.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.openldap.common.ui.model;
/**
* An enumeration of all the possible olcLimits selectors
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum LimitSelectorEnum
{
ANY( "*" ),
ANONYMOUS( "anonymous" ),
USERS( "users" ),
DNSPEC( "dn" ),
GROUP( "group" ),
NONE( "---" );
/** The associated name */
private String name;
/**
* Creates a selector instance
*/
private LimitSelectorEnum( String name )
{
this.name = name;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( LimitSelectorEnum limitSelector : values() )
{
names[pos] = limitSelector.name;
pos++;
}
return names;
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param name The name to retrieve
* @return The LimitSelectorEnum instance found, or NONE.
*/
public static LimitSelectorEnum getSelector( String name )
{
for ( LimitSelectorEnum selector : values() )
{
if ( selector.name.equalsIgnoreCase( name ) )
{
return selector;
}
}
return NONE;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DatabaseTypeEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DatabaseTypeEnum.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.openldap.common.ui.model;
/**
* The various Database types. One of :
* <ul>
* <li>None</li>
* <li>Frontend DB</li>
* <li>Config DB</li>
* <li>BDB</li>
* <li>DB Perl</li>
* <li>DB_Socket</li>
* <li>HDB</li>
* <li>MDB</li>
* <li>LDAP</li>
* <li>LDIF</li>
* <li>META</li>
* <li>MONITOR</li>
* <li>NDB</li>
* <li>PASSWORD</li>
* <li>RELAY</li>
* <li>SHELL</li>
* <li>SQL DB</li>
* <li>NULL</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum DatabaseTypeEnum
{
/** None */
NONE("None"),
/** Frontend DB */
FRONTEND("Frontend DB"),
/** Config DB */
CONFIG("Config DB"),
/** Berkeley DB */
BDB("BDB (Berkeley DB)"),
/** DB Perl */
DB_PERL("DB Perl"),
/** DB Socket */
DB_SOCKET("DB Socket"),
/** Hierarchical Berkeley DB */
HDB("HDB (Hierarchical Berkeley DB)"),
/** LDAP DB*/
LDAP("LDAP DB"),
/** LDIF DB*/
LDIF("LDIF DB"),
/** META DB*/
META("META DB"),
/** Memory-Mapped DB */
MDB("MDB (Memory-Mapped DB)"),
/** MONITOR DB*/
MONITOR("MONITOR DB"),
/** NDB DB*/
NDB("NDB DB"),
/** Null DB*/
NULL("Null DB"),
/** PASSWD DB */
PASSWD("PASSWD DB"),
/** Relay DB*/
RELAY("Relay DB"),
/** Shell DB*/
SHELL("Shell DB"),
/** SQL DB*/
SQL("SQL DB");
/** The internal name of the database */
private String name;
/** A private constructor with the name as a parameter */
private DatabaseTypeEnum( String name )
{
this.name = name;
}
/**
* @return the DatabaseType name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( DatabaseTypeEnum databaseType : values() )
{
names[pos] = databaseType.name;
pos++;
}
return names;
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param name The name to retrieve
* @return The DatabaseTypeEnum instance found, or NONE.
*/
public static DatabaseTypeEnum getDatabaseType( String name )
{
for ( DatabaseTypeEnum databaseType : values() )
{
if ( name.equalsIgnoreCase( databaseType.name() ) || name.equalsIgnoreCase( databaseType.getName() ) )
{
return databaseType;
}
}
return NONE;
}
} | java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/RequireConditionEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/RequireConditionEnum.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.openldap.common.ui.model;
/**
* An enum for the various possible value of the olcRequires parameter. Some of
* <ul>
* <li>authc</li>
* <li>bind</li>
* <li>LDAPv3</li>
* <li>none</li>
* <li>sasl</li>
* <li>strong</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum RequireConditionEnum
{
UNKNOWN( "---" ),
AUTHC( "authc" ),
BIND( "bind" ),
LDAP_V3( "LDAPv3" ),
NONE( "none" ),
SASL( "sasl" ),
STRONG( "strong" );
/** The interned name */
private String name;
/**
* A private constructor for this enum
*/
private RequireConditionEnum( String name )
{
this.name = name;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( RequireConditionEnum requireCondition : values() )
{
names[pos] = requireCondition.name;
pos++;
}
return names;
}
/**
* Get the RequireConditionEnum instance from its number
*
* @param number The number we are looking for
* @return The associated RequireConditionEnum instance
*/
public static RequireConditionEnum getCondition( int number )
{
RequireConditionEnum[] values = RequireConditionEnum.values();
if ( ( number > 0 ) && ( number < values.length ) )
{
return values[number];
}
else
{
return UNKNOWN;
}
}
/**
* Return an instance of RequireConditionEnum from a String
*
* @param name The condition's name
* @return The associated RequireConditionEnum
*/
public static RequireConditionEnum getCondition( String name )
{
for ( RequireConditionEnum requireCondition : values() )
{
if ( requireCondition.name.equalsIgnoreCase( name ) )
{
return requireCondition;
}
}
return UNKNOWN;
}
/**
* @see Object#toString()
*/
public String toString()
{
return 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/SaslSecPropEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/SaslSecPropEnum.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.openldap.common.ui.model;
/**
* An enum for the various possible value of the olcSaslSecProps parameter.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum SaslSecPropEnum
{
NONE( "none", false ),
NO_PLAIN( "noplain", false ),
NO_ACTIVE( "noactive", false ),
NO_DICT( "nodict", false ),
NO_ANONYMOUS( "noanonymous", false ),
FORWARD_SEC( "forwardsec", false ),
PASS_CRED( "passcred", false ),
MIN_SSF( "minssf", true ),
MAX_SSF( "maxssf", true ),
MAX_BUF_SIZE( "maxbufsize", true ),
UNKNOWN( "---", false);
/** The interned name */
private String name;
/** A flag set when the property has a value */
private boolean hasValue;
/**
* A private constructor for this enum
*/
private SaslSecPropEnum( String name, boolean hasValue )
{
this.name = name;
this.hasValue = hasValue;
}
/**
* Return the SaslSecPropEnum associated with a String
*
* @param name The name we are looking for
* @return The associated SaslSecPropEnum
*/
public static SaslSecPropEnum getSaslSecProp( String name )
{
for ( SaslSecPropEnum saslSecProp : values() )
{
if ( saslSecProp.name.equalsIgnoreCase( name ) )
{
return saslSecProp;
}
}
return UNKNOWN;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( SaslSecPropEnum saslSecProp : values() )
{
names[pos] = saslSecProp.name;
pos++;
}
return names;
}
/**
* @return the hasValue flag
*/
public boolean hasValue()
{
return hasValue;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/AllowFeatureEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/AllowFeatureEnum.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.openldap.common.ui.model;
/**
* An enum for the various possible value of the olcAllows parameter. Some of
* <ul>
* <li>bind_v2</li>
* <li>bind_anon_cred</li>
* <li>bind_anon_dn</li>
* <li>update_anon</li>
* <li>proxy_authz_anon</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum AllowFeatureEnum
{
UNKNOWN( "---" ),
BIND_ANON_CRED( "bind_anon_cred" ),
BIND_ANON_DN( "bind_anon_dn" ),
BIND_V2( "bind_v2" ),
PROXY_AUTHZ_ANON( "proxy_authz_anon" ),
UPDATE_ANON( "update_anon" );
/** The interned name */
private String name;
/**
* A private constructor for this enum
*/
private AllowFeatureEnum( String name )
{
this.name = name;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( AllowFeatureEnum allowFeature : values() )
{
names[pos] = allowFeature.name;
pos++;
}
return names;
}
/**
* Get the AllowFeatureEnumd instance from its number
*
* @param number The number we are looking for
* @return The associated AllowFeatureEnum instance
*/
public static AllowFeatureEnum getAllowFeature( int number )
{
AllowFeatureEnum[] values = AllowFeatureEnum.values();
if ( ( number > 0 ) && ( number < values.length ) )
{
return values[number];
}
else
{
return UNKNOWN;
}
}
/**
* Return an instance of AllowFeatureEnum from a String
*
* @param name The feature's name
* @return The associated AllowFeatureEnum
*/
public static AllowFeatureEnum getAllowFeature( String name )
{
for ( AllowFeatureEnum allowFeature : values() )
{
if ( allowFeature.name.equalsIgnoreCase( name ) )
{
return allowFeature;
}
}
return UNKNOWN;
}
/**
* @see Object#toString()
*/
public String toString()
{
return 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/SsfFeatureEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/SsfFeatureEnum.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.openldap.common.ui.model;
/**
* An enumeration of all the possible SSF features.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum SsfFeatureEnum
{
SSF( "ssf" ),
TRANSPORT( "transport" ),
TLS( "tls" ),
SASL( "sasl" ),
UPDATE_SSF( "update_ssf" ),
UPDATE_TRANSPORT( "update_transport" ),
UPDATE_TLS( "update_tls" ),
UPDATE_SASL( "update_sasl" ),
SIMPLE_BIND( "simple_bind" ),
NONE( "---" );
/** The associated name */
private String name;
/**
* Creates an SsfEnum instance
*/
private SsfFeatureEnum( String name )
{
this.name = name;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( SsfFeatureEnum ssfFeature : values() )
{
names[pos] = ssfFeature.name;
pos++;
}
return names;
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param name The namr to retrieve
* @return The SsfEnum instance found, or NONE.
*/
public static SsfFeatureEnum getSsfFeature( String name )
{
for ( SsfFeatureEnum ssfFeature : values() )
{
if ( ssfFeature.name.equalsIgnoreCase( name ) )
{
return ssfFeature;
}
}
return NONE;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/SsfStrengthEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/SsfStrengthEnum.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.openldap.common.ui.model;
/**
* An enumeration of all the possible SSF strengths.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum SsfStrengthEnum
{
NONE( -1, "None" ),
NO_PROTECTION( 0, "No protection" ),
INTEGRITY_CHECK(1, "Integrity check" ),
DES( 56, "DES" ),
THREE_DES( 112, "3DES" ),
AES_128( 128, "AES-128" ),
AES_256( 256, "AES-256" );
/** The associated name */
private String name;
/** The SSF strength position */
private int nbBits;
/**
* Creates an SsfEnum instance
*/
private SsfStrengthEnum( int nbBits, String name )
{
this.nbBits = nbBits;
this.name = name;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( SsfStrengthEnum ssfStrength : values() )
{
names[pos] = ssfStrength.name;
pos++;
}
return names;
}
/**
* @return the number of bits
*/
public int getNbBits()
{
return nbBits;
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param feature The feature to retrieve
* @return The SsfEnum instance found, or NONE.
*/
public static SsfStrengthEnum getSsfStrength( int nbBits )
{
switch ( nbBits )
{
case 0 : return NO_PROTECTION;
case 1 : return INTEGRITY_CHECK;
case 56 : return DES;
case 112 : return THREE_DES;
case 128 : return AES_128;
case 256 : return AES_256;
default : return NONE;
}
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param text The text we are looking for
* @return The SsfEnum instance found, or NONE.
*/
public static SsfStrengthEnum getSsfStrength( String text )
{
for ( SsfStrengthEnum ssfStrength : values() )
{
if ( ssfStrength.name.equalsIgnoreCase( text ) )
{
return ssfStrength;
}
}
// Default...
return NONE;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/OverlayTypeEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/OverlayTypeEnum.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.openldap.common.ui.model;
/**
* This enum represents the list of Overlays
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum OverlayTypeEnum
{
/** Access Log */
ACCESS_LOG( "Access Log" ),
/** Audit Log */
AUDIT_LOG( "Audit Log" ),
/** Member Of */
MEMBER_OF( "Member Of" ),
/** Password Policy */
PASSWORD_POLICY( "Password Policy" ),
/** Referential Integrity */
REFERENTIAL_INTEGRITY( "Referential Integrity" ),
/** Rewrite/Remap */
REWRITE_REMAP( "Rewrite/Remap" ),
/** Sync Prov (Replication) */
SYNC_PROV( "Sync Prov (Replication)" ),
/** Value Sorting */
VALUE_SORTING( "Value Sorting" ),
/** Unknown */
UNKNOWN( "" );
/** The Overlay name */
private String name;
/**
* Create an instance of an OverlayTypeEnum
*/
private OverlayTypeEnum( String name )
{
this.name = name;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* Return an instance of OverlayTypeEnum from a String
*
* @param name The overlay's name
* @return The associated OverlayTypeEnum
*/
public static OverlayTypeEnum getOverlay( String name )
{
for ( OverlayTypeEnum overlay : values() )
{
if ( overlay.name.equalsIgnoreCase( name ) )
{
return overlay;
}
}
return UNKNOWN;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( OverlayTypeEnum overlayType : values() )
{
names[pos] = overlayType.name;
pos++;
}
return names;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DisallowFeatureEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DisallowFeatureEnum.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.openldap.common.ui.model;
/**
* An enum for the various possible value of the olcDisallows parameter. One of
* <ul>
* <li>bind_anon</li>
* <li>bind_simple</li>
* <li>tls_2_anon</li>
* <li>tls_authc</li>
* <li>proxy_authz_non_critical</li>
* <li>dontusecopy_non_critical</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum DisallowFeatureEnum
{
UNKNOWN( "---" ),
BIND_ANON( "bind_anon" ),
BIND_SIMPLE( "bind_simple" ),
TLS_2_ANON( "tls_2_anon" ),
TLS_AUTHC( "tls_authc" ),
PROXY_AUTHZ_NON_CRITICAL( "proxy_authz_non_critical" ),
DONTUSECOPY_NON_CRITICAL( "dontusecopy_non_critical" );
/** The interned name */
private String name;
/**
* A private constructor for this enum
*/
private DisallowFeatureEnum( String name )
{
this.name = name;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( DisallowFeatureEnum disallowFeature : values() )
{
names[pos] = disallowFeature.name;
pos++;
}
return names;
}
/**
* Get the DisallowFeatureEnumd instance from its number
*
* @param number The number we are looking for
* @return The associated DisallowFeatureEnum instance
*/
public static DisallowFeatureEnum getFeature( int number )
{
DisallowFeatureEnum[] values = DisallowFeatureEnum.values();
if ( ( number > 0 ) && ( number < values.length ) )
{
return values[number];
}
else
{
return UNKNOWN;
}
}
/**
* Return an instance of DisallowFeatureEnum from a String
*
* @param name The feature's name
* @return The associated DisallowFeatureEnum
*/
public static DisallowFeatureEnum getFeature( String name )
{
for ( DisallowFeatureEnum disallowFeature : values() )
{
if ( disallowFeature.name.equalsIgnoreCase( name ) )
{
return disallowFeature;
}
}
return UNKNOWN;
}
/**
* @see Object#toString()
*/
public String toString()
{
return 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DnSpecStyleEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DnSpecStyleEnum.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.openldap.common.ui.model;
/**
* An enumeration of all the possible olcLimits selector dnspec style
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum DnSpecStyleEnum
{
EXACT( "exact" ),
BASE( "base" ),
ONE( "one" ),
ONE_LEVEL( "onelevel" ),
SUB( "sub" ),
SUBTREE( "subtree" ),
CHILDREN( "children" ),
REGEXP( "regexp" ),
ANONYMOUS( "anonymous" ),
NONE( "---" );
/** The associated name */
private String name;
/**
* Creates a dnspec style instance
*/
private DnSpecStyleEnum( String name )
{
this.name = name;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param name The name to retrieve
* @return The DnSpecTypeEnum instance found, or NONE.
*/
public static DnSpecStyleEnum getStyle( String name )
{
for ( DnSpecStyleEnum dnSpecStyle : values() )
{
if ( dnSpecStyle.name.equalsIgnoreCase( name ) )
{
return dnSpecStyle;
}
}
return NONE;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( DnSpecStyleEnum dnSpecStyle : values() )
{
names[pos] = dnSpecStyle.name;
pos++;
}
return names;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/RestrictOperationEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/RestrictOperationEnum.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.openldap.common.ui.model;
/**
* An enum for the various possible value of the olcRestrict parameter. Some of
* <ul>
* <li>add</li>
* <li>all</li>
* <li>bind</li>
* <li>compare</li>
* <li>delete</li>
* <li>extended</li>
* <li>extended=1.3.6.1.4.1.1466.20037</li>
* <li>extended=1.3.6.1.4.1.4203.1.11.1</li>
* <li>extended=1.3.6.1.4.1.4203.1.11.3</li>
* <li>extended=1.3.6.1.1.8</li>
* <li>modify</li>
* <li>modrdn</li>
* <li>read</li>
* <li>rename</li>
* <li>search</li>
* <li>write</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum RestrictOperationEnum
{
UNKNOWN( "---", "" ),
ADD( "add", "add" ),
ALL( "all", "all" ),
BIND( "bind", "bind" ),
COMPARE( "compare", "compare" ),
DELETE( "delete", "delete" ),
EXTENDED( "extended", "extended" ),
EXTENDED_START_TLS( "extended=1.3.6.1.4.1.1466.20037", "START_TLS" ),
EXTENDED_MODIFY_PASSWD( "extended=1.3.6.1.4.1.4203.1.11.1", "MODIFY_PASSWORD" ),
EXTENDED_WHOAMI( "extended=1.3.6.1.4.1.4203.1.11.3", "WHOAMI" ),
EXTENDED_CANCEL( "extended=1.3.6.1.1.8", "CANCEL" ),
MODIFY( "modify", "modify" ),
MODRDN( "modrdn", "modrdn" ),
READ( "read", "read" ),
RENAME( "rename", "rename" ),
SEARCH( "search", "search" ),
WRITE( "write", "write" );
/** The interned name */
private String name;
/** The externalized name */
private String externalName;
/**
* A private constructor for this enum
*/
private RestrictOperationEnum( String name, String externalName )
{
this.name = name;
this.externalName = externalName;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( RestrictOperationEnum restrictOperation : values() )
{
names[pos] = restrictOperation.name;
pos++;
}
return names;
}
/**
* @return the external name
*/
public String getExternalName()
{
return externalName;
}
/**
* Get the RestrictOperationEnum instance from its number
*
* @param number The number we are looking for
* @return The associated RestrictOperationEnum instance
*/
public static RestrictOperationEnum getOperation( int number )
{
RestrictOperationEnum[] values = RestrictOperationEnum.values();
if ( ( number > 0 ) && ( number < values.length ) )
{
return values[number];
}
else
{
return UNKNOWN;
}
}
/**
* Return an instance of RestrictOperationEnum from a String
*
* @param name The operation's name
* @return The associated RestrictOperationEnum
*/
public static RestrictOperationEnum getRestrictOperation( String name )
{
for ( RestrictOperationEnum restrictOperation : values() )
{
if ( restrictOperation.name.equalsIgnoreCase( name ) )
{
return restrictOperation;
}
}
return UNKNOWN;
}
/**
* @see Object#toString()
*/
public String toString()
{
return externalName;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LogLevelEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LogLevelEnum.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.openldap.common.ui.model;
/**
* The various LogLevel values :
* <ul>
* <li>none 0</li>
* <li>trace 1</li>
* <li>packets 2</li>
* <li>args 4</li>
* <li>conns 8</li>
* <li>BER 16</li>
* <li>filter 32</li>
* <li>config 64</li>
* <li>ACL 128</li>
* <li>stats 256</li>
* <li>stats2 512</li>
* <li>shell 1024</li>
* <li>parse 2048</li>
* <li>sync 16384</li>
* <li>any -1</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum LogLevelEnum
{
NONE( "none", 0 ),
TRACE( "trace", 1 ),
PACKETS( "packets", 2 ),
ARGS( "args", 4 ),
CONNS( "conns", 8 ),
BER( "ber", 16 ),
FILTER( "filter", 32 ),
CONFIG( "config", 64 ),
ACL( "acl", 128 ),
STATS( "stats", 256 ),
STATS2( "stats2", 512 ),
SHELL( "shell", 1024 ),
PARSE( "parse", 2048 ),
// 4096 not used
// 8196 not used
SYNC( "sync", 16384 ),
// 327168 and -1 are equivalent
ANY( "any", -1 );
/** The inner value */
private int value;
/** The inner name */
private String name;
/**
* Creates a new instance of LogLevel.
*
* @param value The internal value
*/
private LogLevelEnum( String name, int value )
{
this.name = name;
this.value = value;
}
/**
* @return The internal integer value
*/
public int getValue()
{
return value;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( LogLevelEnum logLevel : values() )
{
names[pos] = logLevel.name;
pos++;
}
return names;
}
/**
* @param logLevel The integer value of the LogLevel
* @return A String representation of the Log Level
*/
public static String getLogLevelText( int logLevel )
{
if ( logLevel == NONE.value )
{
return "none";
}
if ( logLevel == ANY.value )
{
return "any";
}
StringBuilder sb = new StringBuilder();
if ( ( logLevel & ACL.value ) != 0 )
{
sb.append( "ACL " );
}
if ( ( logLevel & ARGS.value ) != 0 )
{
sb.append( "args " );
}
if ( ( logLevel & BER.value ) != 0 )
{
sb.append( "BER " );
}
if ( ( logLevel & CONFIG.value ) != 0 )
{
sb.append( "config " );
}
if ( ( logLevel & CONNS.value ) != 0 )
{
sb.append( "conns " );
}
if ( ( logLevel & FILTER.value ) != 0 )
{
sb.append( "filter " );
}
if ( ( logLevel & PACKETS.value ) != 0 )
{
sb.append( "packets " );
}
if ( ( logLevel & PARSE.value ) != 0 )
{
sb.append( "parse " );
}
if ( ( logLevel & SHELL.value ) != 0 )
{
sb.append( "shell " );
}
if ( ( logLevel & STATS.value ) != 0 )
{
sb.append( "stats " );
}
if ( ( logLevel & STATS2.value ) != 0 )
{
sb.append( "stats2 " );
}
if ( ( logLevel & SYNC.value ) != 0 )
{
sb.append( "sync " );
}
if ( ( logLevel & TRACE.value ) != 0 )
{
sb.append( "trace " );
}
return sb.toString();
}
/**
* Get the integer value associated with a name
*
* @param name The name we are looking for
* @return The associated integer
*/
public static int getIntegerValue( String name )
{
if ( ( name == null ) || ( name.length() == 0 ) )
{
throw new IllegalArgumentException( "Wrong LogLevel name : " + name );
}
if ( "acl".equalsIgnoreCase( name ) )
{
return ACL.value;
}
if ( "any".equalsIgnoreCase( name ) )
{
return ANY.value;
}
if ( "args".equalsIgnoreCase( name ) )
{
return ARGS.value;
}
if ( "ber".equalsIgnoreCase( name ) )
{
return BER.value;
}
if ( "config".equalsIgnoreCase( name ) )
{
return CONFIG.value;
}
if ( "conns".equalsIgnoreCase( name ) )
{
return CONNS.value;
}
if ( "filter".equalsIgnoreCase( name ) )
{
return FILTER.value;
}
if ( "none".equalsIgnoreCase( name ) )
{
return NONE.value;
}
if ( "packets".equalsIgnoreCase( name ) )
{
return PACKETS.value;
}
if ( "parse".equalsIgnoreCase( name ) )
{
return PARSE.value;
}
if ( "shell".equalsIgnoreCase( name ) )
{
return SHELL.value;
}
if ( "stats".equalsIgnoreCase( name ) )
{
return STATS.value;
}
if ( "stats2".equalsIgnoreCase( name ) )
{
return STATS2.value;
}
if ( "sync".equalsIgnoreCase( name ) )
{
return SYNC.value;
}
if ( "trace".equalsIgnoreCase( name ) )
{
return TRACE.value;
}
throw new IllegalArgumentException( "Wrong LogLevel name : " + name );
}
/**
* Parses a LogLevel provided as a String. The format is the following :
* <pre>
* <logLevel> ::= ( Integer | Hex | <Name> )*
* <name> ::= 'none' | 'any' | 'ACL' | 'args' | 'BER' | 'config' | 'conns' |
* 'filter' | 'packets' | 'parse' | 'stats' | 'stats2' | 'sync' | 'trace'
* ;; Nore : those names are case insensitive
* </pre>
* TODO parseLogLevel.
*
* @param logLevelString
* @return
*/
public static int parseLogLevel( String logLevelString )
{
if ( ( logLevelString == null ) || ( logLevelString.length() == 0 ) )
{
return 0;
}
int currentPos = 0;
char[] chars = logLevelString.toCharArray();
int logLevel = 0;
while ( currentPos < chars.length )
{
// Skip the ' ' at the beginning
while ( ( currentPos < chars.length ) && ( chars[currentPos] == ' ' ) )
{
currentPos++;
}
if ( currentPos >= chars.length )
{
break;
}
// Now, start analysing what's next
switch ( chars[currentPos] )
{
case 'a' :
case 'A' :
// ACL, ANY or ARGS
if ( parseName( chars, currentPos, "ACL" ) )
{
// ACL
currentPos += 3;
logLevel |= ACL.value;
}
else if ( parseName( chars, currentPos, "ANY" ) )
{
// ANY
currentPos += 3;
logLevel |= ANY.value;
}
else if ( parseName( chars, currentPos, "ARGS" ) )
{
// ARGS
currentPos += 4;
logLevel |= ARGS.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'b' :
case 'B' :
// BER
if ( parseName( chars, currentPos, "BER" ) )
{
// BER
currentPos += 3;
logLevel |= BER.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'c' :
case 'C' :
// CONFIG or CONNS
if ( parseName( chars, currentPos, "CONFIG" ) )
{
// CONFIG
currentPos += 6;
logLevel |= CONFIG.value;
}
else if ( parseName( chars, currentPos, "CONNS" ) )
{
// CONNS
currentPos += 5;
logLevel |= CONNS.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'f' :
case 'F' :
// FILTER
if ( parseName( chars, currentPos, "FILTER" ) )
{
// FILTER
currentPos += 6;
logLevel |= FILTER.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'n' :
case 'N' :
// NONE
if ( parseName( chars, currentPos, "NONE" ) )
{
// NONE
currentPos += 4;
logLevel |= NONE.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 'p' :
case 'P' :
// PACKETS or PARSE
if ( parseName( chars, currentPos, "PACKETS" ) )
{
// PACKETS
currentPos += 7;
logLevel |= PACKETS.value;
}
else if ( parseName( chars, currentPos, "PARSE" ) )
{
// PARSE
currentPos += 5;
logLevel |= PARSE.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 's' :
case 'S' :
// SHELL, STATS, STATS2 or SYNC
if ( parseName( chars, currentPos, "SHELL" ) )
{
// SHELL
currentPos += 5;
logLevel |= SHELL.value;
}
else if ( parseName( chars, currentPos, "STATS" ) )
{
// STATS
currentPos += 5;
logLevel |= STATS.value;
}
else if ( parseName( chars, currentPos, "STATS2" ) )
{
// STATS2
currentPos += 6;
logLevel |= STATS2.value;
}
else if ( parseName( chars, currentPos, "SYNC" ) )
{
// SYNC
currentPos += 4;
logLevel |= SYNC.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case 't' :
case 'T' :
// TRACE
if ( parseName( chars, currentPos, "TRACE" ) )
{
// TRACE
currentPos += 5;
logLevel |= TRACE.value;
}
else
{
// Wrong name
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
break;
case '0' :
// Numeric or hexa ?
currentPos++;
if ( currentPos < chars.length )
{
if ( ( chars[currentPos] == 'x' ) || ( chars[currentPos] == 'X' ) )
{
// Hex
currentPos++;
boolean done = false;
int numValue = 0;
while ( ( currentPos < chars.length ) && !done )
{
switch ( chars[currentPos] )
{
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
numValue = numValue*16 + chars[currentPos] - '0';
currentPos++;
break;
case 'a' :
case 'b' :
case 'c' :
case 'd' :
case 'e' :
case 'f' :
numValue = numValue*16 + 10 + chars[currentPos] - 'a';
currentPos++;
break;
case 'A' :
case 'B' :
case 'C' :
case 'D' :
case 'E' :
case 'F' :
numValue = numValue*16 + 10 + chars[currentPos] - 'A';
currentPos++;
break;
case ' ' :
logLevel |= numValue;
done = true;
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
// Special case : we are at the end of the STring
if ( !done )
{
logLevel |= numValue;
}
}
}
else
{
// decimal value
boolean done = false;
int numValue = 0;
while ( ( currentPos < chars.length ) && !done )
{
switch ( chars[currentPos] )
{
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
numValue = numValue*10 + chars[currentPos] - '0';
currentPos++;
break;
case ' ' :
logLevel |= numValue;
done = true;
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
}
// Special case : we are at the end of the STring
if ( !done )
{
logLevel |= numValue;
}
}
}
break;
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
// Numeric
int numValue = chars[currentPos] - '0';
currentPos++;
boolean done = false;
while ( ( currentPos < chars.length ) && !done )
{
switch ( chars[currentPos] )
{
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
numValue = numValue*10 + chars[currentPos] - '0';
currentPos++;
break;
case ' ' :
logLevel |= numValue;
done = true;
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
}
// Special case : we are at the end of the STring
if ( !done )
{
logLevel |= numValue;
}
break;
default :
throw new IllegalArgumentException( "Wrong LogLevel at " + currentPos + " : " + logLevelString );
}
}
return logLevel;
}
/**
* Checks that a LogLevel name is correct
*/
private static boolean parseName( char[] chars, int pos, String expected )
{
for ( int current = 0; current < expected.length(); current++ )
{
if ( pos + current < chars.length )
{
char c = chars[pos+ current];
char e = expected.charAt( current );
if ( ( c != e ) && ( c != e + ( 'a' - 'A' ) ) )
{
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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DnSpecTypeEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DnSpecTypeEnum.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.openldap.common.ui.model;
/**
* An enumeration of all the possible olcLimits selector dnspec type
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum DnSpecTypeEnum
{
SELF( "self" ),
THIS( "this" ),
NONE( "---" );
/** The associated name */
private String name;
/**
* Creates a dnspec type instance
*/
private DnSpecTypeEnum( String name )
{
this.name = name;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* Retrieve the instance associated to a String. Return NONE if not found.
*
* @param name The name to retrieve
* @return The DnSpecTypeEnum instance found, or NONE.
*/
public static DnSpecTypeEnum getType( String name )
{
for ( DnSpecTypeEnum dnSpecType : values() )
{
if ( dnSpecType.name.equalsIgnoreCase( name ) )
{
return dnSpecType;
}
}
return NONE;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( DnSpecTypeEnum dnSpecType : values() )
{
names[pos] = dnSpecType.name;
pos++;
}
return names;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/AuthzPolicyEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/AuthzPolicyEnum.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.openldap.common.ui.model;
/**
* An enum for the various possible value of the olcAuthzPolicy parameter. One of
* <ul>
* <li>none</li>
* <li>from</li>
* <li>to</li>
* <li>any</li>
* <li>all</li>
* <li>both</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum AuthzPolicyEnum
{
ALL( "all" ),
ANY( "any" ),
BOTH( "both" ),
FROM( "from" ),
NONE( "none" ),
TO( "to" ),
UNKNOWN( "---" );
/** The interned name */
private String name;
/**
* A private constructor for this enum
*/
private AuthzPolicyEnum( String name )
{
this.name = name;
}
/**
* Return an instance of AuthzPolicyEnum from a String
*
* @param name The policy's name
* @return The associated AuthzPolicyEnum
*/
public static AuthzPolicyEnum getAuthzPolicy( String name )
{
for ( AuthzPolicyEnum authzPolicy : values() )
{
if ( authzPolicy.name.equalsIgnoreCase( name ) )
{
return authzPolicy;
}
}
return UNKNOWN;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( AuthzPolicyEnum authzPolicy : values() )
{
names[pos] = authzPolicy.name;
pos++;
}
return names;
}
/**
* @return the name
*/
public String getName()
{
return 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/PasswordHashEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/PasswordHashEnum.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.openldap.common.ui.model;
/**
* The list of Password Hashes choices
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum PasswordHashEnum
{
NO_CHOICE( 0,"" ),
CLEARTEXT( 1, "{CLEARTEXT}" ),
CRYPT( 2, "{CRYPT}" ),
LANMAN( 3, "{LANMAN}" ),
MD5( 4, "{MD5}" ),
SMD5( 5, "{SMD5}" ),
SHA( 6, "{SHA}" ),
SSHA( 7, "{SSHA}" ),
UNIX( 8, "{UNIX}" );
/** The hash number */
private int number;
/** The interned name */
private String name;
/**
* A private constructor for this enum
*/
private PasswordHashEnum( int number, String name )
{
this.name = name;
this.number = number;
}
/**
* @return The Password Hash name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( PasswordHashEnum passwordHash : values() )
{
names[pos] = passwordHash.name;
pos++;
}
return names;
}
/**
* @return The Password Hash number
*/
public int getNumber()
{
return number;
}
/**
* Get the PasswordHashEnum instance from its number
*
* @param number The number we are looking for
* @return The associated PasswordHashEnum instance
*/
public static PasswordHashEnum getPasswordHash( int number )
{
switch ( number )
{
case 1 : return CLEARTEXT;
case 2 : return CRYPT;
case 3 : return LANMAN;
case 4 : return MD5;
case 5 : return SMD5;
case 6 : return SHA;
case 7 : return SSHA;
case 8 : return UNIX;
default : return NO_CHOICE;
}
}
/**
* Get the PasswordHashEnum instance from its number
*
* @param number The number we are looking for
* @return The associated PasswordHashEnum instance
*/
public static PasswordHashEnum getPasswordHash( String name )
{
for ( PasswordHashEnum passwordHash : values() )
{
if ( passwordHash.name.equalsIgnoreCase( name ) )
{
return passwordHash;
}
}
return NO_CHOICE;
}
/**
* @see Object#toString()
*/
public String toString()
{
return 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/UnixPermissions.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/UnixPermissions.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.openldap.common.ui.model;
import java.text.ParseException;
import java.util.regex.Pattern;
/**
* The class defines an Unix Permissions.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class UnixPermissions
{
/** The pattern used to match a symbolic value (e.g. "-rw-------") */
private static final Pattern SYMBOLIC_FORMAT_PATTERN = Pattern.compile(
"^-(-|r)(-|w)(-|x)(-|r)(-|w)(-|x)(-|r)(-|w)(-|x)$", Pattern.CASE_INSENSITIVE );
private boolean ownerRead;
private boolean ownerWrite;
private boolean ownerExecute;
private boolean groupRead;
private boolean groupWrite;
private boolean groupExecute;
private boolean othersRead;
private boolean othersWrite;
private boolean othersExecute;
/**
* Creates a new instance of UnixPermissions.
*
*/
public UnixPermissions()
{
}
/**
* Creates a new instance of UnixPermissions.
*
* @param s the string
* @throws ParseException if an error occurs during the parsing of the string
*/
public UnixPermissions( String s ) throws ParseException
{
if ( ( s != null ) && ( !s.isEmpty() ) )
{
// First let's trim the value
String trimmed = s.trim();
int integerValue = -1;
try
{
integerValue = Integer.parseInt( trimmed );
}
catch ( NumberFormatException e )
{
// Silent, integerValue will be -1.
}
// Is it an octal value?
if ( trimmed.startsWith( "0" ) )
{
if ( trimmed.length() == 4 )
{
readOwnerOctalValue( trimmed.charAt( 1 ) );
readGroupOctalValue( trimmed.charAt( 2 ) );
readOthersOctalValue( trimmed.charAt( 3 ) );
}
else
{
throw new ParseException( "Unable to recognize the format for this Unix Permissions String '" + s
+ "'.", 0 );
}
}
// Is it a decimal value?
else if ( integerValue != -1 )
{
String octal = Integer.toOctalString( integerValue );
if ( octal.length() == 1 )
{
octal = "00" + octal;
}
else if ( octal.length() == 2 )
{
octal = "0" + octal;
}
readOwnerOctalValue( octal.charAt( 0 ) );
readGroupOctalValue( octal.charAt( 1 ) );
readOthersOctalValue( octal.charAt( 2 ) );
}
// Is it a symbolic value?
else if ( SYMBOLIC_FORMAT_PATTERN.matcher( trimmed ).matches() )
{
readOwnerSymbolicValue( trimmed.substring( 1, 4 ) );
readGroupSymbolicValue( trimmed.substring( 4, 7 ) );
readOthersSymbolicValue( trimmed.substring( 7, 10 ) );
}
else
{
throw new ParseException( "Unable to recognize the format for this Unix Permissions String '" + s
+ "'.", 0 );
}
}
}
/**
* Reads the owner octal value.
*
* @param ownerValue the owner value
*/
private void readOwnerOctalValue( char ownerValue )
{
if ( ownerValue == '1' )
{
ownerExecute = true;
}
else if ( ownerValue == '2' )
{
ownerWrite = true;
}
else if ( ownerValue == '3' )
{
ownerExecute = true;
ownerWrite = true;
}
else if ( ownerValue == '4' )
{
ownerRead = true;
}
else if ( ownerValue == '5' )
{
ownerExecute = true;
ownerRead = true;
}
else if ( ownerValue == '6' )
{
ownerWrite = true;
ownerRead = true;
}
else if ( ownerValue == '7' )
{
ownerExecute = true;
ownerWrite = true;
ownerRead = true;
}
}
/**
* Reads the group octal value.
*
* @param groupValue the group value
*/
private void readGroupOctalValue( char groupValue )
{
if ( groupValue == '1' )
{
groupExecute = true;
}
else if ( groupValue == '2' )
{
groupWrite = true;
}
else if ( groupValue == '3' )
{
groupExecute = true;
groupWrite = true;
}
else if ( groupValue == '4' )
{
groupRead = true;
}
else if ( groupValue == '5' )
{
groupExecute = true;
groupRead = true;
}
else if ( groupValue == '6' )
{
groupWrite = true;
groupRead = true;
}
else if ( groupValue == '7' )
{
groupExecute = true;
groupWrite = true;
groupRead = true;
}
}
/**
* Reads the others octal value.
*
* @param othersValue the others value
*/
private void readOthersOctalValue( char othersValue )
{
if ( othersValue == '1' )
{
othersExecute = true;
}
else if ( othersValue == '2' )
{
othersWrite = true;
}
else if ( othersValue == '3' )
{
othersExecute = true;
othersWrite = true;
}
else if ( othersValue == '4' )
{
othersRead = true;
}
else if ( othersValue == '5' )
{
othersExecute = true;
othersRead = true;
}
else if ( othersValue == '6' )
{
othersWrite = true;
othersRead = true;
}
else if ( othersValue == '7' )
{
othersExecute = true;
othersWrite = true;
othersRead = true;
}
}
/**
* Reads the owner symbolic value.
*
* @param ownerValue the owner value
*/
private void readOwnerSymbolicValue( String ownerValue )
{
if ( ownerValue.length() == 3 )
{
// Read
if ( ownerValue.charAt( 0 ) == 'r' )
{
ownerRead = true;
}
// Write
if ( ownerValue.charAt( 1 ) == 'w' )
{
ownerWrite = true;
}
// Execute
if ( ownerValue.charAt( 2 ) == 'x' )
{
ownerExecute = true;
}
}
}
/**
* Reads the group symbolic value.
*
* @param groupValue the group value
*/
private void readGroupSymbolicValue( String groupValue )
{
if ( groupValue.length() == 3 )
{
// Read
if ( groupValue.charAt( 0 ) == 'r' )
{
groupRead = true;
}
// Write
if ( groupValue.charAt( 1 ) == 'w' )
{
groupWrite = true;
}
// Execute
if ( groupValue.charAt( 2 ) == 'x' )
{
groupExecute = true;
}
}
}
/**
* Reads the others symbolic value.
*
* @param othersValue the others value
*/
private void readOthersSymbolicValue( String othersValue )
{
if ( othersValue.length() == 3 )
{
// Read
if ( othersValue.charAt( 0 ) == 'r' )
{
othersRead = true;
}
// Write
if ( othersValue.charAt( 1 ) == 'w' )
{
othersWrite = true;
}
// Execute
if ( othersValue.charAt( 2 ) == 'x' )
{
othersExecute = true;
}
}
}
/**
* Gets the integer value.
*
* @return the integer value
*/
public Integer getDecimalValue()
{
return Integer.parseInt( getOctalValue(), 8 );
}
/**
* Gets the octal value.
*
* @return the octal value
*/
public String getOctalValue()
{
int value = 0;
// Owner Read
if ( ownerRead )
{
value = value + 400;
}
// Owner Write
if ( ownerWrite )
{
value = value + 200;
}
// Owner Execute
if ( ownerExecute )
{
value = value + 100;
}
// Group Read
if ( groupRead )
{
value = value + 40;
}
// Group Write
if ( groupWrite )
{
value = value + 20;
}
// Group Execute
if ( groupExecute )
{
value = value + 10;
}
// Others Read
if ( othersRead )
{
value = value + 4;
}
// Others Write
if ( othersWrite )
{
value = value + 2;
}
// Others Execute
if ( othersExecute )
{
value = value + 1;
}
// Adding zeros before returning the value
if ( value < 10 )
{
return "000" + value;
}
else if ( value < 100 )
{
return "00" + value;
}
else if ( value < 1000 )
{
return "0" + value;
}
else
{
return "" + value;
}
}
/**
* Gets the symbolic value (no type included).
*
* @return the symbolic value
*/
public String getSymbolicValue()
{
StringBuilder sb = new StringBuilder();
sb.append( '-' );
// Owner Read
if ( ownerRead )
{
sb.append( 'r' );
}
else
{
sb.append( '-' );
}
// Owner Write
if ( ownerWrite )
{
sb.append( 'w' );
}
else
{
sb.append( '-' );
}
// Owner Execute
if ( ownerExecute )
{
sb.append( 'x' );
}
else
{
sb.append( '-' );
}
// Group Read
if ( groupRead )
{
sb.append( 'r' );
}
else
{
sb.append( '-' );
}
// Group Write
if ( groupWrite )
{
sb.append( 'w' );
}
else
{
sb.append( '-' );
}
// Group Execute
if ( groupExecute )
{
sb.append( 'x' );
}
else
{
sb.append( '-' );
}
// Others Read
if ( othersRead )
{
sb.append( 'r' );
}
else
{
sb.append( '-' );
}
// Others Write
if ( othersWrite )
{
sb.append( 'w' );
}
else
{
sb.append( '-' );
}
// Others Execute
if ( othersExecute )
{
sb.append( 'x' );
}
else
{
sb.append( '-' );
}
return sb.toString();
}
public boolean isGroupExecute()
{
return groupExecute;
}
public boolean isGroupRead()
{
return groupRead;
}
public boolean isGroupWrite()
{
return groupWrite;
}
public boolean isOthersExecute()
{
return othersExecute;
}
public boolean isOthersRead()
{
return othersRead;
}
public boolean isOthersWrite()
{
return othersWrite;
}
public boolean isOwnerExecute()
{
return ownerExecute;
}
public boolean isOwnerRead()
{
return ownerRead;
}
public boolean isOwnerWrite()
{
return ownerWrite;
}
public void setGroupExecute( boolean groupExecute )
{
this.groupExecute = groupExecute;
}
public void setGroupRead( boolean groupRead )
{
this.groupRead = groupRead;
}
public void setGroupWrite( boolean groupWrite )
{
this.groupWrite = groupWrite;
}
public void setOthersExecute( boolean othersExecute )
{
this.othersExecute = othersExecute;
}
public void setOthersRead( boolean othersRead )
{
this.othersRead = othersRead;
}
public void setOthersWrite( boolean othersWrite )
{
this.othersWrite = othersWrite;
}
public void setOwnerExecute( boolean ownerExecute )
{
this.ownerExecute = ownerExecute;
}
public void setOwnerRead( boolean ownerRead )
{
this.ownerRead = ownerRead;
}
public void setOwnerWrite( boolean ownerWrite )
{
this.ownerWrite = ownerWrite;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LogOperationEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/LogOperationEnum.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.openldap.common.ui.model;
/**
* This enum represents the various access log operation.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum LogOperationEnum
{
WRITES( "writes" ),
ADD( "add" ),
DELETE( "delete" ),
MODIFY( "modify" ),
MODIFY_RDN( "modrdn" ),
READS( "reads" ),
COMPARE( "compare" ),
SEARCH( "search" ),
SESSION( "session" ),
ABANDON( "abandon" ),
BIND( "bind" ),
UNBIND( "unbind" ),
ALL( "all" );
/** The name */
private String name;
/**
* Creates a new instance of LogOperation.
*
* @param name the name
*/
private LogOperationEnum( String name )
{
this.name = name;
}
/**
* @return the text
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( LogOperationEnum logOperation : values() )
{
names[pos] = logOperation.name;
pos++;
}
return names;
}
/**
* Gets the log operation corresponding to the given string.
*
* @param s the string
* @return the corresponding log operation
*/
public static LogOperationEnum fromString( String s )
{
if ( s != null )
{
if ( s.equalsIgnoreCase( WRITES.name ) )
{
return WRITES;
}
else if ( s.equalsIgnoreCase( ADD.name ) )
{
return ADD;
}
else if ( s.equalsIgnoreCase( DELETE.name ) )
{
return DELETE;
}
else if ( s.equalsIgnoreCase( MODIFY.name ) )
{
return MODIFY;
}
else if ( s.equalsIgnoreCase( MODIFY_RDN.name ) )
{
return MODIFY_RDN;
}
else if ( s.equalsIgnoreCase( READS.name ) )
{
return READS;
}
else if ( s.equalsIgnoreCase( COMPARE.name ) )
{
return COMPARE;
}
else if ( s.equalsIgnoreCase( SEARCH.name ) )
{
return SEARCH;
}
else if ( s.equalsIgnoreCase( SESSION.name ) )
{
return SESSION;
}
else if ( s.equalsIgnoreCase( ABANDON.name ) )
{
return ABANDON;
}
else if ( s.equalsIgnoreCase( BIND.name ) )
{
return BIND;
}
else if ( s.equalsIgnoreCase( UNBIND.name ) )
{
return UNBIND;
}
else if ( s.equalsIgnoreCase( ALL.name ) )
{
return ALL;
}
}
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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DbIndexTypeEnum.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/model/DbIndexTypeEnum.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.openldap.common.ui.model;
/**
* The class defines the different kind of index that can be used :
* <ul>
* <li>approx</li>
* <li>eq</li>
* <li>nolang</li>
* <li>nosubtypes</li>
* <li>notags</li>
* <li>pres</li>
* <li>sub</li>
* <li>subany</li>
* <li>subfinal</li>
* <li>subinitial</li>
* <li>substr</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum DbIndexTypeEnum
{
APPROX( 0, "approx" ),
EQ( 1, "eq" ),
NOLANG( 2, "nolang" ),
NOSUBTYPES( 3, "nosubtypes" ),
NOTAGS( 4, "notags" ),
PRES( 5, "pres" ),
SUB( 6, "sub" ),
SUBANY( 7, "subany" ),
SUBFINAL( 8, "subfinal" ),
SUBINITIAL( 9, "subinitial" ),
SUBSTR( 10, "substr" ), // Same as SUB
NONE( 11, "none" );
/** The internal name */
private String name;
/** The internal number */
private int number;
/**
* A private constructor for this class
*/
private DbIndexTypeEnum( int number, String name )
{
this.name = name;
this.number = number;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @return An array with all the Enum value's name
*/
public static String[] getNames()
{
String[] names = new String[values().length];
int pos = 0;
for ( DbIndexTypeEnum dbIndexType : values() )
{
names[pos] = dbIndexType.name;
pos++;
}
return names;
}
/**
* @return the number
*/
public int getNumber()
{
return number;
}
/**
* Return an instance of DbIndexTypeEnum from a String
*
* @param name The indexType's name
* @return The associated DbIndexTypeEnum
*/
public static DbIndexTypeEnum getIndexType( String name )
{
for ( DbIndexTypeEnum indexType : values() )
{
if ( indexType.getName().equalsIgnoreCase( name ) )
{
if ( SUBSTR.getName().equalsIgnoreCase( name ) )
{
// SUB and SUBSTR are the same. Return SUB
return SUB;
}
else
{
return indexType;
}
}
}
return NONE;
}
/**
* Get the DbIndexTypeEnum instance from its number
*
* @param number The number we are looking for
* @return The associated DbIndexTypeEnum instance
*/
public static DbIndexTypeEnum getIndexType( int number )
{
switch ( number )
{
case 0 : return APPROX;
case 1 : return EQ;
case 2 : return NOLANG;
case 3 : return NOSUBTYPES;
case 4 : return NOTAGS;
case 5 : return PRES;
case 6 : return SUB;
case 7 : return SUBANY;
case 8 : return SUBFINAL;
case 9 : return SUBINITIAL;
case 10 : return SUBSTR;
default : return NONE;
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/EntryWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/EntryWidget.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.openldap.common.ui.widgets;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.studio.common.ui.HistoryUtils;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.ui.RunnableContextRunner;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectEntryDialog;
import org.apache.directory.studio.ldapbrowser.common.widgets.search.Messages;
import org.apache.directory.studio.ldapbrowser.core.jobs.ReadEntryRunnable;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* The EntryWidget could be used to select an entry.
* It is composed
* <ul>
* <li>a combo to manually enter an Dn or to choose one from
* the history
* <li>an up button to switch to the parent's Dn
* <li>a browse button to open a {@link SelectEntryDialog}
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class EntryWidget extends AbstractWidget
{
/** The connection. */
private IBrowserConnection browserConnection;
/** The flag to show the "None" checkbox or not */
private boolean showNoneCheckbox;
/** The selected Dn. */
private Dn dn;
/** The enabled state */
private boolean enabled = true;
// UI widgets
private Composite composite;
private Button noneCheckbox;
private Combo dnCombo;
private Button entryBrowseButton;
// Listeners
private SelectionAdapter noneCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
noneCheckboxSelected( noneCheckbox.getSelection() );
notifyListeners();
}
};
private ModifyListener dnComboListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
try
{
dn = new Dn( dnCombo.getText() );
}
catch ( LdapInvalidDnException e1 )
{
dn = null;
}
internalSetEnabled();
notifyListeners();
}
};
private SelectionAdapter entryBrowseButtonListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
if ( browserConnection != null )
{
// get root entry
IEntry rootEntry = browserConnection.getRootDSE();
// get initial entry
IEntry entry = rootEntry;
if ( ( dn != null ) && ( dn.size() > 0 ) )
{
entry = browserConnection.getEntryFromCache( dn );
if ( entry == null )
{
ReadEntryRunnable runnable = new ReadEntryRunnable( browserConnection, dn );
RunnableContextRunner.execute( runnable, null, true );
entry = runnable.getReadEntry();
}
}
// open dialog
SelectEntryDialog dialog = new SelectEntryDialog( entryBrowseButton.getShell(), Messages
.getString( "EntryWidget.SelectDN" ), rootEntry, entry ); //$NON-NLS-1$
dialog.open();
IEntry selectedEntry = dialog.getSelectedEntry();
// get selected Dn
if ( selectedEntry != null )
{
dn = selectedEntry.getDn();
dnChanged();
internalSetEnabled();
notifyListeners();
}
}
}
};
/**
* Creates a new instance of EntryWidget.
*/
public EntryWidget()
{
this.browserConnection = null;
this.dn = null;
}
/**
* Creates a new instance of EntryWidget.
*
* @param browserConnection the connection
*/
public EntryWidget( IBrowserConnection browserConnection )
{
this.browserConnection = browserConnection;
}
/**
* Creates a new instance of EntryWidget.
*
* @param browserConnection the connection
* @param dn the initial Dn
*/
public EntryWidget( IBrowserConnection browserConnection, Dn dn )
{
this.browserConnection = browserConnection;
this.dn = dn;
}
/**
* Creates a new instance of EntryWidget.
*
* @param browserConnection the connection
* @param dn the initial Dn
* @param showNoneButton the flag to show the "None" checkbox
*/
public EntryWidget( IBrowserConnection browserConnection, Dn dn, boolean showNoneCheckbox )
{
this.browserConnection = browserConnection;
this.dn = dn;
this.showNoneCheckbox = showNoneCheckbox;
}
/**
* Creates the widget.
*
* @param parent the parent
*/
public void createWidget( Composite parent )
{
createWidget( parent, null );
}
/**
* Creates the widget.
*
* @param parent the parent
* @param toolkit the toolkit
*/
public void createWidget( Composite parent, FormToolkit toolkit )
{
// Composite
if ( toolkit != null )
{
composite = toolkit.createComposite( parent );
}
else
{
composite = new Composite( parent, SWT.NONE );
}
GridLayout compositeGridLayout = new GridLayout( getNumberOfColumnsForComposite(), false );
compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
compositeGridLayout.verticalSpacing = 0;
composite.setLayout( compositeGridLayout );
// None Checbox
if ( showNoneCheckbox )
{
if ( toolkit != null )
{
noneCheckbox = toolkit.createButton( composite, "None", SWT.CHECK );
}
else
{
noneCheckbox = BaseWidgetUtils.createCheckbox( composite, "None", 1 );
}
}
// Dn combo
dnCombo = BaseWidgetUtils.createCombo( composite, new String[0], -1, 1 );
if ( toolkit != null )
{
toolkit.adapt( dnCombo );
}
GridData gd = new GridData( GridData.FILL_HORIZONTAL );
gd.horizontalSpan = 1;
gd.widthHint = 50;
dnCombo.setLayoutData( gd );
// Dn history
String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(),
BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY );
dnCombo.setItems( history );
// Browse button
if ( toolkit != null )
{
entryBrowseButton = toolkit.createButton( composite,
Messages.getString( "EntryWidget.BrowseButton" ), SWT.PUSH ); //$NON-NLS-1$
}
else
{
entryBrowseButton = BaseWidgetUtils.createButton( composite,
Messages.getString( "EntryWidget.BrowseButton" ), 1 ); //$NON-NLS-1$
}
dnChanged();
internalSetEnabled();
addListeners();
}
/**
* Adds the listeners
*/
private void addListeners()
{
if ( showNoneCheckbox )
{
noneCheckbox.addSelectionListener( noneCheckboxListener );
}
dnCombo.addModifyListener( dnComboListener );
entryBrowseButton.addSelectionListener( entryBrowseButtonListener );
}
/**
* Removes the listeners
*/
private void removeListeners()
{
if ( showNoneCheckbox )
{
noneCheckbox.removeSelectionListener( noneCheckboxListener );
}
dnCombo.removeModifyListener( dnComboListener );
entryBrowseButton.removeSelectionListener( entryBrowseButtonListener );
}
/**
* Gets the number of columns for the composite.
*
* @return the number of columns for the composite
*/
private int getNumberOfColumnsForComposite()
{
if ( showNoneCheckbox )
{
return 3;
}
else
{
return 2;
}
}
/**
* Notifies that the Dn has been changed.
*/
private void dnChanged()
{
if ( dnCombo != null && entryBrowseButton != null )
{
if ( showNoneCheckbox )
{
boolean noneSelected = ( dn == null );
noneCheckbox.setSelection( noneSelected );
noneCheckboxSelected( noneSelected );
}
dnCombo.setText( dn != null ? dn.getName() : "" ); //$NON-NLS-1$
}
}
/**
* This method is called when the "None" checkbox is clicked.
*/
private void noneCheckboxSelected( boolean state )
{
dnCombo.setEnabled( !state );
entryBrowseButton.setEnabled( !state );
}
/**
* Sets the enabled state of the widget.
*
* @param b true to enable the widget, false to disable the widget
*/
public void setEnabled( boolean enabled )
{
this.enabled = enabled;
if ( enabled )
{
this.dnChanged();
}
internalSetEnabled();
}
/**
* Internal set enabled.
*/
private void internalSetEnabled()
{
if ( showNoneCheckbox )
{
noneCheckbox.setEnabled( enabled );
if ( dn == null )
{
dnCombo.setEnabled( false );
entryBrowseButton.setEnabled( false );
}
else
{
dnCombo.setEnabled( enabled );
entryBrowseButton.setEnabled( ( browserConnection != null ) && enabled );
}
}
else
{
dnCombo.setEnabled( enabled );
entryBrowseButton.setEnabled( ( browserConnection != null ) && enabled );
}
}
/**
* Saves dialog settings.
*/
public void saveDialogSettings()
{
HistoryUtils.save( BrowserCommonActivator.getDefault().getDialogSettings(),
BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY, this.dnCombo.getText() );
}
/**
* Gets the Dn or <code>null</code> if the Dn isn't valid.
*
* @return the Dn or <code>null</code> if the Dn isn't valid
*/
public Dn getDn()
{
if ( showNoneCheckbox && noneCheckbox.getSelection() )
{
return null;
}
return dn;
}
/**
* Gets the browser connection.
*
* @return the browser connection
*/
public IBrowserConnection getBrowserConnection()
{
return browserConnection;
}
/**
* Sets the input.
*
* @param dn the Dn
*/
public void setInput( Dn dn )
{
if ( this.dn != dn )
{
this.dn = dn;
removeListeners();
dnChanged();
addListeners();
}
}
/**
* Returns the primary control associated with this widget.
*
* @return the primary control associated with this widget.
*/
public Control getControl()
{
return composite;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/BooleanWithDefaultWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/BooleanWithDefaultWidget.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.openldap.common.ui.widgets;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.widgets.FormToolkit;
public class BooleanWithDefaultWidget extends AbstractWidget
{
/** The combo viewer's values */
private Object[] comboViewerValues = new Object[]
{
BooleanValue.DEFAULT,
BooleanValue.TRUE,
BooleanValue.FALSE
};
// The default value
private Boolean defaultValue;
// The value
private Boolean value;
// UI widgets
private ComboViewer comboViewer;
/**
* Creates a new instance of BooleanWithDefaultWidget.
*/
public BooleanWithDefaultWidget()
{
}
/**
* Creates a new instance of BooleanWithDefaultWidget.
*
* @param defaultValue the default value
*/
public BooleanWithDefaultWidget( boolean defaultValue )
{
this.defaultValue = defaultValue;
}
/**
* Creates a new instance of BooleanWithDefaultWidget.
*
* @param defaultValue the default value
*/
public BooleanWithDefaultWidget( Boolean defaultValue )
{
this.defaultValue = defaultValue;
}
/**
* Creates the widget.
*
* @param parent the parent composite
*/
public void create( Composite parent )
{
create( parent, null );
}
/**
* Creates the widget.
*
* @param parent the parent composite
*/
public void create( Composite parent, FormToolkit toolkit )
{
comboViewer = new ComboViewer( parent );
comboViewer.setContentProvider( new ArrayContentProvider() );
comboViewer.setLabelProvider( new LabelProvider()
{
public String getText( Object element )
{
if ( element instanceof BooleanValue )
{
BooleanValue booleanValue = ( BooleanValue ) element;
switch ( booleanValue )
{
case DEFAULT:
if ( defaultValue != null )
{
if ( defaultValue.booleanValue() )
{
return NLS.bind( "Default value ({0})", "true" );
}
else
{
return NLS.bind( "Default value ({0})", "false" );
}
}
else
{
return "Default value";
}
case TRUE:
return "True";
case FALSE:
return "False";
}
}
return super.getText( element );
}
} );
comboViewer.addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
value = null;
StructuredSelection selection = ( StructuredSelection ) comboViewer.getSelection();
if ( !selection.isEmpty() )
{
BooleanValue booleanValue = ( BooleanValue ) selection.getFirstElement();
switch ( booleanValue )
{
case DEFAULT:
value = null;
break;
case TRUE:
value = new Boolean( true );
break;
case FALSE:
value = new Boolean( false );
break;
}
}
notifyListeners();
}
} );
comboViewer.setInput( comboViewerValues );
comboViewer.setSelection( new StructuredSelection( comboViewerValues[0] ) );
}
/**
* Returns the primary control associated with this widget.
*
* @return the primary control associated with this widget.
*/
public Control getControl()
{
return comboViewer.getControl();
}
/**
* Sets the value.
*
* @param s the value
*/
public void setValue( Boolean value )
{
this.value = value;
if ( value != null )
{
if ( value.booleanValue() )
{
comboViewer.setSelection( new StructuredSelection( comboViewerValues[1] ) );
}
else
{
comboViewer.setSelection( new StructuredSelection( comboViewerValues[2] ) );
}
}
else
{
comboViewer.setSelection( new StructuredSelection( comboViewerValues[0] ) );
}
}
/**
* Gets the value.
*
* @return the value
*/
public Boolean getValue()
{
return value;
}
/**
* Disposes all created SWT widgets.
*/
public void dispose()
{
if ( ( comboViewer != null ) && ( comboViewer.getControl() != null )
&& ( !comboViewer.getControl().isDisposed() ) )
{
comboViewer.getControl().dispose();
}
}
/**
* Sets the enabled state of the widget.
*
* @param enabled true to enable the widget, false to disable the widget
*/
public void setEnabled( boolean enabled )
{
if ( ( comboViewer != null ) && ( comboViewer.getControl() != null )
&& ( !comboViewer.getControl().isDisposed() ) )
{
comboViewer.getControl().setEnabled( enabled );
}
}
/**
* This enum represents the various values available.
*/
enum BooleanValue
{
DEFAULT, TRUE, 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/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/DirectoryBrowserWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/DirectoryBrowserWidget.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.openldap.common.ui.widgets;
import java.io.File;
import org.apache.directory.studio.common.ui.HistoryUtils;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.widgets.Messages;
import org.apache.directory.studio.openldap.common.ui.OpenLdapCommonUiConstants;
import org.apache.directory.studio.openldap.common.ui.OpenLdapCommonUiPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* The DirectoryBrowserWidget provides a combo with a history of recently
* used directory and a browse button to open the directory browser.
*/
public class DirectoryBrowserWidget extends AbstractWidget
{
/** The combo with the history of recently used directories */
protected Combo directoryCombo;
/** The button to launch the file browser */
protected Button browseButton;
/** The title */
protected String title;
/**
* Creates a new instance of DirectoryBrowserWidget.
*
* @param title The title
*/
public DirectoryBrowserWidget( String title )
{
this.title = title;
}
/**
* Creates the widget.
*
* @param parent the parent
*/
public void createWidget( Composite parent )
{
createWidget( parent, null );
}
/**
* Creates the widget.
*
* @param parent the parent
* @param toolkit the toolkit
*/
public void createWidget( Composite parent, FormToolkit toolkit )
{
// Combo
directoryCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
if ( toolkit != null )
{
toolkit.adapt( directoryCombo );
}
GridData gd = new GridData( GridData.FILL_HORIZONTAL );
gd.widthHint = 50;
directoryCombo.setLayoutData( gd );
directoryCombo.setVisibleItemCount( 20 );
directoryCombo.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
notifyListeners();
}
} );
// Button
if ( toolkit != null )
{
browseButton = toolkit.createButton( parent,
Messages.getString( "FileBrowserWidget.BrowseButton" ), SWT.PUSH ); //$NON-NLS-1$
}
else
{
browseButton = BaseWidgetUtils.createButton( parent,
Messages.getString( "FileBrowserWidget.BrowseButton" ), 1 ); //$NON-NLS-1$
}
browseButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
DirectoryDialog directoryDialog = new DirectoryDialog( browseButton.getShell() );
directoryDialog.setText( title );
File file = new File( directoryCombo.getText() );
if ( file.isFile() )
{
directoryDialog.setFilterPath( file.getParent() );
}
else if ( file.isDirectory() )
{
directoryDialog.setFilterPath( file.getPath() );
}
else
{
directoryDialog.setFilterPath( BrowserCommonActivator.getDefault().getDialogSettings().get(
BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH ) );
}
String returnedFileName = directoryDialog.open();
if ( returnedFileName != null )
{
directoryCombo.setText( returnedFileName );
File file2 = new File( returnedFileName );
BrowserCommonActivator.getDefault().getDialogSettings().put(
BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH, file2.getParent() );
}
}
} );
loadDialogSettings();
}
/**
* Gets the directory path.
*
* @return the directory path or <code>null</code>
*/
public String getDirectoryPath()
{
String directoryPath = directoryCombo.getText();
if ( ( directoryPath != null ) && ( !"".equals( directoryPath ) ) )
{
return directoryPath;
}
return null;
}
/**
* Sets the directory path.
*
* @param directoryPath the directory path
*/
public void setDirectoryPath( String directoryPath )
{
if ( directoryPath == null )
{
directoryCombo.setText( "" );
}
else
{
directoryCombo.setText( directoryPath );
}
}
/**
* Saves dialog settings.
*/
public void loadDialogSettings()
{
String[] history = null;
try
{
history = HistoryUtils.load( OpenLdapCommonUiPlugin.getDefault().getDialogSettings(),
OpenLdapCommonUiConstants.DIALOGSETTING_KEY_DIRECTORY_HISTORY );
}
catch ( Exception e )
{
history = new String[]{};
}
directoryCombo.setItems( history );
}
/**
* Saves dialog settings.
*/
public void saveDialogSettings()
{
OpenLdapCommonUiPlugin plugin = OpenLdapCommonUiPlugin.getDefault();
if ( plugin != null )
{
HistoryUtils.save( OpenLdapCommonUiPlugin.getDefault().getDialogSettings(),
OpenLdapCommonUiConstants.DIALOGSETTING_KEY_DIRECTORY_HISTORY, directoryCombo.getText() );
}
}
/**
* Sets the focus.
*/
public void setFocus()
{
directoryCombo.setFocus();
}
/**
* Enables or disables the widget.
*
* @param b true to enable the widget, false otherwise
*/
public void setEnabled( boolean b )
{
directoryCombo.setEnabled( b );
browseButton.setEnabled( b );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/FileBrowserWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/FileBrowserWidget.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.openldap.common.ui.widgets;
import java.io.File;
import org.apache.directory.studio.common.ui.HistoryUtils;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.widgets.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* The DirectoryBrowserWidget provides a combo with a history of recently
* used directory and a browse button to open the directory browser.
*/
public class FileBrowserWidget extends org.apache.directory.studio.ldapbrowser.common.widgets.FileBrowserWidget
{
/**
* Creates a new instance of FileBrowserWidget.
*
* @param title The title
* @param extensions The valid file extensions
* @param type The type, one of {@link #TYPE_OPEN} or {@link #TYPE_SAVE}
*/
public FileBrowserWidget( String title, String[] extensions, int type )
{
super( title, extensions, type );
}
/**
* Creates the widget.
*
* @param parent the parent
* @param toolkit the toolkit
*/
public void createWidget( Composite parent, FormToolkit toolkit )
{
// Combo
fileCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
if ( toolkit != null )
{
toolkit.adapt( fileCombo );
}
GridData gd = new GridData( GridData.FILL_HORIZONTAL );
gd.widthHint = 50;
fileCombo.setLayoutData( gd );
fileCombo.setVisibleItemCount( 20 );
fileCombo.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
notifyListeners();
}
} );
// Button
if ( toolkit != null )
{
browseButton = toolkit.createButton( parent,
Messages.getString( "FileBrowserWidget.BrowseButton" ), SWT.PUSH ); //$NON-NLS-1$
}
else
{
browseButton = BaseWidgetUtils.createButton( parent,
Messages.getString( "FileBrowserWidget.BrowseButton" ), 1 ); //$NON-NLS-1$
}
browseButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
FileDialog fileDialog = new FileDialog( browseButton.getShell(), type );
fileDialog.setText( title );
fileDialog.setFilterExtensions( extensions );
File file = new File( fileCombo.getText() );
if ( file.isFile() )
{
fileDialog.setFilterPath( file.getParent() );
fileDialog.setFileName( file.getName() );
}
else if ( file.isDirectory() )
{
fileDialog.setFilterPath( file.getPath() );
}
else
{
fileDialog.setFilterPath( BrowserCommonActivator.getDefault().getDialogSettings().get(
BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH ) );
}
String returnedFileName = fileDialog.open();
if ( returnedFileName != null )
{
fileCombo.setText( returnedFileName );
File file2 = new File( returnedFileName );
BrowserCommonActivator.getDefault().getDialogSettings().put(
BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH, file2.getParent() );
}
}
} );
// file history
String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(),
BrowserCommonConstants.DIALOGSETTING_KEY_FILE_HISTORY );
fileCombo.setItems( history );
}
/**
* {@inheritDoc}
*/
public String getFilename()
{
String filename = fileCombo.getText();
if ( ( filename != null ) && ( !"".equals( filename ) ) )
{
return filename;
}
return null;
}
/**
* {@inheritDoc}
*/
public void setFilename( String filename )
{
if ( filename == null )
{
fileCombo.setText( filename );
}
else
{
fileCombo.setText( filename );
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/UnixPermissionsWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/UnixPermissionsWidget.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.openldap.common.ui.widgets;
import java.text.ParseException;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.apache.directory.studio.openldap.common.ui.dialogs.UnixPermissionsDialog;
import org.apache.directory.studio.openldap.common.ui.model.UnixPermissions;
/**
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class UnixPermissionsWidget extends AbstractWidget
{
// The value
private String value;
// UI widgets
private Composite composite;
private Text label;
private Button editButton;
// Listeners
private SelectionListener editButtonSelectionListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
// Creating and opening a UNIX permission dialog
UnixPermissionsDialog dialog = new UnixPermissionsDialog( editButton.getShell(), value );
if ( UnixPermissionsDialog.OK == dialog.open() )
{
setValue( dialog.getDecimalValue() );
notifyListeners();
}
}
};
/**
* Creates the widget.
*
* @param parent the parent composite
*/
public void create( Composite parent )
{
create( parent, null );
}
/**
* Creates the widget.
*
* @param parent the parent composite
*/
public void create( Composite parent, FormToolkit toolkit )
{
// Creating the widget base composite
if ( toolkit != null )
{
composite = toolkit.createComposite( parent );
}
else
{
composite = new Composite( parent, SWT.NONE );
}
GridLayout compositeGridLayout = new GridLayout( 2, false );
compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
compositeGridLayout.verticalSpacing = 0;
composite.setLayout( compositeGridLayout );
// Label
if ( toolkit != null )
{
label = toolkit.createText( composite, "" );
}
else
{
label = BaseWidgetUtils.createText( composite, "", 1 );
}
label.setEditable( false );
label.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
// Edit Button
if ( toolkit != null )
{
editButton = toolkit.createButton( composite, "Edit Permissions...", SWT.PUSH );
}
else
{
editButton = BaseWidgetUtils.createButton( composite, "Edit Permissions...", 1 );
}
editButton.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, false, false ) );
// Adding the listeners to the UI widgets
addListeners();
}
/**
* Returns the primary control associated with this widget.
*
* @return the primary control associated with this widget.
*/
public Control getControl()
{
return composite;
}
/**
* Adds the listeners to the UI widgets.
*/
private void addListeners()
{
editButton.addSelectionListener( editButtonSelectionListener );
}
/**
* Sets the value.
*
* @param s the value
*/
public void setValue( String s )
{
value = s;
UnixPermissions perm = null;
try
{
perm = new UnixPermissions( s );
}
catch ( ParseException e )
{
perm = new UnixPermissions();
}
label.setText( NLS.bind( "{0} ({1})", perm.getSymbolicValue(), perm.getOctalValue() ) );
}
/**
* Gets the value.
*
* @return the value
*/
public String getValue()
{
return value;
}
/**
* Disposes all created SWT widgets.
*/
public void dispose()
{
// Composite
if ( ( composite != null ) && ( !composite.isDisposed() ) )
{
composite.dispose();
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/PasswordWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/PasswordWidget.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.openldap.common.ui.widgets;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.apache.directory.studio.openldap.common.ui.dialogs.PasswordDialog;
/**
* The PasswordWidget provides a label to display the password, an edit button
* and a 'Show Password' button to show/hide the password.
*/
public class PasswordWidget extends AbstractWidget
{
/** The password */
private byte[] password;
/** The flag to show the "None" checkbox or not */
private boolean showNoneCheckbox;
/** The flag indicating if the password should be shown or not */
private boolean showPassword;
// UI widgets
private Composite composite;
private Button noneCheckbox;
private Text passwordText;
private Button editButton;
private Button showPasswordCheckbox;
/**
* Creates a new instance of PasswordWidget.
*/
public PasswordWidget()
{
}
/**
* Creates a new instance of PasswordWidget.
*
* @param showNoneButton the flag to show the "None" checkbox
*/
public PasswordWidget( boolean showNoneCheckbox )
{
this.showNoneCheckbox = showNoneCheckbox;
}
/**
* Creates the widget.
*
* @param parent the parent
*/
public void createWidget( Composite parent )
{
createWidget( parent, null );
}
/**
* Creates the widget.
*
* @param parent the parent
* @param toolkit the toolkit
*/
public void createWidget( Composite parent, FormToolkit toolkit )
{
// Composite
if ( toolkit != null )
{
composite = toolkit.createComposite( parent );
}
else
{
composite = new Composite( parent, SWT.NONE );
}
GridLayout compositeGridLayout = new GridLayout( getNumberOfColumnsForComposite(), false );
compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
compositeGridLayout.verticalSpacing = 0;
composite.setLayout( compositeGridLayout );
// None Checbox
if ( showNoneCheckbox )
{
if ( toolkit != null )
{
noneCheckbox = toolkit.createButton( composite, "None", SWT.CHECK );
}
else
{
noneCheckbox = BaseWidgetUtils.createCheckbox( composite, "None", 1 );
}
noneCheckbox.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
noneCheckboxSelected( noneCheckbox.getSelection() );
notifyListeners();
}
} );
}
// Password Text
if ( toolkit != null )
{
passwordText = toolkit.createText( composite, "", SWT.NONE );
}
else
{
passwordText = BaseWidgetUtils.createReadonlyText( composite, "", 1 );
}
passwordText.setEditable( false );
GridData gd = new GridData( SWT.FILL, SWT.CENTER, true, false );
gd.widthHint = 50;
passwordText.setLayoutData( gd );
// Setting the echo char for the password text
if ( showPassword )
{
passwordText.setEchoChar( '\0' );
}
else
{
passwordText.setEchoChar( '\u2022' );
}
// Edit Button
if ( toolkit != null )
{
editButton = toolkit.createButton( composite, "Edit Password...", SWT.PUSH );
}
else
{
editButton = BaseWidgetUtils.createButton( composite, "Edit Password...", 1 );
editButton.setLayoutData( new GridData() );
}
editButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
editButtonAction();
}
} );
// Show Password Checkbox
if ( toolkit != null )
{
if ( showNoneCheckbox )
{
toolkit.createLabel( composite, "" );
}
showPasswordCheckbox = toolkit.createButton( composite, "Show Password", SWT.CHECK );
}
else
{
if ( showNoneCheckbox )
{
BaseWidgetUtils.createLabel( composite, "", 1 );
}
showPasswordCheckbox = BaseWidgetUtils.createCheckbox( composite, "Show Password",
getNumberOfColumnsForComposite() );
}
GridData showPasswordCheckboxGridData = new GridData();
showPasswordCheckboxGridData.horizontalSpan = getNumberOfColumnsForComposite() - 1;
showPasswordCheckbox.setLayoutData( showPasswordCheckboxGridData );
showPasswordCheckbox.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
showPasswordAction();
}
} );
noneCheckboxSelected( showNoneCheckbox );
}
/**
* Gets the number of columns for the composite.
*
* @return the number of columns for the composite
*/
private int getNumberOfColumnsForComposite()
{
if ( showNoneCheckbox )
{
return 3;
}
else
{
return 2;
}
}
/**
* This method is called when the "None" checkbox is clicked.
*/
private void noneCheckboxSelected( boolean state )
{
editButton.setEnabled( !state );
showPasswordCheckbox.setEnabled( !state );
}
/**
* This action is called when the 'Edit...' button is clicked.
*/
private void editButtonAction()
{
// Creating and displaying a password dialog
PasswordDialog passwordDialog = new PasswordDialog( editButton.getShell(), password );
if ( passwordDialog.open() == Dialog.OK )
{
if ( passwordDialog.getNewPassword() != password )
{
byte[] password = passwordDialog.getNewPassword();
if ( ( password != null ) && ( password.length > 0 ) )
{
this.password = password;
passwordText.setText( new String( password ) );
notifyListeners();
}
}
}
}
/**
* This action is called when the 'Show Password' checkbox is clicked.
*/
private void showPasswordAction()
{
if ( showPasswordCheckbox.getSelection() )
{
passwordText.setEchoChar( '\0' );
}
else
{
passwordText.setEchoChar( '\u2022' );
}
}
/**
* Sets the password.
*
* @param password the password
*/
public void setPassword( byte[] password )
{
this.password = password;
if ( showNoneCheckbox )
{
boolean noneSelected = ( password == null );
noneCheckbox.setSelection( noneSelected );
noneCheckboxSelected( noneSelected );
}
// Updating the password text field
if ( ( password != null ) && ( password.length > 0 ) )
{
passwordText.setText( new String( password ) );
}
else
{
passwordText.setText( "" ); //$NON-NLS-1$
}
}
/**
* Gets the password.
*
* @return the password
*/
public byte[] getPassword()
{
if ( showNoneCheckbox && noneCheckbox.getSelection() )
{
return null;
}
if ( ( password != null ) && ( password.length > 0 ) )
{
return password;
}
return null;
}
/**
* Gets the password as string.
*
* @return the password as string
*/
public String getPasswordAsString()
{
if ( showNoneCheckbox && noneCheckbox.getSelection() )
{
return null;
}
if ( ( password != null ) && ( password.length > 0 ) )
{
return new String( password );
}
return null;
}
/**
* Returns the primary control associated with this widget.
*
* @return the primary control associated with this widget.
*/
public Control getControl()
{
return composite;
}
/**
* Sets the enabled state of the widget.
*
* @param enabled true to enable the widget, false to disable the widget
*/
public void setEnabled( boolean enabled )
{
if ( ( editButton != null ) && ( !editButton.isDisposed() ) )
{
if ( showNoneCheckbox )
{
noneCheckbox.setEnabled( enabled );
noneCheckboxSelected( noneCheckbox.getSelection() && enabled );
}
else
{
editButton.setEnabled( enabled );
showPasswordCheckbox.setEnabled( enabled );
}
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperationsWidget.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperationsWidget.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.openldap.common.ui.widgets;
import java.util.ArrayList;
import java.util.List;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.openldap.common.ui.model.LogOperationEnum;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.widgets.FormToolkit;
public class LogOperationsWidget extends AbstractWidget
{
// UI widgets
private Composite composite;
private Composite writeOperationsComposite;
private Composite readOperationsComposite;
private Composite sessionOperationsComposite;
private Button allOperationsCheckbox;
private Button writeOperationsCheckbox;
private Button addOperationCheckbox;
private Button deleteOperationCheckbox;
private Button modifyOperationCheckbox;
private Button modifyRdnOperationCheckbox;
private Button readOperationsCheckbox;
private Button compareOperationCheckbox;
private Button searchOperationCheckbox;
private Button sessionOperationsCheckbox;
private Button abandonOperationCheckbox;
private Button bindOperationCheckbox;
private Button unbindOperationCheckbox;
// Listeners
private SelectionAdapter allOperationsCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
allOperationsCheckboxesSetSelection( allOperationsCheckbox.getSelection() );
notifyListeners();
}
};
private SelectionAdapter writeOperationsCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
writeOperationsCheckboxesSetSelection( writeOperationsCheckbox.getSelection() );
checkAllOperationsCheckboxSelectionState();
notifyListeners();
}
};
private SelectionAdapter writeOperationCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
checkWriteOperationsCheckboxSelectionState();
checkAllOperationsCheckboxSelectionState();
notifyListeners();
}
};
private SelectionAdapter readOperationsCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
readOperationsCheckboxesSetSelection( readOperationsCheckbox.getSelection() );
checkAllOperationsCheckboxSelectionState();
notifyListeners();
}
};
private SelectionAdapter readOperationCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
checkReadOperationsCheckboxSelectionState();
checkAllOperationsCheckboxSelectionState();
notifyListeners();
}
};
private SelectionAdapter sessionOperationsCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
sessionOperationsCheckboxesSetSelection( sessionOperationsCheckbox.getSelection() );
checkAllOperationsCheckboxSelectionState();
notifyListeners();
}
};
private SelectionAdapter sessionOperationCheckboxListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
checkSessionOperationsCheckboxSelectionState();
checkAllOperationsCheckboxSelectionState();
notifyListeners();
}
};
/**
* Creates the widget.
*
* @param parent the parent composite
*/
public void create( Composite parent )
{
// Creating the widget base composite
composite = new Composite( parent, SWT.NONE );
GridLayout compositeGridLayout = new GridLayout( 3, true );
compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
compositeGridLayout.verticalSpacing = compositeGridLayout.horizontalSpacing = 0;
composite.setLayout( compositeGridLayout );
// All Operations Checkbox
allOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "All operations", 3 );
// Write Operations Checkbox
writeOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "Write operations", 1 );
// Read Operations Checkbox
readOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "Read operations", 1 );
// Session Operations Checkbox
sessionOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "Session operations", 1 );
// Write Operations Composite
writeOperationsComposite = new Composite( composite, SWT.NONE );
GridLayout writeOperationsCompositeGridLayout = new GridLayout( 2, false );
writeOperationsCompositeGridLayout.marginHeight = writeOperationsCompositeGridLayout.marginWidth = 0;
writeOperationsCompositeGridLayout.verticalSpacing = writeOperationsCompositeGridLayout.horizontalSpacing = 0;
writeOperationsComposite.setLayout( writeOperationsCompositeGridLayout );
writeOperationsComposite.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
// Read Operations Composite
readOperationsComposite = new Composite( composite, SWT.NONE );
GridLayout readOperationsCompositeGridLayout = new GridLayout( 2, false );
readOperationsCompositeGridLayout.marginHeight = readOperationsCompositeGridLayout.marginWidth = 0;
readOperationsCompositeGridLayout.verticalSpacing = readOperationsCompositeGridLayout.horizontalSpacing = 0;
readOperationsComposite.setLayout( readOperationsCompositeGridLayout );
readOperationsComposite.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
// Session Operations Composite
sessionOperationsComposite = new Composite( composite, SWT.NONE );
GridLayout sessionOperationsCompositeGridLayout = new GridLayout( 2, false );
sessionOperationsCompositeGridLayout.marginHeight = sessionOperationsCompositeGridLayout.marginWidth = 0;
sessionOperationsCompositeGridLayout.verticalSpacing = sessionOperationsCompositeGridLayout.horizontalSpacing = 0;
sessionOperationsComposite.setLayout( sessionOperationsCompositeGridLayout );
sessionOperationsComposite.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
// Add Operation Checkbox
BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
addOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Add", 1 );
// Delete Operation Checkbox
BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
deleteOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Delete", 1 );
// Modify Operation Checkbox
BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
modifyOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Modify", 1 );
// Modify RDN Operation Checkbox
BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
modifyRdnOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Modify RDN", 1 );
// Compare Operation Checkbox
BaseWidgetUtils.createRadioIndent( readOperationsComposite, 1 );
compareOperationCheckbox = BaseWidgetUtils.createCheckbox( readOperationsComposite, "Compare", 1 );
// Search Operation Checkbox
BaseWidgetUtils.createRadioIndent( readOperationsComposite, 1 );
searchOperationCheckbox = BaseWidgetUtils.createCheckbox( readOperationsComposite, "Search", 1 );
// Abandon Operation Checkbox
BaseWidgetUtils.createRadioIndent( sessionOperationsComposite, 1 );
abandonOperationCheckbox = BaseWidgetUtils.createCheckbox( sessionOperationsComposite, "Abandon", 1 );
// Bind Operation Checkbox
BaseWidgetUtils.createRadioIndent( sessionOperationsComposite, 1 );
bindOperationCheckbox = BaseWidgetUtils.createCheckbox( sessionOperationsComposite, "Bind", 1 );
// Unbind Operation Checkbox
BaseWidgetUtils.createRadioIndent( sessionOperationsComposite, 1 );
unbindOperationCheckbox = BaseWidgetUtils.createCheckbox( sessionOperationsComposite, "Unbind", 1 );
// Adding the listeners to the UI widgets
addListeners();
}
/**
* Returns the associated composite.
*
* @return the composite
*/
public void adapt( FormToolkit toolkit )
{
if ( toolkit != null )
{
toolkit.adapt( composite );
toolkit.adapt( writeOperationsComposite );
toolkit.adapt( readOperationsComposite );
toolkit.adapt( sessionOperationsComposite );
}
}
/**
* Returns the primary control associated with this widget.
*
* @return the primary control associated with this widget.
*/
public Control getControl()
{
return composite;
}
/**
* Adds the listeners to the UI widgets.
*/
private void addListeners()
{
allOperationsCheckbox.addSelectionListener( allOperationsCheckboxListener );
writeOperationsCheckbox.addSelectionListener( writeOperationsCheckboxListener );
addOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
deleteOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
modifyOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
modifyRdnOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
readOperationsCheckbox.addSelectionListener( readOperationsCheckboxListener );
compareOperationCheckbox.addSelectionListener( readOperationCheckboxListener );
searchOperationCheckbox.addSelectionListener( readOperationCheckboxListener );
sessionOperationsCheckbox.addSelectionListener( sessionOperationsCheckboxListener );
abandonOperationCheckbox.addSelectionListener( sessionOperationCheckboxListener );
bindOperationCheckbox.addSelectionListener( sessionOperationCheckboxListener );
unbindOperationCheckbox.addSelectionListener( sessionOperationCheckboxListener );
}
/**
* Sets the selection for all operations checkboxes.
*
* @param selection the selection
*/
private void allOperationsCheckboxesSetSelection( boolean selection )
{
allOperationsCheckbox.setGrayed( false );
allOperationsCheckbox.setSelection( selection );
writeOperationsCheckboxesSetSelection( selection );
readOperationsCheckboxesSetSelection( selection );
sessionOperationsCheckboxesSetSelection( selection );
}
/**
* Sets the selection for the 'Write' operations checkboxes.
*
* @param selection the selection
*/
private void writeOperationsCheckboxesSetSelection( boolean selection )
{
writeOperationsCheckbox.setGrayed( false );
writeOperationsCheckbox.setSelection( selection );
addOperationCheckbox.setSelection( selection );
deleteOperationCheckbox.setSelection( selection );
modifyOperationCheckbox.setSelection( selection );
modifyRdnOperationCheckbox.setSelection( selection );
}
/**
* Sets the selection for the 'Read' operations checkboxes.
*
* @param selection the selection
*/
private void readOperationsCheckboxesSetSelection( boolean selection )
{
readOperationsCheckbox.setGrayed( false );
readOperationsCheckbox.setSelection( selection );
compareOperationCheckbox.setSelection( selection );
searchOperationCheckbox.setSelection( selection );
}
/**
* Sets the selection for the 'Session' operations checkboxes.
*
* @param selection the selection
*/
private void sessionOperationsCheckboxesSetSelection( boolean selection )
{
sessionOperationsCheckbox.setGrayed( false );
sessionOperationsCheckbox.setSelection( selection );
abandonOperationCheckbox.setSelection( selection );
bindOperationCheckbox.setSelection( selection );
unbindOperationCheckbox.setSelection( selection );
}
/**
* Verifies the selection state for the 'All Operations' checkbox.
*/
private void checkAllOperationsCheckboxSelectionState()
{
boolean atLeastOneSelected = addOperationCheckbox.getSelection()
|| deleteOperationCheckbox.getSelection() || modifyOperationCheckbox.getSelection()
|| modifyRdnOperationCheckbox.getSelection() || compareOperationCheckbox.getSelection()
|| searchOperationCheckbox.getSelection() || abandonOperationCheckbox.getSelection()
|| bindOperationCheckbox.getSelection() || unbindOperationCheckbox.getSelection();
boolean allSelected = addOperationCheckbox.getSelection()
&& deleteOperationCheckbox.getSelection() && modifyOperationCheckbox.getSelection()
&& modifyRdnOperationCheckbox.getSelection() && compareOperationCheckbox.getSelection()
&& searchOperationCheckbox.getSelection() && abandonOperationCheckbox.getSelection()
&& bindOperationCheckbox.getSelection() && unbindOperationCheckbox.getSelection();
allOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
allOperationsCheckbox.setSelection( atLeastOneSelected );
}
/**
* Verifies the selection state for the 'Write Operations' checkbox.
*/
private void checkWriteOperationsCheckboxSelectionState()
{
boolean atLeastOneSelected = isChecked( addOperationCheckbox )
|| isChecked( deleteOperationCheckbox ) || isChecked( modifyOperationCheckbox )
|| isChecked( modifyRdnOperationCheckbox );
boolean allSelected = isChecked( addOperationCheckbox )
&& isChecked( deleteOperationCheckbox ) && isChecked( modifyOperationCheckbox )
&& isChecked( modifyRdnOperationCheckbox );
writeOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
writeOperationsCheckbox.setSelection( atLeastOneSelected );
}
/**
* Verifies the selection state for the 'Read Operations' checkbox.
*/
private void checkReadOperationsCheckboxSelectionState()
{
boolean atLeastOneSelected = isChecked( compareOperationCheckbox )
|| isChecked( searchOperationCheckbox );
boolean allSelected = isChecked( compareOperationCheckbox )
&& isChecked( searchOperationCheckbox );
readOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
readOperationsCheckbox.setSelection( atLeastOneSelected );
}
/**
* Verifies the selection state for the 'Session Operations' checkbox.
*/
private void checkSessionOperationsCheckboxSelectionState()
{
boolean atLeastOneSelected = isChecked( abandonOperationCheckbox )
|| isChecked( bindOperationCheckbox ) || isChecked( unbindOperationCheckbox );
boolean allSelected = isChecked( abandonOperationCheckbox )
&& isChecked( bindOperationCheckbox ) && isChecked( unbindOperationCheckbox );
sessionOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
sessionOperationsCheckbox.setSelection( atLeastOneSelected );
}
/**
* Sets the input.
*
* @param operationsList the operations list
*/
public void setInput( List<LogOperationEnum> operationsList )
{
// Reset all checkboxes
resetAllCheckboxes();
// Select checkboxes according to the log operations list
if ( operationsList != null )
{
for ( LogOperationEnum logOperation : operationsList )
{
switch ( logOperation )
{
case ALL:
allOperationsCheckbox.setSelection( true );
allOperationsCheckboxesSetSelection( true );
break;
case WRITES:
writeOperationsCheckbox.setSelection( true );
writeOperationsCheckboxesSetSelection( true );
break;
case ADD:
addOperationCheckbox.setSelection( true );
break;
case DELETE:
deleteOperationCheckbox.setSelection( true );
break;
case MODIFY:
modifyOperationCheckbox.setSelection( true );
break;
case MODIFY_RDN:
modifyRdnOperationCheckbox.setSelection( true );
break;
case READS:
readOperationsCheckbox.setSelection( true );
readOperationsCheckboxesSetSelection( true );
break;
case COMPARE:
compareOperationCheckbox.setSelection( true );
break;
case SEARCH:
searchOperationCheckbox.setSelection( true );
break;
case SESSION:
sessionOperationsCheckbox.setSelection( true );
sessionOperationsCheckboxesSetSelection( true );
break;
case ABANDON:
abandonOperationCheckbox.setSelection( true );
break;
case BIND:
bindOperationCheckbox.setSelection( true );
break;
case UNBIND:
unbindOperationCheckbox.setSelection( true );
break;
}
}
}
// Check hierarchical checkboxes
checkWriteOperationsCheckboxSelectionState();
checkReadOperationsCheckboxSelectionState();
checkSessionOperationsCheckboxSelectionState();
checkAllOperationsCheckboxSelectionState();
}
/**
* Resets all checkboxes.
*/
private void resetAllCheckboxes()
{
allOperationsCheckbox.setSelection( false );
allOperationsCheckbox.setGrayed( false );
writeOperationsCheckbox.setSelection( false );
writeOperationsCheckbox.setGrayed( false );
addOperationCheckbox.setSelection( false );
addOperationCheckbox.setGrayed( false );
deleteOperationCheckbox.setSelection( false );
deleteOperationCheckbox.setGrayed( false );
modifyOperationCheckbox.setSelection( false );
modifyOperationCheckbox.setGrayed( false );
readOperationsCheckbox.setSelection( false );
readOperationsCheckbox.setGrayed( false );
compareOperationCheckbox.setSelection( false );
compareOperationCheckbox.setGrayed( false );
searchOperationCheckbox.setSelection( false );
searchOperationCheckbox.setGrayed( false );
sessionOperationsCheckbox.setSelection( false );
sessionOperationsCheckbox.setGrayed( false );
abandonOperationCheckbox.setSelection( false );
abandonOperationCheckbox.setGrayed( false );
bindOperationCheckbox.setSelection( false );
bindOperationCheckbox.setGrayed( false );
unbindOperationCheckbox.setSelection( false );
unbindOperationCheckbox.setGrayed( false );
}
/**
* Returns the list of selected operations.
*
* @return the list of selected operations
*/
public List<LogOperationEnum> getSelectedOperationsList()
{
List<LogOperationEnum> logOperations = new ArrayList<LogOperationEnum>();
// All operations
if ( isChecked( allOperationsCheckbox ) )
{
logOperations.add( LogOperationEnum.ALL );
}
else
{
// Write operations
if ( isChecked( writeOperationsCheckbox ) )
{
logOperations.add( LogOperationEnum.WRITES );
}
else
{
// Add operation
if ( isChecked( addOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.ADD );
}
// Delete operation
if ( isChecked( deleteOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.DELETE );
}
// Modify operation
if ( isChecked( modifyOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.MODIFY );
}
// Modify RDN operation
if ( isChecked( modifyRdnOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.MODIFY_RDN );
}
}
// Read operations
if ( isChecked( readOperationsCheckbox ) )
{
logOperations.add( LogOperationEnum.READS );
}
else
{
// Compare operation
if ( isChecked( compareOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.COMPARE );
}
// Search operation
if ( isChecked( searchOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.SEARCH );
}
}
// Session operations
if ( isChecked( sessionOperationsCheckbox ) )
{
logOperations.add( LogOperationEnum.SESSION );
}
else
{
// Abandon operation
if ( isChecked( abandonOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.ABANDON );
}
// Bind operation
if ( isChecked( bindOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.BIND );
}
// Unbind operation
if ( isChecked( unbindOperationCheckbox ) )
{
logOperations.add( LogOperationEnum.UNBIND );
}
}
}
return logOperations;
}
/**
* Indicates if a checkbox is checked ('selected' and not 'grayed').
*
* @param checkbox the checkbox
* @return <code>true</code> if the checkbox is checked
* <code>false</code> if not.
*/
private boolean isChecked( Button checkbox )
{
return ( ( checkbox != null ) && ( !checkbox.isDisposed() ) && ( checkbox.getSelection() ) && ( !checkbox
.getGrayed() ) );
}
/**
* Disposes all created SWT widgets.
*/
public void dispose()
{
// Composite
if ( ( composite != null ) && ( !composite.isDisposed() ) )
{
composite.dispose();
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/LogLevelDialog.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/LogLevelDialog.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.openldap.common.ui.dialogs;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.openldap.common.ui.model.LogLevelEnum;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* The LogLevelDialog is used to edit the LogLevel. Here are the possible values :
*
* <ul>
* <li>none 0</li>
* <li>trace 1</li>
* <li>packets 2</li>
* <li>args 4</li>
* <li>conns 8</li>
* <li>BER 16</li>
* <li>filter 32</li>
* <li>config 64</li>
* <li>ACL 128</li>
* <li>stats 256</li>
* <li>stats2 512</li>
* <li>shell 1024</li>
* <li>parse 2048</li>
* <li>sync 16384</li>
* <li>any -1</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LogLevelDialog extends Dialog
{
/** The logLevel value */
private int logLevelValue;
// UI widgets
private Button noneCheckbox;
private Button traceCheckbox;
private Button packetsCheckbox;
private Button argsCheckbox;
private Button connsCheckbox;
private Button berCheckbox;
private Button filterCheckbox;
private Button configCheckbox;
private Button aclCheckbox;
private Button statsCheckbox;
private Button stats2Checkbox;
private Button shellCheckbox;
private Button parseCheckbox;
private Button syncCheckbox;
private Button anyCheckbox;
/** An array of all the checkboxes */
private Button[] buttons = new Button[13];
// The resulting integer
private Text logLevelText;
// An empty space
protected static final String TABULATION = " ";
/**
* The listener in charge of exposing the changes when some buttons are checked
*/
private SelectionListener checkboxSelectionListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
Object object = e.getSource();
if ( object instanceof Button )
{
Button selectedButton = (Button)object;
if ( selectedButton.equals( noneCheckbox ) )
{
// None, we have to uncheck all the other checkbox
for ( Button button : buttons )
{
button.setSelection( false );
}
// reset the Any button
anyCheckbox.setSelection( false );
// set the None button
noneCheckbox.setSelection( true );
}
else if ( selectedButton.equals( anyCheckbox ) )
{
// Any, we have to check all the buttons
for ( Button button : buttons )
{
button.setSelection( true );
}
// reset the None button
noneCheckbox.setSelection( false );
// set the Any button
anyCheckbox.setSelection( true );
}
else
{
// deselect the any and none button, unless we don't have any more
// selected button or all the button selected
int count = 0;
for ( Button button : buttons )
{
if ( button.getSelection() )
{
count++;
}
}
if ( count == 0 )
{
anyCheckbox.setSelection( false );
noneCheckbox.setSelection( true );
}
else if ( count == buttons.length )
{
anyCheckbox.setSelection( true );
noneCheckbox.setSelection( false );
}
else
{
anyCheckbox.setSelection( false );
noneCheckbox.setSelection( false );
}
}
}
computeLogValue();
setLogLevelText();
}
};
/**
* Creates a new instance of LogLevelDialog.
*
* @param parentShell the parent shell
*/
public LogLevelDialog( Shell parentShell )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
}
/**
* Creates a new instance of LogLevelDialog.
*
* @param parentShell the parent shell
* @param value the initial value
*/
public LogLevelDialog( Shell parentShell, int value )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.logLevelValue = value;
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( "OpenLDAP LogLevel" );
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
computeLogValue();
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
composite.setLayoutData( gd );
createLogLevelArea( composite );
createLogLevelValueArea( composite );
setCheckboxesValue();
addListeners();
applyDialogFont( composite );
return composite;
}
/**
* Sets the checkboxes value.
*
* @param perm the Unix permissions
*/
private void setCheckboxesValue()
{
noneCheckbox.setSelection( logLevelValue == LogLevelEnum.NONE.getValue() );
traceCheckbox.setSelection( ( logLevelValue & LogLevelEnum.TRACE.getValue() ) != 0 );
packetsCheckbox.setSelection( ( logLevelValue & LogLevelEnum.PACKETS.getValue() ) != 0 );
argsCheckbox.setSelection( ( logLevelValue & LogLevelEnum.ARGS.getValue() ) != 0 );
connsCheckbox.setSelection( ( logLevelValue & LogLevelEnum.CONNS.getValue() ) != 0 );
berCheckbox.setSelection( ( logLevelValue & LogLevelEnum.BER.getValue() ) != 0 );
filterCheckbox.setSelection( ( logLevelValue & LogLevelEnum.FILTER.getValue() ) != 0 );
configCheckbox.setSelection( ( logLevelValue & LogLevelEnum.CONFIG.getValue() ) != 0 );
aclCheckbox.setSelection( ( logLevelValue & LogLevelEnum.ACL.getValue() ) != 0 );
statsCheckbox.setSelection( ( logLevelValue & LogLevelEnum.STATS.getValue() ) != 0 );
stats2Checkbox.setSelection( ( logLevelValue & LogLevelEnum.STATS2.getValue() ) != 0 );
shellCheckbox.setSelection( ( logLevelValue & LogLevelEnum.SHELL.getValue() ) != 0 );
parseCheckbox.setSelection( ( logLevelValue & LogLevelEnum.PARSE.getValue() ) != 0 );
syncCheckbox.setSelection( ( logLevelValue & LogLevelEnum.SYNC.getValue() ) != 0 );
anyCheckbox.setSelection( logLevelValue == LogLevelEnum.ANY.getValue() );
}
/**
* Sets the LogLevel value.
*/
private void setLogLevelText()
{
logLevelText.setText( Integer.toString( logLevelValue ) );
}
/**
* Creates the LogLevel area.
*
* @param parent the parent composite
*/
private void createLogLevelArea( Composite parent )
{
Group logLevelGroup = BaseWidgetUtils.createGroup( parent, "Log Levels", 1 );
logLevelGroup.setLayout( new GridLayout( 5, false ) );
int pos = 0;
// None and any, centered
BaseWidgetUtils.createLabel( logLevelGroup, TABULATION, 1 );
noneCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "None", 1 );
BaseWidgetUtils.createLabel( logLevelGroup, TABULATION, 1 );
anyCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Any", 1 );
BaseWidgetUtils.createLabel( logLevelGroup, TABULATION, 1 );
// The first 5 options
aclCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "ACL", 1 );
buttons[pos++] = aclCheckbox;
argsCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Args", 1 );
buttons[pos++] = argsCheckbox;
berCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "BER", 1 );
buttons[pos++] = berCheckbox;
configCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Config", 1 );
buttons[pos++] = configCheckbox;
connsCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Conns", 1 );
buttons[pos++] = connsCheckbox;
// The next 5 options
filterCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Filter", 1 );
buttons[pos++] = filterCheckbox;
packetsCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Packets", 1 );
buttons[pos++] = packetsCheckbox;
parseCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Parses", 1 );
buttons[pos++] = parseCheckbox;
shellCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Shell", 1 );
buttons[pos++] = shellCheckbox;
statsCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Stats", 1 );
buttons[pos++] = statsCheckbox;
// The last 3 options, centered
BaseWidgetUtils.createLabel( logLevelGroup, TABULATION, 1 );
stats2Checkbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Stats2", 1 );
buttons[pos++] = stats2Checkbox;
traceCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Trace", 1 );
buttons[pos++] = traceCheckbox;
syncCheckbox = BaseWidgetUtils.createCheckbox( logLevelGroup, "Sync", 1 );
buttons[pos++] = syncCheckbox;
BaseWidgetUtils.createLabel( logLevelGroup, TABULATION, 1 );
}
/**
* Creates the LogLevel value area. It's not editable
*
* @param parent the parent composite
*/
private void createLogLevelValueArea( Composite parent )
{
Group logLevelValueGroup = BaseWidgetUtils.createGroup( parent, "LogLevel Value", 1 );
logLevelText = BaseWidgetUtils.createText( logLevelValueGroup, Integer.toString( logLevelValue ), 1 );
logLevelText.setTextLimit( 5 );
logLevelText.setEditable( false );
}
/**
* Adds listeners.
*/
private void addListeners()
{
noneCheckbox.addSelectionListener( checkboxSelectionListener );
for ( Button button : buttons )
{
button.addSelectionListener( checkboxSelectionListener );
}
anyCheckbox.addSelectionListener( checkboxSelectionListener );
}
private void computeLogValue()
{
if ( noneCheckbox.getSelection() )
{
logLevelValue = 0;
}
else if ( anyCheckbox.getSelection() )
{
logLevelValue = -1;
}
else
{
if ( logLevelValue == LogLevelEnum.ANY.getValue() )
{
// We cancel the ANY selection, so we have to set the LogLevelValue
// to 0, as it's currently -1
logLevelValue = 0;
}
// Now, check all the checkBox selections
if ( aclCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.ACL.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.ACL.getValue();
}
if ( argsCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.ARGS.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.ARGS.getValue();
}
if ( berCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.BER.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.BER.getValue();
}
if ( configCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.CONFIG.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.CONFIG.getValue();
}
if ( connsCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.CONNS.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.CONNS.getValue();
}
if ( filterCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.FILTER.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.FILTER.getValue();
}
if ( packetsCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.PACKETS.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.PACKETS.getValue();
}
if ( parseCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.PARSE.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.PARSE.getValue();
}
if ( shellCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.SHELL.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.SHELL.getValue();
}
if ( statsCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.STATS.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.STATS.getValue();
}
if ( stats2Checkbox.getSelection() )
{
logLevelValue |= LogLevelEnum.STATS2.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.STATS2.getValue();
}
if ( syncCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.SYNC.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.SYNC.getValue();
}
if ( traceCheckbox.getSelection() )
{
logLevelValue |= LogLevelEnum.TRACE.getValue();
}
else
{
logLevelValue &= ~LogLevelEnum.TRACE.getValue();
}
}
}
/**
* @return The computed integer that codes for the selected LogLevels
*/
public int getLogLevelValue()
{
return logLevelValue;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/AttributeDialog.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/AttributeDialog.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.openldap.common.ui.dialogs;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* The AttributeDialog is used to enter/select an attribute type.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class AttributeDialog extends Dialog
{
/** The possible attribute types */
private String[] attributeTypes;
/** The return attribute */
private String returnAttribute;
// UI widgets
private Button okButton;
private Combo combo;
/**
* Creates a new instance of AttributeDialog.
*
* @param parentShell the parent shell
* @param connection the connection
*/
public AttributeDialog( Shell parentShell, IBrowserConnection browserConnection )
{
super( parentShell );
init( browserConnection, null );
}
/**
* Creates a new instance of AttributeDialog.
*
* @param parentShell the parent shell
* @param connection the connection
* @param attribute the attribute
*/
public AttributeDialog( Shell parentShell, IBrowserConnection browserConnection, String attribute )
{
super( parentShell );
init( browserConnection, attribute );
}
/**
* Initializes the object.
*
* @param connection the connection
* @param attribute the attribute
*/
private void init( IBrowserConnection browserConnection, String attribute )
{
List<String> attributeTypes = new ArrayList<String>();
if ( browserConnection != null )
{
Collection<AttributeType> atds = browserConnection.getSchema().getAttributeTypeDescriptions();
for ( AttributeType atd : atds )
{
for ( String name : atd.getNames() )
{
attributeTypes.add( name );
}
}
Collections.sort( attributeTypes );
}
this.attributeTypes = attributeTypes.toArray( new String[attributeTypes.size()] );
returnAttribute = attribute;
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell newShell )
{
super.configureShell( newShell );
newShell.setText( "Select Attribute Type" );
}
/**
* {@inheritDoc}
*/
protected void createButtonsForButtonBar( Composite parent )
{
okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
validate();
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
returnAttribute = combo.getText();
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
BaseWidgetUtils.createLabel( c, "Attribute Type:", 1 );
combo = BaseWidgetUtils.createCombo( c, attributeTypes, -1, 1 );
if ( returnAttribute != null )
{
combo.setText( returnAttribute );
}
combo.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
validate();
}
} );
return composite;
}
/**
* Validates the dialog.
*/
private void validate()
{
okButton.setEnabled( !"".equals( combo.getText() ) ); //$NON-NLS-1$
}
/**
* Gets the entered/selected attribute.
*
* @return the attribute
*/
public String getAttribute()
{
return returnAttribute;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsDialog.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsDialog.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.openldap.common.ui.dialogs;
import java.text.ParseException;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.openldap.common.ui.model.UnixPermissions;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* The UnixPermissionsDialog is used to edit a Unix Permissions value. Unix
* permissions are stored using 3 sets of permissions for 3 different entities :
*
* <ul>
* <li>users</li>
* <li>group</li>
* <li>other</li>
* </ul>
*
* with the following permissions :
*
* <ul>
* <li>read</li>
* <li>write</li>
* <li>execute</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class UnixPermissionsDialog extends Dialog
{
/** The octal value */
private String value;
// UI widgets
private Button ownerReadCheckbox;
private Button ownerWriteCheckbox;
private Button ownerExecuteCheckbox;
private Button groupReadCheckbox;
private Button groupWriteCheckbox;
private Button groupExecuteCheckbox;
private Button othersReadCheckbox;
private Button othersWriteCheckbox;
private Button othersExecuteCheckbox;
private Text octalNotationText;
// The octal verifier only accepts values between 0 and 7.
private VerifyListener octalNotationTextVerifyListener = new VerifyListener()
{
public void verifyText( VerifyEvent e )
{
if ( !e.text.matches( "[0-7]*" ) ) //$NON-NLS-1$
{
e.doit = false;
}
}
};
private ModifyListener octalNotationTextModifyListener = new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
resetChecboxSelection();
try
{
UnixPermissions perm = new UnixPermissions( octalNotationText.getText() );
removeListeners();
setCheckboxesValue( perm );
addListeners();
}
catch ( ParseException e1 )
{
// Nothing to do
}
}
};
private SelectionListener checkboxSelectionListener = new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
UnixPermissions perm = new UnixPermissions();
perm.setOwnerRead( ownerReadCheckbox.getSelection() );
perm.setOwnerWrite( ownerWriteCheckbox.getSelection() );
perm.setOwnerExecute( ownerExecuteCheckbox.getSelection() );
perm.setGroupRead( groupReadCheckbox.getSelection() );
perm.setGroupWrite( groupWriteCheckbox.getSelection() );
perm.setGroupExecute( groupExecuteCheckbox.getSelection() );
perm.setOthersRead( othersReadCheckbox.getSelection() );
perm.setOthersWrite( othersWriteCheckbox.getSelection() );
perm.setOthersExecute( othersExecuteCheckbox.getSelection() );
removeListeners();
setOctalValue( perm );
addListeners();
}
};
/**
* Creates a new instance of UnixPermissionsDialog.
*
* @param parentShell the parent shell
*/
public UnixPermissionsDialog( Shell parentShell )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
}
/**
* Creates a new instance of UnixPermissionsDialog.
*
* @param parentShell the parent shell
* @param value the initial value
*/
public UnixPermissionsDialog( Shell parentShell, String value )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.value = value;
}
/**
* {@inheritDoc}
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( "Unix Permissions Dialog" );
}
/**
* {@inheritDoc}
*/
protected void okPressed()
{
try
{
UnixPermissions perm = new UnixPermissions( octalNotationText.getText() );
value = perm.getOctalValue();
}
catch ( ParseException e )
{
value = "0000";
}
super.okPressed();
}
/**
* {@inheritDoc}
*/
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
composite.setLayoutData( gd );
createPermissionsArea( composite );
createOctalNotationArea( composite );
initialize();
addListeners();
applyDialogFont( composite );
return composite;
}
/**
* Initializes the dialog with the initial value
*/
private void initialize()
{
if ( value != null )
{
try
{
UnixPermissions perm = new UnixPermissions( value );
setCheckboxesValue( perm );
setOctalValue( perm );
}
catch ( ParseException e )
{
resetChecboxSelection();
setOctalValue( new UnixPermissions() );
}
}
else
{
resetChecboxSelection();
setOctalValue( new UnixPermissions() );
}
}
/**
* Sets the checkboxes value.
*
* @param perm the Unix permissions
*/
private void setCheckboxesValue( UnixPermissions perm )
{
ownerReadCheckbox.setSelection( perm.isOwnerRead() );
ownerWriteCheckbox.setSelection( perm.isOwnerWrite() );
ownerExecuteCheckbox.setSelection( perm.isOwnerExecute() );
groupReadCheckbox.setSelection( perm.isGroupRead() );
groupWriteCheckbox.setSelection( perm.isGroupWrite() );
groupExecuteCheckbox.setSelection( perm.isGroupExecute() );
othersReadCheckbox.setSelection( perm.isOthersRead() );
othersWriteCheckbox.setSelection( perm.isOthersWrite() );
othersExecuteCheckbox.setSelection( perm.isOthersExecute() );
}
/**
* Sets the octal value.
*
* @param perm the Unix permissions
*/
private void setOctalValue( UnixPermissions perm )
{
octalNotationText.setText( perm.getOctalValue() );
}
/**
* Resets the checkbox selection
*/
private void resetChecboxSelection()
{
ownerReadCheckbox.setSelection( false );
ownerWriteCheckbox.setSelection( false );
ownerExecuteCheckbox.setSelection( false );
groupReadCheckbox.setSelection( false );
groupWriteCheckbox.setSelection( false );
groupExecuteCheckbox.setSelection( false );
othersReadCheckbox.setSelection( false );
othersWriteCheckbox.setSelection( false );
othersExecuteCheckbox.setSelection( false );
}
/**
* Creates the permissions area.
*
* @param parent the parent composite
*/
private void createPermissionsArea( Composite parent )
{
Group symbolicNotationGroup = BaseWidgetUtils.createGroup( parent, "Permissions", 1 );
symbolicNotationGroup.setLayout( new GridLayout( 2, false ) );
BaseWidgetUtils.createLabel( symbolicNotationGroup, "Owner:", 1 );
Composite ownerComposite = BaseWidgetUtils.createColumnContainer( symbolicNotationGroup, 3, true, 1 );
ownerReadCheckbox = BaseWidgetUtils.createCheckbox( ownerComposite, "Read", 1 );
ownerWriteCheckbox = BaseWidgetUtils.createCheckbox( ownerComposite, "Write", 1 );
ownerExecuteCheckbox = BaseWidgetUtils.createCheckbox( ownerComposite, "Execute", 1 );
BaseWidgetUtils.createLabel( symbolicNotationGroup, "Group:", 1 );
Composite groupComposite = BaseWidgetUtils.createColumnContainer( symbolicNotationGroup, 3, true, 1 );
groupReadCheckbox = BaseWidgetUtils.createCheckbox( groupComposite, "Read", 1 );
groupWriteCheckbox = BaseWidgetUtils.createCheckbox( groupComposite, "Write", 1 );
groupExecuteCheckbox = BaseWidgetUtils.createCheckbox( groupComposite, "Execute", 1 );
BaseWidgetUtils.createLabel( symbolicNotationGroup, "Others:", 1 );
Composite othersComposite = BaseWidgetUtils.createColumnContainer( symbolicNotationGroup, 3, true, 1 );
othersReadCheckbox = BaseWidgetUtils.createCheckbox( othersComposite, "Read", 1 );
othersWriteCheckbox = BaseWidgetUtils.createCheckbox( othersComposite, "Write", 1 );
othersExecuteCheckbox = BaseWidgetUtils.createCheckbox( othersComposite, "Execute", 1 );
}
/**
* Creates the octal notation area.
*
* @param parent the parent composite
*/
private void createOctalNotationArea( Composite parent )
{
Group octalNotationGroup = BaseWidgetUtils.createGroup( parent, "Octal Notation", 1 );
octalNotationText = BaseWidgetUtils.createText( octalNotationGroup, "0000", 1 );
octalNotationText.setTextLimit( 4 );
}
/**
* Adds listeners.
*/
private void addListeners()
{
ownerReadCheckbox.addSelectionListener( checkboxSelectionListener );
ownerWriteCheckbox.addSelectionListener( checkboxSelectionListener );
ownerExecuteCheckbox.addSelectionListener( checkboxSelectionListener );
groupReadCheckbox.addSelectionListener( checkboxSelectionListener );
groupWriteCheckbox.addSelectionListener( checkboxSelectionListener );
groupExecuteCheckbox.addSelectionListener( checkboxSelectionListener );
othersReadCheckbox.addSelectionListener( checkboxSelectionListener );
othersWriteCheckbox.addSelectionListener( checkboxSelectionListener );
othersExecuteCheckbox.addSelectionListener( checkboxSelectionListener );
octalNotationText.addVerifyListener( octalNotationTextVerifyListener );
octalNotationText.addModifyListener( octalNotationTextModifyListener );
}
/**
* Remove listeners.
*/
private void removeListeners()
{
ownerReadCheckbox.removeSelectionListener( checkboxSelectionListener );
ownerWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
ownerExecuteCheckbox.removeSelectionListener( checkboxSelectionListener );
groupReadCheckbox.removeSelectionListener( checkboxSelectionListener );
groupWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
groupExecuteCheckbox.removeSelectionListener( checkboxSelectionListener );
othersReadCheckbox.removeSelectionListener( checkboxSelectionListener );
othersWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
othersExecuteCheckbox.removeSelectionListener( checkboxSelectionListener );
octalNotationText.removeVerifyListener( octalNotationTextVerifyListener );
octalNotationText.removeModifyListener( octalNotationTextModifyListener );
}
/**
* Gets the symbolic value (no type included).
*
* @return the symbolic value
*/
public String getSymbolicValue()
{
UnixPermissions perm = null;
try
{
perm = new UnixPermissions( value );
}
catch ( ParseException e )
{
perm = new UnixPermissions();
}
return perm.getSymbolicValue();
}
/**
* Gets the octal value.
*
* @return the octal value
*/
public String getOctalValue()
{
return value;
}
/**
* Gets the decimal value.
*
* @return the decimal value
*/
public String getDecimalValue()
{
return "" + Integer.parseInt( value, 8 );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/PasswordDialog.java | plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/PasswordDialog.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.openldap.common.ui.dialogs;
import org.apache.directory.api.ldap.model.constants.LdapSecurityConstants;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.ldapbrowser.core.model.Password;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
import org.apache.directory.studio.valueeditors.password.Messages;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* The PasswordDialog is used from the password value editor to view the current password
* and to enter a new password.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PasswordDialog extends Dialog
{
/** The constant for no hash method */
private static final String NO_HASH_METHOD = "NO-HASH-METHOD";
/** The supported hash methods */
private static final Object[] HASH_METHODS =
{
LdapSecurityConstants.HASH_METHOD_SHA,
LdapSecurityConstants.HASH_METHOD_SHA256,
LdapSecurityConstants.HASH_METHOD_SHA384,
LdapSecurityConstants.HASH_METHOD_SHA512,
LdapSecurityConstants.HASH_METHOD_SSHA,
LdapSecurityConstants.HASH_METHOD_SSHA256,
LdapSecurityConstants.HASH_METHOD_SSHA384,
LdapSecurityConstants.HASH_METHOD_SSHA512,
LdapSecurityConstants.HASH_METHOD_MD5,
LdapSecurityConstants.HASH_METHOD_SMD5,
LdapSecurityConstants.HASH_METHOD_CRYPT,
NO_HASH_METHOD };
/** The current password */
private Password currentPassword;
/** The new password */
private Password newPassword;
/** The return password*/
private byte[] returnPassword;
// UI Widgets
private Button okButton;
private Group currentPasswordGroup;
private Text currentPasswordText;
private Text currentPasswordHashMethodText;
private Text currentPasswordValueHexText;
private Text currentPasswordSaltHexText;
private Button showCurrentPasswordDetailsButton;
private Group newPasswordGroup;
private Text newPasswordText;
private ComboViewer newPasswordHashMethodComboViewer;
private Text newPasswordPreviewText;
private Button newSaltButton;
private Text newPasswordPreviewValueHexText;
private Text newPasswordPreviewSaltHexText;
private Button showNewPasswordDetailsButton;
/**
* Creates a new instance of PasswordDialog.
*
* @param parentShell the parent shell
* @param currentPassword the current password, null if none
* @param entry the entry used to bind
*/
public PasswordDialog( Shell parentShell, byte[] currentPassword )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
if ( currentPassword != null )
{
this.currentPassword = new Password( currentPassword );
}
}
/**
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( Messages.getString( "PasswordDialog.PasswordEditor" ) ); //$NON-NLS-1$
shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_PASSWORDEDITOR ) );
}
/**
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
protected void okPressed()
{
// create password
if ( newPassword != null )
{
returnPassword = newPassword.toBytes();
}
else
{
returnPassword = null;
}
super.okPressed();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
protected void createButtonsForButtonBar( Composite parent )
{
okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
if ( hasCurrentPassword() )
{
updateCurrentPasswordGroup();
}
updateNewPasswordGroup();
}
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
composite.setLayoutData( gd );
if ( hasCurrentPassword() )
{
createCurrentPasswordGroup( composite );
}
createNewPasswordGroup( composite );
addListeners();
applyDialogFont( composite );
return composite;
}
/**
* Creates the current password group.
*
* @param parent the parent composite
*/
private void createCurrentPasswordGroup( Composite parent )
{
currentPasswordGroup = BaseWidgetUtils.createGroup( parent, "Current Password", 1 );
currentPasswordGroup.setLayout( new GridLayout( 2, false ) );
currentPasswordGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
// Current password text
BaseWidgetUtils.createLabel( currentPasswordGroup, Messages
.getString( "PasswordDialog.CurrentPassword" ) + ":", 1 ); //$NON-NLS-1$//$NON-NLS-2$
currentPasswordText = BaseWidgetUtils.createReadonlyText( currentPasswordGroup, "", 1 ); //$NON-NLS-1$
// Current password details composite
new Label( currentPasswordGroup, SWT.NONE );
Composite currentPasswordDetailsComposite = BaseWidgetUtils.createColumnContainer( currentPasswordGroup,
2, 1 );
// Current password hash method label
BaseWidgetUtils.createLabel( currentPasswordDetailsComposite,
Messages.getString( "PasswordDialog.HashMethod" ), 1 ); //$NON-NLS-1$
currentPasswordHashMethodText = BaseWidgetUtils.createLabeledText( currentPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Current password hex label
BaseWidgetUtils.createLabel( currentPasswordDetailsComposite, Messages
.getString( "PasswordDialog.PasswordHex" ), 1 ); //$NON-NLS-1$
currentPasswordValueHexText = BaseWidgetUtils.createLabeledText( currentPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Current password salt hex label
BaseWidgetUtils.createLabel( currentPasswordDetailsComposite,
Messages.getString( "PasswordDialog.SaltHex" ), 1 ); //$NON-NLS-1$
currentPasswordSaltHexText = BaseWidgetUtils.createLabeledText( currentPasswordDetailsComposite, "", 1 ); //$NON-NLS-1$
// Show current password details button
showCurrentPasswordDetailsButton = BaseWidgetUtils.createCheckbox( currentPasswordDetailsComposite, Messages
.getString( "PasswordDialog.ShowCurrentPasswordDetails" ), 2 ); //$NON-NLS-1$
}
/**
* Creates the new password group.
*
* @param parent the parent composite
*/
private void createNewPasswordGroup( Composite parent )
{
newPasswordGroup = BaseWidgetUtils.createGroup( parent, "New Password", 1 );
newPasswordGroup.setLayout( new GridLayout( 2, false ) );
newPasswordGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
// New password text
BaseWidgetUtils.createLabel( newPasswordGroup, Messages.getString( "PasswordDialog.EnterNewPassword" ), 1 ); //$NON-NLS-1$
newPasswordText = BaseWidgetUtils.createText( newPasswordGroup, "", 1 ); //$NON-NLS-1$
// New password hashing method combo
BaseWidgetUtils.createLabel( newPasswordGroup, Messages.getString( "PasswordDialog.SelectHashMethod" ), 1 ); //$NON-NLS-1$
newPasswordHashMethodComboViewer = new ComboViewer( newPasswordGroup );
newPasswordHashMethodComboViewer.setContentProvider( new ArrayContentProvider() );
newPasswordHashMethodComboViewer.setLabelProvider( new LabelProvider()
{
public String getText( Object element )
{
String hashMethod = getHashMethodName( element );
if ( !"".equals( hashMethod ) )
{
return hashMethod;
}
return super.getText( element );
}
} );
newPasswordHashMethodComboViewer.setInput( HASH_METHODS );
newPasswordHashMethodComboViewer.setSelection( new StructuredSelection( NO_HASH_METHOD ) );
newPasswordHashMethodComboViewer.getControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
// New password preview text
BaseWidgetUtils.createLabel( newPasswordGroup, Messages.getString( "PasswordDialog.PasswordPreview" ), 1 ); //$NON-NLS-1$
newPasswordPreviewText = BaseWidgetUtils.createReadonlyText( newPasswordGroup, "", 1 ); //$NON-NLS-1$
// New salt button
newSaltButton = BaseWidgetUtils.createButton( newPasswordGroup, Messages
.getString( "PasswordDialog.NewSalt" ), 1 ); //$NON-NLS-1$
newSaltButton.setLayoutData( new GridData() );
newSaltButton.setEnabled( false );
// New password preview details composite
Composite newPasswordPreviewDetailsComposite = BaseWidgetUtils.createColumnContainer( newPasswordGroup, 2,
1 );
// New password preview hex label
BaseWidgetUtils.createLabel( newPasswordPreviewDetailsComposite,
Messages.getString( "PasswordDialog.PasswordHex" ), 1 ); //$NON-NLS-1$
newPasswordPreviewValueHexText = BaseWidgetUtils.createLabeledText( newPasswordPreviewDetailsComposite, ":", 1 ); //$NON-NLS-1$
// New password preview salt hex label
BaseWidgetUtils.createLabel( newPasswordPreviewDetailsComposite,
Messages.getString( "PasswordDialog.SaltHex" ), 1 ); //$NON-NLS-1$
newPasswordPreviewSaltHexText = BaseWidgetUtils.createLabeledText( newPasswordPreviewDetailsComposite, "", 1 ); //$NON-NLS-1$
// Show new password details button
showNewPasswordDetailsButton = BaseWidgetUtils.createCheckbox( newPasswordPreviewDetailsComposite, Messages
.getString( "PasswordDialog.ShowNewPasswordDetails" ), 2 ); //$NON-NLS-1$
}
/**
* Updates the current password tab.
*/
private void updateCurrentPasswordGroup()
{
// set current password to the UI widgets
if ( currentPassword != null )
{
currentPasswordHashMethodText.setText( getCurrentPasswordHashMethodName() );
currentPasswordValueHexText.setText( Utils
.getNonNullString( currentPassword.getHashedPasswordAsHexString() ) );
currentPasswordSaltHexText.setText( Utils.getNonNullString( currentPassword.getSaltAsHexString() ) );
currentPasswordText.setText( currentPassword.toString() );
}
// show password details?
if ( showCurrentPasswordDetailsButton.getSelection() )
{
currentPasswordText.setEchoChar( '\0' );
currentPasswordValueHexText.setEchoChar( '\0' );
currentPasswordSaltHexText.setEchoChar( '\0' );
}
else
{
currentPasswordText.setEchoChar( '\u2022' );
currentPasswordValueHexText.setEchoChar( '\u2022' );
currentPasswordSaltHexText.setEchoChar( currentPasswordSaltHexText.getText().equals(
Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
}
}
/**
* Updates the new password tab.
*/
private void updateNewPasswordGroup()
{
// set new password to the UI widgets
newPassword = new Password( getSelectedNewPasswordHashMethod(), newPasswordText.getText() );
if ( !"".equals( newPasswordText.getText() ) || newPassword.getHashMethod() == null ) //$NON-NLS-1$
{
newPasswordPreviewValueHexText
.setText( Utils.getNonNullString( newPassword.getHashedPasswordAsHexString() ) );
newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( newPassword.getSaltAsHexString() ) );
newPasswordPreviewText.setText( newPassword.toString() );
newSaltButton.setEnabled( newPassword.getSalt() != null );
okButton.setEnabled( true );
getShell().setDefaultButton( okButton );
}
else
{
newPassword = null;
newPasswordPreviewValueHexText.setText( Utils.getNonNullString( null ) );
newPasswordPreviewSaltHexText.setText( Utils.getNonNullString( null ) );
newPasswordPreviewText.setText( Utils.getNonNullString( null ) );
newSaltButton.setEnabled( false );
okButton.setEnabled( false );
}
// show password details?
if ( showNewPasswordDetailsButton.getSelection() )
{
newPasswordText.setEchoChar( '\0' );
newPasswordPreviewText.setEchoChar( '\0' );
newPasswordPreviewValueHexText.setEchoChar( '\0' );
newPasswordPreviewSaltHexText.setEchoChar( '\0' );
}
else
{
newPasswordText.setEchoChar( '\u2022' );
newPasswordPreviewText.setEchoChar( newPasswordPreviewText.getText()
.equals( Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
newPasswordPreviewValueHexText.setEchoChar( newPasswordPreviewValueHexText.getText().equals(
Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
newPasswordPreviewSaltHexText.setEchoChar( newPasswordPreviewSaltHexText.getText().equals(
Utils.getNonNullString( null ) ) ? '\0' : '\u2022' );
}
}
/**
* Adds the listeners.
*/
private void addListeners()
{
if ( hasCurrentPassword() )
{
showCurrentPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent arg0 )
{
updateCurrentPasswordGroup();
}
} );
}
newPasswordText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
updateNewPasswordGroup();
}
} );
newPasswordHashMethodComboViewer.addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
updateNewPasswordGroup();
}
} );
newSaltButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
updateNewPasswordGroup();
}
} );
showNewPasswordDetailsButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent arg0 )
{
updateNewPasswordGroup();
}
} );
}
/**
* Indicates if the dialog has a current password.
*
* @return <code>true</code> if the dialog has a current password,
* <code>false</code> if not.
*/
private boolean hasCurrentPassword()
{
return ( ( currentPassword != null ) && ( currentPassword.toBytes().length > 0 ) );
}
/**
* Gets the selected new password hash method.
*
* @return the selected new password hash method
*/
private LdapSecurityConstants getSelectedNewPasswordHashMethod()
{
StructuredSelection selection = ( StructuredSelection ) newPasswordHashMethodComboViewer.getSelection();
if ( !selection.isEmpty() )
{
Object selectedObject = selection.getFirstElement();
if ( selectedObject instanceof LdapSecurityConstants )
{
return ( LdapSecurityConstants ) selectedObject;
}
}
return null;
}
/**
* Gets the name of the hash method.
*
* @param o the hash method object
* @return the name of the hash method
*/
private String getHashMethodName( Object o )
{
if ( o instanceof LdapSecurityConstants )
{
LdapSecurityConstants hashMethod = ( LdapSecurityConstants ) o;
return hashMethod.getName();
}
else if ( ( o instanceof String ) && NO_HASH_METHOD.equals( o ) )
{
return BrowserCoreMessages.model__no_hash;
}
return null;
}
/**
* Gets the current password hash method name.
*
* @return the current password hash method name
*/
private String getCurrentPasswordHashMethodName()
{
LdapSecurityConstants hashMethod = currentPassword.getHashMethod();
if ( hashMethod != null )
{
return Utils.getNonNullString( getHashMethodName( hashMethod ) );
}
else
{
return Utils.getNonNullString( getHashMethodName( NO_HASH_METHOD ) );
}
}
/**
* Gets the new password.
*
* @return the password, either encrypted by the selected
* algorithm or as plain text.
*/
public byte[] getNewPassword()
{
return returnPassword;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Credentials.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Credentials.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.connection.core;
/**
* Default implementation of ICredentials.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Credentials implements ICredentials
{
/** The bind principal. */
private String bindPrincipal;
/** The bind password. */
private String bindPassword;
/** The connection parameter. */
private ConnectionParameter connectionParameter;
/**
* Creates a new instance of Credentials.
*
* @param bindPrincipal the bind principal, typically a Dn
* @param bindPassword the bind password
* @param connectionParameter the connection parameter
*/
public Credentials( String bindPrincipal, String bindPassword, ConnectionParameter connectionParameter )
{
this.bindPrincipal = bindPrincipal;
this.bindPassword = bindPassword;
this.connectionParameter = connectionParameter;
}
/**
* {@inheritDoc}
*/
public ConnectionParameter getConnectionParameter()
{
return connectionParameter;
}
/**
* {@inheritDoc}
*/
public String getBindPrincipal()
{
return bindPrincipal;
}
/**
* {@inheritDoc}
*/
public String getBindPassword()
{
return bindPassword;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionActionFilterAdapter.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionActionFilterAdapter.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.connection.core;
import org.eclipse.ui.IActionFilter;
/**
* This class implements an {@link IActionFilter} adapter for the {@link LdapServer} class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ConnectionActionFilterAdapter implements IActionFilter
{
// Identifier and value strings
private static final String ID = "id"; //$NON-NLS-1$
private static final String NAME = "name"; //$NON-NLS-1$
private static final String HOST = "host"; //$NON-NLS-1$
private static final String PORT = "port"; //$NON-NLS-1$
private static final String ENCRYPTION_METHOD = "encryptionMethod"; //$NON-NLS-1$
private static final String AUTH_METHOD = "authMethod"; //$NON-NLS-1$
private static final String BIND_PRINCIPAL = "bindPrincipal"; //$NON-NLS-1$
private static final String BIND_PASSWORD = "bindPassword"; //$NON-NLS-1$
private static final String SASL_REALM = "saslRealm"; //$NON-NLS-1$
private static final String SASL_QOP = "saslQop"; //$NON-NLS-1$
private static final String SASL_SECURITY_STRENGTH = "saslSecurityStrength"; //$NON-NLS-1$
private static final String SASL_MUTUAL_AUTHENTICATION = "saslMutualAuthentication"; //$NON-NLS-1$
private static final String KRB5_CREDENTIAL_CONFIGURATION = "krb5CredentialConfiguration"; //$NON-NLS-1$
private static final String KRB5_CONFIGURATION = "krb5Configuration"; //$NON-NLS-1$
private static final String KRB5_CONFIGURATION_FILE = "krb5ConfigurationFile"; //$NON-NLS-1$
private static final String KRB5_REALM = "krb5Realm"; //$NON-NLS-1$
private static final String KRB5_KDC_HOST = "krb5KdcHost"; //$NON-NLS-1$
private static final String KRB5_KDC_PORT = "krb5KdcPort"; //$NON-NLS-1$
private static final String VENDOR_NAME = "vendorName"; //$NON-NLS-1$
private static final String VENDOR_VERSION = "vendorVersion"; //$NON-NLS-1$
private static final String SERVER_TYPE = "serverType"; //$NON-NLS-1$
private static final String SUPPORTED_LDAP_VERSIONS = "supportedLdapVersions"; //$NON-NLS-1$
private static final String SUPPORTED_CONTROLS = "supportedControls"; //$NON-NLS-1$
private static final String SUPPORTED_EXTENSIONS = "supportedExtensions"; //$NON-NLS-1$
private static final String SUPPORTED_FEATURES = "supportedFeatures"; //$NON-NLS-1$
/** The class instance */
private static ConnectionActionFilterAdapter INSTANCE = new ConnectionActionFilterAdapter();
/**
* Private constructor.
*/
private ConnectionActionFilterAdapter()
{
// Nothing to initialize
}
/**
* Returns an instance of {@link ConnectionActionFilterAdapter}.
*
* @return
* an instance of {@link ConnectionActionFilterAdapter}
*/
public static ConnectionActionFilterAdapter getInstance()
{
return INSTANCE;
}
/**
* {@inheritDoc}
*/
public boolean testAttribute( Object target, String name, String value )
{
if ( target instanceof Connection )
{
Connection connection = ( Connection ) target;
// ID
if ( ID.equals( name ) )
{
return value.equals( connection.getId() );
}
// NAME
else if ( NAME.equals( name ) )
{
return value.equals( connection.getName() );
}
// HOST
else if ( HOST.equals( name ) )
{
return value.equals( connection.getHost() );
}
// PORT
else if ( PORT.equals( name ) )
{
return value.equals( "" + connection.getPort() ); //$NON-NLS-1$
}
// ENCRYPTION METHOD
else if ( ENCRYPTION_METHOD.equals( name ) )
{
return value.equals( connection.getEncryptionMethod().toString() );
}
// AUTH METHOD
else if ( AUTH_METHOD.equals( name ) )
{
return value.equals( connection.getAuthMethod().toString() );
}
// BIND PRINCIPAL
else if ( BIND_PRINCIPAL.equals( name ) )
{
return value.equals( connection.getBindPrincipal() );
}
// BIND PASSWORD
else if ( BIND_PASSWORD.equals( name ) )
{
return value.equals( connection.getBindPassword() );
}
// SASL REALM
else if ( SASL_REALM.equals( name ) )
{
return value.equals( connection.getSaslRealm() );
}
// SASL QOP
else if ( SASL_QOP.equals( name ) )
{
return value.equals( connection.getSaslQop().toString() );
}
// SASL SECURITY STRENGTH
else if ( SASL_SECURITY_STRENGTH.equals( name ) )
{
return value.equals( connection.getSaslSecurityStrength().toString() );
}
// SASL MUTUAL AUTHENTICATION
else if ( SASL_MUTUAL_AUTHENTICATION.equals( name ) )
{
return value.equals( connection.isSaslMutualAuthentication() ? "true" : "false" ); //$NON-NLS-1$ //$NON-NLS-2$
}
// KRB5 CREDENTIAL CONFIGURATION
else if ( KRB5_CREDENTIAL_CONFIGURATION.equals( name ) )
{
return value.equals( connection.getKrb5CredentialConfiguration().toString() );
}
// KRB5 CONFIGURATION
else if ( KRB5_CONFIGURATION.equals( name ) )
{
return value.equals( connection.getKrb5Configuration().toString() );
}
// KRB5 CONFIGURATION FILE
else if ( KRB5_CONFIGURATION_FILE.equals( name ) )
{
return value.equals( connection.getKrb5ConfigurationFile() );
}
// KRB5 REALM
else if ( KRB5_REALM.equals( name ) )
{
return value.equals( connection.getKrb5Realm() );
}
// KRB5 KDC HOST
else if ( KRB5_KDC_HOST.equals( name ) )
{
return value.equals( connection.getKrb5KdcHost() );
}
// KRB5 KDC PORT
else if ( KRB5_KDC_PORT.equals( name ) )
{
return value.equals( "" + connection.getKrb5KdcPort() ); //$NON-NLS-1$
}
// VENDOR NAME
else if ( VENDOR_NAME.equals( name ) )
{
return value.equals( "" + connection.getDetectedConnectionProperties().getVendorName() ); //$NON-NLS-1$
}
// VENDOR VERSION
else if ( VENDOR_VERSION.equals( name ) )
{
if ( connection.getDetectedConnectionProperties().getVendorVersion() != null )
{
return connection.getDetectedConnectionProperties().getVendorVersion().indexOf( value ) != -1;
}
}
// SERVER TYPE
else if ( SERVER_TYPE.equals( name ) )
{
return value.equals( "" + connection.getDetectedConnectionProperties().getServerType().toString() ); //$NON-NLS-1$
}
// SUPPORTED LDAP VERSIONS
else if ( SUPPORTED_LDAP_VERSIONS.equals( name ) )
{
connection.getDetectedConnectionProperties().getSupportedLdapVersions().contains( value );
}
// SUPPORTED CONTROLS
else if ( SUPPORTED_CONTROLS.equals( name ) )
{
connection.getDetectedConnectionProperties().getSupportedControls().contains( value );
}
// SUPPORTED EXTENSIONS
else if ( SUPPORTED_EXTENSIONS.equals( name ) )
{
connection.getDetectedConnectionProperties().getSupportedExtensions().contains( value );
}
// SUPPORTED FEATURES
else if ( SUPPORTED_FEATURES.equals( name ) )
{
connection.getDetectedConnectionProperties().getSupportedFeatures().contains( value );
}
}
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/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionPropertyPageProvider.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionPropertyPageProvider.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.connection.core;
import org.eclipse.core.runtime.IAdaptable;
/**
* Tagging interface for objects that provide input for the connection
* property page. Implementations must also implement the IAdaptable interface
* and the getAdaptable() method must return the right {@link Connection} object.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface ConnectionPropertyPageProvider extends IAdaptable
{
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.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.connection.core;
import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
/**
* A Connection Listener is informed when a connection is opened or closed.
* To register for those events the implementing plug-in must also implement
* the org.apache.directory.studio.connection.core.connectionListener
* extension point.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface IConnectionListener
{
/**
* Called when an {@link Connection} was opened.
*
* @param connection the opened connection
* @param monitor the progress monitor
*/
void connectionOpened( Connection connection, StudioProgressMonitor monitor );
/**
* Called when an {@link Connection} was closed.
*
* @param connection the closed connection
* @param monitor the progress monitor
*/
void connectionClosed( Connection connection, StudioProgressMonitor monitor );
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DetectedConnectionProperties.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DetectedConnectionProperties.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.connection.core;
import java.util.List;
/**
* This class contains all the properties that were detected for a connection
* during the first connection.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class DetectedConnectionProperties
{
/** The key for the connection parameter "Vendor name" */
public static final String CONNECTION_PARAMETER_VENDOR_NAME = "detectedProperties.vendorName"; //$NON-NLS-1$
/** The key for the connection parameter "Vendor version" */
public static final String CONNECTION_PARAMETER_VENDOR_VERSION = "detectedProperties.vendorVersion"; //$NON-NLS-1$
/** The key for the connection parameter "Server type" */
public static final String CONNECTION_PARAMETER_SERVER_TYPE = "detectedProperties.serverType"; //$NON-NLS-1$
/** The key for the connection parameter "Supported LDAP versions" */
public static final String CONNECTION_PARAMETER_SUPPORTED_LDAP_VERSIONS = "detectedProperties.supportedLdapVersions"; //$NON-NLS-1$
/** The key for the connection parameter "Supported SASL mechanisms" */
public static final String CONNECTION_PARAMETER_SUPPORTED_SASL_MECHANISMS = "detectedProperties.supportedSaslMechanisms"; //$NON-NLS-1$
/** The key for the connection parameter "Supported controls" */
public static final String CONNECTION_PARAMETER_SUPPORTED_CONTROLS = "detectedProperties.supportedControls"; //$NON-NLS-1$
/** The key for the connection parameter "Supported extensions" */
public static final String CONNECTION_PARAMETER_SUPPORTED_EXTENSIONS = "detectedProperties.supportedExtensions"; //$NON-NLS-1$
/** The key for the connection parameter "Supported features" */
public static final String CONNECTION_PARAMETER_SUPPORTED_FEATURES = "detectedProperties.supportedFeatures"; //$NON-NLS-1$
/** The connection */
public Connection connection;
/**
* Creates a new instance of DetectedConnectionProperties.
*
* @param connection the associated connection
*/
public DetectedConnectionProperties( Connection connection )
{
this.connection = connection;
}
/**
* Gets the server type.
*
* @return the server type
*/
public ConnectionServerType getServerType()
{
try
{
String serverType = connection.getConnectionParameter().getExtendedProperty(
CONNECTION_PARAMETER_SERVER_TYPE );
if ( serverType != null )
{
return ConnectionServerType.valueOf( serverType );
}
else
{
return ConnectionServerType.UNKNOWN;
}
}
catch ( IllegalArgumentException e )
{
return ConnectionServerType.UNKNOWN;
}
}
/**
* Gets the supported controls.
*
* @return the supported controls
*/
public List<String> getSupportedControls()
{
return connection.getConnectionParameter().getExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_CONTROLS );
}
/**
* Gets the supported extensions.
*
* @return the supported extensions
*/
public List<String> getSupportedExtensions()
{
return connection.getConnectionParameter().getExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_EXTENSIONS );
}
/**
* Gets the supported features.
*
* @return the supported features
*/
public List<String> getSupportedFeatures()
{
return connection.getConnectionParameter().getExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_FEATURES );
}
/**
* Gets the supported LDAP versions.
*
* @return the supported LDAP versions
*/
public List<String> getSupportedLdapVersions()
{
return connection.getConnectionParameter().getExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_LDAP_VERSIONS );
}
/**
* Gets the supported SASL mechanisms.
*
* @return the supported SASL mechanisms
*/
public List<String> getSupportedSaslMechanisms()
{
return connection.getConnectionParameter().getExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_SASL_MECHANISMS );
}
/**
* Gets the vendor name.
*
* @return the vendor name
*/
public String getVendorName()
{
return connection.getConnectionParameter().getExtendedProperty( CONNECTION_PARAMETER_VENDOR_NAME );
}
/**
* Gets the vendor version.
*
* @return the vendor version
*/
public String getVendorVersion()
{
return connection.getConnectionParameter().getExtendedProperty( CONNECTION_PARAMETER_VENDOR_VERSION );
}
/**
* Sets the server type.
*
* @param serverType the server type
*/
public void setServerType( Object serverType )
{
connection.getConnectionParameter().setExtendedProperty( CONNECTION_PARAMETER_SERVER_TYPE,
serverType.toString() );
}
/**
* Sets the supported controls.
*
* @param supportedControls the supported controls
*/
public void setSupportedControls( List<String> supportedControls )
{
connection.getConnectionParameter().setExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_CONTROLS,
supportedControls );
}
/**
* Sets the supported extensions.
*
* @param supportedExtensions the supported extensions
*/
public void setSupportedExtensions( List<String> supportedExtensions )
{
connection.getConnectionParameter().setExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_EXTENSIONS,
supportedExtensions );
}
/**
* Sets the supported features.
*
* @param supportedFeatures the supported features
*/
public void setSupportedFeatures( List<String> supportedFeatures )
{
connection.getConnectionParameter().setExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_FEATURES,
supportedFeatures );
}
/**
* Sets the supported LDAP versions.
*
* @param supportedLdapVersions the supported LDAP versions
*/
public void setSupportedLdapVersions( List<String> supportedLdapVersions )
{
connection.getConnectionParameter().setExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_LDAP_VERSIONS,
supportedLdapVersions );
}
/**
* Sets the supported SASL mechanisms.
*
* @param supportedSaslMechanisms
* the supported SASL mechanisms
*/
public void setSupportedSaslMechanisms( List<String> supportedSaslMechanisms )
{
connection.getConnectionParameter().setExtendedListStringProperty(
CONNECTION_PARAMETER_SUPPORTED_SASL_MECHANISMS,
supportedSaslMechanisms );
}
/**
* Sets the vendor name.
*
* @param vendorName the vendor name
*/
public void setVendorName( String vendorName )
{
connection.getConnectionParameter().setExtendedProperty( CONNECTION_PARAMETER_VENDOR_NAME, vendorName );
}
/**
* Sets the vendor version.
*
* @param vendorVersion the vendor version
*/
public void setVendorVersion( String vendorVersion )
{
connection.getConnectionParameter().setExtendedProperty( CONNECTION_PARAMETER_VENDOR_VERSION, vendorVersion );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/StudioPagedResultsControl.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.connection.core;
import java.io.IOException;
import javax.naming.ldap.PagedResultsControl;
/**
* Implementation of the RFC 2696 Paged Results Control.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class StudioPagedResultsControl extends StudioControl
{
/** The serialVersionUID. */
private static final long serialVersionUID = -6219375680879062812L;
/** The OID of Simple Paged Search Control (1.2.840.113556.1.4.319) */
public static final String OID = "1.2.840.113556.1.4.319"; //$NON-NLS-1$
/** The name of Simple Paged Search Control. */
public static final String NAME = "Simple Paged Results"; //$NON-NLS-1$
/** The page size. */
private int size;
/** The cookie. */
private byte[] cookie;
/** The is scroll mode. */
private boolean isScrollMode;
/**
* Creates a new instance of StudioPagedResultsControl.
*/
public StudioPagedResultsControl()
{
super();
}
/**
* Creates a new instance of SimplePagedSearchControl.
*
* @param size the page size
* @param cookie the cookie, may be null
* @param critical the critical flag
* @param isScrollMode the is scroll mode
*/
public StudioPagedResultsControl( int size, byte[] cookie, boolean critical, boolean isScrollMode )
{
super( NAME, OID, critical, null );
this.size = size;
this.cookie = cookie;
this.isScrollMode = isScrollMode;
encode();
}
/**
* Gets the size.
*
* @return the size
*/
public int getSize()
{
return size;
}
/**
* Sets the size.
*
* @param size the new size
*/
public void setSize( int size )
{
this.size = size;
encode();
}
/**
* Gets the cookie.
*
* @return the cookie
*/
public byte[] getCookie()
{
return cookie;
}
/**
* Sets the cookie.
*
* @param cookie the new cookie
*/
public void setCookie( byte[] cookie )
{
this.cookie = cookie;
encode();
}
/**
* Checks if is scroll mode.
*
* @return true, if is scroll mode
*/
public boolean isScrollMode()
{
return isScrollMode;
}
/**
* Sets the scroll mode.
*
* @param isScrollMode the new scroll mode
*/
public void setScrollMode( boolean isScrollMode )
{
this.isScrollMode = isScrollMode;
}
/**
* Encodes the size and cookie values.
*/
private void encode()
{
try
{
controlValue = new PagedResultsControl( size, cookie, critical ).getEncodedValue();
}
catch ( IOException e )
{
}
}
/**
* {@inheritDoc}
*/
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + ( isScrollMode ? 1231 : 1237 );
return result;
}
/**
* {@inheritDoc}
*/
public boolean equals( Object obj )
{
if ( !( obj instanceof StudioPagedResultsControl ) )
{
return false;
}
StudioPagedResultsControl other = ( StudioPagedResultsControl ) obj;
return this.toString().equals( other.toString() ) && this.isScrollMode == other.isScrollMode;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Utils.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/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.connection.core;
import java.util.Arrays;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.naming.directory.SearchControls;
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.api.util.Strings;
import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
/**
* Some utils.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Utils
{
private static final String DOT_DOT_DOT = "..."; //$NON-NLS-1$
public static ResourceBundle oidDescriptions = null;
// Load RessourceBundle with OID descriptions
static
{
try
{
oidDescriptions = ResourceBundle.getBundle( "org.apache.directory.studio.connection.core.OIDDescriptions" ); //$NON-NLS-1$
}
catch ( Exception e )
{
e.printStackTrace();
}
}
public static ResourceBundle resultCodeDescriptions = null;
// Load RessourceBundle with OID descriptions
static
{
try
{
resultCodeDescriptions = ResourceBundle
.getBundle( "org.apache.directory.studio.connection.core.ResultCodeDescriptions" ); //$NON-NLS-1$
}
catch ( Exception e )
{
e.printStackTrace();
}
}
/**
* Gets the textual OID description for the given numeric OID.
*
* @param oid the numeric OID
*
* @return the OID description, null if the numeric OID is unknown
*/
public static String getOidDescription( String oid )
{
if ( oidDescriptions != null )
{
try
{
return oidDescriptions.getString( oid );
}
catch ( MissingResourceException ignored )
{
}
}
return null;
}
/**
* Gets the textual result code description for the given numeric result code.
*
* @param code the result code
*
* @return the OID description, null if the numeric OID is unknown
*/
public static String getResultCodeDescription( int code )
{
if ( resultCodeDescriptions != null )
{
try
{
return resultCodeDescriptions.getString( "" + code ); //$NON-NLS-1$
}
catch ( MissingResourceException ignored )
{
}
}
return null;
}
/**
* Shortens the given label to the given maximum length
* and filters non-printable characters.
*
* @param label the label
* @param maxLength the max length
*
* @return the shortened label
*/
public static String shorten( String label, int maxLength )
{
if ( label == null )
{
return null;
}
// shorten label
if ( maxLength < 3 )
{
return DOT_DOT_DOT;
}
if ( label.length() > maxLength )
{
label = label.substring( 0, maxLength / 2 ) + DOT_DOT_DOT
+ label.substring( label.length() - maxLength / 2, label.length() );
}
// filter non-printable characters
StringBuffer sb = new StringBuffer( maxLength + 3 );
for ( int i = 0; i < label.length(); i++ )
{
char c = label.charAt( i );
if ( Character.isISOControl( c ) )
{
sb.append( '.' );
}
else
{
sb.append( c );
}
}
return sb.toString();
}
/**
* Converts a String into a String that could be used as a filename.
*
* @param s
* the String to convert
* @return
* the converted String
*/
public static String getFilenameString( String s )
{
if ( s == null )
{
return null;
}
byte[] b = Strings.getBytesUtf8( s );
StringBuffer sb = new StringBuffer();
for ( int i = 0; i < b.length; i++ )
{
if ( b[i] == '-' || b[i] == '_' || ( '0' <= b[i] && b[i] <= '9' ) || ( 'A' <= b[i] && b[i] <= 'Z' )
|| ( 'a' <= b[i] && b[i] <= 'z' ) )
{
sb.append( ( char ) b[i] );
}
else
{
int x = ( int ) b[i];
if ( x < 0 )
x = 256 + x;
String t = Integer.toHexString( x );
if ( t.length() == 1 )
t = '0' + t; //$NON-NLS-1$
sb.append( t );
}
}
return sb.toString();
}
/**
* Transforms the given search parameters into an LDAP URL.
*
* @param connection the connection
* @param searchBase the search base
* @param scope the search scope
* @param filter the search filter
* @param attributes the returning attributes
*
* @return the LDAP URL for the given search parameters
*/
public static LdapUrl getLdapURL( Connection connection, String searchBase, int scope, String filter,
String[] attributes )
{
LdapUrl url = new LdapUrl();
url.setScheme( connection.getEncryptionMethod() == EncryptionMethod.LDAPS ? LdapUrl.LDAPS_SCHEME
: LdapUrl.LDAP_SCHEME );
url.setHost( connection.getHost() );
url.setPort( connection.getPort() );
try
{
url.setDn( new Dn( searchBase ) );
}
catch ( LdapInvalidDnException e )
{
}
if ( attributes != null )
{
url.setAttributes( Arrays.asList( attributes ) );
}
url.setScope( scope );
url.setFilter( filter );
return url;
}
/**
* Gets the simple normalized form of the LDAP URL: schema, host and port.
*
* @param url the LDAP URL
*
* @return the simple normalized form of the LDAP URL
*/
public static String getSimpleNormalizedUrl( LdapUrl url )
{
return url.getScheme()
+ ( url.getHost() != null ? Strings.toLowerCase( url.getHost() ) : "" ) + ":" + url.getPort(); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Transforms the given search parameters into an ldapsearch command line.
*
* @param connection the connection
* @param searchBase the search base
* @param scope the search scope
* @param aliasesDereferencingMethod the aliases dereferencing method
* @param sizeLimit the size limit
* @param timeLimit the time limit
* @param filter the search filter
* @param attributes the returning attributes
*
* @return the ldapsearch command line for the given search parameters
*/
public static String getLdapSearchCommandLine( Connection connection, String searchBase, int scope,
AliasDereferencingMethod aliasesDereferencingMethod, long sizeLimit, long timeLimit, String filter,
String[] attributes )
{
StringBuilder cmdLine = new StringBuilder();
cmdLine.append( "ldapsearch" ); //$NON-NLS-1$
cmdLine.append( " -H " ).append( //$NON-NLS-1$
connection.getEncryptionMethod() == EncryptionMethod.LDAPS ? LdapUrl.LDAPS_SCHEME : LdapUrl.LDAP_SCHEME )
.append( connection.getHost() ).append( ":" ).append( connection.getPort() ); //$NON-NLS-1$
if ( connection.getEncryptionMethod() == EncryptionMethod.START_TLS )
{
cmdLine.append( " -ZZ" ); //$NON-NLS-1$
}
switch ( connection.getAuthMethod() )
{
case SIMPLE:
cmdLine.append( " -x" ); //$NON-NLS-1$
cmdLine.append( " -D \"" ).append( connection.getBindPrincipal() ).append( "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
cmdLine.append( " -W" ); //$NON-NLS-1$
break;
case SASL_CRAM_MD5:
cmdLine.append( " -U \"" ).append( connection.getBindPrincipal() ).append( "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
cmdLine.append( " -Y \"CRAM-MD5\"" ); //$NON-NLS-1$
break;
case SASL_DIGEST_MD5:
cmdLine.append( " -U \"" ).append( connection.getBindPrincipal() ).append( "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
cmdLine.append( " -Y \"DIGEST-MD5\"" ); //$NON-NLS-1$
break;
case SASL_GSSAPI:
cmdLine.append( " -Y \"GSSAPI\"" ); //$NON-NLS-1$
break;
}
cmdLine.append( " -b \"" ).append( searchBase ).append( "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
String scopeAsString = scope == SearchControls.SUBTREE_SCOPE ? "sub" //$NON-NLS-1$
: scope == SearchControls.ONELEVEL_SCOPE ? "one" : "base"; //$NON-NLS-1$ //$NON-NLS-2$
cmdLine.append( " -s " ).append( scopeAsString ); //$NON-NLS-1$
if ( aliasesDereferencingMethod != AliasDereferencingMethod.NEVER )
{
String aliasAsString = aliasesDereferencingMethod == AliasDereferencingMethod.ALWAYS ? "always" //$NON-NLS-1$
: aliasesDereferencingMethod == AliasDereferencingMethod.FINDING ? "find" //$NON-NLS-1$
: aliasesDereferencingMethod == AliasDereferencingMethod.SEARCH ? "search" : "never"; //$NON-NLS-1$ //$NON-NLS-2$
cmdLine.append( " -a " ).append( aliasAsString ); //$NON-NLS-1$
}
if ( sizeLimit > 0 )
{
cmdLine.append( " -z " ).append( sizeLimit ); //$NON-NLS-1$
}
if ( timeLimit > 0 )
{
cmdLine.append( " -l " ).append( timeLimit ); //$NON-NLS-1$
}
cmdLine.append( " \"" ).append( filter ).append( "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
if ( attributes != null )
{
if ( attributes.length == 0 )
{
cmdLine.append( " \"1.1\"" ); //$NON-NLS-1$
}
for ( String attribute : attributes )
{
cmdLine.append( " \"" ).append( attribute ).append( "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
}
}
return cmdLine.toString();
}
/**
* Gets the LdapDN from the given String or null if the
* String can't be parsed.
*
* @param dn the Dn as String
*
* @return the Dn as LdapDN
*/
public static Dn getLdapDn( String dn )
{
if ( dn == null )
{
return null;
}
try
{
return new Dn( dn );
}
catch ( LdapInvalidDnException e )
{
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/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.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.connection.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.directory.api.util.FileUtils;
import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
import org.apache.directory.studio.connection.core.io.ConnectionIO;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* This class is used to manage {@link ConnectionFolder}s.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ConnectionFolderManager implements ConnectionUpdateListener
{
private static final String CONNECTION_FOLDERS_FILENAME = "connectionFolders.xml"; //$NON-NLS-1$
private static final String ROOT_ID = "0"; //$NON-NLS-1$
/** The root connection folder. */
private ConnectionFolder root;
/** The list of folders. */
private Set<ConnectionFolder> folderList;
/**
* Creates a new instance of ConnectionFolderManager.
*/
public ConnectionFolderManager()
{
this.root = new ConnectionFolder( "" ); //$NON-NLS-1$s
this.root.setId( ROOT_ID ); //$NON-NLS-1$s
this.folderList = new HashSet<ConnectionFolder>();
loadConnectionFolders();
ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
this.folderList.add( this.root );
}
/**
* Gets the filename of the connection folder store.
*
* @return
* the filename of the connection folder store
*/
public static final String getConnectionFolderStoreFileName()
{
String filename = ConnectionCorePlugin.getDefault().getStateLocation().append( CONNECTION_FOLDERS_FILENAME )
.toOSString();
return filename;
}
/**
* Adds the ConnectionFolder to the connection folder list. If there is already a
* connection folder with the same name the new connection folder is renamed.
*
* @param connectionFolder the connection folder
*/
public void addConnectionFolder( ConnectionFolder connectionFolder )
{
if ( getConnectionFolderByName( connectionFolder.getName() ) != null )
{
String newConnectionFolderName = Messages.bind( Messages.copy_n_of_s, "", connectionFolder.getName() ); //$NON-NLS-1$
for ( int i = 2; getConnectionFolderByName( newConnectionFolderName ) != null; i++ )
{
newConnectionFolderName = Messages.bind( Messages.copy_n_of_s, i + " ", connectionFolder.getName() ); //$NON-NLS-1$
}
connectionFolder.setName( newConnectionFolderName );
}
folderList.add( connectionFolder );
ConnectionEventRegistry.fireConnectonFolderAdded( connectionFolder, this );
}
/**
* Removes the given ConnectionFolder from the connection folder list.
*
* @param connectionFolder
* the connection folder to remove
*/
public void removeConnectionFolder( ConnectionFolder connectionFolder )
{
folderList.remove( connectionFolder );
ConnectionEventRegistry.fireConnectonFolderRemoved( connectionFolder, this );
}
/**
* Gets an array of connection folders.
*
* @return
* an array of connection folders
*/
public ConnectionFolder[] getConnectionFolders()
{
return folderList.toArray( new ConnectionFolder[0] );
}
/**
* Gets a connection folder from its id.
*
* @param id
* the id of the connection folder
* @return
* the corresponding connection folder
*/
public ConnectionFolder getConnectionFolderById( String id )
{
for ( ConnectionFolder folder : folderList )
{
if ( folder.getId().equals( id ) )
{
return folder;
}
}
return null;
}
/**
* Gets a connection folder from its name.
*
* @param name
* the name of the connection folder
* @return
* the corresponding connection folder
*/
public ConnectionFolder getConnectionFolderByName( String name )
{
for ( ConnectionFolder folder : folderList )
{
if ( folder.getName().equals( name ) )
{
return folder;
}
}
return null;
}
/**
* Gets the parent connection folder of the given connection.
*
* @param connection
* the connection used to search the parent
* @return
* the parent connection folder of the given connection
*/
public ConnectionFolder getParentConnectionFolder( Connection connection )
{
for ( ConnectionFolder folder : folderList )
{
if ( folder.getConnectionIds().contains( connection.getId() ) )
{
return folder;
}
}
return getRootConnectionFolder();
}
/**
* Gets the parent connection folder of the given connection folder
* or null if the folder doesn't have a parent folder.
*
* @param connectionFolder
* the connection folder used to search the parent
* @return
* the parent connection folder of the given connection folder
* or null if the folder doesn't have a parent folder
*/
public ConnectionFolder getParentConnectionFolder( ConnectionFolder connectionFolder )
{
for ( ConnectionFolder folder : folderList )
{
if ( folder.getSubFolderIds().contains( connectionFolder.getId() ) )
{
return folder;
}
}
return null;
}
/**
* Gets the all sub-folders of the given folder including the given folder.
*
* @param folder the folder
*
* @return all sub-folders
*/
public Set<ConnectionFolder> getAllSubFolders( ConnectionFolder folder )
{
Set<ConnectionFolder> allSubFolders = new HashSet<ConnectionFolder>();
List<String> ids = new ArrayList<String>();
ids.add( folder.getId() );
while ( !ids.isEmpty() )
{
String id = ids.remove( 0 );
ConnectionFolder subFolder = getConnectionFolderById( id );
allSubFolders.add( subFolder );
ids.addAll( subFolder.getSubFolderIds() );
}
return allSubFolders;
}
/**
* Gets the all parent folders of the given folder including the given folder.
*
* @param folder the folder
*
* @return all parent folders
*/
public Set<ConnectionFolder> getAllParentFolders( ConnectionFolder folder )
{
Set<ConnectionFolder> allParentFolders = new HashSet<ConnectionFolder>();
do
{
allParentFolders.add( folder );
folder = getParentConnectionFolder( folder );
}
while ( folder != null );
return allParentFolders;
}
/**
* Gets the root connection folder.
*
* @return the root connection folder
*/
public ConnectionFolder getRootConnectionFolder()
{
return root;
}
/**
* Sets the root connection folder.
*
* @param root the new root connection folder
*/
public void setRootConnectionFolder( ConnectionFolder root )
{
this.root = root;
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionAdded( Connection connection )
{
saveConnectionFolders();
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionRemoved( Connection connection )
{
saveConnectionFolders();
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionUpdated( Connection connection )
{
saveConnectionFolders();
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionOpened( Connection connection )
{
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionClosed( Connection connection )
{
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
*/
public void connectionFolderModified( ConnectionFolder connectionFolder )
{
saveConnectionFolders();
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderAdded(org.apache.directory.studio.connection.core.ConnectionFolder)
*/
public void connectionFolderAdded( ConnectionFolder connectionFolder )
{
saveConnectionFolders();
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderRemoved(org.apache.directory.studio.connection.core.ConnectionFolder)
*/
public void connectionFolderRemoved( ConnectionFolder connectionFolder )
{
saveConnectionFolders();
}
/**
* Saves the Connection Folders
*/
private synchronized void saveConnectionFolders()
{
File file = new File( getConnectionFolderStoreFileName() );
File tempFile = new File( getConnectionFolderStoreFileName() + ConnectionManager.TEMP_SUFFIX );
// To avoid a corrupt file, save object to a temp file first
try ( FileOutputStream fileOutputStream = new FileOutputStream( tempFile ) )
{
ConnectionIO.saveConnectionFolders( folderList, fileOutputStream );
}
catch ( IOException e )
{
Status status = new Status( IStatus.ERROR, ConnectionCoreConstants.PLUGIN_ID,
Messages.error__saving_connections + e.getMessage(), e );
ConnectionCorePlugin.getDefault().getLog().log( status );
return;
}
// move temp file to good file
if ( file.exists() )
{
file.delete();
}
try
{
String content = FileUtils.readFileToString( tempFile, ConnectionManager.ENCODING_UTF8 );
FileUtils.writeStringToFile( file, content, ConnectionManager.ENCODING_UTF8 );
}
catch ( IOException e )
{
Status status = new Status( IStatus.ERROR, ConnectionCoreConstants.PLUGIN_ID,
Messages.error__saving_connections + e.getMessage(), e );
ConnectionCorePlugin.getDefault().getLog().log( status );
return;
}
}
/**
* Loads the Connection Folders
*/
private synchronized void loadConnectionFolders()
{
ConnectionEventRegistry.suspendEventFiringInCurrentThread();
File file = new File( getConnectionFolderStoreFileName() );
if ( file.exists() )
{
try ( FileInputStream fileInputStream = new FileInputStream( file ) )
{
folderList = ConnectionIO.loadConnectionFolders( fileInputStream );
}
catch ( Exception e )
{
Status status = new Status( IStatus.ERROR, ConnectionCoreConstants.PLUGIN_ID,
Messages.error__loading_connections + e.getMessage(), e );
ConnectionCorePlugin.getDefault().getLog().log( status );
}
}
if ( !folderList.isEmpty() )
{
for ( ConnectionFolder folder : folderList )
{
if ( ROOT_ID.equals( folder.getId() ) )
{
root = folder;
}
}
}
else
{
Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
for ( Connection connection : connections )
{
root.addConnectionId( connection.getId() );
}
}
ConnectionEventRegistry.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/connection.core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.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.connection.core;
import javax.naming.InvalidNameException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
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;
/**
* Utility class for Dn specific stuff.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class DnUtils
{
/**
* Gets the prefix, cuts the suffix from the given Dn.
*
* @param dn the Dn
* @param suffix the suffix
*
* @return the prefix
*/
public static Dn getPrefixName( Dn dn, Dn suffix )
{
if ( suffix.size() < 1 )
{
return null;
}
else
{
try
{
Dn prefix = dn.getDescendantOf( suffix );
return prefix;
}
catch ( LdapInvalidDnException lide )
{
return null;
}
}
}
/**
* Composes an Rdn based on the given types and values.
*
* @param rdnTypes the types
* @param rdnValues the values
*
* @return the Rdn
*
* @throws InvalidNameException the invalid name exception
*/
public static Rdn composeRdn( String[] rdnTypes, String[] rdnValues ) throws InvalidNameException
{
try
{
Ava[] avas = new Ava[rdnTypes.length];
for ( int i = 0; i < rdnTypes.length; i++ )
{
avas[i] = new Ava( rdnTypes[i], rdnValues[i] );
}
Rdn rdn = new Rdn( avas );
return rdn;
}
catch ( LdapInvalidDnException e1 )
{
throw new InvalidNameException( Messages.error__invalid_rdn );
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ReferralsInfo.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ReferralsInfo.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.connection.core;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import org.apache.directory.api.ldap.model.exception.LdapLoopDetectedException;
import org.apache.directory.api.ldap.model.message.Referral;
/**
* Helper class that holds info about referrals to be processed and
* already processed referrals.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ReferralsInfo
{
private LinkedList<Referral> referralsToProcess = new LinkedList<Referral>();
private Set<String> processedUrls = new HashSet<String>();
private boolean throwExceptionOnLoop;
/**
* Creates a new instance of ReferralsInfo.
*
* @param throwExceptionOnLoop if an exception should be thrown when a referral loop is detected.
*/
public ReferralsInfo( boolean throwExceptionOnLoop )
{
this.throwExceptionOnLoop = throwExceptionOnLoop;
}
/**
* Adds the referral entry to the list of referrals to be processed.
*
* @param referral the referral
*/
public void addReferral( Referral referral )
{
referralsToProcess.addLast( referral );
}
/**
* Gets the next referral or null.
*
* @return the next referral or null
* @throws LdapLoopDetectedException
*/
public Referral getNextReferral() throws LdapLoopDetectedException
{
handleAlreadyProcessedUrls();
if ( !referralsToProcess.isEmpty() )
{
Referral referral = referralsToProcess.removeFirst();
processedUrls.addAll( referral.getLdapUrls() );
return referral;
}
else
{
return null;
}
}
/**
* Checks for more referrals.
*
* @return true, if there are more referrals
* @throws LdapLoLinkLoopExceptionopDetectedException
*/
public boolean hasMoreReferrals() throws LdapLoopDetectedException
{
handleAlreadyProcessedUrls();
return !referralsToProcess.isEmpty();
}
private void handleAlreadyProcessedUrls() throws LdapLoopDetectedException
{
while ( !referralsToProcess.isEmpty() )
{
Referral referral = referralsToProcess.getFirst();
boolean alreadyProcessed = referral.getLdapUrls().stream().anyMatch( url -> processedUrls.contains( url ) );
if ( alreadyProcessed )
{
// yes, already processed, remove the current referral and continue with filtering
if ( throwExceptionOnLoop )
{
throw new LdapLoopDetectedException( "Referral " + referral.getLdapUrls() + " already processed" );
}
else
{
referralsToProcess.removeFirst();
}
}
else
{
// no, not yet processed, done with filtering
return;
}
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.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.connection.core;
import java.util.TimeZone;
/**
* Constants for the connection core plugin.
* Final reference -> class shouldn't be extended
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public final class ConnectionCoreConstants
{
/**
* 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 ConnectionCoreConstants()
{
}
/** The plug-in ID */
public static final String PLUGIN_ID = ConnectionCoreConstants.class.getPackage().getName();
/** The line separator. */
public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); //$NON-NLS-1$
/** The date format of the modification logger */
public static final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; //$NON-NLS-1$
/** Defines an UTC/GMT time zone */
public static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); //$NON-NLS-1$
/** The constant used to identify if certificates for secure connections should be validated */
public static final String PREFERENCE_VALIDATE_CERTIFICATES = "validateCertificates"; //$NON-NLS-1$
/** The constant used to identify the "enable modification logs" preference */
public static final String PREFERENCE_MODIFICATIONLOGS_ENABLE = "modificationLogsEnable"; //$NON-NLS-1$
/** The constant used to identify the "modification log file count" preference */
public static final String PREFERENCE_MODIFICATIONLOGS_FILE_COUNT = "modificationLogsFileCount"; //$NON-NLS-1$
/** The constant used to identify the "modification log file size" preference */
public static final String PREFERENCE_MODIFICATIONLOGS_FILE_SIZE = "modificationLogsFileSize"; //$NON-NLS-1$
/** The constant used to identify the "enable search request logs" preference */
public static final String PREFERENCE_SEARCHREQUESTLOGS_ENABLE = "searchRequestLogsEnable"; //$NON-NLS-1$
/** The constant used to identify the "enable search result entry logs" preference */
public static final String PREFERENCE_SEARCHRESULTENTRYLOGS_ENABLE = "searchResultEntryLogsEnable"; //$NON-NLS-1$
/** The constant used to identify the "search log file count" preference */
public static final String PREFERENCE_SEARCHLOGS_FILE_COUNT = "searchLogsFileCount"; //$NON-NLS-1$
/** The constant used to identify the "search log file size" preference */
public static final String PREFERENCE_SEARCHLOGS_FILE_SIZE = "searchLogsFileSize"; //$NON-NLS-1$
/** The constant used to identify the "masked attributes" preference */
public static final String PREFERENCE_MODIFICATIONLOGS_MASKED_ATTRIBUTES = "modificationLogsMaskedAttributes"; //$NON-NLS-1$
/** The constant used to identify the "use KRB5 system properties" preference */
public static final String PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES = "useKrb5SystemProperties"; //$NON-NLS-1$
/** The constant used to identify the KRB5 login module class name */
public static final String PREFERENCE_KRB5_LOGIN_MODULE = "krb5LoginModule"; //$NON-NLS-1$
/** The constant used to identify if connections passwords should be stored in a keystore */
public static final String PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE = "connectionsPasswordsKeystore"; //$NON-NLS-1$
/** The constant used to identify the 'off' value for the connections passwords keystore setting */
public static final int PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_OFF = 0;
/** The constant used to identify the 'on' value for the connections passwords keystore setting */
public static final int PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_ON = 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/connection.core/src/main/java/org/apache/directory/studio/connection/core/IAuthHandler.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IAuthHandler.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.connection.core;
/**
* Callback interface to request credentials from a
* higher-level layer (from the UI plugin).
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface IAuthHandler
{
/**
* Gets credentials from this authentication handler.
* The credentials are used to bind to the given connection.
* The authentication handler may display a dialog to the user.
*
* @param connectionParameter the connection to bind to
* @return the credentials, null to cancel the authentication
*/
ICredentials getCredentials( ConnectionParameter connectionParameter );
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Messages.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/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.connection.core;
import org.eclipse.osgi.util.NLS;
/**
* This class contains most of the Strings used by the Plugin
*
* @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.connection.core.messages"; //$NON-NLS-1$
/**
* Creates a new instance of Messages.
*/
private Messages()
{
}
static
{
// initialize resource bundle
NLS.initializeMessages( BUNDLE_NAME, Messages.class );
}
public static String copy_n_of_s;
public static String error__execute_connection_initializer;
public static String error__invalid_rdn;
public static String error__saving_connections;
public static String error__loading_connections;
public static String error__unable_to_create_connection_listener;
public static String error__unable_to_create_ldap_logger;
public static String error__unable_to_get_plugin_properties;
public static String error__connection_is_readonly;
public static String error__untrusted_certificate;
public static String model__no_auth_handler;
public static String model__no_credentials;
public static String jobs__check_bind_name;
public static String jobs__check_bind_task;
public static String jobs__check_bind_error;
public static String jobs__check_network_name;
public static String jobs__check_network_task;
public static String jobs__check_network_error;
public static String jobs__open_connections_name_1;
public static String jobs__open_connections_name_n;
public static String jobs__open_connections_task;
public static String jobs__open_connections_error_1;
public static String jobs__open_connections_error_n;
public static String jobs__close_connections_name_1;
public static String jobs__close_connections_name_n;
public static String jobs__close_connections_task;
public static String jobs__close_connections_error_1;
public static String jobs__close_connections_error_n;
public static String StudioTrustManager_CantCreateTrustManager;
public static String StudioKeyStoreManager_CantAddCertificateToTrustStore;
public static String StudioKeyStoreManager_CantRemoveCertificateFromTrustStore;
public static String StudioKeyStoreManager_CantReadTrustStore;
public static String DirectoryApiConnectionWrapper_NoConnection;
public static String DirectoryApiConnectionWrapper_UnableToConnect;
public static String DirectoryApiConnectionWrapper_UnsecuredConnection;
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ICredentials.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ICredentials.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.connection.core;
/**
* An ICredential holds authentication information for a connection.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface ICredentials
{
/**
* Gets the connection parameter.
*
* @return the connection parameter
*/
ConnectionParameter getConnectionParameter();
/**
* Gets the bind principal, typically a Dn.
*
* @return the bind principal
*/
String getBindPrincipal();
/**
* Gets the bind password.
*
* @return the bind password
*/
String getBindPassword();
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/ConnectionParameter.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.connection.core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.directory.api.ldap.model.constants.SaslQoP;
import org.apache.directory.api.ldap.model.constants.SaslSecurityStrength;
/**
* A Bean class to hold the connection parameters.
* It is used to make connections persistent.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ConnectionParameter
{
/**
* Enum for the used encryption method.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum EncryptionMethod
{
/** No encryption. */
NONE,
/** SSL encryption. */
LDAPS,
/** Encryption using Start TLS extension. */
START_TLS
;
public boolean isEncrytped()
{
return this != NONE;
}
}
/**
* Enum for the used authentication method.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum AuthenticationMethod
{
/** No authentication, anonymous bind. */
NONE(0),
/** Simple authentication, simple bind. */
SIMPLE(1),
/** SASL authentication using DIGEST-MD5. */
SASL_DIGEST_MD5(2),
/** SASL authentication using CRAM-MD5. */
SASL_CRAM_MD5(3),
/** SASL authentication using GSSAPI. */
SASL_GSSAPI(4);
private int value;
private AuthenticationMethod( int value )
{
this.value = value;
}
public int getValue()
{
return value;
}
}
public enum Krb5CredentialConfiguration
{
USE_NATIVE, OBTAIN_TGT
}
public enum Krb5Configuration
{
DEFAULT, FILE, MANUAL
}
/** The unique id. */
private String id;
/** The symbolic name. */
private String name;
/** The host name or IP address of the LDAP server. */
private String host;
/** The port of the LDAP server. */
private int port;
/** The encryption method. */
private EncryptionMethod encryptionMethod;
/** The authentication method. */
private AuthenticationMethod authMethod;
/** The bind principal, typically a Dn. */
private String bindPrincipal;
/** The bind password. */
private String bindPassword;
/** The SASL realm. */
private String saslRealm;
/** The SASL qualitiy of protection. */
private SaslQoP saslQop = SaslQoP.AUTH;
/** The SASL security strength. */
private SaslSecurityStrength saslSecurityStrength = SaslSecurityStrength.HIGH;
/** The SASL mutual authentication flag. */
private boolean saslMutualAuthentication = true;
/** The Kerberos credential configuration. */
private Krb5CredentialConfiguration krb5CredentialConfiguration = Krb5CredentialConfiguration.USE_NATIVE;
/** The Kerberos configuration. */
private Krb5Configuration krb5Configuration = Krb5Configuration.DEFAULT;
/** The Kerberos configuration file. */
private String krb5ConfigurationFile;
/** The Kerberos realm. */
private String krb5Realm;
/** The Kerberos KDC host. */
private String krb5KdcHost;
/** The Kerberos KDC port. */
private int krb5KdcPort = 88;
/** The read only flag. */
private boolean isReadOnly;
/** The extended properties. */
private Map<String, String> extendedProperties;
/** The connection timeout. Default to 30 seconds */
private long timeoutMillis = 30000L;
/**
* Creates a new instance of ConnectionParameter.
*/
public ConnectionParameter()
{
this.extendedProperties = new HashMap<>();
}
/**
* Creates a new instance of ConnectionParameter.
*
* @param name the connection name
* @param host the host
* @param port the port
* @param encryptionMethod the encryption method
* @param authMethod the authentication method
* @param bindPrincipal the bind principal
* @param bindPassword the bind password
* @param saslRealm the SASL realm
* @param isReadOnly the read only flag
* @param extendedProperties the extended properties
* @param timeoutMillis the timeout in milliseconds
*/
public ConnectionParameter( String name, String host, int port, EncryptionMethod encryptionMethod,
AuthenticationMethod authMethod, String bindPrincipal, String bindPassword,
String saslRealm, boolean isReadOnly, Map<String, String> extendedProperties, long timeoutMillis )
{
this.id = createId();
this.name = name;
this.host = host;
this.port = port;
this.encryptionMethod = encryptionMethod;
this.authMethod = authMethod;
this.bindPrincipal = bindPrincipal;
this.bindPassword = bindPassword;
this.saslRealm = saslRealm;
this.isReadOnly = isReadOnly;
this.extendedProperties = new HashMap<>();
if ( extendedProperties != null )
{
this.extendedProperties.putAll( extendedProperties );
}
this.timeoutMillis = timeoutMillis;
}
/**
* Gets the auth method.
*
* @return the auth method
*/
public AuthenticationMethod getAuthMethod()
{
return authMethod;
}
/**
* Sets the auth method.
*
* @param authMethod the auth method
*/
public void setAuthMethod( AuthenticationMethod authMethod )
{
this.authMethod = authMethod;
}
/**
* Gets the bind password.
*
* @return the bind password
*/
public String getBindPassword()
{
return bindPassword;
}
/**
* Sets the bind password.
*
* @param bindPassword the bind password
*/
public void setBindPassword( String bindPassword )
{
this.bindPassword = bindPassword;
}
/**
* Gets the SASL realm
*
* @return the SASL realm
*/
public String getSaslRealm()
{
return saslRealm;
}
/**
* Sets the SASL realm
*
* @param saslRealm the SASL realm
*/
public void setSaslRealm( String saslRealm )
{
this.saslRealm = saslRealm;
}
/**
* Checks if this connection is read only.
*
* @return true, if this connection is read only
*/
public boolean isReadOnly()
{
return isReadOnly;
}
/**
* Sets the read only flag.
*
* @param isReadOnly the new read only flag
*/
public void setReadOnly( boolean isReadOnly )
{
this.isReadOnly = isReadOnly;
}
/**
* Gets the bind principal.
*
* @return the bind principal
*/
public String getBindPrincipal()
{
return bindPrincipal;
}
/**
* Sets the bind principal.
*
* @param bindPrincipal the bind principal
*/
public void setBindPrincipal( String bindPrincipal )
{
this.bindPrincipal = bindPrincipal;
}
/**
* Gets the encryption method.
*
* @return the encryption method
*/
public EncryptionMethod getEncryptionMethod()
{
return encryptionMethod;
}
/**
* Sets the encryption method.
*
* @param encryptionMethod the encryption method
*/
public void setEncryptionMethod( EncryptionMethod encryptionMethod )
{
this.encryptionMethod = encryptionMethod;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId()
{
if ( id == null )
{
id = createId();
}
return id;
}
/**
* Sets the id.
*
* @param id the id
*/
public void setId( String id )
{
this.id = id;
}
/**
* Gets the host.
*
* @return the host
*/
public String getHost()
{
return host;
}
/**
* Sets the host.
*
* @param host the host
*/
public void setHost( String host )
{
this.host = host;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName()
{
return name;
}
/**
* Sets the name.
*
* @param name the name
*/
public void setName( String name )
{
this.name = name;
}
/**
* Gets the port.
*
* @return the port
*/
public int getPort()
{
return port;
}
/**
* Sets the port.
*
* @param port the port
*/
public void setPort( int port )
{
this.port = port;
}
/**
* Gets the SASL quality of protection.
*
* @return the SASL quality of protection
*/
public SaslQoP getSaslQop()
{
return saslQop;
}
/**
* Sets the SASL qualitiy of protection.
*
* @param saslQop the new SASL qualitiy of protection
*/
public void setSaslQop( SaslQoP saslQop )
{
this.saslQop = saslQop;
}
/**
* Gets the SASL security strength.
*
* @return the SASL security strength
*/
public SaslSecurityStrength getSaslSecurityStrength()
{
return saslSecurityStrength;
}
/**
* Sets the SASL security strength.
*
* @param saslSecurityStrength the new SASL security strength
*/
public void setSaslSecurityStrength( SaslSecurityStrength saslSecurityStrength )
{
this.saslSecurityStrength = saslSecurityStrength;
}
/**
* Checks if is SASL mutual authentication.
*
* @return true, if is SASL mutual authentication
*/
public boolean isSaslMutualAuthentication()
{
return saslMutualAuthentication;
}
/**
* Sets the SASL mutual authentication.
*
* @param saslMutualAuthentication the new SASL mutual authentication
*/
public void setSaslMutualAuthentication( boolean saslMutualAuthentication )
{
this.saslMutualAuthentication = saslMutualAuthentication;
}
/**
* Gets the Kerberos credential configuration.
*
* @return the Kerberos credential configuration
*/
public Krb5CredentialConfiguration getKrb5CredentialConfiguration()
{
return krb5CredentialConfiguration;
}
/**
* Sets the Kerberos credential configuration.
*
* @param krb5CredentialConfiguration the new Kerberos credential configuration
*/
public void setKrb5CredentialConfiguration( Krb5CredentialConfiguration krb5CredentialConfiguration )
{
this.krb5CredentialConfiguration = krb5CredentialConfiguration;
}
/**
* Gets the Kerberos configuration.
*
* @return the Kerberos configuration
*/
public Krb5Configuration getKrb5Configuration()
{
return krb5Configuration;
}
/**
* Sets the Kerberos configuration.
*
* @param krb5Configuration the new Kerberos configuration
*/
public void setKrb5Configuration( Krb5Configuration krb5Configuration )
{
this.krb5Configuration = krb5Configuration;
}
/**
* Gets the Kerberos configuration file.
*
* @return the Kerberos configuration file
*/
public String getKrb5ConfigurationFile()
{
return krb5ConfigurationFile;
}
/**
* Sets the Kerberos configuration file.
*
* @param krb5ConfigurationFile the new Kerberos configuration file
*/
public void setKrb5ConfigurationFile( String krb5ConfigurationFile )
{
this.krb5ConfigurationFile = krb5ConfigurationFile;
}
/**
* Gets the Kerberos realm.
*
* @return the Kerberos realm
*/
public String getKrb5Realm()
{
return krb5Realm;
}
/**
* Sets the Kerberos realm.
*
* @param krb5Realm the new Kerberos realm
*/
public void setKrb5Realm( String krb5Realm )
{
this.krb5Realm = krb5Realm;
}
/**
* Gets the Kerberos KDC host.
*
* @return the Kerberos KDC host
*/
public String getKrb5KdcHost()
{
return krb5KdcHost;
}
/**
* Sets the Kerberos KDC host.
*
* @param krb5KdcHost the new Kerberos KDC host
*/
public void setKrb5KdcHost( String krb5KdcHost )
{
this.krb5KdcHost = krb5KdcHost;
}
/**
* Gets the Kerberos KDC port.
*
* @return the Kerberos KDCport
*/
public int getKrb5KdcPort()
{
return krb5KdcPort;
}
/**
* Sets the Kerberos KDC port.
*
* @param krb5KdcPort the new Kerberos KDC port
*/
public void setKrb5KdcPort( int krb5KdcPort )
{
this.krb5KdcPort = krb5KdcPort;
}
/**
* Gets the extended properties.
*
* @return the extended properties
*/
public Map<String, String> getExtendedProperties()
{
return extendedProperties;
}
/**
* Sets the extended properties.
*
* @param extendedProperties the extended properties
*/
public void setExtendedProperties( Map<String, String> extendedProperties )
{
this.extendedProperties = extendedProperties;
}
/**
* Sets the extended property.
*
* @param key the key
* @param value the value
*/
public void setExtendedProperty( String key, String value )
{
extendedProperties.put( key, value );
}
/**
* Gets the extended property.
*
* @param key the key
*
* @return the extended property or null if the property doesn't exist
*/
public String getExtendedProperty( String key )
{
return extendedProperties.get( key );
}
/**
* Sets the extended list string property.
*
* @param key the key
* @param value the value
*/
public void setExtendedListStringProperty( String key, List<String> value )
{
StringBuilder sb = new StringBuilder();
if ( ( value != null ) && ( !value.isEmpty() ) )
{
for ( String string : value )
{
sb.append( string );
sb.append( ';' );
}
sb.deleteCharAt( sb.length() - 1 );
}
extendedProperties.put( key, sb.toString() );
}
/**
* Gets the extended list string property.
*
* @param key the key
*
* @return the extended list string property or <code>null</code> if the property doesn't exist
*/
public List<String> getExtendedListStringProperty( String key )
{
String s = extendedProperties.get( key );
if ( s != null )
{
String[] array = s.split( ";" ); //$NON-NLS-1$
if ( ( array != null ) && ( array.length > 0 ) )
{
return new ArrayList<>( Arrays.asList( array ) );
}
}
return null;
}
/**
* Sets the extended int property.
*
* @param key the key
* @param value the value
*/
public void setExtendedIntProperty( String key, int value )
{
extendedProperties.put( key, Integer.toString( value ) );
}
/**
* Gets the extended int property.
*
* @param key the key
*
* @return the extended int property or -1 if the property doesn't exist
*/
public int getExtendedIntProperty( String key )
{
String s = extendedProperties.get( key );
if ( s != null )
{
return Integer.parseInt( s );
}
else
{
return -1;
}
}
/**
* Sets the extended bool property.
*
* @param key the key
* @param value the value
*/
public void setExtendedBoolProperty( String key, boolean value )
{
extendedProperties.put( key, Boolean.toString( value ) );
}
/**
* Gets the extended bool property.
*
* @param key the key
*
* @return the extended bool property or false if the property doesn'T exist
*/
public boolean getExtendedBoolProperty( String key )
{
String s = extendedProperties.get( key );
if ( s != null )
{
return Boolean.parseBoolean( s );
}
else
{
return false;
}
}
/**
* Gets the timeout in milliseconds.
*
* @return the timeout in milliseconds
*/
public long getTimeoutMillis()
{
return timeoutMillis;
}
/**
* Sets the timeout in milliseconds.
*
* @param timeoutMillis the timeout in milliseconds
*/
public void setTimeoutMillis( long timeoutMillis )
{
this.timeoutMillis = timeoutMillis;
}
/**
* Creates a unique id.
*
* @return the created id
*/
private String createId()
{
return UUID.randomUUID().toString();
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode()
{
return getId().hashCode();
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals( Object obj )
{
if ( obj instanceof ConnectionParameter )
{
ConnectionParameter other = ( ConnectionParameter ) obj;
return getId().equals( other.getId() );
}
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/connection.core/src/main/java/org/apache/directory/studio/connection/core/Controls.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Controls.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.connection.core;
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.controls.ManageDsaIT;
import org.apache.directory.api.ldap.model.message.controls.ManageDsaITImpl;
import org.apache.directory.api.ldap.model.message.controls.OpaqueControl;
import org.apache.directory.api.ldap.model.message.controls.PagedResults;
import org.apache.directory.api.ldap.model.message.controls.PagedResultsImpl;
import org.apache.directory.api.ldap.model.message.controls.Subentries;
import org.apache.directory.api.ldap.model.message.controls.SubentriesImpl;
/**
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Controls
{
public static final Subentries SUBENTRIES_CONTROL = new SubentriesImpl();
static
{
SUBENTRIES_CONTROL.setVisibility( true );
}
public static final ManageDsaIT MANAGEDSAIT_CONTROL = new ManageDsaITImpl();
public static final Control TREEDELETE_CONTROL = new OpaqueControl( "1.2.840.113556.1.4.805", false );
public static final PagedResults newPagedResultsControl( int size )
{
PagedResults control = new PagedResultsImpl();
control.setSize( size );
return control;
}
public static final PagedResults newPagedResultsControl( int size, byte[] cookie )
{
PagedResults control = new PagedResultsImpl();
control.setSize( size );
control.setCookie( cookie );
return control;
}
public static Control create( String oid, boolean isCritical, byte[] value )
{
try
{
LdapApiService codec = LdapApiServiceFactory.getSingleton();
ControlFactory<? extends Control> factory = codec.getRequestControlFactories().get( oid );
Control control = factory.newControl();
control.setCritical( isCritical );
//byte[] bytes = Base64.decode( valueAttribute.getValue().toCharArray() );
factory.decodeValue( control, value );
return control;
}
catch ( DecoderException e )
{
throw new RuntimeException( e );
}
}
public static byte[] getEncodedValue( Control control )
{
LdapApiService codec = LdapApiServiceFactory.getSingleton();
ControlFactory<? extends Control> factory = codec.getRequestControlFactories().get( control.getOid() );
Asn1Buffer buffer = new Asn1Buffer();
factory.encodeValue( buffer, control );
byte[] bytes = buffer.getBytes().array();
return bytes;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/PasswordsKeyStoreManager.java | plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/PasswordsKeyStoreManager.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.connection.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.KeyStore.SecretKeyEntry;
import java.security.KeyStoreException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import org.apache.directory.api.util.FileUtils;
/**
* A wrapper around {@link KeyStore} for storing passwords.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PasswordsKeyStoreManager
{
/** The default filename */
private static final String KEYSTORE_DEFAULT_FILENAME = "passwords.jks";
/** The keystore file name */
private String filename = KEYSTORE_DEFAULT_FILENAME;
/** The master password */
private String masterPassword;
/** The keystore */
private KeyStore keystore;
/**
* Creates a new instance of PasswordsKeyStoreManager.
*/
public PasswordsKeyStoreManager()
{
}
/**
* Creates a new instance of PasswordsKeyStoreManager.
*
* @param filename the filename
*/
public PasswordsKeyStoreManager( String filename )
{
this.filename = filename;
}
/**
* Indicates if the keystore is loaded.
*
* @return <code>true</code> if the keystore is loaded,
* <code>false</code> if not.
*/
public boolean isLoaded()
{
return keystore != null;
}
public void load( String masterPassword ) throws KeyStoreException
{
this.masterPassword = masterPassword;
try
{
keystore = KeyStore.getInstance( "PKCS12" ); //$NON-NLS-1$
// Getting the keystore file
File keystoreFile = getKeyStoreFile();
// Checking if the keystore file is available on disk
if ( keystoreFile.exists() && keystoreFile.isFile() && keystoreFile.canRead() )
{
try ( FileInputStream fis = new FileInputStream( keystoreFile ) )
{
keystore.load( fis, masterPassword.toCharArray() );
}
}
else
{
keystore.load( null, null );
}
}
// Catch for the following exceptions that may be raised while
// handling the keystore:
// - java.security.KeyStoreException
// - java.security.NoSuchAlgorithmException
// - java.security.cert.CertificateException
catch ( GeneralSecurityException e )
{
this.masterPassword = null;
this.keystore = null;
throw new KeyStoreException( e );
}
// Catch for the following exceptions that may be raised while
// handling the file:
// - java.io.IOException
// - java.io.FileNotFoundException
catch ( IOException e )
{
this.masterPassword = null;
this.keystore = null;
throw new KeyStoreException( e );
}
}
/**
* Saves the keystore on disk.
*/
public void save() throws KeyStoreException
{
if ( isLoaded() && ( masterPassword != null ) )
{
try ( FileOutputStream fos = new FileOutputStream( getKeyStoreFile() ) )
{
keystore.store( fos, masterPassword.toCharArray() );
}
// Catch for the following exceptions that may be raised while
// handling the keystore:
// - java.security.KeyStoreException
// - java.security.NoSuchAlgorithmException
// - java.security.cert.CertificateException
catch ( GeneralSecurityException e )
{
throw new KeyStoreException( e );
}
// Catch for the following exceptions that may be raised while
// handling the file:
// - java.io.IOException
// - java.io.FileNotFoundException
catch ( IOException e )
{
throw new KeyStoreException( e );
}
}
}
/**
* Checks the master password.
*
* @param masterPassword the master password
* @return <code>true</code> if the master password is correct,
* <code>false</code> if not.
* @throws KeyStoreException if an error occurs
*/
public boolean checkMasterPassword( String masterPassword ) throws KeyStoreException
{
// If the keystore is already loaded, we compare the master password directly
if ( isLoaded() )
{
return ( ( this.masterPassword != null ) && ( this.masterPassword.equals( masterPassword ) ) );
}
// The keystore is not loaded yet
else
{
try
{
// Loading the keystore
load( masterPassword );
// Returning the check value
return isLoaded();
}
catch ( KeyStoreException e )
{
throw e;
}
}
}
/**
* Sets the master password.
*
* @param masterPassword the master password
*/
public void setMasterPassword( String masterPassword )
{
// Creating a map to store previously stored passwords
Map<String, String> passwordsMap = new HashMap<String, String>();
if ( isLoaded() )
{
// Getting the connection IDs
String[] connectionIds = getConnectionIds();
// Storing the password of each connection in the map
for ( String connectionId : connectionIds )
{
// Getting the connection password
String connectionPassword = getConnectionPassword( connectionId );
// Checking if we got a password
if ( connectionPassword != null )
{
// Storing the password of the connection in the map
passwordsMap.put( connectionId, connectionPassword );
}
// Removing the password from the keystore
storeConnectionPassword( connectionId, null, false );
}
}
// Assigning the new master password
this.masterPassword = masterPassword;
// Storing the previous passwords back in the keystore
if ( passwordsMap.size() > 0 )
{
Set<String> connectionIds = passwordsMap.keySet();
// Storing the password of each connection in the keystore
if ( connectionIds != null )
{
for ( String connectionId : connectionIds )
{
String connectionPassword = passwordsMap.get( connectionId );
if ( connectionPassword != null )
{
// Storing the password of the connection in the keystore
storeConnectionPassword( connectionId, connectionPassword, false );
}
}
}
}
}
/**
* Gets the keystore file.
*
* @return the keystore file
*/
public File getKeyStoreFile()
{
return ConnectionCorePlugin.getDefault().getStateLocation().append( filename ).toFile();
}
/**
* Deletes the keystore.
*/
public void deleteKeystoreFile()
{
// Getting the keystore file
File keystoreFile = getKeyStoreFile();
// Checking if the keystore file is available on disk
if ( keystoreFile.exists() && keystoreFile.isFile() && keystoreFile.canRead() && keystoreFile.canWrite() )
{
keystoreFile.delete();
}
}
/**
* Gets the connections IDs contained in the keystore.
*
* @return the connection IDs contained in the keystore
*/
public String[] getConnectionIds()
{
if ( keystore != null )
{
try
{
return Collections.list( keystore.aliases() ).toArray( new String[0] );
}
catch ( KeyStoreException e )
{
// Silent
}
}
return new String[0];
}
/**
* Stores a connection password.
*
* @param connection the connection
* @param password the password
*/
public void storeConnectionPassword( Connection connection, String password )
{
if ( connection != null )
{
storeConnectionPassword( connection.getId(), password );
}
}
/**
* Stores a connection password.
*
* @param connection the connection
* @param password the password
* @param saveKeystore if the keystore needs to be saved
*/
public void storeConnectionPassword( Connection connection, String password, boolean saveKeystore )
{
if ( connection != null )
{
storeConnectionPassword( connection.getId(), password, true );
}
}
/**
* Stores a connection password.
*
* @param connectionId the connection id
* @param password the password
*/
public void storeConnectionPassword( String connectionId, String password )
{
storeConnectionPassword( connectionId, password, true );
}
/**
* Stores a connection password.
*
* @param connectionId the connection id
* @param password the password
* @param saveKeystore if the keystore needs to be saved
*/
public void storeConnectionPassword( String connectionId, String password, boolean saveKeystore )
{
if ( isLoaded() && ( connectionId != null ) )
{
try
{
// Checking if the password is null
if ( password == null )
{
// We need to remove the corresponding entry in the keystore
if ( keystore.containsAlias( connectionId ) )
{
keystore.deleteEntry( connectionId );
}
}
else
{
// Generating a secret key from the password
SecretKeyFactory factory = SecretKeyFactory.getInstance( "PBE" );
SecretKey generatedSecret = factory.generateSecret( new PBEKeySpec( password.toCharArray() ) );
// Setting the entry in the keystore
keystore.setEntry( connectionId, new KeyStore.SecretKeyEntry( generatedSecret ),
new KeyStore.PasswordProtection( masterPassword.toCharArray() ) );
}
// Saving
if ( saveKeystore )
{
save();
}
}
catch ( Exception e )
{
// Silent
}
}
}
/**
* Gets a connection password.
*
* @param connection the connection
* @return the password for the connection or <code>null</code>.
*/
public String getConnectionPassword( Connection connection )
{
if ( connection != null )
{
return getConnectionPassword( connection.getId() );
}
return null;
}
/**
* Gets a connection password.
*
* @param connectionId the connection id
* @return the password for the connection id or <code>null</code>.
*/
public String getConnectionPassword( String connectionId )
{
if ( isLoaded() && ( connectionId != null ) )
{
try
{
SecretKeyFactory factory = SecretKeyFactory.getInstance( "PBE" );
SecretKeyEntry ske = ( SecretKeyEntry ) keystore.getEntry( connectionId,
new KeyStore.PasswordProtection( masterPassword.toCharArray() ) );
if ( ske != null )
{
PBEKeySpec keySpec = ( PBEKeySpec ) factory.getKeySpec( ske.getSecretKey(), PBEKeySpec.class );
if ( keySpec != null )
{
char[] password = keySpec.getPassword();
if ( password != null )
{
return new String( password );
}
}
}
}
catch ( Exception e )
{
return null;
}
}
return null;
}
/**
* Resets the keystore manager.
*/
public void reset()
{
// Reseting the fields
this.keystore = null;
this.masterPassword = null;
// Getting the keystore file
File keystoreFile = getKeyStoreFile();
// If the keystore file exists, we need to remove it
if ( keystoreFile.exists() )
{
// Deleting the file
FileUtils.deleteQuietly( keystoreFile );
}
}
public void unload()
{
// Reseting the fields
this.keystore = null;
this.masterPassword = null;
}
public void reload( String masterPassword ) throws KeyStoreException
{
unload();
load( masterPassword );
}
/**
* Gets the master password.
*
* @return the master password
*/
public String getMasterPassword()
{
return masterPassword;
}
} | java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.