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.mayo.qdm.webapp.rest.controller.TranslatorController.java
/** * Gets the exceuctions./*from www . jav a 2s. c o m*/ * * @param request the request * @return the exceuctions * @throws Exception the exception */ @RequestMapping(value = "executor/executions", method = RequestMethod.GET) public Object getExceuctions(HttpServletRequest request) throws Exception { String requestUrl = request.getRequestURL().toString(); requestUrl = StringUtils.replace(requestUrl, "/executions", "/execution/{id}/{resource}"); UriTemplate template = new UriTemplate(requestUrl); Set<ExecutionInfo> dataFiles = this.fileSystemResolver.getExecutionInfo(); Executions executions = new Executions(dataFiles, template); String xml = xmlProcessor.executionsToXml(executions); return this.buildResponse(request, executions, xml); }
From source file:cn.fql.utility.FileUtility.java
/** * Copy source folder's content to a new folder, if there are existed duplicated files and overwrite * flag is true, it might overwrite it//from w ww . ja v a 2 s. c o m * * @param sourceFolder source folder path * @param newFolder new folder path * @param forceOverwrite determine whether it is required to overwrite for duplicated files */ public static void copyFolder(String sourceFolder, String newFolder, boolean forceOverwrite) { String oldPath = StringUtils.replace(sourceFolder, "/", File.separator); String newPath = StringUtils.replace(newFolder, "/", File.separator); if (!oldPath.endsWith(File.separator)) { oldPath = oldPath + File.separator; } if (!newPath.endsWith(File.separator)) { newPath = newPath + File.separator; } new File(newPath).mkdirs(); File sourceDir = new File(oldPath); String[] files = sourceDir.list(); File oldFile; File newFile; for (int i = 0; i < files.length; i++) { oldFile = new File(oldPath + files[i]); newFile = new File(newPath + files[i]); if (oldFile.isFile() && (!forceOverwrite || (!newFile.exists() || oldFile.length() != newFile.length() || oldFile.lastModified() > newFile.lastModified()))) { copyFile(oldFile.getPath(), newFile.getPath()); } if (oldFile.isDirectory()) { copyFolder(oldPath + files[i], newPath + files[i], forceOverwrite); } } }
From source file:com.sk89q.craftbook.mechanics.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 w w w . ja 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 (disabledICs.contains(id.toLowerCase()) || disabledICs.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."); block.breakNaturally(); 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.sourcemeter.analyzer.cpp.batch.SourceMeterCppSensor.java
@Override public void analyse(Project module, SensorContext context) { String analyseMode = this.settings.getString("sonar.analysis.mode"); this.projectName = settings.getString("sonar.projectKey"); this.projectName = StringUtils.replace(projectName, ":", "_"); if ("incremental".equals(analyseMode)) { LOG.warn("Incremental mode is on. There are no metric based (INFO level) issues in this mode."); this.isIncrementalMode = true; }// www . ja v a2 s. c o m this.resultGraph = FileHelper.getSMSourcePath(settings, fileSystem, '-') + File.separator + projectName + ".graph"; long startTime = System.currentTimeMillis(); LOG.info(" Graph: " + resultGraph); try { loadDataFromGraphBin(this.resultGraph, project, sensorContext); } catch (GraphlibException e) { throw new SonarException("Error during graph loading!", e); } LOG.info(" Load data from graph bin and save resources and metrics done: " + (System.currentTimeMillis() - startTime) + MS); }
From source file:com.bibisco.manager.SpellCheckManager.java
public static JSONObject spell(String pStrText) { JSONObject lJSONObjectResult;/*from ww w .j a va2 s . c om*/ mLog.debug("Start spell(String)"); SpellCheckManager lSpellCheckManager = getInstance(ContextManager.getInstance().getProjectLanguage()); Map<String, Integer> lMapWordOccurences = TextEditorManager.getWordsOccurrencesMap(pStrText, true); try { lJSONObjectResult = new JSONObject(); JSONArray lJSONArrayMisspelledWords = new JSONArray(); lJSONObjectResult.put("misspelledWords", lJSONArrayMisspelledWords); int j = 0; for (String lStrWord : lMapWordOccurences.keySet()) { if (lSpellCheckManager.misspelled(lStrWord)) { List<String> lListSuggestions = lSpellCheckManager.getSuggestions(lStrWord); StringBuilder lStringBuilder = new StringBuilder(); for (int i = 0; i < lListSuggestions.size(); i++) { if (i > 0) { lStringBuilder.append("|"); } lStringBuilder.append(StringUtils.replace(lListSuggestions.get(i), "'", "'")); } JSONObject lJSONObject = new JSONObject(); lJSONObject.put("misspelledWord", lStrWord); lJSONObject.put("occurences", lMapWordOccurences.get(lStrWord)); lJSONObject.put("suggestions", lStringBuilder.toString()); lJSONArrayMisspelledWords.put(j++, lJSONObject); } } } catch (JSONException e) { mLog.error(e); throw new BibiscoException(e, BibiscoException.FATAL); } mLog.debug("End spell(String)"); return lJSONObjectResult; }
From source file:com.sourcemeter.analyzer.python.batch.SourceMeterPythonSensor.java
@Override public void analyse(Project module, SensorContext context) { this.projectName = this.settings.getString("sonar.projectKey"); this.projectName = StringUtils.replace(this.projectName, ":", "_"); String analyseMode = this.settings.getString("sonar.analysis.mode"); if ("incremental".equals(analyseMode)) { LOG.warn("Incremental mode is on. There are no metric based (INFO level) issues in this mode."); this.isIncrementalMode = true; }// w w w. j a va 2 s . c om this.resultGraph = FileHelper.getSMSourcePath(settings, fileSystem, '_') + File.separator + this.projectName + ".graph"; long startTime = System.currentTimeMillis(); LOG.info(" Graph: " + resultGraph); try { loadDataFromGraphBin(this.resultGraph, project, sensorContext); } catch (GraphlibException e) { throw new SonarException("Error during graph loading!", e); } LOG.info(" Load data from graph bin and save resources and metrics done: " + (System.currentTimeMillis() - startTime) + MS); }
From source file:com.prowidesoftware.swift.model.field.Field335Test.java
@Test public void testGetValue1() { Field335 f = new Field335(); String v = EXAMPLE1_FIELD_335; f = new Field335(v); assertEquals(StringUtils.replace(v, "\n", FINWriterVisitor.SWIFT_EOL), f.getValue()); }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractComponent.java
public void assignAutoDebugId() { AppUI ui = AppUI.getCurrent();/*from w w w .j a v a 2 s . co m*/ if (ui != null && ui.isTestMode()) { String alternativeDebugId = getAlternativeDebugId(); // always change cuba id, do not assign auto id for components if (getId() == null && component != null) { component.setCubaId(alternativeDebugId); } if (frame == null || StringUtils.isEmpty(frame.getId())) return; String fullFrameId = ComponentsHelper.getFullFrameId(frame); TestIdManager testIdManager = ui.getTestIdManager(); String candidateId = fullFrameId + "." + alternativeDebugId; if (getDebugId() != null) { String postfix = StringUtils.replace(getDebugId(), testIdManager.normalize(candidateId), ""); if (StringUtils.isEmpty(postfix) || NumberUtils.isDigits(postfix)) { // do not assign new Id return; } } setDebugId(testIdManager.getTestId(candidateId)); } }
From source file:de.awtools.basic.file.AWToolsFileUtilsTest.java
@Test public void testStringUtils() { assertThat(StringUtils.replace("abc/./abc/./abc", "/./", "/")).isEqualTo("abc/abc/abc"); assertThat(StringUtils.replace("abc\\.\\abc\\.\\abc", "\\.\\", "/")).isEqualTo("abc/abc/abc"); }
From source file:com.sourcemeter.analyzer.java.batch.SourceMeterJavaSensor.java
/** * {@inheritDoc}/* www . ja v a2s. com*/ */ @Override public void analyse(Project project, SensorContext sensorContext) { this.projectName = this.settings.getString("sonar.projectKey"); this.projectName = StringUtils.replace(this.projectName, ":", "_"); String analyseMode = this.settings.getString("sonar.analysis.mode"); if ("incremental".equals(analyseMode)) { LOG.warn("Incremental mode is on. There are no metric based (INFO level) issues in this mode."); this.isIncrementalMode = true; } this.resultGraph = FileHelper.getSMSourcePath(settings, fileSystem, '-') + File.separator + this.projectName + ".graph"; long startTime = System.currentTimeMillis(); LOG.info(" Graph: " + resultGraph); try { loadDataFromGraphBin(this.resultGraph, project, sensorContext); } catch (GraphlibException e) { throw new SonarException("Error during graph loading!", e); } LOG.info(" Load data from graph bin and save resources and metrics done: " + (System.currentTimeMillis() - startTime) + MS); }