if ( !uri.isStoreRoot() ) {
resourceType += "<principal/>";
}
props.put(
"DAV:resourcetype",
new NodeProperty( "resourcetype", resourceType, "DAV:", "", false ) );
props.put(
"DAV:displayname",
new NodeProperty( "displayname", (!uri.isStoreRoot() && principalNameAttribute != null?(String)objectNameMap.get(objectName):objectName), "DAV:", "", false ) );
// The storeRoot isn't a real object so it doesn't have any parameters to look up
if ( !uri.isStoreRoot() ) {
String localFilter = rdnAttribute + "=" + (principalNameAttribute != null?(String)objectNameMap.get(objectName):objectName);
SearchControls controls = new SearchControls();
controls.setSearchScope( searchScope );
controls.setReturningAttributes( descriptorAttributes );
try {
NamingEnumeration results = ctx.search(
container,
localFilter,
controls );
if ( !results.hasMore() ) {
if (ctx != null) {
closeContext(ctx);
}
throw new RevisionDescriptorNotFoundException( uri.toString() );
}
while ( results.hasMore() ) {
SearchResult result = null;
try {
result = (SearchResult)results.next();
} catch ( NamingException e ) {
getLogger().log(
name + ": Error getting search result with filter: " + localFilter +
" from container: " + container + ".",
LOG_CHANNEL, Logger.ERROR );
if (ctx != null) {
closeContext(ctx);
}
throw new ServiceAccessException( this, e );
}
NamingEnumeration attributes = result.getAttributes().getAll();
while ( attributes.hasMore() ) {
Attribute attribute = (Attribute)attributes.next();
StringBuffer valueString = new StringBuffer();
boolean isGms = attribute.getID().equals( groupMemberSet );
boolean isMva = attribute.size() > 1;
for ( int i = 0; i < attribute.size(); i++ ) {
try {
Object value = attribute.get( i );
if ( !( value instanceof String ) ) {
getLogger().log(
name + ": Non-string value found for " +
attribute.getID() + ".",
LOG_CHANNEL,
Logger.DEBUG );
continue;
}
if ( isGms ) {
valueString.append( "<D:href xmlns:D='DAV:'>" );
valueString.append( usersPath ).append( "/" );
String name = parseLdapName(value.toString());
if (principalNameAttribute != null) {
// lookup LDAP user entry
controls.setReturningAttributes(new String[] { principalNameAttribute });
NamingEnumeration roleResults =
ctx.search(container, rdnAttribute + "=" + name, controls);
if (roleResults.hasMore()) {
SearchResult userObject = (SearchResult)roleResults.next();
name = ((String)userObject.getAttributes().get(principalNameAttribute).get()).toLowerCase();
}
}
valueString.append(name);
valueString.append( "</D:href>" );
} else {
if ( isMva ) {
valueString.append( "<mva xmlns=\"" )
.append( LDAP_NAMESPACE ).append( "\">" );
valueString.append( value.toString() );
valueString.append( "</mva>" );
} else {
valueString.append( value.toString() );
}
}
} catch ( NamingException e ) {
getLogger().log(
name + ": Error fetching next attribute value for attribute " +
attribute.getID() + ".",
e, LOG_CHANNEL, Logger.DEBUG );
}
}
if ( isGms ) {
getLogger().log(
name + ": Adding property \"group-member-set\" in namespace " +
"\"DAV:\" with value of \"" + valueString.toString() + "\" to " +
uri.toString() + ".",
LOG_CHANNEL, Logger.DEBUG );
props.put(
"DAV:group-member-set",
new NodeProperty(
"group-member-set",
valueString.toString(),
"DAV:" ) );
} else {
getLogger().log(
name + ": Adding property \"" + attribute.getID() +
"\" in namespace \"" + LDAP_NAMESPACE + "\" " +
"with value of \"" +
valueString.toString() + "\" to " + uri.toString() + ".",
LOG_CHANNEL, Logger.DEBUG );
props.put(
LDAP_NAMESPACE + attribute.getID(),
new NodeProperty(
attribute.getID(),
valueString.toString(),
LDAP_NAMESPACE ) );
}
}