* @throws UnableToBuildCapabilityMapException
* @see org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
*/
public CapabilityMap getCapabilityMap(String userAgent) throws UnableToBuildCapabilityMapException
{
CapabilityMap map = null;
boolean bClientFound = false;
String defaultAgent = null;
if (userAgent == null)
{
userAgent = DEFAULT_AGENT;
}
// Check the cache if we have already a capability map for
// the given Agent
synchronized (capabilityMapCache)
{
map = (CapabilityMap) capabilityMapCache.get(userAgent);
if (map != null)
{
capabilityMapCacheKeyList.remove(userAgent);
capabilityMapCacheKeyList.addFirst(userAgent);
}
}
if (map != null)
{
// Entry found
return map;
}
while (!bClientFound)
{
Client entry = findClient(userAgent);
if (entry == null)
{
if (userAgent.equals(DEFAULT_AGENT))
{
log.error(
"CapabilityMap: Default agent not found in Client Registry !");
// Stop searching -- event the default userAgent can't be found
bClientFound = true;
} else
{
// Retry with the default Agent
if (log.isDebugEnabled())
{
log.debug(
"CapabilityMap: useragent "
+ userAgent
+ "unknown, falling back to default");
}
// Use default Client
defaultAgent = userAgent;
userAgent = DEFAULT_AGENT;
}
} else
{
// Found Client entry start populating the capability map.
map = new CapabilityMapImpl();
// Add client to CapabilityMap
map.setClient(entry);
// Add capabilities
Iterator capabilities = entry.getCapabilities().iterator();
while (capabilities.hasNext())
{
map.addCapability((Capability) capabilities.next());
}
Collection mediatypes =
getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
// Add Mimetypes to map
Iterator mimetypes = entry.getMimetypes().iterator();
while (mimetypes.hasNext())
{
map.addMimetype((MimeType) mimetypes.next());
}
Iterator media = mediatypes.iterator();
while (media.hasNext())
{
map.addMediaType((MediaType) media.next());
}
//Set preferred Mimetype
MediaType mtEntry =
getMediaTypeForMimeType(map.getPreferredType().getName());
map.setPreferredMediaType(mtEntry);
// Add map to cache
synchronized (capabilityMapCache)
{
if (capabilityMapCache.put(userAgent, map) != null)