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:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) { buffer.setLength(0);//from w w w. j a v a 2s. co m if (localName.equals("FIELD")) { if (doColSizes) { FieldDef fldDef = new FieldDef(); fields.add(fldDef); for (int i = 0; i < attrs.getLength(); i++) { String attr = attrs.getLocalName(i); String value = attrs.getValue(i); if (attr.equals("EMPTYOK")) { fldDef.setNullable(value.equals("YES")); } else if (attr.equals("NAME")) { value = StringUtils.capitalize(value.trim()); value = StringUtils.deleteWhitespace(value); //value = StringUtils.replace(value, "", "n"); value = StringUtils.replace(value, ":", ""); value = StringUtils.replace(value, ";", ""); //value = StringUtils.replace(value, "", "a"); value = StringUtils.replace(value, ".", ""); //value = StringUtils.replace(value, "", "a"); //value = StringUtils.replace(value, "", "a"); value = StringUtils.replace(value, "/", ""); //System.out.println(value); if ((value.charAt(0) >= '0' && value.charAt(0) <= '9') || value.equalsIgnoreCase("New") || value.equalsIgnoreCase("Group")) { value = "Fld" + value; } fldDef.setName(value); } else if (attr.equals("TYPE")) { if (value.equals("TEXT")) { fldDef.setType(DataType.eText); } else if (value.equals("NUMBER")) { fldDef.setType(DataType.eNumber); } else if (value.equals("DATE")) { fldDef.setType(DataType.eDate); } else if (value.equals("TIME")) { fldDef.setType(DataType.eTime); } else { System.err.println("Unknown Type[" + value + "]"); } } //System.out.println(attrs.getLocalName(i)+" = "+attrs.getValue(i)); } } } else if (localName.equals("ROW")) { for (int i = 0; i < attrs.getLength(); i++) { String attr = attrs.getLocalName(i); String value = attrs.getValue(i); if (attr.equals("RECORDID")) { rowNum = Integer.parseInt(value); break; } } } }
From source file:com.google.gdt.eclipse.designer.core.wizards.ProjectWizardTest.java
public void test_for21() throws Exception { Activator.getStore().setValue(Constants.P_GWT_LOCATION, GTestUtils.getLocation_21()); ProjectWizard.configureProjectAsGWTProject(m_javaProject); assertTrue(Utils.isGWTProject(m_javaProject)); {// w ww. j a va 2 s .c o m String classPath = getFileContent(".classpath"); classPath = StringUtils.replace(classPath, "\r\n", "\n"); assertEquals( getSourceDQ(new String[] { "<?xml version='1.0' encoding='UTF-8'?>", "<classpath>", " <classpathentry kind='con' path='org.eclipse.jdt.launching.JRE_CONTAINER'/>", " <classpathentry kind='src' path='src'/>", " <classpathentry kind='var' path='GWT_HOME/gwt-user.jar'/>", " <classpathentry kind='output' path='war/WEB-INF/classes'/>", "</classpath>" }), classPath); } assertTrue(getFolder0("war").exists()); assertTrue(getFolder0("war/WEB-INF").exists()); assertTrue(getFolder0("war/WEB-INF/classes").exists()); assertTrue(getFolder0("war/WEB-INF/lib").exists()); assertTrue(getFile("war/WEB-INF/lib/gwt-servlet.jar").exists()); }
From source file:net.sf.click.jquery.examples.page.SourceViewer.java
private String getEncodedLine(String line) { if (isHtml) { line = ClickUtils.escapeHtml(line); for (int i = 0; i < HTML_KEYWORDS.length; i++) { String keyword = HTML_KEYWORDS[i]; line = renderHtmlKeywords(line, keyword); }/*from w w w . j av a2s . c o m*/ for (int i = 0; i < VELOCITY_KEYWORDS.length; i++) { String keyword = VELOCITY_KEYWORDS[i]; line = renderVelocityKeywords(line, keyword); } String renderedDollar = "<font color=\"red\">$</font>"; line = StringUtils.replace(line, "$", renderedDollar); } else if (isXml) { line = ClickUtils.escapeHtml(line); for (int i = 0; i < XML_KEYWORDS.length; i++) { String keyword = XML_KEYWORDS[i]; line = renderXmlKeywords(line, keyword); } } else { line = ClickUtils.escapeHtml(line); } return line; }
From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java
public static String cleanPhenotype(String s) { String clean = Translate.decode(s).replace("<", "").replace(">", ""); clean = StringUtils.replace(clean, "script", ""); clean = StringUtils.replace(clean, "%", ""); clean = StringUtils.replace(clean, "#", ""); clean = StringUtils.replace(clean, ";", ""); clean = StringUtils.replace(clean, "\"", ""); clean = StringUtils.replace(clean, "$", ""); clean = StringUtils.replace(clean, "(", ""); clean = StringUtils.replace(clean, ")", ""); clean = StringUtils.replace(clean, "/", ""); clean = StringUtils.replace(clean, "\\", ""); if (clean.length() == 0) { clean = "empty"; }//from w w w .j a va 2 s .c o m return clean; }
From source file:com.hangum.tadpole.rdb.core.editors.main.composite.MessageComposite.java
/** * new error message//from ww w .j av a2 s . c om * * @param userDBDAO * @param requestQuery * @param tadpoleMessageDAO */ public void addErrorAfterRefresh(UserDBDAO userDBDAO, RequestQuery requestQuery, TadpoleMessageDAO tadpoleMessageDAO) { String strNewMessage = " "; //$NON-NLS-1$ String strSearchError = userDBDAO.getDbms_type() + " "; //$NON-NLS-1$ Throwable throwable = tadpoleMessageDAO.getThrowable(); if (throwable == null) { strNewMessage = Messages.get().SystemMessage; strNewMessage += tadpoleMessageDAO.getStrMessage(); strSearchError = tadpoleMessageDAO.getStrMessage(); textMessage.setBackground(SWTResourceManager.getColor(248, 248, 255)); } else { strNewMessage = Messages.get().ErrorMessage; Throwable cause = throwable.getCause(); if (throwable instanceof SQLException) { strNewMessage += sqlExceptionToMsg((SQLException) throwable, tadpoleMessageDAO); strSearchError += sqlExceptionToSearchMsg((SQLException) throwable, tadpoleMessageDAO); } else if (cause instanceof SQLException) { strNewMessage += sqlExceptionToMsg((SQLException) cause, tadpoleMessageDAO); strSearchError += sqlExceptionToSearchMsg((SQLException) cause, tadpoleMessageDAO); } else { strNewMessage += tadpoleMessageDAO.getStrMessage(); strSearchError += tadpoleMessageDAO.getStrMessage(); } // sqlite ?,? .--;; if (userDBDAO.getDBDefine() == DBDefine.SQLite_DEFAULT) { strSearchError = throwable.getMessage(); } textMessage.setBackground(SWTResourceManager.getColor(255, 228, 225)); } // // first show last error message // final String strOldText = textMessage.getText(); // if ("".equals(strOldText)) { //$NON-NLS-1$ textMessage.setText(strNewMessage); try { String strDeleteWhiteSpace = StringUtils.replace(strSearchError, "\"", "'"); lblGoogleSearch.setText("<a href=\"http://www.google.com/search?q=" + strDeleteWhiteSpace + "\" target='_blank'>" + strDeleteWhiteSpace + "</a>"); lblGoogleSearch.getParent().layout(); } catch (Exception e) { logger.error("===" + strSearchError + "===="); logger.error("parse", e); } // } else { // textMessage.setText(strNewMessage + PublicTadpoleDefine.LINE_SEPARATOR + PublicTadpoleDefine.LINE_SEPARATOR + strOldText); // } // textMessage.setSelection(0, strNewMessage.length()); // textMessage.setFocus(); }
From source file:com.sun.socialsite.util.Utilities.java
/** * Autoformat./*ww w. j ava 2 s . co m*/ */ public static String autoformat(String s) { String ret = StringUtils.replace(s, "\n", "<br />"); return ret; }
From source file:com.vmware.bdd.usermgmt.SssdConfigurationGenerator.java
public String getConfigurationContent(UserMgmtServer userMgmtServer, String[] groups) { load();/* w w w . j a v a 2s . c o m*/ String configContent = new String(getTemplateContent(userMgmtServer.getType())); ArrayList<String[]> replacementList = new ArrayList<>(); replacementList.add(new String[] { "LDAP_GROUP_SEARCH_BASE_VALUE", userMgmtServer.getBaseGroupDn() }); replacementList.add(new String[] { "LDAP_USER_SEARCH_BASE_VALUE", userMgmtServer.getBaseUserDn() }); replacementList.add(new String[] { "LDAP_URI_VALUE", userMgmtServer.getPrimaryUrl() }); replacementList.add(new String[] { "LDAP_DEFAULT_BIND_DN_VALUE", userMgmtServer.getUserName() }); replacementList.add(new String[] { "LDAP_DEFAULT_AUTHTOK_VALUE", userMgmtServer.getPassword() }); StringBuilder stringBuilder = new StringBuilder(); if (groups.length > 1) { stringBuilder.append("(|"); for (String group : groups) { stringBuilder.append("(memberOf=cn=").append(group).append(",") .append(userMgmtServer.getBaseGroupDn()).append(')'); } stringBuilder.append(')'); } else { stringBuilder.append("memberOf=cn=").append(groups[0]).append(",") .append(userMgmtServer.getBaseGroupDn()); } replacementList.add(new String[] { "LDAP_ACCESS_FILTER_VALUE", stringBuilder.toString() }); for (String[] replacement : replacementList) { configContent = StringUtils.replace(configContent, replacement[0], replacement[1]); } return configContent; }
From source file:de.awtools.config.AbstractGlueConfig.java
/** * Ersetzt die ${...} Platzhalter in einem String. Die Ersetzung werden * in einer Map gelagert. Die Schlssel reprsentieren die Platzhalter * im String. Die Ersetzungen sind die Werte der Schlssel in der * <code>placeholders</code> Map. * * @param string Der zu prfende String./*from w ww .jav a 2 s. c om*/ * @param placeholders Die Ersetzungen. * @return Der berarbeitete String. */ public static String replacePlaceholder(final String string, final Map<String, String> placeholders) { String result = string; String[] keys = StringUtils.substringsBetween(string, "${", "}"); if (keys != null) { for (String key : keys) { String value = placeholders.get(key); if (value != null) { StringBuilder sb = new StringBuilder("${").append(key).append("}"); result = StringUtils.replace(result, sb.toString(), value); } } } return result; }
From source file:eionet.cr.harvest.UploadHarvest.java
/** * Harvest finished with errors, store relevant metadata for harves source. * * @param error Error message.//from www . j ava 2s . co m * @param noOfTriples number of triples. */ private void finishWithError(Throwable error, int noOfTriples) { // update context source DTO with the results of this harvest getContextSourceDTO().setStatements(noOfTriples); getContextSourceDTO().setLastHarvest(new Date()); getContextSourceDTO().setLastHarvestFailed(error != null); // add harvest message about the given error if it's not null if (error != null) { String message = error.getMessage() == null ? error.toString() : error.getMessage(); String stackTrace = Util.getStackTrace(error); stackTrace = StringUtils.replace(stackTrace, "\r", ""); addHarvestMessage(message, HarvestMessageType.ERROR, stackTrace); } // add source metadata resulting from this harvest String firstSeen = formatDate(getContextSourceDTO().getTimeCreated()); String lastRefreshed = formatDate(new Date()); addSourceMetadata(Predicates.CR_FIRST_SEEN, ObjectDTO.createLiteral(firstSeen, XMLSchema.DATETIME)); addSourceMetadata(Predicates.CR_LAST_REFRESHED, ObjectDTO.createLiteral(lastRefreshed, XMLSchema.DATETIME)); if (error != null) { addSourceMetadata(Predicates.CR_ERROR_MESSAGE, ObjectDTO.createLiteral(error.toString())); } }
From source file:com.fengduo.bee.service.impl.file.FileServiceImpl.java
@Override public Result delFileByPath(String filePath) { if (StringUtils.isEmpty(filePath)) { return Result.failed(); }//from w w w .j a v a 2 s . co m filePath = StringUtils.replace(filePath, STATIC_TMP_IMG, StringUtils.EMPTY); String tmpPath = UPLOAD_TMP_PATH.replaceAll(STATIC_TMP_IMG, ""); File file = new File(tmpPath + filePath); if (file == null || file.isFile()) { FileUtils.deleteQuietly(file); return Result.success("?", null); } return Result.failed(); }