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: import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
25:
26: /**
27: * Builds all nodes below the top-level <sitemap> element, and returns the
28: * <pipelines> node. There is no node for >sitemap< since no processing
29: * occurs at this level.
30: *
31: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
32: * @version CVS $Id: SitemapNodeBuilder.java 433543 2006-08-22 06:22:54Z crossley $
33: */
34:
35: public class SitemapNodeBuilder extends
36: AbstractParentProcessingNodeBuilder implements ThreadSafe {
37:
38: // Name of children that have to be built in a particular order.
39: // For example, views have to be built before resources and both before pipelines.
40: private static final String[] orderedNames = { "components",
41: "views", "resources" };
42:
43: public ProcessingNode buildNode(Configuration config)
44: throws Exception {
45:
46: // Start by explicitely ordered children
47: for (int i = 0; i < orderedNames.length; i++) {
48: Configuration childConfig = config.getChild(
49: orderedNames[i], false);
50: if (childConfig != null) {
51: ProcessingNodeBuilder builder = this .treeBuilder
52: .createNodeBuilder(childConfig);
53: // Don't build them since "pipelines" is not present in this list
54: builder.buildNode(childConfig);
55: }
56: }
57:
58: ProcessingNode pipelines = null;
59:
60: // Now build all those that have no particular order
61: Configuration[] childConfigs = config.getChildren();
62:
63: loop: for (int i = 0; i < childConfigs.length; i++) {
64:
65: Configuration childConfig = childConfigs[i];
66: if (isChild(childConfig)) {
67: // Is it in the ordered list ?
68: for (int j = 0; j < orderedNames.length; j++) {
69: if (orderedNames[j].equals(childConfig.getName())) {
70: // yep : already built above
71: continue loop;
72: }
73: }
74:
75: ProcessingNodeBuilder builder = this .treeBuilder
76: .createNodeBuilder(childConfig);
77: ProcessingNode node = builder.buildNode(childConfig);
78: if (node instanceof PipelinesNode) {
79: if (pipelines != null) {
80: String msg = "Only one 'pipelines' is allowed, at "
81: + childConfig.getLocation();
82: throw new ConfigurationException(msg);
83: }
84: pipelines = node;
85: }
86: }
87: }
88:
89: if (pipelines == null) {
90: String msg = "Invalid sitemap : there must be a 'pipelines' at "
91: + config.getLocation();
92: throw new ConfigurationException(msg);
93: }
94:
95: return pipelines;
96: }
97: }
|