001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.webapps.authentication.components;
018:
019: import java.util.Collections;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.apache.avalon.framework.configuration.Configuration;
024: import org.apache.avalon.framework.configuration.ConfigurationException;
025: import org.apache.cocoon.ProcessingException;
026: import org.apache.cocoon.components.ChainedConfiguration;
027: import org.apache.cocoon.components.SitemapConfigurationHolder;
028: import org.apache.cocoon.environment.ObjectModelHelper;
029: import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
030:
031: /**
032: * This is a utility class managing the authentication handlers
033: *
034: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
035: * @deprecated This block is deprecated and will be removed in future versions.
036: * @version CVS $Id: DefaultHandlerManager.java 433543 2006-08-22 06:22:54Z crossley $
037: */
038: public final class DefaultHandlerManager {
039:
040: /**
041: * Get the current handler configuration
042: */
043: static public Map prepareHandlerConfiguration(Map objectModel,
044: SitemapConfigurationHolder holder)
045: throws ConfigurationException {
046: Map configs = (Map) holder.getPreparedConfiguration();
047: if (null == configs) {
048: ChainedConfiguration chainedConfig = holder
049: .getConfiguration();
050: configs = prepare(objectModel, holder, chainedConfig);
051: }
052: return configs;
053: }
054:
055: /**
056: * Prepare the handler configuration
057: */
058: static private Map prepare(Map objectModel,
059: SitemapConfigurationHolder holder, ChainedConfiguration conf)
060: throws ConfigurationException {
061: // test for handlers
062: boolean found = false;
063: Configuration[] handlers = null;
064: Configuration handlersWrapper = conf
065: .getChild("handlers", false);
066: if (null != handlersWrapper) {
067: handlers = handlersWrapper.getChildren("handler");
068: if (null != handlers && handlers.length > 0) {
069: found = true;
070: }
071: }
072:
073: Map values = null;
074: final ChainedConfiguration parent = conf.getParent();
075: if (null != parent) {
076: values = prepare(objectModel, holder, parent);
077: if (found) {
078: values = new HashMap(values);
079: }
080: } else if (found) {
081: values = new HashMap(10);
082: } else {
083: values = Collections.EMPTY_MAP;
084: }
085:
086: if (found) {
087: for (int i = 0; i < handlers.length; i++) {
088: // check unique name
089: final String name = handlers[i].getAttribute("name");
090: if (null != values.get(name)) {
091: throw new ConfigurationException(
092: "Handler names must be unique: " + name);
093: }
094:
095: addHandler(objectModel, handlers[i], values);
096: }
097: }
098: holder.setPreparedConfiguration(conf, values);
099:
100: return values;
101: }
102:
103: /**
104: * Add one handler configuration
105: */
106: static private void addHandler(Map objectModel,
107: Configuration configuration, Map values)
108: throws ConfigurationException {
109: // get handler name
110: final String name = configuration.getAttribute("name");
111:
112: // create handler
113: HandlerConfiguration currentHandler = new HandlerConfiguration(
114: name);
115:
116: try {
117: currentHandler.configure(ObjectModelHelper
118: .getRequest(objectModel), configuration);
119: } catch (ProcessingException se) {
120: throw new ConfigurationException(
121: "Exception during configuration of handler: "
122: + name, se);
123: }
124: values.put(name, currentHandler);
125: }
126:
127: }
|