You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/09/01 06:02:11 UTC
svn commit: r265643 - in /directory/shared/ldap/trunk/common/src:
antlr/subtree-specification.g
java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
Author: akarasulu
Date: Wed Aug 31 21:02:05 2005
New Revision: 265643
URL: http://svn.apache.org/viewcvs?rev=265643&view=rev
Log:
Commiting patch from Ersin Er on DIRLDAP-50 here:
http://issues.apache.org/jira/browse/DIRLDAP-50
Modified:
directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
Modified: directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g?rev=265643&r1=265642&r2=265643&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g (original)
+++ directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g Wed Aug 31 21:02:05 2005
@@ -28,6 +28,7 @@
import javax.naming.NamingException;
import org.apache.ldap.common.name.DnParser;
+import org.apache.ldap.common.name.NameComponentNormalizer;
import org.apache.ldap.common.filter.ExprNode;
import org.apache.ldap.common.filter.LeafNode;
import org.apache.ldap.common.filter.SimpleNode;
@@ -73,7 +74,10 @@
{
private static final Logger log = LoggerFactory.getLogger( AntlrSubtreeSpecificationParser.class );
- private final DnParser dnParser = createDnParser();
+ private DnParser dnParser;
+
+ private boolean isNormalizing = false;
+ NameComponentNormalizer normalizer;
private Set chopBeforeExclusions = new HashSet();
private Set chopAfterExclusions = new HashSet();
@@ -81,15 +85,24 @@
SubtreeSpecificationModifier ssModifier = null;
/**
- * Creates a subordinate DnParser for parsing LocalNames.
+ * Creates a (normalizing) subordinate DnParser for parsing LocalNames.
+ * This method MUST be called for each instance while we cannot do
+ * constructor overloading for this class.
*
* @return the DnParser to be used for parsing LocalNames
*/
- private DnParser createDnParser()
+ public void init()
{
try
{
- return new DnParser();
+ if( isNormalizing )
+ {
+ dnParser = new DnParser( normalizer );
+ }
+ else
+ {
+ dnParser = new DnParser();
+ }
}
catch ( NamingException e )
{
@@ -100,6 +113,15 @@
throw new NullPointerException( "dnParser is null: " + msg );
}
+ }
+
+ /**
+ * Sets the NameComponentNormalizer for this parser's dnParser.
+ */
+ public void setNormalizer(NameComponentNormalizer normalizer)
+ {
+ this.normalizer = normalizer;
+ this.isNormalizing = true;
}
}
Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java?rev=265643&r1=265642&r2=265643&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java (original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java Wed Aug 31 21:02:05 2005
@@ -21,6 +21,8 @@
import java.io.StringReader;
import java.text.ParseException;
+import org.apache.ldap.common.name.NameComponentNormalizer;
+
import antlr.RecognitionException;
import antlr.TokenStreamException;
@@ -42,6 +44,7 @@
/** the antlr generated lexer being wrapped */
private ReusableAntlrSubtreeSpecificationLexer lexer;
+ private final boolean isNormalizing;
/**
* Creates a subtree specification parser.
@@ -51,6 +54,24 @@
StringReader in = new StringReader(""); // place holder for the first input
this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
+ this.parser.init(); // this method MUST be called while we cannot do
+ // constructor overloading for antlr generated parser
+ this.isNormalizing = false;
+ }
+
+ /**
+ * Creates a normalizing subtree specification parser.
+ */
+ public SubtreeSpecificationParser(NameComponentNormalizer normalizer)
+ {
+ StringReader in = new StringReader(""); // place holder for the first input
+ this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
+ this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
+
+ this.parser.setNormalizer( normalizer );
+ this.parser.init(); // this method MUST be called while we cannot do
+ // constructor overloading for antlr generated parser
+ this.isNormalizing = true;
}
@@ -105,5 +126,15 @@
}
return ss;
+ }
+
+ /**
+ * Tests to see if this parser is normalizing.
+ *
+ * @return true if it normalizes false otherwise
+ */
+ public boolean isNormizing()
+ {
+ return this.isNormalizing ;
}
}
Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java?rev=265643&r1=265642&r2=265643&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java (original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java Wed Aug 31 21:02:05 2005
@@ -30,6 +30,8 @@
import org.apache.ldap.common.filter.BranchNode;
import org.apache.ldap.common.filter.SimpleNode;
import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.name.SimpleNameComponentNormalizer;
+import org.apache.ldap.common.schema.DeepTrimNormalizer;
import org.apache.ldap.common.subtree.SubtreeSpecification;
@@ -104,6 +106,9 @@
private static final String INVALID_SILLY_THING =
"How much wood would a wood chuck chuck if a wood chuck would chuck wood?";
+ /** A valid specification only with base set and normalizing to be applied */
+ private static final String SPEC_WITH_BASE_NORMALIZING =
+ "{ base \"ou=system \" }";
/** the ss parser wrapper */
SubtreeSpecificationParser parser;
@@ -403,6 +408,22 @@
{
assertNotNull( e );
}
+ }
+
+ /**
+ * Tests the parser with a valid specification with base set and normalizing active.
+ */
+ public void testSpecWithBaseNormalizing() throws Exception
+ {
+ // create a new normalizing parser for this test case
+ SubtreeSpecificationParser parser = new SubtreeSpecificationParser(
+ new SimpleNameComponentNormalizer(
+ new DeepTrimNormalizer()));
+ SubtreeSpecification ss = parser.parse( SPEC_WITH_BASE_NORMALIZING );
+ assertNotNull( ss );
+
+ // looking for "ou=system" and not "ou=system " due to normalizing
+ assertEquals( "ou=system" , ss.getBase().toString() );
}