directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1762095 - in /directory/studio/trunk: plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/ plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ plugins/valueeditors/ plugins/value...
Date Fri, 23 Sep 2016 21:27:34 GMT
Author: seelmann
Date: Fri Sep 23 21:27:33 2016
New Revision: 1762095

URL: http://svn.apache.org/viewvc?rev=1762095&view=rev
Log:
DIRSTUDIO-1115: Make value editor behaviour more consistent. Add checks if value can be handled
by an value editor. Add tests.

Added:
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/StringValueEditorUtils.java
  (with props)
    directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/
    directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java
  (with props)
    directory/studio/trunk/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ValueEditorTest.java
  (with props)
Modified:
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogBinaryValueEditor.java
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogStringValueEditor.java
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractInPlaceStringValueEditor.java
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/IValueEditor.java
    directory/studio/trunk/plugins/valueeditors/pom-first.xml
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.java

Modified: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogBinaryValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogBinaryValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogBinaryValueEditor.java
(original)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogBinaryValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -27,7 +27,6 @@ import org.eclipse.osgi.util.NLS;
 
 
 /**
- * 
  * Abstract base class for value editors that handle binary values
  * in a dialog. 
  *
@@ -58,14 +57,17 @@ public abstract class AbstractDialogBina
         }
         else
         {
-            if ( value == null )
+            Object rawValue = getRawValue( value );
+
+            if ( rawValue == null )
             {
-                return NULL; //$NON-NLS-1$
+                return NULL;
             }
-            else if ( value.isBinary() )
+            else if ( rawValue instanceof byte[] )
             {
-                byte[] data = value.getBinaryValue();
-                return NLS.bind( Messages.getString( "AbstractDialogBinaryValueEditor.BinaryDateNBytes"
), data.length ); //$NON-NLS-1$
+                byte[] data = ( byte[] ) rawValue;
+                return NLS.bind( Messages.getString( "AbstractDialogBinaryValueEditor.BinaryDateNBytes"
), //$NON-NLS-1$
+                    data.length );
             }
             else
             {

Modified: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogStringValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogStringValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogStringValueEditor.java
(original)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractDialogStringValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -26,7 +26,6 @@ import org.apache.directory.studio.ldapb
 
 
 /**
- * 
  * Abstract base class for value editors that handle string values
  * in a dialog. 
  *
@@ -51,15 +50,7 @@ public abstract class AbstractDialogStri
     public String getDisplayValue( IValue value )
     {
         Object obj = getRawValue( value );
-        
-        if ( obj == null )
-        {
-            return NULL;
-        }
-        else
-        {
-            return obj.toString();
-        }
+        return StringValueEditorUtils.getDisplayValue( obj );
     }
 
 
@@ -90,44 +81,7 @@ public abstract class AbstractDialogStri
      */
     public Object getRawValue( IValue value )
     {
-        if ( value == null )
-        {
-            return null;
-        }
-        else if ( value.isString() )
-        {
-            return value.getStringValue();
-        }
-        else if ( value.isBinary() && isEditable( value.getBinaryValue() ) )
-        {
-            return value.getStringValue();
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-
-    /**
-     * Small helper.
-     */
-    private boolean isEditable( byte[] b )
-    {
-        if ( b == null )
-        {
-            return false;
-        }
-
-        for ( int i = 0; i < b.length; i++ )
-        {
-            if ( ( b[i] > '\u007F' ) || ( ( b[i] < '\u0020' ) && ( b[i] !=
'\n' ) && ( b[i] != '\r' ) ) )
-            {
-                return false;
-            }
-        }
-
-        return true;
+        return StringValueEditorUtils.getRawValue( value );
     }
 
 
@@ -139,13 +93,6 @@ public abstract class AbstractDialogStri
      */
     public Object getStringOrBinaryValue( Object rawValue )
     {
-        if ( rawValue instanceof String )
-        {
-            return rawValue;
-        }
-        else
-        {
-            return null;
-        }
+        return StringValueEditorUtils.getStringOrBinaryValue( rawValue );
     }
 }

Modified: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractInPlaceStringValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractInPlaceStringValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractInPlaceStringValueEditor.java
(original)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/AbstractInPlaceStringValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -84,7 +84,7 @@ public abstract class AbstractInPlaceStr
     {
         if ( attributeHierarchy == null )
         {
-            return "NULL"; //$NON-NLS-1$
+            return NULL;
         }
 
         List<IValue> valueList = new ArrayList<IValue>();
@@ -123,15 +123,7 @@ public abstract class AbstractInPlaceStr
     public String getDisplayValue( IValue value )
     {
         Object obj = getRawValue( value );
-        
-        if ( obj == null ) 
-        {
-            return "NULL";
-        }
-        else
-        {
-            return obj.toString();
-        }
+        return StringValueEditorUtils.getDisplayValue( obj );
     }
 
 
@@ -184,41 +176,7 @@ public abstract class AbstractInPlaceStr
      */
     public Object getRawValue( IValue value )
     {
-        if ( value != null )
-        {
-            if ( value.isString() )
-            {
-                return value.getStringValue();
-            }
-            else if ( value.isBinary() && isEditable( value.getBinaryValue() ) )
-            {
-                return value.getStringValue();
-            }
-        }
-
-        return null;
-    }
-
-
-    /**
-     * Small helper.
-     */
-    private boolean isEditable( byte[] b )
-    {
-        if ( b == null )
-        {
-            return false;
-        }
-
-        for ( int i = 0; i < b.length; i++ )
-        {
-            if ( ( b[i] > '\u007F') || ( ( b[i] < '\u0020' ) && ( b[i] != '\n'
) && ( b[i] != '\r' ) ) )
-            {
-                return false;
-            }
-        }
-
-        return true;
+        return StringValueEditorUtils.getRawValue( value );
     }
 
 
@@ -230,14 +188,7 @@ public abstract class AbstractInPlaceStr
      */
     public Object getStringOrBinaryValue( Object rawValue )
     {
-        if ( rawValue instanceof String )
-        {
-            return rawValue;
-        }
-        else
-        {
-            return null;
-        }
+        return StringValueEditorUtils.getStringOrBinaryValue( rawValue );
     }
 
 

Modified: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/IValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/IValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/IValueEditor.java
(original)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/IValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -198,5 +198,5 @@ public interface IValueEditor
 
     // A constant for the emtpy string and null string.
     String EMPTY = ""; //$NON-NLS-1$
-    String NULL = "NULL"; //$NON-NLS-1$
+    String NULL = ">>> Error, the configured value editor can not handle this value!
<<<"; //$NON-NLS-1$
 }

Added: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/StringValueEditorUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/StringValueEditorUtils.java?rev=1762095&view=auto
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/StringValueEditorUtils.java
(added)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/StringValueEditorUtils.java
Fri Sep 23 21:27:33 2016
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.valueeditors;
+
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+
+
+/**
+ * Common code used by {@link AbstractInPlaceStringValueEditor} and 
+ * {@link AbstractDialogStringValueEditor}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StringValueEditorUtils
+{
+
+    static String getDisplayValue( Object rawValue )
+    {
+        if ( rawValue == null )
+        {
+            return IValueEditor.NULL;
+        }
+        else
+        {
+            return rawValue.toString();
+        }
+    }
+
+
+    static Object getRawValue( IValue value )
+    {
+        if ( value == null )
+        {
+            return null;
+        }
+        else if ( value.isString() )
+        {
+            return value.getStringValue();
+        }
+        else if ( value.isBinary() && StringValueEditorUtils.isEditable( value.getBinaryValue()
) )
+        {
+            return value.getStringValue();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    static Object getStringOrBinaryValue( Object rawValue )
+    {
+        if ( rawValue instanceof String )
+        {
+            return rawValue;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    static boolean isEditable( byte[] b )
+    {
+        if ( b == null )
+        {
+            return false;
+        }
+
+        return !( new String( b, StandardCharsets.UTF_8 ).contains( "\uFFFD" ) );
+    }
+
+}

Propchange: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/valueeditors/StringValueEditorUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java?rev=1762095&view=auto
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java
(added)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java
Fri Sep 23 21:27:33 2016
@@ -0,0 +1,52 @@
+
+package org.apache.directory.studio.valueeditors;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+
+import org.junit.Test;
+
+
+public class ValueEditorUtilsTest
+{
+
+    @Test
+    public void testEmptyStringIsEditable()
+    {
+        assertTrue( StringValueEditorUtils.isEditable( "".getBytes() ) );
+    }
+
+
+    @Test
+    public void testAsciiIsEditable()
+    {
+        assertTrue( StringValueEditorUtils.isEditable( "abc\n123".getBytes( StandardCharsets.US_ASCII
) ) );
+    }
+
+
+    @Test
+    public void testUft8IsEditable()
+    {
+        assertTrue( StringValueEditorUtils.isEditable( "a\nb\r\u00e4\t\u5047".getBytes( StandardCharsets.UTF_8
) ) );
+    }
+
+
+    @Test
+    public void testIso88591IsNotEditable()
+    {
+        assertFalse(
+            StringValueEditorUtils.isEditable( "\u00e4\u00f6\u00fc".getBytes( StandardCharsets.ISO_8859_1
) ) );
+    }
+
+
+    @Test
+    public void testPngIsNotEditable()
+    {
+        assertFalse( StringValueEditorUtils.isEditable( new byte[]
+            { ( byte ) 0x89, 0x50, 0x4E, 0x47 } ) );
+    }
+
+}

Propchange: directory/studio/trunk/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/studio/trunk/plugins/valueeditors/pom-first.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/pom-first.xml?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/pom-first.xml (original)
+++ directory/studio/trunk/plugins/valueeditors/pom-first.xml Fri Sep 23 21:27:33 2016
@@ -48,10 +48,20 @@
             <Bundle-Activator>org.apache.directory.studio.valueeditors.ValueEditorsActivator</Bundle-Activator>
             
             <Export-Package>org.apache.directory.studio.valueeditors,
+ org.apache.directory.studio.valueeditors.address,
+ org.apache.directory.studio.valueeditors.administrativerole,
+ org.apache.directory.studio.valueeditors.adtime,
+ org.apache.directory.studio.valueeditors.bool,
+ org.apache.directory.studio.valueeditors.certificate,
  org.apache.directory.studio.valueeditors.dn,
- org.apache.directory.studio.valueeditors.time,
+ org.apache.directory.studio.valueeditors.image,
+ org.apache.directory.studio.valueeditors.integer,
+ org.apache.directory.studio.valueeditors.msad,
+ org.apache.directory.studio.valueeditors.objectclass,
+ org.apache.directory.studio.valueeditors.oid,
  org.apache.directory.studio.valueeditors.password,
- org.apache.directory.studio.valueeditors.integer</Export-Package>
+ org.apache.directory.studio.valueeditors.time,
+ org.apache.directory.studio.valueeditors.uuid</Export-Package>
  
             <Import-Package>
  org.apache.commons.lang,

Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java
(original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -21,6 +21,8 @@
 package org.apache.directory.studio.valueeditors.bool;
 
 
+import org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
 import org.apache.directory.studio.valueeditors.AbstractInPlaceStringValueEditor;
 
 
@@ -54,18 +56,14 @@ public class InPlaceBooleanValueEditor e
             {
                 return null;
             }
-            else if ( "TRUE".equalsIgnoreCase( stringValue )
-                || "T".equalsIgnoreCase( stringValue )
-                || "YES".equalsIgnoreCase( stringValue )
-                || "Y".equalsIgnoreCase( stringValue )
+            else if ( "TRUE".equalsIgnoreCase( stringValue ) || "T".equalsIgnoreCase( stringValue
)
+                || "YES".equalsIgnoreCase( stringValue ) || "Y".equalsIgnoreCase( stringValue
)
                 || "1".equalsIgnoreCase( stringValue ) )
             {
                 return TRUE;
             }
-            else if ( "FALSE".equalsIgnoreCase( stringValue )
-                || "F".equalsIgnoreCase( stringValue )
-                || "NO".equalsIgnoreCase( stringValue )
-                || "N".equalsIgnoreCase( stringValue )
+            else if ( "FALSE".equalsIgnoreCase( stringValue ) || "F".equalsIgnoreCase( stringValue
)
+                || "NO".equalsIgnoreCase( stringValue ) || "N".equalsIgnoreCase( stringValue
)
                 || "0".equalsIgnoreCase( stringValue ) )
             {
                 return FALSE;
@@ -74,4 +72,21 @@ public class InPlaceBooleanValueEditor e
 
         return value;
     }
+
+
+    @Override
+    public Object getRawValue( IValue value )
+    {
+        Object rawValue = super.getRawValue( value );
+
+        if ( rawValue instanceof String && new BooleanSyntaxChecker().isValidSyntax(
rawValue ) )
+        {
+            return rawValue;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
 }

Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java
(original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java
Fri Sep 23 21:27:33 2016
@@ -32,6 +32,7 @@ import java.io.IOException;
 import org.apache.directory.api.util.Strings;
 import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.apache.directory.studio.valueeditors.IValueEditor;
 import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
 import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
 import org.eclipse.core.runtime.IStatus;
@@ -782,7 +783,7 @@ public class ImageDialog extends Dialog
     {
         if ( imageRawData == null )
         {
-            return "NULL"; //$NON-NLS-1$
+            return IValueEditor.NULL;
         }
 
         String text;

Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java
(original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -79,7 +79,7 @@ public class ImageValueEditor extends Ab
         {
             if ( value == null )
             {
-                return NULL; //$NON-NLS-1$
+                return NULL;
             }
             else if ( value.isBinary() )
             {

Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java
(original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/objectclass/ObjectClassValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -71,7 +71,7 @@ public class ObjectClassValueEditor exte
     {
         if ( getRawValue( value ) == null )
         {
-            return "NULL"; //$NON-NLS-1$
+            return NULL;
         }
 
         String displayValue = value.getStringValue();

Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.java?rev=1762095&r1=1762094&r2=1762095&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.java
(original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/oid/InPlaceOidValueEditor.java
Fri Sep 23 21:27:33 2016
@@ -21,6 +21,7 @@
 package org.apache.directory.studio.valueeditors.oid;
 
 
+import org.apache.directory.api.ldap.model.schema.syntaxCheckers.NumericOidSyntaxChecker;
 import org.apache.directory.studio.connection.core.Utils;
 import org.apache.directory.studio.ldapbrowser.core.model.IValue;
 import org.apache.directory.studio.valueeditors.AbstractInPlaceStringValueEditor;
@@ -47,7 +48,7 @@ public class InPlaceOidValueEditor exten
         if ( !showRawValues() )
         {
             String description = Utils.getOidDescription( displayValue );
-            
+
             if ( description != null )
             {
                 displayValue = displayValue + " (" + description + ")"; //$NON-NLS-1$ //$NON-NLS-2$
@@ -56,4 +57,20 @@ public class InPlaceOidValueEditor exten
 
         return displayValue;
     }
+
+
+    @Override
+    public Object getRawValue( IValue value )
+    {
+        Object rawValue = super.getRawValue( value );
+
+        if ( rawValue instanceof String && new NumericOidSyntaxChecker().isValidSyntax(
rawValue ) )
+        {
+            return rawValue;
+        }
+        else
+        {
+            return null;
+        }
+    }
 }

Added: directory/studio/trunk/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ValueEditorTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ValueEditorTest.java?rev=1762095&view=auto
==============================================================================
--- directory/studio/trunk/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ValueEditorTest.java
(added)
+++ directory/studio/trunk/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ValueEditorTest.java
Fri Sep 23 21:27:33 2016
@@ -0,0 +1,403 @@
+/*
+ *  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.test.integration.ui;
+
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.valueeditors.HexValueEditor;
+import org.apache.directory.studio.valueeditors.IValueEditor;
+import org.apache.directory.studio.valueeditors.InPlaceTextValueEditor;
+import org.apache.directory.studio.valueeditors.TextValueEditor;
+import org.apache.directory.studio.valueeditors.bool.InPlaceBooleanValueEditor;
+import org.apache.directory.studio.valueeditors.oid.InPlaceOidValueEditor;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+
+/**
+ * Tests the value editors.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(Parameterized.class)
+public class ValueEditorTest
+{
+
+    @Parameters(name = "{0}")
+    public static Object[] data()
+    {
+        return new Object[][]
+            {
+                // InPlaceTextValueEditor 
+
+                { "InPlaceTextValueEditor - empty value",
+                    Data.data().valueEditorClass( InPlaceTextValueEditor.class ).attribute(
"cn" )
+                        .rawValue( IValue.EMPTY_STRING_VALUE ).expectedRawValue( "" ).expectedDisplayValue(
"" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "" ) },
+
+                { "InPlaceTextValueEditor - empty string",
+                    Data.data().valueEditorClass( InPlaceTextValueEditor.class ).attribute(
"cn" ).rawValue( "" )
+                        .expectedRawValue( "" ).expectedDisplayValue( "" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "" ) },
+
+                { "InPlaceTextValueEditor - ascii",
+                    Data.data().valueEditorClass( InPlaceTextValueEditor.class ).attribute(
"cn" )
+                        .rawValue( "a-zA+Z0.9" ).expectedRawValue( "a-zA+Z0.9" ).expectedDisplayValue(
"a-zA+Z0.9" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "a-zA+Z0.9"
) },
+
+                { "InPlaceTextValueEditor - ascii with newline",
+                    Data.data().valueEditorClass( InPlaceTextValueEditor.class ).attribute(
"cn" ).rawValue( "a\nb\rc" )
+                        .expectedRawValue( "a\nb\rc" ).expectedDisplayValue( "a\nb\rc" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "a\nb\rc" ) },
+
+                { "InPlaceTextValueEditor - unicode",
+                    Data.data().valueEditorClass( InPlaceTextValueEditor.class ).attribute(
"cn" )
+                        .rawValue( "\u00e4\u2000\n\u5047" ).expectedRawValue( "\u00e4\u2000\n\u5047"
)
+                        .expectedDisplayValue( "\u00e4\u2000\n\u5047" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "\u00e4\u2000\n\u5047" ) },
+
+                { "InPlaceTextValueEditor - bytearray UTF8",
+                    Data.data().valueEditorClass( InPlaceTextValueEditor.class ).attribute(
"userPassword" )
+                        .rawValue( "a\nb\r\u00e4\t\u5047".getBytes( UTF_8 ) ).expectedRawValue(
"a\nb\r\u00e4\t\u5047" )
+                        .expectedDisplayValue( "a\nb\r\u00e4\t\u5047" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "a\nb\r\u00e4\t\u5047" ) },
+
+                { "InPlaceTextValueEditor - bytearray binary", Data.data()
+                    .valueEditorClass( InPlaceTextValueEditor.class ).attribute( "userPassword"
).rawValue( new byte[]
+                        { ( byte ) 0x89, 0x50, 0x4E, 0x47 } )
+                    .expectedRawValue( null ).expectedDisplayValue( IValueEditor.NULL ).expectedHasValue(
true )
+                    .expectedStringOrBinaryValue( null ) },
+
+                // InPlaceBooleanValueEditor 
+
+                { "InPlaceBooleanValueEditor - TRUE",
+                    Data.data().valueEditorClass( InPlaceBooleanValueEditor.class ).attribute(
"cn" ).rawValue( "TRUE" )
+                        .expectedRawValue( "TRUE" ).expectedDisplayValue( "TRUE" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "TRUE" ) },
+
+                { "InPlaceBooleanValueEditor - FALSE",
+                    Data.data().valueEditorClass( InPlaceBooleanValueEditor.class ).attribute(
"cn" )
+                        .rawValue( "FALSE" ).expectedRawValue( "FALSE" ).expectedDisplayValue(
"FALSE" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "FALSE" )
},
+
+                { "InPlaceBooleanValueEditor - INVALID",
+                    Data.data().valueEditorClass( InPlaceBooleanValueEditor.class ).attribute(
"cn" )
+                        .rawValue( "invalid" ).expectedRawValue( null ).expectedDisplayValue(
IValueEditor.NULL )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( null ) },
+
+                { "InPlaceBooleanValueEditor - bytearray TRUE",
+                    Data.data().valueEditorClass( InPlaceBooleanValueEditor.class ).attribute(
"userPassword" )
+                        .rawValue( "TRUE".getBytes( UTF_8 ) ).expectedRawValue( "TRUE" ).expectedDisplayValue(
"TRUE" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "TRUE" ) },
+
+                { "InPlaceBooleanValueEditor - bytearray FALSE",
+                    Data.data().valueEditorClass( InPlaceBooleanValueEditor.class ).attribute(
"userPassword" )
+                        .rawValue( "FALSE".getBytes( UTF_8 ) ).expectedRawValue( "FALSE"
)
+                        .expectedDisplayValue( "FALSE" ).expectedHasValue( true )
+                        .expectedStringOrBinaryValue( "FALSE" ) },
+
+                { "InPlaceBooleanValueEditor - bytearray INVALID",
+                    Data.data().valueEditorClass( InPlaceBooleanValueEditor.class ).attribute(
"userPassword" )
+                        .rawValue( "invalid".getBytes( UTF_8 ) ).expectedRawValue( null )
+                        .expectedDisplayValue( IValueEditor.NULL ).expectedHasValue( true
)
+                        .expectedStringOrBinaryValue( null ) },
+
+                // InPlaceOidValueEditor 
+
+                { "InPlaceOidValueEditor - 1.3.6.1.4.1.1466.20037",
+                    Data.data().valueEditorClass( InPlaceOidValueEditor.class ).attribute(
"cn" )
+                        .rawValue( "1.3.6.1.4.1.1466.20037" ).expectedRawValue( "1.3.6.1.4.1.1466.20037"
)
+                        .expectedDisplayValue( "1.3.6.1.4.1.1466.20037 (Start TLS)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "1.3.6.1.4.1.1466.20037" ) },
+
+                { "InPlaceOidValueEditor - INVALID",
+                    Data.data().valueEditorClass( InPlaceOidValueEditor.class ).attribute(
"cn" ).rawValue( "invalid" )
+                        .expectedRawValue( null ).expectedDisplayValue( IValueEditor.NULL
).expectedHasValue( true )
+                        .expectedStringOrBinaryValue( null ) },
+
+                { "InPlaceOidValueEditor - bytearray 1.3.6.1.4.1.1466.20037",
+                    Data.data().valueEditorClass( InPlaceOidValueEditor.class ).attribute(
"userPassword" )
+                        .rawValue( "1.3.6.1.4.1.1466.20037".getBytes( UTF_8 ) )
+                        .expectedRawValue( "1.3.6.1.4.1.1466.20037" )
+                        .expectedDisplayValue( "1.3.6.1.4.1.1466.20037 (Start TLS)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "1.3.6.1.4.1.1466.20037" ) },
+
+                { "InPlaceOidValueEditor - bytearray INVALID",
+                    Data.data().valueEditorClass( InPlaceOidValueEditor.class ).attribute(
"userPassword" )
+                        .rawValue( "invalid".getBytes( UTF_8 ) ).expectedRawValue( null )
+                        .expectedDisplayValue( IValueEditor.NULL ).expectedHasValue( true
)
+                        .expectedStringOrBinaryValue( null ) },
+
+                // TextValueEditor
+
+                { "TextValueEditor - empty string value",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "cn"
)
+                        .rawValue( IValue.EMPTY_STRING_VALUE ).expectedRawValue( "" ).expectedDisplayValue(
"" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "" ) },
+
+                { "TextValueEditor - empty string",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "cn"
).rawValue( "" )
+                        .expectedRawValue( "" ).expectedDisplayValue( "" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "" ) },
+
+                { "TextValueEditor - ascii",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "cn"
).rawValue( "a-zA+Z0.9" )
+                        .expectedRawValue( "a-zA+Z0.9" ).expectedDisplayValue( "a-zA+Z0.9"
).expectedHasValue( true )
+                        .expectedStringOrBinaryValue( "a-zA+Z0.9" ) },
+
+                { "TextValueEditor - ascii with newline",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "cn"
).rawValue( "a\nb\rc" )
+                        .expectedRawValue( "a\nb\rc" ).expectedDisplayValue( "a\nb\rc" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "a\nb\rc" ) },
+
+                { "TextValueEditor - unicode",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "cn"
)
+                        .rawValue( "\u00e4\u2000\n\u5047" ).expectedRawValue( "\u00e4\u2000\n\u5047"
)
+                        .expectedDisplayValue( "\u00e4\u2000\n\u5047" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "\u00e4\u2000\n\u5047" ) },
+
+                { "TextValueEditor - empty binary value",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "userPassword"
)
+                        .rawValue( IValue.EMPTY_BINARY_VALUE ).expectedRawValue( "" ).expectedDisplayValue(
"" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "" ) },
+
+                { "TextValueEditor - empty bytearray",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "userPassword"
)
+                        .rawValue( new byte[0] ).expectedRawValue( "" ).expectedDisplayValue(
"" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( "" ) },
+
+                { "TextValueEditor - bytearray UTF8",
+                    Data.data().valueEditorClass( TextValueEditor.class ).attribute( "userPassword"
)
+                        .rawValue( "a\nb\r\u00e4\t\u5047".getBytes( UTF_8 ) ).expectedRawValue(
"a\nb\r\u00e4\t\u5047" )
+                        .expectedDisplayValue( "a\nb\r\u00e4\t\u5047" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "a\nb\r\u00e4\t\u5047" ) },
+
+                { "TextValueEditor - bytearray binary", Data.data().valueEditorClass( InPlaceTextValueEditor.class
)
+                    .attribute( "userPassword" ).rawValue( new byte[]
+                        { ( byte ) 0x89, 0x50, 0x4E, 0x47 } )
+                    .expectedRawValue( null ).expectedDisplayValue( IValueEditor.NULL ).expectedHasValue(
true )
+                    .expectedStringOrBinaryValue( null ) },
+
+                // HexValueEditor
+
+                { "HexValueEditor - empty string value",
+                    Data.data().valueEditorClass( HexValueEditor.class ).attribute( "cn"
)
+                        .rawValue( IValue.EMPTY_STRING_VALUE ).expectedRawValue( new byte[0]
)
+                        .expectedDisplayValue( "Binary Data (0 Bytes)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( new byte[0] ) },
+
+                { "HexValueEditor - empty string",
+                    Data.data().valueEditorClass( HexValueEditor.class ).attribute( "cn"
).rawValue( "" )
+                        .expectedRawValue( new byte[0] ).expectedDisplayValue( "Binary Data
(0 Bytes)" )
+                        .expectedHasValue( true ).expectedStringOrBinaryValue( new byte[0]
) },
+
+                { "HexValueEditor - ascii",
+                    Data.data().valueEditorClass( HexValueEditor.class ).attribute( "cn"
).rawValue( "a-zA+Z0.9" )
+                        .expectedRawValue( "a-zA+Z0.9".getBytes( StandardCharsets.US_ASCII
) )
+                        .expectedDisplayValue( "Binary Data (9 Bytes)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "a-zA+Z0.9".getBytes( StandardCharsets.US_ASCII
) ) },
+
+                { "HexValueEditor - empty binary value",
+                    Data.data().valueEditorClass( HexValueEditor.class ).attribute( "userPassword"
)
+                        .rawValue( IValue.EMPTY_BINARY_VALUE ).expectedRawValue( new byte[0]
)
+                        .expectedDisplayValue( "Binary Data (0 Bytes)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( new byte[0] ) },
+
+                { "HexValueEditor - empty bytearray",
+                    Data.data().valueEditorClass( HexValueEditor.class ).attribute( "userPassword"
)
+                        .rawValue( new byte[0] ).expectedRawValue( new byte[0] )
+                        .expectedDisplayValue( "Binary Data (0 Bytes)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( new byte[0] ) },
+
+                { "HexValueEditor - bytearray UTF8",
+                    Data.data().valueEditorClass( HexValueEditor.class ).attribute( "userPassword"
)
+                        .rawValue( "a\nb\r\u00e4\t\u5047".getBytes( UTF_8 ) )
+                        .expectedRawValue( "a\nb\r\u00e4\t\u5047".getBytes( UTF_8 ) )
+                        .expectedDisplayValue( "Binary Data (10 Bytes)" ).expectedHasValue(
true )
+                        .expectedStringOrBinaryValue( "a\nb\r\u00e4\t\u5047".getBytes( UTF_8
) ) },
+
+                { "HexValueEditor - bytearray binary", Data.data().valueEditorClass( HexValueEditor.class
)
+                    .attribute( "userPassword" ).rawValue( new byte[]
+                        { ( byte ) 0x89, 0x50, 0x4E, 0x47 } )
+                    .expectedRawValue( new byte[]
+                        { ( byte ) 0x89, 0x50, 0x4E, 0x47 } )
+                    .expectedDisplayValue( "Binary Data (4 Bytes)" ).expectedHasValue( true
)
+                    .expectedStringOrBinaryValue( new byte[]
+                        { ( byte ) 0x89, 0x50, 0x4E, 0x47 } ) },
+
+            };
+    }
+
+    @Parameter(value = 0)
+    public String name;
+
+    @Parameter(value = 1)
+    public Data data;
+
+    private IValue value;
+
+    private IValueEditor editor;
+
+
+    @Before
+    public void setup() throws Exception
+    {
+        IEntry entry = new DummyEntry( new Dn(), new DummyConnection( Schema.DEFAULT_SCHEMA
) );
+        IAttribute attribute = new Attribute( entry, data.attribute );
+        value = new Value( attribute, data.rawValue );
+        editor = data.valueEditorClass.newInstance();
+    }
+
+
+    @Test
+    public void testGetRawValue()
+    {
+        if ( data.expectedRawValue instanceof byte[] )
+        {
+            assertArrayEquals( ( byte[] ) data.expectedRawValue, ( byte[] ) editor.getRawValue(
value ) );
+        }
+        else
+        {
+            assertEquals( data.expectedRawValue, editor.getRawValue( value ) );
+        }
+    }
+
+
+    @Test
+    public void testGetDisplayValue()
+    {
+        assertEquals( data.expectedDisplayValue, editor.getDisplayValue( value ) );
+    }
+
+
+    @Test
+    public void testHasValue()
+    {
+        assertEquals( data.expectedHasValue, editor.hasValue( value ) );
+    }
+
+
+    @Test
+    public void testGetStringOrBinaryValue()
+    {
+        if ( data.expectedStringOrBinaryValue instanceof byte[] )
+        {
+            assertArrayEquals( ( byte[] ) data.expectedStringOrBinaryValue,
+                ( byte[] ) editor.getStringOrBinaryValue( editor.getRawValue( value ) ) );
+        }
+        else
+        {
+            assertEquals( data.expectedStringOrBinaryValue,
+                editor.getStringOrBinaryValue( editor.getRawValue( value ) ) );
+        }
+    }
+
+    static class Data
+    {
+        public Class<? extends IValueEditor> valueEditorClass;
+
+        public String attribute;
+
+        public Object rawValue;
+
+        public Object expectedRawValue;
+
+        public String expectedDisplayValue;
+
+        public boolean expectedHasValue;
+
+        public Object expectedStringOrBinaryValue;
+
+
+        public static Data data()
+        {
+            return new Data();
+        }
+
+
+        public Data valueEditorClass( Class<? extends IValueEditor> valueEditorClass
)
+        {
+            this.valueEditorClass = valueEditorClass;
+            return this;
+        }
+
+
+        public Data attribute( String attribute )
+        {
+            this.attribute = attribute;
+            return this;
+        }
+
+
+        public Data rawValue( Object rawValue )
+        {
+            this.rawValue = rawValue;
+            return this;
+        }
+
+
+        public Data expectedRawValue( Object expectedRawValue )
+        {
+            this.expectedRawValue = expectedRawValue;
+            return this;
+        }
+
+
+        public Data expectedDisplayValue( String expectedDisplayValue )
+        {
+            this.expectedDisplayValue = expectedDisplayValue;
+            return this;
+        }
+
+
+        public Data expectedHasValue( boolean expectedHasValue )
+        {
+            this.expectedHasValue = expectedHasValue;
+            return this;
+        }
+
+
+        public Data expectedStringOrBinaryValue( Object expectedStringOrBinaryValue )
+        {
+            this.expectedStringOrBinaryValue = expectedStringOrBinaryValue;
+            return this;
+        }
+
+    }
+}

Propchange: directory/studio/trunk/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/ValueEditorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native




Mime
View raw message