You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/11/04 21:42:09 UTC

svn commit: r591833 - in /directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core: BrowserConnectionIO.java utils/DnUtils.java

Author: seelmann
Date: Sun Nov  4 12:42:08 2007
New Revision: 591833

URL: http://svn.apache.org/viewvc?rev=591833&view=rev
Log:
DIRSTUDIO-229: Forgot some files.

Added:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java   (with props)
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java   (with props)

Added: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java?rev=591833&view=auto
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java (added)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java Sun Nov  4 12:42:08 2007
@@ -0,0 +1,489 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.ldapbrowser.core;
+
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.io.ConnectionIOException;
+import org.apache.directory.studio.ldapbrowser.core.model.BookmarkParameter;
+import org.apache.directory.studio.ldapbrowser.core.model.IBookmark;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.AliasDereferencingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Bookmark;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+
+/**
+ * This class is used to read/write the 'connections.xml' file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserConnectionIO
+{
+    // XML tags
+    private static final String BROWSER_CONNECTIONS_TAG = "browserConnections";
+    
+    private static final String BROWSER_CONNECTION_TAG = "browserConnection";
+    private static final String ID_TAG = "id";
+    
+    private static final String SEARCHES_TAG = "searches";
+    private static final String SEARCH_PARAMETER_TAG = "searchParameter";
+    private static final String NAME_TAG = "name";
+    private static final String SEARCH_BASE_TAG = "searchBase";
+    private static final String FILTER_TAG = "filer";
+    private static final String RETURNING_ATTRIBUTES_TAG = "returningAttributes";
+    private static final String RETURNING_ATTRIBUTE_TAG = "returningAttribute";
+    private static final String VALUE_TAG = "value";
+    private static final String SCOPE_TAG = "scope";
+    private static final String TIME_LIMIT_TAG = "timeLimit";
+    private static final String COUNT_LIMIT_TAG = "countLimit";
+    private static final String ALIASES_DEREFERENCING_METHOD_TAG = "aliasesDereferencingMethod";
+    private static final String REFERRALS_HANDLING_METHOD_TAG = "referralsHandlingMethod";
+    //TODO: Controls
+    
+    private static final String BOOKMARKS_TAG = "bookmarks";
+    private static final String BOOKMARK_PARAMETER_TAG = "bookmarkParameter";
+    private static final String DN_TAG = "dn";
+    
+
+    /**
+     * Loads the browser connections using the input stream.
+     *
+     * @param stream
+     *      the input stream
+     * @param browserConnectionMap
+     *      the map of browser connections
+     * @throws ConnectionIOException 
+     *      if an error occurs when converting the document
+     */
+    public static void load( FileInputStream stream, Map<String, IBrowserConnection> browserConnectionMap ) throws ConnectionIOException
+    {
+        SAXReader saxReader = new SAXReader();
+        Document document = null;
+
+        try
+        {
+            document = saxReader.read( stream );
+        }
+        catch ( DocumentException e )
+        {
+            throw new ConnectionIOException( e.getMessage() );
+        }
+
+        Element rootElement = document.getRootElement();
+        if ( !rootElement.getName().equals( BROWSER_CONNECTIONS_TAG ) )
+        {
+            throw new ConnectionIOException( "The file does not seem to be a valid BrowserConnections file." );
+        }
+
+        for ( Iterator<?> i = rootElement.elementIterator( BROWSER_CONNECTION_TAG ); i.hasNext(); )
+        {
+            Element browserConnectionElement = ( Element ) i.next();
+            readBrowserConnection( browserConnectionElement, browserConnectionMap );
+        }
+    }
+
+
+    /**
+     * Reads a browser connection from the given Element.
+     *
+     * @param element
+     *      the element
+     * @param browserConnectionMap
+     *      the map of browser connections     *      
+     * @throws ConnectionIOException
+     *      if an error occurs when converting values
+     */
+    private static void readBrowserConnection( Element element, Map<String, IBrowserConnection> browserConnectionMap ) throws ConnectionIOException
+    {
+        // ID
+        Attribute idAttribute = element.attribute( ID_TAG );
+        if ( idAttribute != null )
+        {
+            String id = idAttribute.getValue();
+            IBrowserConnection browserConnection = browserConnectionMap.get( id );
+            
+            if( browserConnection != null )
+            {
+                Element searchesElement = element.element( SEARCHES_TAG );
+                if ( searchesElement != null )
+                {
+                    for ( Iterator<?> i = searchesElement.elementIterator( SEARCH_PARAMETER_TAG ); i.hasNext(); )
+                    {
+                        Element searchParameterElement = ( Element ) i.next();
+                        SearchParameter searchParameter = readSearch( searchParameterElement, browserConnection );
+                        ISearch search = new Search( browserConnection, searchParameter );
+                        browserConnection.getSearchManager().addSearch( search );
+                    }
+                }
+                
+                Element bookmarksElement = element.element( BOOKMARKS_TAG );
+                if ( bookmarksElement != null )
+                {
+                    for ( Iterator<?> i = bookmarksElement.elementIterator( BOOKMARK_PARAMETER_TAG ); i.hasNext(); )
+                    {
+                        Element bookmarkParameterElement = ( Element ) i.next();
+                        BookmarkParameter bookmarkParameter = readBookmark( bookmarkParameterElement, browserConnection );
+                        IBookmark bookmark = new Bookmark( browserConnection, bookmarkParameter );
+                        browserConnection.getBookmarkManager().addBookmark( bookmark );
+                    }
+                }
+            }
+        }
+    }
+    
+    
+    private static SearchParameter readSearch( Element searchParameterElement, IBrowserConnection browserConnection ) throws ConnectionIOException
+    {
+        SearchParameter searchParameter = new SearchParameter();
+        
+        // Name
+        Attribute nameAttribute = searchParameterElement.attribute( NAME_TAG );
+        if ( nameAttribute != null )
+        {
+            searchParameter.setName( nameAttribute.getValue() );
+        }
+        
+        // Search base
+        Attribute searchBaseAttribute = searchParameterElement.attribute( SEARCH_BASE_TAG );
+        if ( searchBaseAttribute != null )
+        {
+            try
+            {
+                searchParameter.setSearchBase( new LdapDN( searchBaseAttribute.getValue() ) );
+            }
+            catch ( InvalidNameException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Search Base' of search '" + searchParameter.getName()
+                    + "' :" + searchBaseAttribute.getValue() );
+            }
+        }
+        
+        // Filter
+        Attribute filterAttribute = searchParameterElement.attribute( FILTER_TAG );
+        if ( filterAttribute != null )
+        {
+            searchParameter.setFilter( filterAttribute.getValue() );
+        }
+        
+        // Returning Attributes
+        Element returningAttributesElement = searchParameterElement.element( RETURNING_ATTRIBUTES_TAG );
+        if ( returningAttributesElement != null )
+        {
+            List<String> returningAttributes = new ArrayList<String>();
+            for ( Iterator<?> i = returningAttributesElement.elementIterator( RETURNING_ATTRIBUTE_TAG ); i.hasNext(); )
+            {
+                Element returningAttributeElement = ( Element ) i.next();
+                
+                Attribute valueAttribute = returningAttributeElement.attribute( VALUE_TAG );
+                if ( valueAttribute != null )
+                {
+                    returningAttributes.add( valueAttribute.getValue() );
+                }
+            }
+            searchParameter.setReturningAttributes( returningAttributes
+                .toArray( new String[returningAttributes.size()] ) );
+        }
+        
+        // Scope
+        Attribute scopeAttribute = searchParameterElement.attribute( SCOPE_TAG );
+        if ( scopeAttribute != null )
+        {
+            try
+            {
+                searchParameter.setScope( SearchScope.valueOf( scopeAttribute.getValue() ) );
+            }
+            catch ( IllegalArgumentException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Scope' of search '"
+                    + searchParameter.getName() + "' as int value. Scope value :"
+                    + scopeAttribute.getValue() );
+            }
+        }
+        
+        // Time limit
+        Attribute timeLimitAttribute = searchParameterElement.attribute( TIME_LIMIT_TAG );
+        if ( timeLimitAttribute != null )
+        {
+            try
+            {
+                searchParameter.setTimeLimit( Integer.parseInt( timeLimitAttribute.getValue() ) );
+            }
+            catch ( NumberFormatException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Time limit' of search '" + searchParameter.getName()
+                    + "' as int value. Time limit value :" + timeLimitAttribute.getValue() );
+            }
+        }
+        
+        // Count limit
+        Attribute countLimitAttribute = searchParameterElement.attribute( COUNT_LIMIT_TAG );
+        if ( countLimitAttribute != null )
+        {
+            try
+            {
+                searchParameter.setCountLimit( Integer.parseInt( countLimitAttribute.getValue() ) );
+            }
+            catch ( NumberFormatException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Count limit' of search '" + searchParameter.getName()
+                    + "' as int value. Count limit value :" + countLimitAttribute.getValue() );
+            }
+        }
+        
+        // Alias dereferencing method
+        Attribute aliasesDereferencingMethodAttribute = searchParameterElement.attribute( ALIASES_DEREFERENCING_METHOD_TAG );
+        if ( aliasesDereferencingMethodAttribute != null )
+        {
+            try
+            {
+                searchParameter.setAliasesDereferencingMethod( AliasDereferencingMethod
+                    .valueOf( aliasesDereferencingMethodAttribute.getValue() ) );
+            }
+            catch ( IllegalArgumentException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Aliases Dereferencing Method' of search '"
+                    + searchParameter.getName() + "' as int value. Aliases Dereferencing Method value :"
+                    + aliasesDereferencingMethodAttribute.getValue() );
+            }
+        }
+        
+        // Referrals handling method
+        Attribute referralsHandlingMethodAttribute = searchParameterElement.attribute( REFERRALS_HANDLING_METHOD_TAG );
+        if ( referralsHandlingMethodAttribute != null )
+        {
+            try
+            {
+                searchParameter.setReferralsHandlingMethod( ReferralHandlingMethod
+                    .valueOf( referralsHandlingMethodAttribute.getValue() ) );
+            }
+            catch ( IllegalArgumentException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'Referrals Handling Method' of search '"
+                    + searchParameter.getName() + "' as int value. Referrals Handling Method value :"
+                    + referralsHandlingMethodAttribute.getValue() );
+            }
+        }
+    
+        // TODO: Controls
+    
+        return searchParameter;
+    }
+
+
+    private static BookmarkParameter readBookmark( Element bookmarkParameterElement, IBrowserConnection browserConnection )
+        throws ConnectionIOException
+    {
+        BookmarkParameter bookmarkParameter = new BookmarkParameter();
+    
+        // Name
+        Attribute nameAttribute = bookmarkParameterElement.attribute( NAME_TAG );
+        if ( nameAttribute != null )
+        {
+            bookmarkParameter.setName( nameAttribute.getValue() );
+        }
+    
+        // DN
+        Attribute dnAttribute = bookmarkParameterElement.attribute( DN_TAG );
+        if ( dnAttribute != null )
+        {
+            try
+            {
+                bookmarkParameter.setDn( new LdapDN( dnAttribute.getValue() ) );
+            }
+            catch ( InvalidNameException e )
+            {
+                throw new ConnectionIOException( "Unable to parse 'DN' of bookmark '" + bookmarkParameter.getName()
+                    + "' :" + dnAttribute.getValue() );
+            }
+        }
+    
+        return bookmarkParameter;
+    }
+
+
+    /**
+     * Saves the browser connections using the output stream.
+     *
+     * @param stream
+     *      the OutputStream
+     * @param browserConnectionMap
+     *      the map of browser connections
+     * @throws IOException
+     *      if an I/O error occurs
+     */
+    public static void save( FileOutputStream stream, Map<String, IBrowserConnection> browserConnectionMap ) throws IOException
+    {
+        // Creating the Document
+        Document document = DocumentHelper.createDocument();
+
+        // Creating the root element
+        Element root = document.addElement( BROWSER_CONNECTIONS_TAG );
+
+        if ( browserConnectionMap != null )
+        {
+            for ( IBrowserConnection browserConnection : browserConnectionMap.values() )
+            {
+                writeBrowserConnection( root, browserConnection );
+            }
+        }
+
+        // Writing the file to disk
+        OutputFormat outformat = OutputFormat.createPrettyPrint();
+        outformat.setEncoding( "UTF-8" );
+        XMLWriter writer = new XMLWriter( stream, outformat );
+        writer.write( document );
+        writer.flush();
+    }
+
+
+    /**
+     * Writes the given browser connection to the given parent Element.
+     *
+     * @param parent
+     *      the parent Element
+     * @param browserConnection
+     *      the browser connection
+     */
+    private static void writeBrowserConnection( Element parent, IBrowserConnection browserConnection )
+    {
+        Element browserConnectionElement = parent.addElement( BROWSER_CONNECTION_TAG );
+
+        // ID
+        browserConnectionElement.addAttribute( ID_TAG, browserConnection.getConnection().getId() );
+
+        // Searches
+        Element searchesElement = browserConnectionElement.addElement( SEARCHES_TAG );
+        ISearch[] searches = browserConnection.getSearchManager().getSearches();
+        for ( ISearch search : searches )
+        {
+            Element searchParameterElement = searchesElement.addElement( SEARCH_PARAMETER_TAG );
+            writeSearch( searchParameterElement, search.getSearchParameter() );
+        }
+        
+        // Bookmarks
+        Element bookmarksElement = browserConnectionElement.addElement( BOOKMARKS_TAG );
+        IBookmark[] bookmarks = browserConnection.getBookmarkManager().getBookmarks();
+        for ( IBookmark bookmark : bookmarks )
+        {
+            Element bookmarkParameterElement = bookmarksElement.addElement( BOOKMARK_PARAMETER_TAG );
+            writeBookmark( bookmarkParameterElement, bookmark.getBookmarkParameter() );
+        }
+        
+        
+//        // Name
+//        connectionElement.addAttribute( NAME_TAG, connection.getName() );
+//
+//        // Host
+//        connectionElement.addAttribute( HOST_TAG, connection.getHost() );
+//
+//        // Port
+//        connectionElement.addAttribute( PORT_TAG, "" + connection.getPort() );
+//
+//        // Encryption Method
+//        connectionElement.addAttribute( ENCRYPTION_METHOD_TAG, connection.getEncryptionMethod().toString() );
+//
+//        // Auth Method
+//        connectionElement.addAttribute( AUTH_METHOD_TAG, connection.getAuthMethod().toString() );
+//
+//        // Bind Principal
+//        connectionElement.addAttribute( BIND_PRINCIPAL_TAG, connection.getBindPrincipal() );
+//
+//        // Bind Password
+//        connectionElement.addAttribute( BIND_PASSWORD_TAG, connection.getBindPassword() );
+
+    }
+
+
+    private static void writeSearch( Element searchParameterElement, SearchParameter searchParameter )
+    {
+        // Name
+        searchParameterElement.addAttribute( NAME_TAG, searchParameter.getName() );
+        
+        // Search base
+        String searchBase = searchParameter.getSearchBase() != null ? searchParameter.getSearchBase().getUpName() : "";
+        searchParameterElement.addAttribute( SEARCH_BASE_TAG, searchBase );
+        
+        // Filter
+        searchParameterElement.addAttribute( FILTER_TAG, searchParameter.getFilter() );
+        
+        // Returning Attributes
+        Element returningAttributesElement = searchParameterElement.addElement( RETURNING_ATTRIBUTES_TAG );
+        for ( String ra : searchParameter.getReturningAttributes() )
+        {
+            Element raElement = returningAttributesElement.addElement( RETURNING_ATTRIBUTE_TAG );
+            raElement.addAttribute( VALUE_TAG, ra );
+        } 
+        
+        // Scope
+        searchParameterElement.addAttribute( SCOPE_TAG, searchParameter.getScope().toString() );
+        
+        // Time limit
+        searchParameterElement.addAttribute( TIME_LIMIT_TAG, "" + searchParameter.getTimeLimit() );
+        
+        // Count limit
+        searchParameterElement.addAttribute( COUNT_LIMIT_TAG, "" + searchParameter.getCountLimit() );
+        
+        // Alias dereferencing method
+        searchParameterElement.addAttribute( ALIASES_DEREFERENCING_METHOD_TAG, searchParameter
+            .getAliasesDereferencingMethod().toString() );
+        
+        // Referrals handling method
+        searchParameterElement.addAttribute( REFERRALS_HANDLING_METHOD_TAG, searchParameter
+            .getReferralsHandlingMethod().toString() );
+        
+        // TODO: Controls
+    }
+
+
+    private static void writeBookmark( Element bookmarkParameterElement, BookmarkParameter bookmarkParameter )
+    {
+        // Name
+        bookmarkParameterElement.addAttribute( NAME_TAG, bookmarkParameter.getName() );
+        
+        // DN
+        String dn = bookmarkParameter.getDn() != null ? bookmarkParameter.getDn().getUpName() : "";
+        bookmarkParameterElement.addAttribute( DN_TAG, dn );
+    }
+
+}

Propchange: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionIO.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java?rev=591833&view=auto
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java (added)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java Sun Nov  4 12:42:08 2007
@@ -0,0 +1,209 @@
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+import java.util.Iterator;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+
+
+/**
+ * Utility class for LdapDN specific stuff.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DnUtils
+{
+
+    /**
+     * Transforms the given DN into a normalized String, usable by the schema cache.
+     * The following transformations are permformed:
+     * <ul>
+     *   <li>The attribute type is replaced by the OID
+     *   <li>The attribute value is trimmed and lowercased
+     * </ul> 
+     * Example: the surname=Bar will be transformed to
+     * 2.5.4.4=bar
+     * 
+     * 
+     * @param dn the DN
+     * @param schema the schema
+     * 
+     * @return the oid string
+     */
+    public static String getNormalizedOidString( LdapDN dn, Schema schema )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        Iterator<Rdn> it = dn.getRdns().iterator();
+        while ( it.hasNext() )
+        {
+            Rdn rdn = it.next();
+            sb.append( getOidString( rdn, schema ) );
+            if ( it.hasNext() )
+            {
+                sb.append( ',' );
+            }
+        }
+
+        return sb.toString();
+    }
+
+
+    private static String getOidString( Rdn rdn, Schema schema )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        Iterator<AttributeTypeAndValue> it = rdn.iterator();
+        while ( it.hasNext() )
+        {
+            AttributeTypeAndValue atav = it.next();
+            sb.append( getOidString( atav, schema ) );
+            if ( it.hasNext() )
+            {
+                sb.append( '+' );
+            }
+        }
+
+        return sb.toString();
+    }
+
+
+    private static String getOidString( AttributeTypeAndValue atav, Schema schema )
+    {
+        String oid = schema != null ? schema.getAttributeTypeDescription( atav.getNormType() ).getNumericOID() : atav
+            .getNormType();
+        return oid.trim().toLowerCase() + "=" + ( ( String ) atav.getUpValue() ).trim().toLowerCase(); //$NON-NLS-1$
+    }
+
+
+    /**
+     * Composes an DN based on the given RDN and DN.
+     * 
+     * @param rdn the RDN
+     * @param parent the parent DN
+     * 
+     * @return the composed DN
+     */
+    public static LdapDN composeDn( Rdn rdn, LdapDN parent )
+    {
+        LdapDN ldapDn = ( LdapDN ) parent.clone();
+        ldapDn.add( ( Rdn ) rdn.clone() );
+        return ldapDn;
+    }
+
+
+    /**
+     * Gets the parent DN of the given DN or null if the given 
+     * DN hasn't a parent.
+     * 
+     * @param dn the DN
+     * 
+     * @return the parent DN, null if the given DN hasn't a parent
+     */
+    public static LdapDN getParent( LdapDN dn )
+    {
+        if ( dn.size() < 1 )
+        {
+            return null;
+        }
+        else
+        {
+            LdapDN parent = ( LdapDN ) dn.getPrefix( dn.size() - 1 );
+            return parent;
+        }
+    }
+
+
+    /**
+     * Compose an DN based on the given RDN and DN.
+     * 
+     * @param rdn the RDN
+     * @param parent the parent DN
+     * 
+     * @return the composed RDN
+     * 
+     * @throws InvalidNameException the invalid name exception
+     */
+    public static LdapDN composeDn( String rdn, String parent ) throws InvalidNameException
+    {
+        return composeDn( new Rdn( rdn ), new LdapDN( parent ) );
+    }
+
+
+    /**
+     * Composes an DN based on the given prefix and suffix.
+     * 
+     * @param prefix the prefix
+     * @param suffix the suffix
+     * 
+     * @return the composed DN
+     */
+    public static LdapDN composeDn( LdapDN prefix, LdapDN suffix )
+    {
+        LdapDN ldapDn = ( LdapDN ) suffix.clone();
+        
+        for ( Rdn rdn : prefix.getRdns() )
+        {
+            ldapDn.add( ( Rdn ) rdn.clone() );
+        }
+        
+        return ldapDn;
+    }
+    
+    /**
+     * Gets the prefix, cuts the suffix from the given DN.
+     * 
+     * @param dn the DN
+     * @param suffix the suffix
+     * 
+     * @return the prefix
+     */
+    public static LdapDN getPrefixName( LdapDN dn, LdapDN suffix )
+    {
+        if ( suffix.size() < 1 )
+        {
+            return null;
+        }
+        else
+        {
+            LdapDN parent = ( LdapDN ) dn.getSuffix( suffix.size() - 1 );
+            return parent;
+        }
+    }
+
+
+    /**
+     * Composes an RDN based on the given types and values.
+     * 
+     * @param rdnTypes the types
+     * @param rdnValues the values
+     * 
+     * @return the RDN
+     * 
+     * @throws InvalidNameException the invalid name exception
+     */
+    public static Rdn composeRdn( String[] rdnTypes, String[] rdnValues ) throws InvalidNameException
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( int i = 0; i < rdnTypes.length; i++ )
+        {
+            if( i > 0 )
+            {
+                sb.append( '+' );
+            }
+            
+            sb.append( rdnTypes[i] );
+            sb.append( '=' );
+            sb.append( Rdn.escapeValue( rdnValues[i] ) );
+        }
+        Rdn rdn = new Rdn( sb.toString() );
+        return rdn;
+    }
+
+}

Propchange: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Re: svn commit: r591833 - in /directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core: BrowserConnectionIO.java utils/DnUtils.java

Posted by Felix Knecht <fe...@apache.org>.
seelmann@apache.org schrieb:
> Author: seelmann
> Date: Sun Nov  4 12:42:08 2007
> New Revision: 591833
> 
> URL: http://svn.apache.org/viewvc?rev=591833&view=rev
> Log:
> DIRSTUDIO-229: Forgot some files.

Thanks, it's compiling again.

Felix