1 16 17 package org.apache.jetspeed.capability; 18 19 import org.apache.jetspeed.om.registry.ClientEntry; 20 import org.apache.jetspeed.om.registry.ClientRegistry; 21 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 22 import org.apache.jetspeed.services.logging.JetspeedLogger; 23 import org.apache.jetspeed.services.Registry; 24 25 import org.apache.turbine.util.RunData; 26 27 28 38 public class CapabilityMapFactory 39 { 40 41 public static final String DEFAULT_AGENT = "Mozilla/4.0"; 42 43 public static final String AGENT_XML = "agentxml/1.0"; 44 45 48 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(CapabilityMapFactory.class.getName()); 49 50 59 public static CapabilityMap getCapabilityMap( RunData rundata ) 60 { 61 62 if (rundata == null) 63 { 64 return getCapabilityMap(DEFAULT_AGENT); 65 } 66 67 return getCapabilityMap( rundata.getUserAgent() ); 68 } 69 70 76 public static CapabilityMap getCapabilityMap( String useragent ) 77 { 78 CapabilityMap map = null; 79 80 if (useragent == null) 81 { 82 useragent = DEFAULT_AGENT; 83 } 84 85 ClientRegistry registry = (ClientRegistry)Registry.get(Registry.CLIENT); 86 ClientEntry entry = registry.findEntry(useragent); 87 88 if (entry == null) 89 { 90 if (useragent.equals(DEFAULT_AGENT)) 91 { 92 logger.error("CapabilityMap: Default agent not found in Client Registry !"); 93 } 94 else 95 { 96 if (logger.isDebugEnabled()) 97 { 98 logger.debug("CapabilityMap: useragent "+ useragent + "unknown, falling back to default"); 99 } 100 map = getDefaultCapabilityMap(); 101 } 102 } 103 else 104 { 105 map = new BaseCapabilityMap(useragent, entry); 106 } 107 108 109 if (logger.isDebugEnabled()) 110 { 111 logger.debug("CapabilityMap: User-agent: "+useragent+" mapped to "+map); 112 } 113 114 return map; 115 } 116 117 123 public static CapabilityMap getDefaultCapabilityMap() 124 { 125 return getCapabilityMap(DEFAULT_AGENT); 126 } 127 } | Popular Tags |