You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/12/22 11:16:08 UTC
svn commit: r489600 - in /directory/trunks/shared/ldap/src:
main/java/org/apache/directory/shared/ldap/schema/syntax/
test/java/org/apache/directory/shared/ldap/schema/syntax/
Author: elecharny
Date: Fri Dec 22 02:16:07 2006
New Revision: 489600
URL: http://svn.apache.org/viewvc?view=rev&rev=489600
Log:
Added two more SC : Fax and OtherMail
Added:
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxChecker.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxChecker.java
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxCheckerTest.java
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxCheckerTest.java
Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxChecker.java?view=auto&rev=489600
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxChecker.java Fri Dec 22 02:16:07 2006
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Fax according to RFC 4517.
+ *
+ * We didn't implemented the check against RFC 804, so the value is considered
+ * to contain an OctetString.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 488616 $
+ */
+public class FaxSyntaxChecker extends BinarySyntaxChecker
+{
+ /** the Apache assigned internal OID for this syntax checker */
+ private static final String SC_OID = "1.3.6.1.4.1.1466.115.121.1.23";
+
+
+ /**
+ * Private default constructor to prevent unnecessary instantiation.
+ */
+ public FaxSyntaxChecker()
+ {
+ super( SC_OID );
+ }
+
+ /**
+ *
+ * Creates a new instance of FaxSyntaxChecker.
+ *
+ * @param the oid to associate with this new SyntaxChecker
+ *
+ */
+ protected FaxSyntaxChecker( String oid )
+ {
+ super( oid );
+ }
+
+ /**
+ * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#isValidSyntax(Object)
+ */
+ public boolean isValidSyntax( Object value )
+ {
+ return true;
+ }
+}
Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxChecker.java?view=auto&rev=489600
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxChecker.java Fri Dec 22 02:16:07 2006
@@ -0,0 +1,123 @@
+/*
+ * 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 an OtherMailbox according to
+ * RFC 4517 :
+ *
+ * OtherMailbox = mailbox-type DOLLAR mailbox
+ * mailbox-type = PrintableString
+ * mailbox = IA5String
+ *
+ * This class extends PrintableString to benefit from its isValid() method. Of
+ * course, we also have to check that the second part is an IA5String, but as in
+ * Java we can't inherit from two classes, and as IA5Strings are easier to check,
+ * we have made this choice.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class OtherMailboxSyntaxChecker 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.39";
+
+ /**
+ *
+ * Creates a new instance of OtherMailboxSyntaxChecker.
+ *
+ */
+ public OtherMailboxSyntaxChecker()
+ {
+ super( SC_OID );
+ }
+
+ /**
+ *
+ * Creates a new instance of OtherMailboxSyntaxChecker.
+ *
+ * @param the oid to associate with this new SyntaxChecker
+ *
+ */
+ protected OtherMailboxSyntaxChecker( 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 '$' => error
+ return false;
+ }
+
+ String mailboxType = strValue.substring( 0, dollar );
+
+ String mailbox = ( ( dollar < strValue.length() - 1 ) ?
+ strValue.substring( dollar + 1 ) : "" );
+
+ // Check that the mailboxType is a PrintableString
+ if ( !StringTools.isPrintableString( mailboxType ) )
+ {
+ return false;
+ }
+
+ // Check that the mailbox is an IA5String
+ return ( StringTools.isIA5String( mailbox ) );
+ }
+}
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxCheckerTest.java?view=auto&rev=489600
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/FaxSyntaxCheckerTest.java Fri Dec 22 02:16:07 2006
@@ -0,0 +1,56 @@
+/*
+ * 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 FaxSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class FaxSyntaxCheckerTest extends TestCase
+{
+ FaxSyntaxChecker checker = new FaxSyntaxChecker();
+
+
+ public void testNullString()
+ {
+ assertTrue( checker.isValidSyntax( null ) );
+ }
+
+
+ public void testEmptyString()
+ {
+ assertTrue( checker.isValidSyntax( "" ) );
+ }
+
+ public void testOid()
+ {
+ assertEquals( "1.3.6.1.4.1.1466.115.121.1.23", checker.getSyntaxOid() );
+ }
+
+ public void testCorrectCase()
+ {
+ assertTrue( checker.isValidSyntax( "FALSE" ) );
+ assertTrue( checker.isValidSyntax( new byte[]{0x01, (byte)0xFF} ) );
+ }
+}
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxCheckerTest.java?view=auto&rev=489600
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/OtherMailboxSyntaxCheckerTest.java Fri Dec 22 02:16:07 2006
@@ -0,0 +1,59 @@
+/*
+ * 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 OtherMailboxSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class OtherMailboxSyntaxCheckerTest extends TestCase
+{
+ OtherMailboxSyntaxChecker checker = new OtherMailboxSyntaxChecker();
+
+
+ public void testNullString()
+ {
+ assertFalse( checker.isValidSyntax( null ) );
+ }
+
+
+ public void testEmptyString()
+ {
+ assertFalse( checker.isValidSyntax( "" ) );
+ }
+
+
+ public void testWrongCase() throws Exception
+ {
+ assertFalse( checker.isValidSyntax( "mailType" ) );
+ assertFalse( checker.isValidSyntax( "%$test" ) );
+ assertFalse( checker.isValidSyntax( new String( new byte[]{ 'm', 'a', 'i', 'l', '$', 0x00, 0x7F, (byte)0x80 }, "UTF-8" ) ) );
+ }
+
+
+ public void testCorrectCase()
+ {
+ assertTrue( checker.isValidSyntax( "SMTP$dev@directory.apache.org" ) );
+ }
+}