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.v2.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.configurers.Configurer;
27 import net.sf.urlchecker.v2.communication.HTTPMethods;
28
29 import org.apache.commons.configuration.HierarchicalConfiguration;
30 import org.apache.commons.configuration.XMLConfiguration;
31
32 /**
33 * The Class MethodsConfigurer for the new HttpClient.
34 *
35 * <p>
36 * <b> $Id: MethodsConfigurer.java 183 2010-12-17 19:10:21Z georgosn $</b>
37 * </p>
38 *
39 * @author $LastChangedBy: georgosn $
40 * @version $LastChangedRevision: 183 $
41 */
42 public class MethodsConfigurer implements Configurer<Map<String, HTTPMethods>> {
43
44 /*
45 * (non-Javadoc)
46 *
47 * @see
48 * net.sf.urlchecker.communication.configurers.Configurer#configureWith(org
49 * .apache.commons.configuration.XMLConfiguration, java.lang.Object)
50 */
51 /** {@inheritDoc} */
52 public Map<String, HTTPMethods> configureWith(XMLConfiguration config) {
53 final Map<String, HTTPMethods> methods = new HashMap<String, HTTPMethods>();
54 if (config.containsKey("methods.method")) {
55 final List<HierarchicalConfiguration> methodsConfig = config
56 .configurationsAt("methods.method");
57 if (null != methodsConfig) {
58 for (final HierarchicalConfiguration method : methodsConfig) {
59 if ("*".equals(method.getString("[@source]"))) {
60 methods.put(null, HTTPMethods.valueOf(method.getString(
61 "[@type]", "HEAD")));
62 } else {
63 methods.put(method.getString("[@source]"), HTTPMethods
64 .valueOf(method.getString("[@type]", "HEAD")));
65 }
66 }
67 }
68 }
69 return methods;
70 }
71 }