directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1044454 - in /directory/studio/trunk/plugins/apacheds.configuration.v2: plugin.properties plugin.xml src/main/java/org/apache/directory/studio/apacheds/configuration/v2/ApacheDS2ConfigurationContentDescriber.java
Date Fri, 10 Dec 2010 17:52:33 GMT
Author: pamarcelot
Date: Fri Dec 10 17:52:33 2010
New Revision: 1044454

URL: http://svn.apache.org/viewvc?rev=1044454&view=rev
Log:
Added a ContentDescriber class which checks that the given file is a correct ApacheDS Configuration
2.0 file.
Defined a specific content type which rules the opening of the Editor.

Added:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/ApacheDS2ConfigurationContentDescriber.java
Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.properties
    directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.xml

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.properties?rev=1044454&r1=1044453&r2=1044454&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.properties (original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.properties Fri Dec 10
17:52:33 2010
@@ -17,6 +17,9 @@
 
 Plugin_id=org.apache.directory.studio.apacheds.configuration.v2
 
+ContentType_ServerConfiguration_id=org.apache.directory.studio.apacheds.configuration.v2.contenttype
+ContentType_ServerConfiguration_name=Apache DS Configuration File
+
 Editor_ServerConfigurationEditor_id=org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor
 Editor_ServerConfigurationEditor_name=Server Configuration
 

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.xml?rev=1044454&r1=1044453&r2=1044454&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.xml (original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/plugin.xml Fri Dec 10 17:52:33
2010
@@ -23,13 +23,25 @@
          point="org.eclipse.ui.editors">
       <editor
             class="org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor"
-            default="true"
+            default="false"
             icon="resources/icons/editor.gif"
             id="%Editor_ServerConfigurationEditor_id"
             name="%Editor_ServerConfigurationEditor_name">
+         <contentTypeBinding
+               contentTypeId="%ContentType_ServerConfiguration_id">
+         </contentTypeBinding>
       </editor>
    </extension>
    <extension
+         point="org.eclipse.core.contenttype.contentTypes">
+      <content-type
+            describer="org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationContentDescriber"
+            file-names="config.ldif"
+            id="%ContentType_ServerConfiguration_id"
+            name="%ContentType_ServerConfiguration_name">
+      </content-type>
+   </extension>
+   <extension
          point="org.eclipse.ui.popupMenus">
       <objectContribution
             objectClass="org.apache.directory.studio.connection.core.Connection"
@@ -48,4 +60,4 @@
          </visibility>-->
       </objectContribution>
    </extension>
-</plugin>
\ No newline at end of file
+</plugin>

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/ApacheDS2ConfigurationContentDescriber.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/ApacheDS2ConfigurationContentDescriber.java?rev=1044454&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/ApacheDS2ConfigurationContentDescriber.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/ApacheDS2ConfigurationContentDescriber.java
Fri Dec 10 17:52:33 2010
@@ -0,0 +1,200 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.configuration.v2;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.name.DN;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.ITextContentDescriber;
+
+
+/**
+ * This class implements a ContentDescriber for Apache DS Configuration file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ApacheDS2ConfigurationContentDescriber implements ITextContentDescriber
+{
+    /** The maximum number of entries to search before determining the file as invalid */
+    private static int MAX_NUMBER_ENTRIES_SEARCH = 10;
+
+    /** The DN of the config entry ('ou=config')*/
+    private DN configEntryDn;
+
+    /** The DN of the directory service entry ('ads-directoryServiceId=default,ou=config')
*/
+    private DN directoryServiceDn;
+
+
+    /**
+     * Creates a new instance of ApacheDS2ConfigurationContentDescriber.
+     */
+    public ApacheDS2ConfigurationContentDescriber()
+    {
+        // Initializing DNs
+        try
+        {
+            configEntryDn = new DN( "ou=config" );
+            directoryServiceDn = new DN( "ads-directoryServiceId=default,ou=config" );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            // Will never occur.
+        }
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int describe( Reader contents, IContentDescription description ) throws IOException
+    {
+        long t1 = System.currentTimeMillis();
+
+        System.out.println( "describe" );
+
+        LdifReader reader = null;
+        try
+        {
+            reader = new LdifReader( contents );
+            return isValid( reader );
+        }
+        catch ( LdapException e )
+        {
+            return ITextContentDescriber.INVALID;
+        }
+        finally
+        {
+            if ( reader != null )
+            {
+                reader.close();
+            }
+            System.out.println( System.currentTimeMillis() - t1 );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int describe( InputStream contents, IContentDescription description ) throws IOException
+    {
+        long t1 = System.currentTimeMillis();
+        System.out.println( "describe" );
+
+        LdifReader reader = null;
+        try
+        {
+            reader = new LdifReader( contents );
+            return isValid( reader );
+        }
+        catch ( LdapException e )
+        {
+            return ITextContentDescriber.INVALID;
+        }
+        finally
+        {
+            if ( reader != null )
+            {
+                reader.close();
+            }
+            System.out.println( System.currentTimeMillis() - t1 );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public QualifiedName[] getSupportedOptions()
+    {
+        return new QualifiedName[0];
+    }
+
+
+    /**
+     * Indicates if the given {@link Reader} is a valid server configuration.
+     *
+     * @param reader
+     *      the LDIF reader
+     * @return
+     *      <code>ITextContentDescriber.VALID</code> if the given LDIF reader
is a valid server 
+     *      configuration, <code>ITextContentDescriber.INVALID</code> if not
+     */
+    private int isValid( LdifReader reader )
+    {
+        int checkedEntries = 0;
+        boolean configEntryFound = false;
+        boolean directoryServiceEntryFound = false;
+
+        while ( reader.hasNext() && ( checkedEntries < MAX_NUMBER_ENTRIES_SEARCH
) )
+        {
+            if ( configEntryFound && directoryServiceEntryFound )
+            {
+                // Getting out of the loop if we found both entries
+                break;
+            }
+
+            LdifEntry entry = reader.next();
+            checkedEntries++;
+
+            // Checking if this is the config entry
+            if ( !configEntryFound )
+            {
+                if ( configEntryDn.getName().equalsIgnoreCase( entry.getDn().getNormName()
) )
+                {
+                    configEntryFound = true;
+                    continue;
+                }
+            }
+
+            // Checking if this is the directory service entry
+            if ( !directoryServiceEntryFound )
+            {
+                if ( directoryServiceDn.getName().equalsIgnoreCase( entry.getDn().getNormName()
) )
+                {
+                    directoryServiceEntryFound = true;
+                    continue;
+                }
+            }
+        }
+
+        System.out.println( checkedEntries );
+
+        // Checking if we found both entries
+        if ( configEntryFound && directoryServiceEntryFound )
+        {
+            return ITextContentDescriber.VALID;
+        }
+        else
+        {
+            return ITextContentDescriber.INVALID;
+        }
+    }
+}



Mime
View raw message