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:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java
String processVariableValue(ByteBuf cb) throws PEException { String value = StringUtils.EMPTY; valueType = MyItemResultCode.fromByte(cb.readByte()); valueCharSet = cb.readInt();/* w ww . j av a 2s .co m*/ valueLen = cb.readInt(); valueBytes = Unpooled.buffer(cb.readableBytes()).order(ByteOrder.LITTLE_ENDIAN); valueBytes.writeBytes(cb); switch (valueType) { case DECIMAL_RESULT: value = processDecimalValue(valueBytes, valueLen); break; case INT_RESULT: value = processIntValue(valueBytes, valueLen); break; case REAL_RESULT: value = Double.toString(valueBytes.readDouble()); break; case STRING_RESULT: value = "'" + StringUtils.replace( MysqlAPIUtils.readBytesAsString(valueBytes, valueLen, CharsetUtil.UTF_8), "'", "''") + "'"; break; case ROW_RESULT: default: throw new PEException( "Unsupported variable type '" + valueType + "' for variable '" + variableName + "'"); } return value; }
From source file:com.painiu.webapp.util.PhotoUtils.java
public static String toLinkURL(String url) { String linkURL = StringUtils.replace(url, "http://photo.", "http://pic."); if (linkURL.endsWith("/")) { linkURL = linkURL.substring(0, linkURL.length() - 1) + ".jpg"; }//from w ww .j a v a 2 s.c o m return linkURL; }
From source file:com.alibaba.otter.shared.common.utils.extension.classpath.FileSystemClassScanner.java
private Class<?> scanInJar(String jarFileName, String className) { ZipFile zipfile = null;//from w w w. ja v a 2 s .c o m try { zipfile = new ZipFile(jarFileName); Enumeration<?> zipenum = zipfile.entries(); ZipEntry entry = null; String tempClassName = null; while (zipenum.hasMoreElements()) { entry = (ZipEntry) zipenum.nextElement(); tempClassName = entry.getName(); if (tempClassName.endsWith(".class")) { tempClassName = StringUtils.replace(FilenameUtils.removeExtension(tempClassName), "/", "."); if (tempClassName.equals(className)) { try { return fileClassLoader.loadClass(className); } catch (Exception ex) { logger.warn("WARN ## load this class has an error,the fileName is = " + className, ex); } } } } } catch (IOException ex) { logger.error(ex.getMessage(), ex); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } } } return null; }
From source file:info.magnolia.cms.beans.config.RotatingVirtualURIMapping.java
/** * {@inheritDoc}//from www. j a v a 2 s. com */ @Override public MappingResult mapURI(String uri) { // delegate the initial processing to RegexpVirtualURIMapping MappingResult mr = super.mapURI(uri); if (mr != null) { if (end > start) { int randomNumber = RandomUtils.nextInt(end - (start - 1)) + start; String randomAsString = StringUtils.leftPad(Integer.toString(randomNumber), padding, '0'); mr.setToURI(StringUtils.replace(mr.getToURI(), RANDOM_PLACEHOLDER, randomAsString)); } else { log.warn("End value must be greater than start value."); } } return mr; }
From source file:edu.ku.brc.dbsupport.DatabaseDriverInfo.java
/** * @param connStr/*w w w.j av a2s . c o m*/ * @return */ protected String subForDataDir(final String connStr) { String dataDir = UIRegistry.getEmbeddedDBPath(); if (StringUtils.isNotEmpty(dataDir)) { dataDir = new File(dataDir).getAbsolutePath(); //log.debug(dataDir); return StringUtils.replace(connStr, "DATADIR", dataDir); //$NON-NLS-1$ } return connStr; }
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
/** * @param inputText/* ww w. ja va 2 s . c om*/ */ protected String translate(final String inputText) { if (inputText.isEmpty()) return ""; //System.out.println("\n"+inputText); Translate.setHttpReferrer("http://www.specifysoftware.org"); try { String text = inputText; boolean hasSpecialChars = false; while (StringUtils.contains(text, "%d") || StringUtils.contains(text, "%s") || StringUtils.contains(text, "\\n")) { text = StringUtils.replace(text, "%d", "99"); text = StringUtils.replace(text, "%s", "88"); text = StringUtils.replace(text, "\\n", " 77 "); hasSpecialChars = true; } Language lang = getLangFromCode(destLocale.getLanguage()); //System.out.println(text); String newText = Translate.execute(text, Language.ENGLISH, lang); if (hasSpecialChars) { while (StringUtils.contains(newText, "77") || StringUtils.contains(newText, "88") || StringUtils.contains(newText, "99")) { newText = StringUtils.replace(newText, "99", "%d"); newText = StringUtils.replace(newText, "88", "%s"); newText = StringUtils.replace(newText, " 77 ", " \\n "); newText = StringUtils.replace(newText, "77 ", "\\n "); newText = StringUtils.replace(newText, " 77", " \\n"); } } //System.out.println(newText); return newText; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.cognifide.cq.cqsm.core.models.ImportSummaryModel.java
public String getFileName() { if (script == null) { return EXECUTION + ".txt"; } else {/*from w w w.j a va 2 s. c o m*/ return EXECUTION + "-" + StringUtils.replace(script.getPath(), ".cqsm", ".txt"); } }
From source file:com.sk89q.craftbook.circuits.ic.ICMechanic.java
public Object[] setupIC(Block block, boolean create) { // if we're not looking at a wall sign, it can't be an IC. if (block.getType() != Material.WALL_SIGN) return null; ChangedSign sign = BukkitUtil.toChangedSign(block); // detect the text on the sign to see if it's any kind of IC at all. Matcher matcher = RegexUtil.IC_PATTERN.matcher(sign.getLine(1)); if (!matcher.matches()) return null; String prefix = matcher.group(2); // TODO: remove after some time to stop converting existing MCA ICs // convert existing MCA ICs to the new [MCXXXX]A syntax if (prefix.equalsIgnoreCase("MCA")) { sign.setLine(1, (StringUtils.replace(sign.getLine(1).toLowerCase(Locale.ENGLISH), "mca", "mc") + "a") .toUpperCase(Locale.ENGLISH)); sign.update(false);//from ww w . j a v a 2s. c o m return setupIC(block, create); } if (sign.getLine(1).toLowerCase(Locale.ENGLISH).startsWith("[mc0")) { if (sign.getLine(1).equalsIgnoreCase("[mc0420]")) sign.setLine(1, "[MC1421]S"); else if (sign.getLine(1).equalsIgnoreCase("[mc0421]")) sign.setLine(1, "[MC1422]S"); else sign.setLine(1, (StringUtils.replace(sign.getLine(1).toLowerCase(Locale.ENGLISH), "mc0", "mc1") + "s") .toUpperCase(Locale.ENGLISH)); sign.update(false); return setupIC(block, create); } if (sign.getLine(1).toLowerCase(Locale.ENGLISH).startsWith("[mcz")) { sign.setLine(1, (StringUtils.replace(sign.getLine(1).toLowerCase(Locale.ENGLISH), "mcz", "mcx") + "s") .toUpperCase(Locale.ENGLISH)); sign.update(false); return setupIC(block, create); } if (!manager.hasCustomPrefix(prefix)) return null; String id = matcher.group(1); if (CraftBookPlugin.inst().getConfiguration().ICsDisabled.contains(id.toLowerCase()) || CraftBookPlugin.inst().getConfiguration().ICsDisabled.contains(id)) return null; //This IC is disabled. // after this point, we don't return null if we can't make an IC: we throw shit, // because it SHOULD be an IC and can't possibly be any other kind of mechanic. // now actually try to pull up an IC of that id number. RegisteredICFactory registration = manager.get(id); if (registration == null) { CraftBookPlugin.logger().warning("\"" + sign.getLine(1) + "\" should be an IC ID, but no IC registered under that ID could be found."); return null; } IC ic; // check if the ic is cached and get that single instance instead of creating a new one if (ICManager.isCachedIC(block.getLocation())) { ic = ICManager.getCachedIC(block.getLocation()); if (ic.getSign().updateSign(sign)) { ICManager.removeCachedIC(block.getLocation()); ic = registration.getFactory().create(sign); if (!sign.getLine(0).equals(ic.getSignTitle()) && !sign.getLine(0).startsWith("=")) { sign.setLine(0, ic.getSignTitle()); sign.update(false); } ic.load(); // add the created ic to the cache ICManager.addCachedIC(block.getLocation(), ic); } } else if (create) { ic = registration.getFactory().create(sign); if (!sign.getLine(0).equals(ic.getSignTitle()) && !sign.getLine(0).startsWith("=")) { sign.setLine(0, ic.getSignTitle()); sign.update(false); } ic.load(); // add the created ic to the cache ICManager.addCachedIC(block.getLocation(), ic); } else return null; // extract the suffix String suffix = ""; String[] str = RegexUtil.RIGHT_BRACKET_PATTERN.split(sign.getLine(1)); if (str.length > 1) { suffix = str[1]; } ICFamily family = registration.getFamilies()[0]; if (suffix != null && !suffix.isEmpty()) { for (ICFamily f : registration.getFamilies()) { if (f.getSuffix().equalsIgnoreCase(suffix)) { family = f; break; } } } // okay, everything checked out. we can finally make it. if (ic instanceof SelfTriggeredIC && (sign.getLine(1).trim().toUpperCase(Locale.ENGLISH).endsWith("S") || ((SelfTriggeredIC) ic).isAlwaysST())) CraftBookPlugin.inst().getSelfTriggerManager().registerSelfTrigger(block.getLocation()); Object[] rets = new Object[3]; rets[0] = id; rets[1] = family; rets[2] = ic; return rets; }
From source file:com.funambol.server.SyncMLCanonizer.java
/** * Replace the '&' with "&" within the message. * * @param message the original message xml * * @return the updated message/*from w ww . j av a 2 s .c om*/ */ private String replaceEntity(String message) { return StringUtils.replace(message, "&", "&"); }
From source file:com.htmlhifive.tools.wizard.utils.H5IOUtils.java
/** * ????. ${PROJECT_NAME}???????./* w ww. ja va 2 s. c o m*/ * * @param shell * @param projectHandle ? * @param fileName ?? * @param varNames ?? */ private static void convertName(Shell shell, IProject projectHandle, String fileName, String[] varNames, String[] varValues) { final IFile file = projectHandle.getFile(new Path(fileName)); if (!file.isAccessible()) { return; } InputStream is = null; InputStream is2 = null; try { is = file.getContents(); String text = IOUtils.toString(is, file.getCharset()); for (int i = 0; i < varNames.length; i++) { text = StringUtils.replace(text, "${" + varNames[i] + "}", varValues[i]); } is2 = IOUtils.toInputStream(text, file.getCharset()); file.setContents(is2, true, true, null); } catch (IOException e) { H5LogUtils.putLog(e, Messages.SE0024, fileName); //H5LogUtils.showLog(e, Messages.SE0022, Messages.SE0024, fileName); } catch (CoreException e) { H5LogUtils.putLog(e, Messages.SE0024, fileName); //H5LogUtils.showLog(e, Messages.SE0022, Messages.SE0024, fileName); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(is2); } }