KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31
32 public class ViewNodeBuilder extends NamedContainerNodeBuilder implements ThreadSafe {
33
34     public ProcessingNode buildNode(Configuration config) throws Exception JavaDoc {
35
36         // Get the label or position (pseudo-label) of this view.
37
String JavaDoc label = config.getAttribute("from-label", null);
38
39         if (label == null) {
40             String JavaDoc position = config.getAttribute("from-position");
41             if ("first".equals(position)) {
42                 label = SitemapLanguage.FIRST_POS_LABEL;
43             } else if ("last".equals(position)) {
44                 label = SitemapLanguage.LAST_POS_LABEL;
45             } else {
46                 String JavaDoc msg = "Bad value for 'from-position' at " + config.getLocation();
47                 throw new ConfigurationException(msg);
48             }
49         }
50
51         SitemapLanguage sitemapBuilder = (SitemapLanguage)this.treeBuilder;
52
53         // Indicate to child builders that we're in a view (they won't perform view branching)
54
sitemapBuilder.setBuildingView(true);
55
56         // Build children
57
NamedProcessingNode result = (NamedProcessingNode)super.buildNode(config);
58
59         sitemapBuilder.addViewForLabel(label, result.getName());
60
61         // Clear the flag
62
sitemapBuilder.setBuildingView(false);
63
64         return result;
65     }
66 }
67
Popular Tags