diff options
| author | abranson <andrew.branson@cern.ch> | 2011-08-04 00:42:34 +0200 |
|---|---|---|
| committer | abranson <andrew.branson@cern.ch> | 2011-08-04 00:42:34 +0200 |
| commit | 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch) | |
| tree | 5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/lookup/LDAPLookupUtils.java | |
| parent | 036cbdba66f804743c4c838ed598d6972c4b3e17 (diff) | |
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better
Rewrote RemoteMap to use TreeMap instead of the internal array for
order. It now sorts its keys by number if they parse, else as strings.
Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/lookup/LDAPLookupUtils.java')
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/lookup/LDAPLookupUtils.java | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/source/com/c2kernel/lookup/LDAPLookupUtils.java b/source/com/c2kernel/lookup/LDAPLookupUtils.java index 6516374..8df365b 100755..100644 --- a/source/com/c2kernel/lookup/LDAPLookupUtils.java +++ b/source/com/c2kernel/lookup/LDAPLookupUtils.java @@ -49,7 +49,7 @@ final public class LDAPLookupUtils {
return getEntry(ld, dn, LDAPSearchConstraints.DEREF_NEVER);
}
-
+
static public String getFirstAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException
{
LDAPAttribute attr = anEntry.getAttribute(attribute);
@@ -61,11 +61,11 @@ final public class LDAPLookupUtils static public String[] getAllAttributeValues(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException
{
LDAPAttribute attr = anEntry.getAttribute(attribute);
- if (attr!=null)
+ if (attr!=null)
return attr.getStringValueArray();
-
+
throw new ObjectNotFoundException("No attributes named '"+attribute+"'", "");
-
+
}
static public boolean existsAttributeValue(LDAPEntry anEntry, String attribute, String value)
@@ -94,7 +94,7 @@ final public class LDAPLookupUtils //this is for a single-valued attribute
static public void setAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String newValue)
throws ObjectNotFoundException, ObjectCannotBeUpdated
- {
+ {
try {
if (!hasOneAttributeValue(anEntry, attribute))
throw new ObjectCannotBeUpdated("Attribute "+attribute + " of entry " + anEntry.getDN()+" has more than one value", "");
@@ -102,26 +102,26 @@ final public class LDAPLookupUtils addAttributeValue(ld, anEntry, attribute, newValue);
}
try
- {
+ {
ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(attribute,newValue)));
- }
- catch (LDAPException ex)
+ }
+ catch (LDAPException ex)
{
Logger.error(ex);
throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be modified", "");
}
}
-
+
//this is for a multi-valued attribute eg uniqueMember
static public void addAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String value)
throws ObjectCannotBeUpdated
{
- try
+ try
{
- ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.ADD, new LDAPAttribute(attribute,value)));
- }
- catch (LDAPException ex)
+ ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.ADD, new LDAPAttribute(attribute,value)));
+ }
+ catch (LDAPException ex)
{
Logger.error(ex);
throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be added.", "");
@@ -131,18 +131,18 @@ final public class LDAPLookupUtils //this is for a multi-valued attribute eg uniqueMember
static public void removeAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String value)
throws ObjectCannotBeUpdated
- {
+ {
try
{
ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.DELETE,new LDAPAttribute(attribute,value)));
- }
- catch (LDAPException ex)
+ }
+ catch (LDAPException ex)
{
Logger.error(ex);
throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be deleted", "");
}
}
-
+
static public boolean exists(LDAPConnection ld, String name)
{
try {
@@ -178,7 +178,7 @@ final public class LDAPLookupUtils LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
-
+
try
{
LDAPSearchResults res = ld.search(dn,LDAPConnection.SCOPE_ONE,filter,attr,false,searchCons);
@@ -200,7 +200,7 @@ final public class LDAPLookupUtils LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
-
+
try
{
LDAPSearchResults res = ld.search(dn,LDAPConnection.SCOPE_ONE,filter,attr,false,searchCons);
@@ -209,7 +209,7 @@ final public class LDAPLookupUtils while (res.hasMore())
{
LDAPEntry findEntry=res.next();
- if (findEntry!=null)
+ if (findEntry!=null)
{
result[i++] = new String(findEntry.getDN());
}
@@ -254,9 +254,9 @@ final public class LDAPLookupUtils objectclass_values[0] = "cristalcontext";
if (name.equals("last"))
attrs.add(new LDAPAttribute("intsyskey", "0"));
-
- attrs.add(new LDAPAttribute("objectclass",objectclass_values));
-
+
+ attrs.add(new LDAPAttribute("objectclass",objectclass_values));
+
LDAPLookupUtils.addEntry(ld,new LDAPEntry(dn,attrs));
}
catch (Exception ex)
@@ -269,7 +269,7 @@ final public class LDAPLookupUtils {
if (LDAPLookupUtils.exists(ld,dn))
return;
-
+
try
{
String name = LDAPDN.explodeDN(dn,true)[0];
@@ -283,7 +283,7 @@ final public class LDAPLookupUtils {
Logger.msg(ex.toString());
}
- }
+ }
public static String escapeDN (String name) {
//From RFC 2253 and the / character for JNDI
final char[] META_CHARS = {'+', '"', '<', '>', ';', '/'};
@@ -296,8 +296,8 @@ final public class LDAPLookupUtils escapedStr = escapedStr.replaceAll("^#","\\\\#");
escapedStr = escapedStr.replaceAll("^ | $","\\\\ ");
- for (int i=0;i < META_CHARS.length;i++) {
- escapedStr = escapedStr.replaceAll("\\"+META_CHARS[i],"\\\\" + META_CHARS[i]);
+ for (char element : META_CHARS) {
+ escapedStr = escapedStr.replaceAll("\\"+element,"\\\\" + element);
}
Logger.msg(6, "LDAP DN "+name+" escaped to "+escapedStr);
return escapedStr;
@@ -313,5 +313,5 @@ final public class LDAPLookupUtils escapedStr = escapedStr.replaceAll("\\)","\\\\29");
Logger.msg(6, "LDAP Search Filter "+filter+" escaped to "+escapedStr);
return escapedStr;
- }
+ }
}
|
