View Javadoc

1   /*
2    * (C)opyright 2010, Nikolaos Georgosopoulos
3    *
4    * This file is part of URLChecker.
5   
6       URLChecker is free software: you can redistribute it and/or modify
7       it under the terms of the Lesser General Public License as published by
8       the Free Software Foundation, either version 3 of the License, or
9       (at your option) any later version.
10  
11      URLChecker is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.
15  
16      You should have received a copy of the Lesser General Public License
17      along with URLChecker.  If not, see <http://www.gnu.org/licenses/>.
18  
19   */
20  package net.sf.urlchecker.communication.configurers;
21  
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import net.sf.urlchecker.communication.HTTPMethods;
27  
28  import org.apache.commons.configuration.HierarchicalConfiguration;
29  import org.apache.commons.configuration.XMLConfiguration;
30  
31  /**
32   * The Methods Configurer Class.
33   * 
34   * <p>
35   * <b> $Id: MethodsConfigurer.java 182 2010-12-13 22:51:53Z georgosn $</b>
36   * </p>
37   * 
38   * @author $LastChangedBy: georgosn $
39   * @version $LastChangedRevision: 182 $
40   */
41  public class MethodsConfigurer implements Configurer<Map<String, HTTPMethods>> {
42  
43      /*
44       * (non-Javadoc)
45       * 
46       * @see
47       * net.sf.urlchecker.communication.configurers.Configurer#configureWith(org
48       * .apache.commons.configuration.XMLConfiguration, java.lang.Object)
49       */
50      /** {@inheritDoc} */
51      public Map<String, HTTPMethods> configureWith(XMLConfiguration config) {
52          final Map<String, HTTPMethods> methods = new HashMap<String, HTTPMethods>();
53          if (config.containsKey("methods.method")) {
54              final List<HierarchicalConfiguration> methodsConfig = config
55                      .configurationsAt("methods.method");
56              if (null != methodsConfig) {
57                  for (final HierarchicalConfiguration method : methodsConfig) {
58                      if ("*".equals(method.getString("[@source]"))) {
59                          methods.put(null, HTTPMethods.valueOf(method.getString(
60                                  "[@type]", "HEAD")));
61                      } else {
62                          methods.put(method.getString("[@source]"), HTTPMethods
63                                  .valueOf(method.getString("[@type]", "HEAD")));
64                      }
65                  }
66              }
67          }
68          return methods;
69      }
70  
71  }