List of usage examples for org.apache.commons.lang3 StringUtils replaceEach
public static String replaceEach(final String text, final String[] searchList, final String[] replacementList)
Replaces all occurrences of Strings within another String.
From source file:com.ipcglobal.fredimport.process.DistinctCategories.java
/** * Creates the file name./* ww w .j a v a 2s.co m*/ * * @param outputPathRptSql the output path rpt sql * @param subDir the sub dir * @param currCategory1Name the curr category1 name * @param xlsRow the xls row * @return the string */ private String createPathNameExtSqlScript(String outputPathRptSql, String subDir, String currCategory1Name, int xlsRow) { // Percent is a special case - change % to Pct currCategory1Name = currCategory1Name.replace("%", "Pct"); // Slash is a special case - probably a date - change to dash currCategory1Name = currCategory1Name.replace("/", "-"); final String[] searchList = { "\\", "(", ")", ".", ",", "~", "`", "!", "@", "#", "$", "^", "&", "*", "+", "=", "{", "}", "[", "]", ":", ";", "'", "\"", "?", "<", ">" }; final String[] replacementList = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", }; //final String[] replacementList = {"_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", }; String result = outputPathRptSql + subDir + "t" + xlsRow + "_" + StringUtils.replaceEach(currCategory1Name, searchList, replacementList); if (result.length() > 96) result = result.substring(0, 96); // 100 is max for tar return result + ".qvs"; }
From source file:info.novatec.testit.livingdoc.util.ClassUtils.java
public static String[] escapeValues(String[] values) { for (int index = 0; index < values.length; index++) { values[index] = StringUtils.replaceEach(values[index], new String[] { "%3B" }, new String[] { ";" }); }//from ww w . j av a 2 s .co m return values; }
From source file:com.qcadoo.model.api.search.SearchRestrictions.java
private static String convertWildcards(final String value) { return StringUtils.replaceEach(value, QCADOO_WILDCARDS, HIBERNATE_WILDCARDS); }
From source file:net.launchpad.jabref.plugins.ZentralSearch.java
private String replaceUmlaute(String entry) { String res = StringUtils.replaceEach(entry, // new String[] { "\\\"a", "\\\"o", "\\\"u" }, // new String[] { "", "", "" }); res = StringUtils.replaceEach(res, // new String[] { "\\\"A", "\\\"O", "\\\"U" }, // new String[] { "", "", "" }); return res;/* ww w . ja v a2 s . c o m*/ }
From source file:com.hesine.manager.generate.Generate.java
public static void execute(File curProjectPath, String packageName, String moduleName, Map<String, String> table, List<Map<String, String>> fileds) { // ========== ?? ==================== // ??????/*from w w w. j av a 2 s.c om*/ // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? // String packageName = "com.hesine.manager"; // String moduleName = "function"; // ???sys // String moduleName = ""; // ???sys // String tableName = "tb_product"; // ???sys // String subModuleName = ""; // ????? // String className = "product"; // ??product // String classAuthor = "Jason"; // ThinkGem // String functionName = "?"; // ?? String tableName = table.get("tableName"); // ???sys String subModuleName = ""; // ????? String className = table.get("className"); // ??product String classAuthor = "Jason"; // ThinkGem String functionName = table.get("comment"); // ?? // ??? Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } // StringUtils.isBlank(moduleName) || if (StringUtils.isBlank(packageName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = curProjectPath; // while(!new File(projectPath.getPath()+separator+"src"+separator+"main").exists()){ // projectPath = projectPath.getParentFile(); // } logger.info("Project Path: {}", projectPath); // ? String tmpProjectPath = "/Users/zhanghongbing/Workspaces/Projects/hesine-projects/github-framework/hesine-demo/hesine-portal"; String tplPath = StringUtils.replace(tmpProjectPath + "/src/main/java/com/hesine/manager/generate/template", "/", separator); // String tplPath = StringUtils.replace(projectPath+"/src/main/java/com/hesine/manager/generate/template", "/", separator); logger.info("Template Path: {}", tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); logger.info("Java Path: {}", javaPath); // Xml String xmlPath = StringUtils.replace(projectPath + "/src/main/resources/mybatis", "/", separator); logger.info("Xml Path: {}", xmlPath); // String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator); logger.info("View Path: {}", viewPath); // ??? Map<String, Object> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); model.put("moduleName", StringUtils.lowerCase(moduleName)); model.put("subModuleName", StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : ""); model.put("className", StringUtils.uncapitalize(className)); model.put("ClassName", StringUtils.capitalize(className)); model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); model.put("classVersion", DateUtils.getDate()); model.put("functionName", functionName); // model.put("tableName", model.get("moduleName")+(StringUtils.isNotBlank(subModuleName) // ?"_"+StringUtils.lowerCase(subModuleName):"")+"_"+model.get("className")); model.put("tableName", tableName); model.put("urlPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "") + "/" + model.get("className")); model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "") + ":" + model.get("className")); model.put("fileds", fileds); // ? Entity FileGenUtils.generateEntity(tplPath, javaPath, model); // ? sqlMap FileGenUtils.generateSqlMap(tplPath, xmlPath, model); // ? Model FileGenUtils.generateModel(tplPath, javaPath, model); // ? Dao FileGenUtils.generateDao(tplPath, javaPath, model); // ? Service FileGenUtils.generateService(tplPath, javaPath, model); // ? ServiceImpl FileGenUtils.generateServiceImpl(tplPath, javaPath, model); // ? Controller FileGenUtils.generateController(tplPath, javaPath, model); // // // ? add.ftl // FileGenUtils.generateAddFtl(tplPath, viewPath, model); // // // ? edit.ftl // FileGenUtils.generateEditFtl(tplPath, viewPath, model); // // ? list.ftl // FileGenUtils.generateListFtl(tplPath, viewPath, model); logger.info("Generate Success."); }
From source file:de.azapps.mirakel.model.task.TaskBase.java
public void setContent(String content) { if (this.content != null && this.content.equals(content)) return;// w w w . j a v a 2 s . c o m if (content != null) { this.content = StringUtils.replaceEach(content.trim(), new String[] { "\\n", "\\\"", "\b" }, new String[] { "\n", "\"", "" }); } else { this.content = null; } this.edited.put(CONTENT, true); }
From source file:com.moneydance.modules.features.mdvenmoimporter.VenmoImporterWindow.java
public void downloadVenmoTransactions() { String venmoPositivecharge = "pay"; String venmoUserId;/*from ww w. j a v a2 s. c o m*/ AccountBook book = extension.getUnprotectedContext().getCurrentAccountBook(); Account targetAcc = book.getAccountByUUID(targetAcctId); if (targetAcc == null) { JOptionPane.showMessageDialog(this, "\n There was a problem with your account selection."); return; //Should never happen, as the combobox forces you to call the method after selecting a valid account id. } OnlineTxnList txnlist = targetAcc.getDownloadedTxns(); URL VenmoURL; try { VenmoURL = new URL("https://api.venmo.com/v1/me?access_token=" + venmoToken); BufferedReader in = new BufferedReader(new InputStreamReader(VenmoURL.openStream())); JSONObject tId; tId = new JSONObject(in.readLine()); if (tId.has("error")) { throw new Exception("The request to Venmo had the following error:\n\n" + tId.getJSONObject("error").getInt("code") + " " + tId.getJSONObject("error").getString("message")); } venmoUserId = tId.getJSONObject("data").getJSONObject("user").getString("id"); in.close(); VenmoURL = new URL("https://api.venmo.com/v1/payments?limit=" + venmoDownloadTrabsactionLimit + "&access_token=" + venmoToken); in = new BufferedReader(new InputStreamReader(VenmoURL.openStream())); JSONObject tr; tr = new JSONObject(in.readLine()); if (tr.has("error")) { throw new Exception("The request to Venmo had the following error:\n\n" + tr.getJSONObject("error").getInt("code") + " " + tr.getJSONObject("error").getString("message")); } double amount = 0; String comment; String remotetxnId; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleDateFormat output = new SimpleDateFormat("yyyyMMdd"); int date; OnlineTxn otrans; for (int i = 0; i < tr.getJSONArray("data").length(); i++) { JSONObject t = tr.getJSONArray("data").getJSONObject(i); if (!t.getString("status").equals("settled")) continue; if (t.getJSONObject("actor").getString("id").equals(venmoUserId)) { if (t.getString("action").equals(venmoPositivecharge)) { amount = -t.getDouble("amount"); } else { amount = +t.getDouble("amount"); } } else if (t.getJSONObject("target").getString("type").equals("user") && t.getJSONObject("target").getJSONObject("user").getString("id").equals(venmoUserId)) { if (t.getString("action").equals(venmoPositivecharge)) { amount = +t.getDouble("amount"); } else { amount = -t.getDouble("amount"); } } //must be in the same order as descriptionFields String[] descriptionValues = { Double.toString(t.getDouble("amount")), t.getString("action"), t.getJSONObject("actor").getString("display_name"), t.getJSONObject("actor").getString("username"), t.getJSONObject("target").getJSONObject("user").getString("display_name"), t.getJSONObject("target").getJSONObject("user").getString("username"), t.getString("note"), t.getString("date_created"), t.getString("date_completed"), t.getString("note") }; //private static final String[] descriptionFields = {"@amount", "@action", "@actor", "@actor_username", "@target", "@target_username", "@note", "@date_created", "@date_completed", "@id"}; comment = StringUtils.replaceEach(descriptionFormat, descriptionFields, descriptionValues); date = Integer.parseInt(output.format(sdf.parse(t.getString("date_completed")))); remotetxnId = t.getString("id"); otrans = txnlist.newTxn(); otrans.setAmount((long) Math.round(amount * 100)); otrans.setMemo(comment); otrans.setDatePostedInt(date); otrans.setFITxnId(remotetxnId); txnlist.addNewTxn(otrans); } in.close(); } catch (NumberFormatException | JSONException | ParseException e) { //Date format not recognized. Should never happen given the venmo api JOptionPane.showMessageDialog(this, e.toString()); e.printStackTrace(); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.toString() + "\n\n See the moneydance console for additional details on the error."); e.printStackTrace(); } targetAcc.downloadedTxnsUpdated(); com.moneydance.apps.md.controller.Main mainApp = (com.moneydance.apps.md.controller.Main) extension .getUnprotectedContext(); OnlineManager onlineMgr = new OnlineManager((MoneydanceGUI) mainApp.getUI()); onlineMgr.processDownloadedTxns(targetAcc); }
From source file:gobblin.data.management.copy.hive.HiveDataset.java
/*** * Replace various tokens (DB, TABLE, LOGICAL_DB, LOGICAL_TABLE) with their values. * * @param datasetConfig The config object that needs to be resolved with final values. * @param realDbAndTable Real DB and Table . * @param logicalDbAndTable Logical DB and Table. * @return Resolved config object./*from w w w. j a v a 2 s . c o m*/ */ @VisibleForTesting protected static Config resolveConfig(Config datasetConfig, DbAndTable realDbAndTable, DbAndTable logicalDbAndTable) { Preconditions.checkNotNull(datasetConfig, "Dataset config should not be null"); Preconditions.checkNotNull(realDbAndTable, "Real DB and table should not be null"); Preconditions.checkNotNull(logicalDbAndTable, "Logical DB and table should not be null"); Properties resolvedProperties = new Properties(); Config resolvedConfig = datasetConfig.resolve(); for (Map.Entry<String, ConfigValue> entry : resolvedConfig.entrySet()) { if (ConfigValueType.LIST.equals(entry.getValue().valueType())) { List<String> rawValueList = resolvedConfig.getStringList(entry.getKey()); List<String> resolvedValueList = Lists.newArrayList(); for (String rawValue : rawValueList) { String resolvedValue = StringUtils.replaceEach(rawValue, new String[] { DATABASE_TOKEN, TABLE_TOKEN, LOGICAL_DB_TOKEN, LOGICAL_TABLE_TOKEN }, new String[] { realDbAndTable.getDb(), realDbAndTable.getTable(), logicalDbAndTable.getDb(), logicalDbAndTable.getTable() }); resolvedValueList.add(resolvedValue); } StringBuilder listToStringWithQuotes = new StringBuilder(); for (String resolvedValueStr : resolvedValueList) { if (listToStringWithQuotes.length() > 0) { listToStringWithQuotes.append(","); } listToStringWithQuotes.append("\"").append(resolvedValueStr).append("\""); } resolvedProperties.setProperty(entry.getKey(), listToStringWithQuotes.toString()); } else { String resolvedValue = StringUtils.replaceEach(resolvedConfig.getString(entry.getKey()), new String[] { DATABASE_TOKEN, TABLE_TOKEN, LOGICAL_DB_TOKEN, LOGICAL_TABLE_TOKEN }, new String[] { realDbAndTable.getDb(), realDbAndTable.getTable(), logicalDbAndTable.getDb(), logicalDbAndTable.getTable() }); resolvedProperties.setProperty(entry.getKey(), resolvedValue); } } return ConfigUtils.propertiesToConfig(resolvedProperties); }
From source file:com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocationCreator.java
private String createBdioName(final String codeLocationName, final IntegrationEscapeUtil integrationEscapeUtil) { final String filenameRaw = StringUtils.replaceEach(codeLocationName, new String[] { "/", "\\", " " }, new String[] { "_", "_", "_" }); final String filename = integrationEscapeUtil.escapeForUri(filenameRaw); return filename + ".jsonld"; }
From source file:de.gbv.ole.Marc21ToOleBulk.java
/** * Write data to bib output.//from www . ja v a 2 s .c o m * * Does Unicode NFC normalization. * * Masks these four characters: \n \r \t \\ * This masking is needed for LOAD DATA INFILE. * * @param data data to write * @throws SAXException on write error */ private void write(final String data) throws SAXException { String normalized = Normalizer.normalize(data, Normalizer.Form.NFC); char[] charArray = StringUtils.replaceEach(normalized, new String[] { "\n", "\r", "\t", "\\", }, new String[] { "\\\n", "\\\r", "\\\t", "\\\\", }).toCharArray(); handler.characters(charArray, 0, charArray.length); }