1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.velocity.tools

File URLTool.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
10
1
1
61
27
3
0.3
10
1
3

Classes

Class Line # Actions
URLTool 37 10 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.velocity.tools;
21   
22    import java.nio.charset.StandardCharsets;
23    import java.util.ArrayList;
24    import java.util.LinkedHashMap;
25    import java.util.List;
26    import java.util.Map;
27   
28    import org.apache.http.NameValuePair;
29    import org.apache.http.client.utils.URLEncodedUtils;
30   
31    /**
32    * Velocity tool to parse URL parts.
33    *
34    * @version $Id: dbbb6644b7c0f267c556a8c7857ae21b02f4c0f7 $
35    * @since 6.3M1
36    */
 
37    public class URLTool
38    {
39    /**
40    * Parse a query string into a map of key-value pairs.
41    *
42    * @param query query string to be parsed
43    * @return a mapping of parameter names to values suitable e.g. to pass into {@link EscapeTool#url(Map)}
44    */
 
45  5 toggle public Map<String, List<String>> parseQuery(String query)
46    {
47  5 Map<String, List<String>> queryParams = new LinkedHashMap<>();
48  5 if (query != null) {
49  4 for (NameValuePair params : URLEncodedUtils.parse(query, StandardCharsets.UTF_8)) {
50  9 String name = params.getName();
51  9 List<String> values = queryParams.get(name);
52  9 if (values == null) {
53  7 values = new ArrayList<>();
54  7 queryParams.put(name, values);
55    }
56  9 values.add(params.getValue());
57    }
58    }
59  5 return queryParams;
60    }
61    }