Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 90652 invoked from network); 21 Aug 2005 16:54:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Aug 2005 16:54:22 -0000 Received: (qmail 95508 invoked by uid 500); 21 Aug 2005 16:54:22 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 95438 invoked by uid 500); 21 Aug 2005 16:54:21 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 95412 invoked by uid 99); 21 Aug 2005 16:54:21 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Aug 2005 09:54:21 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 21 Aug 2005 09:54:36 -0700 Received: (qmail 90432 invoked by uid 65534); 21 Aug 2005 16:54:16 -0000 Message-ID: <20050821165416.90431.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r234264 [11/11] - in /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src: ./ java/ java/main/ java/main/org/ java/main/org/apache/ java/main/org/apache/asn1new/ java/main/org/apache/asn1new/ldap/ java/main/org/apache/... Date: Sun, 21 Aug 2005 16:54:00 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/PresentFilter.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/PresentFilter.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/PresentFilter.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/PresentFilter.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,134 @@ +/* + * Copyright 2005 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.asn1new.ldap.pojo.filters; + +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; + +import org.apache.asn1new.EncoderException; +import org.apache.asn1new.ber.tlv.Length; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.primitives.LdapString; + + +/** + * Object to store the filter. A filter is seen as a tree with a root. + * + * @author Apache Directory Project + */ +public class PresentFilter extends Filter +{ + //~ Instance fields ---------------------------------------------------------------------------- + + /** The attribute description. */ + private LdapString attributeDescription; + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * The constructor. + */ + public PresentFilter() + { + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the attribute + * + * @return Returns the attributeDescription. + */ + public LdapString getAttributeDescription() + { + return attributeDescription; + } + + /** + * Set the attributeDescription + * + * @param attributeDescription The attributeDescription to set. + */ + public void setAttributeDescription( LdapString attributeDescription ) + { + this.attributeDescription = attributeDescription; + } + + /** + * Compute the PresentFilter length + * + * PresentFilter : + * + * 0x87 L1 present + * + * Length(PresentFilter) = Length(0x87) + Length(super.computeLength()) + super.computeLength() + * + */ + public int computeLength() + { + return 1 + Length.getNbBytes( attributeDescription.getLength() ) + attributeDescription.getLength(); + } + + /** + * Encode the PresentFilter message to a PDU. + * + * PresentFilter : + * + * 0x87 LL attributeDescription + * + * @param buffer The buffer where to put the PDU + * @return The PDU. + */ + public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException + { + if (buffer == null) + { + throw new EncoderException("Cannot put a PDU in a null buffer !"); + } + + try + { + // The PresentFilter Tag + buffer.put( (byte)LdapConstants.PRESENT_FILTER_TAG ); + buffer.put( Length.getBytes( attributeDescription.getLength() ) ); + buffer.put( attributeDescription.getData() ); + } + catch ( BufferOverflowException boe ) + { + throw new EncoderException("The PDU buffer size is too small !"); + } + + super.encode( buffer ); + + return buffer; + } + + /** + * Return a string compliant with RFC 2254 representing a Present filter + * + * @return The Present filter string + */ + public String toString() + { + + StringBuffer sb = new StringBuffer(); + + sb.append( attributeDescription.toString() ).append( "=*" ); + + return sb.toString(); + } +} Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/SubstringFilter.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/SubstringFilter.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/SubstringFilter.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/pojo/filters/SubstringFilter.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,344 @@ +/* + * Copyright 2005 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.asn1new.ldap.pojo.filters; + +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Iterator; + +import org.apache.asn1new.EncoderException; +import org.apache.asn1new.ber.tlv.Length; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.ber.tlv.Value; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.primitives.LdapString; + + +/** + * A Object that stores the substring filter. A substring filter follow this grammar : + * substring = attr "=" ([initial] any [final] | + * (initial [any] [final) | + * ([initial] [any] final) + * initial = value + * any = "*" *(value "*") + * final = value + * + * @author Apache Directory Project + */ +public class SubstringFilter extends Filter +{ + //~ Instance fields ---------------------------------------------------------------------------- + + /** The substring filter type (an attributeDescription) */ + private LdapString type; + + /** This member is used to control the length of the three parts of the substring filter **/ + private transient int substringsLength; + + /** The initial filter */ + private LdapString initialSubstrings; + + /** The any filter. It's a list of LdapString */ + private ArrayList anySubstrings; + + /** The final filter */ + private LdapString finalSubstrings; + + private transient int substringsFilterLength; + + private transient int substringsFilterSequenceLength; + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * The constructor. We will create the 'any' subsring arraylist with only one element. + */ + public SubstringFilter() + { + anySubstrings = new ArrayList(1); + } + + /** + * Get the internal substrings + * + * @return Returns the anySubstrings. + */ + public ArrayList getAnySubstrings() + { + return anySubstrings; + } + + /** + * Add a internal substring + * + * @param anySubstrings The anySubstrings to set. + */ + public void addAnySubstrings( LdapString anySubstrings ) + { + this.anySubstrings.add(anySubstrings); + } + + /** + * Get the final substring + * + * @return Returns the finalSubstrings. + */ + public LdapString getFinalSubstrings() + { + return finalSubstrings; + } + + /** + * Set the final substring + * + * @param finalSubstrings The finalSubstrings to set. + */ + public void setFinalSubstrings( LdapString finalSubstrings ) + { + this.finalSubstrings = finalSubstrings; + } + + /** + * Get the initial substring + * + * @return Returns the initialSubstrings. + */ + public LdapString getInitialSubstrings() + { + return initialSubstrings; + } + + /** + * Set the initial substring + * + * @param initialSubstrings The initialSubstrings to set. + */ + public void setInitialSubstrings( LdapString initialSubstrings ) + { + this.initialSubstrings = initialSubstrings; + } + + /** + * Get the attribute + * + * @return Returns the type. + */ + public LdapString getType() + { + return type; + } + + /** + * Set the attribute to match + * + * @param type The type to set. + */ + public void setType( LdapString type ) + { + this.type = type; + } + + /** + * @return Returns the substringsLength. + */ + public int getSubstringsLength() + { + return substringsLength; + } + + /** + * @param substringsLength The substringsLength to set. + */ + public void setSubstringsLength(int substringsLength) + { + this.substringsLength = substringsLength; + } + + /** + * Compute the SubstringFilter length + * + * SubstringFilter : + * + * 0xA4 L1 + * | + * +--> 0x04 L2 type + * +--> 0x30 L3 + * | + * [+--> 0x80 L4 initial] + * [+--> 0x81 L5-1 any] + * [+--> 0x81 L5-2 any] + * [+--> ... + * [+--> 0x81 L5-i any] + * [+--> ... + * [+--> 0x81 L5-n any] + * [+--> 0x82 L6 final] + * + */ + public int computeLength() + { + // The type + substringsFilterLength = 1 + Length.getNbBytes( type.getLength() ) + type.getLength(); + substringsFilterSequenceLength = 0; + + if ( initialSubstrings != null ) + { + substringsFilterSequenceLength += 1 + Length.getNbBytes( initialSubstrings.getLength() ) + initialSubstrings.getLength(); + } + + if ( anySubstrings != null) + { + Iterator anyIterator = anySubstrings.iterator(); + + while ( anyIterator.hasNext() ) + { + LdapString any = (LdapString)anyIterator.next(); + substringsFilterSequenceLength += 1 + Length.getNbBytes( any.getLength() ) + any.getLength(); + } + } + + if ( finalSubstrings != null ) + { + substringsFilterSequenceLength += 1 + Length.getNbBytes( finalSubstrings.getLength() ) + finalSubstrings.getLength(); + } + + substringsFilterLength += 1 + Length.getNbBytes( substringsFilterSequenceLength ) + substringsFilterSequenceLength; + + return 1 + Length.getNbBytes( substringsFilterLength ) + substringsFilterLength; + } + + /** + * Encode the Substrings Filter to a PDU. + * + * Substrings Filter : + * + * 0xA4 LL + * 0x30 LL substringsFilter + * 0x04 LL type + * 0x30 LL substrings sequence + * | 0x80 LL initial + * | / [0x81 LL any]* + * |/ [0x82 LL final] + * +--[0x81 LL any]+ + * \ [0x82 LL final] + * \ + * 0x82 LL final + * + * @param buffer The buffer where to put the PDU + * @return The PDU. + */ + public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException + { + if (buffer == null) + { + throw new EncoderException("Cannot put a PDU in a null buffer !"); + } + + try + { + // The SubstringFilter Tag + buffer.put( (byte)LdapConstants.SUBSTRINGS_FILTER_TAG ); + buffer.put( Length.getBytes( substringsFilterLength ) ); + + // The type + Value.encode( buffer, type ); + + // The SubstringSequenceFilter Tag + buffer.put( UniversalTag.SEQUENCE_TAG ); + buffer.put( Length.getBytes( substringsFilterSequenceLength ) ); + + + if ( ( initialSubstrings == null ) && + ( ( anySubstrings == null ) || ( anySubstrings.size() == 0 ) ) && + ( finalSubstrings == null ) ) + { + throw new EncoderException("Cannot have a null initial, any and final substring"); + } + + // The initial substring + if ( initialSubstrings != null ) + { + buffer.put( (byte)LdapConstants.SEARCH_SUBSTRINGS_INITIAL_TAG ); + buffer.put( Length.getBytes( initialSubstrings.getLength() ) ); + buffer.put( initialSubstrings.getData() ); + } + + // The any substrings + if ( anySubstrings != null) + { + Iterator anyIterator = anySubstrings.iterator(); + + while ( anyIterator.hasNext() ) + { + LdapString any = (LdapString)anyIterator.next(); + buffer.put( (byte)LdapConstants.SEARCH_SUBSTRINGS_ANY_TAG ); + buffer.put( Length.getBytes( any.getLength() ) ); + buffer.put( any.getData() ); + } + } + + // The final substring + if ( finalSubstrings != null ) + { + buffer.put( (byte)LdapConstants.SEARCH_SUBSTRINGS_FINAL_TAG ); + buffer.put( Length.getBytes( finalSubstrings.getLength() ) ); + buffer.put( finalSubstrings.getData() ); + } + } + catch ( BufferOverflowException boe ) + { + throw new EncoderException("The PDU buffer size is too small !"); + } + + return buffer; + } + + /** + * Return a string compliant with RFC 2254 representing a Substring filter + * + * @return The substring filter string + */ + public String toString() + { + + StringBuffer sb = new StringBuffer(); + + if (initialSubstrings != null) + { + sb.append( initialSubstrings.toString() ); + } + + sb.append('*'); + + if ( anySubstrings != null ) + { + Iterator anyIterator = anySubstrings.iterator(); + + while (anyIterator.hasNext()) + { + sb.append( (LdapString)anyIterator.next() ).append('*'); + } + } + + if (finalSubstrings != null) + { + sb.append( finalSubstrings.toString() ); + } + + return sb.toString(); + } +}