一、前言
关于camel-exec-2.21.0.jar包中的org.apache.camel.component.exec.impl.ExecParseUtils解析工具类,对分隔特殊字符串序列splitToWhiteSpaceSeparatedTokens、单独匹配字符串isSingleQuoted及是否isDoubleQuoted发电额等。
二、源码说明
package org.apache.camel.component.exec.impl;@b@@b@import java.util.ArrayList;@b@import java.util.List;@b@import java.util.StringTokenizer;@b@@b@public final class ExecParseUtils@b@{@b@ public static final String WHITESPACE = " ";@b@ public static final String QUOTE_CHAR = "\"";@b@@b@ public static List<String> splitToWhiteSpaceSeparatedTokens(String input)@b@ {@b@ if (input == null)@b@ return new ArrayList();@b@@b@ StringTokenizer tokenizer = new StringTokenizer(input.trim(), "\" ", true);@b@ List tokens = new ArrayList();@b@@b@ StringBuilder quotedText = new StringBuilder();@b@@b@ while (tokenizer.hasMoreTokens()) {@b@ String token = tokenizer.nextToken();@b@ if ("\"".equals(token))@b@ {@b@ quotedText.append("\"");@b@ String buffer = quotedText.toString();@b@ if ((isSingleQuoted(buffer)) || (isDoubleQuoted(buffer))) {@b@ tokens.add(buffer.substring(1, buffer.length() - 1));@b@ quotedText = new StringBuilder();@b@ }@b@ } else if (" ".equals(token))@b@ {@b@ if (quotedText.length() > 0)@b@ quotedText.append(" ");@b@@b@ }@b@ else if (quotedText.length() > 0) {@b@ quotedText.append(token);@b@ } else {@b@ tokens.add(token);@b@ }@b@ }@b@@b@ if (quotedText.length() > 0)@b@ throw new IllegalArgumentException(new StringBuilder().append("Invalid quoting found in args ").append(quotedText).toString());@b@@b@ return tokens;@b@ }@b@@b@ protected static boolean isSingleQuoted(String input)@b@ {@b@ if ((input == null) || (input.trim().length() == 0))@b@ return false;@b@@b@ return input.matches("(^\"{1}([^\"]+)\"{1})");@b@ }@b@@b@ protected static boolean isDoubleQuoted(String input)@b@ {@b@ if ((input == null) || (input.trim().length() == 0))@b@ return false;@b@@b@ return input.matches("(^\"{2}([^\"]+)\"{2})");@b@ }@b@}