01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.treeprocessor.sitemap;
18:
19: import org.apache.avalon.framework.configuration.Configuration;
20: import org.apache.avalon.framework.configuration.ConfigurationException;
21: import org.apache.avalon.framework.thread.ThreadSafe;
22: import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
23: import org.apache.cocoon.components.treeprocessor.ProcessingNode;
24:
25: /**
26: *
27: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
28: * @version CVS $Id: ActionSetNodeBuilder.java 433543 2006-08-22 06:22:54Z crossley $
29: */
30:
31: public class ActionSetNodeBuilder extends
32: AbstractParentProcessingNodeBuilder implements ThreadSafe {
33:
34: /** The TreeBuilder attribute indicating that an ActionSet is being built */
35: public static final String IN_ACTION_SET = ActionSetNodeBuilder.class
36: .getName()
37: + "/inActionSet";
38:
39: public ProcessingNode buildNode(Configuration config)
40: throws Exception {
41:
42: String actionSetName = config.getAttribute("name");
43:
44: Configuration[] childrenConfig = config.getChildren();
45: // Inform other builders that we're in an action-set
46: this .treeBuilder.setAttribute(IN_ACTION_SET, Boolean.TRUE);
47:
48: // Get the child actions
49: ProcessingNode[] nodes = this .buildChildNodes(config);
50:
51: // And get their names
52: String[] actions = new String[nodes.length];
53: for (int i = 0; i < childrenConfig.length; i++) {
54: Configuration childConfig = childrenConfig[i];
55: String name = childConfig.getName();
56:
57: if ("act".equals(name)) {
58: actions[i] = childConfig.getAttribute("action", null);
59: } else {
60: // Unknown element
61: String msg = "Unknown element " + name
62: + " in action-set at "
63: + childConfig.getLocation();
64: throw new ConfigurationException(msg);
65: }
66: }
67:
68: ActionSetNode node = new ActionSetNode(actionSetName, nodes,
69: actions);
70: this .treeBuilder.setupNode(node, config);
71:
72: // Inform other builders that we're no more in an action-set
73: this.treeBuilder.setAttribute(IN_ACTION_SET, null);
74:
75: return node;
76: }
77: }
|