KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > sitemap > SitemapNodeBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.treeprocessor.sitemap;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20 import org.apache.avalon.framework.thread.ThreadSafe;
21 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
22 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
23 import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
24
25 /**
26  * Builds all nodes below the top-level <sitemap> element, and returns the
27  * <pipelines> node. There is no node for >sitemap< since no processing
28  * occurs at this level.
29  *
30  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
31  * @version CVS $Id: SitemapNodeBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
32  */

33
34 public class SitemapNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
35     
36     // Name of children that have to be built in a particular order.
37
// For example, views have to be built before resources and both before pipelines.
38
private static final String JavaDoc[] orderedNames = { "components", "views", "resources" };
39
40     public ProcessingNode buildNode(Configuration config) throws Exception JavaDoc {
41         
42         // Start by explicitely ordered children
43
for (int i = 0; i < orderedNames.length; i++) {
44             Configuration childConfig = config.getChild(orderedNames[i], false);
45             if (childConfig != null) {
46                 ProcessingNodeBuilder builder = this.treeBuilder.createNodeBuilder(childConfig);
47                 // Don't build them since "pipelines" is not present in this list
48
builder.buildNode(childConfig);
49             }
50         }
51         
52         ProcessingNode pipelines = null;
53
54         // Now build all those that have no particular order
55
Configuration[] childConfigs = config.getChildren();
56         
57         loop: for (int i = 0; i < childConfigs.length; i++) {
58             
59             Configuration childConfig = childConfigs[i];
60             if (isChild(childConfig)) {
61                 // Is it in the ordered list ?
62
for (int j = 0; j < orderedNames.length; j++) {
63                     if (orderedNames[j].equals(childConfig.getName())) {
64                         // yep : already built above
65
continue loop;
66                     }
67                 }
68                 
69                 ProcessingNodeBuilder builder = this.treeBuilder.createNodeBuilder(childConfig);
70                 ProcessingNode node = builder.buildNode(childConfig);
71                 if (node instanceof PipelinesNode) {
72                     if (pipelines != null) {
73                         String JavaDoc msg = "Only one 'pipelines' is allowed, at " + childConfig.getLocation();
74                         throw new ConfigurationException(msg);
75                     }
76                     pipelines = node;
77                 }
78             }
79         }
80
81         if (pipelines == null) {
82             String JavaDoc msg = "Invalid sitemap : there must be a 'pipelines' at " + config.getLocation();
83             throw new ConfigurationException(msg);
84         }
85
86         return pipelines;
87     }
88 }
89
Popular Tags