List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineManagerTest.java
/** * Test case for {@link MicroPipelineManager#getPipelineIds()} with previously registered {@link MicroPipeline} instance *//*from w ww . j ava 2s .c o m*/ @Test public void testGetPipelineIds_withExistingConfiguration() throws Exception { MicroPipelineConfiguration cfg = new MicroPipelineConfiguration(); cfg.setId("testExecutePipeline_withValidConfiguration"); MicroPipeline pipeline = Mockito.mock(MicroPipeline.class); Mockito.when(pipeline.getId()).thenReturn(cfg.getId()); MicroPipelineFactory factory = Mockito.mock(MicroPipelineFactory.class); Mockito.when(factory.instantiatePipeline(cfg, executorService)).thenReturn(pipeline); MicroPipelineManager manager = new MicroPipelineManager("id", factory, executorService); Assert.assertTrue("The result must be empty", manager.getPipelineIds().isEmpty()); Assert.assertEquals("Values must be equal", StringUtils.lowerCase(StringUtils.trim(cfg.getId())), manager.executePipeline(cfg)); Assert.assertEquals("Values must be equal", 1, manager.getNumOfRegisteredPipelines()); Assert.assertEquals("The set must contain 1 element", 1, manager.getPipelineIds().size()); Assert.assertTrue("The set must contain the identifier", manager.getPipelineIds().contains(StringUtils.lowerCase(StringUtils.trim(cfg.getId())))); Mockito.verify(factory).instantiatePipeline(cfg, executorService); }
From source file:com.ottogroup.bi.spqr.metrics.MetricsHandler.java
/** * {@link ScheduledReporter#start(long, java.util.concurrent.TimeUnit) Starts} the referenced {@link ScheduledReporter} * @param id/*from w ww . ja v a2 s.co m*/ * @param period * @param unit */ public void startScheduledReporter(final String id, final int period, final TimeUnit unit) { String key = StringUtils.lowerCase(StringUtils.trim(id)); ScheduledReporter scheduledReporter = this.scheduledReporters.get(key); if (scheduledReporter != null) { scheduledReporter.start(period, unit); } }
From source file:com.dell.asm.asmcore.asmmanager.util.discovery.providers.CServer.java
private Map<String, String> parseBMCOutput(String serverMsg) { Map<String, String> firmwareVersions = new HashMap<String, String>(); String[] tokens = serverMsg.split("\n"); String model = null;//from w w w . jav a 2s . c o m String serviceTag = null; String vendor = null; String biosVersion = "BIOS version"; String bmcVersion = "BMC version"; String fcbVersion = "FCB version"; if (tokens != null && tokens.length > 0) { for (int i = 0; i < tokens.length; i++) { String[] strings = tokens[i].split(":"); if (strings != null && strings.length == 2) { if (StringUtils.contains(strings[0], "Product Name")) model = strings[1]; if (StringUtils.contains(strings[0], "Product Serial")) serviceTag = strings[1]; if (StringUtils.contains(strings[0], "Product Manufacturer")) vendor = strings[1]; if (StringUtils.contains(strings[0], biosVersion)) firmwareVersions.put("BIOS", StringUtils.trim(strings[1])); if (StringUtils.contains(strings[0], bmcVersion)) firmwareVersions.put("BMC", StringUtils.trim(strings[1])); if (StringUtils.contains(strings[0], fcbVersion)) firmwareVersions.put("FCB", StringUtils.trim(strings[1])); } } } if (model != null) { result.setModel(StringUtils.trim(model)); result.setServiceTag(StringUtils.trim(serviceTag)); result.setVendor(StringUtils.trim(vendor)); result.setDisplayName(result.getServiceTag()); } return firmwareVersions; }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java
private static <T> T readJsonValue(String name, Class<T> type, String json) { try {//from ww w .j a v a2s . c o m return reader.forType(type).readValue(json); } catch (IOException e) { if (ExceptionUtils.getRootCause(e) instanceof ClassNotFoundException) { //attempt to find the old class name and replace it with the new one ClassNotFoundException classNotFoundException = (ClassNotFoundException) ExceptionUtils .getRootCause(e); String msg = classNotFoundException.getMessage(); msg = StringUtils.remove(msg, "java.lang.ClassNotFound:"); String oldName = StringUtils.trim(msg); try { Class newName = ClassNameChangeRegistry.findClass(oldName); String newNameString = newName.getName(); if (StringUtils.contains(json, oldName)) { //replace and try again json = StringUtils.replace(json, oldName, newNameString); return readJsonValue(name, type, json); } } catch (ClassNotFoundException c) { } } throw new MetadataRepositoryException("Failed to deserialize JSON property: " + name, e); } }
From source file:de.crowdcode.kissmda.core.jdt.JdtHelper.java
/** * Get JDT ParameterizedType for the given type name. * //from ww w . j a va 2 s . co m * @param ast * JDT AST tree * @param typeName * input type name * @return JDT ParameterizedType */ @SuppressWarnings("unchecked") public ParameterizedType getAstParameterizedType(AST ast, String typeName) { // Get the component type and parameters <Type, Type, ...> String componentTypeName = StringUtils.substringBefore(typeName, "<"); Type componentType = getAstSimpleType(ast, componentTypeName); ParameterizedType parameterizedType = ast.newParameterizedType(componentType); String paramTypeNames = StringUtils.substringAfter(typeName, "<"); paramTypeNames = StringUtils.removeEnd(paramTypeNames, ">"); // Result: String, Integer, List<Boolean>, de.test.Company String[] parametersAsString = StringUtils.split(paramTypeNames, ","); for (int index = 0; index < parametersAsString.length; index++) { String paramTypeName = parametersAsString[index]; paramTypeName = StringUtils.remove(paramTypeName, ","); paramTypeName = StringUtils.trim(paramTypeName); Type paramType = getChosenType(ast, paramTypeName, paramTypeName, ""); // Add the type arguments parameterizedType.typeArguments().add(paramType); } return parameterizedType; }
From source file:gov.nih.nci.caintegrator.external.biodbnet.BioDbNetSearchImpl.java
private Set<PathwayResults> extractPathways(String[] pathwayInfo) { Set<PathwayResults> pathways = Sets.newHashSet(); for (String pathway : pathwayInfo) { Matcher titleMatcher = PATHWAY_TITLE_PATTERN.matcher(pathway); Matcher nameMatcher = PATHWAY_NAME_PATTERN.matcher(pathway); nameMatcher.find();/* ww w . j a v a 2s .c om*/ PathwayResults result = new PathwayResults(); result.setName(StringUtils.trim(nameMatcher.group())); result.setTitle(getValue(titleMatcher)); pathways.add(result); } return pathways; }
From source file:jodtemplate.template.expression.DefaultExpressionHandler.java
private String getExpressionBody(final String expression) { String expressionBody = StringUtils.substringBetween(expression, beginTag, endTag); expressionBody = StringUtils.trim(expressionBody); expressionBody = expressionBody.replaceAll("[?]", "\""); return expressionBody; }
From source file:io.cloudslang.lang.cli.SlangCli.java
private String printCompileErrors(List<RuntimeException> exceptions, File file, StringBuilder stringBuilder) { if (exceptions.size() > 0) { stringBuilder.append("Following exceptions were found:").append(System.lineSeparator()); for (RuntimeException exception : exceptions) { stringBuilder.append("\t"); stringBuilder.append(exception.getClass()); stringBuilder.append(": "); stringBuilder.append(exception.getMessage()); stringBuilder.append(System.lineSeparator()); }//from w w w . j a va2s . c o m throw new RuntimeException(stringBuilder.toString()); } else { stringBuilder.append("Compilation was successful for ").append(file.getName()); } return StringUtils.trim(stringBuilder.toString()); }
From source file:mfi.filejuggler.responsibles.BasicApplication.java
@Responsible(conditions = { Condition.LOGIN_CHANGE_PASS }) public void fjPasswortAendern(StringBuilder sb, Map<String, String> parameters, Model model) throws Exception { String user = StringUtils.trim(parameters.get("pw_change_user")); String passOld = StringUtils.trim(parameters.get("pw_change_old_pw")); String passNew1 = StringUtils.trim(parameters.get("pw_change_new_pass1")); String passNew2 = StringUtils.trim(parameters.get("pw_change_new_pass2")); if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(passOld) && StringUtils.isNotBlank(passNew1) && StringUtils.isNotBlank(passNew2)) { if (!StringUtils.equals(passNew1, passNew2)) { model.lookupConversation().getMeldungen() .add("Die beiden eingegebenen neuen Passwrter sind nicht identisch"); model.lookupConversation().setForwardCondition(Condition.LOGIN_CHANGE_PASS_FORM); return; }/*w ww .ja va 2 s . c o m*/ if (!Security.checkUserCredentials(user, passOld)) { model.lookupConversation().getMeldungen().add("Name und altes Passwort sind nicht korrekt."); model.lookupConversation().setForwardCondition(Condition.LOGIN_CHANGE_PASS_FORM); return; } String hash = Crypto.encryptLoginCredentials(user, passNew1); KVMemoryMap.getInstance().writeKeyValue("user." + user + ".pass", hash, true); KVMemoryMap.getInstance().save(); logger.info("User/Passwort geaendert fuer: " + user); model.lookupConversation().getMeldungen().add("Das Passwort wurde erfolgreich gendert."); } else if (StringUtils.isNotBlank(user) && StringUtils.isBlank(passOld) && StringUtils.isNotBlank(passNew1) && StringUtils.isNotBlank(passNew2)) { if (!StringUtils.equals(passNew1, passNew2)) { model.lookupConversation().getMeldungen() .add("Die beiden eingegebenen neuen Passwrter sind nicht identisch"); model.lookupConversation().setForwardCondition(Condition.LOGIN_CHANGE_PASS_FORM); return; } if (!Security.isUserActive(user)) { model.lookupConversation().getMeldungen().add("Der Name ist nicht bekannt oder gesperrt."); model.lookupConversation().setForwardCondition(Condition.LOGIN_CHANGE_PASS_FORM); return; } String hash = Crypto.encryptLoginCredentials(user, passNew1); String verification = Security.generateVerificationString(); KVMemoryMap.getInstance().writeKeyValue("user." + user + ".resetPass", hash + " # " + verification + " @ " + Hilfsklasse.zeitstempelAlsString(), true); KVMemoryMap.getInstance().save(); logger.info("Passwort Reset vorbereitet fuer: " + user); model.lookupConversation().getMeldungen().add( "Das Passwort wurde gespeichert, muss aber noch vom Administrator freigeschaltet werden, da das alte Passwort nicht angegeben wurde. " + "Bitte hierzu dem Administrator den Verifikationsschlssel '" + verification + "' nennen"); } else { model.lookupConversation().getMeldungen().add("Bitte erst alle bentigten Felder eingeben."); } model.lookupConversation().setForwardCondition(Condition.LOGIN_FORMULAR); return; }
From source file:gtu._work.ui.SqlCreaterUI.java
private void executeBtnPreformed() { try {/*from www.j a v a 2 s .co m*/ logArea.setText(""); File srcFile = JCommonUtil.filePathCheck(excelFilePathText.getText(), "?", false); if (srcFile == null) { return; } if (!srcFile.getName().endsWith(".xlsx")) { JCommonUtil._jOptionPane_showMessageDialog_error("excel"); return; } if (StringUtils.isBlank(sqlArea.getText())) { return; } File saveFile = JCommonUtil._jFileChooser_selectFileOnly_saveFile(); if (saveFile == null) { JCommonUtil._jOptionPane_showMessageDialog_error("?"); return; } String sqlText = sqlArea.getText(); StringBuffer sb = new StringBuffer(); Map<Integer, String> refMap = new HashMap<Integer, String>(); Pattern sqlPattern = Pattern.compile("\\$\\{(\\w+)\\}", Pattern.MULTILINE); Matcher matcher = sqlPattern.matcher(sqlText); while (matcher.find()) { String val = StringUtils.trim(matcher.group(1)).toUpperCase(); refMap.put(ExcelUtil.cellEnglishToPos(val), val); matcher.appendReplacement(sb, "\\$\\{" + val + "\\}"); } matcher.appendTail(sb); appendLog(refMap.toString()); sqlText = sb.toString(); sqlArea.setText(sqlText); Configuration cfg = new Configuration(); StringTemplateLoader stringTemplatge = new StringTemplateLoader(); stringTemplatge.putTemplate("aaa", sqlText); cfg.setTemplateLoader(stringTemplatge); cfg.setObjectWrapper(new DefaultObjectWrapper()); Template temp = cfg.getTemplate("aaa"); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(saveFile), "utf8")); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile)); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bis); Sheet sheet = xssfWorkbook.getSheetAt(0); for (int j = 0; j < sheet.getPhysicalNumberOfRows(); j++) { Row row = sheet.getRow(j); if (row == null) { continue; } Map<String, Object> root = new HashMap<String, Object>(); for (int index : refMap.keySet()) { root.put(refMap.get(index), formatCellType(row.getCell(index))); } appendLog(root.toString()); StringWriter out = new StringWriter(); temp.process(root, out); out.flush(); String writeStr = out.getBuffer().toString(); appendLog(writeStr); writer.write(writeStr); writer.newLine(); } bis.close(); writer.flush(); writer.close(); JCommonUtil._jOptionPane_showMessageDialog_info("? : \n" + saveFile); } catch (Exception ex) { JCommonUtil.handleException(ex); } }