1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.capability;
1819import org.apache.jetspeed.om.registry.ClientEntry;
20import org.apache.jetspeed.om.registry.ClientRegistry;
21import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
22import org.apache.jetspeed.services.logging.JetspeedLogger;
23import org.apache.jetspeed.services.Registry;
2425import org.apache.turbine.util.RunData;
262728/***29This class describes various browsers capabilities and provides the30ability to query them.3132FIXME: the implementation should change to be configuration file based and33handle more browsers.3435@author <a href="mailto:raphael@apache.org">Raphaël Luta</a>36@version $Id: CapabilityMapFactory.java,v 1.15 2004/02/23 02:46:39 jford Exp $37*/38publicclassCapabilityMapFactory39 {
4041publicstaticfinal String DEFAULT_AGENT = "Mozilla/4.0";
4243publicstaticfinal String AGENT_XML = "agentxml/1.0";
4445/***46 * Static initialization of the logger for this class47 */48privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(CapabilityMapFactory.class.getName());
4950/***51 Returns the map corresponding to the given RunData.52 *53 FIXME: the method will be changed to use a Jetspeed specific request54 wrapper5556 @param rundata the request RunData57 @return the map correspondin to the user-agent described in the RunData58 */59publicstaticCapabilityMap getCapabilityMap( RunData rundata )
60 {
6162if (rundata == null)
63 {
64return getCapabilityMap(DEFAULT_AGENT);
65 }
6667return getCapabilityMap( rundata.getUserAgent() );
68 }
6970/***71 Returns the map corresponding to the given user-agent7273 @param useragent a user-agent string in the HTTP User-agent format74 @return the map corresponding to the user-agent75 */76publicstaticCapabilityMap getCapabilityMap( String useragent )
77 {
78CapabilityMap map = null;
7980if (useragent == null)
81 {
82 useragent = DEFAULT_AGENT;
83 }
8485ClientRegistry registry = (ClientRegistry)Registry.get(Registry.CLIENT);
86ClientEntry entry = registry.findEntry(useragent);
8788if (entry == null)
89 {
90if (useragent.equals(DEFAULT_AGENT))
91 {
92 logger.error("CapabilityMap: Default agent not found in Client Registry !");
93 }
94else95 {
96if (logger.isDebugEnabled())
97 {
98 logger.debug("CapabilityMap: useragent "+ useragent + "unknown, falling back to default");
99 }
100 map = getDefaultCapabilityMap();
101 }
102 }
103else104 {
105 map = newBaseCapabilityMap(useragent, entry);
106 }
107108109if (logger.isDebugEnabled())
110 {
111 logger.debug("CapabilityMap: User-agent: "+useragent+" mapped to "+map);
112 }
113114return map;
115 }
116117/***118 Returns the map corresponding to the given user-agent119120 @param useragent a user-agent string in the HTTP User-agent format121 @return the map corresponding to the user-agent122 */123publicstaticCapabilityMap getDefaultCapabilityMap()
124 {
125return getCapabilityMap(DEFAULT_AGENT);
126 }
127 }