directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592082 [19/20] - in /directory/sandbox/felixk/studio-ldapbrowser-core: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ s...
Date Mon, 05 Nov 2007 16:52:07 GMT
Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,218 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+import java.util.Comparator;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+
+
+public class AttributeComparator implements Comparator
+{
+
+    private IEntry dummyEntry;
+
+
+    public AttributeComparator( IBrowserConnection connection )
+    {
+        this.dummyEntry = new DummyEntry( LdapDN.EMPTY_LDAPDN, connection );
+    }
+
+
+    public AttributeComparator( IEntry entry )
+    {
+        this.dummyEntry = entry;
+    }
+
+
+    public int compare( Object o1, Object o2 )
+    {
+
+        IAttribute attribute1 = null;
+        IValue value1 = null;
+        if ( o1 instanceof IAttribute )
+        {
+            attribute1 = ( IAttribute ) o1;
+        }
+        else if ( o1 instanceof IValue )
+        {
+            value1 = ( IValue ) o1;
+            attribute1 = value1.getAttribute();
+        }
+        else if ( o1 instanceof LdifAttrValLine )
+        {
+            LdifAttrValLine line1 = ( LdifAttrValLine ) o1;
+            value1 = ModelConverter.ldifAttrValLineToValue( line1, dummyEntry );
+            attribute1 = value1.getAttribute();
+        }
+
+        IAttribute attribute2 = null;
+        IValue value2 = null;
+        if ( o2 instanceof IAttribute )
+        {
+            attribute2 = ( IAttribute ) o2;
+        }
+        else if ( o2 instanceof IValue )
+        {
+            value2 = ( IValue ) o2;
+            attribute2 = value2.getAttribute();
+        }
+        else if ( o2 instanceof LdifAttrValLine )
+        {
+            LdifAttrValLine line2 = ( LdifAttrValLine ) o2;
+            value2 = ModelConverter.ldifAttrValLineToValue( line2, dummyEntry );
+            attribute2 = value2.getAttribute();
+        }
+
+        if ( value1 != null && value2 != null )
+        {
+            if ( this.getSortByOrDefault() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION )
+            {
+                if ( value1.getAttribute() != value2.getAttribute() )
+                {
+                    return this.compareAttributeNames( value1.getAttribute(), value2.getAttribute() );
+                }
+                else
+                {
+                    return this.compareValues( value1, value2 );
+                }
+            }
+            else if ( this.getSortByOrDefault() == BrowserCoreConstants.SORT_BY_VALUE )
+            {
+                return this.compareValues( value1, value2 );
+            }
+            else
+            {
+                return this.equal();
+            }
+        }
+        else if ( attribute1 != null && attribute2 != null )
+        {
+            return this.compareAttributeNames( attribute1, attribute2 );
+        }
+        else
+        {
+            return this.equal();
+        }
+    }
+
+
+    private int compareAttributeNames( IAttribute attribute1, IAttribute attribute2 )
+    {
+
+        if ( attribute1.isObjectClassAttribute() )
+        {
+            return lessThan();
+        }
+        else if ( attribute2.isObjectClassAttribute() )
+        {
+            return greaterThan();
+        }
+
+        if ( attribute1.isMustAttribute() && !attribute2.isMustAttribute() )
+        {
+            return lessThan();
+        }
+        else if ( attribute2.isMustAttribute() && !attribute1.isMustAttribute() )
+        {
+            return greaterThan();
+        }
+
+        if ( attribute1.isOperationalAttribute() && !attribute2.isOperationalAttribute() )
+        {
+            return greaterThan();
+        }
+        else if ( attribute2.isOperationalAttribute() && !attribute1.isOperationalAttribute() )
+        {
+            return lessThan();
+        }
+
+        return compare( attribute1.getDescription(), attribute2.getDescription() );
+    }
+
+
+    private int compareValues( IValue value1, IValue value2 )
+    {
+
+        if ( value1.isEmpty() && value2.isEmpty() )
+        {
+            return equal();
+        }
+
+        if ( value1.isEmpty() && !value2.isEmpty() )
+        {
+            return greaterThan();
+        }
+        if ( !value1.isEmpty() && value2.isEmpty() )
+        {
+            return lessThan();
+        }
+
+        return compare( value1.getStringValue(), value2.getStringValue() );
+    }
+
+
+    private int getSortOrderOrDefault()
+    {
+        return BrowserCoreConstants.SORT_ORDER_ASCENDING;
+    }
+
+
+    private int getSortByOrDefault()
+    {
+        return BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION;
+    }
+
+
+    private int lessThan()
+    {
+        return this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1;
+    }
+
+
+    private int equal()
+    {
+        return 0;
+    }
+
+
+    private int greaterThan()
+    {
+        return this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1;
+    }
+
+
+    private int compare( String s1, String s2 )
+    {
+        return this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1.compareToIgnoreCase( s2 )
+            : s2.compareToIgnoreCase( s1 );
+    }
+
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/AttributeComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java Mon Nov  5 08:51:43 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/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/DnUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,213 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+import java.net.ConnectException;
+import java.net.NoRouteToHostException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ReferralException;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
+import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
+
+
+/**
+ * Utility class for JNDI specific stuff.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JNDIUtils
+{
+
+    /**
+     * Gets the LdapDN from a JNDI SearchResult object.
+     *
+     * @param sr the JNDI search result
+     * @return the LdapDN 
+     * @throws NamingException
+     */
+    public static LdapDN getDn( javax.naming.directory.SearchResult sr ) throws NamingException
+    {
+        String dn = sr.getNameInNamespace();
+        LdapDN ldapDn = new LdapDN( unescapeJndiName( dn ) );
+        return ldapDn;
+    }
+
+
+    /**
+     * Correct some JNDI encodings...
+     * 
+     * @param name the DN
+     * @return the modified DN
+     */
+    public static String unescapeJndiName( String name )
+    {
+        if ( name.startsWith( "\"" ) && name.endsWith( "\"" ) ) { //$NON-NLS-1$ //$NON-NLS-2$
+            name = name.substring( 1, name.length() - 1 );
+        }
+
+        name = name.replaceAll( "\\\\\\\\\"", "\\\\\"" ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\2C", "\\\\," ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\3B", "\\\\;" ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\22", "\\\\\"" ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\3C", "\\\\<" ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\3E", "\\\\>" ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\2B", "\\\\+" ); //$NON-NLS-1$ //$NON-NLS-2$
+        name = name.replaceAll( "\\\\5C", "\\\\\\\\" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        return name;
+    }
+
+
+    /**
+     * Creates a connection exception.
+     * 
+     * @param searchParameter the search parameter
+     * @param e the exception
+     * 
+     * @return the connection exception
+     */
+    public static ConnectionException createConnectionException( SearchParameter searchParameter, Throwable e )
+    {
+        ConnectionException connectionException = null;
+        ConnectionException lastException = null;
+
+        do
+        {
+            String message = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
+            int ldapStatusCode = -1;
+            String[] referrals = null;
+
+            // get LDAP status code
+            // [LDAP: error code 21 - telephoneNumber: value #0 invalid per
+            // syntax]
+            if ( message != null && message.startsWith( "[LDAP: error code " ) ) { //$NON-NLS-1$
+                int begin = "[LDAP: error code ".length(); //$NON-NLS-1$
+                int end = begin + 2;
+                try
+                {
+                    ldapStatusCode = Integer.parseInt( message.substring( begin, end ).trim() );
+                }
+                catch ( NumberFormatException nfe )
+                {
+                }
+            }
+
+            // special causes
+            // java_io_IOException=I/O exception occurred: {0}
+            // java_io_EOFException=End of file encountered: {0}
+            // java_io_FileNotFoundException=File not found: {0}
+            // java_io_InterruptedIOException=I/O has been interrupted.
+            // java_net_UnknownHostException=Cannot locate host: {0}
+            // java_net_ConnectException=Cannot connect to host: {0}
+            // java_net_SocketException=Socket Exception: {0}
+            // java_net_NoRouteToHostException={0}
+            if ( e instanceof ConnectException )
+            {
+                message = e.getMessage() + " (" + e.getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            if ( e instanceof NoRouteToHostException )
+            {
+                message += e.getMessage() + " (" + e.getMessage() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            if ( e instanceof UnknownHostException )
+            {
+                message = BrowserCoreMessages.model__unknown_host + e.getMessage();
+            }
+            if ( e instanceof SocketException )
+            {
+                message = e.getMessage() + " (" + e.getMessage() + ")";; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            if ( e instanceof ReferralException )
+            {
+                message = "Referrals: "; //$NON-NLS-1$
+                ReferralException re;
+                ArrayList<Object> referralsList = new ArrayList<Object>();
+
+                re = ( ReferralException ) e;
+                message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
+                referralsList.add( re.getReferralInfo() );
+
+                while ( re.skipReferral() )
+                {
+                    try
+                    {
+                        Context ctx = re.getReferralContext();
+                        ctx.list( "" ); //$NON-NLS-1$
+                    }
+                    catch ( NamingException e1 )
+                    {
+                        if ( e1 instanceof ReferralException )
+                        {
+                            re = ( ReferralException ) e1;
+                            message += BrowserCoreConstants.LINE_SEPARATOR + re.getReferralInfo();
+                            referralsList.add( re.getReferralInfo() );
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                }
+
+                referrals = referralsList.toArray( new String[referralsList.size()] );
+            }
+
+            ConnectionException ce;
+            if ( referrals != null )
+            {
+                ce = new org.apache.directory.studio.ldapbrowser.core.model.ReferralException( searchParameter,
+                    referrals, ldapStatusCode, message, e );
+            }
+            else
+            {
+                ce = new ConnectionException( ldapStatusCode, message, e );
+            }
+            if ( lastException != null )
+            {
+                lastException.initCause( ce );
+            }
+            lastException = ce;
+            if ( connectionException == null )
+            {
+                connectionException = lastException;
+            }
+
+            // next cause
+            e = e.getCause();
+        }
+        while ( e != null );
+
+        return connectionException;
+
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/JNDIUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,111 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+
+
+/**
+ * Utilies for filter handling.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapFilterUtils
+{
+
+    /**
+     * Creates a filter from the given value.
+     *
+     * @param value the value
+     *
+     * @return the filter
+     */
+    public static String getFilter( IValue value )
+    {
+        if ( value.isString() )
+        {
+            return "(" + value.getAttribute().getDescription() + "=" + getEncodedValue( value.getStringValue() ) + ")";
+        }
+        else
+        {
+            StringBuffer filter = new StringBuffer();
+            filter.append( "(" );
+            filter.append( value.getAttribute().getDescription() );
+            filter.append( "=" );
+
+            byte[] bytes = value.getBinaryValue();
+            for ( int i = 0; i < bytes.length; i++ )
+            {
+                int b = ( int ) bytes[i];
+                if ( b < 0 )
+                {
+                    b = 256 + b;
+                }
+                String s = Integer.toHexString( b );
+                filter.append( "\\" );
+                if ( s.length() == 1 )
+                {
+                    filter.append( "0" );
+                }
+                filter.append( s );
+            }
+
+            filter.append( ")" );
+            return filter.toString();
+        }
+    }
+
+
+    /**
+     * Encodes the given value according RFC2254.
+     *
+     * <pre>
+     * If a value should contain any of the following characters
+     * Character       ASCII value
+     * ---------------------------
+     * *               0x2a
+     * (               0x28
+     * )               0x29
+     * \               0x5c
+     * NUL             0x00
+     * the character must be encoded as the backslash '\' character (ASCII
+     * 0x5c) followed by the two hexadecimal digits representing the ASCII
+     * value of the encoded character. The case of the two hexadecimal
+     * digits is not significant.
+     * </pre>
+     *
+     * @param value the value
+     *
+     * @return the encoded value
+     */
+    public static String getEncodedValue( String value )
+    {
+        value = value.replaceAll( "\\\\", "\\\\5c" );
+        value = value.replaceAll( "" + '\u0000', "\\\\00" );
+        value = value.replaceAll( "\\*", "\\\\2a" );
+        value = value.replaceAll( "\\(", "\\\\28" );
+        value = value.replaceAll( "\\)", "\\\\29" );
+        return value;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdapFilterUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdifUtils.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdifUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdifUtils.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,242 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+
+
+/**
+ * Utilities for LDAP related encoding and decoding.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdifUtils
+{
+
+
+    /**
+     * Encodes the given string to UTF-8
+     *
+     * @param s the string to encode
+     *
+     * @return the byte[] the encoded value
+     */
+    public static byte[] utf8encode( String s )
+    {
+        try
+        {
+            return s.getBytes( "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            return s.getBytes();
+        }
+    }
+
+
+    /**
+     * Encodes the given string into URL format.
+     *
+     * @param s the string to encode
+     *
+     * @return the string the URL encoded string
+     */
+    public static String urlEncode( String s )
+    {
+        try
+        {
+            return URLEncoder.encode( s, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            return s;
+        }
+    }
+
+
+    /**
+     * Encodes the given byte array using BASE-64 encoding.
+     *
+     * @param b the b the byte array to encode
+     *
+     * @return the BASE-64 encoded string
+     */
+    public static String base64encode( byte[] b )
+    {
+        return utf8decode( Base64.encodeBase64( b ) );
+    }
+
+
+    /**
+     * Encodes the given byte array to a sequence of
+     * its hex values.
+     *
+     * @param data the data to encode
+     * @return the HEX encoded string
+     */
+    public static String hexEncode( byte[] data )
+    {
+        if ( data == null )
+            return null;
+
+        char[] c = Hex.encodeHex( data );
+        String s = new String( c );
+        return s;
+
+        // StringBuffer sb = new StringBuffer(data.length*3);
+        // for(int i=0; i<data.length; i++) {
+        // int b = (int)data[i];
+        // if(b<0) b=256+b;
+        // String s = Integer.toHexString(b)/*.toUpperCase()*/;
+        // if(s.length() ==1) s = "0" + s; //$NON-NLS-1$
+        // sb.append(s);
+        // if(i+1 < data.length)
+        // sb.append(' ');
+        // }
+        // return(sb.toString());
+    }
+
+
+    /**
+     * Decodes the given UTF-8 byte array to an string.
+     *
+     * @param b the b the byte array to decode
+     *
+     * @return the decoded string
+     */
+    public static String utf8decode( byte[] b )
+    {
+        try
+        {
+            return new String( b, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            return new String( b );
+        }
+    }
+
+
+    /**
+     * Decodes the given BASE-64 encoded string to its
+     * bytes presentation.
+     *
+     * @param s the s the BASE-64 encoded string
+     *
+     * @return the byte[] the decoded byte array
+     */
+    public static byte[] base64decodeToByteArray( String s )
+    {
+        return Base64.decodeBase64( utf8encode( s ) );
+    }
+
+
+    /**
+     * Checks if the given distinguished name must be encoded.
+     *
+     * @param dn the dn to check
+     *
+     * @return true, if must encode DN
+     */
+    public static boolean mustEncodeDN( String dn )
+    {
+        return mustEncode( dn );
+    }
+
+
+    /**
+     * Checks if the given string must be encoded to be
+     * used in an LDIF.
+     *
+     * @param value the value to check
+     *
+     * @return true, if must encode
+     */
+    public static boolean mustEncode( String value )
+    {
+        if ( value == null || value.length() < 1 )
+        {
+            return false;
+        }
+
+        if ( value.startsWith( " " ) || value.startsWith( ":" ) || value.startsWith( "<" ) )
+        {
+            return true;
+        }
+        if ( value.endsWith( " " ) )
+        {
+            return true;
+        }
+
+        for ( int i = 0; i < value.length(); i++ )
+        {
+            if ( value.charAt( i ) == '\r' || value.charAt( i ) == '\n' || value.charAt( i ) == '\u0000'
+                || value.charAt( i ) > '\u007F' )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    /**
+     * Gets the string value from the given {@link IValue}. If the given
+     * {@link IValue} is binary is is encoded according to the regquested
+     * encoding type.
+     *
+     * @param value the value
+     * @param binaryEncoding the binary encoding type
+     *
+     * @return the string value
+     */
+    public static String getStringValue( IValue value, int binaryEncoding )
+    {
+        String s = value.getStringValue();
+        if ( value.isBinary() && LdifUtils.mustEncode( s ) )
+        {
+            byte[] binary = value.getBinaryValue();
+            if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_BASE64 )
+            {
+                s = LdifUtils.base64encode( binary );
+            }
+            else if ( binaryEncoding == BrowserCoreConstants.BINARYENCODING_HEX )
+            {
+                s = LdifUtils.hexEncode( binary );
+            }
+            else
+            {
+                s = BrowserCoreConstants.BINARY;
+            }
+        }
+        return s;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/LdifUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,296 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+/**
+ * Utilities to convert between models
+ */
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifChangeRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifChangeTypeLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifCommentLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifDnLine;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifSepLine;
+
+
+public class ModelConverter
+{
+
+
+    /**
+     * Converts the given {@link LdifContentRecord} to an {@link DummyEntry}.
+     *
+     * @param ldifContentRecord the ldif content record to convert
+     * @param connection the connection
+     *
+     * @return the resulting dummy entry
+     *
+     * @throws InvalidNameException
+     */
+    public static DummyEntry ldifContentRecordToEntry( LdifContentRecord ldifContentRecord, IBrowserConnection connection )
+        throws InvalidNameException
+    {
+        return createIntern( ldifContentRecord, connection );
+    }
+
+
+    /**
+     * Converts the given {@link LdifChangeAddRecord} to an {@link DummyEntry}.
+     *
+     * @param ldifChangeAddRecord the ldif change add record to convert
+     * @param connection the connection
+     *
+     * @return the resulting dummy entry
+     *
+     * @throws InvalidNameException
+     */
+    public static DummyEntry ldifChangeAddRecordToEntry( LdifChangeAddRecord ldifChangeAddRecord, IBrowserConnection connection )
+        throws InvalidNameException
+    {
+        return createIntern( ldifChangeAddRecord, connection );
+    }
+
+
+    /**
+     * Creates an {@link DummyEntry} from the given {@link LdifRecord}.
+     *
+     * @param connection the connection
+     * @param ldifRecord the ldif record
+     *
+     * @return the dummy entry
+     *
+     * @throws InvalidNameException
+     */
+    private static DummyEntry createIntern( LdifRecord ldifRecord, IBrowserConnection connection ) throws InvalidNameException
+    {
+        LdifPart[] parts = ldifRecord.getParts();
+
+        EventRegistry.suspendEventFireingInCurrentThread();
+
+        DummyEntry entry = new DummyEntry( new LdapDN( ldifRecord.getDnLine().getValueAsString() ), connection );
+
+        for ( int i = 0; i < parts.length; i++ )
+        {
+            if ( parts[i] instanceof LdifAttrValLine )
+            {
+                LdifAttrValLine line = ( LdifAttrValLine ) parts[i];
+                String attributeName = line.getUnfoldedAttributeDescription();
+                Object value = line.getValueAsObject();
+                IAttribute attribute = entry.getAttribute( attributeName );
+                if ( attribute == null )
+                {
+                    attribute = new Attribute( entry, attributeName );
+                    entry.addAttribute( attribute );
+                }
+                attribute.addValue( new Value( attribute, value ) );
+            }
+            else if ( !( parts[i] instanceof LdifDnLine ) && !( parts[i] instanceof LdifSepLine ) )
+            {
+                String name = parts[i].toRawString();
+                name = name.replaceAll( "\n", "" );
+                name = name.replaceAll( "\r", "" );
+                IAttribute attribute = new Attribute( entry, name );
+                attribute.addValue( new Value( attribute, parts[i] ) );
+                entry.addAttribute( attribute );
+                // IAttribute attribute = entry.getAttribute("");
+                // if(attribute == null) {
+                // attribute = new Attribute(entry, "");
+                // entry.addAttribute(attribute, null);
+                // }
+                // attribute.addValue(new Value(attribute, parts[i]), null);
+            }
+        }
+
+        EventRegistry.resumeEventFireingInCurrentThread();
+
+        return entry;
+    }
+
+
+    public static LdifChangeAddRecord entryToLdifChangeAddRecord( IEntry entry )
+    {
+
+        boolean mustCreateChangeTypeLine = true;
+        IAttribute[] attributes = entry.getAttributes();
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+            IValue[] values = attributes[i].getValues();
+            for ( int ii = 0; ii < values.length; ii++ )
+            {
+                IValue value = values[ii];
+                if ( value.getRawValue() instanceof LdifPart )
+                {
+                    mustCreateChangeTypeLine = false;
+                }
+            }
+        }
+
+        // LdifChangeAddRecord record =
+        // LdifChangeAddRecord.create(entry.getDn().toString());
+        LdifChangeAddRecord record = new LdifChangeAddRecord( LdifDnLine.create( entry.getDn().getUpName() ) );
+        if ( mustCreateChangeTypeLine )
+        {
+            addControls( record, entry );
+            record.setChangeType( LdifChangeTypeLine.createAdd() );
+        }
+
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+            String name = attributes[i].getDescription();
+            IValue[] values = attributes[i].getValues();
+            for ( int ii = 0; ii < values.length; ii++ )
+            {
+                IValue value = values[ii];
+                if ( value.getRawValue() instanceof LdifPart )
+                {
+                    LdifPart part = ( LdifPart ) value.getRawValue();
+                    if ( part instanceof LdifChangeTypeLine )
+                    {
+                        record.setChangeType( ( LdifChangeTypeLine ) part );
+                    }
+                    else if ( part instanceof LdifCommentLine )
+                    {
+                        record.addComment( ( LdifCommentLine ) part );
+                    }
+                    else if ( part instanceof LdifControlLine )
+                    {
+                        record.addControl( ( LdifControlLine ) part );
+                    }
+                }
+                else if ( value.isString() )
+                {
+                    record.addAttrVal( LdifAttrValLine.create( name, value.getStringValue() ) );
+                }
+                else
+                {
+                    record.addAttrVal( LdifAttrValLine.create( name, value.getBinaryValue() ) );
+                }
+            }
+        }
+
+        record.finish( LdifSepLine.create() );
+
+        return record;
+    }
+
+
+    public static LdifContentRecord entryToLdifContentRecord( IEntry entry )
+    {
+
+        LdifContentRecord record = LdifContentRecord.create( entry.getDn().getUpName() );
+
+        IAttribute[] attributes = entry.getAttributes();
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+            String name = attributes[i].getDescription();
+            IValue[] values = attributes[i].getValues();
+            for ( int ii = 0; ii < values.length; ii++ )
+            {
+                IValue value = values[ii];
+                if ( value.getRawValue() instanceof LdifPart )
+                {
+                    LdifPart part = ( LdifPart ) value.getRawValue();
+                    if ( part instanceof LdifCommentLine )
+                    {
+                        record.addComment( ( LdifCommentLine ) part );
+                    }
+                }
+                else if ( value.isString() )
+                {
+                    record.addAttrVal( LdifAttrValLine.create( name, value.getStringValue() ) );
+                }
+                else
+                {
+                    record.addAttrVal( LdifAttrValLine.create( name, value.getBinaryValue() ) );
+                }
+            }
+        }
+
+        record.finish( LdifSepLine.create() );
+
+        return record;
+    }
+
+
+    public static LdifAttrValLine valueToLdifAttrValLine( IValue value )
+    {
+
+        LdifAttrValLine line;
+        if ( value.isString() )
+        {
+            line = LdifAttrValLine.create( value.getAttribute().getDescription(), value.getStringValue() );
+        }
+        else
+        {
+            line = LdifAttrValLine.create( value.getAttribute().getDescription(), value.getBinaryValue() );
+        }
+        return line;
+    }
+
+
+    public static IValue ldifAttrValLineToValue( LdifAttrValLine line, IEntry entry )
+    {
+        try
+        {
+            IAttribute attribute = new Attribute( entry, line.getUnfoldedAttributeDescription() );
+            IValue value = new Value( attribute, line.getValueAsObject() );
+            return value;
+        }
+        catch ( Exception e )
+        {
+            return null;
+        }
+    }
+
+
+    public static LdifDnLine dnToLdifDnLine( LdapDN dn )
+    {
+        LdifDnLine line = LdifDnLine.create( dn.getUpName() );
+        return line;
+    }
+
+
+    public static void addControls( LdifChangeRecord cr, IEntry entry )
+    {
+        if ( entry.isReferral() )
+        {
+            cr.addControl( LdifControlLine.create( IBrowserConnection.CONTROL_MANAGEDSAIT, null, ( String ) null ) );
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/UnixCrypt.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/UnixCrypt.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/UnixCrypt.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/UnixCrypt.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,518 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+/*
+ * @(#)UnixCrypt.java	0.9 96/11/25
+ *
+ * Copyright (c) 1996 Aki Yoshida. All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software
+ * for non-commercial or commercial purposes and without fee is
+ * hereby granted provided that this copyright notice appears in
+ * all copies.
+ */
+
+/**
+ * Unix crypt(3C) utility
+ *
+ * @version 	0.9, 11/25/96
+ * @author 	Aki Yoshida
+ */
+
+/**
+ * modified April 2001
+ * by Iris Van den Broeke, Daniel Deville
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+   /*
+    * @(#)UnixCrypt.java   0.9 96/11/25
+    *
+    * Copyright (c) 1996 Aki Yoshida. All rights reserved.
+    *
+    * Permission to use, copy, modify and distribute this software
+    * for non-commercial or commercial purposes and without fee is
+    * hereby granted provided that this copyright notice appears in
+    * all copies.
+   */
+  
+  /**
+   * Unix crypt(3C) utility
+   *
+   * @version     0.9, 11/25/96
+   * @author  Aki Yoshida
+   */
+  
+  /**
+   * modified April 2001
+   * by Iris Van den Broeke, Daniel Deville
+   */
+  
+  
+  /* ------------------------------------------------------------ */
+  /** Unix Crypt.
+   * Implements the one way cryptography used by Unix systems for
+   * simple password protection.
+   * @version $Id: UnixCrypt.java,v 1.1 2005/10/05 14:09:14 janb Exp $
+   * @author Greg Wilkins (gregw)
+   */
+  public class UnixCrypt extends Object
+  {
+  
+      /* (mostly) Standard DES Tables from Tom Truscott */
+      private static final byte[] IP = {      /* initial permutation */
+          58, 50, 42, 34, 26, 18, 10,  2,
+          60, 52, 44, 36, 28, 20, 12,  4,
+          62, 54, 46, 38, 30, 22, 14,  6,
+          64, 56, 48, 40, 32, 24, 16,  8,
+          57, 49, 41, 33, 25, 17,  9,  1,
+          59, 51, 43, 35, 27, 19, 11,  3,
+          61, 53, 45, 37, 29, 21, 13,  5,
+          63, 55, 47, 39, 31, 23, 15,  7};
+  
+      /* The final permutation is the inverse of IP - no table is necessary */
+      private static final byte[] ExpandTr = {    /* expansion operation */
+          32,  1,  2,  3,  4,  5,
+          4,  5,  6,  7,  8,  9,
+          8,  9, 10, 11, 12, 13,
+          12, 13, 14, 15, 16, 17,
+          16, 17, 18, 19, 20, 21,
+          20, 21, 22, 23, 24, 25,
+          24, 25, 26, 27, 28, 29,
+          28, 29, 30, 31, 32,  1};
+  
+      private static final byte[] PC1 = {     /* permuted choice table 1 */
+          57, 49, 41, 33, 25, 17,  9,
+          1, 58, 50, 42, 34, 26, 18,
+          10,  2, 59, 51, 43, 35, 27,
+          19, 11,  3, 60, 52, 44, 36,
+      
+          63, 55, 47, 39, 31, 23, 15,
+          7, 62, 54, 46, 38, 30, 22,
+          14,  6, 61, 53, 45, 37, 29,
+          21, 13,  5, 28, 20, 12,  4};
+  
+      private static final byte[] Rotates = { /* PC1 rotation schedule */
+          1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1};
+  
+  
+      private static final byte[] PC2 = {     /* permuted choice table 2 */
+          9, 18,    14, 17, 11, 24,  1,  5,
+          22, 25,     3, 28, 15,  6, 21, 10,
+          35, 38,    23, 19, 12,  4, 26,  8,
+          43, 54,    16,  7, 27, 20, 13,  2,
+  
+          0,  0,    41, 52, 31, 37, 47, 55,
+          0,  0,    30, 40, 51, 45, 33, 48,
+          0,  0,    44, 49, 39, 56, 34, 53,
+          0,  0,    46, 42, 50, 36, 29, 32};
+  
+      private static final byte[][] S = { /* 48->32 bit substitution tables */
+          /* S[1]         */
+          {14,  4, 13,  1,  2, 15, 11,  8,  3, 10,  6, 12,  5,  9,  0,  7,
+           0, 15,  7,  4, 14,  2, 13,  1, 10,  6, 12, 11,  9,  5,  3,  8,
+           4,  1, 14,  8, 13,  6,  2, 11, 15, 12,  9,  7,  3, 10,  5,  0,
+           15, 12,  8,  2,  4,  9,  1,  7,  5, 11,  3, 14, 10,  0,  6, 13},
+          /* S[2]         */
+          {15,  1,  8, 14,  6, 11,  3,  4,  9,  7,  2, 13, 12,  0,  5, 10,
+           3, 13,  4,  7, 15,  2,  8, 14, 12,  0,  1, 10,  6,  9, 11,  5,
+           0, 14,  7, 11, 10,  4, 13,  1,  5,  8, 12,  6,  9,  3,  2, 15,
+           13,  8, 10,  1,  3, 15,  4,  2, 11,  6,  7, 12,  0,  5, 14,  9},
+          /* S[3]         */
+          {10,  0,  9, 14,  6,  3, 15,  5,  1, 13, 12,  7, 11,  4,  2,  8,
+           13,  7,  0,  9,  3,  4,  6, 10,  2,  8,  5, 14, 12, 11, 15,  1,
+           13,  6,  4,  9,  8, 15,  3,  0, 11,  1,  2, 12,  5, 10, 14,  7,
+           1, 10, 13,  0,  6,  9,  8,  7,  4, 15, 14,  3, 11,  5,  2, 12},
+         /* S[4]         */
+         {7, 13, 14,  3,  0,  6,  9, 10,  1,  2,  8,  5, 11, 12,  4, 15,
+          13,  8, 11,  5,  6, 15,  0,  3,  4,  7,  2, 12,  1, 10, 14,  9,
+          10,  6,  9,  0, 12, 11,  7, 13, 15,  1,  3, 14,  5,  2,  8,  4,
+          3, 15,  0,  6, 10,  1, 13,  8,  9,  4,  5, 11, 12,  7,  2, 14},
+         /* S[5]         */
+         {2, 12,  4,  1,  7, 10, 11,  6,  8,  5,  3, 15, 13,  0, 14,  9,
+          14, 11,  2, 12,  4,  7, 13,  1,  5,  0, 15, 10,  3,  9,  8,  6,
+          4,  2,  1, 11, 10, 13,  7,  8, 15,  9, 12,  5,  6,  3,  0, 14,
+          11,  8, 12,  7,  1, 14,  2, 13,  6, 15,  0,  9, 10,  4,  5,  3},
+         /* S[6]         */
+         {12,  1, 10, 15,  9,  2,  6,  8,  0, 13,  3,  4, 14,  7,  5, 11,
+          10, 15,  4,  2,  7, 12,  9,  5,  6,  1, 13, 14,  0, 11,  3,  8,
+          9, 14, 15,  5,  2,  8, 12,  3,  7,  0,  4, 10,  1, 13, 11,  6,
+          4,  3,  2, 12,  9,  5, 15, 10, 11, 14,  1,  7,  6,  0,  8, 13},
+         /* S[7]         */
+         {4, 11,  2, 14, 15,  0,  8, 13,  3, 12,  9,  7,  5, 10,  6,  1,
+          13,  0, 11,  7,  4,  9,  1, 10, 14,  3,  5, 12,  2, 15,  8,  6,
+          1,  4, 11, 13, 12,  3,  7, 14, 10, 15,  6,  8,  0,  5,  9,  2,
+          6, 11, 13,  8,  1,  4, 10,  7,  9,  5,  0, 15, 14,  2,  3, 12},
+         /* S[8]         */
+         {13,  2,  8,  4,  6, 15, 11,  1, 10,  9,  3, 14,  5,  0, 12,  7,
+          1, 15, 13,  8, 10,  3,  7,  4, 12,  5,  6, 11,  0, 14,  9,  2,
+          7, 11,  4,  1,  9, 12, 14,  2,  0,  6, 10, 13, 15,  3,  5,  8,
+          2,  1, 14,  7,  4, 10,  8, 13, 15, 12,  9,  0,  3,  5,  6, 11}};
+ 
+     private static final byte[] P32Tr = {   /* 32-bit permutation function */
+         16,  7, 20, 21,
+         29, 12, 28, 17,
+         1, 15, 23, 26,
+         5, 18, 31, 10,
+         2,  8, 24, 14,
+         32, 27,  3,  9,
+         19, 13, 30,  6,
+         22, 11,  4, 25};
+ 
+     private static final byte[] CIFP = {    /* compressed/interleaved permutation */
+         1,  2,  3,  4,   17, 18, 19, 20,
+         5,  6,  7,  8,   21, 22, 23, 24,
+         9, 10, 11, 12,   25, 26, 27, 28,
+         13, 14, 15, 16,   29, 30, 31, 32,
+ 
+         33, 34, 35, 36,   49, 50, 51, 52,
+         37, 38, 39, 40,   53, 54, 55, 56,
+         41, 42, 43, 44,   57, 58, 59, 60,
+         45, 46, 47, 48,   61, 62, 63, 64};
+ 
+     private static final byte[] ITOA64 = {      /* 0..63 => ascii-64 */
+         (byte)'.',(byte) '/',(byte) '0',(byte) '1',(byte) '2',(byte) '3',(byte) '4',(byte) '5',
+         (byte)'6',(byte) '7',(byte) '8',(byte) '9',(byte) 'A',(byte) 'B',(byte) 'C',(byte) 'D',
+         (byte)'E',(byte) 'F',(byte) 'G',(byte) 'H',(byte) 'I',(byte) 'J',(byte) 'K',(byte) 'L', 
+         (byte)'M',(byte) 'N',(byte) 'O',(byte) 'P',(byte) 'Q',(byte) 'R',(byte) 'S',(byte) 'T', 
+         (byte)'U',(byte) 'V',(byte) 'W',(byte) 'X',(byte) 'Y',(byte) 'Z',(byte) 'a',(byte) 'b', 
+         (byte)'c',(byte) 'd',(byte) 'e',(byte) 'f',(byte) 'g',(byte) 'h',(byte) 'i',(byte) 'j', 
+         (byte)'k',(byte) 'l',(byte) 'm',(byte) 'n',(byte) 'o',(byte) 'p',(byte) 'q',(byte) 'r', 
+         (byte)'s',(byte) 't',(byte) 'u',(byte) 'v',(byte) 'w',(byte) 'x',(byte) 'y',(byte) 'z'};
+ 
+     /* =====  Tables that are initialized at run time  ==================== */
+ 
+     private static byte[] A64TOI = new byte[128];   /* ascii-64 => 0..63 */
+ 
+     /* Initial key schedule permutation */
+     private static long[][] PC1ROT = new long[16][16];
+ 
+     /* Subsequent key schedule rotation permutations */
+     private static long[][][] PC2ROT = new long[2][16][16];
+ 
+     /* Initial permutation/expansion table */
+     private static long[][] IE3264 = new long[8][16];
+ 
+     /* Table that combines the S, P, and E operations.  */
+     private static long[][] SPE = new long[8][64];
+ 
+     /* compressed/interleaved => final permutation table */
+     private static long[][] CF6464 = new long[16][16];
+ 
+ 
+     /* ==================================== */
+ 
+     static {
+         byte[] perm = new byte[64];
+         byte[] temp = new byte[64];
+ 
+         // inverse table.
+         for (int i=0; i<64; i++) A64TOI[ITOA64[i]] = (byte)i;
+ 
+         // PC1ROT - bit reverse, then PC1, then Rotate, then PC2
+         for (int i=0; i<64; i++) perm[i] = (byte)0;;
+         for (int i=0; i<64; i++) {
+             int k;
+             if ((k = (int)PC2[i]) == 0) continue;
+             k += Rotates[0]-1;
+             if ((k%28) < Rotates[0]) k -= 28;
+             k = (int)PC1[k];
+             if (k > 0) {
+                 k--;
+                 k = (k|0x07) - (k&0x07);
+                 k++;
+             }
+             perm[i] = (byte)k;
+         }
+         init_perm(PC1ROT, perm, 8);
+ 
+         // PC2ROT - PC2 inverse, then Rotate, then PC2
+         for (int j=0; j<2; j++) {
+             int k;
+             for (int i=0; i<64; i++) perm[i] = temp[i] = 0;
+             for (int i=0; i<64; i++) {
+                 if ((k = (int)PC2[i]) == 0) continue;
+                 temp[k-1] = (byte)(i+1);
+             }
+             for (int i=0; i<64; i++) {
+                 if ((k = (int)PC2[i]) == 0) continue;
+                 k += j;
+                 if ((k%28) <= j) k -= 28;
+                 perm[i] = temp[k];
+             }
+ 
+             init_perm(PC2ROT[j], perm, 8);
+         }
+ 
+         // Bit reverse, intial permupation, expantion
+         for (int i=0; i<8; i++) {
+             for (int j=0; j<8; j++) {
+                 int k = (j < 2)? 0: IP[ExpandTr[i*6+j-2]-1];
+                 if (k > 32) k -= 32;
+                 else if (k > 0) k--;
+                 if (k > 0) {
+                     k--;
+                     k = (k|0x07) - (k&0x07);
+                     k++;
+                 }
+                 perm[i*8+j] = (byte)k;
+             }
+         }
+ 
+         init_perm(IE3264, perm, 8);
+ 
+         // Compression, final permutation, bit reverse
+         for (int i=0; i<64; i++) {
+             int k = IP[CIFP[i]-1];
+             if (k > 0) {
+                 k--;
+                 k = (k|0x07) - (k&0x07);
+                 k++;
+             }
+             perm[k-1] = (byte)(i+1);
+         }
+ 
+         init_perm(CF6464, perm, 8);
+ 
+         // SPE table
+         for (int i=0; i<48; i++)
+             perm[i] = P32Tr[ExpandTr[i]-1];
+         for (int t=0; t<8; t++) {
+             for (int j=0; j<64; j++) {
+                 int k = (((j >> 0) & 0x01) << 5) | (((j >> 1) & 0x01) << 3) |
+                     (((j >> 2) & 0x01) << 2) | (((j >> 3) & 0x01) << 1) |
+                     (((j >> 4) & 0x01) << 0) | (((j >> 5) & 0x01) << 4);
+                 k = S[t][k];
+                 k = (((k >> 3) & 0x01) << 0) | (((k >> 2) & 0x01) << 1) |
+                     (((k >> 1) & 0x01) << 2) | (((k >> 0) & 0x01) << 3);
+                 for (int i=0; i<32; i++) temp[i] = 0;
+                 for (int i=0; i<4; i++) temp[4*t+i] = (byte)((k >> i) & 0x01);
+                 long kk = 0;
+                 for (int i=24; --i>=0; ) kk = ((kk<<1) |
+                                                ((long)temp[perm[i]-1])<<32 |
+                                                ((long)temp[perm[i+24]-1]));
+ 
+                 SPE[t][j] = to_six_bit(kk);
+             }
+         }
+     }
+ 
+     /**
+      * You can't call the constructer.
+      */
+     private UnixCrypt() { }
+ 
+     /**
+      * Returns the transposed and split code of a 24-bit code
+      * into a 4-byte code, each having 6 bits.
+      */
+     private static int to_six_bit(int num) {
+         return (((num << 26) & 0xfc000000) | ((num << 12) & 0xfc0000) | 
+                 ((num >> 2) & 0xfc00) | ((num >> 16) & 0xfc));
+     }
+ 
+     /**
+      * Returns the transposed and split code of two 24-bit code 
+      * into two 4-byte code, each having 6 bits.
+      */
+     private static long to_six_bit(long num) {
+         return (((num << 26) & 0xfc000000fc000000L) | ((num << 12) & 0xfc000000fc0000L) | 
+                 ((num >> 2) & 0xfc000000fc00L) | ((num >> 16) & 0xfc000000fcL));
+     }
+   
+     /**
+      * Returns the permutation of the given 64-bit code with
+      * the specified permutataion table.
+      */
+     private static long perm6464(long c, long[][]p) {
+         long out = 0L;
+         for (int i=8; --i>=0; ) {
+             int t = (int)(0x00ff & c);
+             c >>= 8;
+             long tp = p[i<<1][t&0x0f];
+             out |= tp;
+             tp = p[(i<<1)+1][t>>4];
+             out |= tp;
+         }
+         return out;
+     }
+ 
+     /**
+      * Returns the permutation of the given 32-bit code with
+      * the specified permutataion table.
+      */
+     private static long perm3264(int c, long[][]p) {
+         long out = 0L;
+         for (int i=4; --i>=0; ) {
+             int t = (0x00ff & c);
+             c >>= 8;
+             long tp = p[i<<1][t&0x0f];
+             out |= tp;
+             tp = p[(i<<1)+1][t>>4];
+             out |= tp;
+         }
+         return out;
+     }
+ 
+     /**
+      * Returns the key schedule for the given key.
+      */
+     private static long[] des_setkey(long keyword) {
+         long K = perm6464(keyword, PC1ROT);
+         long[] KS = new long[16];
+         KS[0] = K&~0x0303030300000000L;
+     
+         for (int i=1; i<16; i++) {
+             KS[i] = K;
+             K = perm6464(K, PC2ROT[Rotates[i]-1]);
+ 
+             KS[i] = K&~0x0303030300000000L;
+         }
+         return KS;
+     }
+ 
+     /**
+      * Returns the DES encrypted code of the given word with the specified 
+      * environment.
+      */
+     private static long des_cipher(long in, int salt, int num_iter, long[] KS) {
+         salt = to_six_bit(salt);
+         long L = in;
+         long R = L;
+         L &= 0x5555555555555555L;
+         R = (R & 0xaaaaaaaa00000000L) | ((R >> 1) & 0x0000000055555555L);
+         L = ((((L << 1) | (L << 32)) & 0xffffffff00000000L) | 
+              ((R | (R >> 32)) & 0x00000000ffffffffL));
+     
+         L = perm3264((int)(L>>32), IE3264);
+         R = perm3264((int)(L&0xffffffff), IE3264);
+ 
+         while (--num_iter >= 0) {
+             for (int loop_count=0; loop_count<8; loop_count++) {
+                 long kp;
+                 long B;
+                 long k;
+ 
+                 kp = KS[(loop_count<<1)];
+                 k = ((R>>32) ^ R) & salt & 0xffffffffL;
+                 k |= (k<<32);
+                 B = (k ^ R ^ kp);
+ 
+                 L ^= (SPE[0][(int)((B>>58)&0x3f)] ^ SPE[1][(int)((B>>50)&0x3f)] ^
+                       SPE[2][(int)((B>>42)&0x3f)] ^ SPE[3][(int)((B>>34)&0x3f)] ^
+                       SPE[4][(int)((B>>26)&0x3f)] ^ SPE[5][(int)((B>>18)&0x3f)] ^
+                       SPE[6][(int)((B>>10)&0x3f)] ^ SPE[7][(int)((B>>2)&0x3f)]);
+ 
+                 kp = KS[(loop_count<<1)+1];
+                 k = ((L>>32) ^ L) & salt & 0xffffffffL;
+                 k |= (k<<32);
+                 B = (k ^ L ^ kp);
+ 
+                 R ^= (SPE[0][(int)((B>>58)&0x3f)] ^ SPE[1][(int)((B>>50)&0x3f)] ^
+                       SPE[2][(int)((B>>42)&0x3f)] ^ SPE[3][(int)((B>>34)&0x3f)] ^
+                       SPE[4][(int)((B>>26)&0x3f)] ^ SPE[5][(int)((B>>18)&0x3f)] ^
+                       SPE[6][(int)((B>>10)&0x3f)] ^ SPE[7][(int)((B>>2)&0x3f)]);
+             }
+             // swap L and R
+             L ^= R;
+             R ^= L;
+             L ^= R;
+         }
+         L = ((((L>>35) & 0x0f0f0f0fL) | (((L&0xffffffff)<<1) & 0xf0f0f0f0L))<<32 |
+              (((R>>35) & 0x0f0f0f0fL) | (((R&0xffffffff)<<1) & 0xf0f0f0f0L)));
+ 
+         L = perm6464(L, CF6464);
+ 
+         return L;
+     }
+ 
+     /**
+      * Initializes the given permutation table with the mapping table.
+      */
+     private static void init_perm(long[][] perm, byte[] p,int chars_out) {
+         for (int k=0; k<chars_out*8; k++) {
+ 
+             int l = p[k] - 1;
+             if (l < 0) continue;
+             int i = l>>2;
+             l = 1<<(l&0x03);
+             for (int j=0; j<16; j++) {
+                 int s = ((k&0x07)+((7-(k>>3))<<3));
+                 if ((j & l) != 0x00) perm[i][j] |= (1L<<s);
+             }
+         }
+     }
+ 
+     /**
+      * Encrypts String into crypt (Unix) code.
+      * @param key the key to be encrypted
+      * @param setting the salt to be used
+      * @return the encrypted String
+      */
+     public static String crypt(String key, String setting)
+     {
+         long constdatablock = 0L;       /* encryption constant */
+         byte[] cryptresult = new byte[13];  /* encrypted result */
+         long keyword = 0L;
+         /* invalid parameters! */
+         if(key==null||setting==null) 
+             return "*"; // will NOT match under ANY circumstances!
+ 
+         int keylen = key.length();
+ 
+         for (int i=0; i<8 ; i++) {
+             keyword = (keyword << 8) | ((i < keylen)? 2*key.charAt(i): 0);
+         }
+ 
+         long[] KS = des_setkey(keyword);
+ 
+         int salt = 0;
+         for (int i=2; --i>=0;) {
+             char c = (i < setting.length())? setting.charAt(i): '.';
+             cryptresult[i] = (byte)c;
+             salt = (salt<<6) | (0x00ff&A64TOI[c]);
+         }
+ 
+         long rsltblock = des_cipher(constdatablock, salt, 25, KS);
+ 
+         cryptresult[12] = ITOA64[(((int)rsltblock)<<2)&0x3f];
+         rsltblock >>= 4;
+         for (int i=12; --i>=2; ) {
+             cryptresult[i] = ITOA64[((int)rsltblock)&0x3f];
+             rsltblock >>= 6;
+         }
+ 
+         return new String(cryptresult, 0x00, 0, 13);
+     }
+ 
+     public static void main(String[] arg)
+     {
+         if (arg.length!=2)
+         {
+             System.err.println("Usage - java org.mortbay.util.UnixCrypt <key> <salt>");
+             System.exit(1);
+         }
+ 
+         System.err.println("Crypt="+crypt(arg[0],arg[1]));
+     }
+     
+ }

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/UnixCrypt.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java Mon Nov  5 08:51:43 2007
@@ -0,0 +1,234 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.core.utils;
+
+
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class Utils
+{
+
+    public static String[] stringToArray( String s )
+    {
+        if ( s == null )
+        {
+            return null;
+        }
+        else
+        {
+            List attributeList = new ArrayList();
+
+            StringBuffer temp = new StringBuffer();
+            for ( int i = 0; i < s.length(); i++ )
+            {
+                char c = s.charAt( i );
+
+                if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == '-'
+                    || c == '.' || c == ';' )
+                {
+                    temp.append( c );
+                }
+                else
+                {
+                    if ( temp.length() > 0 )
+                    {
+                        attributeList.add( temp.toString() );
+                        temp = new StringBuffer();
+                    }
+                }
+            }
+            if ( temp.length() > 0 )
+            {
+                attributeList.add( temp.toString() );
+            }
+
+            return ( String[] ) attributeList.toArray( new String[attributeList.size()] );
+        }
+
+        // else {
+        // s = s.trim();
+        // s = s.replaceAll(" ", "");
+        // s = s.replaceAll(",,", ",");
+        // String[] a;
+        // if(s.length() > 0) {
+        // a = s.split(",", 0);
+        // }
+        // else {
+        // a = new String[0];
+        // }
+        // return a;
+        // }
+    }
+
+
+    public static String arrayToString( String[] array )
+    {
+        if ( array == null || array.length == 0 )
+        {
+            return "";
+        }
+        else
+        {
+            StringBuffer sb = new StringBuffer( array[0] );
+            for ( int i = 1; i < array.length; i++ )
+            {
+                sb.append( ", " );
+                sb.append( array[i] );
+            }
+            return sb.toString();
+        }
+    }
+
+
+    public static boolean equals( byte[] data1, byte[] data2 )
+    {
+        if ( data1 == data2 )
+            return true;
+        if ( data1 == null || data2 == null )
+            return false;
+        if ( data1.length != data2.length )
+            return false;
+        for ( int i = 0; i < data1.length; i++ )
+        {
+            if ( data1[i] != data2[i] )
+                return false;
+        }
+        return true;
+    }
+
+
+    public static String getShortenedString( String value, int length )
+    {
+
+        if ( value == null )
+            return "";
+
+        if ( value.length() > length )
+        {
+            value = value.substring( 0, length ) + "...";
+        }
+
+        return value;
+    }
+
+
+    public static String serialize( Object o )
+    {
+        Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLEncoder encoder = new XMLEncoder( baos );
+        encoder.writeObject( o );
+        encoder.close();
+        String s = LdifUtils.utf8decode( baos.toByteArray() );
+        return s;
+    }
+
+
+    public static Object deserialize( String s )
+    {
+        Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
+        ByteArrayInputStream bais = new ByteArrayInputStream( LdifUtils.utf8encode( s ) );
+        XMLDecoder decoder = new XMLDecoder( bais );
+        Object o = decoder.readObject();
+        decoder.close();
+        return o;
+    }
+
+
+    public static String getNonNullString( Object o )
+    {
+        return o == null ? "-" : o.toString();
+    }
+
+
+    public static String formatBytes( long bytes )
+    {
+        String size = "";
+        if ( bytes > 1024 * 1024 )
+            size += ( bytes / 1024 / 1024 ) + " MB (" + bytes + " Bytes)";
+        else if ( bytes > 1024 )
+            size += ( bytes / 1024 ) + " KB (" + bytes + " Bytes)";
+        else if ( bytes > 1 )
+            size += bytes + " Bytes";
+        else
+            size += bytes + " Byte";
+        return size;
+    }
+
+
+    public static boolean containsIgnoreCase( Collection c, String s )
+    {
+        if ( c == null || s == null )
+        {
+            return false;
+        }
+
+        Iterator it = c.iterator();
+        while ( it.hasNext() )
+        {
+            Object o = it.next();
+            if ( o instanceof String && ( ( String ) o ).equalsIgnoreCase( s ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    public static String shorten( String label, int maxLength )
+    {
+        if ( label == null )
+        {
+            return null;
+        }
+        if ( maxLength < 3 )
+        {
+            return "...";
+        }
+        if ( label.length() > maxLength )
+        {
+            label = label.substring( 0, maxLength / 2 ) + "..."
+                + label.substring( label.length() - maxLength / 2, label.length() );
+
+        }
+        StringBuffer sb = new StringBuffer( maxLength + 3 );
+        for ( int i = 0; i < label.length(); i++ )
+        {
+            char c = label.charAt( i );
+            if ( c > 31 && c < 127 )
+                sb.append( c );
+            else
+                sb.append( '.' );
+        }
+        return sb.toString();
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/resources/about.html
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/resources/about.html?rev=592082&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/resources/about.html (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/resources/about.html Mon Nov  5 08:51:43 2007
@@ -0,0 +1,76 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+<body lang="EN-US">
+<h2>About Eclipse LDAP Browser and Editor</h2>
+
+<h3>Copyright</h3>
+
+<p>Copyright (c) 2006 Apache Software Foundation. All rights reserved.</p>
+
+<h3>License</h3>
+
+<p>Eclipse LDAP Browser and Editor is provided to you under the terms and conditions of the
+Apache License Version 2.0. A copy of the Apache Licence can be found in <a href="about_files/licence.txt">about_files/license.txt</a>
+and is also available at <a href="http://www.apache.org/licenses/LICENSE-2.0.html</a>.</p>
+
+<h3>Third Party Content</h3>
+
+<p>The Content includes items that have been sourced from third parties as follows:</p>
+
+<h4>Eclipse</h4>
+
+<p>The plug-in is accompanied by software developed by the Eclipse Foundation at
+<a href="http://www.eclipse.org/">http://www.eclipse.org/</a>.
+Parts of Eclipse code, icons and documents are included with the plug-in.
+Your use of Eclipse is subject to the terms and conditions of the Eclipse Public License Version 1.0 (&quot;EPL&quot;).
+A copy of the EPL can be found in <a href="about_files/epl-v10.txt">about_files/epl-v10.txt</a>
+and is also available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+The source code for Eclipse is available at <a href="http://www.eclipse.org/">http://www.eclipse.org/</a>.</p>
+
+<h4>Commons Codec 1.3</h4>
+
+<p>The plug-in is accompanied by software developed by the Apache Software Foundation at
+<a href="http://jakarta.apache.org/commons/codec/">http://jakarta.apache.org/commons/codec/</a>.
+The binary code of Commons Codec 1.3 (&quot;Commons Codec&quot;) is included with the plug-in without modification in lib/commons-codec-1.3.jar.
+Your use of Commons Codec is subject to the terms and conditions of the Apache License, Version 2.0 (&quot;Apache License&quot;).
+A copy of the Apache License can be found in <a href="about_files/asl-v20.txt">about_files/asl-v20.txt</a>
+and is also available at <a href="http://www.apache.org/licenses/LICENSE-2.0.html">http://www.apache.org/licenses/LICENSE-2.0.html</a>.
+The source code for Commons Codec is available at <a href="http://jakarta.apache.org/commons/codec/">http://jakarta.apache.org/commons/codec/</a>.</p>
+
+<h4>Jakarta POI 2.5.1-final-20040804</h4>
+
+<p>The plug-in is accompanied by software developed by the Apache Software Foundation at
+<a href="http://jakarta.apache.org/poi/">http://jakarta.apache.org/poi/</a>.
+The binary code of Jakarta POI 2.5.1-final-20040804 (&quot;POI&quot;) is included with the plug-in without modification in lib/poi-2.5.1-final-20040804.jar.
+Your use of POI is subject to the terms and conditions of the Apache License, Version 1.1 (&quot;Apache License&quot;).
+A copy of the Apache License can be found in <a href="about_files/asl-v11.txt">about_files/asl-v11.txt</a>
+and is also available at <a href="http://www.apache.org/licenses/LICENSE-1.1">http://www.apache.org/licenses/LICENSE-1.1</a>.
+The source code for POI is available at <a href="http://jakarta.apache.org/poi/">http://jakarta.apache.org/poi/</a>.</p>
+
+<h4>ANTLR 2.7.5</h4>
+
+<p>The plug-in is accompanied by software developed by Terence Parr at
+<a href="http://www.antlr.org/">http://www.antlr.org/</a>.
+The binary code of ANTLR 2.7.5 (&quot;ANTLR&quot;) is included with the plug-in without modification in lib/antlr-2.7.5.jar.
+Your use of ANTLR is subject to the terms and conditions of the ANTLR License (&quot;ANTLR License&quot;).
+A copy of the ANTLR License can be found in <a href="about_files/antlr.txt">about_files/antlr.txt</a>
+and is also available at <a href="http://www.antlr.org/license.html">http://www.antlr.org/license.html</a>.
+The source code for ANTLR is available at <a href="http://www.antlr.org/">http://www.antlr.org/</a>.</p>
+
+<h4>OpenLDAP</h4>
+
+<p>The plug-in is accompanied by software developed by the OpenLDAP Foundation at
+<a href="http://www.openldap.org/">http://www.openldap.org/</a>.
+Parts of OpenLDAP (Schema files) are included with the plug-in.
+Your use of OpenLDAP is subject to the terms and conditions of the OpenLDAP Public License, Version 2.8 (&quot;OpenLDAP Public License&quot;).
+A copy of the OpenLDAP Public License can be found in <a href="about_files/openldap.txt">about_files/openldap.txt</a>
+and is also available at <a href="http://www.OpenLDAP.org/license.html">http://www.OpenLDAP.org/license.html</a>.
+The source code for OpenLDAP is available at <a href="http://www.openldap.org/">http://www.openldap.org/</a>.</p>
+
+
+</body>
+</html>
\ No newline at end of file

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/resources/about.html
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message