Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 77555 invoked from network); 7 Apr 2011 12:46:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Apr 2011 12:46:20 -0000 Received: (qmail 31882 invoked by uid 500); 7 Apr 2011 12:46:19 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 31820 invoked by uid 500); 7 Apr 2011 12:46:19 -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 31813 invoked by uid 99); 7 Apr 2011 12:46:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Apr 2011 12:46:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Apr 2011 12:46:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9748823889BB; Thu, 7 Apr 2011 12:45:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1089859 - in /directory/shared/trunk: ldap/model/src/main/java/org/apache/directory/shared/ldap/model/url/LdapUrl.java util/src/main/java/org/apache/directory/shared/util/Strings.java Date: Thu, 07 Apr 2011 12:45:57 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110407124557.9748823889BB@eris.apache.org> Author: elecharny Date: Thu Apr 7 12:45:57 2011 New Revision: 1089859 URL: http://svn.apache.org/viewvc?rev=1089859&view=rev Log: o Moved some utility classes from LdapUrl to Strings o Removed some unused methods o Some other refactorings Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/url/LdapUrl.java directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/url/LdapUrl.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/url/LdapUrl.java?rev=1089859&r1=1089858&r2=1089859&view=diff ============================================================================== --- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/url/LdapUrl.java (original) +++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/url/LdapUrl.java Thu Apr 7 12:45:57 2011 @@ -67,10 +67,6 @@ import org.apache.directory.shared.util. */ public class LdapUrl { - - // ~ Static fields/initializers - // ----------------------------------------------------------------- - /** The constant for "ldaps://" scheme. */ public static final String LDAPS_SCHEME = "ldaps://"; @@ -80,9 +76,6 @@ public class LdapUrl /** A null LdapUrl */ public static final LdapUrl EMPTY_URL = new LdapUrl(); - // ~ Instance fields - // ---------------------------------------------------------------------------- - /** The scheme */ private String scheme; @@ -134,11 +127,12 @@ public class LdapUrl /** - * Parse a LdapUrl + * Parse a LdapUrl. + * * @param chars The chars containing the URL * @throws org.apache.directory.shared.ldap.model.exception.LdapURLEncodingException If the URL is invalid */ - public void parse( char[] chars ) throws LdapURLEncodingException + private void parse( char[] chars ) throws LdapURLEncodingException { scheme = LDAP_SCHEME; host = null; @@ -159,7 +153,6 @@ public class LdapUrl // [dn ["?" [attributes] ["?" [scope] // ["?" [filter] ["?" extensions]]]]]] // scheme = "ldap" - int pos = 0; // The scheme @@ -318,31 +311,6 @@ public class LdapUrl /** - * Create a new LdapUrl after having parsed it. - * - * @param bytes The byte buffer that contains the LDAPURL - * @throws LdapURLEncodingException If the byte array does not comply with RFC 2255 - */ - public LdapUrl( byte[] bytes ) throws LdapURLEncodingException - { - if ( ( bytes == null ) || ( bytes.length == 0 ) ) - { - throw new LdapURLEncodingException( I18n.err( I18n.ERR_04410 ) ); - } - - string = Strings.utf8ToString(bytes); - - this.bytes = new byte[bytes.length]; - System.arraycopy( bytes, 0, this.bytes, 0, bytes.length ); - - parse( string.toCharArray() ); - } - - - // ~ Methods - // ------------------------------------------------------------------------------------ - - /** * Parse this rule :
*

* <host> ::= <hostname> ':' <hostnumber>
@@ -579,59 +547,8 @@ public class LdapUrl return pos; } - - - /** - * From commons-httpclients. Converts the byte array of HTTP content - * characters to a string. If the specified charset is not supported, - * default system encoding is used. - * - * @param data the byte array to be encoded - * @param offset the index of the first byte to encode - * @param length the number of bytes to encode - * @param charset the desired character encoding - * @return The result of the conversion. - * @since 3.0 - */ - public static String getString( final byte[] data, int offset, int length, String charset ) - { - if ( data == null ) - { - throw new IllegalArgumentException( I18n.err( I18n.ERR_04411 ) ); - } - - if ( ( charset == null ) || ( charset.length() == 0 ) ) - { - throw new IllegalArgumentException( I18n.err( I18n.ERR_04412 ) ); - } - - try - { - return new String( data, offset, length, charset ); - } - catch ( UnsupportedEncodingException e ) - { - return new String( data, offset, length ); - } - } - - - /** - * From commons-httpclients. Converts the byte array of HTTP content - * characters to a string. If the specified charset is not supported, - * default system encoding is used. - * - * @param data the byte array to be encoded - * @param charset the desired character encoding - * @return The result of the conversion. - * @since 3.0 - */ - public static String getString( final byte[] data, String charset ) - { - return getString( data, 0, data.length, charset ); - } - - + + /** * Converts the specified string to byte array of ASCII characters. * @@ -639,7 +556,7 @@ public class LdapUrl * @return The string as a byte array. * @throws org.apache.directory.shared.ldap.model.exception.UrlDecoderException if encoding is not supported */ - public static byte[] getAsciiBytes( final String data ) throws UrlDecoderException + private static byte[] getAsciiBytes( final String data ) throws UrlDecoderException { if ( data == null ) @@ -722,7 +639,7 @@ public class LdapUrl try { byte[] rawdata = decodeUrl( getAsciiBytes( escaped ) ); - return getString( rawdata, "UTF-8" ); + return Strings.getString( rawdata, "UTF-8" ); } catch ( UrlDecoderException e ) { @@ -1365,7 +1282,6 @@ public class LdapUrl sb.append( scope.getLdapUrlValue() ); } - else { if ( ( scope != SearchScope.OBJECT ) || ( filter != null ) || ( extensionList.size() != 0 ) ) @@ -1776,18 +1692,6 @@ public class LdapUrl /** - * If set to true forces the toString method to render the scope - * regardless of optional nature. Use this when you want explicit - * search URL scope rendering. - * - * @return the forceScopeRendering - */ - public boolean isForceScopeRendering() - { - return forceScopeRendering; - } - - /** * An inner bean to hold extension information. * * @author Apache Directory Project @@ -1880,5 +1784,4 @@ public class LdapUrl this.value = value; } } - } Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java?rev=1089859&r1=1089858&r2=1089859&view=diff ============================================================================== --- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java (original) +++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java Thu Apr 7 12:45:57 2011 @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.directory.shared.i18n.I18n; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -1988,14 +1989,65 @@ public final class Strings */ public static byte[] copy( byte[] value ) { - if ( isEmpty( value ) ) - { - return StringConstants.EMPTY_BYTES; - } + if ( isEmpty( value ) ) + { + return StringConstants.EMPTY_BYTES; + } + + byte[] copy = new byte[value.length]; + System.arraycopy( value, 0, copy, 0, value.length ); + + return copy; + } + + + /** + * From commons-httpclients. Converts the byte array of HTTP content + * characters to a string. If the specified charset is not supported, + * default system encoding is used. + * + * @param data the byte array to be encoded + * @param offset the index of the first byte to encode + * @param length the number of bytes to encode + * @param charset the desired character encoding + * @return The result of the conversion. + * @since 3.0 + */ + public static String getString( final byte[] data, int offset, int length, String charset ) + { + if ( data == null ) + { + throw new IllegalArgumentException( I18n.err( I18n.ERR_04411 ) ); + } + + if ( ( charset == null ) || ( charset.length() == 0 ) ) + { + throw new IllegalArgumentException( I18n.err( I18n.ERR_04412 ) ); + } + + try + { + return new String( data, offset, length, charset ); + } + catch ( UnsupportedEncodingException e ) + { + return new String( data, offset, length ); + } + } - byte[] copy = new byte[value.length]; - System.arraycopy( value, 0, copy, 0, value.length ); - return copy; + /** + * From commons-httpclients. Converts the byte array of HTTP content + * characters to a string. If the specified charset is not supported, + * default system encoding is used. + * + * @param data the byte array to be encoded + * @param charset the desired character encoding + * @return The result of the conversion. + * @since 3.0 + */ + public static String getString( final byte[] data, String charset ) + { + return getString( data, 0, data.length, charset ); } }