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/14 16:37:42 UTC
svn commit: r487239 -
/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DNSyntaxChecker.java
Author: elecharny
Date: Thu Dec 14 07:37:41 2006
New Revision: 487239
URL: http://svn.apache.org/viewvc?view=rev&rev=487239
Log:
Added the DN syntax checker
Added:
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DNSyntaxChecker.java
Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DNSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DNSyntaxChecker.java?view=auto&rev=487239
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DNSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DNSyntaxChecker.java Thu Dec 14 07:37:41 2006
@@ -0,0 +1,118 @@
+/*
+ * 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 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.name.LdapDN;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a valid DN. We just check
+ * that the DN is valid, we don't need to verify each of the RDN syntax.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DNSyntaxChecker implements SyntaxChecker
+{
+ /** The Syntax OID, according RFC 4517, par. 3.3.9 */
+ public static final String DEFAULT_OID = "1.3.6.1.4.1.1466.115.121.1.12";
+
+ /** The Syntax OID */
+ private final String oid;
+
+
+ public DNSyntaxChecker( String oid )
+ {
+ this.oid = oid;
+ }
+
+ /**
+ *
+ * Creates a new instance of DNSyntaxChecker.
+ *
+ */
+ public DNSyntaxChecker()
+ {
+ this.oid = DEFAULT_OID;
+ }
+
+
+ /* (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;
+ }
+
+ // Check that the value is a valid DN
+ return LdapDN.isValid( strValue );
+ }
+}