1 16 package org.apache.cocoon.webapps.authentication.components; 17 18 import java.util.Collections ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.cocoon.ProcessingException; 25 import org.apache.cocoon.components.ChainedConfiguration; 26 import org.apache.cocoon.components.SitemapConfigurationHolder; 27 import org.apache.cocoon.environment.ObjectModelHelper; 28 import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration; 29 30 31 37 public final class DefaultHandlerManager { 38 39 42 static public Map prepareHandlerConfiguration(Map objectModel, 43 SitemapConfigurationHolder holder) 44 throws ConfigurationException { 45 Map configs = (Map )holder.getPreparedConfiguration(); 46 if ( null == configs ) { 47 ChainedConfiguration chainedConfig = holder.getConfiguration(); 48 configs = prepare( objectModel, holder, chainedConfig ); 49 } 50 return configs; 51 } 52 55 static private Map prepare( Map objectModel, 56 SitemapConfigurationHolder holder, 57 ChainedConfiguration conf) 58 throws ConfigurationException { 59 boolean found = false; 61 Configuration[] handlers = null; 62 Configuration handlersWrapper = conf.getChild("handlers", false); 63 if ( null != handlersWrapper ) { 64 handlers = handlersWrapper.getChildren("handler"); 65 if ( null != handlers && handlers.length > 0) { 66 found = true; 67 } 68 } 69 70 Map values = null; 71 final ChainedConfiguration parent = conf.getParent(); 72 if ( null != parent ) { 73 values = prepare( objectModel, holder, parent ); 74 if ( found ) { 75 values = new HashMap ( values ); 76 } 77 } else if ( found ){ 78 values = new HashMap (10); 79 } else { 80 values = Collections.EMPTY_MAP; 81 } 82 83 if ( found ) { 84 for(int i=0; i<handlers.length;i++) { 85 final String name = handlers[i].getAttribute("name"); 87 if ( null != values.get(name) ) { 88 throw new ConfigurationException("Handler names must be unique: " + name); 89 } 90 91 addHandler( objectModel, handlers[i], values ); 92 } 93 } 94 holder.setPreparedConfiguration( conf, values ); 95 96 return values; 97 } 98 99 102 static private void addHandler(Map objectModel, 103 Configuration configuration, 104 Map values) 105 throws ConfigurationException { 106 final String name = configuration.getAttribute("name"); 108 109 HandlerConfiguration currentHandler = new HandlerConfiguration(name); 111 112 try { 113 currentHandler.configure(ObjectModelHelper.getRequest(objectModel), configuration); 114 } catch (ProcessingException se) { 115 throw new ConfigurationException("Exception during configuration of handler: " + name, se); 116 } 117 values.put( name, currentHandler ); 118 } 119 120 121 } 122 | Popular Tags |