View Javadoc
1   package com.atlassian.plugin.refimpl;
2   
3   import com.google.common.collect.ImmutableMap;
4   import org.slf4j.Logger;
5   import org.slf4j.LoggerFactory;
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   
10  /**
11   * Helps with configuration parsing.
12   *
13   * @since 2.7.0
14   */
15  public class ConfigParser {
16      /**
17       * Not for instantiation.
18       */
19      private ConfigParser() {
20      }
21  
22      private static final Logger LOG = LoggerFactory.getLogger(ConfigParser.class);
23  
24      /**
25       * Parses the configuration string in the form of "com.abc.def=1.2.3, org.xyz=4.5.6"
26       *
27       * @param input the configuration string to parse, cannot be null.
28       * @return (key, value) map parsed from the given input string.
29       */
30      public static Map<String, String> parseMap(final String input) {
31          final Map<String, String> output = new HashMap<String, String>();
32  
33          final String[] items = input.split("[,]");
34          for (String item : items) {
35              String[] parts = item.split("[=]");
36              if (parts.length == 2) {
37                  output.put(parts[0].trim(), parts[1].trim());
38              } else {
39                  LOG.warn("Ignored unparsable item in configuration:" + item);
40              }
41          }
42  
43          return ImmutableMap.copyOf(output);
44      }
45  }