Java Code Examples for org.apache.commons.lang3.StringUtils#replaceAll()

The following examples show how to use org.apache.commons.lang3.StringUtils#replaceAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestLoggingFilter.java    From spring-boot-start-current with Apache License 2.0 6 votes vote down vote up
@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 );
}
 
Example 2
Source File: PostController.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 去除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, " ", "-");
}
 
Example 3
Source File: DataUtils.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * 将数据中包含的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;
}
 
Example 4
Source File: DefaultInjectionAttackHandler.java    From spring-boot-start-current with Apache License 2.0 5 votes vote down vote up
@Override
public String filterSqlInjection ( String rawCharacters ) {
    if ( StringUtils.isBlank( rawCharacters ) ) {
        return rawCharacters;
    }
    return StringUtils.replaceAll( rawCharacters , SQL_INJECTION_REGEX , StringUtils.EMPTY );
}
 
Example 5
Source File: DefaultInjectionAttackHandler.java    From spring-boot-start-current with Apache License 2.0 5 votes vote down vote up
@Override
public String filterXSSInjection ( String rawCharacters ) {
    if ( StringUtils.isBlank( rawCharacters ) ) {
        return rawCharacters;
    }
    return StringUtils.replaceAll( rawCharacters , XSS_REGEX , StringUtils.EMPTY );
}
 
Example 6
Source File: DefaultInjectionAttackHandler.java    From spring-boot-start-current with Apache License 2.0 5 votes vote down vote up
@Override
public String filterSpecialCharacters ( String rawCharacters ) {
    if ( StringUtils.isBlank( rawCharacters ) ) {
        return rawCharacters;
    }
    return StringUtils.replaceAll( rawCharacters , SPECIAL_CHARACTERS_REGEX , StringUtils.EMPTY );
}
 
Example 7
Source File: FindAndReplaceUpgradeOperation.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: Utils.java    From julongchain with Apache License 2.0 4 votes vote down vote up
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"));
}
 
Example 9
Source File: GeneralUtils.java    From smockin with Apache License 2.0 4 votes vote down vote up
public static String removeAllLineBreaks(final String original) {
    return StringUtils.replaceAll(original, System.getProperty("line.separator"), "");
}
 
Example 10
Source File: DAVRedirectStrategy.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected URI createLocationURI(final String location) throws ProtocolException {
    return super.createLocationURI(StringUtils.replaceAll(location, " ", "%20"));
}
 
Example 11
Source File: PoiExcelHelper.java    From bird-java with MIT License 4 votes vote down vote up
/**
 * 读取每一行的数据
 *
 * @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;
}
 
Example 12
Source File: ReplaceAll.java    From vscrawler with Apache License 2.0 4 votes vote down vote up
@Override
protected String handle(String input, String second, String third) {
    return StringUtils.replaceAll(input, second, third);
}
 
Example 13
Source File: MappingStoreTypeCompleter.java    From onos with Apache License 2.0 4 votes vote down vote up
private String removeMapPrefix(String type) {
    return StringUtils.replaceAll(type, MAP_PREFIX, "");
}
 
Example 14
Source File: HtmlUtils.java    From kbase-doc with Apache License 2.0 2 votes vote down vote up
/**
 * 将 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\"");
}
 
Example 15
Source File: ZkService.java    From DBus with Apache License 2.0 2 votes vote down vote up
/**
 * 获得当前值
 *
 * @param path
 * @return
 * @throws Exception
 */
@Override
public List<String> getChildren(String path) throws Exception {
    path = StringUtils.replaceAll(path, "//", "/");
    return client.getChildren().forPath(path);
}