directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r489894 - in /directory/trunks/shared/ldap/src: main/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxChecker.java test/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxCheckerTest.java
Date Sat, 23 Dec 2006 14:42:58 GMT
Author: elecharny
Date: Sat Dec 23 06:42:55 2006
New Revision: 489894

URL: http://svn.apache.org/viewvc?view=rev&rev=489894
Log:
Added the TelexNumber SC

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxChecker.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxCheckerTest.java

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxChecker.java?view=auto&rev=489894
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxChecker.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxChecker.java
Sat Dec 23 06:42:55 2006
@@ -0,0 +1,162 @@
+/*
+ *  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 org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Telex Number according to 
+ * RFC 4517 :
+ * 
+ * telex-number  = actual-number DOLLAR country-code DOLLAR answerback
+ * actual-number = PrintableString
+ * country-code  = PrintableString
+ * answerback    = PrintableString
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TelexNumberSyntaxChecker extends AbstractSyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517 */
+    private static final String SC_OID = "1.3.6.1.4.1.1466.115.121.1.52";
+    
+    /**
+     * 
+     * Creates a new instance of TelexNumberSyntaxChecker.
+     *
+     */
+    public TelexNumberSyntaxChecker()
+    {
+        super( SC_OID );
+    }
+    
+    /**
+     * 
+     * Creates a new instance of TelexNumberSyntaxChecker.
+     * 
+     * @param the oid to associate with this new SyntaxChecker
+     *
+     */
+    protected TelexNumberSyntaxChecker( String oid )
+    {
+        super( 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;
+        }
+
+        // Search for the first '$' separator
+        int dollar = strValue.indexOf( '$' );
+        
+        // We must have one, and not on first position
+        if ( dollar <= 0 )
+        {
+            // No '$' => error
+            return false;
+        }
+        
+        String actualNumber = strValue.substring( 0, dollar );
+        
+        // The actualNumber must not be empty
+        if ( actualNumber.length() == 0 )
+        {
+            return false;
+        }
+        
+        // The actual number should be a PrintableString 
+        if ( ! StringTools.isPrintableString( actualNumber ) )
+        {
+            return false;
+        }
+        
+        // Search for the second separator
+        int dollar2 = strValue.indexOf( '$', dollar + 1 );
+            
+        // We must have one
+        if ( dollar2 == -1 )
+        {
+            // No '$' => error
+            return false;
+        }
+
+        String countryCode = strValue.substring( dollar + 1, dollar2 );
+        
+        // The countryCode must not be empty
+        if ( countryCode.length() == 0 )
+        {
+            return false;
+        }
+        
+        // The country Code should be a PrintableString 
+        if ( ! StringTools.isPrintableString( countryCode ) )
+        {
+            return false;
+        }
+        
+        // Now, check for the answerBack
+        if ( dollar2 + 1 == strValue.length() )
+        {
+            // The last string should not be null
+            return false;
+        }
+        
+        String answerBack = strValue.substring( dollar2 + 1 );
+        
+        // The answerBack should be a PrintableString 
+        if ( ! StringTools.isPrintableString( answerBack ) )
+        {
+            return false;
+        }
+        
+        // Check that the mailboxType is a PrintableString
+        return StringTools.isPrintableString( answerBack );
+    }
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxCheckerTest.java?view=auto&rev=489894
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxCheckerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/TelexNumberSyntaxCheckerTest.java
Sat Dec 23 06:42:55 2006
@@ -0,0 +1,64 @@
+/*
+ *  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 TelexNumberSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TelexNumberSyntaxCheckerTest extends TestCase
+{
+    TelexNumberSyntaxChecker checker = new TelexNumberSyntaxChecker();
+
+
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    public void testWrongCase() throws Exception
+    {
+        assertFalse( checker.isValidSyntax( "test" ) );
+        assertFalse( checker.isValidSyntax( "test$test" ) );
+        assertFalse( checker.isValidSyntax( "test$test$" ) );
+        assertFalse( checker.isValidSyntax( "test$$test" ) );
+        assertFalse( checker.isValidSyntax( "$test$test" ) );
+        assertFalse( checker.isValidSyntax( "test$test$test$test" ) );
+        assertFalse( checker.isValidSyntax( new String( new byte[]{ 't', 'e', 's', 't', '$',
0x00, 0x7F, (byte)0x80, '$', 't', 'e', 's', 't' }, "UTF-8" ) ) );
+    }
+    
+    
+    public void testCorrectCase()
+    {
+        assertTrue( checker.isValidSyntax( "test$test$test" ) );
+        assertTrue( checker.isValidSyntax( "t$t$t" ) );
+    }
+}



Mime
View raw message