List of usage examples for org.apache.commons.lang StringUtils replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
From source file:de.fhg.iais.asc.transformer.jdom.handler.XmlFieldStripper.java
private static String stripText(final String input) { String result = input;/*from w w w .j a va 2 s.co m*/ result = StringUtils.replace(result, "\\s", " "); result = StringUtils.replace(result, " {2,}", " "); result = StringUtils.replace(result, " .", "."); result = StringUtils.replace(result, " ,", ","); result = StringUtils.replace(result, " ;", ";"); result = StringUtils.removeEnd(result, ","); result = StringUtils.removeEnd(result, ";"); result = result.trim(); return result; }
From source file:net.kamhon.ieagle.util.StringUtil.java
/** * refer to <a href="http://leepoint.net/notes-java/io/10file/sys-indep-newline.html">System Independent Newline * Characters</a>// w ww . j a v a 2 s. co m */ public static String newLineToHtmlBr(String s) { s = StringUtils.replace(s, "\r\n", "<br/>"); return StringUtils.replace(s, "\n", "<br/>"); }
From source file:eionet.cr.util.FileUtil.java
/** * Downloads the contents of the given URL into the given file and closes the file. * * @param urlString downloadable url//from w w w . j a v a2 s. c o m * @param toFile output file location * @throws IOException if input of output fails */ public static void downloadUrlToFile(final String urlString, final File toFile) throws IOException { URLConnection urlConnection = null; InputStream inputStream = null; try { URL url = new URL(urlString == null ? urlString : StringUtils.replace(urlString, " ", "%20")); urlConnection = url.openConnection(); urlConnection.setRequestProperty("Connection", "close"); inputStream = urlConnection.getInputStream(); FileUtil.streamToFile(inputStream, toFile); } finally { IOUtils.closeQuietly(inputStream); URLUtil.disconnect(urlConnection); } }
From source file:co.marcin.novaguilds.enums.Lang.java
/** * Load lang from a file// ww w .j a v a2 s .c o m * * @param file the file * @return the lang * @throws IOException */ public static Lang fromFile(File file) throws IOException { try { String langName = StringUtils.replace(StringUtils.replace(file.getName().toUpperCase(), "-", "_"), ".YML", ""); return Lang.valueOf(langName); } catch (Exception e) { try (BufferedReader brTest = new BufferedReader(new FileReader(file))) { String line = brTest.readLine(); if (line.startsWith("#")) { line = line.substring(1); LoggerUtils.info("Detected custom encoding for file " + file.getName() + ": " + line); Lang lang = Lang.CUSTOM; lang.setCharset(Charset.forName(line)); return lang; } LoggerUtils.info("Found custom translation, applying default translation UTF-8"); LoggerUtils.info("Add #ENCODING to the first line of your language file"); LoggerUtils.info("Please consider sharing your translation with the community"); } return Lang.CUSTOM; } }
From source file:com.senacor.wbs.web.core.EnumConverter.java
public Object convertToObject(String value, Locale locale) { String upper = value.toUpperCase(locale).trim(); String enumName = StringUtils.replace(upper, " ", "_"); try {//w ww.j av a 2 s . c o m return Enum.valueOf(enumType, enumName); } catch (IllegalArgumentException ex) { throw newConversionException("Cannot parse '" + value + "' using enum type " + enumType.getName(), value, locale); } }
From source file:com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperStat.java
public String getHtmlOriginalContent() { return StringUtils.replace(originalContent, "\n", "<br>"); }
From source file:io.kahu.hawaii.util.logger.Log4jConfigListener.java
@Override public void contextInitialized(ServletContextEvent sce) { String config = System.getenv("log4j.configuration"); if (StringUtils.isBlank(config)) { config = System.getProperty("log4j.configuration"); }/*from w w w .ja v a 2 s. com*/ if (StringUtils.isNotEmpty(config)) { String overrideConfig = StringUtils.replace(config, ".xml", ".local.xml"); if (!configureAndWatch(overrideConfig)) { configureAndWatch(config); sce.getServletContext().log("Configured to watch log configuration '" + config + "'"); } else { sce.getServletContext().log("Configured to watch log configuration '" + overrideConfig + "'"); } } }
From source file:de.mgd.simplesoundboard.service.DefaultSoundResourceService.java
private String enhanceName(final String fileName) { return StringUtils.replace(FilenameUtils.getBaseName(fileName), "_", " "); }
From source file:net.kamhon.ieagle.aop.SchemaChangeB4Advice.java
public void before(Method m, Object[] args, Object target) throws Throwable { if (StringUtils.isNotBlank(fromSchema) && StringUtils.isNotBlank(toSchema)) if (args.length > 0) { if ((args[0] instanceof String) && isSql((String) args[0])) { String sql = (String) args[0]; sql = StringUtils.replace(sql, fromSchema, toSchema); }// w ww . j a va 2 s . co m } }
From source file:com.discursive.jccook.xml.bean.ReplaceRule.java
public void begin(Attributes attributes) throws Exception { Message message = (Message) digester.getRoot(); String repl = attributes.getValue("search"); String with = attributes.getValue("replace"); String text = message.getText(); String translated = StringUtils.replace(text, repl, with); message.setText(translated);/*from w w w.j av a 2s . co m*/ }