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.cocoon.components.treeprocessor.NamedContainerNodeBuilder;
22: import org.apache.cocoon.components.treeprocessor.NamedProcessingNode;
23: import org.apache.cocoon.components.treeprocessor.ProcessingNode;
24:
25: /**
26: * Builds a <map:view>
27: *
28: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
29: * @version CVS $Id: ViewNodeBuilder.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31:
32: public class ViewNodeBuilder extends NamedContainerNodeBuilder {
33:
34: public ProcessingNode buildNode(Configuration config)
35: throws Exception {
36:
37: // Get the label or position (pseudo-label) of this view.
38: String label = config.getAttribute("from-label", null);
39:
40: if (label == null) {
41: String position = config.getAttribute("from-position");
42: if ("first".equals(position)) {
43: label = SitemapLanguage.FIRST_POS_LABEL;
44: } else if ("last".equals(position)) {
45: label = SitemapLanguage.LAST_POS_LABEL;
46: } else {
47: String msg = "Bad value for 'from-position' at "
48: + config.getLocation();
49: throw new ConfigurationException(msg);
50: }
51: }
52:
53: SitemapLanguage sitemapBuilder = (SitemapLanguage) this .treeBuilder;
54:
55: // Indicate to child builders that we're in a view (they won't perform view branching)
56: sitemapBuilder.setBuildingView(true);
57:
58: // Build children
59: NamedProcessingNode result = (NamedProcessingNode) super
60: .buildNode(config);
61:
62: sitemapBuilder.addViewForLabel(label, result.getName());
63:
64: // Clear the flag
65: sitemapBuilder.setBuildingView(false);
66:
67: return result;
68: }
69: }
|