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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/NonExistingLdifEditorInput.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/NonExistingLdifEditorInput.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.ldifeditor.editor;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.editors.text.ILocationProvider;
/**
* This EditorInput is used to create a LDIF file that isn't saved yet.
* It is used from File->New, but also from the embedded LDIF editors
* in modification view, in batch operation wizard and the LDIF preference page.
*
* Inspired from org.eclipse.ui.internal.editors.text.NonExistingFileEditorInput.java
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class NonExistingLdifEditorInput implements IPathEditorInput, ILocationProvider
{
/** The counter to create unique names */
private static int counter = 0;
/** The name, displayed in Editor tab */
private String name;
/**
* Creates a new instance of NonExistingLdifEditorInput.
*/
public NonExistingLdifEditorInput()
{
counter++;
name = "LDIF " + counter; //$NON-NLS-1$
}
/**
* As the name says, this implementations always returns false.
*/
public boolean exists()
{
return false;
}
/**
* Returns the LDIF file image.
*/
public ImageDescriptor getImageDescriptor()
{
return LdifEditorActivator.getDefault().getImageDescriptor( LdifEditorConstants.IMG_BROWSER_LDIFEDITOR );
}
/**
* Returns the name.
*/
public String getName()
{
return name;
}
/**
* As the name says, this implementations always returns false.
*/
public IPersistableElement getPersistable()
{
return null;
}
/**
* Returns the name.
*/
public String getToolTipText()
{
return name;
}
/**
* An EditorInput must return a good ILocationProvider, otherwise
* the editor is not editable.
*/
public Object getAdapter( Class adapter )
{
if ( ILocationProvider.class.equals( adapter ) )
{
return this;
}
return Platform.getAdapterManager().getAdapter( this, adapter );
}
/**
* This implementation returns a path that point to the plugin's
* state location.
*
* A valid, writeable path must be returned, otherwise the editor
* is not editable.
*/
public IPath getPath( Object element )
{
if ( element instanceof NonExistingLdifEditorInput )
{
NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) element;
return input.getPath();
}
return null;
}
/**
* This implemention just compares the names
*/
public boolean equals( Object o )
{
if ( o == this )
{
return true;
}
if ( o instanceof NonExistingLdifEditorInput )
{
NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) o;
return name.equals( input.name );
}
return false;
}
/**
* Returns hash code of the name string.
*/
public int hashCode()
{
return name.hashCode();
}
/**
* This implementation returns a path that point to the plugin's
* state location. The state location is a platform indepentend
* location that is writeable.
*
* A valid, writeable path must be returned, otherwise the editor
* is not editable.
*/
public IPath getPath()
{
return LdifEditorActivator.getDefault().getStateLocation().append( name + ".ldif" ); //$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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifSourceViewerConfiguration.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifSourceViewerConfiguration.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.ldifeditor.editor;
import org.apache.directory.studio.ldapbrowser.common.widgets.DialogContentAssistant;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.reconciler.LdifReconcilingStrategy;
import org.apache.directory.studio.ldifeditor.editor.text.LdifAnnotationHover;
import org.apache.directory.studio.ldifeditor.editor.text.LdifAutoEditStrategy;
import org.apache.directory.studio.ldifeditor.editor.text.LdifCompletionProcessor;
import org.apache.directory.studio.ldifeditor.editor.text.LdifDamagerRepairer;
import org.apache.directory.studio.ldifeditor.editor.text.LdifDoubleClickStrategy;
import org.apache.directory.studio.ldifeditor.editor.text.LdifPartitionScanner;
import org.apache.directory.studio.ldifeditor.editor.text.LdifTextHover;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.graphics.RGB;
/**
* This class enables the features of the editor (Syntax coloring, code completion, etc.)
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifSourceViewerConfiguration extends SourceViewerConfiguration
{
private ILdifEditor editor;
// Error hover and annotations
private LdifAnnotationHover annotationHover;
private LdifTextHover textHover;
// Presentation Reconciler (syntax highlight)
private PresentationReconciler presentationReconciler;
private LdifDamagerRepairer damagerRepairer;
// Content Assistent
private boolean contentAssistEnabled;
private ContentAssistant contentAssistant;
private IContentAssistProcessor contentAssistProcessor;
private LdifDoubleClickStrategy doubleClickStrategy;
// Asynchronous Reconciler (annotations)
private MonoReconciler reconciler;
private LdifReconcilingStrategy reconcilingStrategy;
private IAutoEditStrategy[] autoEditStrategies;
/**
* Creates a new instance of LdifSourceViewerConfiguration.
*
* @param editor
* @param contentAssistEnabled
*/
public LdifSourceViewerConfiguration( ILdifEditor editor, boolean contentAssistEnabled )
{
super();
this.editor = editor;
this.contentAssistEnabled = contentAssistEnabled;
}
/**
* Overwrites the style set in preference store
*
* @param key
* the key
* @param rgb
* the color
* @param style
* the stule
*/
public void setTextAttribute( String key, RGB rgb, int style )
{
damagerRepairer.setTextAttribute( key, rgb, style );
}
/**
* {@inheritDoc}
*/
public String getConfiguredDocumentPartitioning( ISourceViewer sourceViewer )
{
return LdifDocumentSetupParticipant.LDIF_PARTITIONING;
}
/**
* {@inheritDoc}
*/
public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
{
return new String[]
{ IDocument.DEFAULT_CONTENT_TYPE, LdifPartitionScanner.LDIF_RECORD };
}
/**
* {@inheritDoc}
*/
public ITextDoubleClickStrategy getDoubleClickStrategy( ISourceViewer sourceViewer, String contentType )
{
if ( this.doubleClickStrategy == null )
{
this.doubleClickStrategy = new LdifDoubleClickStrategy();
}
return this.doubleClickStrategy;
}
/**
* {@inheritDoc}
*/
public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
{
if ( this.presentationReconciler == null )
{
this.presentationReconciler = new PresentationReconciler();
this.presentationReconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) );
damagerRepairer = new LdifDamagerRepairer( this.editor );
this.presentationReconciler.setDamager( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
this.presentationReconciler.setRepairer( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
this.presentationReconciler.setDamager( damagerRepairer, LdifPartitionScanner.LDIF_RECORD );
this.presentationReconciler.setRepairer( damagerRepairer, LdifPartitionScanner.LDIF_RECORD );
}
return this.presentationReconciler;
}
/**
* {@inheritDoc}
*/
public IReconciler getReconciler( ISourceViewer sourceViewer )
{
if ( this.reconciler == null )
{
this.reconcilingStrategy = new LdifReconcilingStrategy( editor );
// Reconciler reconciler = new Reconciler();
// reconciler.setIsIncrementalReconciler(true);
// reconciler.setReconcilingStrategy(strategy,
// LdifPartitionScanner.LDIF_RECORD);
// reconciler.setReconcilingStrategy(strategy,
// IDocument.DEFAULT_CONTENT_TYPE);
// reconciler.setProgressMonitor(new NullProgressMonitor());
// reconciler.setDelay(500);
// return reconciler;
this.reconciler = new MonoReconciler( this.reconcilingStrategy, true );
this.reconciler.setProgressMonitor( new NullProgressMonitor() );
this.reconciler.setDelay( 500 );
}
return this.reconciler;
}
/**
* {@inheritDoc}
*/
public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
{
if ( this.contentAssistEnabled )
{
if ( this.contentAssistant == null )
{
// this.contentAssistant = new ContentAssistant();
this.contentAssistant = new DialogContentAssistant();
this.contentAssistProcessor = new LdifCompletionProcessor( editor, contentAssistant );
this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
LdifPartitionScanner.LDIF_RECORD );
this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
IDocument.DEFAULT_CONTENT_TYPE );
this.contentAssistant.setDocumentPartitioning( LdifDocumentSetupParticipant.LDIF_PARTITIONING );
this.contentAssistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE );
this.contentAssistant.setInformationControlCreator( getInformationControlCreator( sourceViewer ) );
IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore();
this.contentAssistant.enableAutoInsert( store
.getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
this.contentAssistant.enableAutoActivation( store
.getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
this.contentAssistant.setAutoActivationDelay( store
.getInt( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
// this.contentAssistant.enableAutoInsert(true);
// this.contentAssistant.enableAutoActivation(true);
// this.contentAssistant.setAutoActivationDelay(100);
}
return this.contentAssistant;
}
else
{
return null;
}
}
/**
* {@inheritDoc}
*/
public IAnnotationHover getAnnotationHover( ISourceViewer sourceViewer )
{
if ( this.annotationHover == null )
{
this.annotationHover = new LdifAnnotationHover( this.editor );
}
return this.annotationHover;
}
/**
* {@inheritDoc}
*/
public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType )
{
if ( this.textHover == null )
{
this.textHover = new LdifTextHover( this.editor );
}
return this.textHover;
}
/**
* {@inheritDoc}
*/
public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer, String contentType )
{
if ( autoEditStrategies == null )
{
this.autoEditStrategies = new IAutoEditStrategy[2];
this.autoEditStrategies[0] = new DefaultIndentLineAutoEditStrategy();
this.autoEditStrategies[1] = new LdifAutoEditStrategy( this.editor );
}
return autoEditStrategies;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifEditorContributor.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifEditorContributor.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.ldifeditor.editor;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
/**
* This class manages the installation and removal of global actions for the LDIF Editor.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifEditorContributor extends BasicTextEditorActionContributor
{
private static final String CONTENTASSIST_ACTION = LdifEditorConstants.CONTENTASSIST_ACTION;
private RetargetTextEditorAction contentAssist;
/**
* Creates a new instance of LdifEditorContributor.
*/
public LdifEditorContributor()
{
super();
contentAssist = new RetargetTextEditorAction( LdifEditorActivator.getDefault().getResourceBundle(),
"ContentAssistProposal." ); //$NON-NLS-1$
contentAssist.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS );
}
/**
* {@inheritDoc}
*/
public void setActiveEditor( IEditorPart part )
{
super.setActiveEditor( part );
ITextEditor editor = ( part instanceof ITextEditor ) ? ( ITextEditor ) part : null;
contentAssist.setAction( getAction( editor, CONTENTASSIST_ACTION ) );
}
/**
* {@inheritDoc}
*/
public void init( IActionBars bars, IWorkbenchPage page )
{
super.init( bars, page );
bars.setGlobalActionHandler( CONTENTASSIST_ACTION, contentAssist );
}
/**
* {@inheritDoc}
*/
public void dispose()
{
setActiveEditor( null );
super.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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifDocumentSetupParticipant.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifDocumentSetupParticipant.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.ldifeditor.editor;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.text.LdifPartitionScanner;
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.FastPartitioner;
/**
* This class implements the IDocumentSetupParticipant interface for LDIF document
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifDocumentSetupParticipant implements IDocumentSetupParticipant
{
/** The LDIF Partitioning ID */
public final static String LDIF_PARTITIONING = LdifEditorConstants.LDIF_PARTITIONING;
/**
* Creates a new instance of LdifDocumentSetupParticipant.
*/
public LdifDocumentSetupParticipant()
{
}
/**
* {@inheritDoc}
*/
public void setup( IDocument document )
{
if ( document instanceof IDocumentExtension3 )
{
IDocumentExtension3 extension3 = ( IDocumentExtension3 ) document;
if ( extension3.getDocumentPartitioner( LdifDocumentSetupParticipant.LDIF_PARTITIONING ) == null )
{
IDocumentPartitioner partitioner = createDocumentPartitioner();
extension3.setDocumentPartitioner( LDIF_PARTITIONING, partitioner );
partitioner.connect( document );
}
}
}
/**
* Creates the Document Partitioner
*
* @return
* the Document Partitioner
*/
private IDocumentPartitioner createDocumentPartitioner()
{
IDocumentPartitioner partitioner = new FastPartitioner( new LdifPartitionScanner(), new String[]
{ LdifPartitionScanner.LDIF_RECORD } );
return partitioner;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/Messages.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/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.ldifeditor.editor;
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/ExecuteLdifAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/ExecuteLdifAction.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.ldifeditor.editor;
import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectBrowserConnectionDialog;
import org.apache.directory.studio.ldapbrowser.core.jobs.ExecuteLdifRunnable;
import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
/**
* This Action executes LDIF code.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ExecuteLdifAction extends Action
{
/** The LDIF Editor */
private LdifEditor editor;
/**
* Creates a new instance of ExecuteLdifAction.
*
* @param editor
* the attached editor
*/
public ExecuteLdifAction( LdifEditor editor )
{
super(
Messages.getString( "ExecuteLdifAction.ExecuteLDIF" ), LdifEditorActivator.getDefault().getImageDescriptor( LdifEditorConstants.IMG_EXECUTE ) ); //$NON-NLS-1$
super.setToolTipText( Messages.getString( "ExecuteLdifAction.ExecuteLDIF" ) ); //$NON-NLS-1$
this.editor = editor;
}
/**
* {@inheritDoc}
*/
public void run()
{
IBrowserConnection connection = editor.getConnection();
// Checking if we already have a connection
if ( connection == null )
{
// Requesting the user to select a connection
SelectBrowserConnectionDialog dialog = new SelectBrowserConnectionDialog( editor.getSite().getShell(),
Messages.getString( "ExecuteLdifAction.SelectConnection" ), null ); //$NON-NLS-1$
if ( dialog.open() == SelectBrowserConnectionDialog.OK )
{
connection = dialog.getSelectedBrowserConnection();
if ( connection != null )
{
editor.setConnection( connection, true );
}
}
// Checking a second time if we have a connection
if ( connection == null )
{
return;
}
}
String ldif = editor.getLdifModel().toRawString();
IPreferenceStore preferenceStore = LdifEditorActivator.getDefault().getPreferenceStore();
boolean updateIfEntryExistsButton = preferenceStore
.getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_UPDATEIFENTRYEXISTS );
boolean continueOnErrorButton = preferenceStore
.getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_CONTINUEONERROR );
ExecuteLdifRunnable runnable = new ExecuteLdifRunnable( connection, ldif, updateIfEntryExistsButton,
continueOnErrorButton );
StudioBrowserJob job = new StudioBrowserJob( runnable );
job.execute();
}
/**
* {@inheritDoc}
*/
public boolean isEnabled()
{
return editor != 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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifEditor.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifEditor.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.ldifeditor.editor;
import java.io.File;
import java.util.ResourceBundle;
import org.apache.directory.studio.common.ui.CommonUIUtils;
import org.apache.directory.studio.common.ui.filesystem.PathEditorInput;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.common.ui.widgets.WidgetModifyEvent;
import org.apache.directory.studio.common.ui.widgets.WidgetModifyListener;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.actions.ValueEditorPreferencesAction;
import org.apache.directory.studio.ldapbrowser.common.widgets.search.BrowserConnectionWidget;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.actions.EditLdifAttributeAction;
import org.apache.directory.studio.ldifeditor.editor.actions.EditLdifRecordAction;
import org.apache.directory.studio.ldifeditor.editor.actions.FormatLdifDocumentAction;
import org.apache.directory.studio.ldifeditor.editor.actions.FormatLdifRecordAction;
import org.apache.directory.studio.ldifeditor.editor.actions.OpenBestValueEditorAction;
import org.apache.directory.studio.ldifeditor.editor.actions.OpenDefaultValueEditorAction;
import org.apache.directory.studio.ldifeditor.editor.actions.OpenValueEditorAction;
import org.apache.directory.studio.ldifeditor.editor.text.LdifPartitionScanner;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.utils.ActionUtils;
import org.apache.directory.studio.valueeditors.AbstractDialogValueEditor;
import org.apache.directory.studio.valueeditors.IValueEditor;
import org.apache.directory.studio.valueeditors.ValueEditorManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.part.IShowInTargetList;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.ui.texteditor.ContentAssistAction;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
/**
* This class implements the LDIF editor
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifEditor extends TextEditor implements ILdifEditor, ConnectionUpdateListener, IPartListener2
{
private ViewForm control;
private BrowserConnectionWidget browserConnectionWidget;
private ToolBar actionToolBar;
private IToolBarManager actionToolBarManager;
private IBrowserConnection browserConnection;
private ProjectionSupport projectionSupport;
protected LdifOutlinePage outlinePage;
private ValueEditorManager valueEditorManager;
private OpenBestValueEditorAction openBestValueEditorAction;
private OpenValueEditorAction[] openValueEditorActions;
private ValueEditorPreferencesAction valueEditorPreferencesAction;
protected boolean showToolBar = true;
/**
* Creates a new instance of LdifEditor.
*/
public LdifEditor()
{
super();
setSourceViewerConfiguration( new LdifSourceViewerConfiguration( this, true ) );
setDocumentProvider( new LdifDocumentProvider() );
IPreferenceStore editorStore = EditorsUI.getPreferenceStore();
IPreferenceStore browserStore = LdifEditorActivator.getDefault().getPreferenceStore();
IPreferenceStore combinedStore = new ChainedPreferenceStore( new IPreferenceStore[]
{ browserStore, editorStore } );
setPreferenceStore( combinedStore );
setHelpContextId( LdifEditorConstants.PLUGIN_ID + "." + "tools_ldif_editor" ); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#handlePreferenceStoreChanged(org.eclipse.jface.util.PropertyChangeEvent)
*/
protected void handlePreferenceStoreChanged( PropertyChangeEvent event )
{
try
{
ISourceViewer sourceViewer = getSourceViewer();
if ( sourceViewer == null )
{
return;
}
int topIndex = getSourceViewer().getTopIndex();
getSourceViewer().getDocument().set( getSourceViewer().getDocument().get() );
getSourceViewer().setTopIndex( topIndex );
}
finally
{
super.handlePreferenceStoreChanged( event );
}
}
/**
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages()
*/
protected String[] collectContextMenuPreferencePages()
{
String[] ids = super.collectContextMenuPreferencePages();
String[] more = new String[ids.length + 4];
more[0] = LdifEditorConstants.PREFERENCEPAGEID_LDIFEDITOR;
more[1] = LdifEditorConstants.PREFERENCEPAGEID_LDIFEDITOR_CONTENTASSIST;
more[2] = LdifEditorConstants.PREFERENCEPAGEID_LDIFEDITOR_SYNTAXCOLORING;
more[3] = LdifEditorConstants.PREFERENCEPAGEID_LDIFEDITOR_TEMPLATES;
System.arraycopy( ids, 0, more, 4, ids.length );
return more;
}
/**
* Gets the ID of the LDIF Editor
*
* @return
* the ID of the LDIF Editor
*/
public static String getId()
{
return LdifEditorConstants.EDITOR_LDIF_EDITOR;
}
/**
* @see org.eclipse.ui.texteditor.AbstractTextEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
*/
public void init( IEditorSite site, IEditorInput input ) throws PartInitException
{
String className = input.getClass().getName();
File file = null;
if ( input instanceof IPathEditorInput )
{
IPathEditorInput pei = ( IPathEditorInput ) input;
IPath path = pei.getPath();
file = path.toFile();
}
else if ( className.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput" ) //$NON-NLS-1$
|| className.equals( "org.eclipse.ui.ide.FileStoreEditorInput" ) ) //$NON-NLS-1$
// The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
// is used when opening a file from the menu File > Open... in Eclipse 3.2.x
// The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
// opening a file from the menu File > Open... in Eclipse 3.3.x
{
file = new File( input.getToolTipText() );
}
if ( file != null )
{
long fileLength = file.length();
if ( fileLength > ( 1 * 1024 * 1024 ) )
{
MessageDialog.openError( site.getShell(), Messages.getString( "LdifEditor.LDIFFileIsTooBig" ), //$NON-NLS-1$
Messages.getString( "LdifEditor.LDIFFileIsTooBigDescription" ) ); //$NON-NLS-1$
input = new NonExistingLdifEditorInput();
}
}
super.init( site, input );
ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() );
getSite().getPage().addPartListener( this );
this.valueEditorManager = new ValueEditorManager( getSite().getShell(), false, false );
}
/**
* @see org.eclipse.ui.editors.text.TextEditor#dispose()
*/
public void dispose()
{
valueEditorManager.dispose();
deactivateGlobalActionHandlers();
ConnectionEventRegistry.removeConnectionUpdateListener( this );
getSite().getPage().removePartListener( this );
super.dispose();
}
/**
* @see org.eclipse.ui.editors.text.TextEditor#getAdapter(java.lang.Class)
*/
public Object getAdapter( Class required )
{
if ( IShowInTargetList.class.equals( required ) )
{
return new IShowInTargetList()
{
public String[] getShowInTargetIds()
{
return new String[]
{ IPageLayout.ID_RES_NAV };
}
};
}
if ( IContentOutlinePage.class.equals( required ) )
{
if ( outlinePage == null || outlinePage.getControl() == null || outlinePage.getControl().isDisposed() )
{
outlinePage = new LdifOutlinePage( this );
}
return outlinePage;
}
if ( ISourceViewer.class.equals( required ) )
{
return getSourceViewer();
}
if ( IAnnotationHover.class.equals( required ) )
{
if ( getSourceViewerConfiguration() != null && getSourceViewer() != null )
return getSourceViewerConfiguration().getAnnotationHover( getSourceViewer() );
}
if ( ITextHover.class.equals( required ) )
{
if ( getSourceViewerConfiguration() != null && getSourceViewer() != null )
return getSourceViewerConfiguration().getTextHover( getSourceViewer(), null );
}
if ( IContentAssistProcessor.class.equals( required ) )
{
if ( getSourceViewerConfiguration() != null && getSourceViewer() != null )
return getSourceViewerConfiguration().getContentAssistant( getSourceViewer() )
.getContentAssistProcessor( LdifPartitionScanner.LDIF_RECORD );
}
if ( projectionSupport != null )
{
Object adapter = projectionSupport.getAdapter( getSourceViewer(), required );
if ( adapter != null )
return adapter;
}
return super.getAdapter( required );
}
/**
* @see org.eclipse.ui.editors.text.TextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
protected void editorContextMenuAboutToShow( IMenuManager menu )
{
super.editorContextMenuAboutToShow( menu );
IContributionItem[] items = menu.getItems();
for ( int i = 0; i < items.length; i++ )
{
if ( items[i] instanceof ActionContributionItem )
{
ActionContributionItem aci = ( ActionContributionItem ) items[i];
if ( aci.getAction() == getAction( ITextEditorActionConstants.SHIFT_LEFT ) )
{
menu.remove( items[i] );
}
if ( aci.getAction() == getAction( ITextEditorActionConstants.SHIFT_RIGHT ) )
{
menu.remove( items[i] );
}
}
}
// add Edit actions
addAction( menu, ITextEditorActionConstants.GROUP_EDIT,
LdifEditorConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION );
addAction( menu, ITextEditorActionConstants.GROUP_EDIT, BrowserCommonConstants.ACTION_ID_EDIT_VALUE );
MenuManager valueEditorMenuManager = new MenuManager( Messages.getString( "LdifEditor.EditValueWith" ) ); //$NON-NLS-1$
if ( this.openBestValueEditorAction.isEnabled() )
{
valueEditorMenuManager.add( this.openBestValueEditorAction );
valueEditorMenuManager.add( new Separator() );
}
for ( int i = 0; i < this.openValueEditorActions.length; i++ )
{
this.openValueEditorActions[i].update();
if ( this.openValueEditorActions[i].isEnabled()
&& this.openValueEditorActions[i].getValueEditor().getClass() != this.openBestValueEditorAction
.getValueEditor().getClass()
&& this.openValueEditorActions[i].getValueEditor() instanceof AbstractDialogValueEditor )
{
valueEditorMenuManager.add( this.openValueEditorActions[i] );
}
}
valueEditorMenuManager.add( new Separator() );
valueEditorMenuManager.add( this.valueEditorPreferencesAction );
menu.appendToGroup( ITextEditorActionConstants.GROUP_EDIT, valueEditorMenuManager );
addAction( menu, ITextEditorActionConstants.GROUP_EDIT, LdifEditorConstants.ACTION_ID_EDIT_RECORD );
// add Format actions
MenuManager formatMenuManager = new MenuManager( Messages.getString( "LdifEditor.Format" ) ); //$NON-NLS-1$
addAction( formatMenuManager, LdifEditorConstants.ACTION_ID_FORMAT_LDIF_DOCUMENT );
addAction( formatMenuManager, LdifEditorConstants.ACTION_ID_FORMAT_LDIF_RECORD );
menu.appendToGroup( ITextEditorActionConstants.GROUP_EDIT, formatMenuManager );
}
/**
* @see org.eclipse.ui.editors.text.TextEditor#createActions()
*/
protected void createActions()
{
super.createActions();
// add content assistant
ResourceBundle bundle = LdifEditorActivator.getDefault().getResourceBundle();
IAction action = new ContentAssistAction( bundle, "ldifeditor__contentassistproposal_", this ); //$NON-NLS-1$
action.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS );
setAction( "ContentAssistProposal", action ); //$NON-NLS-1$
// add execute action (for tool bar)
if ( actionToolBarManager != null )
{
ExecuteLdifAction executeLdifAction = new ExecuteLdifAction( this );
actionToolBarManager.add( executeLdifAction );
setAction( LdifEditorConstants.ACTION_ID_EXECUTE_LDIF, executeLdifAction );
actionToolBarManager.update( true );
}
// add context menu edit actions
EditLdifAttributeAction editLdifAttributeAction = new EditLdifAttributeAction( this );
setAction( BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION, editLdifAttributeAction );
openBestValueEditorAction = new OpenBestValueEditorAction( this );
IValueEditor[] valueEditors = valueEditorManager.getAllValueEditors();
openValueEditorActions = new OpenValueEditorAction[valueEditors.length];
for ( int i = 0; i < this.openValueEditorActions.length; i++ )
{
openValueEditorActions[i] = new OpenValueEditorAction( this, valueEditors[i] );
}
valueEditorPreferencesAction = new ValueEditorPreferencesAction();
OpenDefaultValueEditorAction openDefaultValueEditorAction = new OpenDefaultValueEditorAction( this,
openBestValueEditorAction );
setAction( BrowserCommonConstants.ACTION_ID_EDIT_VALUE, openDefaultValueEditorAction );
EditLdifRecordAction editRecordAction = new EditLdifRecordAction( this );
setAction( LdifEditorConstants.ACTION_ID_EDIT_RECORD, editRecordAction );
// add context menu format actions
FormatLdifDocumentAction formatDocumentAction = new FormatLdifDocumentAction( this );
setAction( LdifEditorConstants.ACTION_ID_FORMAT_LDIF_DOCUMENT, formatDocumentAction );
FormatLdifRecordAction formatRecordAction = new FormatLdifRecordAction( this );
setAction( LdifEditorConstants.ACTION_ID_FORMAT_LDIF_RECORD, formatRecordAction );
// update cut, copy, paste
IAction cutAction = getAction( ITextEditorActionConstants.CUT );
if ( cutAction != null )
{
cutAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_CUT ) );
}
IAction copyAction = getAction( ITextEditorActionConstants.COPY );
if ( copyAction != null )
{
copyAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_COPY ) );
}
IAction pasteAction = getAction( ITextEditorActionConstants.PASTE );
if ( pasteAction != null )
{
pasteAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_PASTE ) );
}
activateGlobalActionHandlers();
}
/**
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
*/
public void createPartControl( Composite parent )
{
setHelpContextId( LdifEditorConstants.PLUGIN_ID + "." + "tools_ldif_editor" ); //$NON-NLS-1$ //$NON-NLS-2$
if ( showToolBar )
{
// create the toolbar (including connection widget and execute button) on top of the editor
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 0;
composite.setLayout( layout );
control = new ViewForm( composite, SWT.NONE );
control.setLayoutData( new GridData( GridData.FILL_BOTH ) );
Composite browserConnectionWidgetControl = BaseWidgetUtils.createColumnContainer( control, 2, 1 );
browserConnectionWidget = new BrowserConnectionWidget();
browserConnectionWidget.createWidget( browserConnectionWidgetControl );
connectionUpdated( null );
browserConnectionWidget.addWidgetModifyListener( new WidgetModifyListener()
{
public void widgetModified( WidgetModifyEvent event )
{
IBrowserConnection browserConnection = browserConnectionWidget.getBrowserConnection();
setConnection( browserConnection );
}
} );
control.setTopLeft( browserConnectionWidgetControl );
// tool bar
actionToolBar = new ToolBar( control, SWT.FLAT | SWT.RIGHT );
actionToolBar.setLayoutData( new GridData( SWT.END, SWT.NONE, true, false ) );
actionToolBarManager = new ToolBarManager( actionToolBar );
control.setTopCenter( actionToolBar );
// local menu
control.setTopRight( null );
// content
Composite editorComposite = new Composite( control, SWT.NONE );
editorComposite.setLayout( new FillLayout() );
GridData data = new GridData( GridData.FILL_BOTH );
data.widthHint = 450;
data.heightHint = 250;
editorComposite.setLayoutData( data );
super.createPartControl( editorComposite );
control.setContent( editorComposite );
}
else
{
super.createPartControl( parent );
}
ProjectionViewer projectionViewer = ( ProjectionViewer ) getSourceViewer();
projectionSupport = new ProjectionSupport( projectionViewer, getAnnotationAccess(), getSharedColors() );
projectionSupport.install();
projectionViewer.doOperation( ProjectionViewer.TOGGLE );
}
/**
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
*/
protected ISourceViewer createSourceViewer( Composite parent, IVerticalRuler ruler, int styles )
{
getAnnotationAccess();
getOverviewRuler();
ISourceViewer viewer = new ProjectionViewer( parent, ruler, getOverviewRuler(), true, styles );
getSourceViewerDecorationSupport( viewer );
return viewer;
}
/**
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#configureSourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport)
*/
protected void configureSourceViewerDecorationSupport( SourceViewerDecorationSupport support )
{
super.configureSourceViewerDecorationSupport( support );
}
/**
* @see org.apache.directory.studio.ldifeditor.editor.ILdifEditor#getLdifModel()
*/
public LdifFile getLdifModel()
{
IDocumentProvider provider = getDocumentProvider();
if ( provider instanceof LdifDocumentProvider )
{
return ( ( LdifDocumentProvider ) provider ).getLdifModel();
}
else
{
return null;
}
}
/**
* This method is used to notify the LDIF Editor that the Outline Page has been closed.
*/
public void outlinePageClosed()
{
projectionSupport.dispose();
outlinePage = null;
}
/**
* @see org.apache.directory.studio.ldifeditor.editor.ILdifEditor#getConnection()
*/
public IBrowserConnection getConnection()
{
return browserConnection;
}
/**
* Sets the Connection
*
* @param browserConnection
* the browser connection to set
*/
protected void setConnection( IBrowserConnection browserConnection )
{
setConnection( browserConnection, false );
}
/**
* Sets the Connection
*
* @param browserConnection the browser connection to set
* @param updateBrowserConnectionWidget the flag indicating if the browser connection widget
* should be updated
*/
protected void setConnection( IBrowserConnection browserConnection, boolean updateBrowserConnectionWidget )
{
this.browserConnection = browserConnection;
if ( updateBrowserConnectionWidget && ( browserConnectionWidget != null ) )
{
browserConnectionWidget.setBrowserConnection( browserConnection );
}
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection)
*/
public final void connectionUpdated( Connection connection )
{
if ( browserConnectionWidget != null )
{
IBrowserConnection browserConnection = browserConnectionWidget.getBrowserConnection();
if ( browserConnection != null && browserConnection.getConnection().equals( connection ) )
{
setConnection( browserConnection );
browserConnectionWidget.setBrowserConnection( browserConnection );
}
}
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionAdded( Connection connection )
{
connectionUpdated( connection );
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionRemoved( Connection connection )
{
connectionUpdated( connection );
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionOpened( Connection connection )
{
connectionUpdated( connection );
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection)
*/
public void connectionClosed( Connection connection )
{
connectionUpdated( connection );
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
*/
public void connectionFolderModified( ConnectionFolder connectionFolder )
{
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderAdded(org.apache.directory.studio.connection.core.ConnectionFolder)
*/
public void connectionFolderAdded( ConnectionFolder connectionFolder )
{
}
/**
* @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderRemoved(org.apache.directory.studio.connection.core.ConnectionFolder)
*/
public void connectionFolderRemoved( ConnectionFolder connectionFolder )
{
}
/**
* This implementation checks if the input is of type
* NonExistingLdifEditorInput. In that case doSaveAs() is
* called to prompt for a new file name and location.
*
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSave(org.eclipse.core.runtime.IProgressMonitor)
*/
public void doSave( IProgressMonitor progressMonitor )
{
final IEditorInput input = getEditorInput();
if ( input instanceof NonExistingLdifEditorInput )
{
super.doSaveAs();
return;
}
super.doSave( progressMonitor );
}
/**
* The input could be one of the following types:
* - NonExistingLdifEditorInput: New file, not yet saved
* - PathEditorInput: file opened with our internal "Open File.." action
* - FileEditorInput: file is within workspace
* - JavaFileEditorInput: file opend with "Open File..." action from org.eclipse.ui.editor
*
* In RCP the FileDialog appears.
* In IDE the super implementation is called.
* To detect if this plugin runs in IDE the org.eclipse.ui.ide extension point is checked.
*
* @see org.eclipse.ui.editors.text.TextEditor#performSaveAs(org.eclipse.core.runtime.IProgressMonitor)
*/
protected void performSaveAs( IProgressMonitor progressMonitor )
{
// detect IDE or RCP:
// check if perspective org.eclipse.ui.resourcePerspective is available
boolean isIDE = CommonUIUtils.isIDEEnvironment();
if ( isIDE )
{
// Just call super implementation for now
IPreferenceStore store = EditorsUI.getPreferenceStore();
String key = getEditorSite().getId() + ".internal.delegateSaveAs"; // $NON-NLS-1$ //$NON-NLS-1$
store.setValue( key, true );
super.performSaveAs( progressMonitor );
}
else
{
// Open FileDialog
Shell shell = getSite().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
final IEditorInput newInput;
FileDialog dialog = new FileDialog( shell, SWT.SAVE );
String path = dialog.open();
if ( path == null )
{
if ( progressMonitor != null )
{
progressMonitor.setCanceled( true );
}
return;
}
// Check whether file exists and if so, confirm overwrite
final File externalFile = new File( path );
if ( externalFile.exists() )
{
MessageDialog overwriteDialog = new MessageDialog(
shell,
Messages.getString( "LdifEditor.Overwrite" ), null, Messages.getString( "LdifEditor.OverwriteQuestion" ), //$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.WARNING, new String[]
{ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1 ); // 'No' is the default
if ( overwriteDialog.open() != Window.OK )
{
if ( progressMonitor != null )
{
progressMonitor.setCanceled( true );
return;
}
}
}
IPath iPath = new Path( path );
newInput = new PathEditorInput( iPath );
boolean success = false;
try
{
provider.aboutToChange( newInput );
provider.saveDocument( progressMonitor, newInput, provider.getDocument( input ), true );
success = true;
}
catch ( CoreException x )
{
final IStatus status = x.getStatus();
if ( status == null || status.getSeverity() != IStatus.CANCEL )
{
String title = Messages.getString( "LdifEditor.ErrorInSaveAs" ); //$NON-NLS-1$
String msg = Messages.getString( "LdifEditor.ErrorInSaveAs" ) + x.getMessage(); //$NON-NLS-1$
MessageDialog.openError( shell, title, msg );
}
}
finally
{
provider.changed( newInput );
if ( success )
{
setInput( newInput );
}
}
if ( progressMonitor != null )
{
progressMonitor.setCanceled( !success );
}
}
}
private IContextActivation contextActivation;
/**
* @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
*/
public void partDeactivated( IWorkbenchPartReference partRef )
{
if ( partRef.getPart( false ) == this && contextActivation != null )
{
deactivateGlobalActionHandlers();
IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | true |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifOutlinePage.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifOutlinePage.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.ldifeditor.editor;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserLabelProvider;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeDeleteRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifDnLine;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
/**
* This class implements the Outline Page for LDIF.
* It used to display LDIF files and records.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifOutlinePage extends ContentOutlinePage
{
/** The editor it is attached to */
private LdifEditor ldifEditor;
/** Whether or not the outline page is linked to an entry in the LDAP Browser view*/
private boolean isLinkedToLdapBrowser = false;
/**
* Creates a new instance of LdifOutlinePage.
*
* @param ldifEditor
* the editor the Outline page is attached to
*/
public LdifOutlinePage( LdifEditor ldifEditor )
{
this.ldifEditor = ldifEditor;
}
/**
* Creates a new instance of LdifOutlinePage.
*
* @param ldifEditor
* the editor the Outline page is attached to
*/
public LdifOutlinePage( LdifEditor ldifEditor, boolean isLinkedToLdapBrowser )
{
this.ldifEditor = ldifEditor;
this.isLinkedToLdapBrowser = isLinkedToLdapBrowser;
}
/**
* {@inheritDoc}
*/
public void createControl( Composite parent )
{
super.createControl( parent );
final TreeViewer treeViewer = getTreeViewer();
treeViewer.setLabelProvider( new LdifLabelProvider( ldifEditor, isLinkedToLdapBrowser ) );
treeViewer.setContentProvider( new LdifContentProvider() );
if ( isLinkedToLdapBrowser )
{
treeViewer.setAutoExpandLevel( 2 );
}
treeViewer.addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
if ( !event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection )
{
Object element = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
if ( element instanceof LdifRecord )
{
LdifRecord ldifRecord = ( LdifRecord ) element;
ldifEditor.selectAndReveal( ldifRecord.getDnLine().getOffset(), ldifRecord.getDnLine()
.getLength() );
}
else if ( element instanceof List )
{
List<?> list = ( List<?> ) element;
if ( !list.isEmpty() && list.get( 0 ) instanceof LdifAttrValLine )
{
LdifAttrValLine line = ( LdifAttrValLine ) list.get( 0 );
ldifEditor.selectAndReveal( line.getOffset(), line.getRawAttributeDescription().length() );
}
}
else if ( element instanceof LdifAttrValLine )
{
LdifAttrValLine line = ( LdifAttrValLine ) element;
ldifEditor.selectAndReveal( line.getOffset() + line.getRawAttributeDescription().length()
+ line.getRawValueType().length(), line.getRawValue().length() );
}
else if ( element instanceof LdifModSpec )
{
LdifModSpec modSpec = ( LdifModSpec ) element;
ldifEditor.selectAndReveal( modSpec.getOffset(), modSpec.getModSpecType().getLength() );
}
}
}
} );
treeViewer.addDoubleClickListener( new IDoubleClickListener()
{
public void doubleClick( DoubleClickEvent event )
{
if ( event.getSelection() instanceof IStructuredSelection )
{
Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
if ( treeViewer.getExpandedState( obj ) )
treeViewer.collapseToLevel( obj, 1 );
else if ( ( ( ITreeContentProvider ) treeViewer.getContentProvider() ).hasChildren( obj ) )
treeViewer.expandToLevel( obj, 1 );
}
}
} );
this.refresh();
}
/**
* Refreshes this viewer starting with the given element.
*
* @param element
* the element
*/
public void refresh( Object element )
{
final TreeViewer treeViewer = getTreeViewer();
if ( treeViewer != null && treeViewer.getTree() != null && !treeViewer.getTree().isDisposed() )
{
treeViewer.refresh( element );
}
}
/**
* Refreshes this viewer completely with information freshly obtained from this viewer's model.
*/
public void refresh()
{
final TreeViewer treeViewer = getTreeViewer();
if ( treeViewer != null && treeViewer.getTree() != null && !treeViewer.getTree().isDisposed() )
{
// ISelection selection = treeViewer.getSelection();
// Object[] expandedElements = treeViewer.getExpandedElements();
if ( !treeViewer.getTree().isEnabled() )
{
treeViewer.getTree().setEnabled( true );
}
if ( ldifEditor != null )
{
if ( treeViewer.getInput() != ldifEditor.getLdifModel() )
{
treeViewer.setInput( ldifEditor.getLdifModel() );
}
}
treeViewer.refresh();
if ( isLinkedToLdapBrowser )
{
treeViewer.setAutoExpandLevel( 2 );
}
// treeViewer.setSelection(selection);
// treeViewer.setExpandedElements(expandedElements);
}
}
/**
* {@inheritDoc}
*/
public void dispose()
{
super.dispose();
if ( ldifEditor != null )
{
ldifEditor.outlinePageClosed();
ldifEditor = null;
}
}
/**
* This class implements the ContentProvider used for the LDIF Outline View
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
private static class LdifContentProvider implements ITreeContentProvider
{
/**
* {@inheritDoc}
*/
public Object[] getChildren( Object element )
{
// file --> records
if ( element instanceof LdifFile )
{
LdifFile ldifFile = ( LdifFile ) element;
return ldifFile.getRecords();
}
// record --> Array of List of AttrValLine
else if ( element instanceof LdifContentRecord )
{
LdifContentRecord record = ( LdifContentRecord ) element;
return getUniqueAttrValLineArray( record.getAttrVals() );
}
else if ( element instanceof LdifChangeAddRecord )
{
LdifChangeAddRecord record = ( LdifChangeAddRecord ) element;
return getUniqueAttrValLineArray( record.getAttrVals() );
}
else if ( element instanceof LdifChangeModifyRecord )
{
LdifChangeModifyRecord record = ( LdifChangeModifyRecord ) element;
return record.getModSpecs();
}
else if ( element instanceof LdifChangeModDnRecord )
{
return new Object[0];
}
else if ( element instanceof LdifChangeDeleteRecord )
{
return new Object[0];
}
// List of AttrValLine --> Array of AttrValLine
else if ( element instanceof List && ( ( List<?> ) element ).get( 0 ) instanceof LdifAttrValLine )
{
List<?> list = ( List<?> ) element;
return list.toArray();
}
else if ( element instanceof LdifModSpec )
{
LdifModSpec modSpec = ( LdifModSpec ) element;
return modSpec.getAttrVals();
}
else
{
return new Object[0];
}
}
/**
* Returns a unique line of attribute values from an array of attribute value lines
*
* @param lines the attribute value lines
* @return a unique line of attribute values from an array of attribute values lines
*/
private Object[] getUniqueAttrValLineArray( LdifAttrValLine[] lines )
{
Map<String, List<LdifAttrValLine>> uniqueAttrMap = new LinkedHashMap<String, List<LdifAttrValLine>>();
for ( LdifAttrValLine ldifAttrValLine : lines )
{
String key = ldifAttrValLine.getUnfoldedAttributeDescription();
List<LdifAttrValLine> listLdifAttrValLine = uniqueAttrMap.get( key );
if ( listLdifAttrValLine == null )
{
listLdifAttrValLine = new ArrayList<LdifAttrValLine>();
uniqueAttrMap.put( key, listLdifAttrValLine );
}
listLdifAttrValLine.add( ldifAttrValLine );
}
return uniqueAttrMap.values().toArray();
}
/**
* {@inheritDoc}
*/
public Object getParent( Object element )
{
return null;
}
/**
* {@inheritDoc}
*/
public boolean hasChildren( Object element )
{
return getChildren( element ) != null && getChildren( element ).length > 0;
}
/**
* {@inheritDoc}
*/
public Object[] getElements( Object inputElement )
{
return getChildren( inputElement );
}
/**
* {@inheritDoc}
*/
public void dispose()
{
}
/**
* {@inheritDoc}
*/
public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
{
}
}
/**
* This class implements the LabelProvider used for the LDIF Outline View
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
private static class LdifLabelProvider extends LabelProvider
{
/** The editor it is attached to */
private LdifEditor ldifEditor;
/** Whether or not the outline page is linked to an entry in the LDAP Browser view*/
private boolean isLinkedToLdapBrowser = false;
public LdifLabelProvider( LdifEditor ldifEditor, boolean isLinkedToLdapBrowser )
{
super();
this.ldifEditor = ldifEditor;
this.isLinkedToLdapBrowser = isLinkedToLdapBrowser;
}
/**
* {@inheritDoc}
*/
public String getText( Object element )
{
// Record
if ( element instanceof LdifRecord )
{
LdifRecord ldifRecord = ( LdifRecord ) element;
return ldifRecord.getDnLine().getValueAsString();
}
// List of AttrValLine
else if ( element instanceof List && ( ( List<?> ) element ).get( 0 ) instanceof LdifAttrValLine )
{
List<?> list = ( List<?> ) element;
return ( ( LdifAttrValLine ) list.get( 0 ) ).getUnfoldedAttributeDescription() + " (" + list.size() //$NON-NLS-1$
+ ")"; //$NON-NLS-1$
}
else if ( element instanceof LdifModSpec )
{
LdifModSpec modSpec = ( LdifModSpec ) element;
return modSpec.getModSpecType().getUnfoldedAttributeDescription() + " (" + modSpec.getAttrVals().length //$NON-NLS-1$
+ ")"; //$NON-NLS-1$
}
// AttrValLine
else if ( element instanceof LdifAttrValLine )
{
LdifAttrValLine line = ( LdifAttrValLine ) element;
return Utils.getShortenedString( line.getValueAsString(), 20 );
}
else
{
return ""; //$NON-NLS-1$
}
}
/**
* {@inheritDoc}
*/
public Image getImage( Object element )
{
// Record
if ( element instanceof LdifContentRecord )
{
if ( isLinkedToLdapBrowser )
{
LdifContentRecord record = ( LdifContentRecord ) element;
LdifDnLine dnLine = record.getDnLine();
if ( dnLine != null )
{
String dn = dnLine.getUnfoldedDn();
if ( ( dn != null ) && ( dn.length() == 0 ) ) //$NON-NLS-1$
{
// Root DSE
return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_ROOT );
}
else
{
// Any other case
try
{
return BrowserLabelProvider.getImageByObjectClass( ldifEditor.getConnection()
.getEntryFromCache( new Dn( dn ) ) );
}
catch ( LdapInvalidDnException e )
{
// Will never occur
}
}
}
}
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_ENTRY );
}
else if ( element instanceof LdifChangeAddRecord )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD );
}
else if ( element instanceof LdifChangeModifyRecord )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MODIFY );
}
else if ( element instanceof LdifChangeDeleteRecord )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_DELETE );
}
else if ( element instanceof LdifChangeModDnRecord )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_RENAME );
}
// List of AttrValLine
else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ATTRIBUTE );
}
else if ( element instanceof LdifModSpec )
{
LdifModSpec modSpec = ( LdifModSpec ) element;
if ( modSpec.isAdd() )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_ADD );
}
else if ( modSpec.isReplace() )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_REPLACE );
}
else if ( modSpec.isDelete() )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_DELETE );
}
else
{
return null;
}
}
// AttrValLine
else if ( element instanceof LdifAttrValLine )
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_VALUE );
}
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/EditLdifRecordAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/EditLdifRecordAction.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.ldifeditor.editor.actions;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.dialogs.LdifEntryEditorDialog;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
import org.eclipse.jface.text.IDocument;
public class EditLdifRecordAction extends AbstractLdifAction
{
public EditLdifRecordAction( LdifEditor editor )
{
super( Messages.getString( "EditLdifRecordAction.EditRecord" ), editor ); //$NON-NLS-1$
super.setActionDefinitionId( LdifEditorConstants.ACTION_ID_EDIT_RECORD );
}
protected void doRun()
{
LdifContainer[] containers = getSelectedLdifContainers();
if ( containers.length == 1
&& ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord ) )
{
LdifContainer container = containers[0];
LdifEntryEditorDialog dialog = null;
if ( container instanceof LdifContentRecord )
{
dialog = new LdifEntryEditorDialog( editor.getEditorSite().getShell(), editor.getConnection(),
( LdifContentRecord ) container );
}
else
{
dialog = new LdifEntryEditorDialog( editor.getEditorSite().getShell(), editor.getConnection(),
( LdifChangeAddRecord ) container );
}
editor.deactivateGlobalActionHandlers();
if ( dialog.open() == LdifEntryEditorDialog.OK )
{
LdifRecord record = dialog.getLdifRecord();
IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
String old = document.get();
StringBuffer sb = new StringBuffer();
sb.append( old.substring( 0, container.getOffset() ) );
sb.append( record.toFormattedString( Utils.getLdifFormatParameters() ) );
sb.append( old.substring( container.getOffset() + container.getLength(), old.length() ) );
document.set( sb.toString() );
}
editor.activateGlobalActionHandlers();
}
}
public void update()
{
LdifContainer[] containers = getSelectedLdifContainers();
super.setEnabled( containers.length == 1
&& ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord ) );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/EditLdifAttributeAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/EditLdifAttributeAction.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.ldifeditor.editor.actions;
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.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.wizards.AttributeWizard;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyConnection;
import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
import org.apache.directory.studio.ldapbrowser.core.utils.ModelConverter;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecSepLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecTypeLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifValueLineBase;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
public class EditLdifAttributeAction extends AbstractLdifAction
{
public EditLdifAttributeAction( LdifEditor editor )
{
super( Messages.getString( "EditLdifAttributeAction.EditAttributeDescription" ), editor ); //$NON-NLS-1$
super.setActionDefinitionId( BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION );
}
public void update()
{
LdifContainer[] containers = getSelectedLdifContainers();
LdifModSpec modSpec = getSelectedLdifModSpec();
LdifPart[] parts = getSelectedLdifParts();
super
.setEnabled( parts.length == 1
&& ( parts[0] instanceof LdifAttrValLine || modSpec != null )
&& containers.length == 1
&& ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord || containers[0] instanceof LdifChangeModifyRecord ) );
}
protected void doRun()
{
LdifContainer[] containers = getSelectedLdifContainers();
LdifModSpec modSpec = getSelectedLdifModSpec();
LdifPart[] parts = getSelectedLdifParts();
if ( parts.length == 1
&& ( parts[0] instanceof LdifAttrValLine || parts[0] instanceof LdifModSpecTypeLine )
&& containers.length == 1
&& ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord || containers[0] instanceof LdifChangeModifyRecord ) )
{
try
{
LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
String attributeDescription = null;
String oldValue = null;
if ( modSpec != null && line instanceof LdifModSpecTypeLine )
{
LdifModSpecTypeLine oldLine = ( LdifModSpecTypeLine ) line;
attributeDescription = oldLine.getUnfoldedAttributeDescription();
oldValue = null;
}
else
{
LdifAttrValLine oldLine = ( LdifAttrValLine ) line;
attributeDescription = oldLine.getUnfoldedAttributeDescription();
oldValue = oldLine.getValueAsString();
}
Schema schema = editor.getConnection() != null ? editor.getConnection().getSchema()
: Schema.DEFAULT_SCHEMA;
IBrowserConnection dummyConnection = new DummyConnection( schema );
IEntry dummyEntry = null;
if ( containers[0] instanceof LdifContentRecord )
{
dummyEntry = ModelConverter.ldifContentRecordToEntry( ( LdifContentRecord ) containers[0],
dummyConnection );
}
else if ( containers[0] instanceof LdifChangeAddRecord )
{
dummyEntry = ModelConverter.ldifChangeAddRecordToEntry( ( LdifChangeAddRecord ) containers[0],
dummyConnection );
}
else if ( containers[0] instanceof LdifChangeModifyRecord )
{
dummyEntry = new DummyEntry( new Dn(), dummyConnection );
}
AttributeWizard wizard = new AttributeWizard( Messages
.getString( "EditLdifAttributeAction.EditAttributeDescription" ), true, false, //$NON-NLS-1$
attributeDescription, dummyEntry );
WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
dialog.setBlockOnOpen( true );
dialog.create();
if ( dialog.open() == Dialog.OK )
{
String newAttributeDescription = wizard.getAttributeDescription();
if ( newAttributeDescription != null )
{
IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
if ( modSpec != null )
{
LdifModSpecTypeLine oldTypeLine = modSpec.getModSpecType();
LdifModSpecTypeLine newTypeLine = null;
if ( oldTypeLine.isAdd() )
{
newTypeLine = LdifModSpecTypeLine.createAdd( newAttributeDescription );
}
else if ( oldTypeLine.isDelete() )
{
newTypeLine = LdifModSpecTypeLine.createDelete( newAttributeDescription );
}
else if ( oldTypeLine.isReplace() )
{
newTypeLine = LdifModSpecTypeLine.createReplace( newAttributeDescription );
}
LdifAttrValLine[] oldAttrValLines = modSpec.getAttrVals();
LdifAttrValLine[] newAttrValLines = new LdifAttrValLine[oldAttrValLines.length];
for ( int i = 0; i < oldAttrValLines.length; i++ )
{
LdifAttrValLine oldAttrValLine = oldAttrValLines[i];
newAttrValLines[i] = LdifAttrValLine.create( newAttributeDescription, oldAttrValLine
.getValueAsString() );
}
LdifModSpecSepLine newSepLine = LdifModSpecSepLine.create();
String text = newTypeLine.toFormattedString( Utils.getLdifFormatParameters() );
for ( int j = 0; j < newAttrValLines.length; j++ )
{
text += newAttrValLines[j].toFormattedString( Utils.getLdifFormatParameters() );
}
text += newSepLine.toFormattedString( Utils.getLdifFormatParameters() );
try
{
document.replace( modSpec.getOffset(), modSpec.getLength(), text );
}
catch ( BadLocationException e )
{
e.printStackTrace();
}
}
else
{ // LdifContentRecord ||
// LdifChangeAddRecord
LdifAttrValLine newLine = LdifAttrValLine.create( newAttributeDescription, oldValue );
try
{
document.replace( line.getOffset(), line.getLength(), newLine.toFormattedString( Utils
.getLdifFormatParameters() ) );
}
catch ( BadLocationException e )
{
e.printStackTrace();
}
}
}
// ...
}
}
catch ( LdapInvalidDnException e )
{
}
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/OpenBestValueEditorAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/OpenBestValueEditorAction.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.ldifeditor.editor.actions;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.valueeditors.AbstractDialogValueEditor;
import org.apache.directory.studio.valueeditors.IValueEditor;
public class OpenBestValueEditorAction extends AbstractOpenValueEditorAction
{
public OpenBestValueEditorAction( LdifEditor editor )
{
super( editor );
}
public void update()
{
super.setEnabled( isEditableLineSelected() );
// determine value editor
IBrowserConnection connection = getConnection();
String attributeDescription = getAttributeDescription();
if ( attributeDescription != null )
{
valueEditor = valueEditorManager.getCurrentValueEditor( connection.getSchema(), attributeDescription );
Object rawValue = getValueEditorRawValue();
if ( !( valueEditor instanceof AbstractDialogValueEditor ) || rawValue == null )
{
IValueEditor[] vps = valueEditorManager.getAlternativeValueEditors( connection.getSchema(),
attributeDescription );
for ( int i = 0; i < vps.length
&& ( !( valueEditor instanceof AbstractDialogValueEditor ) || rawValue == null ); i++ )
{
valueEditor = vps[i];
rawValue = getValueEditorRawValue();
}
}
}
if ( valueEditor != null )
{
setText( valueEditor.getValueEditorName() );
setImageDescriptor( valueEditor.getValueEditorImageDescriptor() );
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/OpenValueEditorAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/OpenValueEditorAction.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.ldifeditor.editor.actions;
import java.util.Arrays;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.valueeditors.IValueEditor;
public class OpenValueEditorAction extends AbstractOpenValueEditorAction
{
public OpenValueEditorAction( LdifEditor editor, IValueEditor valueEditor )
{
super( editor );
super.valueEditor = valueEditor;
}
public void update()
{
String attributeDescription = getAttributeDescription();
Object rawValue = getValueEditorRawValue();
if ( isEditableLineSelected() )
{
IValueEditor[] alternativeVps = this.editor.getValueEditorManager().getAlternativeValueEditors(
getConnection().getSchema(), attributeDescription );
super.setEnabled( Arrays.asList( alternativeVps ).contains( this.valueEditor ) && rawValue != null );
}
else
{
super.setEnabled( false );
}
setText( valueEditor.getValueEditorName() );
setImageDescriptor( valueEditor.getValueEditorImageDescriptor() );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/FormatLdifRecordAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/FormatLdifRecordAction.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.ldifeditor.editor.actions;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
public class FormatLdifRecordAction extends AbstractLdifAction
{
public FormatLdifRecordAction( LdifEditor editor )
{
super( Messages.getString( "FormatLdifRecordAction.FormatRecord" ), editor ); //$NON-NLS-1$
}
protected void doRun()
{
LdifContainer[] containers = super.getSelectedLdifContainers();
if ( containers.length > 0 )
{
IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
String old = document.get();
StringBuffer sb = new StringBuffer();
sb.append( old.substring( 0, containers[0].getOffset() ) );
for ( int i = 0; i < containers.length; i++ )
{
LdifContainer container = containers[i];
sb.append( container.toFormattedString( Utils.getLdifFormatParameters() ) );
}
sb.append( old.substring( containers[containers.length - 1].getOffset()
+ containers[containers.length - 1].getLength(), old.length() ) );
ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
int topIndex = sourceViewer.getTopIndex();
document.set( sb.toString() );
sourceViewer.setTopIndex( topIndex );
}
}
public void update()
{
LdifContainer[] ldifContainers = super.getSelectedLdifContainers();
for ( int i = 0; i < ldifContainers.length; i++ )
{
LdifContainer container = ldifContainers[i];
if ( !( container instanceof LdifRecord ) )
{
super.setEnabled( false );
return;
}
}
super.setEnabled( 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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/AbstractOpenValueEditorAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/AbstractOpenValueEditorAction.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.ldifeditor.editor.actions;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyConnection;
import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifControlLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifDeloldrdnLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifDnLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifNewrdnLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifNewsuperiorLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifValueLineBase;
import org.apache.directory.studio.valueeditors.AbstractDialogValueEditor;
import org.apache.directory.studio.valueeditors.IValueEditor;
import org.apache.directory.studio.valueeditors.ValueEditorManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
public abstract class AbstractOpenValueEditorAction extends AbstractLdifAction
{
protected ValueEditorManager valueEditorManager;
protected IValueEditor valueEditor;
public AbstractOpenValueEditorAction( LdifEditor editor )
{
super( Messages.getString( "AbstractOpenValueEditorAction.EditValue" ), editor ); //$NON-NLS-1$
valueEditorManager = editor.getValueEditorManager();
}
public Object getValueEditor()
{
return valueEditor;
}
protected void doRun()
{
LdifPart[] parts = getSelectedLdifParts();
if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
{
LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
String attributeDescription = getAttributeDescription();
Object rawValue = getValueEditorRawValue();
if ( valueEditor instanceof AbstractDialogValueEditor )
{
AbstractDialogValueEditor cellEditor = ( AbstractDialogValueEditor ) valueEditor;
cellEditor.setValue( rawValue );
cellEditor.activate();
Object newValue = cellEditor.getValue();
if ( ( newValue instanceof String ) || ( newValue instanceof byte[] ) )
{
IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
LdifValueLineBase newLine;
if ( line instanceof LdifControlLine )
{
LdifControlLine oldControlLine = ( LdifControlLine ) line;
if ( newValue instanceof String )
{
newLine = LdifControlLine.create( oldControlLine.getUnfoldedOid(), oldControlLine
.getUnfoldedCriticality(), ( String ) newValue );
}
else
{
newLine = LdifControlLine.create( oldControlLine.getUnfoldedOid(), oldControlLine
.getUnfoldedCriticality(), ( byte[] ) newValue );
}
}
else
{
if ( newValue instanceof String )
{
newLine = LdifAttrValLine.create( attributeDescription, ( String ) newValue );
}
else
{
newLine = LdifAttrValLine.create( attributeDescription, ( byte[] ) newValue );
}
}
try
{
document.replace( line.getOffset(), line.getLength(), newLine.toFormattedString( Utils
.getLdifFormatParameters() ) );
}
catch ( BadLocationException e )
{
e.printStackTrace();
}
}
}
}
}
protected IBrowserConnection getConnection()
{
return editor.getConnection() != null ? editor.getConnection() : new DummyConnection( Schema.DEFAULT_SCHEMA );
}
protected Object getValueEditorRawValue()
{
IBrowserConnection connection = getConnection();
String dn = getDn();
String description = getAttributeDescription();
Object value = getValue();
Object rawValue = null;
if ( value != null )
{
try
{
// some value editors need the real Dn (e.g. the password editor)
DummyEntry dummyEntry = new DummyEntry( Dn.isValid( dn ) ? new Dn( dn ) : new Dn(),
connection );
Attribute dummyAttribute = new Attribute( dummyEntry, description );
Value dummyValue = new Value( dummyAttribute, value );
rawValue = valueEditor.getRawValue( dummyValue );
}
catch ( LdapInvalidDnException e )
{
// should not occur, as we check with isValid()
}
}
return rawValue;
}
protected String getDn()
{
LdifContainer[] selectedLdifContainers = getSelectedLdifContainers();
String dn = null;
if ( selectedLdifContainers.length == 1 && selectedLdifContainers[0] instanceof LdifRecord )
{
LdifRecord record = ( LdifRecord ) selectedLdifContainers[0];
LdifDnLine dnLine = record.getDnLine();
dn = dnLine.getValueAsString();
}
return dn;
}
protected Object getValue()
{
LdifPart[] parts = getSelectedLdifParts();
Object oldValue = null;
if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
{
LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
oldValue = line.getValueAsObject();
if ( line instanceof LdifControlLine )
{
oldValue = ( ( LdifControlLine ) line ).getUnfoldedControlValue();
}
}
return oldValue;
}
protected String getAttributeDescription()
{
String attributeDescription = null;
LdifPart[] parts = getSelectedLdifParts();
if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
{
LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
if ( line instanceof LdifControlLine )
{
attributeDescription = ""; //$NON-NLS-1$
}
else
{
attributeDescription = line.getUnfoldedLineStart();
}
}
return attributeDescription;
}
protected boolean isEditableLineSelected()
{
LdifPart[] parts = getSelectedLdifParts();
boolean b = parts.length == 1
&& ( parts[0] instanceof LdifAttrValLine || parts[0] instanceof LdifDnLine
|| parts[0] instanceof LdifControlLine || parts[0] instanceof LdifNewrdnLine
|| parts[0] instanceof LdifDeloldrdnLine || parts[0] instanceof LdifNewsuperiorLine );
return 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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/Messages.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/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.ldifeditor.editor.actions;
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/FormatLdifDocumentAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/FormatLdifDocumentAction.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.ldifeditor.editor.actions;
import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
public class FormatLdifDocumentAction extends AbstractLdifAction
{
public FormatLdifDocumentAction( LdifEditor editor )
{
super( Messages.getString( "FormatLdifDocumentAction.FormatDocument" ), editor ); //$NON-NLS-1$
}
protected void doRun()
{
IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
int topIndex = sourceViewer.getTopIndex();
document.set( super.getLdifModel().toFormattedString( Utils.getLdifFormatParameters() ) );
sourceViewer.setTopIndex( topIndex );
}
public void update()
{
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/OpenDefaultValueEditorAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/OpenDefaultValueEditorAction.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.ldifeditor.editor.actions;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
public class OpenDefaultValueEditorAction extends AbstractLdifAction
{
private OpenBestValueEditorAction proxy;
public OpenDefaultValueEditorAction( LdifEditor editor, OpenBestValueEditorAction proxy )
{
super( Messages.getString( "OpenDefaultValueEditorAction.EditValue" ), editor ); //$NON-NLS-1$
super.setActionDefinitionId( BrowserCommonConstants.ACTION_ID_EDIT_VALUE );
this.proxy = proxy;
}
public void update()
{
proxy.update();
setEnabled( proxy.isEnabled() );
setImageDescriptor( proxy.getImageDescriptor() );
}
protected void doRun()
{
proxy.run();
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/AbstractLdifAction.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/actions/AbstractLdifAction.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.ldifeditor.editor.actions;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.texteditor.IUpdate;
public abstract class AbstractLdifAction extends Action implements IUpdate
{
protected LdifEditor editor;
public AbstractLdifAction( String text, LdifEditor editor )
{
super( text );
this.editor = editor;
}
public final void run()
{
if ( this.isEnabled() )
{
doRun();
}
}
protected abstract void doRun();
public boolean isEnabled()
{
update();
return super.isEnabled();
}
protected LdifFile getLdifModel()
{
LdifFile model = editor.getLdifModel();
return model;
}
protected LdifContainer[] getSelectedLdifContainers()
{
LdifContainer[] containers = null;
ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
if ( sourceViewer != null )
{
LdifFile model = editor.getLdifModel();
Point selection = sourceViewer.getSelectedRange();
containers = LdifFile.getContainers( model, selection.x, selection.y );
}
return containers != null ? containers : new LdifContainer[0];
}
protected LdifPart[] getSelectedLdifParts()
{
LdifPart[] parts = null;
ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
if ( sourceViewer != null )
{
LdifFile model = editor.getLdifModel();
Point selection = sourceViewer.getSelectedRange();
parts = LdifFile.getParts( model, selection.x, selection.y );
}
return parts != null ? parts : new LdifPart[0];
}
protected LdifModSpec getSelectedLdifModSpec()
{
LdifModSpec modSpec = null;
LdifContainer[] containers = getSelectedLdifContainers();
if ( containers.length == 1 )
{
ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
if ( sourceViewer != null )
{
Point selection = sourceViewer.getSelectedRange();
modSpec = LdifFile.getInnerContainer( containers[0], selection.x );
}
}
return modSpec;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifTextHover.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifTextHover.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.ldifeditor.editor.text;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.lines.LdifValueLineBase;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
public class LdifTextHover implements ITextHover
{
private ILdifEditor editor;
public LdifTextHover( ILdifEditor editor )
{
this.editor = editor;
}
public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
{
if ( this.editor != null )
{
LdifContainer container = LdifFile.getContainer( this.editor.getLdifModel(), hoverRegion.getOffset() );
if ( container != null )
{
LdifPart part = LdifFile.getContainerContent( container, hoverRegion.getOffset() );
if ( part != null )
{
if ( part instanceof LdifValueLineBase )
{
LdifValueLineBase line = ( LdifValueLineBase ) part;
if ( line.isValueTypeBase64() )
{
return line.getValueAsString();
}
}
}
}
}
return null;
}
public IRegion getHoverRegion( ITextViewer textViewer, int offset )
{
if ( this.editor != null )
{
return new Region( offset, 0 );
}
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAnnotationHover.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.ldifeditor.editor.text;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
public class LdifAnnotationHover implements IAnnotationHover
{
private ILdifEditor editor;
public LdifAnnotationHover( ILdifEditor editor )
{
this.editor = editor;
}
public String getHoverInfo( ISourceViewer sourceViewer, int lineNumber )
{
try
{
if ( this.editor != null )
{
int offset = sourceViewer.getDocument().getLineOffset( lineNumber );
LdifContainer container = LdifFile.getContainer( this.editor.getLdifModel(), offset );
if ( container != null )
{
LdifPart part = LdifFile.getContainerContent( container, offset );
if ( part != null )
{
// return container.getClass().getName() + " - " +
// part.getClass().getName();
return container.getInvalidString() + " - " + part.getInvalidString(); //$NON-NLS-1$
}
}
}
}
catch ( BadLocationException 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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifCompletionProcessor.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.ldifeditor.editor.text;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
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.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifInvalidPart;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifInvalidContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifSepContainer;
import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifChangeTypeLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifSepLine;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.eclipse.swt.graphics.Image;
public class LdifCompletionProcessor extends TemplateCompletionProcessor
{
// private final static String Dn = "dn: ";
private final static String CT_ADD = "changetype: add" + BrowserCoreConstants.LINE_SEPARATOR; //$NON-NLS-1$
private final static String CT_MODIFY = "changetype: modify" + BrowserCoreConstants.LINE_SEPARATOR; //$NON-NLS-1$
private final static String CT_DELETE = "changetype: delete" + BrowserCoreConstants.LINE_SEPARATOR; //$NON-NLS-1$
private final static String CT_MODDN = "changetype: moddn" + BrowserCoreConstants.LINE_SEPARATOR; //$NON-NLS-1$
private final static String MD_NEWRDN = "newrdn: "; //$NON-NLS-1$
private final static String MD_DELETEOLDRDN_TRUE = "deleteoldrdn: 1"; //$NON-NLS-1$
// private final static String MD_DELETEOLDRDN_FALSE = "deleteoldrdn:
// 0";
private final static String MD_NEWSUPERIOR = "newsuperior: "; //$NON-NLS-1$
private final ILdifEditor editor;
private final ContentAssistant contentAssistant;
public LdifCompletionProcessor( ILdifEditor editor, ContentAssistant contentAssistant )
{
this.editor = editor;
this.contentAssistant = contentAssistant;
}
public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
{
IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore();
contentAssistant.enableAutoInsert( store
.getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
contentAssistant.enableAutoActivation( store
.getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
contentAssistant.setAutoActivationDelay( store
.getInt( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
LdifFile model = editor.getLdifModel();
LdifContainer container = LdifFile.getContainer( model, offset );
LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, offset ) : null;
LdifPart part = container != null ? LdifFile.getContainerContent( container, offset ) : null;
int documentLine = -1;
int documentLineOffset = -1;
String prefix = ""; //$NON-NLS-1$
try
{
documentLine = viewer.getDocument().getLineOfOffset( offset );
documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
}
catch ( BadLocationException e )
{
}
// TemplateContextType contextType = getContextType(viewer, new
// Region(offset, 0));
// Add context dependend template proposals
ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset );
if ( templateProposals != null )
{
proposalList.addAll( Arrays.asList( templateProposals ) );
}
// changetype: xxx
if ( container instanceof LdifRecord )
{
LdifRecord record = ( LdifRecord ) container;
LdifPart[] parts = record.getParts();
if ( parts.length > 1 && ( !( parts[1] instanceof LdifChangeTypeLine ) || !parts[1].isValid() ) )
{
if ( CT_ADD.startsWith( prefix ) )
proposalList.add( new CompletionProposal( CT_ADD, offset - prefix.length(), prefix.length(), CT_ADD
.length(), LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD ),
CT_ADD.substring( 0, CT_ADD.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null,
null ) );
if ( CT_MODIFY.startsWith( prefix ) )
proposalList.add( new CompletionProposal( CT_MODIFY, offset - prefix.length(), prefix.length(),
CT_MODIFY.length(), LdifEditorActivator.getDefault().getImage(
LdifEditorConstants.IMG_LDIF_MODIFY ), CT_MODIFY.substring( 0, CT_MODIFY.length()
- BrowserCoreConstants.LINE_SEPARATOR.length() ), null, null ) );
if ( CT_DELETE.startsWith( prefix ) )
proposalList.add( new CompletionProposal( CT_DELETE, offset - prefix.length(), prefix.length(),
CT_DELETE.length(), LdifEditorActivator.getDefault().getImage(
LdifEditorConstants.IMG_LDIF_DELETE ), CT_DELETE.substring( 0, CT_DELETE.length()
- BrowserCoreConstants.LINE_SEPARATOR.length() ), null, null ) );
if ( CT_MODDN.startsWith( prefix ) )
proposalList.add( new CompletionProposal( CT_MODDN, offset - prefix.length(), prefix.length(),
CT_MODDN.length(), LdifEditorActivator.getDefault().getImage(
LdifEditorConstants.IMG_LDIF_RENAME ), CT_MODDN.substring( 0, CT_MODDN.length()
- BrowserCoreConstants.LINE_SEPARATOR.length() ), null, null ) );
}
}
// changetype: modify
if ( container instanceof LdifChangeModDnRecord )
{
LdifChangeModDnRecord record = ( LdifChangeModDnRecord ) container;
if ( ( record.getNewrdnLine() == null || !record.getNewrdnLine().isValid() )
&& MD_NEWRDN.startsWith( prefix ) )
{
proposalList.add( new CompletionProposal( MD_NEWRDN, offset - prefix.length(), prefix.length(),
MD_NEWRDN.length(), null, null, null, null ) );
}
if ( ( record.getDeloldrdnLine() == null || !record.getDeloldrdnLine().isValid() )
&& MD_DELETEOLDRDN_TRUE.startsWith( prefix ) )
{
proposalList.add( new CompletionProposal( MD_DELETEOLDRDN_TRUE, offset - prefix.length(), prefix
.length(), MD_DELETEOLDRDN_TRUE.length(), null, null, null, null ) );
}
if ( ( record.getNewsuperiorLine() == null || !record.getNewsuperiorLine().isValid() )
&& MD_NEWSUPERIOR.startsWith( prefix ) )
{
proposalList.add( new CompletionProposal( MD_NEWSUPERIOR, offset - prefix.length(), prefix.length(),
MD_NEWSUPERIOR.length(), null, null, null, null ) );
}
}
// modspecs
if ( innerContainer instanceof LdifModSpec )
{
LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
String att = modSpec.getModSpecType().getRawAttributeDescription();
if ( att != null && att.startsWith( prefix ) )
{
proposalList.add( new CompletionProposal( att, offset - prefix.length(), prefix.length(), att.length(),
null, null, null, null ) );
}
}
// attribute descriptions
if ( container instanceof LdifContentRecord || container instanceof LdifChangeAddRecord )
{
if ( part instanceof LdifInvalidPart
|| part instanceof LdifAttrValLine
|| ( part instanceof LdifSepLine && ( container instanceof LdifContentRecord || container instanceof LdifChangeAddRecord ) ) )
{
String rawAttributeDescription = prefix;
String rawValueType = ""; //$NON-NLS-1$
if ( part instanceof LdifAttrValLine )
{
LdifAttrValLine line = ( LdifAttrValLine ) part;
rawAttributeDescription = line.getRawAttributeDescription();
rawValueType = line.getRawValueType();
}
if ( offset <= part.getOffset() + rawAttributeDescription.length() )
{
Schema schema = editor.getConnection() != null ? editor.getConnection().getSchema()
: Schema.DEFAULT_SCHEMA;
String[] attributeNames = SchemaUtils.getNamesAsArray( schema.getAttributeTypeDescriptions() );
Arrays.sort( attributeNames );
for ( String attributeName : attributeNames )
{
if ( rawAttributeDescription.length() == 0
|| Strings.toLowerCase( attributeName ).startsWith(
Strings.toLowerCase( rawAttributeDescription ) ) )
{
String proposal = attributeName;
if ( rawValueType.length() == 0 )
{
if ( SchemaUtils.isBinary( schema.getAttributeTypeDescription( proposal ), schema ) )
{
proposal += ":: "; //$NON-NLS-1$
}
else
{
proposal += ": "; //$NON-NLS-1$
}
}
proposalList
.add( new CompletionProposal( proposal, offset - rawAttributeDescription.length(),
rawAttributeDescription.length(), proposal.length() ) );
}
}
}
}
}
// comment
boolean commentOnly = false;
if ( documentLineOffset == offset )
{
commentOnly = proposalList.isEmpty();
proposalList.add( new CompletionProposal( "# ", offset, 0, 2, LdifEditorActivator.getDefault().getImage( //$NON-NLS-1$
LdifEditorConstants.IMG_LDIF_COMMENT ), "# - Comment", null, null ) ); //$NON-NLS-1$
}
// adjust auto-insert
this.contentAssistant.enableAutoInsert( !commentOnly );
ICompletionProposal[] proposals = ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
return proposals;
}
protected String extractPrefix( ITextViewer viewer, int offset )
{
IDocument document = viewer.getDocument();
if ( offset > document.getLength() )
return ""; //$NON-NLS-1$
try
{
int documentLine = viewer.getDocument().getLineOfOffset( offset );
int documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
String prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
return prefix;
}
catch ( BadLocationException e )
{
return ""; //$NON-NLS-1$
}
}
public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset )
{
return null;
}
public char[] getCompletionProposalAutoActivationCharacters()
{
char[] chars = new char[53];
for ( int i = 0; i < 26; i++ )
chars[i] = ( char ) ( 'a' + i );
for ( int i = 0; i < 26; i++ )
chars[i + 26] = ( char ) ( 'A' + i );
chars[52] = ':';
return chars;
}
public char[] getContextInformationAutoActivationCharacters()
{
return null;
}
public String getErrorMessage()
{
return null;
}
public IContextInformationValidator getContextInformationValidator()
{
return null;
}
protected Template[] getTemplates( String contextTypeId )
{
Template[] templates = LdifEditorActivator.getDefault().getLdifTemplateStore().getTemplates( contextTypeId );
return templates;
}
protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
{
int offset = region.getOffset();
LdifFile model = editor.getLdifModel();
LdifContainer container = LdifFile.getContainer( model, offset );
LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, offset ) : null;
LdifPart part = container != null ? LdifFile.getContainerContent( container, offset ) : null;
int documentLine = -1;
int documentLineOffset = -1;
String prefix = ""; //$NON-NLS-1$
try
{
documentLine = viewer.getDocument().getLineOfOffset( offset );
documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
}
catch ( BadLocationException e )
{
}
// FILE
if ( container == null && innerContainer == null && part == null )
{
return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
LdifEditorConstants.LDIF_FILE_TEMPLATE_ID );
}
if ( container instanceof LdifSepContainer && innerContainer == null && part instanceof LdifSepLine )
{
return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
LdifEditorConstants.LDIF_FILE_TEMPLATE_ID );
}
if ( ( container instanceof LdifInvalidContainer && part instanceof LdifInvalidPart && "d".equals( prefix ) ) //$NON-NLS-1$
|| ( container instanceof LdifContentRecord && part instanceof LdifInvalidPart && "dn".equals( prefix ) ) //$NON-NLS-1$
|| ( container instanceof LdifContentRecord && part instanceof LdifInvalidPart && "dn:".equals( prefix ) ) ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
LdifEditorConstants.LDIF_FILE_TEMPLATE_ID );
}
// MODIFICATION RECORD
if ( container instanceof LdifChangeModifyRecord && innerContainer == null
&& ( part instanceof LdifSepLine || part instanceof LdifInvalidPart ) )
{
return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
LdifEditorConstants.LDIF_MODIFICATION_RECORD_TEMPLATE_ID );
}
// MODIFICATION ITEM
if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec )
{
return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
LdifEditorConstants.LDIF_MODIFICATION_ITEM_TEMPLATE_ID );
}
// MODDN RECORD
if ( container instanceof LdifChangeModDnRecord && innerContainer == null
&& ( part instanceof LdifSepLine || part instanceof LdifInvalidPart ) )
{
return LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
LdifEditorConstants.LDIF_MODDN_RECORD_TEMPLATE_ID );
}
// TemplateContextType contextType =
// Activator.getDefault().getContextTypeRegistry().getContextType(LdifEditorConstants.LDIF_FILE_TEMPLATE_ID);
// TemplateContextType contextType =
// Activator.getDefault().getContextTypeRegistry().getContextType(LdifEditorConstants.LDIF_MODIFICATION_RECORD_TEMPLATE_ID);
return null;
}
protected Image getImage( Template template )
{
if ( template.getPattern().indexOf( "add: " ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_ADD );
}
else if ( template.getPattern().indexOf( "replace: " ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_REPLACE );
}
else if ( template.getPattern().indexOf( "delete: " ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_DELETE );
}
else if ( template.getPattern().indexOf( "changetype: add" ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD );
}
else if ( template.getPattern().indexOf( "changetype: modify" ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MODIFY );
}
else if ( template.getPattern().indexOf( "changetype: delete" ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_DELETE );
}
else if ( template.getPattern().indexOf( "changetype: moddn" ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_RENAME );
}
else if ( template.getPattern().indexOf( "dn: " ) > -1 ) //$NON-NLS-1$
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_ENTRY );
}
else
{
return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_TEMPLATE );
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifValueRule.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifValueRule.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.ldifeditor.editor.text;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
public class LdifValueRule implements IRule
{
private IToken token;
public LdifValueRule( IToken token )
{
this.token = token;
}
public IToken evaluate( ICharacterScanner scanner )
{
if ( matchContent( scanner ) )
{
return this.token;
}
else
{
return Token.UNDEFINED;
}
}
protected boolean matchContent( ICharacterScanner scanner )
{
int count = 0;
int c = scanner.read();
while ( c != ICharacterScanner.EOF )
{
// check for folding
if ( c == '\n' || c == '\r' )
{
StringBuffer temp = new StringBuffer( 3 );
if ( c == '\r' )
{
c = scanner.read();
if ( c == '\n' )
{
temp.append( c );
}
else
{
scanner.unread();
}
}
else if ( c == '\n' )
{
c = scanner.read();
if ( c == '\r' )
{
temp.append( c );
}
else
{
scanner.unread();
}
}
c = scanner.read();
if ( c == ' ' && c != ICharacterScanner.EOF )
{
// space after newline, continue
temp.append( c );
count += temp.length();
c = scanner.read();
}
else
{
for ( int i = 0; i < temp.length(); i++ )
scanner.unread();
break;
}
}
else
{
count++;
c = scanner.read();
}
}
scanner.unread();
return count > 0;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifAutoEditStrategy.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.ldifeditor.editor.text;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecTypeLine;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
public class LdifAutoEditStrategy implements IAutoEditStrategy
{
private ILdifEditor editor;
public LdifAutoEditStrategy( ILdifEditor editor )
{
this.editor = editor;
}
public void customizeDocumentCommand( IDocument d, DocumentCommand c )
{
LdifFile model = editor.getLdifModel();
LdifContainer container = LdifFile.getContainer( model, c.offset );
LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, c.offset ) : null;
LdifPart part = container != null ? LdifFile.getContainerContent( container, c.offset ) : null;
boolean smartInsertAttributeInModSpec = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC );
if ( smartInsertAttributeInModSpec )
{
if ( c.length == 0 && c.text != null && TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
{
if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec
&& ( part instanceof LdifAttrValLine || part instanceof LdifModSpecTypeLine ) )
{
LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
String att = modSpec.getModSpecType().getUnfoldedAttributeDescription();
c.text += att + ": "; //$NON-NLS-1$
}
}
}
boolean autoWrap = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FORMATTER_AUTOWRAP );
if ( autoWrap )
{
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifExternalAnnotationModel.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.ldifeditor.editor.text;
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
public class LdifExternalAnnotationModel extends ProjectionAnnotationModel
{
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDamagerRepairer.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.ldifeditor.editor.text;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifEOFPart;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifInvalidPart;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeDeleteRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifModSpec;
import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifChangeTypeLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifCommentLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifControlLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifDeloldrdnLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifDnLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifLineBase;
import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecSepLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifModSpecTypeLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifNewrdnLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifNewsuperiorLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifVersionLine;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationRepairer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
public class LdifDamagerRepairer implements IPresentationDamager, IPresentationRepairer
{
private ILdifEditor editor;
private Map<String, Object> textAttributeKeyToValueMap;
public LdifDamagerRepairer( ILdifEditor editor )
{
super();
this.editor = editor;
}
public void setDocument( IDocument document )
{
}
public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged )
{
return partition;
}
public void createPresentation( TextPresentation presentation, ITypedRegion damage )
{
LdifFile ldifModel = this.editor.getLdifModel();
List<LdifContainer> allContainers = ldifModel.getContainers();
List<LdifContainer> containerList = new ArrayList<LdifContainer>();
for ( LdifContainer ldifContainer : allContainers )
{
Region containerRegion = new Region( ldifContainer.getOffset(), ldifContainer.getLength() );
if ( TextUtilities.overlaps( containerRegion, damage ) )
{
containerList.add( ldifContainer );
}
}
LdifContainer[] containers = ( LdifContainer[] ) containerList
.toArray( new LdifContainer[containerList.size()] );
this.highlight( containers, presentation, damage );
}
private TextAttribute getTextAttribute( String key )
{
IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore();
String colorKey = key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX;
String styleKey = key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX;
RGB rgb = PreferenceConverter.getColor( store, colorKey );
int style = store.getInt( styleKey );
if ( textAttributeKeyToValueMap != null )
{
if ( textAttributeKeyToValueMap.containsKey( colorKey ) )
{
rgb = ( RGB ) textAttributeKeyToValueMap.get( colorKey );
}
if ( textAttributeKeyToValueMap.containsKey( styleKey ) )
{
style = ( ( Integer ) textAttributeKeyToValueMap.get( styleKey ) ).intValue();
}
}
/*
* Use color <code>null</code> if the default is the default string, This is important
* to not override the system color when a high-contrast theme is used.
*/
boolean isDefaultDefaultKey = IPreferenceStore.STRING_DEFAULT_DEFAULT.equals( store.getString( colorKey ) );
Color color = isDefaultDefaultKey ? null : LdifEditorActivator.getDefault().getColor( rgb );
TextAttribute textAttribute = new TextAttribute( color, null, style );
return textAttribute;
}
/**
* Overwrites the style set in preference store
*
* @param key
* the key
* LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_xxx +
* LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX
* ore
* LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX
* @param newValue
* RGB object or Integer object
*/
public void setTextAttribute( String key, RGB rgb, int style )
{
if ( textAttributeKeyToValueMap == null )
{
textAttributeKeyToValueMap = new HashMap<String, Object>();
}
textAttributeKeyToValueMap.put( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, rgb );
textAttributeKeyToValueMap.put( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX,
new Integer( style ) );
}
private void highlight( LdifContainer[] containers, TextPresentation presentation, ITypedRegion damage )
{
TextAttribute COMMENT_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_COMMENT );
TextAttribute KEYWORD_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_KEYWORD );
TextAttribute DN_TEXT_ATTRIBUTE = getTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_DN );
TextAttribute ATTRIBUTE_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_ATTRIBUTE );
TextAttribute VALUETYPE_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUETYPE );
TextAttribute VALUE_TEXT_ATTRIBUTE = getTextAttribute( LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUE );
TextAttribute ADD_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEADD );
TextAttribute MODIFY_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODIFY );
TextAttribute DELETE_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEDELETE );
TextAttribute MODDN_TEXT_ATTRIBUTE = getTextAttribute(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODDN );
for ( int z = 0; z < containers.length; z++ )
{
LdifContainer container = containers[z];
LdifPart[] parts = container.getParts();
for ( int i = 0; i < parts.length; i++ )
{
// int offset = damage.getOffset() + parts[i].getOffset();
int offset = parts[i].getOffset();
if ( parts[i] instanceof LdifLineBase )
{
LdifLineBase line = ( LdifLineBase ) parts[i];
// String debug = line.getClass().getName() +
// "("+line.getOffset()+","+line.getLength()+"):
// "+line.toString();
// debug = debug.replaceAll("\n", "\\\\n");
// debug = debug.replaceAll("\r", "\\\\r");
// System.out.println(debug);
if ( line instanceof LdifVersionLine )
{
this.addStyleRange( presentation, offset, line.getLength(), KEYWORD_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifCommentLine )
{
this.addStyleRange( presentation, offset, line.getLength(), COMMENT_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifDnLine )
{
LdifDnLine dnLine = ( LdifDnLine ) line;
int dnSpecLength = dnLine.getRawDnSpec().length();
int valueTypeLength = dnLine.getRawValueType().length();
int dnLength = dnLine.getRawDn().length();
this.addStyleRange( presentation, offset, dnSpecLength, DN_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + dnSpecLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + dnSpecLength + valueTypeLength, dnLength,
DN_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifAttrValLine )
{
LdifAttrValLine attrValLine = ( LdifAttrValLine ) line;
int attributeNameLength = attrValLine.getRawAttributeDescription().length();
int valueTypeLength = attrValLine.getRawValueType().length();
int valueLength = attrValLine.getRawValue().length();
this.addStyleRange( presentation, offset, attributeNameLength, ATTRIBUTE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + attributeNameLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + attributeNameLength + valueTypeLength, valueLength,
VALUE_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifChangeTypeLine )
{
LdifChangeTypeLine changeTypeLine = ( LdifChangeTypeLine ) line;
int changeTypeSpecLength = changeTypeLine.getRawChangeTypeSpec().length();
int valueTypeLength = changeTypeLine.getRawValueType().length();
int changeTypeLength = changeTypeLine.getRawChangeType().length();
this.addStyleRange( presentation, offset, changeTypeSpecLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + changeTypeSpecLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
if ( container instanceof LdifChangeAddRecord )
{
this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
changeTypeLength, ADD_TEXT_ATTRIBUTE );
}
else if ( container instanceof LdifChangeModifyRecord )
{
this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
changeTypeLength, MODIFY_TEXT_ATTRIBUTE );
}
else if ( container instanceof LdifChangeModDnRecord )
{
this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
changeTypeLength, MODDN_TEXT_ATTRIBUTE );
}
else if ( container instanceof LdifChangeDeleteRecord )
{
this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
changeTypeLength, DELETE_TEXT_ATTRIBUTE );
}
}
else if ( line instanceof LdifNewrdnLine )
{
LdifNewrdnLine newrdnLine = ( LdifNewrdnLine ) line;
int newrdnSpecLength = newrdnLine.getRawNewrdnSpec().length();
int valueTypeLength = newrdnLine.getRawValueType().length();
int newrdnLength = newrdnLine.getRawNewrdn().length();
this.addStyleRange( presentation, offset, newrdnSpecLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + newrdnSpecLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + newrdnSpecLength + valueTypeLength, newrdnLength,
VALUE_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifDeloldrdnLine )
{
LdifDeloldrdnLine deleteoldrdnLine = ( LdifDeloldrdnLine ) line;
int deleteoldrdnSpecLength = deleteoldrdnLine.getRawDeleteOldrdnSpec().length();
int valueTypeLength = deleteoldrdnLine.getRawValueType().length();
int deleteoldrdnLength = deleteoldrdnLine.getRawDeleteOldrdn().length();
this.addStyleRange( presentation, offset, deleteoldrdnSpecLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + deleteoldrdnSpecLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + deleteoldrdnSpecLength + valueTypeLength,
deleteoldrdnLength, VALUE_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifNewsuperiorLine )
{
LdifNewsuperiorLine newsuperiorLine = ( LdifNewsuperiorLine ) line;
int newsuperiorSpecLength = newsuperiorLine.getRawNewSuperiorSpec().length();
int valueTypeLength = newsuperiorLine.getRawValueType().length();
int newsuperiorLength = newsuperiorLine.getRawNewSuperiorDn().length();
this.addStyleRange( presentation, offset, newsuperiorSpecLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + newsuperiorSpecLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + newsuperiorSpecLength + valueTypeLength,
newsuperiorLength, VALUE_TEXT_ATTRIBUTE );
}
// else if(line instanceof LdifDeloldrdnLine) {
// this.addStyleRange(presentation, offset,
// line.getLength(), MODTYPE_TEXT_ATTRIBUTE);
// }
// else if(line instanceof LdifNewsuperiorLine) {
// this.addStyleRange(presentation, offset,
// line.getLength(), MODTYPE_TEXT_ATTRIBUTE);
// }
else if ( line instanceof LdifModSpecTypeLine )
{
LdifModSpecTypeLine modSpecTypeLine = ( LdifModSpecTypeLine ) line;
int modTypeLength = modSpecTypeLine.getRawModType().length();
int valueTypeLength = modSpecTypeLine.getRawValueType().length();
int attributeDescriptionLength = modSpecTypeLine.getRawAttributeDescription().length();
this.addStyleRange( presentation, offset, modTypeLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + modTypeLength, valueTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + modTypeLength + valueTypeLength,
attributeDescriptionLength, ATTRIBUTE_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifModSpecSepLine )
{
this.addStyleRange( presentation, offset, line.getLength(), VALUETYPE_TEXT_ATTRIBUTE );
}
else if ( line instanceof LdifControlLine )
{
LdifControlLine controlLine = ( LdifControlLine ) line;
int controlSpecLength = controlLine.getRawControlSpec().length();
int controlTypeLength = controlLine.getRawControlType().length();
int oidLength = controlLine.getRawOid().length();
int critLength = controlLine.getRawCriticality().length();
int valueTypeLength = controlLine.getRawControlValueType().length();
int valueLength = controlLine.getRawControlValue().length();
this.addStyleRange( presentation, offset, controlSpecLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + controlSpecLength, controlTypeLength,
VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength, oidLength,
ATTRIBUTE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength,
critLength, KEYWORD_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength
+ critLength, valueTypeLength, VALUETYPE_TEXT_ATTRIBUTE );
this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength
+ critLength + valueTypeLength, valueLength, VALUE_TEXT_ATTRIBUTE );
}
else
{
// this.addStyleRange(presentation, offset,
// line.getLength(), DEFAULT_TEXT_ATTRIBUTE);
}
}
else if ( parts[i] instanceof LdifModSpec )
{
LdifModSpec modSpec = ( LdifModSpec ) parts[i];
this.highlight( new LdifContainer[]
{ modSpec }, presentation, damage );
}
else if ( parts[i] instanceof LdifInvalidPart )
{
// LdifUnknownPart unknownPart =
// (LdifUnknownPart)parts[i];
// this.addStyleRange(presentation, offset,
// unknownPart.getLength(), UNKNOWN_TEXT_ATTRIBUTE);
// this.addStyleRange(presentation, offset,
// parts[i].getLength(), DEFAULT_TEXT_ATTRIBUTE);
}
else if ( parts[i] instanceof LdifEOFPart )
{
// ignore
}
else
{
// TODO
System.out.println( "LdifDamagerRepairer: Unspecified Token: " + parts[i].getClass() ); //$NON-NLS-1$
}
}
}
}
private void addStyleRange( TextPresentation presentation, int offset, int length, TextAttribute textAttribute )
{
if ( offset >= 0 && length > 0 )
{
StyleRange range = new StyleRange( offset, length, textAttribute.getForeground(), textAttribute
.getBackground(), textAttribute.getStyle() & ( SWT.BOLD | SWT.ITALIC ) );
range.underline = ( textAttribute.getStyle() & TextAttribute.UNDERLINE ) != 0;
range.strikeout = ( textAttribute.getStyle() & TextAttribute.STRIKETHROUGH ) != 0;
presentation.addStyleRange( range );
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifPartitionScanner.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.ldifeditor.editor.text;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
import org.eclipse.jface.text.rules.Token;
public class LdifPartitionScanner extends RuleBasedPartitionScanner
{
public final static String LDIF_RECORD = "__ldif_record"; //$NON-NLS-1$
public LdifPartitionScanner()
{
IToken record = new Token( LDIF_RECORD );
IPredicateRule[] rules = new IPredicateRule[1];
rules[0] = new LdifRecordRule( record );
setPredicateRules( rules );
}
public int read()
{
return super.read();
// try {
// return super.read();
// } finally {
// fColumn = UNDEFINED;
// }
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifRecordRule.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifRecordRule.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.ldifeditor.editor.text;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
/**
* Rule to detect LDIF records. A LDIF record must start with "dn:" at column 0
* and end with new line at column 0.
*
*
*/
public class LdifRecordRule implements IPredicateRule
{
private static char[] DN_SEQUENCE = new char[]
{ 'd', 'n', ':' };
private IToken recordToken;
public LdifRecordRule( IToken recordToken )
{
this.recordToken = recordToken;
}
public IToken getSuccessToken()
{
return this.recordToken;
}
/**
* Checks for new line "\n", "\r" or "\r\n".
*
* @param scanner
* @return
*/
private int matchNewline( ICharacterScanner scanner )
{
int c = scanner.read();
if ( c == '\r' )
{
c = scanner.read();
if ( c == '\n' )
{
return 2;
}
else
{
scanner.unread();
return 1;
}
}
else if ( c == '\n' )
{
c = scanner.read();
if ( c == '\r' )
{
return 2;
}
else
{
scanner.unread();
return 1;
}
}
else
{
scanner.unread();
return 0;
}
}
/**
* Checks for "dn:".
*
* @param scanner
* @return
*/
private int matchDnAndColon( ICharacterScanner scanner )
{
for ( int i = 0; i < DN_SEQUENCE.length; i++ )
{
int c = scanner.read();
if ( c != DN_SEQUENCE[i] )
{
while ( i >= 0 )
{
scanner.unread();
i--;
}
return 0;
}
}
return DN_SEQUENCE.length;
}
private boolean matchEOF( ICharacterScanner scanner )
{
int c = scanner.read();
if ( c == ICharacterScanner.EOF )
{
return true;
}
else
{
scanner.unread();
return false;
}
}
public IToken evaluate( ICharacterScanner scanner, boolean resume )
{
if ( scanner.getColumn() != 0 )
{
return Token.UNDEFINED;
}
int c;
do
{
c = scanner.read();
if ( c == '\r' || c == '\n' )
{
// check end of record
scanner.unread();
if ( this.matchNewline( scanner ) > 0 )
{
int nlCount = this.matchNewline( scanner );
if ( nlCount > 0 )
{
int dnCount = this.matchDnAndColon( scanner );
if ( dnCount > 0 )
{
while ( dnCount > 0 )
{
scanner.unread();
dnCount--;
}
return this.recordToken;
}
else if ( this.matchEOF( scanner ) )
{
return this.recordToken;
}
else
{
while ( nlCount > 0 )
{
scanner.unread();
nlCount--;
}
}
}
else if ( this.matchEOF( scanner ) )
{
return this.recordToken;
}
}
else if ( this.matchEOF( scanner ) )
{
return this.recordToken;
}
}
else if ( c == ICharacterScanner.EOF )
{
return this.recordToken;
}
}
while ( true );
}
public IToken evaluate( ICharacterScanner scanner )
{
return this.evaluate( scanner, 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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/text/LdifDoubleClickStrategy.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.ldifeditor.editor.text;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifparser.model.LdifEOFPart;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifInvalidPart;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.lines.LdifLineBase;
import org.apache.directory.studio.ldifparser.model.lines.LdifSepLine;
import org.apache.directory.studio.ldifparser.model.lines.LdifValueLineBase;
import org.apache.directory.studio.ldifparser.parser.LdifParser;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultTextDoubleClickStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITypedRegion;
public class LdifDoubleClickStrategy implements ITextDoubleClickStrategy
{
private static final int OFFSET = 0;
private static final int LENGTH = 1;
/**
* Default double click strategy
*/
private DefaultTextDoubleClickStrategy delegateDoubleClickStrategy;
public LdifDoubleClickStrategy()
{
this.delegateDoubleClickStrategy = new DefaultTextDoubleClickStrategy();
}
public void doubleClicked( ITextViewer viewer )
{
if ( !LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) )
{
delegateDoubleClickStrategy.doubleClicked( viewer );
}
else
{
int cursorPos = viewer.getSelectedRange().x;
if ( cursorPos < 0 )
{
return;
}
try
{
LdifParser parser = new LdifParser();
IDocument document = viewer.getDocument();
ITypedRegion partition = document.getPartition( cursorPos );
// now use position relative to partition
int offset = partition.getOffset();
int relativePos = cursorPos - offset;
// parse partition
String s = document.get( partition.getOffset(), partition.getLength() );
LdifFile model = parser.parse( s );
LdifContainer container = LdifFile.getContainer( model, relativePos );
if ( container != null )
{
LdifPart part = LdifFile.getContainerContent( container, relativePos );
if ( part != null && !( part instanceof LdifSepLine ) && !( part instanceof LdifInvalidPart )
&& !( part instanceof LdifEOFPart ) )
{
// calculate selected range
int[] range = null;
if ( part instanceof LdifValueLineBase )
{
LdifValueLineBase line = ( LdifValueLineBase ) part;
range = getRange( relativePos, part.getOffset(), new String[]
{ line.getRawLineStart(), line.getRawValueType(), line.getRawValue() } );
}
else if ( part instanceof LdifLineBase )
{
LdifLineBase line = ( LdifLineBase ) part;
range = new int[]
{ part.getOffset(), part.getLength() - line.getRawNewLine().length() };
}
// set range on viewer, add global offset
int start = range != null ? range[OFFSET] : part.getOffset();
start += offset;
int length = range != null ? range[LENGTH] : part.getLength();
viewer.setSelectedRange( start, length );
}
else
{
// use default double click strategy
delegateDoubleClickStrategy.doubleClicked( viewer );
}
}
}
catch ( BadLocationException e )
{
e.printStackTrace();
}
}
}
private int[] getRange( int pos, int offset, String[] parts )
{
for ( int i = 0; i < parts.length; i++ )
{
if ( parts[i] != null )
{
if ( pos < offset + parts[i].length() )
{
return new int[]
{ offset, parts[i].length() };
}
offset += parts[i].length();
}
}
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifReconcilingStrategy.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.ldifeditor.editor.reconciler;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifeditor.editor.LdifOutlinePage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
public class LdifReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension
{
private ILdifEditor editor;
// private IDocument document;
// private IProgressMonitor progressMonitor;
private LdifFoldingRegionUpdater foldingUpdater;
private LdifAnnotationUpdater annotationUpdater;
public LdifReconcilingStrategy( ILdifEditor editor )
{
this.editor = editor;
this.annotationUpdater = new LdifAnnotationUpdater( this.editor );
this.foldingUpdater = new LdifFoldingRegionUpdater( this.editor );
}
public void dispose()
{
this.annotationUpdater.dispose();
this.foldingUpdater.dispose();
}
public void setDocument( IDocument document )
{
// this.document = document;
}
public void setProgressMonitor( IProgressMonitor monitor )
{
// this.progressMonitor = monitor;
}
public void reconcile( DirtyRegion dirtyRegion, IRegion subRegion )
{
reconcile();
}
public void reconcile( IRegion partition )
{
reconcile();
}
public void initialReconcile()
{
reconcile();
}
private void reconcile()
{
notifyEnvironment();
}
private void notifyEnvironment()
{
Display.getDefault().asyncExec( new Runnable()
{
public void run()
{
// notify outline
IContentOutlinePage outline = ( IContentOutlinePage ) editor.getAdapter( IContentOutlinePage.class );
if ( outline instanceof LdifOutlinePage )
{
( ( LdifOutlinePage ) outline ).refresh();
}
// notify annotation updater
annotationUpdater.updateAnnotations();
// notify folding updater
foldingUpdater.updateFoldingRegions();
}
} );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifAnnotationUpdater.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.ldifeditor.editor.reconciler;
import java.util.ArrayList;
import java.util.List;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.IAnnotationModelExtension;
import org.eclipse.jface.text.source.ISourceViewer;
class LdifAnnotationUpdater
{
private static final String ERROR_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.error"; //$NON-NLS-1$
private ILdifEditor editor;
public LdifAnnotationUpdater( ILdifEditor editor )
{
this.editor = editor;
}
public void dispose()
{
}
public void updateAnnotations( LdifContainer[] containers )
{
}
public void updateAnnotations()
{
LdifFile model = editor.getLdifModel();
ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
if ( viewer == null )
{
return;
}
IDocument document = viewer.getDocument();
IAnnotationModel annotationModel = viewer.getAnnotationModel();
if ( document == null || annotationModel == null || model == null )
{
return;
}
if ( annotationModel instanceof IAnnotationModelExtension )
{
( ( IAnnotationModelExtension ) annotationModel ).removeAllAnnotations();
List<Position> positionList = new ArrayList<Position>();
List<LdifContainer> containers = model.getContainers();
for ( LdifContainer ldifContainer : containers )
{
// LdifPart errorPart = null;
int errorOffset = -1;
int errorLength = -1;
StringBuilder errorText = null;
LdifPart[] parts = ldifContainer.getParts();
for ( LdifPart ldifPart : parts )
{
if ( !ldifPart.isValid() )
{
if ( errorOffset == -1 )
{
// errorPart = part;
errorOffset = ldifPart.getOffset();
errorLength = ldifPart.getLength();
errorText = new StringBuilder();
errorText.append( ldifPart.toRawString() );
}
else
{
errorLength += ldifPart.getLength();
errorText.append( ldifPart.toRawString() );
}
}
}
if ( errorOffset == -1 && !ldifContainer.isValid() )
{
errorOffset = ldifContainer.getOffset();
errorLength = ldifContainer.getLength();
errorText = new StringBuilder();
errorText.append( ldifContainer.toRawString() );
}
if ( errorOffset > -1 )
{
Annotation annotation = new Annotation( ERROR_ANNOTATION_TYPE, true, errorText.toString() );
Position position = new Position( errorOffset, errorLength );
positionList.add( position );
viewer.getAnnotationModel().addAnnotation( annotation, position );
}
}
}
}
} | java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/reconciler/LdifFoldingRegionUpdater.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.ldifeditor.editor.reconciler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.LdifPart;
import org.apache.directory.studio.ldifparser.model.container.LdifCommentContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.lines.LdifNonEmptyLineBase;
import org.apache.directory.studio.ldifparser.model.lines.LdifSepLine;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
public class LdifFoldingRegionUpdater implements IPropertyChangeListener
{
private ILdifEditor editor;
public LdifFoldingRegionUpdater( ILdifEditor editor )
{
this.editor = editor;
LdifEditorActivator.getDefault().getPreferenceStore().addPropertyChangeListener( this );
}
public void dispose()
{
LdifEditorActivator.getDefault().getPreferenceStore().removePropertyChangeListener( this );
}
public void propertyChange( PropertyChangeEvent event )
{
if ( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE.equals( event.getProperty() )
|| LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS.equals( event.getProperty() )
|| LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS.equals( event.getProperty() )
|| LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES.equals( event.getProperty() ) )
{
this.updateFoldingRegions();
}
}
public void updateFoldingRegions()
{
ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
if ( viewer == null )
return;
IDocument document = viewer.getDocument();
try
{
ProjectionAnnotationModel projectionAnnotationModel = ( ProjectionAnnotationModel ) editor
.getAdapter( ProjectionAnnotationModel.class );
if ( projectionAnnotationModel == null )
return;
// create folding regions of current LDIF model; mark comments
// and
// folded lines as collapsed
Map<Position, ProjectionAnnotation> positionToAnnotationMap = createFoldingRegions( editor.getLdifModel(), document );
// compare with current annotation model (--> toAdd, toDelete)
List<Annotation> annotationsToDeleteList = new ArrayList<Annotation>();
Map<ProjectionAnnotation, Position> annotationsToAddMap = new HashMap<ProjectionAnnotation, Position>();
this.computeDifferences( projectionAnnotationModel, positionToAnnotationMap, annotationsToDeleteList,
annotationsToAddMap );
Annotation[] annotationsToDelete = ( Annotation[] ) annotationsToDeleteList
.toArray( new Annotation[annotationsToDeleteList.size()] );
// update annotation model
if ( !annotationsToDeleteList.isEmpty() || !annotationsToAddMap.isEmpty() )
{
projectionAnnotationModel.modifyAnnotations( annotationsToDelete, annotationsToAddMap,
new Annotation[0] );
}
}
catch ( BadLocationException e )
{
e.printStackTrace();
}
}
private void computeDifferences( ProjectionAnnotationModel model, Map<Position, ProjectionAnnotation> positionToAnnotationMap,
List<Annotation> annotationsToDeleteList, Map<ProjectionAnnotation, Position> annotationsToAddMap )
{
for ( Iterator<Annotation> iter = model.getAnnotationIterator(); iter.hasNext(); )
{
Annotation annotation = iter.next();
if ( annotation instanceof ProjectionAnnotation )
{
Position position = model.getPosition( ( Annotation ) annotation );
if ( positionToAnnotationMap.containsKey( position ) )
{
positionToAnnotationMap.remove( position );
}
else
{
annotationsToDeleteList.add( annotation );
}
}
}
for ( Map.Entry<Position, ProjectionAnnotation> entry : positionToAnnotationMap.entrySet() )
{
annotationsToAddMap.put( entry.getValue(), entry.getKey() );
}
}
/**
* Creates all folding region of the given LDIF model.
* LdifCommentContainers and wrapped lines are marked as collapsed.
*
* @param model
* @param document
* @return a map with positions as keys to annotations as values
* @throws BadLocationException
*/
private Map<Position, ProjectionAnnotation> createFoldingRegions( LdifFile model, IDocument document ) throws BadLocationException
{
Map<Position, ProjectionAnnotation> positionToAnnotationMap = new HashMap<Position, ProjectionAnnotation>();
List<LdifContainer> containers = model.getContainers();
boolean ENABLE_FOLDING = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE );
boolean FOLD_COMMENTS = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS );
boolean FOLD_RECORDS = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS );
boolean FOLD_WRAPPEDLINES = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES );
if ( ENABLE_FOLDING )
{
for ( LdifContainer ldifContainer : containers )
{
int containerStartLine = document.getLineOfOffset( ldifContainer.getOffset() );
int containerEndLine = -1;
LdifPart[] parts = ldifContainer.getParts();
for ( int j = parts.length - 1; j >= 0; j-- )
{
if ( containerEndLine == -1
&& ( !( parts[j] instanceof LdifSepLine ) || ( ldifContainer instanceof LdifCommentContainer && j < parts.length - 1 ) ) )
{
containerEndLine = document.getLineOfOffset( parts[j].getOffset() + parts[j].getLength() - 1 );
// break;
}
if ( parts[j] instanceof LdifNonEmptyLineBase )
{
LdifNonEmptyLineBase line = ( LdifNonEmptyLineBase ) parts[j];
if ( line.isFolded() )
{
Position position = new Position( line.getOffset(), line.getLength() );
// ProjectionAnnotation annotation = new
// ProjectionAnnotation(true);
ProjectionAnnotation annotation = new ProjectionAnnotation( FOLD_WRAPPEDLINES );
positionToAnnotationMap.put( position, annotation );
}
}
}
if ( containerStartLine < containerEndLine )
{
int start = document.getLineOffset( containerStartLine );
int end = document.getLineOffset( containerEndLine ) + document.getLineLength( containerEndLine );
Position position = new Position( start, end - start );
ProjectionAnnotation annotation = new ProjectionAnnotation( FOLD_RECORDS
|| ( FOLD_COMMENTS && ldifContainer instanceof LdifCommentContainer ) );
positionToAnnotationMap.put( position, annotation );
}
}
}
return positionToAnnotationMap;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/widgets/LdifEditorWidget.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/widgets/LdifEditorWidget.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.ldifeditor.widgets;
import org.apache.directory.studio.common.ui.widgets.AbstractWidget;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifeditor.editor.LdifDocumentProvider;
import org.apache.directory.studio.ldifeditor.editor.LdifSourceViewerConfiguration;
import org.apache.directory.studio.ldifeditor.editor.NonExistingLdifEditorInput;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextListener;
import org.eclipse.jface.text.TextEvent;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* The LdifEditorWidget provides basic LDIF editor functionality like
* syntax highlighting and content assistent.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifEditorWidget extends AbstractWidget implements ILdifEditor, ITextListener
{
/** The connection. */
private IBrowserConnection connection;
/** The initial LDIF. */
private String initialLdif;
/** The content assist enabled. */
private boolean contentAssistEnabled;
/** The editor input. */
private NonExistingLdifEditorInput editorInput;
/** The document provider. */
private LdifDocumentProvider documentProvider;
/** The source viewer. */
private SourceViewer sourceViewer;
/** The source viewer configuration. */
private LdifSourceViewerConfiguration sourceViewerConfiguration;
/** The widget composite */
private Composite composite;
/**
* Creates a new instance of LdifEditorWidget.
*
* @param contentAssistEnabled the content assist enabled
* @param initialLdif the initial ldif
* @param connection the connection
*/
public LdifEditorWidget( IBrowserConnection connection, String initialLdif, boolean contentAssistEnabled )
{
this.connection = connection;
this.initialLdif = initialLdif;
this.contentAssistEnabled = contentAssistEnabled;
}
/**
* Disposes this widget.
*/
public void dispose()
{
if ( editorInput != null )
{
sourceViewer.removeTextListener( this );
documentProvider.disconnect( editorInput );
// documentProvider = null;
editorInput = null;
}
}
/**
* Creates the widget.
*
* @param parent the parent
*/
public void createWidget( Composite parent )
{
composite = new Composite( parent, SWT.NONE );
composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
GridLayout layout = new GridLayout( 1, false );
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout( layout );
// create source viewer
// sourceViewer = new ProjectionViewer(parent, ruler,
// getOverviewRuler(), true, styles);
sourceViewer = new SourceViewer( composite, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL );
sourceViewer.getControl().setLayoutData( new GridData( GridData.FILL_BOTH ) );
// configure
sourceViewerConfiguration = new LdifSourceViewerConfiguration( this, this.contentAssistEnabled );
sourceViewer.configure( sourceViewerConfiguration );
// set font
Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
sourceViewer.getTextWidget().setFont( font );
// setup document
try
{
editorInput = new NonExistingLdifEditorInput();
documentProvider = new LdifDocumentProvider();
documentProvider.connect( editorInput );
IDocument document = documentProvider.getDocument( editorInput );
document.set( initialLdif );
sourceViewer.setDocument( document );
}
catch ( CoreException e )
{
e.printStackTrace();
}
// listener
sourceViewer.addTextListener( this );
// focus
sourceViewer.getControl().setFocus();
}
/**
* {@inheritDoc}
*/
public IBrowserConnection getConnection()
{
return connection;
}
/**
* {@inheritDoc}
*/
public LdifFile getLdifModel()
{
return documentProvider.getLdifModel();
}
/**
* {@inheritDoc}
*/
public Object getAdapter( Class adapter )
{
return null;
}
/**
* {@inheritDoc}
*/
public void textChanged( TextEvent event )
{
super.notifyListeners();
}
/**
* Gets the source viewer.
*
* @return the source viewer
*/
public SourceViewer getSourceViewer()
{
return sourceViewer;
}
/**
* Gets the source viewer configuration.
*
* @return the source viewer configuration
*/
public LdifSourceViewerConfiguration getSourceViewerConfiguration()
{
return sourceViewerConfiguration;
}
/**
* Returns the primary control associated with this view form.
*
* @return the SWT control which displays this view form's content
*/
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/Messages.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/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.ldifeditor.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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/LdifEntryEditorDialog.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/LdifEntryEditorDialog.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.ldifeditor.dialogs;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidget;
import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetActionGroup;
import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetActionGroupWithAttribute;
import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetConfiguration;
import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetUniversalListener;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyConnection;
import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
import org.apache.directory.studio.ldapbrowser.core.utils.ModelConverter;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
public class LdifEntryEditorDialog extends Dialog
{
public static final String DIALOG_TITLE = Messages.getString( "LdifEntryEditorDialog.LDIFRecordEditor" ); //$NON-NLS-1$
public static final int MAX_WIDTH = 450;
public static final int MAX_HEIGHT = 250;
private IBrowserConnection browserConnection;
private boolean originalReadOnlyFlag;
private LdifRecord ldifRecord;
private IEntry entry;
private EntryEditorWidgetConfiguration configuration;
private EntryEditorWidgetActionGroup actionGroup;
private EntryEditorWidget mainWidget;
private EntryEditorWidgetUniversalListener universalListener;
/** Token used to activate and deactivate shortcuts in the editor */
private IContextActivation contextActivation;
public LdifEntryEditorDialog( Shell parentShell, IBrowserConnection browserConnection, LdifContentRecord ldifRecord )
{
this( parentShell, browserConnection, ldifRecord, null );
}
public LdifEntryEditorDialog( Shell parentShell, IBrowserConnection browserConnection,
LdifChangeAddRecord ldifRecord )
{
this( parentShell, browserConnection, ldifRecord, null );
}
private LdifEntryEditorDialog( Shell parentShell, IBrowserConnection browserConnection, LdifRecord ldifRecord,
String s )
{
super( parentShell );
setShellStyle( getShellStyle() | SWT.RESIZE );
this.ldifRecord = ldifRecord;
this.browserConnection = browserConnection != null ? browserConnection : new DummyConnection(
Schema.DEFAULT_SCHEMA );
try
{
if ( ldifRecord instanceof LdifContentRecord )
{
entry = ModelConverter.ldifContentRecordToEntry( ( LdifContentRecord ) this.ldifRecord,
this.browserConnection );
}
else if ( ldifRecord instanceof LdifChangeAddRecord )
{
entry = ModelConverter.ldifChangeAddRecordToEntry( ( LdifChangeAddRecord ) this.ldifRecord,
this.browserConnection );
}
}
catch ( LdapInvalidDnException e )
{
entry = null;
}
}
protected void configureShell( Shell shell )
{
super.configureShell( shell );
shell.setText( DIALOG_TITLE );
shell.setImage( LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_BROWSER_LDIFEDITOR ) );
}
protected void createButtonsForButtonBar( Composite parent )
{
createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
if ( entry != null )
{
createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
}
getShell().update();
getShell().layout( true, true );
}
protected void buttonPressed( int buttonId )
{
if ( IDialogConstants.OK_ID == buttonId && entry != null )
{
if ( this.ldifRecord instanceof LdifContentRecord )
{
this.ldifRecord = ModelConverter.entryToLdifContentRecord( entry );
}
else if ( this.ldifRecord instanceof LdifChangeAddRecord )
{
this.ldifRecord = ModelConverter.entryToLdifChangeAddRecord( entry );
}
}
super.buttonPressed( buttonId );
}
public void create()
{
super.create();
if ( browserConnection.getConnection() != null )
{
originalReadOnlyFlag = browserConnection.getConnection().isReadOnly();
browserConnection.getConnection().setReadOnly( true );
}
}
public boolean close()
{
boolean returnValue = super.close();
if ( returnValue )
{
this.dispose();
if ( browserConnection.getConnection() != null )
{
browserConnection.getConnection().setReadOnly( originalReadOnlyFlag );
}
}
return returnValue;
}
public void dispose()
{
if ( this.configuration != null )
{
this.universalListener.dispose();
this.universalListener = null;
this.mainWidget.dispose();
this.mainWidget = null;
this.actionGroup.deactivateGlobalActionHandlers();
this.actionGroup.dispose();
this.actionGroup = null;
this.configuration.dispose();
this.configuration = null;
if ( contextActivation != null )
{
IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
IContextService.class );
contextService.deactivateContext( contextActivation );
contextActivation = null;
}
}
}
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
if ( entry == null )
{
String message = Messages.getString( "LdifEntryEditorDialog.InvalidDnCantEditEntry" ); //$NON-NLS-1$
BaseWidgetUtils.createLabel( composite, message, 1 );
}
else
{
// create configuration
configuration = new EntryEditorWidgetConfiguration();
// create main widget
mainWidget = new EntryEditorWidget( configuration );
mainWidget.createWidget( composite );
mainWidget.getViewer().getTree().setFocus();
// create actions
actionGroup = new EntryEditorWidgetActionGroupWithAttribute( mainWidget, configuration );
actionGroup.fillToolBar( mainWidget.getToolBarManager() );
actionGroup.fillMenu( mainWidget.getMenuManager() );
actionGroup.fillContextMenu( mainWidget.getContextMenuManager() );
IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
IContextService.class );
contextActivation = contextService.activateContext( BrowserCommonConstants.CONTEXT_DIALOGS );
actionGroup.activateGlobalActionHandlers();
// hack to activate the action handlers when changing the selection
mainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
actionGroup.deactivateGlobalActionHandlers();
actionGroup.activateGlobalActionHandlers();
}
} );
// create the listener
universalListener = new EntryEditorWidgetUniversalListener( mainWidget.getViewer(), configuration,
actionGroup, actionGroup.getOpenDefaultEditorAction() );
universalListener.setInput( entry );
}
applyDialogFont( composite );
return composite;
}
public LdifRecord getLdifRecord()
{
return ldifRecord;
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorTemplatesPreferencePage.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorTemplatesPreferencePage.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.ldifeditor.dialogs.preferences;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.eclipse.ui.texteditor.templates.TemplatePreferencePage;
public class LdifEditorTemplatesPreferencePage extends TemplatePreferencePage
{
public LdifEditorTemplatesPreferencePage()
{
super();
super.setPreferenceStore( LdifEditorActivator.getDefault().getPreferenceStore() );
super.setTemplateStore( LdifEditorActivator.getDefault().getLdifTemplateStore() );
super.setContextTypeRegistry( LdifEditorActivator.getDefault().getLdifTemplateContextTypeRegistry() );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorContentAssistPreferencePage.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorContentAssistPreferencePage.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.ldifeditor.dialogs.preferences;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class LdifEditorContentAssistPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
{
private Button insertSingleProposalAutoButton;
private Button enableAutoActivationButton;
private Label autoActivationDelayLabel;
private Text autoActivationDelayText;
private Label autoActivationDelayMs;
private Button smartInsertAttributeInModspecButton;
public LdifEditorContentAssistPreferencePage()
{
super( Messages.getString( "LdifEditorContentAssistPreferencePage.ContentAssist" ) ); //$NON-NLS-1$
super.setPreferenceStore( LdifEditorActivator.getDefault().getPreferenceStore() );
}
public void init( IWorkbench workbench )
{
}
protected Control createContents( Composite parent )
{
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout( 1, false );
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
composite.setLayout( layout );
GridData gd = new GridData( GridData.FILL_HORIZONTAL );
composite.setLayoutData( gd );
BaseWidgetUtils.createSpacer( composite, 1 );
BaseWidgetUtils.createSpacer( composite, 1 );
Group caGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), Messages
.getString( "LdifEditorContentAssistPreferencePage.ContentAssist" ), 1 ); //$NON-NLS-1$
insertSingleProposalAutoButton = BaseWidgetUtils.createCheckbox( caGroup, Messages
.getString( "LdifEditorContentAssistPreferencePage.InsertSingleProposalAutomatically" ), 1 ); //$NON-NLS-1$
insertSingleProposalAutoButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
enableAutoActivationButton = BaseWidgetUtils.createCheckbox( caGroup, Messages
.getString( "LdifEditorContentAssistPreferencePage.EnableAutoAction" ), 1 ); //$NON-NLS-1$
enableAutoActivationButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
enableAutoActivationButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
checkEnabled();
}
} );
Composite autoActivationDelayComposite = BaseWidgetUtils.createColumnContainer( caGroup, 4, 1 );
BaseWidgetUtils.createRadioIndent( autoActivationDelayComposite, 1 );
autoActivationDelayLabel = BaseWidgetUtils.createLabel( autoActivationDelayComposite, Messages
.getString( "LdifEditorContentAssistPreferencePage.AutoActivationDelay" ), //$NON-NLS-1$
1 );
autoActivationDelayText = BaseWidgetUtils.createText( autoActivationDelayComposite, "", 4, 1 ); //$NON-NLS-1$
autoActivationDelayText.setText( getPreferenceStore().getString(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
autoActivationDelayText.addVerifyListener( new VerifyListener()
{
public void verifyText( VerifyEvent e )
{
if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
{
e.doit = false;
}
if ( "".equals( autoActivationDelayText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
{
e.doit = false;
}
}
} );
autoActivationDelayMs = BaseWidgetUtils.createLabel( autoActivationDelayComposite, Messages
.getString( "LdifEditorContentAssistPreferencePage.MilliSecons" ), 1 ); //$NON-NLS-1$
smartInsertAttributeInModspecButton = BaseWidgetUtils.createCheckbox( caGroup, Messages
.getString( "LdifEditorContentAssistPreferencePage.SmartInsertAttributeName" ), 1 ); //$NON-NLS-1$
smartInsertAttributeInModspecButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC ) );
checkEnabled();
return composite;
}
private void checkEnabled()
{
autoActivationDelayLabel.setEnabled( enableAutoActivationButton.getSelection() );
autoActivationDelayText.setEnabled( enableAutoActivationButton.getSelection() );
autoActivationDelayMs.setEnabled( enableAutoActivationButton.getSelection() );
}
public boolean performOk()
{
getPreferenceStore().setValue(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO,
this.insertSingleProposalAutoButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION,
this.enableAutoActivationButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY,
this.autoActivationDelayText.getText() );
getPreferenceStore().setValue(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC,
this.smartInsertAttributeInModspecButton.getSelection() );
return true;
}
protected void performDefaults()
{
insertSingleProposalAutoButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
enableAutoActivationButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
autoActivationDelayText.setText( getPreferenceStore().getDefaultString(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
smartInsertAttributeInModspecButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC ) );
super.performDefaults();
checkEnabled();
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/Messages.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/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.ldifeditor.dialogs.preferences;
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorPreferencePage.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorPreferencePage.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.ldifeditor.dialogs.preferences;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.eclipse.jface.preference.PreferencePage;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.dialogs.PreferencesUtil;
/**
* The main preference page of the LDIF editor.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LdifEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
{
// private Button autoWrapButton;
/** The enable folding button. */
private Button enableFoldingButton;
/** The initially fold label. */
private Label initiallyFoldLabel;
/** The initially fold comments button. */
private Button initiallyFoldCommentsButton;
/** The initially fold records button. */
private Button initiallyFoldRecordsButton;
/** The initially fold wrapped lines button. */
private Button initiallyFoldWrappedLinesButton;
/** The use ldif double click button. */
private Button useLdifDoubleClickButton;
/** The update if entry exists button. */
private Button updateIfEntryExistsButton;
/** The continue on error button. */
private Button continueOnErrorButton;
/**
* Creates a new instance of LdifEditorPreferencePage.
*/
public LdifEditorPreferencePage()
{
super( Messages.getString( "LdifEditorPreferencePage.LDIFEditor" ) ); //$NON-NLS-1$
super.setPreferenceStore( LdifEditorActivator.getDefault().getPreferenceStore() );
}
/**
* {@inheritDoc}
*/
public void init( IWorkbench workbench )
{
}
/**
* {@inheritDoc}
*/
protected Control createContents( Composite parent )
{
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout( 1, false );
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
composite.setLayout( layout );
composite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
String text = Messages.getString( "LdifEditorPreferencePage.LinkToTextEditors" ); //$NON-NLS-1$
Link link = BaseWidgetUtils.createLink( composite, text, 1 );
link.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
PreferencesUtil.createPreferenceDialogOn( getShell(),
"org.eclipse.ui.preferencePages.GeneralTextEditor", null, null ); //$NON-NLS-1$
}
} );
String text2 = Messages.getString( "LdifEditorPreferencePage.LinkToTextFormats" ); //$NON-NLS-1$
Link link2 = BaseWidgetUtils.createLink( composite, text2, 1 );
link2.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
PreferencesUtil.createPreferenceDialogOn( getShell(), LdifEditorConstants.PREFERENCEPAGEID_TEXTFORMATS,
null, null ); //$NON-NLS-1$
}
} );
BaseWidgetUtils.createSpacer( composite, 1 );
BaseWidgetUtils.createSpacer( composite, 1 );
Group foldGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
Messages.getString( "LdifEditorPreferencePage.Folding" ), 1 ); //$NON-NLS-1$
enableFoldingButton = BaseWidgetUtils.createCheckbox( foldGroup, Messages
.getString( "LdifEditorPreferencePage.EnableFolding" ), 1 ); //$NON-NLS-1$
enableFoldingButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE ) );
enableFoldingButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
checkEnabled();
}
} );
Composite initiallyFoldComposiste = BaseWidgetUtils.createColumnContainer( foldGroup, 4, 1 );
initiallyFoldLabel = BaseWidgetUtils.createLabel( initiallyFoldComposiste, Messages
.getString( "LdifEditorPreferencePage.InitiallyFold" ), 1 ); //$NON-NLS-1$
initiallyFoldCommentsButton = BaseWidgetUtils.createCheckbox( initiallyFoldComposiste, Messages
.getString( "LdifEditorPreferencePage.Comments" ), 1 ); //$NON-NLS-1$
initiallyFoldCommentsButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS ) );
initiallyFoldRecordsButton = BaseWidgetUtils.createCheckbox( initiallyFoldComposiste, Messages
.getString( "LdifEditorPreferencePage.Records" ), 1 ); //$NON-NLS-1$
initiallyFoldRecordsButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS ) );
initiallyFoldWrappedLinesButton = BaseWidgetUtils.createCheckbox( initiallyFoldComposiste, Messages
.getString( "LdifEditorPreferencePage.WrappedLines" ), 1 ); //$NON-NLS-1$
initiallyFoldWrappedLinesButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES ) );
BaseWidgetUtils.createSpacer( composite, 1 );
Group doubleClickGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
Messages.getString( "LdifEditorPreferencePage.DoubleClickBehaviour" ), 1 ); //$NON-NLS-1$
useLdifDoubleClickButton = BaseWidgetUtils.createCheckbox( doubleClickGroup, Messages
.getString( "LdifEditorPreferencePage.SelectWholeAttributeOnDoubleClick" ), 1 ); //$NON-NLS-1$
useLdifDoubleClickButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) );
BaseWidgetUtils.createSpacer( composite, 1 );
// Options
Group optionsGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
Messages.getString( "LdifEditorPreferencePage.ExecuteOptions" ), 1 ); //$NON-NLS-1$
updateIfEntryExistsButton = BaseWidgetUtils.createCheckbox( optionsGroup, Messages
.getString( "LdifEditorPreferencePage.UpdateExistingEntries" ), 1 ); //$NON-NLS-1$
updateIfEntryExistsButton.setToolTipText( Messages
.getString( "LdifEditorPreferencePage.UpdateExistingEntriesToolTip1" ) //$NON-NLS-1$
+ Messages.getString( "LdifEditorPreferencePage.UpdateExistingEntriesToolTip2" ) ); //$NON-NLS-1$
updateIfEntryExistsButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_UPDATEIFENTRYEXISTS ) );
continueOnErrorButton = BaseWidgetUtils.createCheckbox( optionsGroup, Messages
.getString( "LdifEditorPreferencePage.ContinueOnError" ), 1 ); //$NON-NLS-1$
continueOnErrorButton.setSelection( getPreferenceStore().getBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_CONTINUEONERROR ) );
checkEnabled();
return composite;
}
/**
* Enables/disables widgets dependent if options are selected.
*/
private void checkEnabled()
{
initiallyFoldLabel.setEnabled( enableFoldingButton.getSelection() );
initiallyFoldCommentsButton.setEnabled( enableFoldingButton.getSelection() );
initiallyFoldRecordsButton.setEnabled( enableFoldingButton.getSelection() );
initiallyFoldWrappedLinesButton.setEnabled( enableFoldingButton.getSelection() );
}
/**
* {@inheritDoc}
*/
public boolean performOk()
{
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE,
enableFoldingButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS,
initiallyFoldCommentsButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS,
initiallyFoldRecordsButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES,
initiallyFoldWrappedLinesButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK,
useLdifDoubleClickButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_UPDATEIFENTRYEXISTS,
updateIfEntryExistsButton.getSelection() );
getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_CONTINUEONERROR,
continueOnErrorButton.getSelection() );
return true;
}
/**
* {@inheritDoc}
*/
protected void performDefaults()
{
enableFoldingButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE ) );
initiallyFoldCommentsButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS ) );
initiallyFoldRecordsButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS ) );
initiallyFoldWrappedLinesButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES ) );
useLdifDoubleClickButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) );
updateIfEntryExistsButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_UPDATEIFENTRYEXISTS ) );
continueOnErrorButton.setSelection( getPreferenceStore().getDefaultBoolean(
LdifEditorConstants.PREFERENCE_LDIFEDITOR_OPTIONS_CONTINUEONERROR ) );
super.performDefaults();
checkEnabled();
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorSyntaxColoringPreferencePage.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/dialogs/preferences/LdifEditorSyntaxColoringPreferencePage.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.ldifeditor.dialogs.preferences;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldifeditor.LdifEditorActivator;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.ILdifEditor;
import org.apache.directory.studio.ldifeditor.widgets.LdifEditorWidget;
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.RGB;
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.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class LdifEditorSyntaxColoringPreferencePage extends PreferencePage implements IWorkbenchPreferencePage,
ILdifEditor
{
private static final String LDIF_INITIAL = "" + "# Content record" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$
+ "dn: cn=content record" + BrowserCoreConstants.LINE_SEPARATOR + "objectClass: person" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "cn: content record" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$
+ "cn;lang-ja:: 5Za25qWt6YOo" + BrowserCoreConstants.LINE_SEPARATOR + "" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$
+ "# Add record with control" + BrowserCoreConstants.LINE_SEPARATOR + "dn: cn=add record" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "control: 1.2.3.4 true: controlValue" //$NON-NLS-1$
+ BrowserCoreConstants.LINE_SEPARATOR + "changetype: add" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$
+ "objectClass: person" + BrowserCoreConstants.LINE_SEPARATOR + "cn: add record" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$
+ "# Modify record" + BrowserCoreConstants.LINE_SEPARATOR + "dn: cn=modify record" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "changetype: modify" + BrowserCoreConstants.LINE_SEPARATOR + "add: cn" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "cn: modify record" + BrowserCoreConstants.LINE_SEPARATOR + "-" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "delete: cn" + BrowserCoreConstants.LINE_SEPARATOR + "-" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "replace: cn" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$
+ "cn: modify record" + BrowserCoreConstants.LINE_SEPARATOR + "-" + BrowserCoreConstants.LINE_SEPARATOR + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ BrowserCoreConstants.LINE_SEPARATOR
+ "# Delete record" + BrowserCoreConstants.LINE_SEPARATOR + "dn: cn=delete record" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "changetype: delete" + BrowserCoreConstants.LINE_SEPARATOR + "" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR
+ "# Modify Dn record" + BrowserCoreConstants.LINE_SEPARATOR + "dn: cn=moddn record" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "changetype: moddn" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$
+ "newrdn: cn=new rdn" + BrowserCoreConstants.LINE_SEPARATOR + "deleteoldrdn: 1" //$NON-NLS-1$ //$NON-NLS-2$
+ BrowserCoreConstants.LINE_SEPARATOR + "newsuperior: cn=new superior" + BrowserCoreConstants.LINE_SEPARATOR //$NON-NLS-1$
+ "" + BrowserCoreConstants.LINE_SEPARATOR; //$NON-NLS-1$
private LdifEditorWidget ldifEditorWidget;
private SyntaxItem[] syntaxItems;
private ColorSelector colorSelector;
private Button boldCheckBox;
private Button italicCheckBox;
private Button underlineCheckBox;
private Button strikethroughCheckBox;
private TableViewer syntaxItemViewer;
private class SyntaxItem
{
String displayName;
String key;
RGB rgb;
boolean bold;
boolean italic;
boolean strikethrough;
boolean underline;
SyntaxItem( String displayName, String key )
{
this.displayName = displayName;
this.key = key;
loadPreferences();
}
int getStyle()
{
int style = SWT.NORMAL;
if ( bold )
style |= SWT.BOLD;
if ( italic )
style |= SWT.ITALIC;
if ( strikethrough )
style |= TextAttribute.STRIKETHROUGH;
if ( underline )
style |= TextAttribute.UNDERLINE;
return style;
}
void setStyle( int style )
{
this.bold = ( style & SWT.BOLD ) != SWT.NORMAL;
this.italic = ( style & SWT.ITALIC ) != SWT.NORMAL;
this.strikethrough = ( style & TextAttribute.STRIKETHROUGH ) != SWT.NORMAL;
this.underline = ( style & TextAttribute.UNDERLINE ) != SWT.NORMAL;
}
void loadPreferences()
{
IPreferenceStore store = getPreferenceStore();
this.rgb = PreferenceConverter.getColor( store, key
+ LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX );
int style = store.getInt( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX );
setStyle( style );
}
void savePreferences()
{
IPreferenceStore store = getPreferenceStore();
PreferenceConverter
.setValue( store, key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, rgb );
store.setValue( key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, getStyle() );
}
void loadDefaultPreferences()
{
IPreferenceStore store = getPreferenceStore();
String colorKey = key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX;
store.setToDefault( colorKey);
String styleKey = key + LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX;
store.setToDefault( styleKey);
this.rgb = PreferenceConverter.getDefaultColor( store, colorKey );
int style = store.getDefaultInt( styleKey );
setStyle( style );
}
public String toString()
{
return displayName;
}
}
public LdifEditorSyntaxColoringPreferencePage()
{
super( Messages.getString( "LdifEditorSyntaxColoringPreferencePage.SyntaxColoring" ) ); //$NON-NLS-1$
super.setPreferenceStore( LdifEditorActivator.getDefault().getPreferenceStore() );
// super.setDescription("");
}
public void init( IWorkbench workbench )
{
}
public void dispose()
{
ldifEditorWidget.dispose();
super.dispose();
}
protected Control createContents( Composite parent )
{
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout( 1, false );
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
composite.setLayout( layout );
GridData gd = new GridData( GridData.FILL_HORIZONTAL );
composite.setLayoutData( gd );
BaseWidgetUtils.createSpacer( composite, 1 );
BaseWidgetUtils.createSpacer( composite, 1 );
createSyntaxPage( composite );
createPreviewer( composite );
syntaxItems = new SyntaxItem[10];
syntaxItems[0] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.Comments" ), LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_COMMENT ); //$NON-NLS-1$
syntaxItems[1] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.DN" ), LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_DN ); //$NON-NLS-1$
syntaxItems[2] = new SyntaxItem( Messages
.getString( "LdifEditorSyntaxColoringPreferencePage.AttributeDescriptions" ), //$NON-NLS-1$
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_ATTRIBUTE );
syntaxItems[3] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.ValueTypes" ), LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUETYPE ); //$NON-NLS-1$
syntaxItems[4] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.Values" ), LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUE ); //$NON-NLS-1$
syntaxItems[5] = new SyntaxItem( Messages.getString( "LdifEditorSyntaxColoringPreferencePage.Keywords" ), //$NON-NLS-1$
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_KEYWORD );
syntaxItems[6] = new SyntaxItem( Messages.getString( "LdifEditorSyntaxColoringPreferencePage.ChangetypeAdd" ), //$NON-NLS-1$
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEADD );
syntaxItems[7] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.ChangetypeModify" ), //$NON-NLS-1$
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODIFY );
syntaxItems[8] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.ChangetypeDelete" ), //$NON-NLS-1$
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEDELETE );
syntaxItems[9] = new SyntaxItem(
Messages.getString( "LdifEditorSyntaxColoringPreferencePage.ChangetypeModdn" ), //$NON-NLS-1$
LdifEditorConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODDN );
syntaxItemViewer.setInput( syntaxItems );
syntaxItemViewer.setSelection( new StructuredSelection( syntaxItems[0] ) );
return composite;
}
private void createSyntaxPage( Composite parent )
{
BaseWidgetUtils.createLabel( parent, Messages.getString( "LdifEditorSyntaxColoringPreferencePage.Element" ), 1 ); //$NON-NLS-1$
Composite editorComposite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
syntaxItemViewer = new TableViewer( editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER
| SWT.FULL_SELECTION );
syntaxItemViewer.setLabelProvider( new LabelProvider() );
syntaxItemViewer.setContentProvider( new ArrayContentProvider() );
// colorListViewer.setSorter(new WorkbenchViewerSorter());
GridData gd = new GridData( GridData.FILL_BOTH );
gd.heightHint = convertHeightInCharsToPixels( 5 );
syntaxItemViewer.getControl().setLayoutData( gd );
Composite stylesComposite = BaseWidgetUtils.createColumnContainer( editorComposite, 1, 1 );
stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
Composite colorComposite = BaseWidgetUtils.createColumnContainer( stylesComposite, 2, 1 );
BaseWidgetUtils.createLabel( colorComposite, Messages
.getString( "LdifEditorSyntaxColoringPreferencePage.Color" ), 1 ); //$NON-NLS-1$
colorSelector = new ColorSelector( colorComposite );
boldCheckBox = BaseWidgetUtils.createCheckbox( stylesComposite, Messages
.getString( "LdifEditorSyntaxColoringPreferencePage.Bold" ), 1 ); //$NON-NLS-1$
italicCheckBox = BaseWidgetUtils.createCheckbox( stylesComposite, Messages
.getString( "LdifEditorSyntaxColoringPreferencePage.Italic" ), 1 ); //$NON-NLS-1$
strikethroughCheckBox = BaseWidgetUtils.createCheckbox( stylesComposite, Messages
.getString( "LdifEditorSyntaxColoringPreferencePage.Strikethrough" ), 1 ); //$NON-NLS-1$
underlineCheckBox = BaseWidgetUtils.createCheckbox( stylesComposite, Messages
.getString( "LdifEditorSyntaxColoringPreferencePage.Underline" ), 1 ); //$NON-NLS-1$
syntaxItemViewer.addSelectionChangedListener( new ISelectionChangedListener()
{
public void selectionChanged( SelectionChangedEvent event )
{
handleSyntaxItemViewerSelectionEvent();
}
} );
colorSelector.addListener( new IPropertyChangeListener()
{
public void propertyChange( PropertyChangeEvent event )
{
handleColorSelectorEvent();
}
} );
boldCheckBox.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
handleBoldSelectionEvent();
}
} );
italicCheckBox.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
handleItalicSelectionEvent();
}
} );
strikethroughCheckBox.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
handleStrikethroughSelectionEvent();
}
} );
underlineCheckBox.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
handleUnderlineSelectionEvent();
}
} );
}
private void handleUnderlineSelectionEvent()
{
SyntaxItem item = getSyntaxItem();
if ( item != null )
{
item.underline = underlineCheckBox.getSelection();
setTextAttribute( item );
}
}
private void handleStrikethroughSelectionEvent()
{
SyntaxItem item = getSyntaxItem();
if ( item != null )
{
item.strikethrough = strikethroughCheckBox.getSelection();
setTextAttribute( item );
}
}
private void handleItalicSelectionEvent()
{
SyntaxItem item = getSyntaxItem();
if ( item != null )
{
item.italic = italicCheckBox.getSelection();
setTextAttribute( item );
}
}
private void handleBoldSelectionEvent()
{
SyntaxItem item = getSyntaxItem();
if ( item != null )
{
item.bold = boldCheckBox.getSelection();
setTextAttribute( item );
}
}
private void handleColorSelectorEvent()
{
SyntaxItem item = getSyntaxItem();
if ( item != null )
{
item.rgb = colorSelector.getColorValue();
setTextAttribute( item );
}
}
private void handleSyntaxItemViewerSelectionEvent()
{
SyntaxItem item = getSyntaxItem();
if ( item != null )
{
colorSelector.setColorValue( item.rgb );
boldCheckBox.setSelection( item.bold );
italicCheckBox.setSelection( item.italic );
strikethroughCheckBox.setSelection( item.strikethrough );
underlineCheckBox.setSelection( item.underline );
}
}
private SyntaxItem getSyntaxItem()
{
SyntaxItem item = ( SyntaxItem ) ( ( IStructuredSelection ) syntaxItemViewer.getSelection() ).getFirstElement();
return item;
}
private void setTextAttribute( SyntaxItem item )
{
ldifEditorWidget.getSourceViewerConfiguration().setTextAttribute( item.key, item.rgb, item.getStyle() );
int topIndex = ldifEditorWidget.getSourceViewer().getTopIndex();
// ldifEditorWidget.getSourceViewer().getDocument().set("");
ldifEditorWidget.getSourceViewer().getDocument().set( LDIF_INITIAL );
ldifEditorWidget.getSourceViewer().setTopIndex( topIndex );
}
private void createPreviewer( Composite parent )
{
BaseWidgetUtils.createLabel( parent, Messages.getString( "LdifEditorSyntaxColoringPreferencePage.Preview" ), 1 ); //$NON-NLS-1$
ldifEditorWidget = new LdifEditorWidget( null, LDIF_INITIAL, false );
ldifEditorWidget.createWidget( parent );
ldifEditorWidget.getSourceViewer().setEditable( false );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertWidthInCharsToPixels( 20 );
gd.heightHint = convertHeightInCharsToPixels( 5 );
ldifEditorWidget.getSourceViewer().getControl().setLayoutData( gd );
}
public IBrowserConnection getConnection()
{
return ldifEditorWidget.getConnection();
}
public LdifFile getLdifModel()
{
return ldifEditorWidget.getLdifModel();
}
public boolean performOk()
{
for ( int i = 0; i < syntaxItems.length; i++ )
{
syntaxItems[i].savePreferences();
}
return true;
}
protected void performDefaults()
{
for ( int i = 0; i < syntaxItems.length; i++ )
{
syntaxItems[i].loadDefaultPreferences();
setTextAttribute( syntaxItems[i] );
}
handleSyntaxItemViewerSelectionEvent();
super.performDefaults();
}
public Object getAdapter( Class adapter )
{
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/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/wizards/NewLdifFileWizard.java | plugins/ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/wizards/NewLdifFileWizard.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.ldifeditor.wizards;
import org.apache.directory.studio.ldifeditor.LdifEditorConstants;
import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
import org.apache.directory.studio.ldifeditor.editor.NonExistingLdifEditorInput;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
/**
* The NewLdifFileWizard is used to add a "New LDIF" action to the platforms
* "New..." menu. It just opens an editor with a dummy LDIF editor input.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class NewLdifFileWizard extends Wizard implements INewWizard
{
/** The window. */
private IWorkbenchWindow window;
/**
* Creates a new instance of NewLdifFileWizard.
*/
public NewLdifFileWizard()
{
}
/**
* {@inheritDoc}
*/
public void init( IWorkbench workbench, IStructuredSelection selection )
{
window = workbench.getActiveWorkbenchWindow();
}
/**
* {@inheritDoc}
*/
public void dispose()
{
window = null;
}
/**
* Gets the id.
*
* @return the id
*/
public static String getId()
{
return LdifEditorConstants.NEW_WIZARD_NEW_LDIF_FILE;
}
/**
* {@inheritDoc}
*/
public boolean performFinish()
{
IEditorInput input = new NonExistingLdifEditorInput();
String editorId = LdifEditor.getId();
try
{
IWorkbenchPage page = window.getActivePage();
page.openEditor( input, editorId );
}
catch ( PartInitException e )
{
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.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/RetryTest.java | plugins/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/RetryTest.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.syncrepl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class RetryTest
{
@Test
public void testEmpty() throws Exception
{
try
{
Retry.parse( "" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete1() throws Exception
{
try
{
Retry.parse( "12" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete3() throws Exception
{
try
{
Retry.parse( "12 " );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete4() throws Exception
{
try
{
Retry.parse( "12 34 " );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testOk1() throws Exception
{
Retry retry = Retry.parse( "1 2" );
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair pair = retry.getPairs()[0];
assertNotNull( pair );
assertEquals( 1, pair.getInterval() );
assertEquals( 2, pair.getRetries() );
assertEquals( "1 2", retry.toString() );
}
@Test
public void testOk2() throws Exception
{
Retry retry = Retry.parse( "12 34" );
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair pair = retry.getPairs()[0];
assertNotNull( pair );
assertEquals( 12, pair.getInterval() );
assertEquals( 34, pair.getRetries() );
assertEquals( "12 34", retry.toString() );
}
@Test
public void testOk3() throws Exception
{
Retry retry = Retry.parse( "123 456" );
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair pair = retry.getPairs()[0];
assertNotNull( pair );
assertEquals( 123, pair.getInterval() );
assertEquals( 456, pair.getRetries() );
assertEquals( "123 456", retry.toString() );
}
@Test
public void testOk4() throws Exception
{
Retry retry = Retry.parse( "1234 5678" );
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair pair = retry.getPairs()[0];
assertNotNull( pair );
assertEquals( 1234, pair.getInterval() );
assertEquals( 5678, pair.getRetries() );
assertEquals( "1234 5678", retry.toString() );
}
@Test
public void testOk5() throws Exception
{
Retry retry = Retry.parse( "1 +" );
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair pair = retry.getPairs()[0];
assertNotNull( pair );
assertEquals( 1, pair.getInterval() );
assertEquals( RetryPair.PLUS, pair.getRetries() );
assertEquals( "1 +", retry.toString() );
}
@Test
public void testOk6() throws Exception
{
Retry retry = Retry.parse( "1 2 3 4" );
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 1, pair1.getInterval() );
assertEquals( 2, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 3, pair2.getInterval() );
assertEquals( 4, pair2.getRetries() );
assertEquals( "1 2 3 4", retry.toString() );
}
@Test
public void testOk7() throws Exception
{
Retry retry = Retry.parse( "12 34 56 78" );
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 12, pair1.getInterval() );
assertEquals( 34, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 56, pair2.getInterval() );
assertEquals( 78, pair2.getRetries() );
assertEquals( "12 34 56 78", retry.toString() );
}
@Test
public void testOk8() throws Exception
{
Retry retry = Retry.parse( "123 456 789 123" );
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 123, pair1.getInterval() );
assertEquals( 456, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 789, pair2.getInterval() );
assertEquals( 123, pair2.getRetries() );
assertEquals( "123 456 789 123", retry.toString() );
}
@Test
public void testOk9() throws Exception
{
Retry retry = Retry.parse( "1234 5678 9123 4567" );
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 1234, pair1.getInterval() );
assertEquals( 5678, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 9123, pair2.getInterval() );
assertEquals( 4567, pair2.getRetries() );
assertEquals( "1234 5678 9123 4567", retry.toString() );
}
@Test
public void testOk10() throws Exception
{
Retry retry = Retry.parse( "1 + 2 +" );
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 1, pair1.getInterval() );
assertEquals( RetryPair.PLUS, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 2, pair2.getInterval() );
assertEquals( RetryPair.PLUS, pair2.getRetries() );
assertEquals( "1 + 2 +", retry.toString() );
}
@Test
public void testOk11() throws Exception
{
Retry retry = Retry.parse( "1 2 3 4 5 6" );
assertNotNull( retry );
assertEquals( 3, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 1, pair1.getInterval() );
assertEquals( 2, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 3, pair2.getInterval() );
assertEquals( 4, pair2.getRetries() );
RetryPair pair3 = retry.getPairs()[2];
assertNotNull( pair3 );
assertEquals( 5, pair3.getInterval() );
assertEquals( 6, pair3.getRetries() );
assertEquals( "1 2 3 4 5 6", retry.toString() );
}
@Test
public void testOk12() throws Exception
{
Retry retry = Retry.parse( "12 34 56 78 90 12" );
assertNotNull( retry );
assertEquals( 3, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 12, pair1.getInterval() );
assertEquals( 34, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 56, pair2.getInterval() );
assertEquals( 78, pair2.getRetries() );
RetryPair pair3 = retry.getPairs()[2];
assertNotNull( pair3 );
assertEquals( 90, pair3.getInterval() );
assertEquals( 12, pair3.getRetries() );
assertEquals( "12 34 56 78 90 12", retry.toString() );
}
@Test
public void testOk13() throws Exception
{
Retry retry = Retry.parse( "123 456 789 123 456 789" );
assertNotNull( retry );
assertEquals( 3, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 123, pair1.getInterval() );
assertEquals( 456, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 789, pair2.getInterval() );
assertEquals( 123, pair2.getRetries() );
RetryPair pair3 = retry.getPairs()[2];
assertNotNull( pair3 );
assertEquals( 456, pair3.getInterval() );
assertEquals( 789, pair3.getRetries() );
assertEquals( "123 456 789 123 456 789", retry.toString() );
}
@Test
public void testOk14() throws Exception
{
Retry retry = Retry.parse( "1234 5678 9123 4567 8901 2345" );
assertNotNull( retry );
assertEquals( 3, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 1234, pair1.getInterval() );
assertEquals( 5678, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 9123, pair2.getInterval() );
assertEquals( 4567, pair2.getRetries() );
RetryPair pair3 = retry.getPairs()[2];
assertNotNull( pair3 );
assertEquals( 8901, pair3.getInterval() );
assertEquals( 2345, pair3.getRetries() );
assertEquals( "1234 5678 9123 4567 8901 2345", retry.toString() );
}
@Test
public void testOk15() throws Exception
{
Retry retry = Retry.parse( "1 + 2 + 3 +" );
assertNotNull( retry );
assertEquals( 3, retry.size() );
RetryPair pair1 = retry.getPairs()[0];
assertNotNull( pair1 );
assertEquals( 1, pair1.getInterval() );
assertEquals( RetryPair.PLUS, pair1.getRetries() );
RetryPair pair2 = retry.getPairs()[1];
assertNotNull( pair2 );
assertEquals( 2, pair2.getInterval() );
assertEquals( RetryPair.PLUS, pair2.getRetries() );
RetryPair pair3 = retry.getPairs()[2];
assertNotNull( pair3 );
assertEquals( 3, pair3.getInterval() );
assertEquals( RetryPair.PLUS, pair3.getRetries() );
assertEquals( "1 + 2 + 3 +", retry.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/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/RetryPairTest.java | plugins/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/RetryPairTest.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.syncrepl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class RetryPairTest
{
@Test
public void testEmpty() throws Exception
{
try
{
RetryPair.parse( "" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete1() throws Exception
{
try
{
RetryPair.parse( "12" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete3() throws Exception
{
try
{
RetryPair.parse( "12 " );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete4() throws Exception
{
try
{
RetryPair.parse( "12 34 " );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testOk1() throws Exception
{
RetryPair retryPair = RetryPair.parse( "1 2" );
assertEquals( 1, retryPair.getInterval() );
assertEquals( 2, retryPair.getRetries() );
assertEquals( "1 2", retryPair.toString() );
}
@Test
public void testOk2() throws Exception
{
RetryPair retryPair = RetryPair.parse( "12 34" );
assertEquals( 12, retryPair.getInterval() );
assertEquals( 34, retryPair.getRetries() );
assertEquals( "12 34", retryPair.toString() );
}
@Test
public void testOk3() throws Exception
{
RetryPair retryPair = RetryPair.parse( "123 456" );
assertEquals( 123, retryPair.getInterval() );
assertEquals( 456, retryPair.getRetries() );
assertEquals( "123 456", retryPair.toString() );
}
@Test
public void testOk4() throws Exception
{
RetryPair retryPair = RetryPair.parse( "1234 5678" );
assertEquals( 1234, retryPair.getInterval() );
assertEquals( 5678, retryPair.getRetries() );
assertEquals( "1234 5678", retryPair.toString() );
}
@Test
public void testOk5() throws Exception
{
RetryPair retryPair = RetryPair.parse( "1 +" );
assertEquals( 1, retryPair.getInterval() );
assertEquals( RetryPair.PLUS, retryPair.getRetries() );
assertEquals( "1 +", retryPair.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/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/SyncReplParserTest.java | plugins/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/SyncReplParserTest.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.syncrepl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class SyncReplParserTest
{
@Test
public void testEmpty() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "" );
assertNull( syncRepl );
}
@Test
public void testUnknownOption() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "unknownOption" );
assertNull( syncRepl );
}
@Test
public void testUnknownOptionWithValue() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "unknownOption=someValue" );
assertNull( syncRepl );
}
@Test
public void testRidOkOneDigit() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "rid=1" );
assertNotNull( syncRepl );
assertEquals( "1", syncRepl.getRid() );
}
@Test
public void testRidOkTwoDigit() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "rid=12" );
assertNotNull( syncRepl );
assertEquals( "12", syncRepl.getRid() );
}
@Test
public void testRidOkThreeDigit() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "rid=123" );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
}
@Test
public void testRidOkThreeDigitWithWhiteSpaces() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( " rid = 123 " );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
}
@Test
public void testProvider() throws Exception
{
SyncReplParser parser = new SyncReplParser();
parser.parse( "provider=ldap://localhost:10389" );
}
@Test
public void testProviderWithWhiteSpaces() throws Exception
{
SyncReplParser parser = new SyncReplParser();
parser.parse( " provider = ldap://localhost:10389" );
}
@Test
public void testSymasDoc1SingleLine() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=0 " +
"provider=ldap://ldapmaster.symas.com:389 " +
"bindmethod=simple " +
"binddn=\"cn=replicator,dc=symas,dc=com\" " +
"credentials=secret " +
"searchbase=\"dc=symas,dc=com\" " +
"logbase=\"cn=accesslog\" " +
"logfilter=\"(&(objectClass=auditWriteObject)(reqResult=0))\" " +
"schemachecking=on " +
"type=refreshAndPersist " +
"retry=\"60 +\" " +
"syncdata=accesslog" );
assertNotNull( syncRepl );
assertEquals( "0", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "ldapmaster.symas.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=replicator,dc=symas,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
assertEquals( "dc=symas,dc=com", syncRepl.getSearchBase() );
assertEquals( "cn=accesslog", syncRepl.getLogBase() );
assertEquals( "(&(objectClass=auditWriteObject)(reqResult=0))", syncRepl.getLogFilter() );
assertEquals( SchemaChecking.ON, syncRepl.getSchemaChecking() );
assertEquals( Type.REFRESH_AND_PERSIST, syncRepl.getType() );
Retry retry = syncRepl.getRetry();
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair retryPair = retry.getPairs()[0];
assertNotNull( retryPair );
assertEquals( 60, retryPair.getInterval() );
assertEquals( RetryPair.PLUS, retryPair.getRetries() );
assertEquals( SyncData.ACCESSLOG, syncRepl.getSyncData() );
}
@Test
public void testSymasDoc1WithSpacesMultilines() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=0 \n" +
"provider=ldap://ldapmaster.symas.com:389 \n" +
"bindmethod=simple \n" +
"binddn=\"cn=replicator,dc=symas,dc=com\" \n" +
"credentials=secret \n" +
"searchbase=\"dc=symas,dc=com\" \n" +
"logbase=\"cn=accesslog\" \n" +
"logfilter=\"(&(objectClass=auditWriteObject)(reqResult=0))\" \n" +
"schemachecking=on \n" +
"type=refreshAndPersist \n" +
"retry=\"60 +\" \n" +
"syncdata=accesslog" );
assertNotNull( syncRepl );
assertEquals( "0", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "ldapmaster.symas.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=replicator,dc=symas,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
assertEquals( "dc=symas,dc=com", syncRepl.getSearchBase() );
assertEquals( "cn=accesslog", syncRepl.getLogBase() );
assertEquals( "(&(objectClass=auditWriteObject)(reqResult=0))", syncRepl.getLogFilter() );
assertEquals( SchemaChecking.ON, syncRepl.getSchemaChecking() );
assertEquals( Type.REFRESH_AND_PERSIST, syncRepl.getType() );
Retry retry = syncRepl.getRetry();
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair retryPair = retry.getPairs()[0];
assertNotNull( retryPair );
assertEquals( 60, retryPair.getInterval() );
assertEquals( RetryPair.PLUS, retryPair.getRetries() );
assertEquals( SyncData.ACCESSLOG, syncRepl.getSyncData() );
}
@Test
public void testSymasDoc1WithoutSpacesMultilines() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=0\n" +
"provider=ldap://ldapmaster.symas.com:389\n" +
"bindmethod=simple\n" +
"binddn=\"cn=replicator,dc=symas,dc=com\"\n" +
"credentials=secret\n" +
"searchbase=\"dc=symas,dc=com\"\n" +
"logbase=\"cn=accesslog\"\n" +
"logfilter=\"(&(objectClass=auditWriteObject)(reqResult=0))\"\n" +
"schemachecking=on\n" +
"type=refreshAndPersist\n" +
"retry=\"60 +\"\n" +
"syncdata=accesslog" );
assertNotNull( syncRepl );
assertEquals( "0", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "ldapmaster.symas.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=replicator,dc=symas,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
assertEquals( "dc=symas,dc=com", syncRepl.getSearchBase() );
assertEquals( "cn=accesslog", syncRepl.getLogBase() );
assertEquals( "(&(objectClass=auditWriteObject)(reqResult=0))", syncRepl.getLogFilter() );
assertEquals( SchemaChecking.ON, syncRepl.getSchemaChecking() );
assertEquals( Type.REFRESH_AND_PERSIST, syncRepl.getType() );
Retry retry = syncRepl.getRetry();
assertNotNull( retry );
assertEquals( 1, retry.size() );
RetryPair retryPair = retry.getPairs()[0];
assertNotNull( retryPair );
assertEquals( 60, retryPair.getInterval() );
assertEquals( RetryPair.PLUS, retryPair.getRetries() );
assertEquals( SyncData.ACCESSLOG, syncRepl.getSyncData() );
}
@Test
public void testSymasDoc2SingleLine() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=001\n provider=ldaps://ldapmaster.symas.com:389 binddn=\"cn=config\" bindmethod=simple credentials=secret searchbase=\"cn=config\" type=refreshAndPersist retry=\"5 5 300 5\" timeout=1" );
assertNotNull( syncRepl );
assertEquals( "001", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertTrue( provider.isLdaps() );
assertEquals( "ldapmaster.symas.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=config", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
assertEquals( "cn=config", syncRepl.getSearchBase() );
Retry retry = syncRepl.getRetry();
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair retryPair1 = retry.getPairs()[0];
assertNotNull( retryPair1 );
assertEquals( 5, retryPair1.getInterval() );
assertEquals( 5, retryPair1.getRetries() );
RetryPair retryPair2 = retry.getPairs()[1];
assertNotNull( retryPair2 );
assertEquals( 300, retryPair2.getInterval() );
assertEquals( 5, retryPair2.getRetries() );
assertEquals( Type.REFRESH_AND_PERSIST, syncRepl.getType() );
assertEquals( 1, syncRepl.getTimeout() );
}
@Test
public void testSymasDoc2WithSpacesMultilines() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=001\n " +
"provider=ldaps://ldapmaster.symas.com:389\n " +
"binddn=\"cn=config\"\n " +
"bindmethod=simple\n " +
"credentials=secret\n " +
"searchbase=\"cn=config\"\n " +
"type=refreshAndPersist\n " +
"retry=\"5 5 300 5\"\n " +
"timeout=1" );
assertNotNull( syncRepl );
assertEquals( "001", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertTrue( provider.isLdaps() );
assertEquals( "ldapmaster.symas.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=config", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
assertEquals( "cn=config", syncRepl.getSearchBase() );
Retry retry = syncRepl.getRetry();
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair retryPair1 = retry.getPairs()[0];
assertNotNull( retryPair1 );
assertEquals( 5, retryPair1.getInterval() );
assertEquals( 5, retryPair1.getRetries() );
RetryPair retryPair2 = retry.getPairs()[1];
assertNotNull( retryPair2 );
assertEquals( 300, retryPair2.getInterval() );
assertEquals( 5, retryPair2.getRetries() );
assertEquals( Type.REFRESH_AND_PERSIST, syncRepl.getType() );
assertEquals( 1, syncRepl.getTimeout() );
}
@Test
public void testSymasDoc2WithoutSpacesMultilines() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=001\n" +
"provider=ldaps://ldapmaster.symas.com:389\n" +
"binddn=\"cn=config\"\n" +
"bindmethod=simple\n" +
"credentials=secret\n" +
"searchbase=\"cn=config\"\n" +
"type=refreshAndPersist\n" +
"retry=\"5 5 300 5\"\n" +
"timeout=1" );
assertNotNull( syncRepl );
assertEquals( "001", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertTrue( provider.isLdaps() );
assertEquals( "ldapmaster.symas.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=config", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
assertEquals( "cn=config", syncRepl.getSearchBase() );
Retry retry = syncRepl.getRetry();
assertNotNull( retry );
assertEquals( 2, retry.size() );
RetryPair retryPair1 = retry.getPairs()[0];
assertNotNull( retryPair1 );
assertEquals( 5, retryPair1.getInterval() );
assertEquals( 5, retryPair1.getRetries() );
RetryPair retryPair2 = retry.getPairs()[1];
assertNotNull( retryPair2 );
assertEquals( 300, retryPair2.getInterval() );
assertEquals( 5, retryPair2.getRetries() );
assertEquals( Type.REFRESH_AND_PERSIST, syncRepl.getType() );
assertEquals( 1, syncRepl.getTimeout() );
}
@Test
public void testSymasDoc3SingleLine() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=123 " +
"provider=ldap://provider.example.com:389 " +
"type=refreshOnly " +
"interval=01:00:00:00 " +
"searchbase=\"dc=example,dc=com\" " +
"filter=\"(objectClass=organizationalPerson)\" " +
"scope=sub " +
"attrs=\"cn,sn,ou,telephoneNumber,title,l\" " +
"schemachecking=off " +
"bindmethod=simple " +
"binddn=\"cn=syncuser,dc=example,dc=com\" " +
"credentials=secret" );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "provider.example.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( Type.REFRESH_ONLY, syncRepl.getType() );
Interval interval = syncRepl.getInterval();
assertNotNull( interval );
assertEquals( 1, interval.getDays() );
assertEquals( 0, interval.getHours() );
assertEquals( 0, interval.getMinutes() );
assertEquals( 0, interval.getSeconds() );
assertEquals( "dc=example,dc=com", syncRepl.getSearchBase() );
assertEquals( "(objectClass=organizationalPerson)", syncRepl.getFilter() );
assertEquals( Scope.SUB, syncRepl.getScope() );
String[] attributes = syncRepl.getAttributes();
assertNotNull( attributes );
assertEquals( 6, attributes.length );
assertEquals( "cn", attributes[0] );
assertEquals( "sn", attributes[1] );
assertEquals( "ou", attributes[2] );
assertEquals( "telephoneNumber", attributes[3] );
assertEquals( "title", attributes[4] );
assertEquals( "l", attributes[5] );
assertEquals( SchemaChecking.OFF, syncRepl.getSchemaChecking() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=syncuser,dc=example,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
}
@Test
public void testSymasDoc3WithoutSpacesMultilines() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=123\n" +
"provider=ldap://provider.example.com:389\n" +
"type=refreshOnly\n" +
"interval=01:00:00:00\n" +
"searchbase=\"dc=example,dc=com\"\n" +
"filter=\"(objectClass=organizationalPerson)\"\n" +
"scope=sub\n" +
"attrs=\"cn,sn,ou,telephoneNumber,title,l\"\n" +
"schemachecking=off\n" +
"bindmethod=simple\n" +
"binddn=\"cn=syncuser,dc=example,dc=com\"\n" +
"credentials=secret" );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "provider.example.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( Type.REFRESH_ONLY, syncRepl.getType() );
Interval interval = syncRepl.getInterval();
assertNotNull( interval );
assertEquals( 1, interval.getDays() );
assertEquals( 0, interval.getHours() );
assertEquals( 0, interval.getMinutes() );
assertEquals( 0, interval.getSeconds() );
assertEquals( "dc=example,dc=com", syncRepl.getSearchBase() );
assertEquals( "(objectClass=organizationalPerson)", syncRepl.getFilter() );
assertEquals( Scope.SUB, syncRepl.getScope() );
String[] attributes = syncRepl.getAttributes();
assertNotNull( attributes );
assertEquals( 6, attributes.length );
assertEquals( "cn", attributes[0] );
assertEquals( "sn", attributes[1] );
assertEquals( "ou", attributes[2] );
assertEquals( "telephoneNumber", attributes[3] );
assertEquals( "title", attributes[4] );
assertEquals( "l", attributes[5] );
assertEquals( SchemaChecking.OFF, syncRepl.getSchemaChecking() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=syncuser,dc=example,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
}
@Test
public void testSymasDoc3WithSpacesMultilines() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=123 \n" +
"provider=ldap://provider.example.com:389 \n" +
"type=refreshOnly \n" +
"interval=01:00:00:00 \n" +
"searchbase=\"dc=example,dc=com\" \n" +
"filter=\"(objectClass=organizationalPerson)\" \n" +
"scope=sub \n" +
"attrs=\"cn,sn,ou,telephoneNumber,title,l\" \n" +
"schemachecking=off \n" +
"bindmethod=simple \n" +
"binddn=\"cn=syncuser,dc=example,dc=com\" \n" +
"credentials=secret" );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "provider.example.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( Type.REFRESH_ONLY, syncRepl.getType() );
Interval interval = syncRepl.getInterval();
assertNotNull( interval );
assertEquals( 1, interval.getDays() );
assertEquals( 0, interval.getHours() );
assertEquals( 0, interval.getMinutes() );
assertEquals( 0, interval.getSeconds() );
assertEquals( "dc=example,dc=com", syncRepl.getSearchBase() );
assertEquals( "(objectClass=organizationalPerson)", syncRepl.getFilter() );
assertEquals( Scope.SUB, syncRepl.getScope() );
String[] attributes = syncRepl.getAttributes();
assertNotNull( attributes );
assertEquals( 6, attributes.length );
assertEquals( "cn", attributes[0] );
assertEquals( "sn", attributes[1] );
assertEquals( "ou", attributes[2] );
assertEquals( "telephoneNumber", attributes[3] );
assertEquals( "title", attributes[4] );
assertEquals( "l", attributes[5] );
assertEquals( SchemaChecking.OFF, syncRepl.getSchemaChecking() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=syncuser,dc=example,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
}
@Test
public void testSymasDoc3WithSpacesMultilinesAllQuoted() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=\"123\" \n" +
"provider=\"ldap://provider.example.com:389\" \n" +
"type=\"refreshOnly\" \n" +
"interval=\"01:00:00:00\" \n" +
"searchbase=\"dc=example,dc=com\" \n" +
"filter=\"(objectClass=organizationalPerson)\" \n" +
"scope=\"sub\" \n" +
"attrs=\"cn,sn,ou,telephoneNumber,title,l\" \n" +
"schemachecking=\"off\" \n" +
"bindmethod=\"simple\" \n" +
"binddn=\"cn=syncuser,dc=example,dc=com\" \n" +
"credentials=\"secret\"" );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "provider.example.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( Type.REFRESH_ONLY, syncRepl.getType() );
Interval interval = syncRepl.getInterval();
assertNotNull( interval );
assertEquals( 1, interval.getDays() );
assertEquals( 0, interval.getHours() );
assertEquals( 0, interval.getMinutes() );
assertEquals( 0, interval.getSeconds() );
assertEquals( "dc=example,dc=com", syncRepl.getSearchBase() );
assertEquals( "(objectClass=organizationalPerson)", syncRepl.getFilter() );
assertEquals( Scope.SUB, syncRepl.getScope() );
String[] attributes = syncRepl.getAttributes();
assertNotNull( attributes );
assertEquals( 6, attributes.length );
assertEquals( "cn", attributes[0] );
assertEquals( "sn", attributes[1] );
assertEquals( "ou", attributes[2] );
assertEquals( "telephoneNumber", attributes[3] );
assertEquals( "title", attributes[4] );
assertEquals( "l", attributes[5] );
assertEquals( SchemaChecking.OFF, syncRepl.getSchemaChecking() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=syncuser,dc=example,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
}
@Test
public void testSymasDoc3WithSpacesMultilinesAllNotQuoted() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser
.parse( "rid=123 \n" +
"provider=ldap://provider.example.com:389 \n" +
"type=refreshOnly \n" +
"interval=01:00:00:00 \n" +
"searchbase=dc=example,dc=com \n" +
"filter=(objectClass=organizationalPerson) \n" +
"scope=sub \n" +
"attrs=cn,sn,ou,telephoneNumber,title,l \n" +
"schemachecking=off \n" +
"bindmethod=simple \n" +
"binddn=cn=syncuser,dc=example,dc=com \n" +
"credentials=secret" );
assertNotNull( syncRepl );
assertEquals( "123", syncRepl.getRid() );
Provider provider = syncRepl.getProvider();
assertNotNull( provider );
assertFalse( provider.isLdaps() );
assertEquals( "provider.example.com", provider.getHost() );
assertEquals( 389, provider.getPort() );
assertEquals( Type.REFRESH_ONLY, syncRepl.getType() );
Interval interval = syncRepl.getInterval();
assertNotNull( interval );
assertEquals( 1, interval.getDays() );
assertEquals( 0, interval.getHours() );
assertEquals( 0, interval.getMinutes() );
assertEquals( 0, interval.getSeconds() );
assertEquals( "dc=example,dc=com", syncRepl.getSearchBase() );
assertEquals( "(objectClass=organizationalPerson)", syncRepl.getFilter() );
assertEquals( Scope.SUB, syncRepl.getScope() );
String[] attributes = syncRepl.getAttributes();
assertNotNull( attributes );
assertEquals( 6, attributes.length );
assertEquals( "cn", attributes[0] );
assertEquals( "sn", attributes[1] );
assertEquals( "ou", attributes[2] );
assertEquals( "telephoneNumber", attributes[3] );
assertEquals( "title", attributes[4] );
assertEquals( "l", attributes[5] );
assertEquals( SchemaChecking.OFF, syncRepl.getSchemaChecking() );
assertEquals( BindMethod.SIMPLE, syncRepl.getBindMethod() );
assertEquals( "cn=syncuser,dc=example,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
}
}
| 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.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/ProviderTest.java | plugins/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/ProviderTest.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.syncrepl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ProviderTest
{
@Test
public void testEmpty() throws Exception
{
try
{
Provider.parse( "" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete1() throws Exception
{
try
{
Provider.parse( "ldap" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete2() throws Exception
{
try
{
Provider.parse( "ldap:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete3() throws Exception
{
try
{
Provider.parse( "ldap://" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testOkLdapHost() throws Exception
{
Provider provider = Provider.parse( "ldap://localhost" );
assertEquals( false, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( Provider.NO_PORT, provider.getPort() );
assertEquals( "ldap://localhost", provider.toString() );
}
@Test
public void testOkLdapsHost() throws Exception
{
Provider provider = Provider.parse( "ldaps://localhost" );
assertEquals( true, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( Provider.NO_PORT, provider.getPort() );
assertEquals( "ldaps://localhost", provider.toString() );
}
@Test
public void testOkLdapHostPort() throws Exception
{
Provider provider = Provider.parse( "ldap://localhost:12345" );
assertEquals( false, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( 12345, provider.getPort() );
assertEquals( "ldap://localhost:12345", provider.toString() );
}
@Test
public void testOkLdapsHostPort() throws Exception
{
Provider provider = Provider.parse( "ldaps://localhost:12345" );
assertEquals( true, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( 12345, provider.getPort() );
assertEquals( "ldaps://localhost:12345", provider.toString() );
}
@Test
public void testOkUppercaseProtocolLdapHost() throws Exception
{
Provider provider = Provider.parse( "LDAP://localhost" );
assertEquals( false, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( Provider.NO_PORT, provider.getPort() );
assertEquals( "ldap://localhost", provider.toString() );
}
@Test
public void testOkUppercaseProtocolLdapsHost() throws Exception
{
Provider provider = Provider.parse( "LDAPS://localhost" );
assertEquals( true, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( Provider.NO_PORT, provider.getPort() );
assertEquals( "ldaps://localhost", provider.toString() );
}
@Test
public void testOkUppercaseProtocolLdapHostPort() throws Exception
{
Provider provider = Provider.parse( "LDAP://localhost:12345" );
assertEquals( false, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( 12345, provider.getPort() );
assertEquals( "ldap://localhost:12345", provider.toString() );
}
@Test
public void testOkUppercaseProtocolLdapsHostPort() throws Exception
{
Provider provider = Provider.parse( "LDAPS://localhost:12345" );
assertEquals( true, provider.isLdaps() );
assertEquals( "localhost", provider.getHost() );
assertEquals( 12345, provider.getPort() );
assertEquals( "ldaps://localhost:12345", provider.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/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/KeepAliveTest.java | plugins/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/KeepAliveTest.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.syncrepl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class KeepAliveTest
{
@Test
public void testEmpty() throws Exception
{
try
{
KeepAlive.parse( "" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete1() throws Exception
{
try
{
KeepAlive.parse( "12:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete3() throws Exception
{
try
{
KeepAlive.parse( "12:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete4() throws Exception
{
try
{
KeepAlive.parse( "12:34" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete5() throws Exception
{
try
{
KeepAlive.parse( "12:34:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testOk1() throws Exception
{
KeepAlive keepAlive = KeepAlive.parse( "1:2:3" );
assertEquals( 1, keepAlive.getIdle() );
assertEquals( 2, keepAlive.getProbes() );
assertEquals( 3, keepAlive.getInterval() );
assertEquals( "1:2:3", keepAlive.toString() );
}
@Test
public void testOk2() throws Exception
{
KeepAlive keepAlive = KeepAlive.parse( "12:34:56" );
assertEquals( 12, keepAlive.getIdle() );
assertEquals( 34, keepAlive.getProbes() );
assertEquals( 56, keepAlive.getInterval() );
assertEquals( "12:34:56", keepAlive.toString() );
}
@Test
public void testOk3() throws Exception
{
KeepAlive keepAlive = KeepAlive.parse( "123:456:789" );
assertEquals( 123, keepAlive.getIdle() );
assertEquals( 456, keepAlive.getProbes() );
assertEquals( 789, keepAlive.getInterval() );
assertEquals( "123:456:789", keepAlive.toString() );
}
@Test
public void testOk4() throws Exception
{
KeepAlive keepAlive = KeepAlive.parse( "1234:5678:9012" );
assertEquals( 1234, keepAlive.getIdle() );
assertEquals( 5678, keepAlive.getProbes() );
assertEquals( 9012, keepAlive.getInterval() );
assertEquals( "1234:5678:9012", keepAlive.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/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/IntervalTest.java | plugins/openldap.syncrepl/src/test/java/com/iktek/studio/openldap/syncrepl/IntervalTest.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.syncrepl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class IntervalTest
{
@Test
public void testEmpty() throws Exception
{
try
{
Interval.parse( "" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete1() throws Exception
{
try
{
Interval.parse( "12" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete3() throws Exception
{
try
{
Interval.parse( "12:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete4() throws Exception
{
try
{
Interval.parse( "12:34" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete5() throws Exception
{
try
{
Interval.parse( "12:34:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete6() throws Exception
{
try
{
Interval.parse( "12:34:56" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testIncomplete7() throws Exception
{
try
{
Interval.parse( "12:34:56:" );
fail();
}
catch ( Exception e )
{
// Should happen
}
}
@Test
public void testOk() throws Exception
{
Interval interval = Interval.parse( "12:34:56:78" );
assertEquals( 12, interval.getDays() );
assertEquals( 34, interval.getHours() );
assertEquals( 56, interval.getMinutes() );
assertEquals( 78, interval.getSeconds() );
assertEquals( "12:34:56:78", interval.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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncData.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncData.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the Sync Data value.
*/
public enum SyncData
{
/** The 'default' Sync Data value */
DEFAULT("default"),
/** The 'accesslog' Sync Data value */
ACCESSLOG("accesslog"),
/** The 'changelog' Sync Data value */
CHANGELOG("changelog");
/** The value */
private String value;
/**
* Parses a sync data string.
*
* @param s the string
* @return a sync data
* @throws ParseException if an error occurs during parsing
*/
public static SyncData parse( String s ) throws ParseException
{
// DEFAULT
if ( DEFAULT.value.equalsIgnoreCase( s ) )
{
return DEFAULT;
}
// ACCESSLOG
else if ( ACCESSLOG.value.equalsIgnoreCase( s ) )
{
return ACCESSLOG;
}
// CHANGELOG
else if ( CHANGELOG.value.equalsIgnoreCase( s ) )
{
return CHANGELOG;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid sync data.", 0 );
}
}
/**
* Creates a new instance of SyncData.
*
* @param value the value
*/
private SyncData( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Interval.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Interval.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.syncrepl;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class implements an interval.
* <p>
* Format: "dd:hh:mm:ss"
*/
public class Interval
{
/** The pattern used for parsing */
private static final Pattern pattern = Pattern.compile( "^([0-9]{2}):([0-9]{2}):([0-9]{2}):([0-9]{2})$" );
/** The days */
private int days;
/** The hours */
private int hours;
/** The minutes */
private int minutes;
/** The seconds */
private int seconds;
/**
* Creates a new instance of Interval.
*
*/
public Interval()
{
}
/**
* Creates a new instance of Interval.
*
* @param days the days
* @param hours the hours
* @param minutes the minutes
* @param seconds the seconds
*/
public Interval( int days, int hours, int minutes, int seconds )
{
this.days = days;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
/**
* Gets a copy of a Interval object.
*
* @param syncRepl the initial Interval object
* @return a copy of the given Interval object
*/
public static Interval copy( Interval interval )
{
if ( interval != null )
{
Interval intervalCopy = new Interval();
intervalCopy.setDays( interval.getDays() );
intervalCopy.setHours( interval.getHours() );
intervalCopy.setMinutes( interval.getMinutes() );
intervalCopy.setSeconds( interval.getSeconds() );
return intervalCopy;
}
return null;
}
/**
* Gets a copy of the Interval object.
*
* @return a copy of the Interval object
*/
public Interval copy()
{
return Interval.copy( this );
}
/**
* Parses an interval string.
*
* @param s the string
* @return an interval
* @throws ParseException if an error occurs during parsing
*/
public static Interval parse( String s ) throws ParseException
{
// Creating the interval
Interval interval = new Interval();
// Matching the string
Matcher matcher = pattern.matcher( s );
// Checking the result
if ( matcher.find() )
{
// Days
String days = matcher.group( 1 );
try
{
interval.setDays( Integer.parseInt( days ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert days value '" + days + "' as an integer.", 0 );
}
// Hours
String hours = matcher.group( 2 );
try
{
interval.setHours( Integer.parseInt( hours ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert hours value '" + hours + "' as an integer.", 0 );
}
// Minutes
String minutes = matcher.group( 3 );
try
{
interval.setMinutes( Integer.parseInt( minutes ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert minutes value '" + minutes + "' as an integer.", 0 );
}
// Seconds
String seconds = matcher.group( 4 );
try
{
interval.setSeconds( Integer.parseInt( seconds ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert seconds value '" + seconds + "' as an integer.", 0 );
}
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid interval.", 0 );
}
return interval;
}
public int getDays()
{
return days;
}
public int getHours()
{
return hours;
}
public int getMinutes()
{
return minutes;
}
public int getSeconds()
{
return seconds;
}
public void setDays( int days )
{
this.days = days;
}
public void setHours( int hours )
{
this.hours = hours;
}
public void setMinutes( int minutes )
{
this.minutes = minutes;
}
public void setSeconds( int seconds )
{
this.seconds = seconds;
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( intValToString( days ) );
sb.append( ":" );
sb.append( intValToString( hours ) );
sb.append( ":" );
sb.append( intValToString( minutes ) );
sb.append( ":" );
sb.append( intValToString( seconds ) );
return sb.toString();
}
/**
* Gets the string value for the given integer.
* <p>
* Makes sure the int is printed with two letters.
*
* @param val the integer
* @return the string value for the given integer
*/
private String intValToString( int val )
{
if ( val < 10 )
{
return "0" + val;
}
else
{
return "" + val;
}
}
}
| 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.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncRepl.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncRepl.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.syncrepl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* This class implements a SyncRepl object.
*/
public class SyncRepl
{
/** The replica ID */
private String rid;
/** The provider */
private Provider provider;
/** The search base */
private String searchBase;
/** The type */
private Type type;
/** The interval */
private Interval interval;
/** The retry */
private Retry retry;
/** The filter */
private String filter;
/** The scope */
private Scope scope;
/** The attributes */
private List<String> attributes = new ArrayList<String>();
/** The attrsonly flag */
private boolean isAttrsOnly;
/** The size limit */
private int sizeLimit = -1;
/** The time limit */
private int timeLimit = -1;
/** The schema checking */
private SchemaChecking schemaChecking;
/** The network timeout */
private int networkTimeout = -1;
/** The timeout */
private int timeout = -1;
/** The bind method */
private BindMethod bindMethod;
/** The bind dn */
private String bindDn;
/** The sasl mech */
private String saslMech;
/** The authentication id */
private String authcid;
/** The authorization id */
private String authzid;
/** The credentials */
private String credentials;
/** The realm */
private String realm;
/** The sec props */
private String secProps;
/** The keep alive */
private KeepAlive keepAlive;
/** The Start TLS */
private StartTls startTls;
/** The TLS cert */
private String tlsCert;
/** The TLS key */
private String tlsKey;
/** The TLS cacert */
private String tlsCacert;
/** The TLS cacert dir */
private String tlsCacertDir;
/** The TLS reqcert */
private TlsReqCert tlsReqcert;
/** The TLS cipher suite */
private String tlsCipherSuite;
/** The TLS crl check */
private TlsCrlCheck tlsCrlcheck;
/** The log base */
private String logBase;
/** The log filter */
private String logFilter;
/** The sync data */
private SyncData syncData;
public SyncRepl()
{
// TODO Auto-generated constructor stub
}
/**
* Creates a default SyncRepl value.
*
* @return a default SyncRepl value
*/
public static SyncRepl createDefault()
{
SyncRepl syncRepl = new SyncRepl();
return syncRepl;
}
/**
* Gets a copy of a SyncRepl object.
*
* @param syncRepl the initial SyncRepl object
* @return a copy of the given SyncRepl object
*/
public static SyncRepl copy( SyncRepl syncRepl )
{
if ( syncRepl != null )
{
SyncRepl syncReplCopy = new SyncRepl();
syncReplCopy.setRid( syncRepl.getRid() );
syncReplCopy.setProvider( Provider.copy( syncRepl.getProvider() ) );
syncReplCopy.setSearchBase( syncRepl.getSearchBase() );
syncReplCopy.setType( syncRepl.getType() );
syncReplCopy.setInterval( Interval.copy( syncRepl.getInterval() ) );
syncReplCopy.setRetry( Retry.copy( syncRepl.getRetry() ) );
syncReplCopy.setFilter( syncRepl.getFilter() );
syncReplCopy.setScope( syncRepl.getScope() );
syncReplCopy.addAttribute( syncRepl.getAttributes() );
syncReplCopy.setAttrsOnly( syncRepl.isAttrsOnly() );
syncReplCopy.setSizeLimit( syncRepl.getSizeLimit() );
syncReplCopy.setTimeLimit( syncRepl.getTimeLimit() );
syncReplCopy.setSchemaChecking( syncRepl.getSchemaChecking() );
syncReplCopy.setNetworkTimeout( syncRepl.getNetworkTimeout() );
syncReplCopy.setTimeout( syncRepl.getTimeout() );
syncReplCopy.setBindMethod( syncRepl.getBindMethod() );
syncReplCopy.setBindDn( syncRepl.getBindDn() );
syncReplCopy.setSaslMech( syncRepl.getSaslMech() );
syncReplCopy.setAuthcid( syncRepl.getAuthcid() );
syncReplCopy.setAuthzid( syncRepl.getAuthzid() );
syncReplCopy.setCredentials( syncRepl.getCredentials() );
syncReplCopy.setRealm( syncRepl.getRealm() );
syncReplCopy.setSecProps( syncRepl.getSecProps() );
syncReplCopy.setKeepAlive( KeepAlive.copy( syncRepl.getKeepAlive() ) );
syncReplCopy.setStartTls( syncRepl.getStartTls() );
syncReplCopy.setTlsCert( syncRepl.getTlsCert() );
syncReplCopy.setTlsKey( syncRepl.getTlsKey() );
syncReplCopy.setTlsCacert( syncRepl.getTlsCacert() );
syncReplCopy.setTlsCacertDir( syncRepl.getTlsCacertDir() );
syncReplCopy.setTlsReqcert( syncRepl.getTlsReqcert() );
syncReplCopy.setTlsCipherSuite( syncRepl.getTlsCipherSuite() );
syncReplCopy.setTlsCrlcheck( syncRepl.getTlsCrlcheck() );
syncReplCopy.setLogBase( syncRepl.getLogBase() );
syncReplCopy.setLogFilter( syncRepl.getLogFilter() );
syncReplCopy.setSyncData( syncRepl.getSyncData() );
return syncReplCopy;
}
return null;
}
/**
* Gets a copy of the SyncRepl object.
*
* @return a copy of the SyncRepl object
*/
public SyncRepl copy()
{
return SyncRepl.copy( this );
}
public String getRid()
{
return rid;
}
public String getSearchBase()
{
return searchBase;
}
public Type getType()
{
return type;
}
public Interval getInterval()
{
return interval;
}
public Retry getRetry()
{
return retry;
}
public String getFilter()
{
return filter;
}
public Scope getScope()
{
return scope;
}
public String[] getAttributes()
{
return attributes.toArray( new String[0] );
}
public boolean isAttrsOnly()
{
return isAttrsOnly;
}
public int getSizeLimit()
{
return sizeLimit;
}
public int getTimeLimit()
{
return timeLimit;
}
public SchemaChecking getSchemaChecking()
{
return schemaChecking;
}
public int getNetworkTimeout()
{
return networkTimeout;
}
public int getTimeout()
{
return timeout;
}
public BindMethod getBindMethod()
{
return bindMethod;
}
public String getBindDn()
{
return bindDn;
}
public String getSaslMech()
{
return saslMech;
}
public String getAuthcid()
{
return authcid;
}
public String getAuthzid()
{
return authzid;
}
public String getCredentials()
{
return credentials;
}
public String getRealm()
{
return realm;
}
public String getSecProps()
{
return secProps;
}
public KeepAlive getKeepAlive()
{
return keepAlive;
}
public StartTls getStartTls()
{
return startTls;
}
public String getTlsCert()
{
return tlsCert;
}
public String getTlsKey()
{
return tlsKey;
}
public String getTlsCacert()
{
return tlsCacert;
}
public String getTlsCacertDir()
{
return tlsCacertDir;
}
public TlsReqCert getTlsReqcert()
{
return tlsReqcert;
}
public String getTlsCipherSuite()
{
return tlsCipherSuite;
}
public TlsCrlCheck getTlsCrlcheck()
{
return tlsCrlcheck;
}
public String getLogBase()
{
return logBase;
}
public String getLogFilter()
{
return logFilter;
}
public SyncData getSyncData()
{
return syncData;
}
public void setRid( String rid )
{
this.rid = rid;
}
public Provider getProvider()
{
return provider;
}
public void setProvider( Provider provider )
{
this.provider = provider;
}
public void setSearchBase( String searchBase )
{
this.searchBase = searchBase;
}
public void setType( Type type )
{
this.type = type;
}
public void setInterval( Interval interval )
{
this.interval = interval;
}
public void setRetry( Retry retry )
{
this.retry = retry;
}
public void setFilter( String filter )
{
this.filter = filter;
}
public void setScope( Scope scope )
{
this.scope = scope;
}
public void addAttribute( String... attributes )
{
if ( attributes != null )
{
for ( String attribute : attributes )
{
this.attributes.add( attribute );
}
}
}
public void removeAttribute( String... attributes )
{
if ( attributes != null )
{
for ( String attribute : attributes )
{
this.attributes.remove( attribute );
}
}
}
public void setAttributes( String[] attributes )
{
this.attributes.clear();
this.attributes.addAll( Arrays.asList( attributes ) );
}
public void setAttrsOnly( boolean isAttrsOnly )
{
this.isAttrsOnly = isAttrsOnly;
}
public void setSizeLimit( int sizeLimit )
{
this.sizeLimit = sizeLimit;
}
public void setTimeLimit( int timeLimit )
{
this.timeLimit = timeLimit;
}
public void setSchemaChecking( SchemaChecking schemaChecking )
{
this.schemaChecking = schemaChecking;
}
public void setNetworkTimeout( int networkTimeout )
{
this.networkTimeout = networkTimeout;
}
public void setTimeout( int timeout )
{
this.timeout = timeout;
}
public void setBindMethod( BindMethod bindMethod )
{
this.bindMethod = bindMethod;
}
public void setBindDn( String bindDn )
{
this.bindDn = bindDn;
}
public void setSaslMech( String saslMech )
{
this.saslMech = saslMech;
}
public void setAuthcid( String authcid )
{
this.authcid = authcid;
}
public void setAuthzid( String authzid )
{
this.authzid = authzid;
}
public void setCredentials( String credentials )
{
this.credentials = credentials;
}
public void setRealm( String realm )
{
this.realm = realm;
}
public void setSecProps( String secProps )
{
this.secProps = secProps;
}
public void setKeepAlive( KeepAlive keepAlive )
{
this.keepAlive = keepAlive;
}
public void setStartTls( StartTls startTls )
{
this.startTls = startTls;
}
public void setTlsCert( String tlsCert )
{
this.tlsCert = tlsCert;
}
public void setTlsKey( String tlsKey )
{
this.tlsKey = tlsKey;
}
public void setTlsCacert( String tlsCacert )
{
this.tlsCacert = tlsCacert;
}
public void setTlsCacertDir( String tlsCacertDir )
{
this.tlsCacertDir = tlsCacertDir;
}
public void setTlsReqcert( TlsReqCert tlsReqcert )
{
this.tlsReqcert = tlsReqcert;
}
public void setTlsCipherSuite( String tlsCipherSuite )
{
this.tlsCipherSuite = tlsCipherSuite;
}
public void setTlsCrlcheck( TlsCrlCheck tlsCrlcheck )
{
this.tlsCrlcheck = tlsCrlcheck;
}
public void setLogBase( String logBase )
{
this.logBase = logBase;
}
public void setLogFilter( String logFilter )
{
this.logFilter = logFilter;
}
public void setSyncData( SyncData syncData )
{
this.syncData = syncData;
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
// Replica ID
if ( rid != null )
{
sb.append( "rid=" );
sb.append( rid );
}
// Provider
if ( provider != null )
{
appendSpaceIfNeeded( sb );
sb.append( "provider=" );
sb.append( provider.toString() );
}
// Search Base
if ( searchBase != null )
{
appendSpaceIfNeeded( sb );
sb.append( "searchbase=" );
sb.append( '"' );
sb.append( escapeDoubleQuotes( searchBase ) );
sb.append( '"' );
}
// Type
if ( type != null )
{
appendSpaceIfNeeded( sb );
sb.append( "type=" );
sb.append( type );
}
// Interval
if ( interval != null )
{
appendSpaceIfNeeded( sb );
sb.append( "interval=" );
sb.append( interval );
}
// Retry
if ( retry != null )
{
appendSpaceIfNeeded( sb );
sb.append( "retry=" );
sb.append( '"' );
sb.append( escapeDoubleQuotes( retry.toString() ) );
sb.append( '"' );
}
// Filter
if ( filter != null )
{
appendSpaceIfNeeded( sb );
sb.append( "filter=" );
sb.append( '"' );
sb.append( escapeDoubleQuotes( filter ) );
sb.append( '"' );
}
// Scope
if ( scope != null )
{
appendSpaceIfNeeded( sb );
sb.append( "scope=" );
sb.append( scope );
}
// Attributes
if ( ( attributes != null ) && ( attributes.size() > 0 ) )
{
appendSpaceIfNeeded( sb );
sb.append( "attrs=" );
sb.append( '"' );
// Looping on all attributes
for ( int i = 0; i < attributes.size(); i++ )
{
// Adding the attribute
sb.append( attributes.get( i ) );
// Adding the separator (except for the last one)
if ( i != attributes.size() - 1 )
{
sb.append( ',' );
}
}
sb.append( '"' );
}
// Attrsonly Flag
if ( isAttrsOnly )
{
appendSpaceIfNeeded( sb );
sb.append( "attrsonly" );
}
// Size Limit
if ( sizeLimit != -1 )
{
appendSpaceIfNeeded( sb );
sb.append( "sizelimit=" );
sb.append( sizeLimit );
}
// Time Limit
if ( timeLimit != -1 )
{
appendSpaceIfNeeded( sb );
sb.append( "timelimit=" );
sb.append( timeLimit );
}
// Schema Checking
if ( schemaChecking != null )
{
appendSpaceIfNeeded( sb );
sb.append( "schemachecking=" );
sb.append( schemaChecking );
}
// Network Timeout
if ( networkTimeout != -1 )
{
appendSpaceIfNeeded( sb );
sb.append( "network-timeout=" );
sb.append( networkTimeout );
}
// Timeout
if ( timeout != -1 )
{
appendSpaceIfNeeded( sb );
sb.append( "timeout=" );
sb.append( timeout );
}
// Bind Method
if ( bindMethod != null )
{
appendSpaceIfNeeded( sb );
sb.append( "bindmethod=" );
sb.append( bindMethod );
}
// Bind DN
if ( bindDn != null )
{
appendSpaceIfNeeded( sb );
sb.append( "binddn=" );
sb.append( '"' );
sb.append( bindDn );
sb.append( '"' );
}
// SASL Mech
if ( saslMech != null )
{
appendSpaceIfNeeded( sb );
sb.append( "saslmech=" );
sb.append( saslMech );
}
// Authentication ID
if ( authcid != null )
{
appendSpaceIfNeeded( sb );
sb.append( "authcid=" );
sb.append( '"' );
sb.append( authcid );
sb.append( '"' );
}
// Authorization ID
if ( authzid != null )
{
appendSpaceIfNeeded( sb );
sb.append( "authzid=" );
sb.append( '"' );
sb.append( authzid );
sb.append( '"' );
}
// Credentials
if ( credentials != null )
{
appendSpaceIfNeeded( sb );
sb.append( "credentials=" );
sb.append( credentials );
}
// Realm
if ( realm != null )
{
appendSpaceIfNeeded( sb );
sb.append( "realm=" );
sb.append( realm );
}
// Sec Props
if ( secProps != null )
{
appendSpaceIfNeeded( sb );
sb.append( "secProps=" );
sb.append( secProps );
}
// Keep Alive
if ( keepAlive != null )
{
appendSpaceIfNeeded( sb );
sb.append( "keepalive=" );
sb.append( keepAlive );
}
// Start TLS
if ( startTls != null )
{
appendSpaceIfNeeded( sb );
sb.append( "starttls=" );
sb.append( startTls );
}
// TLS Cert
if ( tlsCert != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_cert=" );
sb.append( tlsCert );
}
// TLS Key
if ( tlsKey != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_key=" );
sb.append( tlsKey );
}
// TLS Cacert
if ( tlsCacert != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_cacert=" );
sb.append( tlsCacert );
}
// TLS Cacert Dir
if ( tlsCacertDir != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_cacertdir=" );
sb.append( tlsCacertDir );
}
// TLS Reqcert
if ( tlsReqcert != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_reqcert=" );
sb.append( tlsReqcert );
}
// TLS Cipher Suite
if ( tlsCipherSuite != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_ciphersuite=" );
sb.append( tlsCipherSuite );
}
// TLS Crl Check
if ( tlsCrlcheck != null )
{
appendSpaceIfNeeded( sb );
sb.append( "tls_crlcheck=" );
sb.append( tlsCrlcheck );
}
// Log Base
if ( logBase != null )
{
appendSpaceIfNeeded( sb );
sb.append( "logbase=" );
sb.append( '"' );
sb.append( escapeDoubleQuotes( logBase ) );
sb.append( '"' );
}
// Log Filter
if ( logFilter != null )
{
appendSpaceIfNeeded( sb );
sb.append( "logfilter=" );
sb.append( '"' );
sb.append( escapeDoubleQuotes( logFilter ) );
sb.append( '"' );
}
// Sync Data
if ( syncData != null )
{
appendSpaceIfNeeded( sb );
sb.append( "syncdata=" );
sb.append( syncData );
}
return sb.toString();
}
/**
* Appends a space if the string is not empty.
*
* @param sb the string
*/
private void appendSpaceIfNeeded( StringBuilder sb )
{
if ( ( sb != null ) && ( sb.length() > 0 ) )
{
sb.append( " " );
}
}
/**
* Escapes all double quotes (") found in the given text.
*
* @param text the text
* @return a string where all double quotes are escaped
*/
private String escapeDoubleQuotes( String text )
{
if ( text != null )
{
return text.replace( "\"", "\\\"" );
}
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.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Type.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Type.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the replication type value.
*/
public enum Type
{
/** The 'refreshOnly' type value */
REFRESH_ONLY("refreshOnly"),
/** The 'refreshAndPersist' type value */
REFRESH_AND_PERSIST("refreshAndPersist");
/** The value */
private String value;
/**
* Parses a type string.
*
* @param s the string
* @return a type
* @throws ParseException if an error occurs during parsing
*/
public static Type parse( String s ) throws ParseException
{
// REFRESH_ONLY
if ( REFRESH_ONLY.value.equalsIgnoreCase( s ) )
{
return REFRESH_ONLY;
}
// REFRESH_AND_PERSIST
else if ( REFRESH_AND_PERSIST.value.equalsIgnoreCase( s ) )
{
return REFRESH_AND_PERSIST;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid type.", 0 );
}
}
/**
* Creates a new instance of Type.
*
* @param value the value
*/
private Type( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/KeepAlive.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/KeepAlive.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.syncrepl;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class implements a keep alive.
* <p>
* Format: "<idle>:<probes>:<interval>"
*/
public class KeepAlive
{
/** The pattern used for parsing */
private static final Pattern pattern = Pattern.compile( "^([0-9]+):([0-9]+):([0-9]+)$" );
/** The idle */
private int idle;
/** The probes */
private int probes;
/** The interval */
private int interval;
/**
* Creates a new instance of KeepAlive.
*/
public KeepAlive()
{
}
/**
* Creates a new instance of KeepAlive.
*
* @param idle the idle
* @param probes the probes
* @param interval the interval
*/
public KeepAlive( int idle, int probes, int interval )
{
this.idle = idle;
this.probes = probes;
this.interval = interval;
}
/**
* Gets a copy of a KeepAlive object.
*
* @param syncRepl the initial KeepAlive object
* @return a copy of the given KeepAlive object
*/
public static KeepAlive copy( KeepAlive keepAlive )
{
if ( keepAlive != null )
{
KeepAlive keepAliveCopy = new KeepAlive();
keepAliveCopy.setIdle( keepAlive.getIdle() );
keepAliveCopy.setProbes( keepAlive.getProbes() );
keepAliveCopy.setInterval( keepAlive.getInterval() );
return keepAliveCopy;
}
return null;
}
/**
* Gets a copy of the KeepAlive object.
*
* @return a copy of the KeepAlive object
*/
public KeepAlive copy()
{
return KeepAlive.copy( this );
}
/**
* Parses a keep alive string.
*
* @param s the string
* @return a keep alive
* @throws ParseException if an error occurs during parsing
*/
public static KeepAlive parse( String s ) throws ParseException
{
// Creating the keep alive
KeepAlive keepAlive = new KeepAlive();
// Matching the string
Matcher matcher = pattern.matcher( s );
// Checking the result
if ( matcher.find() )
{
// Idle
String idle = matcher.group( 1 );
try
{
keepAlive.setIdle( Integer.parseInt( idle ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert idle value '" + idle + "' as an integer.", 0 );
}
// Probes
String probes = matcher.group( 2 );
try
{
keepAlive.setProbes( Integer.parseInt( probes ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert probes value '" + probes + "' as an integer.", 0 );
}
// Interval
String interval = matcher.group( 3 );
try
{
keepAlive.setInterval( Integer.parseInt( interval ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert interval value '" + interval + "' as an integer.", 0 );
}
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid keep alive.", 0 );
}
return keepAlive;
}
public int getIdle()
{
return idle;
}
public int getProbes()
{
return probes;
}
public int getInterval()
{
return interval;
}
public void setIdle( int idle )
{
this.idle = idle;
}
public void setProbes( int probes )
{
this.probes = probes;
}
public void setInterval( int interval )
{
this.interval = interval;
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( idle );
sb.append( ":" );
sb.append( probes );
sb.append( ":" );
sb.append( interval );
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/TlsCrlCheck.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/TlsCrlCheck.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the TLS CRL Check value.
*/
public enum TlsCrlCheck
{
/** The 'none' TLS CRL Check value */
NONE("none"),
/** The 'peer' TLS CRL Check value */
PEER("peer"),
/** The 'all' TLS CRL Check value */
ALL("all");
/** The value */
private String value;
/**
* Parses a tls crl check string.
*
* @param s the string
* @return a tls crl check
* @throws ParseException if an error occurs during parsing
*/
public static TlsCrlCheck parse( String s ) throws ParseException
{
// NONE
if ( NONE.value.equalsIgnoreCase( s ) )
{
return NONE;
}
// PEER
else if ( PEER.value.equalsIgnoreCase( s ) )
{
return PEER;
}
// ALL
else if ( ALL.value.equalsIgnoreCase( s ) )
{
return ALL;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid tls crl check method.", 0 );
}
}
/**
* Creates a new instance of TlsCrlCheck.
*
* @param value the value
*/
private TlsCrlCheck( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SchemaChecking.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SchemaChecking.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the schema checking value.
*/
public enum SchemaChecking
{
/** The 'on' schema checking value */
ON("on"),
/** The 'off' schema checking value */
OFF("off");
/** The value */
private String value;
/**
* Parses a schema checking string.
*
* @param s the string
* @return a schema checking
* @throws ParseException if an error occurs during parsing
*/
public static SchemaChecking parse( String s ) throws ParseException
{
// ON
if ( ON.value.equalsIgnoreCase( s ) )
{
return ON;
}
// OFF
else if ( OFF.value.equalsIgnoreCase( s ) )
{
return OFF;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid schema checking.", 0 );
}
}
/**
* Creates a new instance of SchemaChecking.
*
* @param value the value
*/
private SchemaChecking( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/BindMethod.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/BindMethod.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the bind method value.
*/
public enum BindMethod
{
/** The 'simple' bind method value */
SIMPLE("simple"),
/** The 'sash' bind method value */
SASL("sasl");
/** The value */
private String value;
/**
* Parses a bind method string.
*
* @param s the string
* @return a bind method
* @throws ParseException if an error occurs during parsing
*/
public static BindMethod parse( String s ) throws ParseException
{
// SIMPLE
if ( SIMPLE.value.equalsIgnoreCase( s ) )
{
return SIMPLE;
}
// SASL
else if ( SASL.value.equalsIgnoreCase( s ) )
{
return SASL;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid bind method.", 0 );
}
}
/**
* Creates a new instance of BindMethod.
*
* @param value the value
*/
private BindMethod( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SaslMechanism.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SaslMechanism.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the SASL mechanism value.
*/
public enum SaslMechanism
{
/** The 'digest-md5' SASL mechanism */
DIGEST_MD5("DIGEST-MD5", "digest-md5"),
/** The 'gssapi' SASL mechanism */
GSSAPI("GSSAPI", "gssapi"), ;
/** The title */
private String title;
/** The value */
private String value;
/**
* Parses a sasl mechanism string.
*
* @param s the string
* @return a sasl mechanism
* @throws ParseException if an error occurs during parsing
*/
public static SaslMechanism parse( String s ) throws ParseException
{
// DIGEST_MD5
if ( DIGEST_MD5.value.equalsIgnoreCase( s ) )
{
return DIGEST_MD5;
}
// GSSAPI
else if ( GSSAPI.value.equalsIgnoreCase( s ) )
{
return GSSAPI;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid sasl mechanism method.", 0 );
}
}
/**
* Creates a new instance of SaslMechanism.
*
* @param value the value
*/
private SaslMechanism( String title, String value )
{
this.title = title;
this.value = value;
}
/**
* Gets the title.
*
* @return the title
*/
public String getTitle()
{
return title;
}
/**
* Gets the value.
*
* @return the value
*/
public String getValue()
{
return value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
return title;
}
}
| 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.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncReplParserException.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncReplParserException.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.syncrepl;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
* This class implements the SyncRepl Parser Exception.
* <p>
* It is used to store all exceptions raised during the parsing of a SyncRepl value.
*/
public class SyncReplParserException extends Exception
{
private static final long serialVersionUID = 1L;
/** The list of exceptions*/
private List<ParseException> exceptions = new ArrayList<ParseException>();
/**
* Creates a new instance of SyncReplParserException.
*/
public SyncReplParserException()
{
super();
}
/**
* Adds one or more {@link ParseException}.
*
* @param parseExceptions one or more {@link ParseException}
*/
public void addParseException( ParseException... parseExceptions )
{
if ( parseExceptions != null )
{
for ( ParseException parseException : parseExceptions )
{
exceptions.add( parseException );
}
}
}
/**
* Gets the number of {@link ParseException} stored.
*
* @return the number of {@link ParseException} stored
*/
public int size()
{
return exceptions.size();
}
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( '[' );
for ( int i = 0; i < exceptions.size(); i++ )
{
sb.append( exceptions.get( i ).toString() );
if ( i != ( exceptions.size() - 1 ) )
{
sb.append( ", " );
}
}
sb.append( ']' );
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/RetryPair.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/RetryPair.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.syncrepl;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class implements a retry pair.
* <p>
* Format: "<retry interval> <# of retries>"
*/
public class RetryPair
{
/** The '+' retries value */
public static final int PLUS = -1;
/** The pattern used for parsing */
private static final Pattern pattern = Pattern.compile( "^([0-9]+) ([0-9]+|\\+)$" );
/** The interval */
private int interval;
/** The retries */
private int retries;
/**
* Gets a copy of a RetryPair object.
*
* @param syncRepl the initial RetryPair object
* @return a copy of the given RetryPair object
*/
public static RetryPair copy( RetryPair retryPair )
{
if ( retryPair != null )
{
RetryPair retryPairCopy = new RetryPair();
retryPairCopy.setInterval( retryPair.getInterval() );
retryPairCopy.setRetries( retryPair.getRetries() );
return retryPairCopy;
}
return null;
}
/**
* Gets a copy of the RetryPair object.
*
* @return a copy of the RetryPair object
*/
public RetryPair copy()
{
return RetryPair.copy( this );
}
/**
* Parses a retry pair string.
*
* @param s the string
* @return a retry pair
* @throws ParseException if an error occurs during parsing
*/
public static RetryPair parse( String s ) throws ParseException
{
// Creating the retry pair
RetryPair retryPair = new RetryPair();
// Matching the string
Matcher matcher = pattern.matcher( s );
// Checking the result
if ( matcher.find() )
{
// Interval
String interval = matcher.group( 1 );
try
{
retryPair.setInterval( Integer.parseInt( interval ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert interval value '" + interval + "' as an integer.", 0 );
}
// Retries
String retries = matcher.group( 2 );
if ( "+".equalsIgnoreCase( retries ) )
{
retryPair.setRetries( PLUS );
}
else
{
try
{
retryPair.setRetries( Integer.parseInt( retries ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert retries value '" + retries + "' as an integer.", 0 );
}
}
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid retry pair.", 0 );
}
return retryPair;
}
public int getInterval()
{
return interval;
}
public int getRetries()
{
return retries;
}
public void setInterval( int interval )
{
this.interval = interval;
}
public void setRetries( int retries )
{
this.retries = retries;
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( interval );
sb.append( " " );
if ( retries == PLUS )
{
sb.append( "+" );
}
else
{
sb.append( retries );
}
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Provider.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Provider.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.syncrepl;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.directory.api.util.Strings;
/**
* This class implements a provider.
* <p>
* Format: "ldap[s]://<hostname>[:port]"
*/
public class Provider
{
/** Constant used as port value when no port is provided */
public static final int NO_PORT = -1;
/** The pattern used for parsing */
private static final Pattern pattern = Pattern
.compile( "^[l|L][d|D][a|A][p|P]([s|S]?)://([^:]+)([:]([0-9]{1,5}))?$" );
/** The LDAPS flag */
private boolean isLdaps;
/** The host */
private String host;
/** The port */
private int port = NO_PORT;
/**
* Creates a new instance of Provider.
*/
public Provider()
{
// TODO Auto-generated constructor stub
}
/**
* Creates a new instance of Provider.
*
* @param isLdaps the LDAPS flag
* @param host the host
* @param port the port
*/
public Provider( boolean isLdaps, String host, int port )
{
this.isLdaps = isLdaps;
this.host = host;
this.port = port;
}
/**
* Gets a copy of a Provider object.
*
* @param provier the initial Provider object
* @return a copy of the given Provider object
*/
public static Provider copy( Provider provider )
{
if ( provider != null )
{
Provider providerCopy = new Provider();
providerCopy.setHost( provider.getHost() );
providerCopy.setPort( provider.getPort() );
providerCopy.setLdaps( provider.isLdaps() );
return providerCopy;
}
return null;
}
/**
* Gets a copy of the Provider object.
*
* @return a copy of the Provider object
*/
public Provider copy()
{
return Provider.copy( this );
}
/**
* Parses a provider string.
*
* @param s the string
* @return a provider
* @throws ParseException if an error occurs during parsing
*/
public static Provider parse( String s ) throws ParseException
{
// Creating the provider
Provider provider = new Provider();
// Matching the string
Matcher matcher = pattern.matcher( s );
// Checking the result
if ( matcher.find() )
{
// LDAPS
provider.setLdaps( "s".equalsIgnoreCase( matcher.group( 1 ) ) );
// Host
String host = matcher.group( 2 );
if ( !Strings.isEmpty( host ) )
{
provider.setHost( host );
}
// Port
String port = matcher.group( 4 );
if ( !Strings.isEmpty( port ) )
{
try
{
provider.setPort( Integer.parseInt( port ) );
}
catch ( NumberFormatException e )
{
throw new ParseException( "Unable to convert port value '" + port + "' as an integer.", 0 );
}
}
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid provider.", 0 );
}
return provider;
}
public boolean isLdaps()
{
return isLdaps;
}
public String getHost()
{
return host;
}
public int getPort()
{
return port;
}
public void setLdaps( boolean isLdaps )
{
this.isLdaps = isLdaps;
}
public void setHost( String host )
{
this.host = host;
}
public void setPort( int port )
{
this.port = port;
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( "ldap" );
if ( isLdaps )
{
sb.append( "s" );
}
sb.append( "://" );
sb.append( host );
if ( port != NO_PORT )
{
sb.append( ":" );
sb.append( port );
}
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncReplParser.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/SyncReplParser.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.syncrepl;
import java.text.ParseException;
import org.apache.directory.api.util.Position;
import org.apache.directory.api.util.Strings;
/**
* A parser of SyncRepl value.
*/
public class SyncReplParser
{
private static final String KEYWORD_RID = "rid";
private static final String KEYWORD_PROVIDER = "provider";
private static final String KEYWORD_SEARCHBASE = "searchbase";
private static final String KEYWORD_TYPE = "type";
private static final String KEYWORD_INTERVAL = "interval";
private static final String KEYWORD_RETRY = "retry";
private static final String KEYWORD_FILTER = "filter";
private static final String KEYWORD_SCOPE = "scope";
private static final String KEYWORD_ATTRS = "attrs";
private static final String KEYWORD_ATTRSONLY = "attrsonly";
private static final String KEYWORD_SIZELIMIT = "sizelimit";
private static final String KEYWORD_TIMELIMIT = "timelimit";
private static final String KEYWORD_SCHEMACHECKING = "schemachecking";
private static final String KEYWORD_NETWORK_TIMEOUT = "network-timeout";
private static final String KEYWORD_TIMEOUT = "timeout";
private static final String KEYWORD_BINDMETHOD = "bindmethod";
private static final String KEYWORD_BINDDN = "binddn";
private static final String KEYWORD_SASLMECH = "saslmech";
private static final String KEYWORD_AUTHCID = "authcid";
private static final String KEYWORD_AUTHZID = "authzid";
private static final String KEYWORD_CREDENTIALS = "credentials";
private static final String KEYWORD_REALM = "realm";
private static final String KEYWORD_SECPROPS = "secprops";
private static final String KEYWORD_KEEPALIVE = "keepalive";
private static final String KEYWORD_STARTTLS = "starttls";
private static final String KEYWORD_TLS_CERT = "tls_cert";
private static final String KEYWORD_TLS_KEY = "tls_key";
private static final String KEYWORD_TLS_CACERT = "tls_cacert";
private static final String KEYWORD_TLS_CACERTDIR = "tls_cacertdir";
private static final String KEYWORD_TLS_REQCERT = "tls_reqcert";
private static final String KEYWORD_TLS_CIPHERSUITE = "tls_ciphersuite";
private static final String KEYWORD_TLS_CRLCHECK = "tls_crlcheck";
private static final String KEYWORD_LOGBASE = "logbase";
private static final String KEYWORD_LOGFILTER = "logfilter";
private static final String KEYWORD_SYNCDATA = "syncdata";
/**
* Parses a SyncRepl value.
*
* @param s
* the string to be parsed
* @return the associated SyncRepl object
* @throws SyncReplParserException
* if there are any recognition errors (bad syntax)
*/
public synchronized SyncRepl parse( String s ) throws SyncReplParserException
{
SyncReplParserException parserException = new SyncReplParserException();
// Trimming the value
s = Strings.trim( s );
// Getting the chars of the string
char[] chars = new char[s.length()];
s.getChars( 0, s.length(), chars, 0 );
// Creating the position
Position pos = new Position();
pos.start = 0;
pos.end = 0;
pos.length = chars.length;
SyncRepl syncRepl = parseInternal( chars, pos, parserException );
if ( parserException.size() > 0 )
{
throw parserException;
}
return syncRepl;
}
private SyncRepl parseInternal( char[] chars, Position pos, SyncReplParserException parserException )
{
SyncRepl syncRepl = new SyncRepl();
boolean foundAtLeastOneProperty = false;
char c = Strings.charAt( chars, pos.start );
do
{
// Whitespace
if ( Character.isWhitespace( c ) )
{
// We ignore all whitespaces
pos.start++;
}
// rid
else if ( Strings.areEquals( chars, pos.start, KEYWORD_RID, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_RID.length();
parseRid( chars, pos, syncRepl, parserException );
}
// provider
else if ( Strings.areEquals( chars, pos.start, KEYWORD_PROVIDER, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_PROVIDER.length();
parseProvider( chars, pos, syncRepl, parserException );
}
// searchbase
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SEARCHBASE, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SEARCHBASE.length();
parseSearchBase( chars, pos, syncRepl, parserException );
}
// type
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TYPE, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TYPE.length();
parseType( chars, pos, syncRepl, parserException );
}
// interval
else if ( Strings.areEquals( chars, pos.start, KEYWORD_INTERVAL, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_INTERVAL.length();
parseInterval( chars, pos, syncRepl, parserException );
}
// retry
else if ( Strings.areEquals( chars, pos.start, KEYWORD_RETRY, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_RETRY.length();
parseRetry( chars, pos, syncRepl, parserException );
}
// filter
else if ( Strings.areEquals( chars, pos.start, KEYWORD_FILTER, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_FILTER.length();
parseFilter( chars, pos, syncRepl, parserException );
}
// scope
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SCOPE, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SCOPE.length();
parseScope( chars, pos, syncRepl, parserException );
}
// attrsonly
else if ( Strings.areEquals( chars, pos.start, KEYWORD_ATTRSONLY, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_ATTRSONLY.length();
syncRepl.setAttrsOnly( true );
}
// attrs
else if ( Strings.areEquals( chars, pos.start, KEYWORD_ATTRS, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_ATTRS.length();
parseAttrs( chars, pos, syncRepl, parserException );
}
// sizelimit
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SIZELIMIT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SIZELIMIT.length();
parseSizeLimit( chars, pos, syncRepl, parserException );
}
// timelimit
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TIMELIMIT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TIMELIMIT.length();
parseTimeLimit( chars, pos, syncRepl, parserException );
}
// schemachecking
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SCHEMACHECKING, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SCHEMACHECKING.length();
parseSchemaChecking( chars, pos, syncRepl, parserException );
}
// network-timeout
else if ( Strings.areEquals( chars, pos.start, KEYWORD_NETWORK_TIMEOUT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_NETWORK_TIMEOUT.length();
parseNetworkTimeout( chars, pos, syncRepl, parserException );
}
// timeout
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TIMEOUT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TIMEOUT.length();
parseTimeout( chars, pos, syncRepl, parserException );
}
// bindmethod
else if ( Strings.areEquals( chars, pos.start, KEYWORD_BINDMETHOD, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_BINDMETHOD.length();
parseBindMethod( chars, pos, syncRepl, parserException );
}
// binddn
else if ( Strings.areEquals( chars, pos.start, KEYWORD_BINDDN, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_BINDDN.length();
parseBindDn( chars, pos, syncRepl, parserException );
}
// saslmech
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SASLMECH, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SASLMECH.length();
parseSaslMech( chars, pos, syncRepl, parserException );
}
// authcid
else if ( Strings.areEquals( chars, pos.start, KEYWORD_AUTHCID, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_AUTHCID.length();
parseAuthcId( chars, pos, syncRepl, parserException );
}
// authzid
else if ( Strings.areEquals( chars, pos.start, KEYWORD_AUTHZID, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_AUTHZID.length();
parseAuthzId( chars, pos, syncRepl, parserException );
}
// credentials
else if ( Strings.areEquals( chars, pos.start, KEYWORD_CREDENTIALS, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_CREDENTIALS.length();
parseCredentials( chars, pos, syncRepl, parserException );
}
// realm
else if ( Strings.areEquals( chars, pos.start, KEYWORD_REALM, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_REALM.length();
parseRealm( chars, pos, syncRepl, parserException );
}
// secprops
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SECPROPS, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SECPROPS.length();
parseSecProps( chars, pos, syncRepl, parserException );
}
// keepalive
else if ( Strings.areEquals( chars, pos.start, KEYWORD_KEEPALIVE, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_KEEPALIVE.length();
parseKeepAlive( chars, pos, syncRepl, parserException );
}
// starttls
else if ( Strings.areEquals( chars, pos.start, KEYWORD_STARTTLS, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_STARTTLS.length();
parseStartTls( chars, pos, syncRepl, parserException );
}
// tls_cert
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CERT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CERT.length();
parseTlsCert( chars, pos, syncRepl, parserException );
}
// tls_key
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_KEY, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_KEY.length();
parseTlsKey( chars, pos, syncRepl, parserException );
}
// tls_cacert
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CACERT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CACERT.length();
parseTlsCacert( chars, pos, syncRepl, parserException );
}
// tls_cacertdir
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CACERTDIR, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CACERTDIR.length();
parseTlsCacertDir( chars, pos, syncRepl, parserException );
}
// tls_reqcert
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_REQCERT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_REQCERT.length();
parseTlsReqCert( chars, pos, syncRepl, parserException );
}
// tls_ciphersuite
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CIPHERSUITE, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CIPHERSUITE.length();
parseTlsCipherSuite( chars, pos, syncRepl, parserException );
}
// tls_crlcheck
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CRLCHECK, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CRLCHECK.length();
parseTlsCrlCheck( chars, pos, syncRepl, parserException );
}
// logbase
else if ( Strings.areEquals( chars, pos.start, KEYWORD_LOGBASE, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_LOGBASE.length();
parseLogBase( chars, pos, syncRepl, parserException );
}
// logfilter
else if ( Strings.areEquals( chars, pos.start, KEYWORD_LOGFILTER, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_LOGFILTER.length();
parseLogFilter( chars, pos, syncRepl, parserException );
}
// syncdata
else if ( Strings.areEquals( chars, pos.start, KEYWORD_SYNCDATA, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_SYNCDATA.length();
parseSyncData( chars, pos, syncRepl, parserException );
}
// We couldn't find the appropriate option
else
{
pos.start++;
}
}
while ( ( pos.start != pos.length ) && ( ( c = Strings.charAt( chars, pos.start ) ) != '\0' ) );
if ( foundAtLeastOneProperty )
{
return syncRepl;
}
return null;
}
/**
* Parses the 'rid' option.
*
* @param s the string
* @param pos the position
* @param syncRepl the SyncRepl object
* @param parserException the parser exception
*/
private void parseRid( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setRid( value );
}
}
private void parseProvider( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setProvider( Provider.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseSearchBase( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setSearchBase( value );
}
}
private void parseType( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setType( Type.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseInterval( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setInterval( Interval.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseRetry( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setRetry( Retry.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseFilter( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setFilter( value );
}
}
private void parseScope( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setScope( Scope.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseAttrs( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
String[] attrs = value.split( ",( )*" );
if ( ( attrs != null ) && ( attrs.length > 0 ) )
{
syncRepl.addAttribute( attrs );
}
}
}
private void parseSizeLimit( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setSizeLimit( Integer.parseInt( value ) );
}
catch ( NumberFormatException e )
{
parserException.addParseException( new ParseException( "Unable to convert size limit value '" + value
+ "' as an integer.", 0 ) );
}
}
}
private void parseTimeLimit( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setTimeLimit( Integer.parseInt( value ) );
}
catch ( NumberFormatException e )
{
parserException.addParseException( new ParseException( "Unable to convert time limit value '" + value
+ "' as an integer.", 0 ) );
}
}
}
private void parseSchemaChecking( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setSchemaChecking( SchemaChecking.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseNetworkTimeout( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setNetworkTimeout( Integer.parseInt( value ) );
}
catch ( NumberFormatException e )
{
parserException.addParseException( new ParseException( "Unable to convert network timeout value '"
+ value
+ "' as an integer.", 0 ) );
}
}
}
private void parseTimeout( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setTimeout( Integer.parseInt( value ) );
}
catch ( NumberFormatException e )
{
parserException.addParseException( new ParseException( "Unable to convert timeout value '" + value
+ "' as an integer.", 0 ) );
}
}
}
private void parseBindMethod( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setBindMethod( BindMethod.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseBindDn( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setBindDn( value );
}
}
private void parseSaslMech( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setSaslMech( value );
}
}
private void parseAuthcId( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setAuthcid( value );
}
}
private void parseAuthzId( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setAuthzid( value );
}
}
private void parseCredentials( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setCredentials( value );
}
}
private void parseRealm( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setRealm( value );
}
}
private void parseSecProps( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setSecProps( value );
}
}
private void parseKeepAlive( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setKeepAlive( KeepAlive.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseStartTls( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setStartTls( StartTls.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseTlsCert( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setTlsCert( value );
}
}
private void parseTlsKey( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setTlsKey( value );
}
}
private void parseTlsCacert( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setTlsCacert( value );
}
}
private void parseTlsCacertDir( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setTlsCacertDir( value );
}
}
private void parseTlsReqCert( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setTlsReqcert( TlsReqCert.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseTlsCipherSuite( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setTlsCipherSuite( value );
}
}
private void parseTlsCrlCheck( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setTlsCrlcheck( TlsCrlCheck.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private void parseLogBase( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setLogBase( value );
}
}
private void parseLogFilter( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
syncRepl.setLogFilter( value );
}
}
private void parseSyncData( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
String value = getQuotedOrNotQuotedOptionValue( chars, pos, syncRepl, parserException );
if ( value != null )
{
try
{
syncRepl.setSyncData( SyncData.parse( value ) );
}
catch ( ParseException e )
{
parserException.addParseException( e );
}
}
}
private boolean findEqual( char[] chars, Position pos, SyncRepl syncRepl, SyncReplParserException parserException )
{
char c = Strings.charAt( chars, pos.start );
do
{
// Whitespace
if ( Character.isWhitespace( c ) )
{
pos.start++;
}
// '=' char
else if ( c == '=' )
{
pos.start++;
return true;
}
else
{
return false;
}
}
while ( ( c = Strings.charAt( chars, pos.start ) ) != '\0' );
return false;
}
private String getQuotedOrNotQuotedOptionValue( char[] chars, Position pos, SyncRepl syncRepl,
SyncReplParserException parserException )
{
if ( findEqual( chars, pos, syncRepl, parserException ) )
{
char quoteChar = '\0';
boolean isInQuotes = false;
char c = Strings.charAt( chars, pos.start );
char[] v = new char[chars.length - pos.start];
int current = 0;
do
{
if ( ( current == 0 ) && !isInQuotes )
{
// Whitespace
if ( Character.isWhitespace( c ) )
{
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | true |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/StartTls.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/StartTls.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the Start TLS value.
*/
public enum StartTls
{
/** The 'yes' Start TLS value */
YES("yes"),
/** The 'critical' Start TLS value */
CRITICAL("critical");
/** The value */
private String value;
/**
* Parses a start tls string.
*
* @param s the string
* @return a bind method
* @throws ParseException if an error occurs during parsing
*/
public static StartTls parse( String s ) throws ParseException
{
// YES
if ( YES.value.equalsIgnoreCase( s ) )
{
return YES;
}
// CRITICAL
else if ( CRITICAL.value.equalsIgnoreCase( s ) )
{
return CRITICAL;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid start tls.", 0 );
}
}
/**
* Creates a new instance of StartTls.
*
* @param value the value
*/
private StartTls( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Scope.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Scope.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the scope value.
*/
public enum Scope
{
/** The 'sub' scope value */
SUB("sub"),
/** The 'one' scope value */
ONE("one"),
/** The 'base' scope value */
BASE("base"),
/** The 'subord' scope value */
SUBORD("subord");
/** The value */
private String value;
/**
* Parses a scope string.
*
* @param s the string
* @return a scope
* @throws ParseException if an error occurs during parsing
*/
public static Scope parse( String s ) throws ParseException
{
// SUB
if ( SUB.value.equalsIgnoreCase( s ) )
{
return SUB;
}
// ONE
else if ( ONE.value.equalsIgnoreCase( s ) )
{
return ONE;
}
// BASE
else if ( BASE.value.equalsIgnoreCase( s ) )
{
return BASE;
}
// SUBORD
else if ( SUBORD.value.equalsIgnoreCase( s ) )
{
return SUBORD;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid scope.", 0 );
}
}
/**
* Creates a new instance of Scope.
*
* @param value the value
*/
private Scope( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/TlsReqCert.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/TlsReqCert.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.syncrepl;
import java.text.ParseException;
/**
* This enum implements all the possible values for the TLS REQ Cert value.
*/
public enum TlsReqCert
{
/** The 'never' TLS REQ Cert value */
NEVER("never"),
/** The 'allow' TLS REQ Cert value */
ALLOW("allow"),
/** The 'try' TLS REQ Cert value */
TRY("try"),
/** The 'demand' TLS REQ Cert value */
DEMAND("demand");
/** The value */
private String value;
/**
* Parses a tls req cert string.
*
* @param s the string
* @return a tls req cert
* @throws ParseException if an error occurs during parsing
*/
public static TlsReqCert parse( String s ) throws ParseException
{
// NEVER
if ( NEVER.value.equalsIgnoreCase( s ) )
{
return NEVER;
}
// ALLOW
else if ( ALLOW.value.equalsIgnoreCase( s ) )
{
return ALLOW;
}
// TRY
else if ( TRY.value.equalsIgnoreCase( s ) )
{
return TRY;
}
// DEMAND
else if ( DEMAND.value.equalsIgnoreCase( s ) )
{
return DEMAND;
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid tls req cert.", 0 );
}
}
/**
* Creates a new instance of TlsReqCert.
*
* @param value the value
*/
private TlsReqCert( String value )
{
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString()
{
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/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Retry.java | plugins/openldap.syncrepl/src/main/java/org/apache/directory/studio/openldap/syncrepl/Retry.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.syncrepl;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class implements a retry.
* <p>
* Format: "[<retry interval> <# of retries>]+"
*/
public class Retry
{
/** The pattern used for parsing */
private static final Pattern pattern = Pattern.compile( "^(([0-9]+) ([0-9]+|\\+))( ([0-9]+) ([0-9]+|\\+))*$" );
/** The pairs */
private List<RetryPair> pairs = new ArrayList<RetryPair>();
/**
* Gets a copy of a Retry object.
*
* @param syncRepl the initial Retry object
* @return a copy of the given Retry object
*/
public static Retry copy( Retry retry )
{
if ( retry != null )
{
Retry retryCopy = new Retry();
for ( RetryPair retryPair : retry.getPairs() )
{
retryCopy.addPair( RetryPair.copy( retryPair ) );
}
return retryCopy;
}
return null;
}
/**
* Gets a copy of the Retry object.
*
* @return a copy of the Retry object
*/
public Retry copy()
{
return Retry.copy( this );
}
/**
* Parses a retry string.
*
* @param s the string
* @return a retry
* @throws ParseException if an error occurs during parsing
*/
public static Retry parse( String s ) throws ParseException
{
// Creating the retry
Retry retry = new Retry();
// Matching the string
Matcher matcher = pattern.matcher( s );
// Checking the result
if ( matcher.find() )
{
// Splitting the string into pieces
String[] pieces = s.split( " " );
// Checking we got a even number of pieces
if ( ( pieces.length % 2 ) == 0 )
{
for ( int i = 0; i < pieces.length; i = i + 2 )
{
retry.addPair( RetryPair.parse( pieces[i] + " " + pieces[i + 1] ) );
}
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid retry.", 0 );
}
}
else
{
throw new ParseException( "Unable to parse string '" + s + "' as a valid retry.", 0 );
}
return retry;
}
public void addPair( RetryPair pair )
{
pairs.add( pair );
}
public RetryPair[] getPairs()
{
return pairs.toArray( new RetryPair[0] );
}
public void removePair( RetryPair pair )
{
pairs.remove( pair );
}
public void setPairs( RetryPair[] pairs )
{
this.pairs = new ArrayList<RetryPair>();
this.pairs.addAll( Arrays.asList( pairs ) );
}
public int size()
{
return pairs.size();
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
for ( int i = 0; i < pairs.size(); i++ )
{
sb.append( pairs.get( i ).toString() );
if ( i != ( pairs.size() - 1 ) )
{
sb.append( " " );
}
}
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/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/model/overlay/OlcValSortValueParserTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/model/overlay/OlcValSortValueParserTest.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.config.model.overlay;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.api.ldap.model.name.Dn;
import org.junit.jupiter.api.Test;
/**
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcValSortValueParserTest
{
@Test
public void testEmpty1() throws Exception
{
OlcValSortValue value = OlcValSortValue.parse( "" );
assertNull( value );
}
@Test
public void testEmpty2() throws Exception
{
OlcValSortValue value = OlcValSortValue.parse( " " );
assertNull( value );
}
@Test
public void testEmpty3() throws Exception
{
OlcValSortValue value = OlcValSortValue.parse( "\t" );
assertNull( value );
}
@Test
public void testEmpty4() throws Exception
{
OlcValSortValue value = OlcValSortValue.parse( "\n" );
assertNull( value );
}
@Test
public void testOk1() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.ALPHA_ASCEND;
String s = attribute + " " + baseDn + " " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertFalse( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk2() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.ALPHA_ASCEND;
String s = attribute + " " + baseDn + " " + sortMethod;
String s2 = attribute + " " + baseDn + " " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertFalse( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s2, value.toString() );
}
@Test
public void testOk3() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.ALPHA_DESCEND;
String s = attribute + " " + baseDn + " " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertFalse( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk4() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.NUMERIC_ASCEND;
String s = attribute + " " + baseDn + " " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertFalse( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk5() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.NUMERIC_DESCEND;
String s = attribute + " " + baseDn + " " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertFalse( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk6() throws Exception
{
String attribute = "attr";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
String s = attribute + " " + baseDn + " weighted";
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertTrue( value.isWeighted() );
assertNull( value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk7() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.ALPHA_ASCEND;
String s = attribute + " " + baseDn + " weighted " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertTrue( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk8() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.ALPHA_DESCEND;
String s = attribute + " " + baseDn + " weighted " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertTrue( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk9() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.NUMERIC_ASCEND;
String s = attribute + " " + baseDn + " weighted " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertTrue( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.toString() );
}
@Test
public void testOk10() throws Exception
{
String attribute = "member";
Dn baseDn = new Dn( "ou=groups,dc=example,dc=com" );
OlcValSortMethodEnum sortMethod = OlcValSortMethodEnum.NUMERIC_DESCEND;
String s = attribute + " " + baseDn + " weighted " + sortMethod;
OlcValSortValue value = OlcValSortValue.parse( s );
assertNotNull( value );
assertEquals( attribute, value.getAttribute() );
assertEquals( baseDn, value.getBaseDn() );
assertTrue( value.isWeighted() );
assertEquals( sortMethod, value.getSortMethod() );
assertEquals( s, value.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/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/editor/dialogs/PurgeTimeSpanTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/editor/dialogs/PurgeTimeSpanTest.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.config.editor.dialogs;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.text.ParseException;
import org.junit.jupiter.api.Test;
/**
* This class tests the {@link PurgeTimeSpan} class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PurgeTimeSpanTest
{
@Test
public void testArguments() throws Exception
{
try
{
new PurgeTimeSpan( -1, 0, 0, 0 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 100000, 0, 0, 0 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 0, -1, 0, 0 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 0, 61, 0, 0 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 0, 0, -1, 0 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 0, 0, 61, 0 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 0, 0, 0, -1 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( 0, 0, 0, 61 );
fail();
}
catch ( IllegalArgumentException e )
{
// Should to pass here
}
}
@Test
public void testTooShort()
{
try
{
new PurgeTimeSpan( "0" );
fail();
}
catch ( ParseException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( "00" );
fail();
}
catch ( ParseException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( "00:" );
fail();
}
catch ( ParseException e )
{
// Should to pass here
}
try
{
new PurgeTimeSpan( "00:0" );
fail();
}
catch ( ParseException e )
{
// Should to pass here
}
}
@Test
public void testParsing() throws Exception
{
PurgeTimeSpan span1 = new PurgeTimeSpan( "12:34" );
assertEquals( 0, span1.getDays() );
assertEquals( 12, span1.getHours() );
assertEquals( 34, span1.getMinutes() );
assertEquals( 0, span1.getSeconds() );
PurgeTimeSpan span2 = new PurgeTimeSpan( "12:34:56" );
assertEquals( 0, span2.getDays() );
assertEquals( 12, span2.getHours() );
assertEquals( 34, span2.getMinutes() );
assertEquals( 56, span2.getSeconds() );
PurgeTimeSpan span3 = new PurgeTimeSpan( "1+23:45" );
assertEquals( 1, span3.getDays() );
assertEquals( 23, span3.getHours() );
assertEquals( 45, span3.getMinutes() );
assertEquals( 0, span3.getSeconds() );
PurgeTimeSpan span4 = new PurgeTimeSpan( "12+14:56" );
assertEquals( 12, span4.getDays() );
assertEquals( 14, span4.getHours() );
assertEquals( 56, span4.getMinutes() );
assertEquals( 0, span4.getSeconds() );
PurgeTimeSpan span5 = new PurgeTimeSpan( "123+15:37" );
assertEquals( 123, span5.getDays() );
assertEquals( 15, span5.getHours() );
assertEquals( 37, span5.getMinutes() );
assertEquals( 0, span5.getSeconds() );
PurgeTimeSpan span6 = new PurgeTimeSpan( "1234+16:38" );
assertEquals( 1234, span6.getDays() );
assertEquals( 16, span6.getHours() );
assertEquals( 38, span6.getMinutes() );
assertEquals( 0, span6.getSeconds() );
PurgeTimeSpan span7 = new PurgeTimeSpan( "12345+17:39" );
assertEquals( 12345, span7.getDays() );
assertEquals( 17, span7.getHours() );
assertEquals( 39, span7.getMinutes() );
assertEquals( 0, span7.getSeconds() );
PurgeTimeSpan span8 = new PurgeTimeSpan( "1+23:45:41" );
assertEquals( 1, span8.getDays() );
assertEquals( 23, span8.getHours() );
assertEquals( 45, span8.getMinutes() );
assertEquals( 41, span8.getSeconds() );
PurgeTimeSpan span9 = new PurgeTimeSpan( "12+14:56:42" );
assertEquals( 12, span9.getDays() );
assertEquals( 14, span9.getHours() );
assertEquals( 56, span9.getMinutes() );
assertEquals( 42, span9.getSeconds() );
PurgeTimeSpan span10 = new PurgeTimeSpan( "123+15:37:43" );
assertEquals( 123, span10.getDays() );
assertEquals( 15, span10.getHours() );
assertEquals( 37, span10.getMinutes() );
assertEquals( 43, span10.getSeconds() );
PurgeTimeSpan span11 = new PurgeTimeSpan( "1234+16:38:45" );
assertEquals( 1234, span11.getDays() );
assertEquals( 16, span11.getHours() );
assertEquals( 38, span11.getMinutes() );
assertEquals( 45, span11.getSeconds() );
PurgeTimeSpan span12 = new PurgeTimeSpan( "12345+17:39:46" );
assertEquals( 12345, span12.getDays() );
assertEquals( 17, span12.getHours() );
assertEquals( 39, span12.getMinutes() );
assertEquals( 46, span12.getSeconds() );
}
@Test
public void testToString() throws Exception
{
PurgeTimeSpan span1 = new PurgeTimeSpan( 0, 1, 2, 0 );
assertEquals( "01:02", span1.toString() );
PurgeTimeSpan span2 = new PurgeTimeSpan( 1, 2, 3, 0 );
assertEquals( "1+02:03", span2.toString() );
PurgeTimeSpan span3 = new PurgeTimeSpan( 12, 3, 4, 5 );
assertEquals( "12+03:04:05", span3.toString() );
PurgeTimeSpan span4 = new PurgeTimeSpan( 123, 4, 5, 6 );
assertEquals( "123+04:05:06", span4.toString() );
PurgeTimeSpan span5 = new PurgeTimeSpan( 1234, 5, 6, 7 );
assertEquals( "1234+05:06:07", span5.toString() );
PurgeTimeSpan span6 = new PurgeTimeSpan( 12345, 6, 7, 8 );
assertEquals( "12345+06:07:08", span6.toString() );
PurgeTimeSpan span7 = new PurgeTimeSpan( 0, 1, 2, 3 );
assertEquals( "01:02:03", span7.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/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SaslSecPropsWrapperTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SaslSecPropsWrapperTest.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.config.wrappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.studio.openldap.common.ui.model.SaslSecPropEnum;
import org.apache.directory.studio.openldap.config.editor.wrappers.SaslSecPropsWrapper;
import org.junit.jupiter.api.Test;
/**
* A test for the SaslSecPropsWrapper class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class SaslSecPropsWrapperTest
{
@Test
public void testToString()
{
SaslSecPropsWrapper ssfWrapper = new SaslSecPropsWrapper();
assertEquals( "", ssfWrapper.toString() );
ssfWrapper = new SaslSecPropsWrapper( "none" );
assertEquals( "none", ssfWrapper.toString() );
ssfWrapper = new SaslSecPropsWrapper( "minssf = 100");
assertEquals( "minssf=100", ssfWrapper.toString() );
}
@Test
public void testIsValid()
{
assertTrue( SaslSecPropsWrapper.isValid( null ) );
assertTrue( SaslSecPropsWrapper.isValid( "" ) );
assertTrue( SaslSecPropsWrapper.isValid( " " ) );
// Standard flags
assertTrue( SaslSecPropsWrapper.isValid( "none" ) );
assertTrue( SaslSecPropsWrapper.isValid( "NoPlain" ) );
assertTrue( SaslSecPropsWrapper.isValid( "noActive" ) );
assertTrue( SaslSecPropsWrapper.isValid( " noDict " ) );
assertTrue( SaslSecPropsWrapper.isValid( "noanonymous" ) );
assertTrue( SaslSecPropsWrapper.isValid( "forwardSec" ) );
assertTrue( SaslSecPropsWrapper.isValid( "passcred" ) );
// properties with value
assertTrue( SaslSecPropsWrapper.isValid( "minSSF=100" ) );
assertTrue( SaslSecPropsWrapper.isValid( " minSsf = 1000 " ) );
assertTrue( SaslSecPropsWrapper.isValid( " maxSsf = 1000 " ) );
assertTrue( SaslSecPropsWrapper.isValid( " maxBufSize = 1000 " ) );
// Multiple properties
assertTrue( SaslSecPropsWrapper.isValid( " maxBufSize = 1000,none, nodict, maxssF = 100 " ) );
// Wrong properties
assertFalse( SaslSecPropsWrapper.isValid( " abc " ) );
assertFalse( SaslSecPropsWrapper.isValid( " maxBufSize = -1000" ) );
assertFalse( SaslSecPropsWrapper.isValid( " maxBufSize = ,none" ) );
// Corner cases
assertTrue( SaslSecPropsWrapper.isValid( " ,none" ) );
assertTrue( SaslSecPropsWrapper.isValid( "none," ) );
assertTrue( SaslSecPropsWrapper.isValid( " ,none," ) );
assertTrue( SaslSecPropsWrapper.isValid( " maxBufSize = 1000,,none, nodict, maxssF = 100 " ) );
}
@Test
public void testCreateSspw()
{
SaslSecPropsWrapper sspw = new SaslSecPropsWrapper( null );
assertEquals( 0, sspw.getFlags().size() );
sspw = new SaslSecPropsWrapper( "" );
assertEquals( 0, sspw.getFlags().size() );
sspw = new SaslSecPropsWrapper( "none" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.NONE ) );
sspw = new SaslSecPropsWrapper( "noplain" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.NO_PLAIN ) );
sspw = new SaslSecPropsWrapper( "noactive" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.NO_ACTIVE ) );
sspw = new SaslSecPropsWrapper( "nodict" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.NO_DICT ) );
sspw = new SaslSecPropsWrapper( "noanonymous" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.NO_ANONYMOUS ) );
sspw = new SaslSecPropsWrapper( "forwardsec" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.FORWARD_SEC ) );
sspw = new SaslSecPropsWrapper( "passcred" );
assertEquals( 1, sspw.getFlags().size() );
assertTrue( sspw.getFlags().contains( SaslSecPropEnum.PASS_CRED ) );
sspw = new SaslSecPropsWrapper( "minssf = 100" );
assertEquals( 0, sspw.getFlags().size() );
assertNotNull( sspw.getMinSsf() );
assertEquals( 100, sspw.getMinSsf().intValue() );
sspw = new SaslSecPropsWrapper( "minssf = 100, maxssf=200, maxBufSize= 2000, " );
assertEquals( 0, sspw.getFlags().size() );
assertNotNull( sspw.getMinSsf() );
assertEquals( 100, sspw.getMinSsf().intValue() );
}
}
| 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.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/TimeLimitWrapperTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/TimeLimitWrapperTest.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.config.wrappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.studio.openldap.config.editor.wrappers.TimeLimitWrapper;
import org.junit.jupiter.api.Test;
/**
* A test for the TimeLimitWrapper class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class TimeLimitWrapperTest
{
@Test
public void testToString()
{
TimeLimitWrapper tlw = new TimeLimitWrapper( null, new Integer( 200 ), new Integer( 100 ) );
assertEquals( "time.hard=200 time.soft=100", tlw.toString() );
tlw = new TimeLimitWrapper( null, new Integer( 100 ), new Integer( 200 ) );
assertEquals( "time=100", tlw.toString() );
tlw = new TimeLimitWrapper( null, new Integer( 100 ), new Integer( 100 ) );
assertEquals( "time=100", tlw.toString() );
tlw = new TimeLimitWrapper( null, new Integer( 100 ), null );
assertEquals( "time.hard=100", tlw.toString() );
tlw = new TimeLimitWrapper( null, null, new Integer( 100 ) );
assertEquals( "time.soft=100", tlw.toString() );
tlw = new TimeLimitWrapper( null, null, null );
assertEquals( "", tlw.toString() );
tlw = new TimeLimitWrapper( new Integer( 100 ), null, null );
assertEquals( "time=100", tlw.toString() );
tlw = new TimeLimitWrapper( new Integer( 100 ), new Integer( 200 ), null );
assertEquals( "time=100", tlw.toString() );
tlw = new TimeLimitWrapper( new Integer( 100 ), null, new Integer( 200 ) );
assertEquals( "time=100", tlw.toString() );
tlw = new TimeLimitWrapper( new Integer( 100 ), new Integer( 200 ), new Integer( 300 ) );
assertEquals( "time=100", tlw.toString() );
tlw = new TimeLimitWrapper( null, new Integer( -1 ), new Integer( 300 ) );
assertEquals( "time.hard=unlimited time.soft=300", tlw.toString() );
tlw = new TimeLimitWrapper( null, new Integer( 200 ), new Integer( -1 ) );
assertEquals( "time=200", tlw.toString() );
tlw = new TimeLimitWrapper( new Integer( -1 ), new Integer( 200 ), new Integer( -1 ) );
assertEquals( "time=unlimited", tlw.toString() );
}
@Test
public void testIsValid()
{
TimeLimitWrapper timeLimitWrapper = new TimeLimitWrapper( null );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( " " );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time=100" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time=none" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time=unlimited" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.hard=100" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.hard=none" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.hard=unlimited" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.soft=100" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.soft=none" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.soft=unlimited" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.soft=100 time.hard=200" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.hard=100 time.soft=200" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.soft=none time.hard=200" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.hard=100 time.soft=unlimited" );
assertTrue( timeLimitWrapper.isValid() );
timeLimitWrapper = new TimeLimitWrapper( "time.hard=soft time.soft=unlimited time=100" );
assertTrue( timeLimitWrapper.isValid() );
}
@Test
public void testCreateTimeLimit()
{
TimeLimitWrapper tlw = new TimeLimitWrapper( null );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( null,tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( " " );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time=100" );
assertEquals( 100, tlw.getGlobalLimit().intValue() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time=none" );
assertEquals( -1, tlw.getGlobalLimit().intValue() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time=unlimited" );
assertEquals( -1, tlw.getGlobalLimit().intValue() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time.hard=100" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( 100, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.hard=none" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( -1, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.hard=unlimited" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( -1, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.soft=100" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( 100, tlw.getSoftLimit().intValue() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time.soft=none" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( -1, tlw.getSoftLimit().intValue() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time.soft=unlimited" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( -1, tlw.getSoftLimit().intValue() );
assertEquals( null, tlw.getHardLimit() );
tlw = new TimeLimitWrapper( "time.soft=100 time.hard=200" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( 100, tlw.getSoftLimit().intValue() );
assertEquals( 200, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.hard=100 time.soft=200" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( 200, tlw.getSoftLimit().intValue() );
assertEquals( 100, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.soft=none time.hard=200" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( -1, tlw.getSoftLimit().intValue() );
assertEquals( 200, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.hard=100 time.soft=unlimited" );
assertEquals( null, tlw.getGlobalLimit() );
assertEquals( -1, tlw.getSoftLimit().intValue() );
assertEquals( 100, tlw.getHardLimit().intValue() );
tlw = new TimeLimitWrapper( "time.hard=soft time.soft=unlimited time=100" );
assertEquals( 100, tlw.getGlobalLimit().intValue() );
assertEquals( null, tlw.getSoftLimit() );
assertEquals( null, tlw.getHardLimit() );
}
}
| 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.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/DbIndexWrapperTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/DbIndexWrapperTest.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.config.wrappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.studio.openldap.config.editor.wrappers.DbIndexWrapper;
import org.apache.directory.studio.openldap.common.ui.model.DbIndexTypeEnum;
import org.junit.jupiter.api.Test;
/**
* A test for the DbIndexWrapper class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class DbIndexWrapperTest
{
@Test
public void testClone()
{
DbIndexWrapper index1 = new DbIndexWrapper( "cn,sn,objectClass eq,sub,approx" );
DbIndexWrapper index2 = index1.clone();
index1.getAttributes().clear();
assertFalse( index1.getAttributes().contains( "cn" ) );
assertTrue( index2.getAttributes().contains( "cn" ) );
}
@Test
public void testConstructor()
{
DbIndexWrapper index1 = new DbIndexWrapper( "cn,sn,objectClass,cn eq,sub,aprox,eq" );
assertEquals( 3, index1.getAttributes().size() );
assertEquals( 2, index1.getIndexTypes().size() );
assertTrue( index1.getIndexTypes().contains( DbIndexTypeEnum.EQ ) );
assertTrue( index1.getIndexTypes().contains( DbIndexTypeEnum.SUB ) );
assertFalse( index1.getIndexTypes().contains( DbIndexTypeEnum.APPROX ) );
assertEquals( "cn,objectclass,sn eq,sub", index1.toString() );
}
@Test
public void testCompare()
{
DbIndexWrapper index = new DbIndexWrapper( "cn,sn,objectClass,cn eq,sub,aprox,eq" );
DbIndexWrapper index2 = new DbIndexWrapper( "cn,sn,objectClass,a eq,sub,aprox,eq" );
DbIndexWrapper index3 = new DbIndexWrapper( "cn,sn,objectClass,z eq,sub,aprox,eq" );
DbIndexWrapper index4 = new DbIndexWrapper( "sn,objectClass,cn eq" );
assertTrue( index.compareTo( index2 ) > 0 );
assertTrue( index.compareTo( index3 ) < 0 );
assertTrue( index.compareTo( index4 ) == 0 );
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SizeLimitWrapperTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SizeLimitWrapperTest.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.config.wrappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.studio.openldap.config.editor.wrappers.SizeLimitWrapper;
import org.junit.jupiter.api.Test;
/**
* A test for the SizeLimitWrapper class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class SizeLimitWrapperTest
{
@Test
public void testToString()
{
SizeLimitWrapper slw = new SizeLimitWrapper( null, new Integer( 200 ), new Integer( 100 ), null, null, null, false );
assertEquals( "size.hard=200 size.soft=100", slw.toString() );
slw = new SizeLimitWrapper( null, new Integer( 100 ), new Integer( 200 ), null, null, null, false );
assertEquals( "size=100", slw.toString() );
slw = new SizeLimitWrapper( null, new Integer( 100 ), new Integer( 100 ), null, null, null, false );
assertEquals( "size=100", slw.toString() );
slw = new SizeLimitWrapper( null, new Integer( 100 ), null, null, null, null, false );
assertEquals( "size.hard=100", slw.toString() );
slw = new SizeLimitWrapper( null, null, new Integer( 100 ), null, null, null, false );
assertEquals( "size.soft=100", slw.toString() );
slw = new SizeLimitWrapper( null, null, null, null, null, null, false );
assertEquals( "", slw.toString() );
slw = new SizeLimitWrapper( new Integer( 100 ), null, null, null, null, null, false );
assertEquals( "size=100", slw.toString() );
slw = new SizeLimitWrapper( new Integer( 100 ), new Integer( 200 ), null, null, null, null, false );
assertEquals( "size=100", slw.toString() );
slw = new SizeLimitWrapper( new Integer( 100 ), null, new Integer( 200 ), null, null, null, false );
assertEquals( "size=100", slw.toString() );
slw = new SizeLimitWrapper( new Integer( 100 ), new Integer( 200 ), new Integer( 300 ), null, null, null, false );
assertEquals( "size=100", slw.toString() );
slw = new SizeLimitWrapper( null, new Integer( -1 ), new Integer( 300 ), null, null, null, false );
assertEquals( "size.hard=unlimited size.soft=300", slw.toString() );
slw = new SizeLimitWrapper( null, new Integer( 200 ), new Integer( -1 ), null, null, null, false );
assertEquals( "size=200", slw.toString() );
slw = new SizeLimitWrapper( new Integer( -1 ), new Integer( 200 ), new Integer( -1 ), null, null, null, false );
assertEquals( "size=unlimited", slw.toString() );
}
@Test
public void testIsValid()
{
SizeLimitWrapper sizeLimitWrapper = new SizeLimitWrapper( null );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( " " );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size=100" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size=none" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size=unlimited" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.hard=100" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.hard=none" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.hard=unlimited" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.soft=100" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.soft=none" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.soft=unlimited" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.soft=100 size.hard=200" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.hard=100 size.soft=200" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.soft=none size.hard=200" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.hard=100 size.soft=unlimited" );
assertTrue( sizeLimitWrapper.isValid() );
sizeLimitWrapper = new SizeLimitWrapper( "size.hard=soft size.soft=unlimited size=100" );
assertTrue( sizeLimitWrapper.isValid() );
}
@Test
public void testCreateSizeLimit()
{
SizeLimitWrapper slw = new SizeLimitWrapper( null );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( " " );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size=100" );
assertEquals( 100, slw.getGlobalLimit().intValue() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size=none" );
assertEquals( -1, slw.getGlobalLimit().intValue() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size=unlimited" );
assertEquals( -1, slw.getGlobalLimit().intValue() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size.hard=100" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( 100, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.hard=none" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( -1, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.hard=unlimited" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( -1, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.soft=100" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( 100, slw.getSoftLimit().intValue() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size.soft=none" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( -1, slw.getSoftLimit().intValue() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size.soft=unlimited" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( -1, slw.getSoftLimit().intValue() );
assertEquals( null, slw.getHardLimit() );
slw = new SizeLimitWrapper( "size.soft=100 size.hard=200" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( 100, slw.getSoftLimit().intValue() );
assertEquals( 200, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.hard=100 size.soft=200" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( 200, slw.getSoftLimit().intValue() );
assertEquals( 100, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.soft=none size.hard=200" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( -1, slw.getSoftLimit().intValue() );
assertEquals( 200, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.hard=100 size.soft=unlimited" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( -1, slw.getSoftLimit().intValue() );
assertEquals( 100, slw.getHardLimit().intValue() );
slw = new SizeLimitWrapper( "size.hard=soft size.soft=unlimited size=100" );
assertEquals( 100, slw.getGlobalLimit().intValue() );
assertEquals( null, slw.getSoftLimit() );
assertEquals( null, slw.getHardLimit() );
assertFalse( slw.isNoEstimate() );
slw = new SizeLimitWrapper( "size.hard=100 size.soft=50 size.unchecked=20 size.pr=10 size.prtotal=20 size.pr=noEstimate" );
assertEquals( null, slw.getGlobalLimit() );
assertEquals( 50, slw.getSoftLimit().intValue() );
assertEquals( 100, slw.getHardLimit().intValue() );
assertEquals( 20, slw.getUncheckedLimit().intValue() );
assertEquals( 10, slw.getPrLimit().intValue() );
assertEquals( 20, slw.getPrTotalLimit().intValue() );
assertTrue( slw.isNoEstimate() );
}
}
| 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.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.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.config.wrappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.studio.openldap.common.ui.model.SsfFeatureEnum;
import org.apache.directory.studio.openldap.config.editor.wrappers.SsfWrapper;
import org.junit.jupiter.api.Test;
/**
* A test for the SsfWrapper class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class SsfWrapperTest
{
@Test
public void testToString()
{
SsfWrapper ssfWrapper = new SsfWrapper( "ssf", 128 );
assertEquals( "ssf=128", ssfWrapper.toString() );
ssfWrapper = new SsfWrapper( "SSF", 128 );
assertEquals( "ssf=128", ssfWrapper.toString() );
ssfWrapper = new SsfWrapper( "ABC", 128 );
assertEquals( "", ssfWrapper.toString() );
}
@Test
public void testIsValid()
{
assertFalse( SsfWrapper.isValid( null ) );
assertFalse( SsfWrapper.isValid( "" ) );
assertFalse( SsfWrapper.isValid( " " ) );
assertTrue( SsfWrapper.isValid( "ssf=0" ) );
assertTrue( SsfWrapper.isValid( "ssf=256" ) );
assertTrue( SsfWrapper.isValid( "update_transport=64" ) );
assertTrue( SsfWrapper.isValid( " SSF = 128" ) );
assertFalse( SsfWrapper.isValid( " ssf = 5 = 7 " ) );
assertFalse( SsfWrapper.isValid( "ssf=-2 " ) );
}
@Test
public void testCreateSsf()
{
SsfWrapper ssfWrapper = new SsfWrapper( "ssf", 128 );
assertEquals( SsfFeatureEnum.SSF, ssfWrapper.getFeature() );
assertEquals( 128, ssfWrapper.getNbBits() );
ssfWrapper = new SsfWrapper( "ssf", -128 );
assertEquals( SsfFeatureEnum.SSF, ssfWrapper.getFeature() );
assertEquals( 0, ssfWrapper.getNbBits() );
ssfWrapper = new SsfWrapper( "SSF", 128 );
assertEquals( SsfFeatureEnum.SSF, ssfWrapper.getFeature() );
assertEquals( 128, ssfWrapper.getNbBits() );
}
}
| 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.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/LimitsWrapperTest.java | plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/LimitsWrapperTest.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.config.wrappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.directory.studio.openldap.common.ui.model.DnSpecStyleEnum;
import org.apache.directory.studio.openldap.common.ui.model.DnSpecTypeEnum;
import org.apache.directory.studio.openldap.common.ui.model.LimitSelectorEnum;
import org.apache.directory.studio.openldap.config.editor.wrappers.LimitWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.LimitsWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.TimeLimitWrapper;
import org.apache.directory.studio.openldap.config.editor.wrappers.SizeLimitWrapper;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* A test for the LimitsWrapper class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LimitsWrapperTest
{
@Test
public void testLimitsWrapper()
{
LimitsWrapper lw = new LimitsWrapper( "dn.this.exact=\".*,dc=example,dc=com\"" );
assertEquals( LimitSelectorEnum.DNSPEC, lw.getSelector() );
assertEquals( DnSpecTypeEnum.THIS, lw.getDnSpecType() );
assertEquals( DnSpecStyleEnum.EXACT, lw.getDnSpecStyle() );
assertEquals( ".*,dc=example,dc=com", lw.getSelectorPattern() );
assertFalse( lw.isValid() );
assertEquals( "{0}dn.this.exact=\".*,dc=example,dc=com\"", lw.toString() );
lw = new LimitsWrapper( "dn=\"*\"" );
assertEquals( LimitSelectorEnum.DNSPEC, lw.getSelector() );
assertNull( lw.getDnSpecType() );
assertNull( lw.getDnSpecStyle() );
assertEquals( "*", lw.getSelectorPattern() );
assertFalse( lw.isValid() );
assertEquals( "{0}dn=\"*\"", lw.toString() );
lw = new LimitsWrapper( "dn.self.regex=\".*,dc=example,dc=com\" time.soft=100 time.hard=1000 size.soft=100 size.hard=soft" );
assertEquals( LimitSelectorEnum.DNSPEC, lw.getSelector() );
assertEquals( DnSpecTypeEnum.SELF, lw.getDnSpecType() );
assertEquals( DnSpecStyleEnum.REGEXP, lw.getDnSpecStyle() );
assertEquals( ".*,dc=example,dc=com", lw.getSelectorPattern() );
assertTrue( lw.isValid() );
List<LimitWrapper> limits = lw.getLimits();
assertEquals( 4, limits.size() );
assertTrue( limits.get( 0 ) instanceof TimeLimitWrapper );
TimeLimitWrapper tlw1 = (TimeLimitWrapper)limits.get( 0 );
assertTrue( tlw1.isValid() );
assertEquals( 100, tlw1.getSoftLimit().intValue() );
assertTrue( limits.get( 1 ) instanceof TimeLimitWrapper );
TimeLimitWrapper tlw2 = (TimeLimitWrapper)limits.get( 1 );
assertTrue( tlw2.isValid() );
assertEquals( 1000, tlw2.getHardLimit().intValue() );
assertTrue( limits.get( 2 ) instanceof SizeLimitWrapper );
SizeLimitWrapper slw1 = (SizeLimitWrapper)limits.get( 2 );
assertTrue( slw1.isValid() );
assertEquals( 100, slw1.getSoftLimit().intValue() );
assertTrue( limits.get( 3 ) instanceof SizeLimitWrapper );
SizeLimitWrapper slw2 = (SizeLimitWrapper)limits.get( 3 );
assertTrue( slw2.isValid() );
assertEquals( SizeLimitWrapper.HARD_SOFT.intValue(), slw2.getGlobalLimit().intValue() );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.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.config;
import java.io.IOException;
import java.net.URL;
import java.util.PropertyResourceBundle;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
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;
/**
* The activator class controls the plug-in life cycle.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OpenLdapConfigurationPlugin extends AbstractUIPlugin
{
/** The shared instance */
private static OpenLdapConfigurationPlugin plugin;
/** The plugin properties */
private PropertyResourceBundle properties;
/** The schema manager */
private SchemaManager schemaManager;
/**
* Creates a new instance of OpenLdapConfigurationPlugin.
*/
public OpenLdapConfigurationPlugin()
{
plugin = this;
}
/**
* Gets the schema manager.
*
* @return the schema manager
* @throws Exception if an error occurred
*/
public synchronized SchemaManager getSchemaManager() throws Exception
{
if ( schemaManager == null )
{
// Initializing the schema manager
schemaManager = new DefaultSchemaManager( new OpenLdapSchemaLoader() );
// Loading only the OpenLDAP schema (and its dependencies)
schemaManager.loadWithDeps( OpenLdapSchemaLoader.OPENLDAPCONFIG_SCHEMA_NAME );
// Checking if no error occurred when loading the schemas
if ( !schemaManager.getErrors().isEmpty() )
{
schemaManager = null;
throw new Exception( "Could not load the OpenLDAP schema correctly." );
}
}
return schemaManager;
}
/**
* Returns the shared instance.
*
* @return the shared instance
*/
public static OpenLdapConfigurationPlugin getDefault()
{
return plugin;
}
/**
* Use this method to get SWT images. Use the IMG_ constants from
* PluginConstants for the key.
*
* @param key The key (relative path to the image in filesystem)
* @return The image descriptor or null
*/
public ImageDescriptor getImageDescriptor( String key )
{
if ( key != null )
{
URL url = FileLocator.find( getBundle(), new Path( key ), null );
if ( url != null )
{
return ImageDescriptor.createFromURL( url );
}
else
{
return null;
}
}
else
{
return null;
}
}
/**
* Use this method to get SWT images. Use the IMG_ constants from
* PluginConstants for the key. A ImageRegistry is used to manage the
* the key->Image mapping.
* <p>
* Note: Don't dispose the returned SWT Image. It is disposed
* automatically when the plugin is stopped.
*
* @param key The key (relative path to the image in filesystem)
* @return The SWT Image or null
*/
public Image getImage( String key )
{
Image image = getImageRegistry().get( key );
if ( image == null )
{
ImageDescriptor id = getImageDescriptor( key );
if ( id != null )
{
image = id.createImage();
getImageRegistry().put( key, image );
}
}
return image;
}
/**
* Gets the plugin properties.
*
* @return the plugin properties
*/
public PropertyResourceBundle getPluginProperties()
{
if ( properties == null )
{
try
{
properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path(
"plugin.properties" ), false ) ); //$NON-NLS-1$
}
catch ( IOException e )
{
// We can't use the PLUGIN_ID constant since loading the plugin.properties file has failed,
// So we're using a default plugin id.
getLog().log(
new Status( Status.ERROR, "org.apache.directory.studio.apacheds.configuration", Status.OK, //$NON-NLS-1$
Messages.getString( "OpenLdapConfigurationPlugin.UnableGetProperties" ), 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.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.config;
import java.util.List;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.util.Strings;
/**
* The class is a utility class for the OpenLDAP Configuration Plugin
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OpenLdapConfigurationPluginUtils
{
private OpenLdapConfigurationPluginUtils()
{
// Nothing to do
}
/**
* Strips the ordering prefix if the given string contains one.
*
* @param s the string
* @return the string without the ordering prefix
*/
public static String stripOrderingPrefix( String s )
{
if ( hasOrderingPrefix( s ) )
{
int indexOfClosingCurlyBracket = s.indexOf( '}' );
if ( indexOfClosingCurlyBracket != -1 )
{
return s.substring( indexOfClosingCurlyBracket + 1 );
}
}
return s;
}
/**
* Strips the ordering postfix if the given string contains one.
*
* @param s the string
* @return the string without the ordering postfix
*/
public static String stripOrderingPostfix( String s )
{
if ( hasOrderingPostfix( s ) )
{
int indexOfOpeningCurlyBracket = s.indexOf( '{' );
if ( indexOfOpeningCurlyBracket != -1 )
{
return s.substring( 0, indexOfOpeningCurlyBracket );
}
}
return s;
}
/**
* Indicates if the given string contains an ordering prefix.
*
* @param s the string
* @return <code>true</code> if the given string contains an ordering prefix,
* <code>false</code> if not.
*/
public static boolean hasOrderingPrefix( String s )
{
return parseOrderingPrefix( s ) != null;
}
/**
* Indicates if the given string contains an ordering postfix.
*
* @param s the string
* @return <code>true</code> if the given string contains an ordering postfix,
* <code>false</code> if not.
*/
public static boolean hasOrderingPostfix( String s )
{
return parseOrderingPostfix( s ) != null;
}
/**
* Fetch the prefix from a String. The prefix must respect the following regexp :
* <pre>
* ^\{-?\d+\}.*$
* </pre>
*/
private static Integer parseOrderingPrefix( String prefixString )
{
if ( prefixString == null )
{
return null;
}
int pos = 0;
if ( !Strings.isCharASCII( prefixString, pos++, '{') )
{
return null;
}
boolean positive = true;
int prefix = 0;
if ( Strings.isCharASCII( prefixString, pos, '-') )
{
positive = false;
pos++;
}
char car;
while ( ( car = Strings.charAt( prefixString, pos++ ) ) != '\0' )
{
switch ( car )
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
prefix = prefix * 10 + car - '0';
break;
case '}' :
if ( positive )
{
return prefix;
}
else
{
return -prefix;
}
default :
return null;
}
}
return null;
}
/**
* Fetch the postfix from a String. The postfix must respect the following regexp :
* <pre>
* ^.*\{-?\d+\}$
* </pre>
*/
private static Integer parseOrderingPostfix( String postfixString )
{
if ( postfixString == null )
{
return null;
}
int pos = -1;
for ( int idx = 0; idx < postfixString.length(); idx++ )
{
if ( Strings.isCharASCII( postfixString, idx, '{') )
{
pos = idx + 1;
break;
}
}
if ( pos == -1 )
{
return null;
}
boolean positive = true;
int prefix = 0;
if ( Strings.isCharASCII( postfixString, pos, '-') )
{
positive = false;
}
char car;
while ( ( car = Strings.charAt( postfixString, pos++ ) ) != '\0' )
{
switch ( car )
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
prefix = prefix * 10 + car - '0';
break;
case '}' :
if ( positive )
{
return prefix;
}
else
{
return -prefix;
}
default :
return null;
}
}
return null;
}
/**
* Gets the ordering prefix value (or -1 if none is found). The String's prefix
* is at the beginning :
* <pre>
* {n}blah
* </pre>
*
* @param prefixString the string
* @return the precedence value (or -1 if none is found).
*/
public static int getOrderingPrefix( String prefixString )
{
Integer orderingPrefix = parseOrderingPrefix( prefixString );
if ( orderingPrefix == null )
{
return -1;
}
else
{
return orderingPrefix;
}
}
/**
* Gets the ordering postfix value (or -1 if none is found).
*
* @param postfixString the string
* @return the precedence value (or -1 if none is found).
*/
public static int getOrderingPostfix( String postfixString )
{
Integer orderingPostfix = parseOrderingPostfix( postfixString );
if ( orderingPostfix == null )
{
return -1;
}
else
{
return orderingPostfix;
}
}
/**
* Gets the first value of the given list of values.
*
* @param values the list of values
* @return the first value if it exists.
*/
public static String getFirstValueString( List<String> values )
{
if ( ( values != null ) && !values.isEmpty() )
{
return values.get( 0 );
}
return null;
}
/**
* Gets the first value of the given list of values.
*
* @param values the list of values
* @return the first value if it exists.
*/
public static String getFirstValueDn( List<Dn> values )
{
if ( ( values != null ) && !values.isEmpty() )
{
return values.get( 0 ).toString();
}
return null;
}
/**
* Concatenates a list of string values.
* Values are separated by a comma and a space (", ").
*
* @param list
* @return
*/
public static String concatenate( List<String> list )
{
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for ( String string : list )
{
if ( isFirst )
{
isFirst = false;
}
else
{
sb.append( ", " );
}
sb.append( string );
}
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/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.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.config;
import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.util.tree.DnNode;
import org.apache.directory.studio.openldap.config.model.io.ConfigurationException;
import org.apache.directory.studio.openldap.config.model.io.ConfigurationUtils;
/**
* This class implements an reader for an expanded LDIF format.
* <p>
* This format consists in a hierarchy ldif files, each one representing an entry,
* and hierarchically organized in associated directories.
* <p>
* NOTE: This implementation is specific to the OpenLDAP "slapd.d" directory.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ExpandedLdifUtils
{
private ExpandedLdifUtils()
{
// Nothing to do
}
/** The LDIF file extension (.ldif) */
private static final String LDIF_FILE_EXTENSION = ".ldif";
/** A filter used to pick all the LDIF files */
private static FileFilter ldifFileFilter = dir ->
{
if ( dir.getName().endsWith( LDIF_FILE_EXTENSION ) )
{
return dir.isFile();
}
else
{
return false;
}
};
/**
* Reads the given directory location.
*
* @param directory the directory
* @return the corresponding node hierarchy
* @throws IOException if an error occurred
*/
public static DnNode<Entry> read( File directory ) throws IOException, LdapException
{
DnNode<Entry> tree = new DnNode<>();
readDirectory( directory, Dn.EMPTY_DN, tree );
return tree;
}
/**
* Reads the given directory.
*
* @param directory the directory
* @param tree the tree
* @return the corresponding node
* @throws IOException
* @throws LdapException
*/
private static void readDirectory( File directory, Dn parentDn, DnNode<Entry> tree ) throws IOException,
LdapException
{
if ( directory != null )
{
// Checking if the directory exists
if ( !directory.exists() )
{
throw new IOException( "Location '" + directory + "' does not exist." );
}
// Checking if the directory is a directory
if ( !directory.isDirectory() )
{
throw new IOException( "Location '" + directory + "' is not a directory." );
}
// Checking if the directory is readable
if ( !directory.canRead() )
{
throw new IOException( "Directory '" + directory + "' can not be read." );
}
// Getting the array of ldif files
File[] ldifFiles = directory.listFiles( ldifFileFilter );
if ( ( ldifFiles != null ) && ( ldifFiles.length != 0 ) )
{
try ( LdifReader ldifReader = new LdifReader() )
{
// Looping on LDIF files
for ( File ldifFile : ldifFiles )
{
// Checking if the LDIF file is a file
if ( !ldifFile.isFile() )
{
throw new IOException( "Location '" + ldifFile + "' is not a file." );
}
// Checking if the LDIF file is readable
if ( !ldifFile.canRead() )
{
throw new IOException( "LDIF file '" + ldifFile + "' can not be read." );
}
// Computing the DN of the entry
Dn entryDn = parentDn.add( stripExtension( ldifFile.getName() ) );
// Reading the LDIF file
List<LdifEntry> ldifEntries = null;
try
{
ldifEntries = ldifReader.parseLdifFile( ldifFile.getAbsolutePath() );
}
finally
{
ldifReader.close();
}
// The LDIF file should have only one entry
if ( ( ldifEntries != null ) && ( ldifEntries.size() == 1 ) )
{
// Getting the LDIF entry
LdifEntry ldifEntry = ldifEntries.get( 0 );
if ( ldifEntry != null )
{
// Getting the entry
Entry entry = ldifEntry.getEntry();
if ( entry != null )
{
// Refactoring the DN to set the "FULL" DN of the entry
entry.setDn( entryDn );
// Creating the new entry node
tree.add( entryDn, entry );
// Creating a file without the LDIF extension (corresponding to children directory)
File childrenDirectoryFile = new File( stripExtension( ldifFile.getAbsolutePath() ) );
// If the directory exists, recursively read it
if ( childrenDirectoryFile.exists() )
{
readDirectory( childrenDirectoryFile, entryDn, tree );
}
}
}
}
}
}
}
}
}
/**
* Strips the file extension.
*
* @param path the path
* @return the path without the file extension
*/
private static String stripExtension( String path )
{
if ( ( path != null ) && ( path.length() > 0 ) )
{
return path.substring( 0, path.lastIndexOf( '.' ) );
}
return null;
}
/**
* Writes the given tree to the directory.
*
* @param tree the tree
* @param directory the directory
* @throws IOException if an error occurs
*/
public static void write( DnNode<Entry> tree, File directory ) throws IOException
{
try
{
Dn rootDn = ConfigurationUtils.getDefaultConfigurationDn();
write( tree, rootDn, directory );
}
catch ( ConfigurationException e )
{
throw new IOException( e );
}
}
/**
* Writes the entry and its children from the given tree and DN, to the directory.
*
* @param tree the tree
* @param dn the dn of the entry
* @param directory the directory
* @throws IOException if an error occurs
*/
public static void write( DnNode<Entry> tree, Dn dn, File directory ) throws IOException
{
// Checking if the directory is null
if ( directory == null )
{
throw new IOException( "Location is 'null'." );
}
// Checking if the directory exists
if ( !directory.exists() )
{
throw new IOException( "Location '" + directory + "' does not exist." );
}
// Checking if the directory is a directory
if ( !directory.isDirectory() )
{
throw new IOException( "Location '" + directory + "' is not a directory." );
}
// Checking if the directory is writable
if ( !directory.canWrite() )
{
throw new IOException( "Directory '" + directory + "' can not be written." );
}
// Getting the entry node
DnNode<Entry> node = tree.getNode( dn );
// Only creating a file if the node contains an entry
if ( node.hasElement() )
{
// Getting the entry
Entry entry = node.getElement();
// Getting the DN of the entry
Dn entryDn = entry.getDn();
// Setting the RDN as DN (specific to OpenLDAP implementation)
try
{
entry.setDn( new Dn( entryDn.getRdn() ) );
}
catch ( LdapInvalidDnException e )
{
throw new IOException( e );
}
// Writing the LDIF file to the disk
try ( FileWriter fw = new FileWriter( new File( directory, getLdifFilename( entry.getDn() ) ) ) )
{
fw.write( new LdifEntry( entry ).toString() );
}
// Checking if the entry has children
if ( node.hasChildren() )
{
// Creating the child directory on disk
File childDirectory = new File( directory, getFilename( entry.getDn() ) );
childDirectory.mkdir();
// Iterating on all children
for ( DnNode<Entry> childNode : node.getChildren().values() )
{
if ( childNode.hasElement() )
{
// Recursively call the method with the child node and directory
write( tree, childNode.getDn(), childDirectory );
}
}
}
}
}
/**
* Gets the filename for the given DN.
*
* @param dn the DN
* @return the associated LDIF filename
*/
private static String getLdifFilename( Dn dn )
{
String filename = getFilename( dn );
if ( filename != null )
{
return filename + LDIF_FILE_EXTENSION;
}
return null;
}
/**
* Gets the filename for the given DN.
*
* @param dn the DN
* @return the associated LDIF filename
*/
private static String getFilename( Dn dn )
{
if ( ( dn != null ) && ( dn.size() > 0 ) )
{
return dn.getRdn().toString();
}
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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ConnectionSchemaLoader.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ConnectionSchemaLoader.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.config;
import java.io.IOException;
import java.util.List;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.ObjectClass;
import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum;
import org.apache.directory.api.ldap.model.schema.SchemaObject;
import org.apache.directory.api.ldap.model.schema.UsageEnum;
import org.apache.directory.api.ldap.model.schema.registries.DefaultSchema;
import org.apache.directory.api.ldap.model.schema.registries.Schema;
import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader;
import org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader;
import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
/**
* This class implements a {@link SchemaLoader} based on a connection to an OpenLDAP
* server, as well as a set of low level base schemas from ApacheDS.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class ConnectionSchemaLoader extends JarLdifSchemaLoader
{
private static final String M_COLLECTIVE = "m-collective";
private static final String M_DESCRIPTION = "m-description";
private static final String M_EQUALITY = "m-equality";
private static final String M_LENGTH = "m-length";
private static final String M_MAY = "m-may";
private static final String M_MUST = "m-must";
private static final String M_NAME = "m-name";
private static final String M_NO_USER_MODIFICATION = "m-noUserModification";
private static final String M_OBSOLETE = "m-obsolete";
private static final String M_OID = "m-oid";
private static final String M_ORDERING = "m-ordering";
private static final String M_SINGLE_VALUE = "m-singleValue";
private static final String M_SUBSTR = "m-substr";
private static final String M_SUP_ATTRIBUTE_TYPE = "m-supAttributeType";
private static final String M_SUP_OBJECT_CLASS = "m-supObjectClass";
private static final String M_SYNTAX = "m-syntax";
private static final String M_TYPE_OBJECT_CLASS = "m-typeObjectClass";
private static final String M_USAGE = "m-usage";
private static final String TRUE = "TRUE";
/** The name of the connection schema */
public static final String CONNECTION_SCHEMA_NAME = "connectionSchema";
/** The configuration prefix */
private static final String CONFIG_PREFIX = "olc";
/** The schema */
private org.apache.directory.studio.ldapbrowser.core.model.schema.Schema browserConnectionSchema;
/**
* Creates a new instance of ConnectionSchemaLoader.
*
* @param connection the connection
* @throws Exception
*/
public ConnectionSchemaLoader( Connection connection ) throws Exception
{
super();
// Getting the browser connection associated with the connection
browserConnectionSchema = BrowserCorePlugin.getDefault().getConnectionManager()
.getBrowserConnection( connection ).getSchema();
initializeSchema();
}
/**
* Initializes the schema.
*/
private void initializeSchema()
{
Schema schema = new DefaultSchema( null, CONNECTION_SCHEMA_NAME );
schema.addDependencies( "system", "core", "apache" );
schemaMap.put( schema.getSchemaName(), schema );
}
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException, IOException
{
List<Entry> attributeTypes = super.loadAttributeTypes( schemas );
for ( Schema schema : schemas )
{
if ( CONNECTION_SCHEMA_NAME.equals( schema.getSchemaName() ) )
{
for ( AttributeType attributeType : browserConnectionSchema.getAttributeTypeDescriptions() )
{
if ( attributeType.getName().startsWith( CONFIG_PREFIX ) )
{
attributeTypes.add( convert( attributeType ) );
}
}
}
}
return attributeTypes;
}
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException, IOException
{
List<Entry> objectClasses = super.loadObjectClasses( schemas );
for ( Schema schema : schemas )
{
if ( CONNECTION_SCHEMA_NAME.equals( schema.getSchemaName() ) )
{
for ( ObjectClass objectClass : browserConnectionSchema.getObjectClassDescriptions() )
{
if ( objectClass.getName().startsWith( CONFIG_PREFIX ) )
{
objectClasses.add( convert( objectClass ) );
}
}
}
}
return objectClasses;
}
/**
* Converts the given attribute type to a schema entry.
*
* @param attributeType the attribute type
* @return the given attribute type as a schema entry.
* @throws LdapException
*/
private Entry convert( AttributeType attributeType ) throws LdapException
{
// Creating a blank entry
Entry entry = new DefaultEntry();
// Setting calculated DN
entry.setDn( getDn( attributeType, SchemaConstants.ATTRIBUTE_TYPES_PATH ) );
// Values common to all schema objects
addSchemaObjectValues( attributeType, SchemaConstants.META_ATTRIBUTE_TYPE_OC, entry );
// Superior value
addSuperiorValue( attributeType, entry );
// Equality matching rule value
addEqualityValue( attributeType, entry );
// Ordering matching rule value
addOrderingValue( attributeType, entry );
// Substrings matching rule value
addSubstrValue( attributeType, entry );
// Syntax value
addSyntaxValue( attributeType, entry );
// Single value value
addSingleValueValue( attributeType, entry );
// Collective value
addCollectiveValue( attributeType, entry );
// No user modification value
addNoUserModificationValue( attributeType, entry );
// Usage value
addUsageValue( attributeType, entry );
return entry;
}
/**
* Converts the given object class to a schema entry.
*
* @param objectClass the object class
* @return the given object class as a schema entry.
* @throws LdapException
*/
private Entry convert( ObjectClass objectClass ) throws LdapException
{
// Creating a blank entry
Entry entry = new DefaultEntry();
// Setting calculated DN
entry.setDn( getDn( objectClass, SchemaConstants.OBJECT_CLASSES_PATH ) );
// Values common to all schema objects
addSchemaObjectValues( objectClass, SchemaConstants.META_OBJECT_CLASS_OC, entry );
// Superiors value
addSuperiorsValue( objectClass, entry );
// Class type value
addClassTypeValue( objectClass, entry );
// Musts value
addMustsValue( objectClass, entry );
// Mays value
addMaysValue( objectClass, entry );
return entry;
}
/**
* Gets the DN associated with the given schema object in the given container.
*
* @param so the schema object
* @param container the container
* @return the DN associated with the given schema object in the given container.
* @throws LdapInvalidDnException
*/
private Dn getDn( SchemaObject so, String container ) throws LdapInvalidDnException, LdapInvalidAttributeValueException
{
return Dn.EMPTY_DN
.add( new Rdn( SchemaConstants.OU_SCHEMA ) )
.add( new Rdn( SchemaConstants.CN_AT, Rdn.escapeValue( CONNECTION_SCHEMA_NAME ) ) )
.add( new Rdn( container ) )
.add( new Rdn( "m-oid", so.getOid() ) );
}
/**
* Adds the values common to all {@link SchemaObject}(s) to the entry.
*
* @param schemaObject the schema object
* @param objectClassValue the value for the objectClass attribute
* @param entry the entry
* @throws LdapException
*/
private static void addSchemaObjectValues( SchemaObject schemaObject, String objectClassValue, Entry entry )
throws LdapException
{
// ObjectClass
addObjectClassValue( schemaObject, objectClassValue, entry );
// OID
addOidValue( schemaObject, entry );
// Names
addNamesValue( schemaObject, entry );
// Description
addDescriptionValue( schemaObject, entry );
// Obsolete
addObsoleteValue( schemaObject, entry );
}
/**
* Adds the objectClass value to the entry.
*
* @param schemaObject the schema object
* @param objectClassValue the value for the objectClass attribute
* @param entry the entry
* @throws LdapException
*/
private static void addObjectClassValue( SchemaObject schemaObject, String objectClassValue, Entry entry )
throws LdapException
{
Attribute objectClassAttribute = new DefaultAttribute( SchemaConstants.OBJECT_CLASS_AT );
entry.add( objectClassAttribute );
objectClassAttribute.add( SchemaConstants.TOP_OC );
objectClassAttribute.add( SchemaConstants.META_TOP_OC );
objectClassAttribute.add( objectClassValue );
}
/**
* Adds the OID value to the entry.
*
* @param schemaObject the schema object
* @param entry the entry
* @throws LdapException
*/
private static void addOidValue( SchemaObject schemaObject, Entry entry ) throws LdapException
{
String oid = schemaObject.getOid();
if ( !Strings.isEmpty( oid ) )
{
Attribute attribute = new DefaultAttribute( M_OID, oid );
entry.add( attribute );
}
}
/**
* Adds the names value to the entry.
*
* @param schemaObject the schema object
* @param entry the entry
* @throws LdapException
*/
private static void addNamesValue( SchemaObject schemaObject, Entry entry ) throws LdapException
{
List<String> names = schemaObject.getNames();
if ( ( names != null ) && !names.isEmpty() )
{
Attribute attribute = new DefaultAttribute( M_NAME );
entry.add( attribute );
for ( String name : names )
{
attribute.add( name );
}
}
}
/**
* Adds the description value to the entry.
*
* @param schemaObject the schema object
* @param entry the entry
* @throws LdapException
*/
private static void addDescriptionValue( SchemaObject schemaObject, Entry entry ) throws LdapException
{
String description = schemaObject.getDescription();
if ( !Strings.isEmpty( description ) )
{
Attribute attribute = new DefaultAttribute( M_DESCRIPTION, description );
entry.add( attribute );
}
}
/**
* Adds the obsolete value to the entry.
*
* @param schemaObject the schema object
* @param entry the entry
* @throws LdapException
*/
private static void addObsoleteValue( SchemaObject schemaObject, Entry entry ) throws LdapException
{
if ( schemaObject.isObsolete() )
{
Attribute attribute = new DefaultAttribute( M_OBSOLETE, TRUE );
entry.add( attribute );
}
}
/**
* Adds the superior value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addSuperiorValue( AttributeType attributeType, Entry entry ) throws LdapException
{
String superior = attributeType.getSuperiorName();
if ( !Strings.isEmpty( superior ) )
{
Attribute attribute = new DefaultAttribute( M_SUP_ATTRIBUTE_TYPE, superior );
entry.add( attribute );
}
}
/**
* Adds the equality matching rule value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addEqualityValue( AttributeType attributeType, Entry entry ) throws LdapException
{
String equality = attributeType.getEqualityName();
if ( !Strings.isEmpty( equality ) )
{
Attribute attribute = new DefaultAttribute( M_EQUALITY, equality );
entry.add( attribute );
}
}
/**
* Adds the ordering matching rule value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addOrderingValue( AttributeType attributeType, Entry entry ) throws LdapException
{
String ordering = attributeType.getOrderingName();
if ( !Strings.isEmpty( ordering ) )
{
Attribute attribute = new DefaultAttribute( M_ORDERING, ordering );
entry.add( attribute );
}
}
/**
* Adds the substring matching rule value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addSubstrValue( AttributeType attributeType, Entry entry ) throws LdapException
{
String substr = attributeType.getSubstringName();
if ( !Strings.isEmpty( substr ) )
{
Attribute attribute = new DefaultAttribute( M_SUBSTR, substr );
entry.add( attribute );
}
}
/**
* Adds the syntax value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addSyntaxValue( AttributeType attributeType, Entry entry ) throws LdapException
{
String syntax = attributeType.getSyntaxName();
if ( !Strings.isEmpty( syntax ) )
{
Attribute attribute = new DefaultAttribute( M_SYNTAX, syntax );
entry.add( attribute );
long syntaxLength = attributeType.getSyntaxLength();
if ( syntaxLength != -1 )
{
attribute = new DefaultAttribute( M_LENGTH, Long.toString( syntaxLength ) );
entry.add( attribute );
}
}
}
/**
* Adds the single value value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addSingleValueValue( AttributeType attributeType, Entry entry ) throws LdapException
{
if ( attributeType.isSingleValued() )
{
Attribute attribute = new DefaultAttribute( M_SINGLE_VALUE, TRUE );
entry.add( attribute );
}
}
/**
* Adds the collective value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addCollectiveValue( AttributeType attributeType, Entry entry ) throws LdapException
{
if ( attributeType.isCollective() )
{
Attribute attribute = new DefaultAttribute( M_COLLECTIVE, TRUE );
entry.add( attribute );
}
}
/**
* Adds the no user modification value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addNoUserModificationValue( AttributeType attributeType, Entry entry ) throws LdapException
{
if ( !attributeType.isUserModifiable() )
{
Attribute attribute = new DefaultAttribute( M_NO_USER_MODIFICATION, TRUE );
entry.add( attribute );
}
}
/**
* Adds the usage value.
*
* @param attributeType the attribute type
* @param entry the entry
* @throws LdapException
*/
private static void addUsageValue( AttributeType attributeType, Entry entry ) throws LdapException
{
UsageEnum usage = attributeType.getUsage();
if ( usage != UsageEnum.USER_APPLICATIONS )
{
Attribute attribute = new DefaultAttribute( M_USAGE, usage.render() );
entry.add( attribute );
}
}
/**
* Adds the superiors value.
*
* @param objectClass the object class
* @param entry the entry
* @throws LdapException
*/
private static void addSuperiorsValue( ObjectClass objectClass, Entry entry ) throws LdapException
{
List<String> superiors = objectClass.getSuperiorOids();
if ( ( superiors != null ) && !superiors.isEmpty() )
{
Attribute attribute = new DefaultAttribute( M_SUP_OBJECT_CLASS );
entry.add( attribute );
for ( String superior : superiors )
{
attribute.add( superior );
}
}
}
/**
* Adds class type value.
*
* @param objectClass the object class
* @param entry the entry
* @throws LdapException
*/
private static void addClassTypeValue( ObjectClass objectClass, Entry entry ) throws LdapException
{
ObjectClassTypeEnum classType = objectClass.getType();
if ( classType != ObjectClassTypeEnum.STRUCTURAL )
{
Attribute attribute = new DefaultAttribute( M_TYPE_OBJECT_CLASS, classType.toString() );
entry.add( attribute );
}
}
/**
* Adds musts value.
*
* @param objectClass the object class
* @param entry the entry
* @throws LdapException
*/
private static void addMustsValue( ObjectClass objectClass, Entry entry ) throws LdapException
{
List<String> musts = objectClass.getMustAttributeTypeOids();
if ( ( musts != null ) && !musts.isEmpty() )
{
Attribute attribute = new DefaultAttribute( M_MUST );
entry.add( attribute );
for ( String must : musts )
{
attribute.add( must );
}
}
}
/**
* Adds mays value.
*
* @param objectClass the object class
* @param entry the entry
* @throws LdapException
*/
private static void addMaysValue( ObjectClass objectClass, Entry entry ) throws LdapException
{
List<String> mays = objectClass.getMayAttributeTypeOids();
if ( ( mays != null ) && !mays.isEmpty() )
{
Attribute attribute = new DefaultAttribute( M_MAY );
entry.add( attribute );
for ( String may : mays )
{
attribute.add( may );
}
}
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapSchemaLoader.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapSchemaLoader.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.config;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
import org.apache.directory.api.ldap.model.schema.registries.Schema;
import org.apache.directory.api.ldap.model.schema.registries.DefaultSchema;
import org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader;
/**
* This class implements a {@link SchemaLoader} based on the OpenLDAP schema bundled
* with the class, as well as a set of low level base schemas from ApacheDS.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OpenLdapSchemaLoader extends JarLdifSchemaLoader
{
/** The name of the OpenLDAP Config schema */
public static final String OPENLDAPCONFIG_SCHEMA_NAME = "openldapconfig";
/** The name of the LDIF file for the OpenLDAP Config schema */
private static final String OPENLDAPCONFIG_SHEMA_LDIF = "openldapconfig.ldif";
/** The attribute type pattern */
private static final Pattern ATTRIBUTE_TYPE_PATTERN = Pattern.compile( "m-oid\\s*=\\s*[0-9\\.]*\\s*"
+ ",\\s*ou\\s*=\\s*attributetypes\\s*,\\s*cn\\s*=\\s*" + OPENLDAPCONFIG_SCHEMA_NAME + "\\s*,\\s*ou=schema\\s*",
Pattern.CASE_INSENSITIVE );
/** The object class pattern */
private static final Pattern OBJECT_CLASS_PATTERN = Pattern.compile( "m-oid\\s*=\\s*[0-9\\.]*\\s*"
+ ",\\s*ou\\s*=\\s*objectclasses\\s*,\\s*cn\\s*=\\s*" + OPENLDAPCONFIG_SCHEMA_NAME + "\\s*,\\s*ou=schema\\s*",
Pattern.CASE_INSENSITIVE );
/** The attribute types entries */
private List<Entry> attributeTypesEntries = new ArrayList<>();
/** The object classes entries */
private List<Entry> objectClassesEntries = new ArrayList<>();
/**
* Creates a new instance of ConnectionSchemaLoader.
*
* @throws Exception
*/
public OpenLdapSchemaLoader() throws Exception
{
super();
initializeSchema();
initializeSchemaObjects();
}
/**
* Initializes the schema. We will load 'system', 'core' and 'apache'.
*/
private void initializeSchema()
{
Schema schema = new DefaultSchema( this, OPENLDAPCONFIG_SCHEMA_NAME );
schema.addDependencies( "system", "core", "apache" );
schemaMap.put( schema.getSchemaName(), schema );
}
/**
* Initializes the schema objects.
*
* @throws LdapException If we weren't able to process the LDIF file
* @throws IOException If we had an issue reading the ldif file
*/
private void initializeSchemaObjects() throws LdapException, IOException
{
// Reading the schema file
try ( LdifReader ldifReader = new LdifReader( OpenLdapSchemaLoader.class.getResourceAsStream( OPENLDAPCONFIG_SHEMA_LDIF ) ) )
{
// Looping on all entries
while ( ldifReader.hasNext() )
{
// Getting the LDIF entry and DN
Entry entry = ldifReader.next().getEntry();
String dn = entry.getDn().getName();
// Checking if the entry is an attribute type
if ( ATTRIBUTE_TYPE_PATTERN.matcher( dn ).matches() )
{
attributeTypesEntries.add( entry );
}
// Checking if the entry is an object class
else if ( OBJECT_CLASS_PATTERN.matcher( dn ).matches() )
{
objectClassesEntries.add( entry );
}
}
}
}
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException, IOException
{
// Getting the attribute types from the supertype implementation
List<Entry> attributeTypes = super.loadAttributeTypes( schemas );
for ( Schema schema : schemas )
{
// Checking if this is the OpenLDAP schema
if ( OPENLDAPCONFIG_SCHEMA_NAME.equals( schema.getSchemaName() ) )
{
// Add all attribute types
attributeTypes.addAll( attributeTypesEntries );
}
}
return attributeTypes;
}
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException, IOException
{
// Getting the object classes from the supertype implementation
List<Entry> objectClasses = super.loadObjectClasses( schemas );
for ( Schema schema : schemas )
{
// Checking if this is the OpenLDAP schema
if ( OPENLDAPCONFIG_SCHEMA_NAME.equals( schema.getSchemaName() ) )
{
// Add all object classes
objectClasses.addAll( objectClassesEntries );
}
}
return objectClasses;
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/Messages.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/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.config;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class Messages
{
private static final String BUNDLE_NAME = "org.apache.directory.studio.openldap.config"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginConstants.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginConstants.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.config;
/**
* This interface contains all the Constants used in the Plugin.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface OpenLdapConfigurationPluginConstants
{
/** The plug-in ID */
String PLUGIN_ID = OpenLdapConfigurationPluginConstants.class.getPackage().getName();
// ------
// IMAGES
// ------
String IMG_ATTRIBUTE = "resources/icons/attribute.gif"; //$NON-NLS-1$
String IMG_DATABASE = "resources/icons/database.gif"; //$NON-NLS-1$
String IMG_DISABLED_DATABASE = "resources/icons/disabledDatabase.gif"; //$NON-NLS-1$
String IMG_EDITOR = "resources/icons/editor.gif"; //$NON-NLS-1$
String IMG_EXPORT = "resources/icons/export.gif"; //$NON-NLS-1$
String IMG_INDEX = "resources/icons/index.png"; //$NON-NLS-1$
String IMG_INFORMATION = "resources/icons/information.gif"; //$NON-NLS-1$
String IMG_IMPORT = "resources/icons/import.gif"; //$NON-NLS-1$
String IMG_OVERLAY = "resources/icons/overlay.gif"; //$NON-NLS-1$
String IMG_LDAP_SERVER = "resources/icons/server.gif"; //$NON-NLS-1$
public static final String WIZARD_NEW_OPENLDAP_CONFIG = OpenLdapConfigurationPlugin.getDefault().getPluginProperties()
.getString( "NewWizards_NewOpenLdapConfigurationFileWizard_id" ); //$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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/PartitionsDiffComputer.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/PartitionsDiffComputer.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.config.jobs;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import org.apache.directory.api.ldap.model.constants.LdapConstants;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.DefaultModification;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Modification;
import org.apache.directory.api.ldap.model.entry.ModificationOperation;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
import org.apache.directory.api.ldap.model.filter.FilterParser;
import org.apache.directory.api.ldap.model.ldif.ChangeType;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.message.AliasDerefMode;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.UsageEnum;
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
/**
* An utility class that computes the difference between two Partitions.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PartitionsDiffComputer
{
private PartitionsDiffComputer()
{
// Nothing to do
}
/**
* Compute the difference between two partitions :
* <ul>
* <li>Added entries</li>
* <li>Removed entries</li>
* <li>Modified entries
* <ul>
* <li>Added Attributes</li>
* <li>Removed Attributes</li>
* <li>Modified Attributes
* <ul>
* <li>Added Values</li>
* <li>Removed Values</li>
* </ul>
* </li>
* </ul>
* </li>
* </ul>
* @param originalPartition The original partition
* @param modifiedPartition The modified partition
* @return A list of LDIF Additions, Deletions or Modifications
* @throws Exception If something went wrong
*/
public static List<LdifEntry> computeModifications( Partition originalPartition, Partition modifiedPartition ) throws Exception
{
// '*' for all user attributes, '+' for all operational attributes
return computeModifications( originalPartition, modifiedPartition, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
}
/**
* Compute the difference between two partitions :
* <ul>
* <li>Added entries</li>
* <li>Removed entries</li>
* <li>Modified entries
* <ul>
* <li>Added Attributes</li>
* <li>Removed Attributes</li>
* <li>Modified Attributes
* <ul>
* <li>Added Values</li>
* <li>Removed Values</li>
* </ul>
* </li>
* </ul>
* </li>
* </ul>
* @param originalPartition The original partition
* @param modifiedPartition The modified partition
* @param attributeIds The list of attributes we want to compare
* @return A list of LDIF Additions, Deletions or Modifications
* @throws Exception If something went wrong
*/
public static List<LdifEntry> computeModifications( Partition originalPartition, Partition modifiedPartition, String[] attributeIds ) throws Exception
{
return computeModifications( originalPartition, modifiedPartition, originalPartition.getSuffixDn(), attributeIds );
}
/**
* Compute the actual diff.
*/
private static List<LdifEntry> computeModifications( Partition originalPartition, Partition modifiedPartition, Dn baseDn, String[] attributeIds ) throws Exception
{
// Checking partitions
checkPartitions( originalPartition, modifiedPartition );
return comparePartitions( originalPartition, modifiedPartition, baseDn, attributeIds );
}
/**
* Checks the partitions.
*/
private static void checkPartitions( Partition originalPartition, Partition modifiedPartition ) throws PartitionsDiffException
{
// Checking the original partition
if ( originalPartition == null )
{
throw new PartitionsDiffException( "The original partition must not be 'null'." );
}
else
{
if ( !originalPartition.isInitialized() )
{
throw new PartitionsDiffException( "The original partition must be intialized." );
}
else if ( originalPartition.getSuffixDn() == null )
{
throw new PartitionsDiffException( "The original suffix is null." );
}
}
// Checking the destination partition
if ( modifiedPartition == null )
{
throw new PartitionsDiffException( "The modified partition must not be 'null'." );
}
else
{
if ( !modifiedPartition.isInitialized() )
{
throw new PartitionsDiffException( "The modified partition must be intialized." );
}
else if ( modifiedPartition.getSuffixDn() == null )
{
throw new PartitionsDiffException( "The modified suffix is null." );
}
}
}
/**
* Compare two partitions.
*
* @param originalPartition The original partition
* @param modifiedPartition The modified partition
* @param baseDn the Dn from which we will iterate
* @param attributeIds the IDs of the attributes we will compare
* @return a list containing LDIF entries with all modifications
* @throws Exception If something went wrong
*/
public static List<LdifEntry> comparePartitions( Partition originalPartition, Partition modifiedPartition,
Dn baseDn, String[] attributeIds ) throws PartitionsDiffException
{
// Creating the list containing all the modifications
List<LdifEntry> modifications = new ArrayList<>();
try
{
// Looking up the original base entry
Entry originalBaseEntry = originalPartition.lookup( new LookupOperationContext( null, baseDn, attributeIds ) );
if ( originalBaseEntry == null )
{
throw new PartitionsDiffException( "Unable to find the base entry in the original partition." );
}
// Creating the list containing all the original entries to be processed
// and adding it the original base entry. This is done going down the tree.
List<Entry> originalEntries = new ArrayList<>();
originalEntries.add( originalBaseEntry );
// Looping until all original entries are being processed. We will read all the children,
// adding each of them at the end of the list, consuming the first element of the list
// at every iteration. When we have processed all the tree in depth, we should not have
// any left entries in the list.
// We don't dereference aliases and referrals.
while ( !originalEntries.isEmpty() )
{
// Getting the first original entry from the list
Entry originalEntry = originalEntries.remove( 0 );
// Creating a modification entry to hold all modifications
LdifEntry ldifEntry = new LdifEntry();
ldifEntry.setDn( originalEntry.getDn() );
// Looking for the equivalent entry in the destination partition
Entry modifiedEntry = modifiedPartition.lookup( new LookupOperationContext( null, originalEntry
.getDn(), attributeIds ) );
if ( modifiedEntry != null )
{
// Setting the changeType to Modify atm
ldifEntry.setChangeType( ChangeType.Modify );
// Comparing both entries
compareEntries( originalEntry, modifiedEntry, ldifEntry );
}
else
{
// The entry has been deleted from the partition. It has to be deleted.
// Note : we *must* delete all of it's children first !!!
List<LdifEntry> deletions = deleteEntry( originalPartition, originalEntry.getDn() );
// Append the children
modifications.addAll( deletions );
// and add the parent entry
ldifEntry.setChangeType( ChangeType.Delete );
// And go on with the remaining entries
continue;
}
// Checking if modifications occurred on the original entry
ChangeType modificationEntryChangeType = ldifEntry.getChangeType();
if ( modificationEntryChangeType != ChangeType.None )
{
if ( modificationEntryChangeType == ChangeType.Delete
|| ( modificationEntryChangeType == ChangeType.Modify && !ldifEntry.getModifications().isEmpty() ) )
{
// Adding the modification entry to the list
modifications.add( ldifEntry );
}
}
// Creating a search operation context to get the children of the current entry
SearchOperationContext soc = new SearchOperationContext( null, originalEntry.getDn(),
SearchScope.ONELEVEL,
FilterParser.parse( originalPartition.getSchemaManager(), LdapConstants.OBJECT_CLASS_STAR ), attributeIds );
soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
// Looking for the children of the current entry
EntryFilteringCursor cursor = originalPartition.search( soc );
while ( cursor.next() )
{
originalEntries.add( cursor.get() );
}
}
// Now, iterate on the modified partition, to see if some entries have
// been added.
Entry destinationBaseEntry = modifiedPartition
.lookup( new LookupOperationContext( null, baseDn, attributeIds ) );
if ( destinationBaseEntry == null )
{
throw new PartitionsDiffException( "Unable to find the base entry in the destination partition." );
}
// Creating the list containing all the destination entries to be processed
// and adding it the destination base entry
List<Entry> modifiedEntries = new ArrayList<>();
modifiedEntries.add( originalBaseEntry );
// Looping until all modified entries are being processed
while ( !modifiedEntries.isEmpty() )
{
// Getting the first modification entry from the list
Entry modifiedEntry = modifiedEntries.remove( 0 );
// Looking for the equivalent entry in the destination partition
Entry originalEntry = originalPartition.lookup( new LookupOperationContext( null, modifiedEntry
.getDn(), attributeIds ) );
// We're only looking for new entries, modified or removed
// entries have already been computed
if ( originalEntry == null )
{
// Creating a modification entry to hold all modifications
LdifEntry modificationEntry = new LdifEntry();
modificationEntry.setDn( modifiedEntry.getDn() );
// Setting the changeType to addition
modificationEntry.setChangeType( ChangeType.Add );
// Copying attributes
for ( Attribute attribute : modifiedEntry )
{
modificationEntry.addAttribute( attribute );
}
// Adding the modification entry to the list
modifications.add( modificationEntry );
}
// Creating a search operation context to get the children of the current entry
SearchOperationContext soc = new SearchOperationContext( null, modifiedEntry.getDn(),
SearchScope.ONELEVEL,
FilterParser.parse( originalPartition.getSchemaManager(), LdapConstants.OBJECT_CLASS_STAR ), attributeIds );
soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
// Looking for the children of the current entry
EntryFilteringCursor cursor = modifiedPartition.search( soc );
while ( cursor.next() )
{
modifiedEntries.add( cursor.get() );
}
}
}
catch ( Exception e )
{
throw new PartitionsDiffException( e );
}
return modifications;
}
/**
* Delete recursively the entries under a parent
*/
private static List<LdifEntry> deleteEntry( Partition originalPartition, Dn parentDn ) throws LdapException, ParseException, CursorException
{
List<LdifEntry> deletions = new ArrayList<>();
// Lookup for the children
SearchOperationContext soc = new SearchOperationContext( null, parentDn,
SearchScope.ONELEVEL,
FilterParser.parse( originalPartition.getSchemaManager(), LdapConstants.OBJECT_CLASS_STAR ), SchemaConstants.NO_ATTRIBUTE_ARRAY );
soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
// Looking for the children of the current entry
EntryFilteringCursor cursor = originalPartition.search( soc );
while ( cursor.next() )
{
LdifEntry deletion = new LdifEntry( cursor.get().getDn() );
// Iterate
List<LdifEntry> childrenDeletions = deleteEntry( originalPartition, deletion.getDn() );
deletions.addAll( childrenDeletions );
deletions.add( deletion );
}
return deletions;
}
/**
* Compares the two given entries.
*
* @param originalEntry the original entry
* @param modifiedEntry the destination entry
* @param modificationEntry the modification LDIF entry holding the modifications between both entries
* @throws LdapInvalidAttributeValueException
*/
private static void compareEntries( Entry originalEntry, Entry modifiedEntry, LdifEntry modificationEntry )
throws LdapInvalidAttributeValueException
{
// We loop on all the attributes of the original entries, to detect the
// modified ones and the deleted ones
for ( Attribute originalAttribute : originalEntry )
{
AttributeType originalAttributeType = originalAttribute.getAttributeType();
// We're only working on 'userApplications' attributes
if ( originalAttributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
{
Attribute modifiedAttribute = modifiedEntry.get( originalAttributeType );
if ( modifiedAttribute == null )
{
// The attribute has been deleted
// Creating a modification for the removed AT
Modification modification = new DefaultModification(
ModificationOperation.REMOVE_ATTRIBUTE, originalAttributeType );
modificationEntry.addModification( modification );
}
else
{
// Comparing both attributes
compareAttributes( originalAttribute, modifiedAttribute, modificationEntry );
}
}
}
// Now, check all the modified entry's attributes to see what are the added ones
for ( Attribute destinationAttribute : modifiedEntry )
{
AttributeType destinationAttributeType = destinationAttribute.getAttributeType();
// We're only working on 'userApplications' attributes
if ( destinationAttributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
{
// Checking if the current AT is not present in the original entry : if so,
// it has been added
if ( !originalEntry.containsAttribute( destinationAttributeType ) )
{
// Creating a modification for the added AT
Modification modification = new DefaultModification(
ModificationOperation.ADD_ATTRIBUTE,
destinationAttribute );
modificationEntry.addModification( modification );
}
}
}
}
/**
* Compares two attributes.
*
* @param originalAttribute the original attribute
* @param modifiedAttribute the destination attribute
* @param modificationEntry the modification LDIF entry holding the modifications between both attributes
*/
private static void compareAttributes( Attribute originalAttribute, Attribute modifiedAttribute,
LdifEntry modificationEntry )
{
// Special case for 'objectClass' attribute, due to a limitation in OpenLDAP
// which does not allow us to modify the 'objectClass' attribute
if ( !SchemaConstants.OBJECT_CLASS_AT.equalsIgnoreCase( originalAttribute.getAttributeType().getName() ) )
{
// Checking if the two attributes are equivalent
if ( !originalAttribute.equals( modifiedAttribute ) )
{
// Creating a modification for the modified AT values. We do that globally, for all the values
// The values should also be ordered if this is required (X-ORDERED)
Modification modification = new DefaultModification(
ModificationOperation.REPLACE_ATTRIBUTE, modifiedAttribute );
modificationEntry.addModification( modification );
}
}
}
}
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | false |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/PartitionsDiffException.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/PartitionsDiffException.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.config.jobs;
/**
* This exception can be raised when an error occurs when computing the diff
* between two partitions.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PartitionsDiffException extends Exception
{
private static final long serialVersionUID = 1L;
/**
* Constructs a new PartitionsDiffException with <code>null</code> as its detail message.
*/
public PartitionsDiffException()
{
super();
}
/**
* Constructs a new PartitionsDiffException with the specified detail message and cause.
*
* @param message
* the message
* @param cause
* the cause
*/
public PartitionsDiffException( String message, Throwable cause )
{
super( message, cause );
}
/**
* Constructs a new PartitionsDiffException with the specified detail message.
*
* @param message
* the message
*/
public PartitionsDiffException( String message )
{
super( message );
}
/**
* Constructs a new exception with the specified cause and a detail message
* of <code>(cause==null ? null : cause.toString())</code>
*
* @param cause
* the cause
*/
public PartitionsDiffException( Throwable cause )
{
super( cause );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/LoadConfigurationRunnable.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/LoadConfigurationRunnable.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.config.jobs;
import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.apache.directory.studio.openldap.config.editor.ConnectionServerConfigurationInput;
import org.apache.directory.studio.openldap.config.editor.DirectoryServerConfigurationInput;
import org.apache.directory.studio.openldap.config.editor.NewServerConfigurationInput;
import org.apache.directory.studio.openldap.config.editor.OpenLdapServerConfigurationEditor;
import org.apache.directory.studio.openldap.config.model.OlcGlobal;
import org.apache.directory.studio.openldap.config.model.OpenLdapConfiguration;
import org.apache.directory.studio.openldap.config.model.io.ConfigurationReader;
/**
* This class implements a {@link Job} that is used to load a server configuration.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LoadConfigurationRunnable implements StudioRunnableWithProgress
{
/** The associated editor */
private OpenLdapServerConfigurationEditor editor;
/**
* Creates a new instance of LoadConfigurationRunnable.
*
* @param editor the editor
*/
public LoadConfigurationRunnable( OpenLdapServerConfigurationEditor editor )
{
this.editor = editor;
}
/**
* {@inheritDoc}
*/
public String getErrorMessage()
{
return "Unable to load the configuration.";
}
/**
* {@inheritDoc}
*/
public Object[] getLockedObjects()
{
return new Object[0];
}
/**
* {@inheritDoc}
*/
public String getName()
{
return "Load Configuration";
}
/**
* {@inheritDoc}
*/
public void run( StudioProgressMonitor monitor )
{
IEditorInput input = editor.getEditorInput();
try
{
final OpenLdapConfiguration configuration = getConfiguration( input, monitor );
if ( configuration != null )
{
Display.getDefault().asyncExec( () -> editor.configurationLoaded( configuration ) );
}
}
catch ( Exception e )
{
// Reporting the error to the monitor
monitor.reportError( e );
// Reporting the error to the editor
final Exception exception = e;
Display.getDefault().asyncExec( () -> editor.configurationLoadFailed( exception ) );
}
}
/**
* Gets the configuration from the input. It may come from an existing connection,
* or from an existing file/directory on the disk, or a brand new configuration
*
* @param input the editor input
* @param monitor the studio progress monitor
* @return the configuration
* @throws Exception
*/
public OpenLdapConfiguration getConfiguration( IEditorInput input, StudioProgressMonitor monitor ) throws Exception
{
if ( input instanceof ConnectionServerConfigurationInput )
{
// If the input is a ConnectionServerConfigurationInput, then we
// read the server configuration from the selected connection
ConfigurationReader.readConfiguration( ( ConnectionServerConfigurationInput ) input );
}
else if ( input instanceof DirectoryServerConfigurationInput )
{
// If the input is a DirectoryServerConfigurationInput, then we
// read the server configuration from the selected 'slapd.d' directory.
return ConfigurationReader.readConfiguration( ( DirectoryServerConfigurationInput ) input );
}
else if ( input instanceof NewServerConfigurationInput )
{
// If the input is a NewServerConfigurationInput, then we only
// need to create a server configuration and return.
// The new configuration will be pretty empty, with just
// the main container (and the olcGlobal instance
OpenLdapConfiguration configuration = new OpenLdapConfiguration();
configuration.setGlobal( new OlcGlobal() );
return configuration;
}
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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/EntryBasedConfigurationPartition.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/jobs/EntryBasedConfigurationPartition.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.config.jobs;
import java.util.UUID;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition;
/**
* This class implements a read-only configuration partition.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class EntryBasedConfigurationPartition extends AbstractLdifPartition
{
/**
* Creates a new instance of EntryBasedConfigurationPartition.
*
* @param schemaManager the schema manager
* @param suffixDn the suffix DN
*/
public EntryBasedConfigurationPartition( SchemaManager schemaManager, Dn suffixDn )
{
super( schemaManager );
this.suffixDn = suffixDn;
}
/**
* {@inheritDoc}
*/
@Override
protected void doInit() throws LdapException
{
setId( "config" );
setSuffixDn( new Dn( "cn=config" ) );
super.doInit();
}
/**
* Adds the given entry.
*
* @param entry
* the entry
* @throws Exception
*/
public void addEntry( Entry entry ) throws Exception
{
// Adding mandatory operational attributes
addMandatoryOpAt( entry );
// Storing the entry
add( new AddOperationContext( null, entry ) );
}
/**
* Adds the CSN and UUID attributes to the entry if they are not present.
*/
private void addMandatoryOpAt( Entry entry ) throws LdapException
{
// entryCSN
if ( entry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
{
entry.add( SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString() );
}
// entryUUID
if ( entry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
{
String uuid = UUID.randomUUID().toString();
entry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
}
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcOverlayConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcOverlayConfig.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.config.model;
/**
* Java bean for the 'olcOverlayConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcOverlayConfig extends OlcConfig
{
/**
* Field for the 'olcDisabled' attribute. (Added in OpenLDAP 2.5.0)
*/
@ConfigurationElement(attributeType = "olcDisabled", version="2.5.0")
private Boolean olcDisabled;
/**
* Field for the 'olcOverlay' attribute.
*/
@ConfigurationElement(attributeType = "olcOverlay", isOptional = false, isRdn = true, version="2.4.0")
protected String olcOverlay;
/**
* Creates a new instance of OlcOverlayConfig.
*/
public OlcOverlayConfig()
{
}
/**
* Creates a copy instance of OlcOverlayConfig.
*
* @param o the initial object
*/
public OlcOverlayConfig( OlcOverlayConfig o )
{
olcOverlay = o.olcOverlay;
}
/**
* @return the olcDisabled
*/
public Boolean getOlcDisabled()
{
return olcDisabled;
}
/**
* @return the olcOverlay
*/
public String getOlcOverlay()
{
return olcOverlay;
}
/**
* @param oldDisabled the olcDisabled to set
*/
public void setOlcDisabled( Boolean olcDisabled )
{
this.olcDisabled = olcDisabled;
}
/**
* @param olcOverlay the olcOverlay to set
*/
public void setOlcOverlay( String olcOverlay )
{
this.olcOverlay = olcOverlay;
}
/**
* Gets a copy of this object.
*
* @return a copy of this object
*/
public OlcOverlayConfig copy()
{
return new OlcOverlayConfig( this );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcSchemaConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcSchemaConfig.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.config.model;
import java.util.ArrayList;
import java.util.List;
/**
* Java bean for the 'OlcSchemaConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcSchemaConfig extends OlcConfig
{
/**
* Field for the 'cn' attribute.
*/
@ConfigurationElement(attributeType = "cn", isRdn = true, version="2.4.0")
private List<String> cn = new ArrayList<>();
/**
* Field for the 'olcAttributeTypes' attribute.
*/
@ConfigurationElement(attributeType = "olcAttributeTypes", version="2.4.0")
private List<String> olcAttributeTypes = new ArrayList<>();
/**
* Field for the 'olcDitContentRules' attribute.
*/
@ConfigurationElement(attributeType = "olcDitContentRules", version="2.4.0")
private List<String> olcDitContentRules = new ArrayList<>();
/**
* Field for the 'olcLdapSyntaxes' attribute.
*/
@ConfigurationElement(attributeType = "olcLdapSyntaxes", version="2.4.12")
private List<String> olcLdapSyntaxes = new ArrayList<>();
/**
* Field for the 'olcObjectClasses' attribute.
*/
@ConfigurationElement(attributeType = "olcObjectClasses", version="2.4.0")
private List<String> olcObjectClasses = new ArrayList<>();
/**
* Field for the 'olcObjectIdentifier' attribute.
*/
@ConfigurationElement(attributeType = "olcObjectIdentifier", version="2.4.0")
private List<String> olcObjectIdentifier = new ArrayList<>();
public void clearCn()
{
cn.clear();
}
public void clearOlcAttributeTypes()
{
olcAttributeTypes.clear();
}
public void clearOlcDitContentRules()
{
olcDitContentRules.clear();
}
public void clearOlcLdapSyntaxes()
{
olcLdapSyntaxes.clear();
}
public void clearOlcObjectClasses()
{
olcObjectClasses.clear();
}
public void clearOlcObjectIdentifier()
{
olcObjectIdentifier.clear();
}
/**
* @param strings
*/
public void addCn( String... strings )
{
for ( String string : strings )
{
cn.add( string );
}
}
/**
* @param strings
*/
public void addOlcAttributeTypes( String... strings )
{
for ( String string : strings )
{
olcAttributeTypes.add( string );
}
}
/**
* @param strings
*/
public void addOlcDitContentRules( String... strings )
{
for ( String string : strings )
{
olcDitContentRules.add( string );
}
}
/**
* @param strings
*/
public void addOlcLdapSyntaxes( String... strings )
{
for ( String string : strings )
{
olcLdapSyntaxes.add( string );
}
}
/**
* @param strings
*/
public void addOlcObjectClasses( String... strings )
{
for ( String string : strings )
{
olcObjectClasses.add( string );
}
}
/**
* @param strings
*/
public void addOlcObjectIdentifier( String... strings )
{
for ( String string : strings )
{
olcObjectIdentifier.add( string );
}
}
/**
* @return the cn
*/
public List<String> getCn()
{
return copyListString( cn );
}
/**
* @return the olcAttributeTypes
*/
public List<String> getOlcAttributeTypes()
{
return copyListString( olcAttributeTypes );
}
/**
* @return the olcDitContentRules
*/
public List<String> getOlcDitContentRules()
{
return copyListString( olcDitContentRules );
}
/**
* @return the olcLdapSyntaxes
*/
public List<String> getOlcLdapSyntaxes()
{
return copyListString( olcLdapSyntaxes );
}
/**
* @return the olcObjectClasses
*/
public List<String> getOlcObjectClasses()
{
return copyListString( olcObjectClasses );
}
/**
* @return the olcObjectIdentifier
*/
public List<String> getOlcObjectIdentifier()
{
return copyListString( olcObjectIdentifier );
}
/**
* @param cn the cn to set
*/
public void setCn( List<String> cn )
{
this.cn = copyListString( cn );
}
/**
* @param olcAttributeTypes the olcAttributeTypes to set
*/
public void setOlcAttributeTypes( List<String> olcAttributeTypes )
{
this.olcAttributeTypes = copyListString( olcAttributeTypes );
}
/**
* @param olcDitContentRules the olcDitContentRules to set
*/
public void setOlcDitContentRules( List<String> olcDitContentRules )
{
this.olcDitContentRules = copyListString( olcDitContentRules );
}
/**
* @param olcLdapSyntaxes the olcLdapSyntaxes to set
*/
public void setOlcLdapSyntaxes( List<String> olcLdapSyntaxes )
{
this.olcLdapSyntaxes = copyListString( olcLdapSyntaxes );
}
/**
* @param olcObjectClasses the olcObjectClasses to set
*/
public void setOlcObjectClasses( List<String> olcObjectClasses )
{
this.olcObjectClasses = copyListString( olcObjectClasses );
}
/**
* @param olcObjectIdentifier the olcObjectIdentifier to set
*/
public void setOlcObjectIdentifier( List<String> olcObjectIdentifier )
{
this.olcObjectIdentifier = copyListString( olcObjectIdentifier );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcBackendConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcBackendConfig.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.config.model;
/**
* Java bean for the 'olcBackendConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcBackendConfig extends OlcConfig
{
/**
* Field for the 'olcBackend' attribute.
*/
@ConfigurationElement(attributeType = "olcBackend", isOptional = false, version="2.4.0")
private String olcBackend;
/**
* Creates a new instance of olcBackendConfig.
*/
public OlcBackendConfig()
{
}
/**
* Creates a copy instance of olcBackendConfig.
*
* @param o the initial object
*/
public OlcBackendConfig( OlcBackendConfig o )
{
olcBackend = o.olcBackend;
}
/**
* @return the olcBackend
*/
public String getOlcBackend()
{
return olcBackend;
}
/**
* @param olcBackend the olcBackend to set
*/
public void setOlcBackend( String olcBackend )
{
this.olcBackend = olcBackend;
}
/**
* Gets a copy of this object.
*
* @return a copy of this object
*/
public OlcBackendConfig copy()
{
return new OlcBackendConfig( this );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OpenLdapConfiguration.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OpenLdapConfiguration.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.config.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.openldap.config.model.database.OlcDatabaseConfig;
/**
* This class implements the basic class for an OpenLDAP configuration.
* <p>
* It contains all the configuration objects found under the "cn=config" branch.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OpenLdapConfiguration
{
/** The connection */
private Connection connection;
/** The global configuration */
private OlcGlobal global;
/** The databases list */
private List<OlcDatabaseConfig> databases = new ArrayList<>();
/** The other configuration elements list*/
private List<OlcConfig> configurationElements = new ArrayList<>();
/** The loaded modules */
private List<OlcModuleList> modules = new ArrayList<>();
/**
* @return the list of modules
*/
public List<OlcModuleList> getModules()
{
return modules;
}
/**
* Add a module in the list of modules
*
* @param modules the modules to add
*/
public void add( OlcModuleList module )
{
modules.add( module );
}
/**
* Remove a module from the list of modules
*
* @param modules the modules to remove
*/
public boolean remove( OlcModuleList module )
{
return modules.remove( module );
}
/**
* Reset the module list
*/
public void clearModuleList()
{
modules.clear();
}
/**
* @return the list of configuration elements
*/
public List<OlcConfig> getConfigurationElements()
{
return configurationElements;
}
/**
* Add a configuration element in the list of elements
*
* @param element the element to add
*/
public boolean add( OlcConfig element )
{
return configurationElements.add( element );
}
/**
* Tells if the list of elements contains a given element
*
* @param element The element we are looking for
* @return true if the element exists
*/
public boolean contains( OlcConfig element )
{
return configurationElements.contains( element );
}
/**
* Remove a element from the list of configuration elements
*
* @param element the element to remove
*/
public boolean remove( OlcConfig element )
{
return configurationElements.remove( element );
}
/**
* @return the list of databases
*/
public List<OlcDatabaseConfig> getDatabases()
{
return databases;
}
/**
* Add a database in the list of databases
*
* @param database the database to add
*/
public boolean add( OlcDatabaseConfig database )
{
return databases.add( database );
}
/**
* Reset the database list
*/
public void clearDatabases()
{
databases.clear();
}
/**
* Remove a database from the list of databases
*
* @param database the database to remove
*/
public boolean remove( OlcDatabaseConfig database )
{
return databases.remove( database );
}
/**
* @return the connection
*/
public Connection getConnection()
{
return connection;
}
/**
* @return the global configuration
*/
public OlcGlobal getGlobal()
{
return global;
}
/**
* Store the global configuration (which belongs to cn=config)
* @param global The configuration
*/
public void setGlobal( OlcGlobal global )
{
this.global = global;
}
/**
* Stores the connection in the configuration
*
* @param connection The connection to store
*/
public void setConnection( Connection connection )
{
this.connection = connection;
}
/**
* @return The number of configuration elements stored
*/
public int size()
{
return configurationElements.size();
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcDistProcConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcDistProcConfig.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.config.model;
/**
* Java bean for the 'olcDistProcConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcDistProcConfig extends OlcOverlayConfig
{
/**
* Field for the 'olcChainCacheURI' attribute.
*/
@ConfigurationElement(attributeType = "olcChainCacheURI", version="2.4.0")
private Boolean olcChainCacheURI;
/**
* Field for the 'olcChainingBehavior' attribute.
*/
@ConfigurationElement(attributeType = "olcChainingBehavior", version="2.4.0")
private String olcChainingBehavior;
/**
* Creates a new instance of OlcDistProcConfig.
*/
public OlcDistProcConfig()
{
super();
}
/**
* Creates a copy instance of OlcDistProcConfig.
*
* @param o the initial object
*/
public OlcDistProcConfig( OlcDistProcConfig o )
{
super( o );
olcChainCacheURI = o.olcChainCacheURI;
olcChainingBehavior = o.olcChainingBehavior;
}
/**
* @return the olcChainCacheURI
*/
public Boolean getOlcChainCacheURI()
{
return olcChainCacheURI;
}
/**
* @return the olcChainingBehavior
*/
public String getOlcChainingBehavior()
{
return olcChainingBehavior;
}
/**
* @param olcChainCacheURI the olcChainCacheURI to set
*/
public void setOlcChainCacheURI( Boolean olcChainCacheURI )
{
this.olcChainCacheURI = olcChainCacheURI;
}
/**
* @param olcChainingBehavior the olcChainingBehavior to set
*/
public void setOlcChainingBehavior( String olcChainingBehavior )
{
this.olcChainingBehavior = olcChainingBehavior;
}
/**
* {@inheritDoc}
*/
@Override
public OlcDistProcConfig copy()
{
return new OlcDistProcConfig( this );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcIncludeFile.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcIncludeFile.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.config.model;
import java.util.ArrayList;
import java.util.List;
/**
* Java bean for the 'olcIncludeFile' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcIncludeFile extends OlcConfig
{
/**
* Field for the 'cn' attribute.
*/
@ConfigurationElement(attributeType = "cn", isRdn = true, version="2.4.0")
private List<String> cn = new ArrayList<>();
/**
* Field for the 'olcInclude' attribute.
*/
@ConfigurationElement(attributeType = "olcInclude", isOptional = false, version="2.4.0")
private List<String> olcInclude = new ArrayList<>();
/**
* Field for the 'olcRootDSE' attribute.
*/
@ConfigurationElement(attributeType = "olcRootDSE", version="2.4.0")
private List<String> olcRootDSE = new ArrayList<>();
/**
* Creates a new instance of olcBackendConfig.
*/
public OlcIncludeFile()
{
}
/**
* Creates a copy instance of olcInclude.
*
* @param o the initial object
*/
public OlcIncludeFile( OlcIncludeFile o )
{
olcInclude = copyListString( o.olcInclude );
}
/**
* @param strings
*/
public void addCn( String... strings )
{
for ( String string : strings )
{
cn.add( string );
}
}
/**
* @param strings
*/
public void addOlcInclude( String... strings )
{
for ( String string : strings )
{
olcInclude.add( string );
}
}
/**
* @param strings
*/
public void addOlcRootDSE( String... strings )
{
for ( String string : strings )
{
olcRootDSE.add( string );
}
}
public void clearCn()
{
cn.clear();
}
/**
*/
public void clearOlcInclude()
{
olcInclude.clear();
}
public void clearOlcRootDSE()
{
olcRootDSE.clear();
}
/**
* @return the cn
*/
public List<String> getCn()
{
return copyListString( cn );
}
/**
* @return the olcInclude
*/
public List<String> getOlcInclude()
{
return copyListString( olcInclude );
}
/**
* @return the olcRootDSE
*/
public List<String> getOlcRootDSE()
{
return copyListString( olcRootDSE );
}
/**
* @param cn the cn to set
*/
public void setCn( List<String> cn )
{
this.cn = copyListString( cn );
}
/**
* @param olcInclude the olcInclude to set
*/
public void setOlcInclude( List<String> olcInclude )
{
this.olcInclude = copyListString( olcInclude );
}
/**
* @param olcRootDSE the olcRootDSE to set
*/
public void setOlcRootDSE( List<String> olcRootDSE )
{
this.olcRootDSE = copyListString( olcRootDSE );
}
/**
* Gets a copy of this object.
*
* @return a copy of this object
*/
public OlcIncludeFile copy()
{
return new OlcIncludeFile( this );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/ConfigurationElement.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/ConfigurationElement.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.config.model;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation used to specify that the qualified field is configuration element.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ConfigurationElement
{
/**
* Returns the attribute type.
*
* @return the attribute type
*/
String attributeType() default "";
/**
* Returns the string value of the default value.
*
* @return the string value of the default value
*/
String defaultValue() default "";
/**
* Returns true if the qualified field is optional.
*
* @return <code>true</code> if the qualified field is optional,
* <code>false</code> if not.
*/
boolean isOptional() default true;
/**
* Returns true if of the qualified field (attribute type and value)
* is the Rdn of the entry.
*
* @return <code>true</code> if of the qualified field (attribute type and value)
* is the Rdn of the entry, <code>false</code> if not.
*/
boolean isRdn() default false;
String version();
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/AuxiliaryObjectClass.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/AuxiliaryObjectClass.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.config.model;
/**
* Java bean for an auxiliary object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface AuxiliaryObjectClass
{
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OpenLdapVersion.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OpenLdapVersion.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.config.model;
/**
* The various OpenLDAP versions
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum OpenLdapVersion
{
VERSION_2_4_0( "2.4.0" ), // Most of the configuration AT were already defined in 2.4.0
// Version prior to 2.4.6 were beta or alpha
VERSION_2_4_6( "2.4.6" ), // olcSortVals, olcServerID, olcTLSCRLFile
VERSION_2_4_7( "2.4.7" ), // olcIndexIntLen
VERSION_2_4_8( "2.4.8" ), //olcDbCryptFile, olcDbCryptKey, olcDbSocketPath, olcDbSocketExtensions, olcMemberOfDanglingError
VERSION_2_4_9( "2.4.9" ),
VERSION_2_4_10( "2.4.10" ), // olcRefintModifiersName
VERSION_2_4_11( "2.4.11" ),
VERSION_2_4_12( "2.4.12" ), // olcDbNoRefs, olcDbNoUndefFilter, olcLdapSyntaxes
VERSION_2_4_13( "2.4.13" ), // olcDbPageSize, olcAddContentAcl
VERSION_2_4_14( "2.4.14" ),
VERSION_2_4_15( "2.4.15" ),
VERSION_2_4_16( "2.4.16" ),
VERSION_2_4_17( "2.4.17" ), // olcPPolicyForwardUpdates, olcSaslAuxprops, olcWriteTimeout
VERSION_2_4_18( "2.4.18" ), // olcTCPBuffer
VERSION_2_4_19( "2.4.19" ),
VERSION_2_4_20( "2.4.20" ), // olcSyncUseSubentry
VERSION_2_4_21( "2.4.21" ),
VERSION_2_4_22( "2.4.22" ), // olcExtraAttrs, olcDbIDAssertPassThru, olcSaslAuxpropsDontUseCopy, olcSaslAuxpropsDontUseCopyIgnore
VERSION_2_4_23( "2.4.23" ),
VERSION_2_4_24( "2.4.24" ), // olcDbBindAllowed
VERSION_2_4_25( "2.4.25" ),
VERSION_2_4_26( "2.4.26" ),
VERSION_2_4_27( "2.4.27" ), // olcDbMaxReaders, olcDbMaxSize, olcDbMode, olcDbNoSync, olcDbSearchStack
VERSION_2_4_28( "2.4.28" ),
VERSION_2_4_29( "2.4.29" ),
VERSION_2_4_30( "2.4.30" ),
VERSION_2_4_31( "2.4.31" ),
VERSION_2_4_32( "2.4.32" ),
VERSION_2_4_33( "2.4.33" ), // olcDbEnvFlags
VERSION_2_4_34( "2.4.34" ), // olcDbKeepalive, olcDbOnErr, olcIndexHash64
VERSION_2_4_35( "2.4.35" ),
VERSION_2_4_36( "2.4.36" ), // olcDisabled, olcListenerThreads, olcThreadQueues
VERSION_2_4_37( "2.4.37" ), // olcTLSProtocolMin
VERSION_2_4_38( "2.4.38" ),
VERSION_2_4_39( "2.4.39" ),
VERSION_2_4_40( "2.4.40" ),
VERSION_2_4_41( "2.4.41" ),
VERSION_2_4_42( "2.4.42" ),
VERSION_2_4_43( "2.4.43" ),
VERSION_2_4_44( "2.4.44" ),
VERSION_2_4_45( "2.4.45" );
/** The interned version */
private String version;
/**
* A private constructor
* @param version
*/
private OpenLdapVersion( String version )
{
this.version = version;
}
/**
* Get the enum associated to a String
*
* @param version The version we are looking at
* @return The found version, or VERSION_2_4_0 of not found.
*/
public static OpenLdapVersion getVersion( String version )
{
for ( OpenLdapVersion openLDAPVersion : OpenLdapVersion.values() )
{
if ( openLDAPVersion.version.equalsIgnoreCase( version ) )
{
return openLDAPVersion;
}
}
return OpenLdapVersion.VERSION_2_4_0;
}
/**
* @return The interned String representation for this value
*/
public String getValue()
{
return version;
}
/**
* @return An array containing all the interned versions as String in reverse order (newest first)
*/
public static String[] getVersions()
{
OpenLdapVersion[] values = OpenLdapVersion.values();
String[] versions = new String[values.length];
int i = values.length - 1;
for ( OpenLdapVersion value : values )
{
versions[i--] = value.version;
}
return versions;
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcModuleList.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcModuleList.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.config.model;
import java.util.ArrayList;
import java.util.List;
/**
* Java bean for the 'OlcGlobal' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcModuleList extends OlcConfig
{
/**
* Field for the 'cn' attribute.
*/
@ConfigurationElement(attributeType = "cn", isRdn = true, version="2.4.0")
private List<String> cn = new ArrayList<>();
/**
* Field for the 'olcAllows' attribute.
*/
@ConfigurationElement(attributeType = "olcModuleLoad", version="2.4.0")
private List<String> olcModuleLoad = new ArrayList<>();
/**
* Field for the 'olcModulePath' attribute.
*/
@ConfigurationElement(attributeType = "olcModulePath", version="2.4.0")
private String olcModulePath;
/**
* @param strings
*/
public void addCn( String... strings )
{
for ( String string : strings )
{
cn.add( string );
}
}
/**
* @param strings
*/
public void addOlcModuleLoad( String... strings )
{
for ( String string : strings )
{
olcModuleLoad.add( string );
}
}
public void clearCn()
{
cn.clear();
}
public void clearOlcModuleLoad()
{
olcModuleLoad.clear();
}
/**
* @return the cn
*/
public List<String> getCn()
{
return copyListString( cn );
}
/**
* @return the olcModuleLoad
*/
public List<String> getOlcModuleLoad()
{
return copyListString( olcModuleLoad );
}
/**
* @return the olcModulePath
*/
public String getOlcModulePath()
{
return olcModulePath;
}
/**
* @param cn the cn to set
*/
public void setCn( List<String> cn )
{
this.cn = copyListString( cn );
}
/**
* @param olcModuleLoad the olcModuleLoad to set
*/
public void setOlcModuleLoad( List<String> olcModuleLoad )
{
this.olcModuleLoad = copyListString( olcModuleLoad );
}
/**
* @param olcArgsFile the olcArgsFile to set
*/
public void setOlcModulePath( String olcModulePath )
{
this.olcModulePath = olcModulePath;
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcGlobal.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcGlobal.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.config.model;
import java.util.ArrayList;
import java.util.List;
/**
* Java bean for the 'OlcGlobal' object class. There are many attributes that have been
* added in some of the latest revisions :
*
* <ul>
* <li>olcTCPBuffer (List<String>) : 2.4.18</li>
* <li>olcSaslAuxpropsDontUseCopy (String) : 2.4.22</li>
* <li>olcSaslAuxpropsDontUseCopyIgnore (Boolean) : 2.4.22</li>
* <li>olcIndexHash64 (Boolean) : 2.4.34</li>
* <li>olcListenerThreads (Integer) : 2.4.36</li>
* <li>olcThreadQueues (Integer) : 2.4.36</li>
* <li>olcTLSProtocolMin (String) : 2.4.37</li>
* <li>olcTLSECName (String) : 2.4.??? (not yet released)</li>
* </ul>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcGlobal extends OlcConfig
{
/**
* Field for the 'cn' attribute.
*/
@ConfigurationElement(attributeType = "cn", isRdn = true, defaultValue="config", isOptional = false, version="2.4.0")
private List<String> cn = new ArrayList<>();
/**
* Field for the 'olcAllows' attribute.
*/
@ConfigurationElement(attributeType = "olcAllows", version="2.4.0")
private List<String> olcAllows = new ArrayList<>();
/**
* Field for the 'olcArgsFile' attribute.
*/
@ConfigurationElement(attributeType = "olcArgsFile", version="2.4.0")
private String olcArgsFile;
/**
* Field for the 'olcAttributeOptions' attribute.
*/
@ConfigurationElement(attributeType = "olcAttributeOptions", version="2.4.0")
private List<String> olcAttributeOptions = new ArrayList<>();
/**
* Field for the 'olcAttributeTypes' attribute.
*/
@ConfigurationElement(attributeType = "olcAttributeTypes", version="2.4.0")
private List<String> olcAttributeTypes = new ArrayList<>();
/**
* Field for the 'olcAuthIDRewrite' attribute.
*/
@ConfigurationElement(attributeType = "olcAuthIDRewrite", version="2.4.0")
private List<String> olcAuthIDRewrite = new ArrayList<>();
/**
* Field for the 'olcAuthzPolicy' attribute.
*/
@ConfigurationElement(attributeType = "olcAuthzPolicy", version="2.4.0")
private String olcAuthzPolicy;
/**
* Field for the 'olcAuthzRegexp' attribute.
*/
@ConfigurationElement(attributeType = "olcAuthzRegexp", version="2.4.0")
private List<String> olcAuthzRegexp = new ArrayList<>();
/**
* Field for the 'olcConcurrency' attribute.
*/
@ConfigurationElement(attributeType = "olcConcurrency", version="2.4.0")
private Integer olcConcurrency;
/**
* Field for the 'olcConfigDir' attribute.
*/
@ConfigurationElement(attributeType = "olcConfigDir", version="2.4.0")
private String olcConfigDir;
/**
* Field for the 'olcConfigFile' attribute.
*/
@ConfigurationElement(attributeType = "olcConfigFile", version="2.4.0")
private String olcConfigFile;
/**
* Field for the 'olcConnMaxPending' attribute.
*/
@ConfigurationElement(attributeType = "olcConnMaxPending", version="2.4.0")
private Integer olcConnMaxPending;
/**
* Field for the 'olcConnMaxPendingAuth' attribute.
*/
@ConfigurationElement(attributeType = "olcConnMaxPendingAuth", version="2.4.0")
private Integer olcConnMaxPendingAuth;
/**
* Field for the 'olcDisallows' attribute.
*/
@ConfigurationElement(attributeType = "olcDisallows", version="2.4.0")
private List<String> olcDisallows = new ArrayList<>();
/**
* Field for the 'olcDitContentRules' attribute.
*/
@ConfigurationElement(attributeType = "olcDitContentRules", version="2.4.0")
private List<String> olcDitContentRules = new ArrayList<>();
/**
* Field for the 'olcGentleHUP' attribute.
*/
@ConfigurationElement(attributeType = "olcGentleHUP", version="2.4.0")
private Boolean olcGentleHUP;
/**
* Field for the 'olcIdleTimeout' attribute.
*/
@ConfigurationElement(attributeType = "olcIdleTimeout", version="2.4.0")
private Integer olcIdleTimeout;
/**
* Field for the 'olcIndexHash64' attribute. (Added in OpenLDAP 2.4.34)
*/
@ConfigurationElement(attributeType = "olcIndexHash64", version="2.4.34")
private Boolean olcIndexHash64;
/**
* Field for the 'olcIndexIntLen' attribute.
*/
@ConfigurationElement(attributeType = "olcIndexIntLen", version="2.4.7")
private Integer olcIndexIntLen;
/**
* Field for the 'olcIndexSubstrAnyLen' attribute.
*/
@ConfigurationElement(attributeType = "olcIndexSubstrAnyLen", version="2.4.0")
private Integer olcIndexSubstrAnyLen;
/**
* Field for the 'olcIndexSubstrAnyStep' attribute.
*/
@ConfigurationElement(attributeType = "olcIndexSubstrAnyStep", version="2.4.0")
private Integer olcIndexSubstrAnyStep;
/**
* Field for the 'olcIndexSubstrIfMaxLen' attribute.
*/
@ConfigurationElement(attributeType = "olcIndexSubstrIfMaxLen", version="2.4.0")
private Integer olcIndexSubstrIfMaxLen;
/**
* Field for the 'olcIndexSubstrIfMinLen' attribute.
*/
@ConfigurationElement(attributeType = "olcIndexSubstrIfMinLen", version="2.4.0")
private Integer olcIndexSubstrIfMinLen;
/**
* Field for the 'olcLdapSyntaxes' attribute.
*/
@ConfigurationElement(attributeType = "olcLdapSyntaxes", version="2.4.12")
private List<String> olcLdapSyntaxes = new ArrayList<>();
/**
* Field for the 'olcListenerThreads' attribute. (Added in OpenLDAP 2.4.36)
*/
@ConfigurationElement(attributeType = "olcListenerThreads", version="2.4.36")
private Integer olcListenerThreads;
/**
* Field for the 'olcLocalSSF' attribute.
*/
@ConfigurationElement(attributeType = "olcLocalSSF", version="2.4.0")
private Integer olcLocalSSF;
/**
* Field for the 'olcLogFile' attribute.
*/
@ConfigurationElement(attributeType = "olcLogFile", version="2.4.0")
private String olcLogFile;
/**
* Field for the 'olcLogLevel' attribute.
*/
@ConfigurationElement(attributeType = "olcLogLevel", version="2.4.0")
private List<String> olcLogLevel = new ArrayList<>();
/**
* Field for the 'olcObjectClasses' attribute.
*/
@ConfigurationElement(attributeType = "olcObjectClasses", version="2.4.0")
private List<String> olcObjectClasses = new ArrayList<>();
/**
* Field for the 'olcObjectIdentifier' attribute.
*/
@ConfigurationElement(attributeType = "olcObjectIdentifier", version="2.4.0")
private List<String> olcObjectIdentifier = new ArrayList<>();
/**
* Field for the 'olcPasswordCryptSaltFormat' attribute.
*/
@ConfigurationElement(attributeType = "olcPasswordCryptSaltFormat", version="2.4.0")
private String olcPasswordCryptSaltFormat;
/**
* Field for the 'olcPasswordHash' attribute.
*/
@ConfigurationElement(attributeType = "olcPasswordHash", version="2.4.0")
private List<String> olcPasswordHash = new ArrayList<>();
/**
* Field for the 'olcPidFile' attribute.
*/
@ConfigurationElement(attributeType = "olcPidFile", version="2.4.0")
private String olcPidFile;
/**
* Field for the 'olcPluginLogFile' attribute.
*/
@ConfigurationElement(attributeType = "olcPluginLogFile", version="2.4.0")
private String olcPluginLogFile;
/**
* Field for the 'olcReadOnly' attribute.
*/
@ConfigurationElement(attributeType = "olcReadOnly", version="2.4.0")
private Boolean olcReadOnly;
/**
* Field for the 'olcReferral' attribute.
*/
@ConfigurationElement(attributeType = "olcReferral", version="2.4.0")
private String olcReferral;
/**
* Field for the 'olcReplogFile' attribute.
*/
@ConfigurationElement(attributeType = "olcReplogFile", version="2.4.0")
private String olcReplogFile;
/**
* Field for the 'olcRequires' attribute.
*/
@ConfigurationElement(attributeType = "olcRequires", version="2.4.0")
private List<String> olcRequires = new ArrayList<>();
/**
* Field for the 'olcRestrict' attribute.
*/
@ConfigurationElement(attributeType = "olcRestrict", version="2.4.0")
private List<String> olcRestrict = new ArrayList<>();
/**
* Field for the 'olcReverseLookup' attribute.
*/
@ConfigurationElement(attributeType = "olcReverseLookup", version="2.4.0")
private Boolean olcReverseLookup;
/**
* Field for the 'olcRootDSE' attribute.
*/
@ConfigurationElement(attributeType = "olcRootDSE", version="2.4.0")
private List<String> olcRootDSE;
/**
* Field for the 'olcSaslAuxprops' attribute.
*/
@ConfigurationElement(attributeType = "olcSaslAuxprops", version="2.4.17")
private String olcSaslAuxprops;
/**
* Field for the 'olcSaslAuxpropsDontUseCopy' attribute. (Added in OpenLDAP 2.4.22)
*/
@ConfigurationElement(attributeType = "olcSaslAuxpropsDontUseCopy", version="2.4.22")
private String olcSaslAuxpropsDontUseCopy;
/**
* Field for the 'olcSaslAuxpropsDontUseCopyIgnore' attribute. (Added in OpenLDAP 2.4.22)
*/
@ConfigurationElement(attributeType = "olcSaslAuxpropsDontUseCopyIgnore", version="2.4.22")
private Boolean olcSaslAuxpropsDontUseCopyIgnore;
/**
* Field for the 'olcSaslHost' attribute.
*/
@ConfigurationElement(attributeType = "olcSaslHost", version="2.4.0")
private String olcSaslHost;
/**
* Field for the 'olcSaslRealm' attribute.
*/
@ConfigurationElement(attributeType = "olcSaslRealm", version="2.4.0")
private String olcSaslRealm;
/**
* Field for the 'olcSaslSecProps' attribute.
*/
@ConfigurationElement(attributeType = "olcSaslSecProps", version="2.4.0")
private String olcSaslSecProps;
/**
* Field for the 'olcSecurity' attribute.
*/
@ConfigurationElement(attributeType = "olcSecurity", version="2.4.0")
private List<String> olcSecurity = new ArrayList<>();
/**
* Field for the 'olcServerID' attribute.
*/
@ConfigurationElement(attributeType = "olcServerID", version="2.4.6")
private List<String> olcServerID = new ArrayList<>();
/**
* Field for the 'olcSizeLimit' attribute.
*/
@ConfigurationElement(attributeType = "olcSizeLimit", version="2.4.0")
private String olcSizeLimit;
/**
* Field for the 'olcSockbufMaxIncoming' attribute.
*/
@ConfigurationElement(attributeType = "olcSockbufMaxIncoming", version="2.4.0")
private Integer olcSockbufMaxIncoming;
/**
* Field for the 'olcSockbufMaxIncomingAuth' attribute.
*/
@ConfigurationElement(attributeType = "olcSockbufMaxIncomingAuth", version="2.4.0")
private String olcSockbufMaxIncomingAuth;
/**
* Field for the 'olcTCPBuffer' attribute. (Added in OpenLDAP 2.4.18)
*/
@ConfigurationElement(attributeType = "olcTCPBuffer", version="2.4.18")
private List<String> olcTCPBuffer = new ArrayList<>();
/**
* Field for the 'olcThreads' attribute
*/
@ConfigurationElement(attributeType = "olcThreads", version="2.4.0")
private Integer olcThreads;
/**
* Field for the 'olcThreadQueues' attribute.
*/
@ConfigurationElement(attributeType = "olcThreadQueues", version="2.4.36")
private Integer olcThreadQueues;
/**
* Field for the 'olcTimeLimit' attribute.
*/
@ConfigurationElement(attributeType = "olcTimeLimit", version="2.4.0")
private List<String> olcTimeLimit = new ArrayList<>();
/**
* Field for the 'olcTLSCACertificateFile' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCACertificateFile", version="2.4.0")
private String olcTLSCACertificateFile;
/**
* Field for the 'olcTLSCACertificatePath' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCACertificatePath", version="2.4.0")
private String olcTLSCACertificatePath;
/**
* Field for the 'olcTLSCertificateFile' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCertificateFile", version="2.4.0")
private String olcTLSCertificateFile;
/**
* Field for the 'olcTLSCertificateKeyFile' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCertificateKeyFile", version="2.4.0")
private String olcTLSCertificateKeyFile;
/**
* Field for the 'olcTLSCipherSuite' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCipherSuite", version="2.4.0")
private String olcTLSCipherSuite;
/**
* Field for the 'olcTLSCRLCheck' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCRLCheck", version="2.4.0")
private String olcTLSCRLCheck;
/**
* Field for the 'olcTLSCRLFile' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSCRLFile", version="2.4.6")
private String olcTLSCRLFile;
/**
* Field for the 'olcTLSDHParamFile' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSDHParamFile", version="2.4.0")
private String olcTLSDHParamFile;
/**
* Field for the 'olcTLSECName' attribute. (Added in OpenLDAP 2.4.41)
*/
@ConfigurationElement(attributeType = "olcTLSECName", version="2.5")
private String olcTLSECName;
/**
* Field for the 'olcTLSProtocolMin' attribute. (Added in OpenLDAP 2.4.37)
*/
@ConfigurationElement(attributeType = "olcTLSProtocolMin", version="2.4.37")
private String olcTLSProtocolMin;
/**
* Field for the 'olcTLSRandFile' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSRandFile", version="2.4.0")
private String olcTLSRandFile;
/**
* Field for the 'olcTLSVerifyClient' attribute.
*/
@ConfigurationElement(attributeType = "olcTLSVerifyClient", version="2.4.0")
private String olcTLSVerifyClient;
/**
* Field for the 'olcToolThreads' attribute.
*/
@ConfigurationElement(attributeType = "olcToolThreads", version="2.4.0")
private Integer olcToolThreads;
/**
* Field for the 'olcWriteTimeout' attribute.
*/
@ConfigurationElement(attributeType = "olcWriteTimeout", version="2.4.17")
private Integer olcWriteTimeout;
/**
* @param strings
*/
public void addCn( String... strings )
{
for ( String string : strings )
{
cn.add( string );
}
}
/**
* @param strings
*/
public void addOlcAllows( String... strings )
{
for ( String string : strings )
{
olcAllows.add( string );
}
}
/**
* @param strings
*/
public void addOlcAttributeOptions( String... strings )
{
for ( String string : strings )
{
olcAttributeOptions.add( string );
}
}
/**
* @param strings
*/
public void addOlcAttributeTypes( String... strings )
{
for ( String string : strings )
{
olcAttributeTypes.add( string );
}
}
/**
* @param strings
*/
public void addOlcAuthIDRewrite( String... strings )
{
for ( String string : strings )
{
olcAuthIDRewrite.add( string );
}
}
/**
* @param strings
*/
public void addOlcAuthzRegexp( String... strings )
{
for ( String string : strings )
{
olcAuthzRegexp.add( string );
}
}
/**
* @param strings
*/
public void addOlcDisallows( String... strings )
{
for ( String string : strings )
{
olcDisallows.add( string );
}
}
/**
* @param strings
*/
public void addOlcDitContentRules( String... strings )
{
for ( String string : strings )
{
olcDitContentRules.add( string );
}
}
/**
* @param strings
*/
public void addOlcLdapSyntaxes( String... strings )
{
for ( String string : strings )
{
olcLdapSyntaxes.add( string );
}
}
/**
* @param strings
*/
public void addOlcLogLevel( String... strings )
{
for ( String string : strings )
{
olcLogLevel.add( string );
}
}
/**
* @param strings
*/
public void addOlcObjectClasses( String... strings )
{
for ( String string : strings )
{
olcObjectClasses.add( string );
}
}
/**
* @param strings
*/
public void addOlcObjectIdentifier( String... strings )
{
for ( String string : strings )
{
olcObjectIdentifier.add( string );
}
}
/**
* @param strings
*/
public void addOlcPasswordHash( String... strings )
{
for ( String string : strings )
{
olcPasswordHash.add( string );
}
}
/**
* @param strings
*/
public void addOlcRequires( String... strings )
{
for ( String string : strings )
{
olcRequires.add( string );
}
}
/**
* @param strings
*/
public void addOlcRestrict( String... strings )
{
for ( String string : strings )
{
olcRestrict.add( string );
}
}
/**
* @param strings
*/
public void addOlcSecurity( String... strings )
{
for ( String string : strings )
{
olcSecurity.add( string );
}
}
/**
* @param strings
*/
public void addOlcServerID( String... strings )
{
for ( String string : strings )
{
olcServerID.add( string );
}
}
/**
* @param strings
*/
public void addOlcTCPBuffer( String... strings )
{
for ( String string : strings )
{
olcTCPBuffer.add( string );
}
}
/**
* @param strings
*/
public void addOlcTimeLimit( String... strings )
{
for ( String string : strings )
{
olcTimeLimit.add( string );
}
}
public void clearCn()
{
cn.clear();
}
public void clearOlcAllows()
{
olcAllows.clear();
}
public void clearOlcAttributeOptions()
{
olcAttributeOptions.clear();
}
public void clearOlcAttributeTypes()
{
olcAttributeTypes.clear();
}
public void clearOlcAuthIDRewrite()
{
olcAuthIDRewrite.clear();
}
public void clearOlcAuthzRegexp()
{
olcAuthzRegexp.clear();
}
public void clearOlcDisallows()
{
olcDisallows.clear();
}
public void clearOlcDitContentRules()
{
olcDitContentRules.clear();
}
public void clearOlcLdapSyntaxes()
{
olcLdapSyntaxes.clear();
}
public void clearOlcLogLevel()
{
olcLogLevel.clear();
}
public void clearOlcObjectClasses()
{
olcObjectClasses.clear();
}
public void clearOlcObjectIdentifier()
{
olcObjectIdentifier.clear();
}
public void clearOlcPasswordHash()
{
olcPasswordHash.clear();
}
public void clearOlcRequires()
{
olcRequires.clear();
}
public void clearOlcRestrict()
{
olcRestrict.clear();
}
public void clearOlcSecurity()
{
olcSecurity.clear();
}
public void clearOlcServerID()
{
olcServerID.clear();
}
public void clearOlcTCPBuffer()
{
olcTCPBuffer.clear();
}
public void clearOlcTimeLimit()
{
olcTimeLimit.clear();
}
/**
* @return the cn
*/
public List<String> getCn()
{
return copyListString( cn );
}
/**
* @return the olcAllows
*/
public List<String> getOlcAllows()
{
return copyListString( olcAllows );
}
/**
* @return the olcArgsFile
*/
public String getOlcArgsFile()
{
return olcArgsFile;
}
/**
* @return the olcAttributeOptions
*/
public List<String> getOlcAttributeOptions()
{
return copyListString( olcAttributeOptions );
}
/**
* @return the olcAttributeTypes
*/
public List<String> getOlcAttributeTypes()
{
return copyListString( olcAttributeTypes );
}
/**
* @return the olcAuthIDRewrite
*/
public List<String> getOlcAuthIDRewrite()
{
return copyListString( olcAuthIDRewrite );
}
/**
* @return the olcAuthzPolicy
*/
public String getOlcAuthzPolicy()
{
return olcAuthzPolicy;
}
/**
* @return the olcAuthzRegexp
*/
public List<String> getOlcAuthzRegexp()
{
return copyListString( olcAuthzRegexp );
}
/**
* @return the olcConcurrency
*/
public Integer getOlcConcurrency()
{
return olcConcurrency;
}
/**
* @return the olcConfigDir
*/
public String getOlcConfigDir()
{
return olcConfigDir;
}
/**
* @return the olcConfigFile
*/
public String getOlcConfigFile()
{
return olcConfigFile;
}
/**
* @return the olcConnMaxPending
*/
public Integer getOlcConnMaxPending()
{
return olcConnMaxPending;
}
/**
* @return the olcConnMaxPendingAuth
*/
public Integer getOlcConnMaxPendingAuth()
{
return olcConnMaxPendingAuth;
}
/**
* @return the olcDisallows
*/
public List<String> getOlcDisallows()
{
return copyListString( olcDisallows );
}
/**
* @return the olcDitContentRules
*/
public List<String> getOlcDitContentRules()
{
return copyListString( olcDitContentRules );
}
/**
* @return the olcGentleHUP
*/
public Boolean getOlcGentleHUP()
{
return olcGentleHUP;
}
/**
* @return the olcIdleTimeout
*/
public Integer getOlcIdleTimeout()
{
return olcIdleTimeout;
}
/**
* @return the olcIndexHash64
*/
public Boolean getOlcIndexHash64()
{
return olcIndexHash64;
}
/**
* @return the olcIndexIntLen
*/
public Integer getOlcIndexIntLen()
{
return olcIndexIntLen;
}
/**
* @return the olcIndexSubstrAnyLen
*/
public Integer getOlcIndexSubstrAnyLen()
{
return olcIndexSubstrAnyLen;
}
/**
* @return the olcIndexSubstrAnyStep
*/
public Integer getOlcIndexSubstrAnyStep()
{
return olcIndexSubstrAnyStep;
}
/**
* @return the olcIndexSubstrIfMaxLen
*/
public Integer getOlcIndexSubstrIfMaxLen()
{
return olcIndexSubstrIfMaxLen;
}
/**
* @return the olcIndexSubstrIfMinLen
*/
public Integer getOlcIndexSubstrIfMinLen()
{
return olcIndexSubstrIfMinLen;
}
/**
* @return the olcLdapSyntaxes
*/
public List<String> getOlcLdapSyntaxes()
{
return copyListString( olcLdapSyntaxes );
}
/**
* @return the olcListenerThreads
*/
public Integer getOlcListenerThreads()
{
return olcListenerThreads;
}
/**
* @return the olcLocalSSF
*/
public Integer getOlcLocalSSF()
{
return olcLocalSSF;
}
/**
* @return the olcLogFile
*/
public String getOlcLogFile()
{
return olcLogFile;
}
/**
* @return the olcLogLevel
*/
public List<String> getOlcLogLevel()
{
return copyListString( olcLogLevel );
}
/**
* @return the olcObjectClasses
*/
public List<String> getOlcObjectClasses()
{
return copyListString( olcObjectClasses );
}
/**
* @return the olcObjectIdentifier
*/
public List<String> getOlcObjectIdentifier()
{
return copyListString( olcObjectIdentifier );
}
/**
* @return the olcPasswordCryptSaltFormat
*/
public String getOlcPasswordCryptSaltFormat()
{
return olcPasswordCryptSaltFormat;
}
/**
* @return the olcPasswordHash
*/
public List<String> getOlcPasswordHash()
{
return copyListString( olcPasswordHash );
}
/**
* @return the olcPidFile
*/
public String getOlcPidFile()
{
return olcPidFile;
}
/**
* @return the olcPluginLogFile
*/
public String getOlcPluginLogFile()
{
return olcPluginLogFile;
}
/**
* @return the olcReadOnly
*/
public Boolean getOlcReadOnly()
{
return olcReadOnly;
}
/**
* @return the olcReferral
*/
public String getOlcReferral()
{
return olcReferral;
}
/**
* @return the olcReplogFile
*/
public String getOlcReplogFile()
{
return olcReplogFile;
}
/**
* @return the olcRequires
*/
public List<String> getOlcRequires()
{
return copyListString( olcRequires );
}
/**
* @return the olcReverseLookup
*/
public Boolean getOlcReverseLookup()
{
return olcReverseLookup;
}
/**
* @return the olcRestrict
*/
public List<String> getOlcRestrict()
{
return copyListString( olcRestrict );
}
/**
* @return the olcRootDSE
*/
public List<String> getOlcRootDSE()
{
return copyListString( olcRootDSE );
}
/**
* @return the olcSaslAuxprops
*/
public String getOlcSaslAuxprops()
{
return olcSaslAuxprops;
}
/**
* @return the olcSaslAuxpropsDontUseCopy
*/
public String getOlcSaslAuxpropsDontUseCopy()
{
return olcSaslAuxpropsDontUseCopy;
}
/**
* @return the olcSaslAuxpropsDontUseCopyIgnore
*/
public Boolean getOlcSaslAuxpropsDontUseCopyIgnore()
{
return olcSaslAuxpropsDontUseCopyIgnore;
}
/**
* @return the olcSaslHost
*/
public String getOlcSaslHost()
{
return olcSaslHost;
}
/**
* @return the olcSaslRealm
*/
public String getOlcSaslRealm()
{
return olcSaslRealm;
}
/**
* @return the olcSaslSecProps
*/
public String getOlcSaslSecProps()
{
return olcSaslSecProps;
}
/**
* @return the olcSecurity
*/
public List<String> getOlcSecurity()
{
return copyListString( olcSecurity );
}
/**
* @return the olcServerID
*/
public List<String> getOlcServerID()
{
return copyListString( olcServerID );
}
/**
* @return the olcSizeLimit
*/
public String getOlcSizeLimit()
{
return olcSizeLimit;
}
/**
* @return the olcSockbufMaxIncoming
*/
public Integer getOlcSockbufMaxIncoming()
{
return olcSockbufMaxIncoming;
}
/**
* @return the olcSockbufMaxIncomingAuth
*/
public String getOlcSockbufMaxIncomingAuth()
{
return olcSockbufMaxIncomingAuth;
}
/**
* @return the olcTCPBuffer
*/
public List<String> getOlcTCPBuffer()
{
return copyListString( olcTCPBuffer );
}
/**
* @return the olcThreads
*/
public Integer getOlcThreads()
{
return olcThreads;
}
/**
* @return the olcThreadQueues
*/
public Integer getOlcThreadQueues()
{
return olcThreadQueues;
}
/**
* @return the olcTimeLimit
*/
public List<String> getOlcTimeLimit()
{
return copyListString( olcTimeLimit );
}
/**
* @return the olcTLSCACertificateFile
*/
public String getOlcTLSCACertificateFile()
{
return olcTLSCACertificateFile;
}
/**
* @return the olcTLSCACertificatePath
*/
public String getOlcTLSCACertificatePath()
{
return olcTLSCACertificatePath;
}
/**
* @return the olcTLSCertificateFile
*/
public String getOlcTLSCertificateFile()
{
return olcTLSCertificateFile;
}
/**
* @return the olcTLSCertificateKeyFile
*/
public String getOlcTLSCertificateKeyFile()
{
return olcTLSCertificateKeyFile;
}
/**
* @return the olcTLSCipherSuite
*/
public String getOlcTLSCipherSuite()
{
return olcTLSCipherSuite;
}
/**
* @return the olcTLSCRLCheck
*/
public String getOlcTLSCRLCheck()
{
return olcTLSCRLCheck;
}
/**
* @return the olcTLSCRLFile
*/
public String getOlcTLSCRLFile()
{
return olcTLSCRLFile;
}
/**
* @return the olcTLSECName
*/
public String getOlcTLSECName()
{
return olcTLSECName;
}
/**
* @return the olcTLSDHParamFile
*/
public String getOlcTLSDHParamFile()
{
return olcTLSDHParamFile;
}
/**
* @return the olcTLSProtocolMin
*/
public String getOlcTLSProtocolMin()
{
return olcTLSProtocolMin;
}
/**
* @return the olcTLSRandFile
*/
public String getOlcTLSRandFile()
{
return olcTLSRandFile;
}
/**
* @return the olcTLSVerifyClient
*/
public String getOlcTLSVerifyClient()
{
return olcTLSVerifyClient;
}
/**
* @return the olcToolThreads
*/
public Integer getOlcToolThreads()
{
return olcToolThreads;
}
/**
* @return the olcWriteTimeout
*/
public Integer getOlcWriteTimeout()
{
return olcWriteTimeout;
}
/**
* @param cn the cn to set
*/
public void setCn( List<String> cn )
{
this.cn = copyListString( cn );
}
/**
* @param olcAllows the olcAllows to set
*/
public void setOlcAllows( List<String> olcAllows )
{
this.olcAllows = copyListString( olcAllows );
}
/**
* @param olcArgsFile the olcArgsFile to set
*/
public void setOlcArgsFile( String olcArgsFile )
{
this.olcArgsFile = olcArgsFile;
}
/**
* @param olcAttributeOptions the olcAttributeOptions to set
*/
public void setOlcAttributeOptions( List<String> olcAttributeOptions )
{
this.olcAttributeOptions = copyListString( olcAttributeOptions );
}
/**
* @param olcAttributeTypes the olcAttributeTypes to set
*/
public void setOlcAttributeTypes( List<String> olcAttributeTypes )
{
this.olcAttributeTypes = copyListString( olcAttributeTypes );
}
/**
* @param olcAuthIDRewrite the olcAuthIDRewrite to set
*/
public void setOlcAuthIDRewrite( List<String> olcAuthIDRewrite )
{
this.olcAuthIDRewrite = copyListString( olcAuthIDRewrite );
}
/**
* @param olcAuthzPolicy the olcAuthzPolicy to set
*/
public void setOlcAuthzPolicy( String olcAuthzPolicy )
{
this.olcAuthzPolicy = olcAuthzPolicy;
}
/**
* @param olcAuthzRegexp the olcAuthzRegexp to set
*/
public void setOlcAuthzRegexp( List<String> olcAuthzRegexp )
{
this.olcAuthzRegexp = copyListString( olcAuthzRegexp );
}
/**
* @param olcConcurrency the olcConcurrency to set
*/
public void setOlcConcurrency( Integer olcConcurrency )
{
this.olcConcurrency = olcConcurrency;
}
/**
* @param olcConfigDir the olcConfigDir to set
*/
public void setOlcConfigDir( String olcConfigDir )
{
| java | Apache-2.0 | e55b93d729a60c986fc93e52f9519f4bbdf51252 | 2026-01-05T02:32:00.866394Z | true |
apache/directory-studio | https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcChainConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcChainConfig.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.config.model;
/**
* Java bean for the 'olcChainConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcChainConfig extends OlcOverlayConfig
{
/**
* Field for the 'olcChainCacheURI' attribute.
*/
@ConfigurationElement(attributeType = "olcChainCacheURI", version="2.4.0")
private Boolean olcChainCacheURI;
/**
* Field for the 'olcChainingBehavior' attribute.
*/
@ConfigurationElement(attributeType = "olcChainingBehavior", version="2.4.0")
private String olcChainingBehavior;
/**
* Field for the 'olcChainMaxReferralDepth' attribute.
*/
@ConfigurationElement(attributeType = "olcChainMaxReferralDepth", version="2.4.0")
private Integer olcChainMaxReferralDepth;
/**
* Field for the 'olcChainReturnError' attribute.
*/
@ConfigurationElement(attributeType = "olcChainReturnError", version="2.4.0")
private Boolean olcChainReturnError;
/**
* Creates a new instance of OlcChainConfig.
*/
public OlcChainConfig()
{
super();
}
/**
* Creates a copy instance of OlcChainConfig.
*
* @param o the initial object
*/
public OlcChainConfig( OlcChainConfig o )
{
super( o );
olcChainCacheURI = o.olcChainCacheURI;
olcChainingBehavior = o.olcChainingBehavior;
olcChainMaxReferralDepth = o.olcChainMaxReferralDepth;
olcChainReturnError = o.olcChainReturnError;
}
/**
* @return the olcChainCacheURI
*/
public Boolean getOlcChainCacheURI()
{
return olcChainCacheURI;
}
/**
* @return the olcChainingBehavior
*/
public String getOlcChainingBehavior()
{
return olcChainingBehavior;
}
/**
* @return the olcChainMaxReferralDepth
*/
public Integer getOlcChainMaxReferralDepth()
{
return olcChainMaxReferralDepth;
}
/**
* @return the olcChainReturnError
*/
public Boolean getOlcChainReturnError()
{
return olcChainReturnError;
}
/**
* @param olcChainCacheURI the olcChainCacheURI to set
*/
public void setOlcChainCacheURI( Boolean olcChainCacheURI )
{
this.olcChainCacheURI = olcChainCacheURI;
}
/**
* @param olcChainingBehavior the olcChainingBehavior to set
*/
public void setOlcChainingBehavior( String olcChainingBehavior )
{
this.olcChainingBehavior = olcChainingBehavior;
}
/**
* @param olcChainMaxReferralDepth the olcChainMaxReferralDepth to set
*/
public void setOlcChainMaxReferralDepth( Integer olcChainMaxReferralDepth )
{
this.olcChainMaxReferralDepth = olcChainMaxReferralDepth;
}
/**
* @param olcChainReturnError the olcChainReturnError to set
*/
public void setOlcChainReturnError( Boolean olcChainReturnError )
{
this.olcChainReturnError = olcChainReturnError;
}
/**
* {@inheritDoc}
*/
@Override
public OlcChainConfig copy()
{
return new OlcChainConfig( this );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcPBindConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcPBindConfig.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.config.model;
/**
* Java bean for the 'olcPBindConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcPBindConfig extends OlcOverlayConfig
{
/**
* Field for the 'olcDbURI' attribute.
*/
@ConfigurationElement(attributeType = "olcDbURI", isOptional = false, version="2.4.0")
private String olcDbURI;
/**
* Field for the 'olcDbNetworkTimeout' attribute.
*/
@ConfigurationElement(attributeType = "olcDbNetworkTimeout", version="2.4.0")
private String olcDbNetworkTimeout;
/**
* Field for the 'olcDbQuarantine' attribute.
*/
@ConfigurationElement(attributeType = "olcDbQuarantine", version="2.4.0")
private String olcDbQuarantine;
/**
* Field for the 'olcStartTLS' attribute.
*/
@ConfigurationElement(attributeType = "olcStartTLS", version="2.5.0")
private String olcStartTLS;
/**
* Creates a new instance of OlcPBindConfig.
*/
public OlcPBindConfig()
{
super();
}
/**
* Creates a copy instance of OlcPBindConfig.
*
* @param o the initial object
*/
public OlcPBindConfig( OlcPBindConfig o )
{
super( o );
olcDbURI = o.olcDbURI;
olcDbNetworkTimeout = o.olcDbNetworkTimeout;
olcDbQuarantine = o.olcDbQuarantine;
olcStartTLS = o.olcStartTLS;
}
/**
* @return the olcDbNetworkTimeout
*/
public String getOlcDbNetworkTimeout()
{
return olcDbNetworkTimeout;
}
/**
* @return the olcDbQuarantine
*/
public String getOlcDbQuarantine()
{
return olcDbQuarantine;
}
/**
* @return the olcDbURI
*/
public String getOlcDbURI()
{
return olcDbURI;
}
/**
* @return the olcStartTLS
*/
public String getOlcStartTLS()
{
return olcStartTLS;
}
/**
* @param olcDbNetworkTimeout the olcDbNetworkTimeout to set
*/
public void setOlcDbNetworkTimeout( String olcDbNetworkTimeout )
{
this.olcDbNetworkTimeout = olcDbNetworkTimeout;
}
/**
* @param olcDbQuarantine the olcDbQuarantine to set
*/
public void setOlcDbQuarantine( String olcDbQuarantine )
{
this.olcDbQuarantine = olcDbQuarantine;
}
/**
* @param olcDbURI the olcDbURI to set
*/
public void setOlcDbURI( String olcDbURI )
{
this.olcDbURI = olcDbURI;
}
/**
* @param olcStartTLS the olcStartTLS to set
*/
public void setOlcStartTLS( String olcStartTLS )
{
this.olcStartTLS = olcStartTLS;
}
/**
* {@inheritDoc}
*/
@Override
public OlcPBindConfig copy()
{
return new OlcPBindConfig( this );
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcConfig.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.config.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.directory.api.ldap.model.name.Dn;
/**
* Java bean for the 'olcConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcConfig
{
/** The parent DN of the associated entry */
protected Dn parentDn;
/** The list of auxiliary object classes */
protected List<AuxiliaryObjectClass> auxiliaryObjectClasses = new ArrayList<>();
/**
* @param auxiliaryObjectClasses
*/
public void addAuxiliaryObjectClasses( AuxiliaryObjectClass... auxiliaryObjectClasses )
{
for ( AuxiliaryObjectClass auxiliaryObjectClass : auxiliaryObjectClasses )
{
this.auxiliaryObjectClasses.add( auxiliaryObjectClass );
}
}
/**
* Gets the list of objects associated with the auxiliary classes.
*
* @return the list of objects associated with auxiliary classes.
*/
public List<AuxiliaryObjectClass> getAuxiliaryObjectClasses()
{
List<AuxiliaryObjectClass> copy = new ArrayList<>( auxiliaryObjectClasses.size() );
copy.addAll( auxiliaryObjectClasses );
return copy;
}
/**
* Gets the number of auxiliary object classes.
*
* @return the number of auxiliary object classes
*/
public int getAuxiliaryObjectClassesSize()
{
return auxiliaryObjectClasses.size();
}
/**
* Gets the parent DN of the associated entry.
*
* @return the dn the parent DN of the asssociated entry
*/
public Dn getParentDn()
{
return parentDn;
}
/**
* Sets the parent DN of the associated entry.
*
* @param dn the parent dn to set
*/
public void setParentDn( Dn parentDn )
{
this.parentDn = parentDn;
}
/**
* Copy a List of Strings into a new List of strings.
*
* @param original The list to copy
* @return The copied list
*/
protected List<String> copyListString( List<String> original )
{
if ( original != null )
{
List<String> copy = new ArrayList<>( original.size() );
copy.addAll( original );
return copy;
}
else
{
return new ArrayList<>();
}
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OpenLdapConfigFormat.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OpenLdapConfigFormat.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.config.model;
/**
* The OpenLDAP configuration format : either static (slapd.conf) or dynamic (slapd.d).
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public enum OpenLdapConfigFormat
{
STATIC, // slapd.d
DYNAMIC; // slapd.conf
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcFrontendConfig.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcFrontendConfig.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.config.model;
import java.util.ArrayList;
import java.util.List;
/**
* Java bean for the 'OlcFrontendConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcFrontendConfig implements AuxiliaryObjectClass
{
/**
* Field for the 'olcDefaultSearchBase' attribute.
*/
@ConfigurationElement(attributeType = "olcDefaultSearchBase", version="2.4.0")
private String olcDefaultSearchBase;
/**
* Field for the 'olcPasswordHash' attribute.
*/
@ConfigurationElement(attributeType = "olcPasswordHash", version="2.4.0")
private List<String> olcPasswordHash = new ArrayList<>();
/**
* Field for the 'olcSortVals' attribute.
*/
@ConfigurationElement(attributeType = "olcSortVals", version="2.4.6")
private List<String> olcSortVals = new ArrayList<>();
/**
* @param strings
*/
public void addOlcPasswordHash( String... strings )
{
for ( String string : strings )
{
olcPasswordHash.add( string );
}
}
/**
* @param strings
*/
public void addOlcSortVals( String... strings )
{
for ( String string : strings )
{
olcSortVals.add( string );
}
}
/**
* @param strings
*/
public void clearOlcPasswordHash()
{
olcPasswordHash.clear();
}
public void clearOlcSortVals()
{
olcSortVals.clear();
}
/**
* @return the olcDefaultSearchBase
*/
public String getOlcDefaultSearchBase()
{
return olcDefaultSearchBase;
}
/**
* @return the olcPasswordHash
*/
public List<String> getOlcPasswordHash()
{
return olcPasswordHash;
}
/**
* @return the olcSortVals
*/
public List<String> getOlcSortVals()
{
return olcSortVals;
}
/**
* @param olcDefaultSearchBase the olcDefaultSearchBase to set
*/
public void setOlcDefaultSearchBase( String olcDefaultSearchBase )
{
this.olcDefaultSearchBase = olcDefaultSearchBase;
}
/**
* @param olcPasswordHash the setOlcPasswordHash to set
*/
public void setOlcPasswordHash( List<String> olcPasswordHash )
{
this.olcPasswordHash = olcPasswordHash;
}
/**
* @param olcSortVals the olcSortVals to set
*/
public void setOlcSortVals( List<String> olcSortVals )
{
this.olcSortVals = olcSortVals;
}
}
| 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.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcDbIndex.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/OlcDbIndex.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.config.model;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.directory.studio.openldap.common.ui.model.DbIndexTypeEnum;
/**
* This class represents an index value.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcDbIndex
{
/** The "default" special flag tag */
private static final String DEFAULT_FLAG = "default";
/** The space ' ' separator */
private static final String SPACE_SEPARATOR = " ";
/** The comma ',' separator */
private static final String COMMA_SEPARATOR = ",";
/** The default flag */
private boolean isDefault = false;
/** The list of attributes */
private List<String> attributes = new ArrayList<>();
/** The list of index types */
private Set<DbIndexTypeEnum> indexTypes = new HashSet<>();
/**
* Creates a new instance of OlcDbIndex.
*/
public OlcDbIndex()
{
}
/**
* Creates a new instance of OlcDbIndex.
*
* @param s the string
*/
public OlcDbIndex( String s )
{
if ( s != null )
{
String[] components = s.split( SPACE_SEPARATOR );
if ( components.length > 0 )
{
String[] attrs = components[0].split( COMMA_SEPARATOR );
if ( attrs.length > 0 )
{
for ( String attribute : attrs )
{
addAttribute( attribute );
}
}
if ( components.length == 2 )
{
String[] indexes = components[1].split( COMMA_SEPARATOR );
if ( indexes.length > 0 )
{
for ( String indexType : indexes )
{
DbIndexTypeEnum type = DbIndexTypeEnum.valueOf( indexType );
if ( type != null )
{
addIndexType( type );
}
}
}
}
}
}
}
/**
* Adds an attribute.
*
* @param attribute the attribute
*/
public void addAttribute( String attribute )
{
if ( DEFAULT_FLAG.equalsIgnoreCase( attribute ) )
{
setDefault( true );
}
else
{
attributes.add( attribute );
}
}
/**
* Gets the default flag.
*
* @return the default flag
*/
public boolean isDefault()
{
return isDefault;
}
/**
* Sets the default flag.
*
* @param isDefault the default flag
*/
public void setDefault( boolean isDefault )
{
this.isDefault = isDefault;
}
/**
* Adds an index type.
*
* @param indexType the index type
*/
public void addIndexType( DbIndexTypeEnum indexType )
{
indexTypes.add( indexType );
}
/**
* Clears the attributes.
*/
public void clearAttributes()
{
attributes.clear();
}
/**
* Clears the index types.
*/
public void clearIndexTypes()
{
indexTypes.clear();
}
/**
* Removes an attribute.
*
* @param attribute the attribute
*/
public void removeAttribute( String attribute )
{
attributes.remove( attribute );
}
/**
* Removes an index type.
*
* @param indexType the index type
*/
public void removeIndexType( DbIndexTypeEnum indexType )
{
indexTypes.remove( indexType );
}
/**
* Gets the attributes.
*
* @return the attributes
*/
public List<String> getAttributes()
{
return attributes;
}
/**
* Gets the index types.
*
* @return the index types
*/
public Set<DbIndexTypeEnum> getIndexTypes()
{
return indexTypes;
}
/**
* {@inheritDoc}
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
if ( isDefault )
{
sb.append( DEFAULT_FLAG );
}
else
{
if ( !attributes.isEmpty() )
{
for ( String attribute : attributes )
{
if ( isFirst )
{
isFirst = false;
}
else
{
sb.append( COMMA_SEPARATOR );
}
sb.append( attribute );
}
}
}
if ( !indexTypes.isEmpty() )
{
sb.append( SPACE_SEPARATOR );
isFirst = true;
for ( DbIndexTypeEnum indexType : indexTypes )
{
if ( isFirst )
{
isFirst = false;
}
else
{
sb.append( COMMA_SEPARATOR );
}
sb.append( indexType.toString() );
}
}
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/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/overlay/OlcMemberOf.java | plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/overlay/OlcMemberOf.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.config.model.overlay;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.studio.openldap.config.model.ConfigurationElement;
import org.apache.directory.studio.openldap.config.model.OlcOverlayConfig;
/**
* Java bean for the 'olcSyncProvConfig' object class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class OlcMemberOf extends OlcOverlayConfig
{
/**
* Field for the 'olcMemberOfDangling' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfDangling", version="2.4.0")
private String olcMemberOfDangling;
/**
* Field for the 'olcMemberOfDanglingError' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfDanglingError", version="2.4.8")
private String olcMemberOfDanglingError;
/**
* Field for the 'olcMemberOfDN' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfDN", version="2.4.0")
private Dn olcMemberOfDN;
/**
* Field for the 'olcMemberOfGroupOC' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfGroupOC", version="2.4.0")
private String olcMemberOfGroupOC;
/**
* Field for the 'olcMemberOfMemberAD' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfMemberAD", version="2.4.0")
private String olcMemberOfMemberAD;
/**
* Field for the 'olcMemberOfMemberOfAD' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfMemberOfAD", version="2.4.0")
private String olcMemberOfMemberOfAD;
/**
* Field for the 'olcMemberOfRefInt' attribute.
*/
@ConfigurationElement(attributeType = "olcMemberOfRefInt", version="2.4.0")
private Boolean olcMemberOfRefInt;
/**
* Creates a new instance of OlcMemberOf.
*/
public OlcMemberOf()
{
super();
olcOverlay = "memberof";
}
/**
* Creates a copy instance of OlcMemberOf.
*
* @param o the initial object
*/
public OlcMemberOf( OlcMemberOf o )
{
super();
olcMemberOfDangling = o.olcMemberOfDangling;
olcMemberOfDanglingError = o.olcMemberOfDanglingError;
olcMemberOfDN = o.olcMemberOfDN;
olcMemberOfGroupOC = o.olcMemberOfGroupOC;
olcMemberOfMemberAD = o.olcMemberOfMemberAD;
olcMemberOfMemberOfAD = o.olcMemberOfMemberOfAD;
olcMemberOfRefInt = o.olcMemberOfRefInt;
}
/**
* @return
*/
public String getOlcMemberOfDangling()
{
return olcMemberOfDangling;
}
/**
* @return
*/
public String getOlcMemberOfDanglingError()
{
return olcMemberOfDanglingError;
}
/**
* @return
*/
public Dn getOlcMemberOfDN()
{
return olcMemberOfDN;
}
/**
* @return
*/
public String getOlcMemberOfGroupOC()
{
return olcMemberOfGroupOC;
}
/**
* @return
*/
public String getOlcMemberOfMemberAD()
{
return olcMemberOfMemberAD;
}
/**
* @return
*/
public String getOlcMemberOfMemberOfAD()
{
return olcMemberOfMemberOfAD;
}
/**
* @return
*/
public Boolean getOlcMemberOfRefInt()
{
return olcMemberOfRefInt;
}
/**
* @param olcMemberOfDangling
*/
public void setOlcMemberOfDangling( String olcMemberOfDangling )
{
this.olcMemberOfDangling = olcMemberOfDangling;
}
/**
* @param olcMemberOfDanglingError
*/
public void setOlcMemberOfDanglingError( String olcMemberOfDanglingError )
{
this.olcMemberOfDanglingError = olcMemberOfDanglingError;
}
/**
* @param olcMemberOfDN
*/
public void setOlcMemberOfDN( Dn olcMemberOfDN )
{
this.olcMemberOfDN = olcMemberOfDN;
}
/**
* @param olcMemberOfGroupOC
*/
public void setOlcMemberOfGroupOC( String olcMemberOfGroupOC )
{
this.olcMemberOfGroupOC = olcMemberOfGroupOC;
}
/**
* @param olcMemberOfMemberAD
*/
public void setOlcMemberOfMemberAD( String olcMemberOfMemberAD )
{
this.olcMemberOfMemberAD = olcMemberOfMemberAD;
}
/**
* @param olcMemberOfMemberOfAD
*/
public void setOlcMemberOfMemberOfAD( String olcMemberOfMemberOfAD )
{
this.olcMemberOfMemberOfAD = olcMemberOfMemberOfAD;
}
/**
* @param olcMemberOfRefInt
*/
public void setOlcMemberOfRefInt( Boolean olcMemberOfRefInt )
{
this.olcMemberOfRefInt = olcMemberOfRefInt;
}
/**
* {@inheritDoc}
*/
@Override
public OlcMemberOf copy()
{
return new OlcMemberOf( this );
}
}
| 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.