1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.directory.utils;
35
36 import org.apache.commons.lang.StringUtils;
37
38 import java.util.ArrayList;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42
43
44
45
46
47
48 public final class UrlUtils
49 {
50 private static final String INTERROGATION_MARK = "?";
51 private static final String AMPERSAND = "&";
52 private static final String EQUAL = "=";
53
54
55
56
57 private UrlUtils( )
58 {
59 }
60
61
62
63
64
65
66
67
68 public static Map<String, List<String>> getMapParametersFromUrl( String strUrl )
69 {
70 Map<String, List<String>> mapParameters = new HashMap<String, List<String>>( );
71
72 if ( StringUtils.isNotBlank( strUrl ) && ( strUrl.indexOf( INTERROGATION_MARK ) > 0 ) )
73 {
74 String strUrlParameters = strUrl.substring( strUrl.indexOf( INTERROGATION_MARK ) + 1 );
75 String [ ] listParameters = strUrlParameters.split( AMPERSAND );
76
77 if ( ( listParameters != null ) && ( listParameters.length > 0 ) )
78 {
79 for ( String strParameter : listParameters )
80 {
81 String [ ] parameter = strParameter.split( EQUAL );
82
83 if ( ( parameter != null ) && ( parameter.length == 2 ) )
84 {
85 List<String> listParameterValues = mapParameters.get( parameter [0] );
86
87 if ( ( listParameterValues != null ) && !listParameterValues.isEmpty( ) )
88 {
89 listParameterValues.add( parameter [1] );
90 }
91 else
92 {
93 listParameterValues = new ArrayList<String>( );
94 listParameterValues.add( parameter [1] );
95 mapParameters.put( parameter [0], listParameterValues );
96 }
97 }
98 }
99 }
100 }
101
102 return mapParameters;
103 }
104 }