You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/04/22 17:17:38 UTC
svn commit: r531201 - in
/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils:
LdapFilterUtils.java LdifUtils.java ModelConverter.java
Author: seelmann
Date: Sun Apr 22 08:17:37 2007
New Revision: 531201
URL: http://svn.apache.org/viewvc?view=rev&rev=531201
Log:
Added some javadoc
Modified:
directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdapFilterUtils.java
directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java
directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/ModelConverter.java
Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdapFilterUtils.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdapFilterUtils.java?view=diff&rev=531201&r1=531200&r2=531201
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdapFilterUtils.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdapFilterUtils.java Sun Apr 22 08:17:37 2007
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.ldapstudio.browser.core.utils;
@@ -24,9 +24,22 @@
import org.apache.directory.ldapstudio.browser.core.model.IValue;
+/**
+ * Utilies for filter handling.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class LdapFilterUtils
{
+ /**
+ * Creates a filter from the given value.
+ *
+ * @param value the value
+ *
+ * @return the filter
+ */
public static String getFilter( IValue value )
{
if ( value.isString() )
@@ -45,11 +58,15 @@
{
int b = ( int ) bytes[i];
if ( b < 0 )
+ {
b = 256 + b;
+ }
String s = Integer.toHexString( b );
filter.append( "\\" );
if ( s.length() == 1 )
+ {
filter.append( "0" );
+ }
filter.append( s );
}
@@ -60,23 +77,26 @@
/**
- *
- * From RFC2254:
- *
+ * Encodes the given value according RFC2254.
+ *
* <pre>
- * If a value should contain any of the following characters
- * Character ASCII value
- * ---------------------------
- * * 0x2a
- * ( 0x28
- * ) 0x29
- * \ 0x5c
- * NUL 0x00
- * the character must be encoded as the backslash '\' character (ASCII
- * 0x5c) followed by the two hexadecimal digits representing the ASCII
- * value of the encoded character. The case of the two hexadecimal
- * digits is not significant.
+ * If a value should contain any of the following characters
+ * Character ASCII value
+ * ---------------------------
+ * * 0x2a
+ * ( 0x28
+ * ) 0x29
+ * \ 0x5c
+ * NUL 0x00
+ * the character must be encoded as the backslash '\' character (ASCII
+ * 0x5c) followed by the two hexadecimal digits representing the ASCII
+ * value of the encoded character. The case of the two hexadecimal
+ * digits is not significant.
* </pre>
+ *
+ * @param value the value
+ *
+ * @return the encoded value
*/
public static String getEncodedValue( String value )
{
Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java?view=diff&rev=531201&r1=531200&r2=531201
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/LdifUtils.java Sun Apr 22 08:17:37 2007
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.ldapstudio.browser.core.utils;
@@ -30,9 +30,23 @@
import org.apache.directory.ldapstudio.browser.core.model.IValue;
+/**
+ * Utilities for LDAP related encoding and decoding.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class LdifUtils
{
+
+ /**
+ * Encodes the given string to UTF-8
+ *
+ * @param s the string to encode
+ *
+ * @return the byte[] the encoded value
+ */
public static byte[] utf8encode( String s )
{
try
@@ -46,6 +60,13 @@
}
+ /**
+ * Encodes the given string into URL format.
+ *
+ * @param s the string to encode
+ *
+ * @return the string the URL encoded string
+ */
public static String urlEncode( String s )
{
try
@@ -59,12 +80,26 @@
}
+ /**
+ * Encodes the given byte array using BASE-64 encoding.
+ *
+ * @param b the b the byte array to encode
+ *
+ * @return the BASE-64 encoded string
+ */
public static String base64encode( byte[] b )
{
return utf8decode( Base64.encodeBase64( b ) );
}
+ /**
+ * Encodes the given byte array to a sequence of
+ * its hex values.
+ *
+ * @param data the data to encode
+ * @return the HEX encoded string
+ */
public static String hexEncode( byte[] data )
{
if ( data == null )
@@ -88,6 +123,13 @@
}
+ /**
+ * Decodes the given UTF-8 byte array to an string.
+ *
+ * @param b the b the byte array to decode
+ *
+ * @return the decoded string
+ */
public static String utf8decode( byte[] b )
{
try
@@ -101,21 +143,43 @@
}
+ /**
+ * Decodes the given BASE-64 encoded string to its
+ * bytes presentation.
+ *
+ * @param s the s the BASE-64 encoded string
+ *
+ * @return the byte[] the decoded byte array
+ */
public static byte[] base64decodeToByteArray( String s )
{
return Base64.decodeBase64( utf8encode( s ) );
}
+ /**
+ * Checks if the given distinguished name must be encoded.
+ *
+ * @param dn the dn to check
+ *
+ * @return true, if must encode DN
+ */
public static boolean mustEncodeDN( String dn )
{
return mustEncode( dn );
}
+ /**
+ * Checks if the given byte array must be encoded to be
+ * used in an LDIF.
+ *
+ * @param b the b the byte array to check
+ *
+ * @return true, if must encode
+ */
public static boolean mustEncode( byte[] b )
{
-
if ( b == null || b.length < 1 )
{
return false;
@@ -142,9 +206,16 @@
}
+ /**
+ * Checks if the given string must be encoded to be
+ * used in an LDIF.
+ *
+ * @param value the value to check
+ *
+ * @return true, if must encode
+ */
public static boolean mustEncode( String value )
{
-
if ( value == null || value.length() < 1 )
{
return false;
@@ -172,6 +243,16 @@
}
+ /**
+ * Gets the string value from the given {@link IValue}. If the given
+ * {@link IValue} is binary is is encoded according to the regquested
+ * encoding type.
+ *
+ * @param value the value
+ * @param binaryEncoding the binary encoding type
+ *
+ * @return the string value
+ */
public static String getStringValue( IValue value, int binaryEncoding )
{
String s;
@@ -190,7 +271,6 @@
{
s = BrowserCoreConstants.BINARY;
}
-
}
else
{
Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/ModelConverter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/ModelConverter.java?view=diff&rev=531201&r1=531200&r2=531201
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/ModelConverter.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/utils/ModelConverter.java Sun Apr 22 08:17:37 2007
@@ -6,21 +6,24 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.ldapstudio.browser.core.utils;
+/**
+ * Utilities to convert between models
+ */
import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
import org.apache.directory.ldapstudio.browser.core.internal.model.DummyEntry;
@@ -48,6 +51,18 @@
public class ModelConverter
{
+
+ /**
+ * Converts the given {@link LdifContentRecord} to an {@link DummyEntry}.
+ *
+ * @param ldifContentRecord the ldif content record to convert
+ * @param connection the connection
+ *
+ * @return the resulting dummy entry
+ *
+ * @throws ModelModificationException the model modification exception
+ * @throws NameException the name exception
+ */
public static DummyEntry ldifContentRecordToEntry( LdifContentRecord ldifContentRecord, IConnection connection )
throws NameException, ModelModificationException
{
@@ -55,6 +70,17 @@
}
+ /**
+ * Converts the given {@link LdifChangeAddRecord} to an {@link DummyEntry}.
+ *
+ * @param ldifChangeAddRecord the ldif change add record to convert
+ * @param connection the connection
+ *
+ * @return the resulting dummy entry
+ *
+ * @throws ModelModificationException the model modification exception
+ * @throws NameException the name exception
+ */
public static DummyEntry ldifChangeAddRecordToEntry( LdifChangeAddRecord ldifChangeAddRecord, IConnection connection )
throws NameException, ModelModificationException
{
@@ -62,10 +88,20 @@
}
+ /**
+ * Creates an {@link DummyEntry} from the given {@link LdifRecord}.
+ *
+ * @param connection the connection
+ * @param ldifRecord the ldif record
+ *
+ * @return the dummy entry
+ *
+ * @throws ModelModificationException the model modification exception
+ * @throws NameException the name exception
+ */
private static DummyEntry createIntern( LdifRecord ldifRecord, IConnection connection ) throws NameException,
ModelModificationException
{
-
LdifPart[] parts = ldifRecord.getParts();
EventRegistry.suspendEventFireingInCurrentThread();