一、前言
关于apache的ibator-1.2.1.681.jar源码包中org.apache.ibatis.ibator.internal.util.StringUtility字符串工具类,实现字符串长度判断stringHasValue、字符串判断是否空格stringContainsSpace、对于字符串分隔符分别针对java/xml/ibatis转码过滤处理,详情参见源码说明部分。
二、源码说明
package org.apache.ibatis.ibator.internal.util;@b@@b@import java.util.StringTokenizer;@b@@b@public class StringUtility@b@{@b@ public static boolean stringHasValue(String s)@b@ {@b@ return ((s != null) && (s.length() > 0));@b@ }@b@@b@ public static String composeFullyQualifiedTableName(String catalog, String schema, String tableName, char separator)@b@ {@b@ StringBuilder sb = new StringBuilder();@b@@b@ if (stringHasValue(catalog)) {@b@ sb.append(catalog);@b@ sb.append(separator);@b@ }@b@@b@ if (stringHasValue(schema)) {@b@ sb.append(schema);@b@ sb.append(separator);@b@ }@b@ else if (sb.length() > 0) {@b@ sb.append(separator);@b@ }@b@@b@ sb.append(tableName);@b@@b@ return sb.toString();@b@ }@b@@b@ public static boolean stringContainsSpace(String s) {@b@ return ((s != null) && (s.indexOf(32) != -1));@b@ }@b@@b@ public static String escapeStringForJava(String s) {@b@ StringTokenizer st = new StringTokenizer(s, "\"", true);@b@ StringBuilder sb = new StringBuilder();@b@ while (st.hasMoreTokens()) {@b@ String token = st.nextToken();@b@ if ("\"".equals(token))@b@ sb.append("\\\"");@b@ else@b@ sb.append(token);@b@@b@ }@b@@b@ return sb.toString();@b@ }@b@@b@ public static String escapeStringForXml(String s) {@b@ StringTokenizer st = new StringTokenizer(s, "\"", true);@b@ StringBuilder sb = new StringBuilder();@b@ while (st.hasMoreTokens()) {@b@ String token = st.nextToken();@b@ if ("\"".equals(token))@b@ sb.append(""");@b@ else@b@ sb.append(token);@b@@b@ }@b@@b@ return sb.toString();@b@ }@b@@b@ public static boolean isTrue(String s) {@b@ return "true".equalsIgnoreCase(s);@b@ }@b@@b@ public static String escapeStringForIbatis(String s) {@b@ StringTokenizer st = new StringTokenizer(s, "$#", true);@b@ StringBuilder sb = new StringBuilder();@b@ while (st.hasMoreTokens()) {@b@ String token = st.nextToken();@b@ if ("$".equals(token))@b@ sb.append("$$");@b@ else if ("#".equals(token))@b@ sb.append("##");@b@ else@b@ sb.append(token);@b@@b@ }@b@@b@ return sb.toString();@b@ }@b@}