Author: akarasulu
Date: Thu Oct 21 14:23:32 2004
New Revision: 55267
Added:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/SimpleNameComponentNormalizer.java
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DeepTrimNormalizer.java
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DeepTrimToLowerNormalizer.java
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnComparator.java
- copied, changed from rev 55174,
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnComparator.java
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnNormalizer.java
- copied, changed from rev 55174,
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnNormalizer.java
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnSyntaxChecker.java
- copied, changed from rev 55174,
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnSyntaxChecker.java
Removed:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/.cvsignore
Modified:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/StringTools.java
Log:
Commit changes ...
o added normalizers around deepTrim and deepTrimToLower string functions
o copied, and cleaned up DnSyntaxChecker from sandbox2/schema-api
o copied, and cleaned up DnNormalizer and DnComparator from sandbox2/sch..
o cleaned up deepTrim method and made it trim all whitespace not just spaces
o added a simple NameComponentNormalizer implementation which uses the
same Normalizer regardless of the attributeType of the assertion value
Added:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/SimpleNameComponentNormalizer.java
==============================================================================
--- (empty file)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/name/SimpleNameComponentNormalizer.java
Thu Oct 21 14:23:32 2004
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.ldap.common.name;
+
+
+import javax.naming.NamingException;
+
+import org.apache.ldap.common.schema.Normalizer;
+
+
+/**
+ * A simple NameComponentNormalizer which uses the same Normalizer to always
+ * normalize the value the same way regardless of the attribute the value is
+ * for.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SimpleNameComponentNormalizer implements NameComponentNormalizer
+{
+ /** the normalizer used to normalize the value every time */
+ private final Normalizer normalizer;
+
+
+ /**
+ * Creates a new SimpleNameComponentNormalizer with the normalizer it uses
+ * ever time irrespective of the attribute name or oid.
+ *
+ * @param normalizer the Normalizer to use for all normalization requests
+ */
+ public SimpleNameComponentNormalizer( Normalizer normalizer )
+ {
+ this.normalizer = normalizer;
+ }
+
+
+ public String normalizeByName( String name, String val ) throws
NamingException
+ {
+ return normalizer.normalize( val ).toString();
+ }
+
+
+ public String normalizeByOid( String oid, String val ) throws
NamingException
+ {
+ return normalizer.normalize( val ).toString();
+ }
+}
Added:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DeepTrimNormalizer.java
==============================================================================
--- (empty file)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DeepTrimNormalizer.java
Thu Oct 21 14:23:32 2004
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.ldap.common.schema;
+
+
+import javax.naming.NamingException;
+
+import org.apache.ldap.common.util.StringTools;
+
+
+/**
+ * Normalizer which trims down whitespace replacing multiple whitespace
+ * characters on the edges and within the string with a single space character
+ * thereby preserving tokenization order.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DeepTrimNormalizer implements Normalizer
+{
+ public Object normalize( Object value ) throws NamingException
+ {
+ return StringTools.deepTrim( value.toString() );
+ }
+}
Added:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DeepTrimToLowerNormalizer.java
==============================================================================
--- (empty file)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DeepTrimToLowerNormalizer.java
Thu Oct 21 14:23:32 2004
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.ldap.common.schema;
+
+
+import javax.naming.NamingException;
+
+import org.apache.ldap.common.util.StringTools;
+
+
+/**
+ * Normalizer which trims down whitespace replacing multiple whitespace
+ * characters on the edges and within the string with a single space character
+ * thereby preserving tokenization order - while doing all this in the same
pass
+ * it lower cases all characters.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DeepTrimToLowerNormalizer implements Normalizer
+{
+ public Object normalize( Object value ) throws NamingException
+ {
+ return StringTools.deepTrimToLower( value.toString() );
+ }
+}
Copied:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnComparator.java
(from rev 55174,
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnComparator.java)
==============================================================================
---
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnComparator.java
(original)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnComparator.java
Thu Oct 21 14:23:32 2004
@@ -1,218 +1,20 @@
-/*
- * Apache License
- * Version 2.0, January 2004
- * http://www.apache.org/licenses/
- *
- * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- *
- * 1. Definitions.
- *
- * "License" shall mean the terms and conditions for use, reproduction,
- * and distribution as defined by Sections 1 through 9 of this document.
- *
- * "Licensor" shall mean the copyright owner or entity authorized by
- * the copyright owner that is granting the License.
- *
- * "Legal Entity" shall mean the union of the acting entity and all
- * other entities that control, are controlled by, or are under common
- * control with that entity. For the purposes of this definition,
- * "control" means (i) the power, direct or indirect, to cause the
- * direction or management of such entity, whether by contract or
- * otherwise, or (ii) ownership of fifty percent (50%) or more of the
- * outstanding shares, or (iii) beneficial ownership of such entity.
- *
- * "You" (or "Your") shall mean an individual or Legal Entity
- * exercising permissions granted by this License.
- *
- * "Source" form shall mean the preferred form for making modifications,
- * including but not limited to software source code, documentation
- * source, and configuration files.
- *
- * "Object" form shall mean any form resulting from mechanical
- * transformation or translation of a Source form, including but
- * not limited to compiled object code, generated documentation,
- * and conversions to other media types.
- *
- * "Work" shall mean the work of authorship, whether in Source or
- * Object form, made available under the License, as indicated by a
- * copyright notice that is included in or attached to the work
- * (an example is provided in the Appendix below).
- *
- * "Derivative Works" shall mean any work, whether in Source or Object
- * form, that is based on (or derived from) the Work and for which the
- * editorial revisions, annotations, elaborations, or other modifications
- * represent, as a whole, an original work of authorship. For the purposes
- * of this License, Derivative Works shall not include works that remain
- * separable from, or merely link (or bind by name) to the interfaces of,
- * the Work and Derivative Works thereof.
- *
- * "Contribution" shall mean any work of authorship, including
- * the original version of the Work and any modifications or additions
- * to that Work or Derivative Works thereof, that is intentionally
- * submitted to Licensor for inclusion in the Work by the copyright owner
- * or by an individual or Legal Entity authorized to submit on behalf of
- * the copyright owner. For the purposes of this definition, "submitted"
- * means any form of electronic, verbal, or written communication sent
- * to the Licensor or its representatives, including but not limited to
- * communication on electronic mailing lists, source code control systems,
- * and issue tracking systems that are managed by, or on behalf of, the
- * Licensor for the purpose of discussing and improving the Work, but
- * excluding communication that is conspicuously marked or otherwise
- * designated in writing by the copyright owner as "Not a Contribution."
- *
- * "Contributor" shall mean Licensor and any individual or Legal Entity
- * on behalf of whom a Contribution has been received by Licensor and
- * subsequently incorporated within the Work.
- *
- * 2. Grant of Copyright License. Subject to the terms and conditions of
- * this License, each Contributor hereby grants to You a perpetual,
- * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- * copyright license to reproduce, prepare Derivative Works of,
- * publicly display, publicly perform, sublicense, and distribute the
- * Work and such Derivative Works in Source or Object form.
- *
- * 3. Grant of Patent License. Subject to the terms and conditions of
- * this License, each Contributor hereby grants to You a perpetual,
- * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- * (except as stated in this section) patent license to make, have made,
- * use, offer to sell, sell, import, and otherwise transfer the Work,
- * where such license applies only to those patent claims licensable
- * by such Contributor that are necessarily infringed by their
- * Contribution(s) alone or by combination of their Contribution(s)
- * with the Work to which such Contribution(s) was submitted. If You
- * institute patent litigation against any entity (including a
- * cross-claim or counterclaim in a lawsuit) alleging that the Work
- * or a Contribution incorporated within the Work constitutes direct
- * or contributory patent infringement, then any patent licenses
- * granted to You under this License for that Work shall terminate
- * as of the date such litigation is filed.
- *
- * 4. Redistribution. You may reproduce and distribute copies of the
- * Work or Derivative Works thereof in any medium, with or without
- * modifications, and in Source or Object form, provided that You
- * meet the following conditions:
- *
- * (a) You must give any other recipients of the Work or
- * Derivative Works a copy of this License; and
- *
- * (b) You must cause any modified files to carry prominent notices
- * stating that You changed the files; and
- *
- * (c) You must retain, in the Source form of any Derivative Works
- * that You distribute, all copyright, patent, trademark, and
- * attribution notices from the Source form of the Work,
- * excluding those notices that do not pertain to any part of
- * the Derivative Works; and
- *
- * (d) If the Work includes a "NOTICE" text file as part of its
- * distribution, then any Derivative Works that You distribute must
- * include a readable copy of the attribution notices contained
- * within such NOTICE file, excluding those notices that do not
- * pertain to any part of the Derivative Works, in at least one
- * of the following places: within a NOTICE text file distributed
- * as part of the Derivative Works; within the Source form or
- * documentation, if provided along with the Derivative Works; or,
- * within a display generated by the Derivative Works, if and
- * wherever such third-party notices normally appear. The contents
- * of the NOTICE file are for informational purposes only and
- * do not modify the License. You may add Your own attribution
- * notices within Derivative Works that You distribute, alongside
- * or as an addendum to the NOTICE text from the Work, provided
- * that such additional attribution notices cannot be construed
- * as modifying the License.
- *
- * You may add Your own copyright statement to Your modifications and
- * may provide additional or different license terms and conditions
- * for use, reproduction, or distribution of Your modifications, or
- * for any such Derivative Works as a whole, provided Your use,
- * reproduction, and distribution of the Work otherwise complies with
- * the conditions stated in this License.
- *
- * 5. Submission of Contributions. Unless You explicitly state otherwise,
- * any Contribution intentionally submitted for inclusion in the Work
- * by You to the Licensor shall be under the terms and conditions of
- * this License, without any additional terms or conditions.
- * Notwithstanding the above, nothing herein shall supersede or modify
- * the terms of any separate license agreement you may have executed
- * with Licensor regarding such Contributions.
- *
- * 6. Trademarks. This License does not grant permission to use the trade
- * names, trademarks, service marks, or product names of the Licensor,
- * except as required for reasonable and customary use in describing the
- * origin of the Work and reproducing the content of the NOTICE file.
- *
- * 7. Disclaimer of Warranty. Unless required by applicable law or
- * agreed to in writing, Licensor provides the Work (and each
- * Contributor provides its Contributions) on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied, including, without limitation, any warranties or conditions
- * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- * PARTICULAR PURPOSE. You are solely responsible for determining the
- * appropriateness of using or redistributing the Work and assume any
- * risks associated with Your exercise of permissions under this License.
- *
- * 8. Limitation of Liability. In no event and under no legal theory,
- * whether in tort (including negligence), contract, or otherwise,
- * unless required by applicable law (such as deliberate and grossly
- * negligent acts) or agreed to in writing, shall any Contributor be
- * liable to You for damages, including any direct, indirect, special,
- * incidental, or consequential damages of any character arising as a
- * result of this License or out of the use or inability to use the
- * Work (including but not limited to damages for loss of goodwill,
- * work stoppage, computer failure or malfunction, or any and all
- * other commercial damages or losses), even if such Contributor
- * has been advised of the possibility of such damages.
- *
- * 9. Accepting Warranty or Additional Liability. While redistributing
- * the Work or Derivative Works thereof, You may choose to offer,
- * and charge a fee for, acceptance of support, warranty, indemnity,
- * or other liability obligations and/or rights consistent with this
- * License. However, in accepting such obligations, You may act only
- * on Your own behalf and on Your sole responsibility, not on behalf
- * of any other Contributor, and only if You agree to indemnify,
- * defend, and hold each Contributor harmless for any liability
- * incurred by, or claims asserted against, such Contributor by reason
- * of your accepting any such warranty or additional liability.
- *
- * END OF TERMS AND CONDITIONS
- *
- * APPENDIX: How to apply the Apache License to your work.
- *
- * To apply the Apache License to your work, attach the following
- * boilerplate notice, with the fields enclosed by brackets "[]"
- * replaced with your own identifying information. (Don't include
- * the brackets!) The text should be enclosed in the appropriate
- * comment syntax for the file format. We also recommend that a
- * file or class name and description of purpose be included on the
- * same "printed page" as the copyright notice for easier
- * identification within third-party archives.
- *
- * Copyright [yyyy] [name of copyright owner]
- *
- * Licensed 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.
- *
- */
-
/*
- * $Id: DnComparator.java,v 1.2 2003/09/18 21:19:48 akarasulu Exp $
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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
*
- * -- (c) LDAPd Group --
- * -- Please refer to the LICENSE.txt file in the root directory of --
- * -- any LDAPd project for copyright and distribution information. --
+ * 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.
*
- * Created on Sep 15, 2003
*/
-package org.apache.ldap.server.schema.matching ;
+package org.apache.ldap.common.schema ;
import java.io.IOException ;
@@ -223,23 +25,22 @@
import javax.naming.NamingException ;
import org.apache.ldap.common.name.DnParser ;
+import org.apache.ldap.common.name.NameComponentNormalizer;
/**
* A DnComparator that uses a parser to parse Dn strings. The parser may
- * or may not be Schema enabled. This code will not be used until a name
- * cache is provided to prevent excessive parser invocations however it is
- * required although inefficent for correct operation for sorted entry
- * returns that sort on distinguished names.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision: 1.2 $
+ * or may not be Schema enabled.
+ *
+ * @todo start using some kinda name cache here; it is way too expensive to be
+ * doing this over and over again
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
*/
-class DnComparator implements Comparator
+public class DnComparator implements Comparator
{
/** The parser used to parse DN Strings */
- private NameParser m_parser ;
+ private NameParser parser ;
// ------------------------------------------------------------------------
@@ -248,14 +49,14 @@
/**
- * Creates the default Schema-less DN Comparator whose parser does not
- * normalize.
+ * Creates a default schema-less DN Comparator whose parser does not
attempt
+ * to normalize assertion valeus while comparing DN components.
*/
public DnComparator()
{
try
{
- m_parser = new DnParser() ;
+ parser = new DnParser() ;
}
catch ( IOException e )
{
@@ -266,13 +67,21 @@
/**
- * Creates a DN Comparator using a specialized name parser.
- *
- * @param a_parser the DN parser
+ * Creates a DN Comparator using a name component normalizer which should
+ * use schema normalizers for attribute equality matching rules to
+ * normalize assertion values.
*/
- public DnComparator( NameParser a_parser )
+ public DnComparator( NameComponentNormalizer normalizer )
{
- m_parser = a_parser ;
+ try
+ {
+ parser = new DnParser( normalizer ) ;
+ }
+ catch ( IOException e )
+ {
+ // Should never really be thrown
+ e.printStackTrace() ;
+ }
}
@@ -284,21 +93,21 @@
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
- public int compare( Object a_obj1, Object a_obj2 )
+ public int compare( Object obj1, Object obj2 )
{
- Name l_dn1 = null ;
- Name l_dn2 = null ;
+ Name dn1 = null ;
+ Name dn2 = null ;
// Figure out how to compose the Name for the first object
- if ( a_obj1 instanceof Name )
+ if ( obj1 instanceof Name )
{
- l_dn1 = ( Name ) a_obj1 ;
+ dn1 = ( Name ) obj1 ;
}
- else if ( a_obj1 instanceof String )
+ else if ( obj1 instanceof String )
{
try
{
- l_dn1 = m_parser.parse( ( String ) a_obj1 ) ;
+ dn1 = parser.parse( ( String ) obj1 ) ;
}
catch ( NamingException ne )
{
@@ -313,15 +122,15 @@
}
// Figure out how to compose the Name for the second object
- if ( a_obj2 instanceof Name )
+ if ( obj2 instanceof Name )
{
- l_dn2 = ( Name ) a_obj2 ;
+ dn2 = ( Name ) obj2 ;
}
- else if ( a_obj2 instanceof String )
+ else if ( obj2 instanceof String )
{
try
{
- l_dn2 = m_parser.parse( ( String ) a_obj2 ) ;
+ dn2 = parser.parse( ( String ) obj2 ) ;
}
catch ( NamingException ne )
{
@@ -335,6 +144,6 @@
"second argument was not a distinguished name" ) ;
}
- return l_dn1.compareTo( l_dn2 ) ;
+ return dn1.compareTo( dn2 ) ;
}
}
Copied:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnNormalizer.java
(from rev 55174,
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnNormalizer.java)
==============================================================================
---
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnNormalizer.java
(original)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnNormalizer.java
Thu Oct 21 14:23:32 2004
@@ -1,219 +1,21 @@
-/*
- * Apache License
- * Version 2.0, January 2004
- * http://www.apache.org/licenses/
- *
- * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- *
- * 1. Definitions.
- *
- * "License" shall mean the terms and conditions for use, reproduction,
- * and distribution as defined by Sections 1 through 9 of this document.
- *
- * "Licensor" shall mean the copyright owner or entity authorized by
- * the copyright owner that is granting the License.
- *
- * "Legal Entity" shall mean the union of the acting entity and all
- * other entities that control, are controlled by, or are under common
- * control with that entity. For the purposes of this definition,
- * "control" means (i) the power, direct or indirect, to cause the
- * direction or management of such entity, whether by contract or
- * otherwise, or (ii) ownership of fifty percent (50%) or more of the
- * outstanding shares, or (iii) beneficial ownership of such entity.
- *
- * "You" (or "Your") shall mean an individual or Legal Entity
- * exercising permissions granted by this License.
- *
- * "Source" form shall mean the preferred form for making modifications,
- * including but not limited to software source code, documentation
- * source, and configuration files.
- *
- * "Object" form shall mean any form resulting from mechanical
- * transformation or translation of a Source form, including but
- * not limited to compiled object code, generated documentation,
- * and conversions to other media types.
- *
- * "Work" shall mean the work of authorship, whether in Source or
- * Object form, made available under the License, as indicated by a
- * copyright notice that is included in or attached to the work
- * (an example is provided in the Appendix below).
- *
- * "Derivative Works" shall mean any work, whether in Source or Object
- * form, that is based on (or derived from) the Work and for which the
- * editorial revisions, annotations, elaborations, or other modifications
- * represent, as a whole, an original work of authorship. For the purposes
- * of this License, Derivative Works shall not include works that remain
- * separable from, or merely link (or bind by name) to the interfaces of,
- * the Work and Derivative Works thereof.
- *
- * "Contribution" shall mean any work of authorship, including
- * the original version of the Work and any modifications or additions
- * to that Work or Derivative Works thereof, that is intentionally
- * submitted to Licensor for inclusion in the Work by the copyright owner
- * or by an individual or Legal Entity authorized to submit on behalf of
- * the copyright owner. For the purposes of this definition, "submitted"
- * means any form of electronic, verbal, or written communication sent
- * to the Licensor or its representatives, including but not limited to
- * communication on electronic mailing lists, source code control systems,
- * and issue tracking systems that are managed by, or on behalf of, the
- * Licensor for the purpose of discussing and improving the Work, but
- * excluding communication that is conspicuously marked or otherwise
- * designated in writing by the copyright owner as "Not a Contribution."
- *
- * "Contributor" shall mean Licensor and any individual or Legal Entity
- * on behalf of whom a Contribution has been received by Licensor and
- * subsequently incorporated within the Work.
- *
- * 2. Grant of Copyright License. Subject to the terms and conditions of
- * this License, each Contributor hereby grants to You a perpetual,
- * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- * copyright license to reproduce, prepare Derivative Works of,
- * publicly display, publicly perform, sublicense, and distribute the
- * Work and such Derivative Works in Source or Object form.
- *
- * 3. Grant of Patent License. Subject to the terms and conditions of
- * this License, each Contributor hereby grants to You a perpetual,
- * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- * (except as stated in this section) patent license to make, have made,
- * use, offer to sell, sell, import, and otherwise transfer the Work,
- * where such license applies only to those patent claims licensable
- * by such Contributor that are necessarily infringed by their
- * Contribution(s) alone or by combination of their Contribution(s)
- * with the Work to which such Contribution(s) was submitted. If You
- * institute patent litigation against any entity (including a
- * cross-claim or counterclaim in a lawsuit) alleging that the Work
- * or a Contribution incorporated within the Work constitutes direct
- * or contributory patent infringement, then any patent licenses
- * granted to You under this License for that Work shall terminate
- * as of the date such litigation is filed.
- *
- * 4. Redistribution. You may reproduce and distribute copies of the
- * Work or Derivative Works thereof in any medium, with or without
- * modifications, and in Source or Object form, provided that You
- * meet the following conditions:
- *
- * (a) You must give any other recipients of the Work or
- * Derivative Works a copy of this License; and
- *
- * (b) You must cause any modified files to carry prominent notices
- * stating that You changed the files; and
- *
- * (c) You must retain, in the Source form of any Derivative Works
- * that You distribute, all copyright, patent, trademark, and
- * attribution notices from the Source form of the Work,
- * excluding those notices that do not pertain to any part of
- * the Derivative Works; and
- *
- * (d) If the Work includes a "NOTICE" text file as part of its
- * distribution, then any Derivative Works that You distribute must
- * include a readable copy of the attribution notices contained
- * within such NOTICE file, excluding those notices that do not
- * pertain to any part of the Derivative Works, in at least one
- * of the following places: within a NOTICE text file distributed
- * as part of the Derivative Works; within the Source form or
- * documentation, if provided along with the Derivative Works; or,
- * within a display generated by the Derivative Works, if and
- * wherever such third-party notices normally appear. The contents
- * of the NOTICE file are for informational purposes only and
- * do not modify the License. You may add Your own attribution
- * notices within Derivative Works that You distribute, alongside
- * or as an addendum to the NOTICE text from the Work, provided
- * that such additional attribution notices cannot be construed
- * as modifying the License.
- *
- * You may add Your own copyright statement to Your modifications and
- * may provide additional or different license terms and conditions
- * for use, reproduction, or distribution of Your modifications, or
- * for any such Derivative Works as a whole, provided Your use,
- * reproduction, and distribution of the Work otherwise complies with
- * the conditions stated in this License.
- *
- * 5. Submission of Contributions. Unless You explicitly state otherwise,
- * any Contribution intentionally submitted for inclusion in the Work
- * by You to the Licensor shall be under the terms and conditions of
- * this License, without any additional terms or conditions.
- * Notwithstanding the above, nothing herein shall supersede or modify
- * the terms of any separate license agreement you may have executed
- * with Licensor regarding such Contributions.
- *
- * 6. Trademarks. This License does not grant permission to use the trade
- * names, trademarks, service marks, or product names of the Licensor,
- * except as required for reasonable and customary use in describing the
- * origin of the Work and reproducing the content of the NOTICE file.
- *
- * 7. Disclaimer of Warranty. Unless required by applicable law or
- * agreed to in writing, Licensor provides the Work (and each
- * Contributor provides its Contributions) on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied, including, without limitation, any warranties or conditions
- * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- * PARTICULAR PURPOSE. You are solely responsible for determining the
- * appropriateness of using or redistributing the Work and assume any
- * risks associated with Your exercise of permissions under this License.
- *
- * 8. Limitation of Liability. In no event and under no legal theory,
- * whether in tort (including negligence), contract, or otherwise,
- * unless required by applicable law (such as deliberate and grossly
- * negligent acts) or agreed to in writing, shall any Contributor be
- * liable to You for damages, including any direct, indirect, special,
- * incidental, or consequential damages of any character arising as a
- * result of this License or out of the use or inability to use the
- * Work (including but not limited to damages for loss of goodwill,
- * work stoppage, computer failure or malfunction, or any and all
- * other commercial damages or losses), even if such Contributor
- * has been advised of the possibility of such damages.
- *
- * 9. Accepting Warranty or Additional Liability. While redistributing
- * the Work or Derivative Works thereof, You may choose to offer,
- * and charge a fee for, acceptance of support, warranty, indemnity,
- * or other liability obligations and/or rights consistent with this
- * License. However, in accepting such obligations, You may act only
- * on Your own behalf and on Your sole responsibility, not on behalf
- * of any other Contributor, and only if You agree to indemnify,
- * defend, and hold each Contributor harmless for any liability
- * incurred by, or claims asserted against, such Contributor by reason
- * of your accepting any such warranty or additional liability.
- *
- * END OF TERMS AND CONDITIONS
- *
- * APPENDIX: How to apply the Apache License to your work.
- *
- * To apply the Apache License to your work, attach the following
- * boilerplate notice, with the fields enclosed by brackets "[]"
- * replaced with your own identifying information. (Don't include
- * the brackets!) The text should be enclosed in the appropriate
- * comment syntax for the file format. We also recommend that a
- * file or class name and description of purpose be included on the
- * same "printed page" as the copyright notice for easier
- * identification within third-party archives.
- *
- * Copyright [yyyy] [name of copyright owner]
- *
- * Licensed 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.
- *
- */
-
/*
- * $Id: DnNormalizer.java,v 1.4 2003/09/18 21:19:48 akarasulu Exp $
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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
*
- * -- (c) LDAPd Group --
- * -- Please refer to the LICENSE.txt file in the root directory of --
- * -- any LDAPd project for copyright and distribution information. --
+ * 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.
*
- * Created on Aug 18, 2003
*/
+package org.apache.ldap.common.schema;
-package org.apache.ldap.server.schema.matching;
import java.io.IOException ;
@@ -222,25 +24,21 @@
import javax.naming.NamingException ;
import org.apache.ldap.common.name.DnParser ;
-import org.apache.ldap.server.schema.Schema ;
import org.apache.ldap.common.name.NameComponentNormalizer ;
-import org.apache.ldap.server.schema.attribute.AttributeType ;
+import org.apache.ldap.common.name.SimpleNameComponentNormalizer;
/**
* A distinguished name normalizer that works with a schema or without.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision: 1.4 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
*/
public class DnNormalizer implements Normalizer
{
/** name parser used by this normalizer */
- private NameParser m_parser = null ;
- /** the schema used if any */
- private final Schema m_schema ;
-
+ private NameParser parser = null ;
+
// ------------------------------------------------------------------------
// C O N S T R U C T O R S
@@ -248,183 +46,74 @@
/**
- * Creats a distinguished name normalizer that presumes caseIgnoreMatch
- * for all name component attribute while performing minimal normalization.
- *
- * @throws NamingException if we fail to initialize the parser.
- * USE WITH CAUTION!
+ * Creates a Dn Normalizer which normalizes distinguished names by
+ * performing a deep trim to lower case normalization on assertion values
+ * regardless of the attributeType of the name component.
*/
- public DnNormalizer()
- throws NamingException
+ public DnNormalizer() throws NamingException
{
- m_schema = null ;
-
- try
- {
- m_parser = new DnParser( new SchemaLess() ) ;
- }
- catch ( IOException ioe )
- {
- NamingException l_ne = new NamingException(
- "Problem creating DnNormalizer's NameParser" ) ;
- l_ne.setRootCause( ioe ) ;
- throw l_ne ;
- }
+ this ( new SimpleNameComponentNormalizer(
+ new DeepTrimToLowerNormalizer() ) ) ;
}
/**
- * Creats a distinguished name normalizer that presumes caseIgnoreMatch
- * for all name component attribute while performing space normalization.
+ * Creates a Dn Normalizer which normalizes distinguished names by
+ * using the same Normalizer to to normalize assertion values regardless
+ * of the attributeType of the name component.
*
- * @param a_parser a distinguished name parser
- * @throws NamingException if we fail to initialize the parser.
- * USE WITH CAUTION!
+ * @param normalizer Normalizer to use for values regardless of
attributeType
*/
- public DnNormalizer( NameParser a_parser )
- throws NamingException
+ public DnNormalizer( Normalizer normalizer ) throws NamingException
{
- m_schema = null ;
- m_parser = a_parser ;
+ this ( new SimpleNameComponentNormalizer( normalizer ) ) ;
}
/**
- * Creates a distinguished name normalizer that uses a Schema to determine
- * name component attribute matching rules when normalizing.
+ * Creates a Dn Normalizer which uses a name component normalizer to
+ * dynamically normalize all name component assertion values based on
+ * attributeType.
*
- * @param a_schema the schema to use while normalizing
- * @throws NamingException if we fail to initialize the parser.
+ * @param normalizer the name component normalizer to use
*/
- public DnNormalizer( Schema a_schema )
+ public DnNormalizer( NameComponentNormalizer normalizer )
throws NamingException
{
- m_schema = a_schema ;
-
try
{
- m_parser = new DnParser( new SchemaFull() ) ;
+ parser = new DnParser( normalizer ) ;
}
catch ( IOException ioe )
{
- NamingException l_ne = new NamingException(
+ NamingException ne = new NamingException(
"Problem creating DnNormalizer's NameParser" ) ;
- l_ne.setRootCause( ioe ) ;
- throw l_ne ;
+ ne.setRootCause( ioe ) ;
+ throw ne ;
}
}
/**
- * Gets the Dn parser used by this DnNormalizer.
- *
- * @return the Dn parser
- */
- public NameParser getNameParser()
- {
- return m_parser ;
- }
-
-
- /**
- * Gets the OID String 2.5.13.1 every time for distinguishedNameMatch.
- *
- * @see org.apache.ldap.server.schema.Normalizer#getEqualityMatch()
- */
- public String getMatchingRule()
- {
- return "2.5.13.1" ;
- }
-
-
- /**
* Normalizes the value if it is a Name or a String returning the String
* representation always. If the value is not a String or a Name the
object
* is returned as is.
*
- * @see
org.apache.ldap.server.schema.Normalizer#normalize(java.lang.Object)
+ * @see
org.apache.ldap.common.schema.Normalizer#normalize(java.lang.Object)
*/
- public Object normalize( Object a_value ) throws NamingException
+ public Object normalize( Object value ) throws NamingException
{
- String l_str = null ;
+ String str = null ;
- if ( a_value instanceof Name )
+ if ( value instanceof Name )
{
- l_str = a_value.toString() ;
+ str = value.toString() ;
}
- else if ( a_value instanceof String )
- {
- l_str = ( String ) a_value ;
- }
-
- return m_parser.parse( l_str ).toString() ;
- }
-
-
- /**
- * A name component normalizer that uses a schema to normalize names.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision: 1.4 $
- */
- class SchemaFull extends Object implements NameComponentNormalizer
- {
- /**
- * @see
org.apache.ldap.common.name.NameComponentNormalizer#normalizeByName(
- * java.lang.String, java.lang.String)
- */
- public String normalizeByName( String a_attributeName, String a_value )
- throws NamingException
+ else if ( value instanceof String )
{
- AttributeType l_spec =
- m_schema.getAttributeSpec( a_attributeName, true ) ;
- return ( String ) l_spec.getNormalizer().normalize( a_value ) ;
+ str = ( String ) value ;
}
-
- /**
- * @see
org.apache.ldap.common.name.NameComponentNormalizer#normalizeByOid(
- * java.lang.String, java.lang.String)
- */
- public String normalizeByOid( String a_attributeOid, String a_value )
- throws NamingException
- {
- AttributeType l_spec =
- m_schema.getAttributeSpec( a_attributeOid, false ) ;
- return ( String ) l_spec.getNormalizer().normalize( a_value ) ;
- }
- }
-
-
- /**
- * A NameComponentNormalizer that treats each attribute of a name component
- * as using the caseIgnoreMatch matching rule in which case it normalizes
- * the value by lowercasing it. USE WITH CAUTION!
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision: 1.4 $
- */
- class SchemaLess extends Object implements NameComponentNormalizer
- {
- /**
- * @see
org.apache.ldap.common.name.NameComponentNormalizer#normalizeByName(
- * java.lang.String, java.lang.String)
- */
- public String normalizeByName( String a_attributeName, String a_value )
- {
- return a_value.toLowerCase() ;
- }
-
-
- /**
- * @see
org.apache.ldap.common.name.NameComponentNormalizer#normalizeByOid(
- * java.lang.String, java.lang.String)
- */
- public String normalizeByOid( String a_attributeOid, String a_value )
- {
- return a_value.toLowerCase() ;
- }
+ return parser.parse( str ).toString() ;
}
}
Copied:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnSyntaxChecker.java
(from rev 55174,
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnSyntaxChecker.java)
==============================================================================
---
incubator/directory/eve/trunk/backend/sandbox/schema-api/src/java/org/apache/ldap/server/schema/matching/DnSyntaxChecker.java
(original)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/DnSyntaxChecker.java
Thu Oct 21 14:23:32 2004
@@ -1,218 +1,20 @@
-/*
- * Apache License
- * Version 2.0, January 2004
- * http://www.apache.org/licenses/
- *
- * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- *
- * 1. Definitions.
- *
- * "License" shall mean the terms and conditions for use, reproduction,
- * and distribution as defined by Sections 1 through 9 of this document.
- *
- * "Licensor" shall mean the copyright owner or entity authorized by
- * the copyright owner that is granting the License.
- *
- * "Legal Entity" shall mean the union of the acting entity and all
- * other entities that control, are controlled by, or are under common
- * control with that entity. For the purposes of this definition,
- * "control" means (i) the power, direct or indirect, to cause the
- * direction or management of such entity, whether by contract or
- * otherwise, or (ii) ownership of fifty percent (50%) or more of the
- * outstanding shares, or (iii) beneficial ownership of such entity.
- *
- * "You" (or "Your") shall mean an individual or Legal Entity
- * exercising permissions granted by this License.
- *
- * "Source" form shall mean the preferred form for making modifications,
- * including but not limited to software source code, documentation
- * source, and configuration files.
- *
- * "Object" form shall mean any form resulting from mechanical
- * transformation or translation of a Source form, including but
- * not limited to compiled object code, generated documentation,
- * and conversions to other media types.
- *
- * "Work" shall mean the work of authorship, whether in Source or
- * Object form, made available under the License, as indicated by a
- * copyright notice that is included in or attached to the work
- * (an example is provided in the Appendix below).
- *
- * "Derivative Works" shall mean any work, whether in Source or Object
- * form, that is based on (or derived from) the Work and for which the
- * editorial revisions, annotations, elaborations, or other modifications
- * represent, as a whole, an original work of authorship. For the purposes
- * of this License, Derivative Works shall not include works that remain
- * separable from, or merely link (or bind by name) to the interfaces of,
- * the Work and Derivative Works thereof.
- *
- * "Contribution" shall mean any work of authorship, including
- * the original version of the Work and any modifications or additions
- * to that Work or Derivative Works thereof, that is intentionally
- * submitted to Licensor for inclusion in the Work by the copyright owner
- * or by an individual or Legal Entity authorized to submit on behalf of
- * the copyright owner. For the purposes of this definition, "submitted"
- * means any form of electronic, verbal, or written communication sent
- * to the Licensor or its representatives, including but not limited to
- * communication on electronic mailing lists, source code control systems,
- * and issue tracking systems that are managed by, or on behalf of, the
- * Licensor for the purpose of discussing and improving the Work, but
- * excluding communication that is conspicuously marked or otherwise
- * designated in writing by the copyright owner as "Not a Contribution."
- *
- * "Contributor" shall mean Licensor and any individual or Legal Entity
- * on behalf of whom a Contribution has been received by Licensor and
- * subsequently incorporated within the Work.
- *
- * 2. Grant of Copyright License. Subject to the terms and conditions of
- * this License, each Contributor hereby grants to You a perpetual,
- * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- * copyright license to reproduce, prepare Derivative Works of,
- * publicly display, publicly perform, sublicense, and distribute the
- * Work and such Derivative Works in Source or Object form.
- *
- * 3. Grant of Patent License. Subject to the terms and conditions of
- * this License, each Contributor hereby grants to You a perpetual,
- * worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- * (except as stated in this section) patent license to make, have made,
- * use, offer to sell, sell, import, and otherwise transfer the Work,
- * where such license applies only to those patent claims licensable
- * by such Contributor that are necessarily infringed by their
- * Contribution(s) alone or by combination of their Contribution(s)
- * with the Work to which such Contribution(s) was submitted. If You
- * institute patent litigation against any entity (including a
- * cross-claim or counterclaim in a lawsuit) alleging that the Work
- * or a Contribution incorporated within the Work constitutes direct
- * or contributory patent infringement, then any patent licenses
- * granted to You under this License for that Work shall terminate
- * as of the date such litigation is filed.
- *
- * 4. Redistribution. You may reproduce and distribute copies of the
- * Work or Derivative Works thereof in any medium, with or without
- * modifications, and in Source or Object form, provided that You
- * meet the following conditions:
- *
- * (a) You must give any other recipients of the Work or
- * Derivative Works a copy of this License; and
- *
- * (b) You must cause any modified files to carry prominent notices
- * stating that You changed the files; and
- *
- * (c) You must retain, in the Source form of any Derivative Works
- * that You distribute, all copyright, patent, trademark, and
- * attribution notices from the Source form of the Work,
- * excluding those notices that do not pertain to any part of
- * the Derivative Works; and
- *
- * (d) If the Work includes a "NOTICE" text file as part of its
- * distribution, then any Derivative Works that You distribute must
- * include a readable copy of the attribution notices contained
- * within such NOTICE file, excluding those notices that do not
- * pertain to any part of the Derivative Works, in at least one
- * of the following places: within a NOTICE text file distributed
- * as part of the Derivative Works; within the Source form or
- * documentation, if provided along with the Derivative Works; or,
- * within a display generated by the Derivative Works, if and
- * wherever such third-party notices normally appear. The contents
- * of the NOTICE file are for informational purposes only and
- * do not modify the License. You may add Your own attribution
- * notices within Derivative Works that You distribute, alongside
- * or as an addendum to the NOTICE text from the Work, provided
- * that such additional attribution notices cannot be construed
- * as modifying the License.
- *
- * You may add Your own copyright statement to Your modifications and
- * may provide additional or different license terms and conditions
- * for use, reproduction, or distribution of Your modifications, or
- * for any such Derivative Works as a whole, provided Your use,
- * reproduction, and distribution of the Work otherwise complies with
- * the conditions stated in this License.
- *
- * 5. Submission of Contributions. Unless You explicitly state otherwise,
- * any Contribution intentionally submitted for inclusion in the Work
- * by You to the Licensor shall be under the terms and conditions of
- * this License, without any additional terms or conditions.
- * Notwithstanding the above, nothing herein shall supersede or modify
- * the terms of any separate license agreement you may have executed
- * with Licensor regarding such Contributions.
- *
- * 6. Trademarks. This License does not grant permission to use the trade
- * names, trademarks, service marks, or product names of the Licensor,
- * except as required for reasonable and customary use in describing the
- * origin of the Work and reproducing the content of the NOTICE file.
- *
- * 7. Disclaimer of Warranty. Unless required by applicable law or
- * agreed to in writing, Licensor provides the Work (and each
- * Contributor provides its Contributions) on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied, including, without limitation, any warranties or conditions
- * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- * PARTICULAR PURPOSE. You are solely responsible for determining the
- * appropriateness of using or redistributing the Work and assume any
- * risks associated with Your exercise of permissions under this License.
- *
- * 8. Limitation of Liability. In no event and under no legal theory,
- * whether in tort (including negligence), contract, or otherwise,
- * unless required by applicable law (such as deliberate and grossly
- * negligent acts) or agreed to in writing, shall any Contributor be
- * liable to You for damages, including any direct, indirect, special,
- * incidental, or consequential damages of any character arising as a
- * result of this License or out of the use or inability to use the
- * Work (including but not limited to damages for loss of goodwill,
- * work stoppage, computer failure or malfunction, or any and all
- * other commercial damages or losses), even if such Contributor
- * has been advised of the possibility of such damages.
- *
- * 9. Accepting Warranty or Additional Liability. While redistributing
- * the Work or Derivative Works thereof, You may choose to offer,
- * and charge a fee for, acceptance of support, warranty, indemnity,
- * or other liability obligations and/or rights consistent with this
- * License. However, in accepting such obligations, You may act only
- * on Your own behalf and on Your sole responsibility, not on behalf
- * of any other Contributor, and only if You agree to indemnify,
- * defend, and hold each Contributor harmless for any liability
- * incurred by, or claims asserted against, such Contributor by reason
- * of your accepting any such warranty or additional liability.
- *
- * END OF TERMS AND CONDITIONS
- *
- * APPENDIX: How to apply the Apache License to your work.
- *
- * To apply the Apache License to your work, attach the following
- * boilerplate notice, with the fields enclosed by brackets "[]"
- * replaced with your own identifying information. (Don't include
- * the brackets!) The text should be enclosed in the appropriate
- * comment syntax for the file format. We also recommend that a
- * file or class name and description of purpose be included on the
- * same "printed page" as the copyright notice for easier
- * identification within third-party archives.
- *
- * Copyright [yyyy] [name of copyright owner]
- *
- * Licensed 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.
- *
- */
-
/*
- * $Id: DnSyntaxChecker.java,v 1.2 2003/09/18 21:19:48 akarasulu Exp $
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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
*
- * -- (c) LDAPd Group --
- * -- Please refer to the LICENSE.txt file in the root directory of --
- * -- any LDAPd project for copyright and distribution information. --
+ * 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.
*
- * Created on Sep 15, 2003
*/
-package org.apache.ldap.server.schema.matching ;
+package org.apache.ldap.common.schema;
import java.io.IOException ;
@@ -222,22 +24,20 @@
import javax.naming.NamingException ;
import org.apache.ldap.common.name.DnParser ;
-import org.apache.ldap.server.schema.syntax.SyntaxChecker ;
/**
- * A distinguished name syntax checker based on a preconfigured DnParser.
+ * A distinguished name syntax checker.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision: 1.2 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
*/
public class DnSyntaxChecker implements SyntaxChecker
{
/** The oid of the checked syntax */
- private final String m_oid ;
+ private final String oid ;
/** The parser used to parse the DN */
- private NameParser m_parser ;
+ private NameParser parser ;
// ------------------------------------------------------------------------
@@ -249,15 +49,22 @@
* Creates a SyntaxChecker for a DN based Syntax that uses a distinguished
* name parser.
*
- * @param a_oid the OID of the syntax
+ * @param oid the OID of the syntax
*/
- public DnSyntaxChecker( String a_oid )
+ public DnSyntaxChecker( String oid )
{
- m_oid = a_oid ;
-
+ this.oid = oid ;
+
+ /*
+ * One may ask: why are we not taking the same measures here to
+ * introduce a name component normalizer? The answer to this is
+ * well we don't care what the value of an attribute assertion is
+ * we only care that the DN containing it is properly formed.
+ */
+
try
{
- m_parser = new DnParser() ;
+ parser = new DnParser() ;
}
catch ( IOException e )
{
@@ -265,51 +72,36 @@
e.printStackTrace() ;
}
}
-
-
- /**
- * Creates a SyntaxChecker for a DN based Syntax with a specialized name
- * parser.
- *
- * @param a_oid the object identifier for the Syntax checked for
- * @param a_parser the parser performing the Syntax validation
- */
- public DnSyntaxChecker( String a_oid, NameParser a_parser )
- {
- m_oid = a_oid ;
- m_parser = a_parser ;
- }
-
-
+
+
// ------------------------------------------------------------------------
// SyntaxChecker Methods
// ------------------------------------------------------------------------
-
-
+
+
/**
- * @see org.apache.ldap.server.schema.SyntaxChecker#getSyntaxOid()
+ * @see org.apache.ldap.common.schema.SyntaxChecker#getSyntaxOid()
*/
public String getSyntaxOid()
{
- return m_oid ;
+ return oid ;
}
/**
- * @see org.apache.ldap.server.schema.SyntaxChecker#isValidSyntax(
- * java.lang.Object)
+ * @see org.apache.ldap.common.schema.SyntaxChecker#isValidSyntax(Object)
*/
- public boolean isValidSyntax( Object a_value )
+ public boolean isValidSyntax( Object value )
{
- if ( a_value instanceof Name )
+ if ( value instanceof Name )
{
return true ;
}
- else if ( a_value instanceof String )
+ else if ( value instanceof String )
{
try
{
- m_parser.parse( ( String ) a_value ) ;
+ parser.parse( ( String ) value ) ;
}
catch ( Exception e )
{
@@ -324,21 +116,20 @@
/**
- * @see org.apache.ldap.server.schema.SyntaxChecker#assertSyntax(
- * java.lang.Object)
+ * @see org.apache.ldap.common.schema.SyntaxChecker#assertSyntax(Object)
*/
- public void assertSyntax( Object a_value ) throws NamingException
+ public void assertSyntax( Object value ) throws NamingException
{
- if ( a_value instanceof Name )
+ if ( value instanceof Name )
{
return ;
}
- else if ( a_value instanceof String )
+ else if ( value instanceof String )
{
- m_parser.parse( ( String ) a_value ) ;
+ parser.parse( ( String ) value ) ;
}
throw new NamingException( "Do not know how syntax check instances of
"
- + a_value.getClass() ) ;
+ + value.getClass() ) ;
}
}
Modified:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/StringTools.java
==============================================================================
---
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/StringTools.java
(original)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/StringTools.java
Thu Oct 21 14:23:32 2004
@@ -268,60 +268,60 @@
/**
* Put common code to deepTrim(String) and deepTrimToLower here.
*
- * @param a_string the string to deep trim
- * @param a_toLowerCase how to normalize for case: upper or lower
+ * @param str the string to deep trim
+ * @param toLowerCase how to normalize for case: upper or lower
* @return the deep trimmed string
* @see StringTools#deepTrim( String )
*/
- public static String deepTrim( String a_string, boolean a_toLowerCase )
+ public static String deepTrim( String str, boolean toLowerCase )
{
- if ( null == a_string )
+ if ( null == str )
{
return null ;
}
char ch ;
- StringBuffer l_buf = new StringBuffer() ;
+ StringBuffer buf = new StringBuffer() ;
- for ( int ii = 0; ii < a_string.length(); ii++ )
+ for ( int ii = 0; ii < str.length(); ii++ )
{
- ch = a_string.charAt( ii ) ;
+ ch = str.charAt( ii ) ;
// filter out all uppercase characters
- if ( Character.isUpperCase( ( char ) ch ) && a_toLowerCase )
+ if ( Character.isUpperCase( ( char ) ch ) && toLowerCase )
{
ch = Character.toLowerCase( ( char ) ch ) ;
}
// Check to see if we should add space
- if ( ch == ' ' )
+ if ( Character.isWhitespace( ch ) )
{
// If the buffer has had characters added already check last
// added character. Only append a spc if last character was
// not whitespace.
- if ( l_buf.length() - 1 >= 0 )
+ if ( buf.length() - 1 >= 0 )
{
- int l_lastChar = l_buf.charAt( l_buf.length() - 1 ) ;
- if ( l_lastChar != ' ' )
+ char lastChar = buf.charAt( buf.length() - 1 ) ;
+ if ( lastChar != ' ' )
{
- l_buf.append( ' ' ) ;
+ buf.append( ' ' ) ;
}
}
}
else
{
// Add all non-whitespace
- l_buf.append( ch ) ;
+ buf.append( ch ) ;
}
}
- int ii = l_buf.length() - 1 ;
- if ( ii >= 0 && ' ' == l_buf.charAt( ii ) )
+ int ii = buf.length() - 1 ;
+ if ( ii >= 0 && Character.isWhitespace( buf.charAt( ii ) ) )
{
- l_buf.deleteCharAt( ii ) ;
+ buf.deleteCharAt( ii ) ;
}
- return l_buf.toString() ;
+ return buf.toString() ;
}