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/05/24 07:23:01 UTC
svn commit: r178078 - in /directory/shared/ldap/trunk/common/src: antlr/
java/org/apache/ldap/common/subtree/ test/org/apache/ldap/common/subtree/
Author: akarasulu
Date: Mon May 23 22:23:00 2005
New Revision: 178078
URL: http://svn.apache.org/viewcvs?rev=178078&view=rev
Log:
got more of the grammar in not much ... fixed somethign that was way wacked.
Modified:
directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.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=178078&r1=178077&r2=178078&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g (original)
+++ directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g Mon May 23 22:23:00 2005
@@ -21,10 +21,11 @@
* will be a bug that comes into the foreground in the new antlr release.
*/
package org.apache.ldap.common.subtree;
-}
+import org.apache.ldap.common.name.LdapName;
+}
// ----------------------------------------------------------------------------
@@ -41,16 +42,6 @@
// ----------------------------------------------------------------------------
-// parser class members
-// ----------------------------------------------------------------------------
-
-{
- /** blah */
- public static final String BLAH = "blah";
-}
-
-
-// ----------------------------------------------------------------------------
// parser productions
// ----------------------------------------------------------------------------
@@ -58,9 +49,22 @@
subtreeSpecification returns [SubtreeSpecification spec]
{
spec = null;
-}
- : LBRACKET RBRACKET { spec = new BaseSubtreeSpecification(); } ;
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+}
+ :
+ LBRACKET
+ (
+ BASE rdn:LOCALNAME
+ {
+ String quoted = rdn.getText();
+
+ modifier.setBase( quoted.substring( 1, quoted.length() - 1 ) );
+ }
+ )?
+ ( SP )*
+ RBRACKET
+ { spec = modifier.getSubtreeSpecification(); };
// ----------------------------------------------------------------------------
@@ -103,14 +107,14 @@
// ----------------------------------------------------------------------------
-SP : ( ' ' )
- {$setType(Token.SKIP);} //ignore this token
- ;
+SP: ' ';
-LBRACKET: '{';
+LBRACKET: '{' ( SP )*;
RBRACKET: '}';
+DQUOTE: '"';
+
COMMA: ',';
OR: "or:";
@@ -121,6 +125,8 @@
ITEM: "item:";
+BASE: "base" ( SP )+ ;
+
protected DIGIT: '0' | LDIGIT;
protected LDIGIT: '1'..'9';
@@ -133,6 +139,23 @@
protected DESCR: ALPHA ( ALPHA | DIGIT | '-' )*;
+// this is all messed up - could not figure out how to get antlr to represent
+// the safe UTF-8 character set from RFC 3642 for production SafeUTF8Character
+
+protected SAFEUTF8CHAR:
+ '\u0001' .. '\u0021' |
+ '\u0023' .. '\u007F' |
+ '\u00c0'..'\u00d6' |
+ '\u00d8'..'\u00f6' |
+ '\u00f8'..'\u00ff' |
+ '\u0100'..'\u1fff' |
+ '\u3040'..'\u318f' |
+ '\u3300'..'\u337f' |
+ '\u3400'..'\u3d2d' |
+ '\u4e00'..'\u9fff' |
+ '\uf900'..'\ufaff' ;
+
OID: DESCR | NUMERICOID;
+LOCALNAME: DQUOTE ( SAFEUTF8CHAR )* DQUOTE ;
Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java?rev=178078&r1=178077&r2=178078&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java (original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java Mon May 23 22:23:00 2005
@@ -17,11 +17,8 @@
package org.apache.ldap.common.subtree;
-import org.apache.ldap.common.name.LdapName;
import org.apache.ldap.common.filter.ExprNode;
-import javax.naming.Name;
-
import java.util.Set;
import java.util.Collections;
@@ -34,8 +31,11 @@
*/
public class BaseSubtreeSpecification implements SubtreeSpecification
{
+ /** the empty string */
+ private final static String EMPTY = "";
+
/** the subtree base relative to the administration point */
- private final Name base;
+ private final String base;
/** the set of subordinates entries and their subordinates to exclude */
private final Set chopBefore;
@@ -65,7 +65,7 @@
*/
public BaseSubtreeSpecification()
{
- this.base = new LdapName();
+ this.base = "";
this.minBaseDistance = 0;
@@ -89,7 +89,7 @@
*/
public BaseSubtreeSpecification( ExprNode refinement )
{
- this.base = new LdapName();
+ this.base = EMPTY;
this.minBaseDistance = 0;
@@ -110,7 +110,7 @@
*
* @param base the base of the subtree relative to the administrative point
*/
- public BaseSubtreeSpecification( Name base )
+ public BaseSubtreeSpecification( String base )
{
this.base = base;
@@ -136,8 +136,8 @@
* @param chopAfter the set of subordinates entries whose subordinates are to be excluded
* @param chopBefore the set of subordinates entries and their subordinates to exclude
*/
- public BaseSubtreeSpecification( Name base, int minBaseDistance, int maxBaseDistance,
- Set chopAfter, Set chopBefore )
+ public BaseSubtreeSpecification( String base, int minBaseDistance, int maxBaseDistance,
+ Set chopAfter, Set chopBefore )
{
this( base, minBaseDistance, maxBaseDistance, chopAfter, chopBefore, null );
}
@@ -146,7 +146,7 @@
/**
* Creates a subtree which may be a refinement filter where all aspects of the
* specification can be set. If the refinement filter is null this defaults to
- * {@link BaseSubtreeSpecification#BaseSubstreeSpecification(Name, int, int, Set, Set)}.
+ * {@link BaseSubtreeSpecification#BaseSubtreeSpecification(String, int, int, Set, Set)}.
*
* @param base the base of the subtree relative to the administrative point
* @param minBaseDistance the minimum distance below base to start including entries
@@ -156,8 +156,8 @@
* @param refinement the filter expression only composed of objectClass attribute
* value assertions
*/
- public BaseSubtreeSpecification( Name base, int minBaseDistance, int maxBaseDistance,
- Set chopAfter, Set chopBefore, ExprNode refinement )
+ public BaseSubtreeSpecification( String base, int minBaseDistance, int maxBaseDistance,
+ Set chopAfter, Set chopBefore, ExprNode refinement )
{
this.base = base;
@@ -185,7 +185,7 @@
// -----------------------------------------------------------------------
- public Name getBase()
+ public String getBase()
{
return this.base;
}
Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java?rev=178078&r1=178077&r2=178078&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java (original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecification.java Mon May 23 22:23:00 2005
@@ -19,7 +19,6 @@
import org.apache.ldap.common.filter.ExprNode;
-import javax.naming.Name;
import java.util.Set;
@@ -46,7 +45,7 @@
* @return the RDN representing the base of the subtree, or the empty string
* name if the base is the administrative point
*/
- Name getBase();
+ String getBase();
/**
* A set of RDNs relative to the base entry representing chopBefore
@@ -54,7 +53,7 @@
* chopBefore form is used then the specified entry and its subordinates
* are excluded from the subtree or subtree refinement."
*
- * @return a set of Names relative to the subtree base or the empty set
+ * @return a set of relative names to the subtree base or the empty set
*/
Set getChopBeforeExclusions();
@@ -64,7 +63,7 @@
* chopAfter form is used then only the subordinates of the specified
* entry are excluded from the subtree or subtree refinement."
*
- * @return a set of Names relative to the subtree base or the empty set
+ * @return a set of relative names to the subtree base or the empty set
*/
Set getChopAfterExclusions();
Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java?rev=178078&r1=178077&r2=178078&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java (original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java Mon May 23 22:23:00 2005
@@ -18,9 +18,6 @@
import org.apache.ldap.common.filter.ExprNode;
-import org.apache.ldap.common.name.LdapName;
-
-import javax.naming.Name;
import java.util.Set;
import java.util.Collections;
@@ -35,8 +32,11 @@
*/
public class SubtreeSpecificationModifier
{
+ /** the empty string */
+ private final static String EMPTY = "";
+
/** the subtree base relative to the administration point */
- private Name base = new LdapName();
+ private String base = EMPTY;
/** the set of subordinates entries and their subordinates to exclude */
private Set chopBefore = Collections.EMPTY_SET;
@@ -84,7 +84,7 @@
*
* @param base subtree base relative to the administration point
*/
- public void setBase( Name base )
+ public void setBase( String base )
{
this.base = base;
}
Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java?rev=178078&r1=178077&r2=178078&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java (original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeParserTest.java Mon May 23 22:23:00 2005
@@ -26,20 +26,35 @@
/**
- * Document this class.
+ * Tests the SubtreeSpecification parser.
*
* @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
public class SubtreeParserTest extends TestCase
{
- /** A valid empty specification test case */
- private static final String EMPTY_SPEC = "{ }";
+ /** A valid empty specification with white space */
+ private static final String EMPTY_SPEC_SP = "{ } ";
+ /** A valid empty specification */
+ private static final String EMPTY_SPEC = "{}";
- public void testEmptySpecTest() throws TokenStreamException, RecognitionException
+ /** A valid specification only with a base set */
+ private static final String SPEC_BASE = "{ base \"ou=system\" }";
+
+
+ /**
+ * Parses a subtreeSpecification attribute value using the antlr generated
+ * lexers and parsers.
+ *
+ * @param value the subtree specification value
+ * @return a SubtreeSpecification instance object representing the spec string
+ * @throws TokenStreamException if we encounter invalid tokens
+ * @throws RecognitionException if we cannot recognize a token
+ */
+ private SubtreeSpecification parse( String value ) throws TokenStreamException, RecognitionException
{
- StringReader in = new StringReader( EMPTY_SPEC );
+ StringReader in = new StringReader( value );
AntlrSubtreeSpecificationLexer lexer = new AntlrSubtreeSpecificationLexer( in );
@@ -48,5 +63,77 @@
SubtreeSpecification spec = parser.subtreeSpecification();
assertNotNull( spec );
+
+ return spec;
+ }
+
+
+ /**
+ * Tests to see if an empty yet legal spec can be parsed without any
+ * whitespace.
+ *
+ * @throws Exception if the parser fails
+ */
+ public void testEmptySpecTest() throws Exception
+ {
+ SubtreeSpecification spec = parse( EMPTY_SPEC );
+
+ assertEquals( "", spec.getBase().toString() );
+
+ assertTrue( spec.getChopAfterExclusions().isEmpty() );
+
+ assertTrue( spec.getChopBeforeExclusions().isEmpty() );
+
+ assertEquals( SubtreeSpecification.UNBOUNDED_MAX, spec.getMaxBaseDistance() );
+
+ assertEquals( 0, spec.getMinBaseDistance() );
+
+ assertNull( spec.getRefinement() );
+ }
+
+
+ /**
+ * Tests to see if an empty yet legal spec can be parsed with whitespace.
+ *
+ * @throws Exception if the parser fails
+ */
+ public void testEmptyWhitespaceSpecTest() throws Exception
+ {
+ SubtreeSpecification spec = parse( EMPTY_SPEC_SP );
+
+ assertEquals( "", spec.getBase() );
+
+ assertTrue( spec.getChopAfterExclusions().isEmpty() );
+
+ assertTrue( spec.getChopBeforeExclusions().isEmpty() );
+
+ assertEquals( SubtreeSpecification.UNBOUNDED_MAX, spec.getMaxBaseDistance() );
+
+ assertEquals( 0, spec.getMinBaseDistance() );
+
+ assertNull( spec.getRefinement() );
+ }
+
+
+ /**
+ * Tests to see if the base is set with a legal spec containing only the subtree base.
+ *
+ * @throws Exception if the parser fails
+ */
+ public void testBaseOnlySpecTest() throws Exception
+ {
+ SubtreeSpecification spec = parse( SPEC_BASE );
+
+ assertEquals( "ou=system", spec.getBase() );
+
+ assertTrue( spec.getChopAfterExclusions().isEmpty() );
+
+ assertTrue( spec.getChopBeforeExclusions().isEmpty() );
+
+ assertEquals( SubtreeSpecification.UNBOUNDED_MAX, spec.getMaxBaseDistance() );
+
+ assertEquals( 0, spec.getMinBaseDistance() );
+
+ assertNull( spec.getRefinement() );
}
}