下面列出了org.apache.commons.lang3.StringUtils#replaceAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void doFilter ( ServletRequest request , ServletResponse response , FilterChain chain )
throws IOException, ServletException {
if ( PatternMatchUtils.simpleMatch( excludeUrlPatterns , ( ( HttpServletRequest ) request ).getRequestURI() ) ) {
chain.doFilter( request , response );
return;
}
final BodyReaderWrapper wrapper = new BodyReaderWrapper( ( HttpServletRequest ) request );
String requestMessage = RequestUtils.getRequestMessage( wrapper );
if ( ! LogUtils.getLogger().isDebugEnabled() ) {
requestMessage = StringUtils.replaceAll( requestMessage , PASSWORD_FILTER_REGEX ,
"enable password protection, if not debug so do not see"
);
}
LogUtils.getLogger().info( requestMessage );
chain.doFilter( wrapper , response );
}
/**
* 去除html,htm后缀,以及将空格替换成-
*
* @param url url
* @return String
*/
private static String urlFilter(String url) {
if (null != url) {
final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm");
if (urlEndsWithHtmlPostFix) {
return url.substring(0, url.lastIndexOf("."));
}
}
return StringUtils.replaceAll(url, " ", "-");
}
/**
* 将数据中包含的secret字符使用星号替换,防止日志打印时被输出
*/
public static <E> E handleDataWithSecret(E data) {
E dataForLog = data;
if(data instanceof String && StringUtils.contains((String)data, "&secret=")){
dataForLog = (E) StringUtils.replaceAll((String)data,"&secret=\\w+&","&secret=******&");
}
return dataForLog;
}
@Override
public String filterSqlInjection ( String rawCharacters ) {
if ( StringUtils.isBlank( rawCharacters ) ) {
return rawCharacters;
}
return StringUtils.replaceAll( rawCharacters , SQL_INJECTION_REGEX , StringUtils.EMPTY );
}
@Override
public String filterXSSInjection ( String rawCharacters ) {
if ( StringUtils.isBlank( rawCharacters ) ) {
return rawCharacters;
}
return StringUtils.replaceAll( rawCharacters , XSS_REGEX , StringUtils.EMPTY );
}
@Override
public String filterSpecialCharacters ( String rawCharacters ) {
if ( StringUtils.isBlank( rawCharacters ) ) {
return rawCharacters;
}
return StringUtils.replaceAll( rawCharacters , SPECIAL_CHARACTERS_REGEX , StringUtils.EMPTY );
}
@Override
protected void updateFile(final String site, final Path path) throws UpgradeException {
String content = readFile(path);
String updated = null;
if(StringUtils.isNotEmpty(content)) {
updated = StringUtils.replaceAll(content, pattern, replacement);
}
if(StringUtils.isNotEmpty(updated) && !StringUtils.equals(content, updated)) {
logger.info("Updating file {0}", path);
writeFile(path, updated);
}
}
public static void replaceFileContent(String filePath, String oldStr, String newStr) throws IOException {
String string = FileUtils.readFileToString(new File(filePath), Charset.forName("UTF-8"));
string = StringUtils.replaceAll(string, oldStr, newStr);
FileUtils.writeStringToFile(new File(filePath), string, Charset.forName("UTF-8"));
}
public static String removeAllLineBreaks(final String original) {
return StringUtils.replaceAll(original, System.getProperty("line.separator"), "");
}
@Override
protected URI createLocationURI(final String location) throws ProtocolException {
return super.createLocationURI(StringUtils.replaceAll(location, " ", "%20"));
}
/**
* 读取每一行的数据
*
* @param row 行数据
* @param headKeys keys
* @param evaluator 公式计算器
* @return 行数据
*/
private static Map<String, Object> readLine(Row row, List<String> headKeys, FormulaEvaluator evaluator) {
if (row == null) return null;
Map<String, Object> line = new HashMap<>(8);
short max = row.getLastCellNum();
for (short i = row.getFirstCellNum(); i < max; i++) {
if (i >= headKeys.size()) break;
Cell cell = row.getCell(i);
if (cell == null) continue;
String key = headKeys.get(i);
Object value = null;
CellType cellType = cell.getCellTypeEnum();
switch (cellType) {
case STRING:
value = StringUtils.replaceAll(cell.getStringCellValue(),"^\\s*|\\s*$|\t|\r|\n","");
break;
case NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
} else {
value = cell.getNumericCellValue();
}
break;
case BOOLEAN:
value = cell.getBooleanCellValue();
break;
case FORMULA:
CellValue cellValue = evaluator.evaluate(cell);
value = cellValue.getCellTypeEnum() == CellType.NUMERIC ? cellValue.getNumberValue() : cellValue.getStringValue();
break;
default:
break;
}
if (value != null && Objects.equals(value.getClass().getName(), "java.lang.Double") && StringUtils.indexOf(value.toString(), "E") >= 0) {
value = DECIMAL_FORMAT.format(value);
}
line.put(key, value);
}
return line;
}
@Override
protected String handle(String input, String second, String third) {
return StringUtils.replaceAll(input, second, third);
}
private String removeMapPrefix(String type) {
return StringUtils.replaceAll(type, MAP_PREFIX, "");
}
/**
* 将 data 中的编码修改为 utf-8
* @author eko.zhan at 2017年8月11日 上午9:54:34
* @param data
* @return
*/
public static String replaceCharset(String data){
return StringUtils.replaceAll(data, "(?i)CONTENT=\"text/html; charset=gb2312\"", "CONTENT=\"text/html; charset=utf-8\"");
}
/**
* 获得当前值
*
* @param path
* @return
* @throws Exception
*/
@Override
public List<String> getChildren(String path) throws Exception {
path = StringUtils.replaceAll(path, "//", "/");
return client.getChildren().forPath(path);
}