1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import org.apache.jetspeed.om.registry.ClientEntry; 20 import org.apache.jetspeed.om.registry.ClientRegistry; 21 import org.apache.jetspeed.om.registry.RegistryEntry; 22 import org.apache.jetspeed.om.registry.InvalidEntryException; 23 import org.apache.jetspeed.om.registry.RegistryException; 24 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 25 import org.apache.jetspeed.services.logging.JetspeedLogger; 26 import org.apache.jetspeed.services.Registry; 27 import java.util.Enumeration ; 28 29 import org.apache.regexp.RE; 31 32 46 public class BaseClientRegistry extends BaseOrderedRegistry implements ClientRegistry 47 { 48 49 52 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BaseClientRegistry.class.getName()); 53 54 57 public void setEntry( RegistryEntry entry ) throws InvalidEntryException 58 { 59 62 try 63 { 64 Registry.addEntry(Registry.CLIENT, entry); 65 } 66 catch (RegistryException e) 67 { 68 logger.error("Exception", e); 69 } 70 } 71 72 75 public void addEntry( RegistryEntry entry ) throws InvalidEntryException 76 { 77 80 try 81 { 82 Registry.addEntry(Registry.CLIENT, entry); 83 } 84 catch (RegistryException e) 85 { 86 logger.error("Exception", e); 87 } 88 } 89 90 93 public void removeEntry( String name ) 94 { 95 98 Registry.removeEntry(Registry.CLIENT, name); 99 } 100 101 104 public void removeEntry( RegistryEntry entry ) 105 { 106 109 if (entry != null) 110 { 111 Registry.removeEntry(Registry.CLIENT, entry.getName()); 112 } 113 } 114 115 122 public ClientEntry findEntry(String useragent) 123 { 124 ClientEntry clientEntry = null; 125 Enumeration clients = getEntries(); 126 127 if ( logger.isDebugEnabled() ) 128 { 129 logger.debug( "ClientRegistry: Looking for client with useragent :" + useragent ); 130 } 131 132 if (clients != null) 133 { 134 while (clients.hasMoreElements()) 135 { 136 ClientEntry client = (ClientEntry)clients.nextElement(); 137 if (client.getUseragentpattern() != null) 138 { 139 try 140 { 141 RE r = new RE(client.getUseragentpattern()); 142 r.setMatchFlags(RE.MATCH_CASEINDEPENDENT); 143 144 if (r.match(useragent)) 145 { 146 147 if ( logger.isDebugEnabled() ) 148 { 149 logger.debug( "ClientRegistry: " + useragent + " matches " + client.getUseragentpattern() ); 150 } 151 152 return client; 153 } 154 else 155 { 156 if ( logger.isDebugEnabled() ) 157 { 158 logger.debug( "ClientRegistry: " + useragent + " does not match " + client.getUseragentpattern() ); 159 } 160 } 161 } 162 catch (org.apache.regexp.RESyntaxException e) 163 { 164 String message = "ClientRegistryService: UserAgentPattern not valid : " + client.getUseragentpattern() + " : " + e.getMessage(); 165 logger.error( message, e ); 166 } 167 } 168 } 169 } 170 171 return clientEntry; 172 } 173 174 180 public RegistryEntry createEntry() 181 { 182 return new BaseClientEntry(); 183 } 184 } 185 | Popular Tags |