KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > config > NavigationElementReader


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.config;
18
19 import java.util.Iterator JavaDoc;
20
21 import org.alfresco.config.ConfigElement;
22 import org.alfresco.config.ConfigException;
23 import org.alfresco.config.xml.elementreader.ConfigElementReader;
24 import org.dom4j.Element;
25
26 /**
27  * Custom element reader to parse config for navigation overrides
28  *
29  * @author gavinc
30  */

31 public class NavigationElementReader implements ConfigElementReader
32 {
33    public static final String JavaDoc ELEMENT_NAVIGATION = "navigation";
34    public static final String JavaDoc ELEMENT_OVERRIDE = "override";
35    public static final String JavaDoc ATTR_FROM_VIEWID = "from-view-id";
36    public static final String JavaDoc ATTR_FROM_OUTCOME = "from-outcome";
37    public static final String JavaDoc ATTR_TO_VIEWID = "to-view-id";
38    public static final String JavaDoc ATTR_TO_OUTCOME = "to-outcome";
39    
40    /**
41     * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
42     */

43    public ConfigElement parse(Element element)
44    {
45       NavigationConfigElement configElement = null;
46       
47       if (element != null)
48       {
49          String JavaDoc name = element.getName();
50          if (ELEMENT_NAVIGATION.equals(name) == false)
51          {
52             throw new ConfigException("NavigationElementReader can only parse " +
53                   ELEMENT_NAVIGATION + "elements, " + "the element passed was '" +
54                   name + "'");
55          }
56          
57          configElement = new NavigationConfigElement();
58          
59          // go through the items to show
60
Iterator JavaDoc<Element> items = element.elementIterator();
61          while (items.hasNext())
62          {
63             Element item = items.next();
64             
65             // only process the override elements
66
if (ELEMENT_OVERRIDE.equals(item.getName()))
67             {
68                String JavaDoc fromViewId = item.attributeValue(ATTR_FROM_VIEWID);
69                String JavaDoc fromOutcome = item.attributeValue(ATTR_FROM_OUTCOME);
70                String JavaDoc toViewId = item.attributeValue(ATTR_TO_VIEWID);
71                String JavaDoc toOutcome = item.attributeValue(ATTR_TO_OUTCOME);
72                
73                configElement.addOverride(fromViewId, fromOutcome, toViewId, toOutcome);
74             }
75          }
76       }
77       
78       return configElement;
79    }
80 }
81
Popular Tags