Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 56244 invoked from network); 22 Dec 2006 13:03:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Dec 2006 13:03:37 -0000 Received: (qmail 35026 invoked by uid 500); 22 Dec 2006 13:03:42 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 34993 invoked by uid 500); 22 Dec 2006 13:03:42 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 34929 invoked by uid 99); 22 Dec 2006 13:03:42 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Dec 2006 05:03:42 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Dec 2006 05:03:32 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id EC8051A981D; Fri, 22 Dec 2006 05:02:42 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r489643 - in /directory/trunks/shared/ldap/src: main/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxChecker.java test/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxCheckerTest.java Date: Fri, 22 Dec 2006 13:02:42 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061222130242.EC8051A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Fri Dec 22 05:02:42 2006 New Revision: 489643 URL: http://svn.apache.org/viewvc?view=rev&rev=489643 Log: Added trhe PostalAddress SC Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxChecker.java directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxCheckerTest.java Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxChecker.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxChecker.java?view=auto&rev=489643 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxChecker.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxChecker.java Fri Dec 22 05:02:42 2006 @@ -0,0 +1,127 @@ +/* + * 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 PostalAddress according to + * RFC 4517 : + * + * = + * = "$" | e + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class PostalAddressSyntaxChecker 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.41"; + + /** + * + * Creates a new instance of PostalAddressSyntaxChecker. + * + */ + public PostalAddressSyntaxChecker() + { + super( SC_OID ); + } + + /** + * + * Creates a new instance of PostalAddressSyntaxChecker. + * + * @param the oid to associate with this new SyntaxChecker + * + */ + protected PostalAddressSyntaxChecker( 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 '$' separator + int dollar = strValue.indexOf( '$' ); + + if ( dollar == -1 ) + { + // No '$' => only a dstring + return true; + } + + int pos = 0; + do + { + // check that the element between each '$' is not empty + String address = strValue.substring( pos, dollar ); + + if ( StringTools.isEmpty( address ) ) + { + return false; + } + + pos = dollar + 1; + + if ( pos == strValue.length() ) + { + // we should not have a '$' at the end + return false; + } + + dollar = strValue.indexOf( '$', pos ); + } while ( dollar > -1 ); + + return true; + } +} Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxCheckerTest.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxCheckerTest.java?view=auto&rev=489643 ============================================================================== --- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxCheckerTest.java (added) +++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/PostalAddressSyntaxCheckerTest.java Fri Dec 22 05:02:42 2006 @@ -0,0 +1,62 @@ +/* + * 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 PostalAddressSyntaxChecker. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class PostalAddressSyntaxCheckerTest extends TestCase +{ + PostalAddressSyntaxChecker checker = new PostalAddressSyntaxChecker(); + + + public void testNullString() + { + assertFalse( checker.isValidSyntax( null ) ); + } + + + public void testEmptyString() + { + assertFalse( checker.isValidSyntax( "" ) ); + } + + + public void testWrongCase() + { + assertFalse( checker.isValidSyntax( "$" ) ); + assertFalse( checker.isValidSyntax( "test $" ) ); + assertFalse( checker.isValidSyntax( "$ test" ) ); + assertFalse( checker.isValidSyntax( "test$$test" ) ); + } + + + public void testCorrectCase() + { + assertTrue( checker.isValidSyntax( "test" ) ); + assertTrue( checker.isValidSyntax( "test$test" ) ); + assertTrue( checker.isValidSyntax( "test$test$test" ) ); + } +}