directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r487525 - in /directory/trunks/shared/ldap/src: main/java/org/apache/directory/shared/ldap/schema/syntax/ test/java/org/apache/directory/shared/ldap/schema/syntax/
Date Fri, 15 Dec 2006 12:02:38 GMT
Author: elecharny
Date: Fri Dec 15 04:02:37 2006
New Revision: 487525

URL: http://svn.apache.org/viewvc?view=rev&rev=487525
Log:
Added the faxTelNumber and its test, plus the DNandUID test

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxChecker.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxCheckerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameAndOptionalUIDSyntaxCheckerTest.java

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxChecker.java?view=auto&rev=487525
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxChecker.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxChecker.java
Fri Dec 15 04:02:37 2006
@@ -0,0 +1,219 @@
+/*
+ *  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.shared.ldap.schema.syntax;
+
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.NamingException;
+
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a facsimile TelephoneNumber according 
+ * to ITU recommendation E.123 for the Telephone number part, and from RFC 4517, par. 
+ * 3.3.11 :
+ * 
+ * fax-number       = telephone-number *( DOLLAR fax-parameter )
+ * telephone-number = PrintableString
+ * fax-parameter    = "twoDimensional" |
+ *                    "fineResolution" |
+ *                    "unlimitedLength" |
+ *                    "b4Length" |
+ *                    "a3Width" |
+ *                    "b4Width" |
+ *                    "uncompressed"
+ *
+ * 
+ * If needed, and to allow more syntaxes, a list of regexps has been added
+ * which can be initialized to other values
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class FacsimileTelephoneNumberSyntaxChecker extends TelephoneNumberSyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.11 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.22";
+    
+    /** Fax parameters possible values */
+    private final static String TWO_DIMENSIONAL  = "twoDimensional";
+    private final static String FINE_RESOLUTION  = "fineResolution";
+    private final static String UNLIMITED_LENGTH = "unlimitedLength";
+    private final static String B4_LENGTH        = "b4Length";
+    private final static String A3_LENGTH        = "a3Width";
+    private final static String B4_WIDTH         = "b4Width";
+    private final static String UNCOMPRESSED     = "uncompressed";
+    
+    /** A set which contaons all the possible fax parameters values */
+    private static Set<String> faxParameters = new HashSet<String>();
+    
+    /** Initialization of the fax parameters set of values */
+    static
+    {
+        faxParameters.add( TWO_DIMENSIONAL.toLowerCase() );
+        faxParameters.add( FINE_RESOLUTION.toLowerCase() );
+        faxParameters.add( UNLIMITED_LENGTH.toLowerCase() );
+        faxParameters.add( B4_LENGTH.toLowerCase() );
+        faxParameters.add( A3_LENGTH.toLowerCase() );
+        faxParameters.add( B4_WIDTH.toLowerCase() );
+        faxParameters.add( UNCOMPRESSED.toLowerCase() );
+    }
+    
+    /**
+     * Creates a new instance of TelephoneNumberSyntaxChecker.
+     */
+    public FacsimileTelephoneNumberSyntaxChecker()
+    {
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+     */
+    public void assertSyntax( Object value ) throws NamingException
+    {
+        if ( ! isValidSyntax( value ) )
+        {
+            throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX
);
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        String strValue;
+
+        if ( value == null )
+        {
+            return false;
+        }
+        
+        if ( value instanceof String )
+        {
+            strValue = ( String ) value;
+        }
+        else if ( value instanceof byte[] )
+        {
+            strValue = StringTools.utf8ToString( ( byte[] ) value ); 
+        }
+        else
+        {
+            strValue = value.toString();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // The facsimile telephone number might be composed
+        // of two parts separated by a '$'.
+        int dollarPos = strValue.indexOf( '$' );
+        
+        if ( dollarPos == -1 )
+        {
+            // We have no fax-parameter : check the Telephone number
+            return super.isValidSyntax( strValue );
+        }
+        
+        // First check the telephone number if the '$' is not at the first position
+        if ( dollarPos > 0 )
+        {
+            if ( !super.isValidSyntax( strValue.substring( 0, dollarPos -1 ) ) )
+            {
+                return false;
+            }
+            
+            // Now, try to validate the fax-parameters : we may
+            // have more than one, so we will store the seen params
+            // in a set to check that we don't have the same param twice
+            Set<String> paramsSeen = new HashSet<String>(); 
+           
+            while ( dollarPos > 0 )
+            {
+                String faxParam = null;
+                int newDollar = strValue.indexOf( '$', dollarPos + 1 );
+
+                if ( newDollar == -1 )
+                {
+                    faxParam = strValue.substring(  dollarPos+1 );
+                }
+                else
+                {
+                    faxParam = strValue.substring(  dollarPos+1, newDollar );
+                }
+                
+                if ( faxParam == null )
+                {
+                    // Not allowed
+                    return false;
+                }
+                
+                // Relax a little bit the syntax by lowercasing the param
+                faxParam = faxParam.toLowerCase();
+                
+                if ( !faxParameters.contains( faxParam ) )
+                {
+                    // This parameter is not in the possible set
+                    return false;
+                }
+                else if ( paramsSeen.contains( faxParam ) )
+                {
+                    // We have the same parameters twice...
+                    return false;
+                } 
+                else
+                {
+                    // It's a correct param, let's add it to the seen 
+                    // params.
+                    paramsSeen.add( faxParam );
+                }
+                
+                dollarPos = newDollar;
+            }
+            
+            return true;
+        }
+        else
+        {
+            // We must have a valid telephone number !
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxCheckerTest.java?view=auto&rev=487525
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxCheckerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FacsimileTelephoneNumberSyntaxCheckerTest.java
Fri Dec 15 04:02:37 2006
@@ -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.shared.ldap.schema.syntax;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for FacsimileTelephoneNumberSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class FacsimileTelephoneNumberSyntaxCheckerTest extends TestCase
+{
+    FacsimileTelephoneNumberSyntaxChecker checker = new FacsimileTelephoneNumberSyntaxChecker();
+
+
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    public void testOneCharString()
+    {
+        assertFalse( checker.isValidSyntax( "A" ) );
+        assertFalse( checker.isValidSyntax( "+" ) );
+    }
+    
+    
+    public void testWrongCase()
+    {
+        assertFalse( checker.isValidSyntax( "123 456 f" ) );
+        assertFalse( checker.isValidSyntax( "+ ()" ) );
+        assertFalse( checker.isValidSyntax( " +2 (123) 456-789 +" ) );
+    }
+    
+    
+    public void testCorrectTelephoneNumber()
+    {
+        assertTrue( checker.isValidSyntax( "1" ) );
+        assertTrue( checker.isValidSyntax( "1111" ) );
+        assertTrue( checker.isValidSyntax( "1 (2) 3" ) );
+        assertTrue( checker.isValidSyntax( "+ 123 ( 456 )7891   12345" ) );
+        assertTrue( checker.isValidSyntax( " 12 34 56 78 90 " ) );
+    }
+    
+    public void testWithNewMandatoryRegexp()
+    {
+        // Adding french telephone number regexp
+        checker.setDefaultRegexp( " *0[1-8](( *|[-/.]{1})\\d\\d){4} *" );
+        
+        assertFalse( checker.isValidSyntax( "+ 123 ( 456 )7891   12345" ) );
+        assertTrue( checker.isValidSyntax( " 01 02 03 04 05 " ) );
+        assertTrue( checker.isValidSyntax( " 0102 03 04 05 " ) );
+        assertTrue( checker.isValidSyntax( " 01 02 03 04  05 " ) );
+        assertTrue( checker.isValidSyntax( " 01/02/03/04/05 " ) );
+        assertFalse( checker.isValidSyntax( " 01 / 02 .03 04--  05 " ) );
+    }
+
+    public void testCorrectTelephoneNumberAndFaxParam()
+    {
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$twoDimensional" ) );
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$fineResolution" ) );
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$unlimitedLength" )
);
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$b4Length" ) );
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$a3Width" ) );
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$b4Width" ) );
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$twoDimensional" ) );
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$uncompressed" ) );
+    }
+    
+    public void testCorrectTelephoneNumberAndFaxParams()
+    {
+        assertTrue( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$twoDimensional$fineResolution$a3Width"
) );
+    }
+
+    public void testCorrectTelephoneNumberBadFaxParams()
+    {
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$" ) );
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$$" ) );
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$twoDimensionnal" )
);
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$ twoDimensional" )
);
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$twoDimensional$" )
);
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$twoDimensional$twoDimensional"
) );
+        assertFalse( checker.isValidSyntax( "+ 33 1 (456) 7891   12345$b4Width$ $a3Width"
) );
+    }
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameAndOptionalUIDSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameAndOptionalUIDSyntaxCheckerTest.java?view=auto&rev=487525
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameAndOptionalUIDSyntaxCheckerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameAndOptionalUIDSyntaxCheckerTest.java
Fri Dec 15 04:02:37 2006
@@ -0,0 +1,93 @@
+/*
+ *  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.shared.ldap.schema.syntax;
+
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for NameAndOptionalUIDSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NameAndOptionalUIDSyntaxCheckerTest extends TestCase
+{
+    NameAndOptionalUIDSyntaxChecker checker = new NameAndOptionalUIDSyntaxChecker();
+
+
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    public void testOneCharString()
+    {
+        assertFalse( checker.isValidSyntax( "0" ) );
+        assertFalse( checker.isValidSyntax( "'" ) );
+        assertFalse( checker.isValidSyntax( "1" ) );
+        assertFalse( checker.isValidSyntax( "#" ) );
+    }
+    
+    
+    public void testWrongDN()
+    {
+        assertFalse( checker.isValidSyntax( "a=b," ) );
+        assertFalse( checker.isValidSyntax( "a=#0101'B" ) );
+        assertFalse( checker.isValidSyntax( "a=b+" ) );
+        assertFalse( checker.isValidSyntax( "a=b,c=d," ) );
+    }
+    
+    public void testWrongUID()
+    {
+        assertFalse( checker.isValidSyntax( "#'0101'B" ) );
+    }
+    
+    
+    public void testCorrectDN()
+    {
+        assertTrue( checker.isValidSyntax( "a=b" ) );
+        assertTrue( checker.isValidSyntax( "a = b" ) );
+        assertTrue( checker.isValidSyntax( "a=b + c=d" ) );
+        assertTrue( checker.isValidSyntax( "a=b,c=d" ) );
+        assertTrue( checker.isValidSyntax( "a=b\\,c = d, e=f" ) );
+    }
+
+    public void testCorrectDNAndUID()
+    {
+        assertTrue( checker.isValidSyntax( "a=b#'1010'B" ) );
+        assertTrue( checker.isValidSyntax( "a = b#'1010'B" ) );
+        assertTrue( checker.isValidSyntax( "a=b + c=d#'1010'B" ) );
+        assertTrue( checker.isValidSyntax( "a=b,c=d#'1010'B" ) );
+        assertTrue( checker.isValidSyntax( "a=b\\,c = d, e=f#'1010'B" ) );
+        assertTrue( checker.isValidSyntax( "a=b\\,c = \\#0A0A, e=f#'1010'B" ) );
+        
+        // With 'false' UID (they are part of DN)
+        assertTrue( checker.isValidSyntax( "a=b##'0101'B" ) );
+        assertTrue( checker.isValidSyntax( "a=b#'0101'C" ) );
+    }
+}



Mime
View raw message