1    /*
2     * Copyright 2007 :torweg free software group
3     * 
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.component.core.site.map;
19   
20   import org.jdom.Element;
21   import org.torweg.pulse.configuration.AbstractConfigBean;
22   import org.torweg.pulse.configuration.ConfigurationException;
23   
24   /**
25    * configuration for {@code SitemapMenuController}.
26    * 
27    * @author Thomas Weber
28    * @version $Revision: 1459 $
29    */
30   public class SitemapMenuConfig extends AbstractConfigBean {
31   
32       /**
33        * serialVersionUID.
34        */
35       private static final long serialVersionUID = 7664133138492005933L;
36   
37       /**
38        * the display mode for the menu.
39        */
40       private String mode;
41   
42       /**
43        * the maximum depth for
44        * {@link GetFullSitemap#getSitemap(org.torweg.pulse.bundle.Bundle, org.torweg.pulse.service.request.ServiceRequest)}
45        * .
46        */
47       private int maxSitemapDepth = Integer.MAX_VALUE;
48   
49       /**
50        * returns the mode.
51        * 
52        * @return the mode
53        */
54       public final String getMode() {
55           return this.mode;
56       }
57   
58       /**
59        * returns the maximum depth for full sitemap display.
60        * 
61        * @return the maximum depth
62        */
63       public final int getMaxSitemapDepth() {
64           return this.maxSitemapDepth;
65       }
66   
67       /**
68        * initialises the {@code ConfigBean}.
69        * 
70        * @param conf
71        *            the configuration
72        * @see org.torweg.pulse.configuration.ConfigBean#init(org.jdom.Element)
73        */
74       public void init(final Element conf) {
75           String m = conf.getChildText("mode");
76           if (!m.equals("compact") && !m.equals("tree")
77                   && !m.equals("threeLevelPlusCompact")) {
78               throw new ConfigurationException("Invalid mode '" + m
79                       + "'. Supported modes: 'tree', 'compact', "
80                       + "'threeLevelPlusCompact'.");
81           }
82           if ((conf.getChild("full-sitemap") != null)
83                   && (conf.getChild("full-sitemap").getAttribute("max-depth") != null)) {
84               this.maxSitemapDepth = Integer.valueOf(conf
85                       .getChild("full-sitemap").getAttributeValue("max-depth"));
86           }
87           this.mode = m;
88       }
89   
90   }
91