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.components.treeprocessor.sitemap;
018:
019: import org.apache.avalon.framework.configuration.Configuration;
020: import org.apache.avalon.framework.configuration.ConfigurationException;
021: import org.apache.cocoon.acting.Action;
022: import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
023: import org.apache.cocoon.components.treeprocessor.CategoryNode;
024: import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
025: import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
026: import org.apache.cocoon.components.treeprocessor.ProcessingNode;
027: import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
028:
029: /**
030: *
031: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
032: * @version CVS $Id: ActNodeBuilder.java 433543 2006-08-22 06:22:54Z crossley $
033: */
034: public class ActNodeBuilder extends AbstractParentProcessingNodeBuilder
035: implements LinkedProcessingNodeBuilder {
036:
037: private ActSetNode actSetNode;
038: private String actSetName;
039:
040: public ProcessingNode buildNode(Configuration config)
041: throws Exception {
042:
043: boolean inActionSet = this .treeBuilder
044: .getAttribute(ActionSetNodeBuilder.IN_ACTION_SET) != null;
045:
046: // Is it an action-set call ?
047: this .actSetName = config.getAttribute("set", null);
048: if (actSetName == null) {
049:
050: if (inActionSet) {
051: // Check that children are only parameters or actions
052: Configuration children[] = config.getChildren();
053: for (int i = 0; i < children.length; i++) {
054: String name = children[i].getName();
055: if (!"act".equals(name)
056: && !"parameter".equals(name)) {
057: throw new ConfigurationException(
058: "An action set can only contain actions and not '"
059: + name + "' at "
060: + children[i].getLocation());
061: }
062: }
063: }
064:
065: String name = config.getAttribute("name", null);
066: String source = config.getAttribute("src", null);
067: String type = this .treeBuilder.getTypeForStatement(config,
068: Action.ROLE + "Selector");
069:
070: ActTypeNode actTypeNode = new ActTypeNode(type,
071: VariableResolverFactory.getResolver(source,
072: this .manager), name, inActionSet);
073: this .treeBuilder.setupNode(actTypeNode, config);
074:
075: actTypeNode.setChildren(buildChildNodes(config));
076:
077: return actTypeNode;
078:
079: } else {
080:
081: if (inActionSet) {
082: throw new ConfigurationException(
083: "Cannot call an action set from an action set at "
084: + config.getLocation());
085: }
086:
087: // Action set call
088: if (config.getAttribute("src", null) != null) {
089: getLogger().warn(
090: "The 'src' attribute is ignored for action-set call at "
091: + config.getLocation());
092: }
093: this .actSetNode = new ActSetNode();
094: this .treeBuilder.setupNode(this .actSetNode, config);
095:
096: this .actSetNode.setChildren(buildChildNodes(config));
097:
098: return this .actSetNode;
099: }
100: }
101:
102: public void linkNode() throws Exception {
103:
104: if (this .actSetNode != null) {
105: // Link action-set call to the action set
106: CategoryNode actionSets = CategoryNodeBuilder
107: .getCategoryNode(this .treeBuilder, "action-sets");
108:
109: if (actionSets == null)
110: throw new ConfigurationException(
111: "This sitemap contains no action sets. Cannot call at "
112: + actSetNode.getLocation());
113:
114: ActionSetNode actionSetNode = (ActionSetNode) actionSets
115: .getNodeByName(this.actSetName);
116:
117: this.actSetNode.setActionSet(actionSetNode);
118: }
119: }
120: }
|