List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:com.dianping.lion.web.action.common.AbstractLionAction.java
protected boolean isAjaxRequest() { String actionName = ActionContext.getContext().getName(); return StringUtils.endsWith(actionName, "Ajax"); }
From source file:com.microsoft.alm.plugin.external.commands.FindConflictsCommand.java
/** * Outputs the conflicts found in the workspace in the following format: * <p/>/* www. j a va 2 s.c o m*/ * tfsTest_01/addFold/testHere2: The item content has changed * tfsTest_01/TestAdd.txt: The item content has changed * * @param stdout * @param stderr * @return */ @Override public ConflictResults parseOutput(final String stdout, final String stderr) { final List<String> contentConflicts = new ArrayList<String>(); final List<String> renameConflicts = new ArrayList<String>(); final List<String> bothConflicts = new ArrayList<String>(); final String[] lines = getLines(stderr); for (final String line : lines) { // find last ue of colon because it can be included in the file path (i.e. C:\\Users\\user\\tfvc\\file.txt: The item content has changed) final int index = line.lastIndexOf(":"); if (index != -1) { if (StringUtils.endsWith(line, BOTH_CONFLICTS_SUFFIX)) { bothConflicts.add(line.substring(0, index)); } else if (StringUtils.endsWith(line, RENAME_CONFLICT_SUFFIX)) { renameConflicts.add(line.substring(0, index)); } else { contentConflicts.add(line.substring(0, index)); } } } return new ConflictResults(contentConflicts, renameConflicts, bothConflicts); }
From source file:com.apexxs.neonblack.setup.Configuration.java
private Configuration() { Properties configFile = new Properties(); try {//from w w w. jav a2 s. c om configFile.load(Configuration.class.getClassLoader().getResourceAsStream("NB.properties")); this.stanfordModel = configFile.getProperty("ner.detector.stanford.model"); this.maxHits = Integer.parseInt(configFile.getProperty("solr.search.maxHits")); this.sortOnPopulation = Boolean.parseBoolean(configFile.getProperty("solr.populationSort")); this.removeStopWords = Boolean.parseBoolean(configFile.getProperty("ner.detector.removeStopWords")); this.removeDemonyms = Boolean.parseBoolean(configFile.getProperty("ner.detector.removeDemonyms")); this.replaceSynonyms = Boolean.parseBoolean(configFile.getProperty("ner.detector.replaceSynonyms")); this.polygonType = configFile.getProperty("polygon.type"); this.polygonDirectory = configFile.getProperty("polygon.directory"); if (!StringUtils.endsWith(this.polygonDirectory, "/")) { this.polygonDirectory += "/"; } this.solrURL = configFile.getProperty("solr.url"); if (!StringUtils.endsWith(this.solrURL, "/")) { this.solrURL += "/"; } this.proximalDistance = configFile.getProperty("coords.proximalDistanceKM"); this.numProximalHits = Integer.parseInt(configFile.getProperty("coords.numProximalHits")); this.numAlternates = Integer.parseInt(configFile.getProperty("results.numAlternates")); this.resultFormat = configFile.getProperty("results.format"); this.resourceDirectory = configFile.getProperty("resource.directory"); if (!StringUtils.endsWith(this.resourceDirectory, "/")) { this.resourceDirectory += "/"; } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.glaf.activiti.executionlistener.SqlInsertExecutionListener.java
public void notify(DelegateExecution execution) throws Exception { logger.debug("-------------------------------------------------------"); logger.debug("--------------SqlInsertExecutionListener---------------"); logger.debug("-------------------------------------------------------"); String tableName = table.getExpressionText(); if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) { tableName = (String) table.getValue(execution); }/*from ww w . j ava2 s .c o m*/ CommandContext commandContext = Context.getCommandContext(); ExecutionEntity executionEntity = commandContext.getExecutionEntityManager() .findExecutionById(execution.getId()); String processDefinitionId = executionEntity.getProcessDefinitionId(); ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager() .findProcessDefinitionById(processDefinitionId); String processName = processDefinitionEntity.getKey(); Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> variables = execution.getVariables(); if (variables != null && variables.size() > 0) { Iterator<String> iterator = variables.keySet().iterator(); while (iterator.hasNext()) { String variableName = iterator.next(); if (params.get(variableName) == null) { Object value = execution.getVariable(variableName); params.put(variableName, value); } } } params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey()); params.put("processInstanceId", execution.getProcessInstanceId()); params.put("processDefinitionId", processDefinitionEntity.getId()); params.put("processName", processName); params.put("now", new Date()); params.put("today", new Date()); params.put("currentDate", new Date()); String variable = (String) execution.getVariable(fields.getExpressionText()); JSONObject jsonObject = JSON.parseObject(variable); TableModel tableModel = new TableModel(); tableModel.setTableName(tableName); Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String columnName = (String) entry.getKey(); String value = (String) entry.getValue(); if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) { value = value.substring(2, value.length() - 1); Object x = params.get(value); if (x != null) { ColumnModel column = new ColumnModel(); column.setColumnName(columnName); column.setJavaType(x.getClass().getSimpleName()); column.setValue(x); tableModel.addColumn(column); } } else { Object x = params.get(value); if (x != null) { ColumnModel column = new ColumnModel(); column.setColumnName(columnName); column.setJavaType(x.getClass().getSimpleName()); column.setValue(x); tableModel.addColumn(column); } } } commandContext.getDbSqlSession().getSqlSession().insert("insertBusinessTableData", tableModel); }
From source file:com.glaf.activiti.executionlistener.SqlDeleteExecutionListener.java
public void notify(DelegateExecution execution) throws Exception { logger.debug("-------------------------------------------------------"); logger.debug("--------------SqlDeleteExecutionListener---------------"); logger.debug("-------------------------------------------------------"); String tableName = table.getExpressionText(); if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) { tableName = (String) table.getValue(execution); }//from w w w. j a v a2 s . com CommandContext commandContext = Context.getCommandContext(); ExecutionEntity executionEntity = commandContext.getExecutionEntityManager() .findExecutionById(execution.getId()); String processDefinitionId = executionEntity.getProcessDefinitionId(); ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager() .findProcessDefinitionById(processDefinitionId); String processName = processDefinitionEntity.getKey(); Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> variables = execution.getVariables(); if (variables != null && variables.size() > 0) { Iterator<String> iterator = variables.keySet().iterator(); while (iterator.hasNext()) { String variableName = iterator.next(); if (params.get(variableName) == null) { Object value = execution.getVariable(variableName); params.put(variableName, value); } } } params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey()); params.put("processInstanceId", execution.getProcessInstanceId()); params.put("processDefinitionId", processDefinitionEntity.getId()); params.put("processName", processName); params.put("now", new Date()); params.put("today", new Date()); params.put("currentDate", new Date()); String variable = (String) execution.getVariable(fields.getExpressionText()); JSONObject jsonObject = JSON.parseObject(variable); TableModel tableModel = new TableModel(); tableModel.setTableName(tableName); Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String columnName = (String) entry.getKey(); String value = (String) entry.getValue(); if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) { value = value.substring(2, value.length() - 1); Object x = params.get(value); if (x != null) { ColumnModel column = new ColumnModel(); column.setColumnName(columnName); column.setJavaType(x.getClass().getSimpleName()); column.setValue(x); tableModel.addColumn(column); } else { throw new RuntimeException(columnName + " '" + value + "' value is null"); } } else { Object x = params.get(value); if (x != null) { ColumnModel column = new ColumnModel(); column.setColumnName(columnName); column.setJavaType(x.getClass().getSimpleName()); column.setValue(x); tableModel.addColumn(column); } else { throw new RuntimeException(columnName + " '" + value + "' value is null"); } } } commandContext.getDbSqlSession().getSqlSession().delete("deleteBusinessTableData", tableModel); }
From source file:com.glaf.activiti.executionlistener.SqlUpdateExecutionListener.java
public void notify(DelegateExecution execution) throws Exception { logger.debug("-------------------------------------------------------"); logger.debug("--------------SqlUpdateExecutionListener---------------"); logger.debug("-------------------------------------------------------"); String tableName = table.getExpressionText(); if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) { tableName = (String) table.getValue(execution); }//from w ww .j a v a 2 s . c o m CommandContext commandContext = Context.getCommandContext(); ExecutionEntity executionEntity = commandContext.getExecutionEntityManager() .findExecutionById(execution.getId()); String processDefinitionId = executionEntity.getProcessDefinitionId(); ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager() .findProcessDefinitionById(processDefinitionId); String processName = processDefinitionEntity.getKey(); Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> variables = execution.getVariables(); if (variables != null && variables.size() > 0) { Iterator<String> iterator = variables.keySet().iterator(); while (iterator.hasNext()) { String variableName = iterator.next(); if (params.get(variableName) == null) { Object value = execution.getVariable(variableName); params.put(variableName, value); } } } params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey()); params.put("processInstanceId", execution.getProcessInstanceId()); params.put("processDefinitionId", processDefinitionEntity.getId()); params.put("processName", processName); params.put("now", new Date()); params.put("today", new Date()); params.put("currentDate", new Date()); String variable = (String) execution.getVariable(fields.getExpressionText()); JSONObject jsonObject = JSON.parseObject(variable); TableModel tableModel = new TableModel(); tableModel.setTableName(tableName); ColumnModel idColumn = new ColumnModel(); idColumn.setColumnName(primaryKey.getExpressionText()); if (execution.getVariable("primaryKey") != null) { Object idValue = execution.getVariable("primaryKey"); idColumn.setJavaType(idValue.getClass().getSimpleName()); tableModel.setIdColumn(idColumn); } else { idColumn.setJavaType("String"); idColumn.setValue(execution.getProcessBusinessKey()); tableModel.setIdColumn(idColumn); } Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String columnName = (String) entry.getKey(); String value = (String) entry.getValue(); if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) { value = value.substring(2, value.length() - 1); Object x = params.get(value); if (x != null) { ColumnModel column = new ColumnModel(); column.setColumnName(columnName); column.setJavaType(x.getClass().getSimpleName()); column.setValue(x); tableModel.addColumn(column); } } else { Object x = params.get(value); if (x != null) { ColumnModel column = new ColumnModel(); column.setColumnName(columnName); column.setJavaType(x.getClass().getSimpleName()); column.setValue(x); tableModel.addColumn(column); } } } commandContext.getDbSqlSession().getSqlSession().update("updateBusinessTableDataByPrimaryKey", tableModel); }
From source file:de.forsthaus.h2.My_H2_SampleDataFiller.java
@Override public void afterPropertiesSet() throws Exception { final Logger logger = Logger.getLogger(getClass()); final Map<Integer, String> allSql = new HashMap<Integer, String>(); final Connection conn = this.dataSource.getConnection(); try {// w ww. j a v a2 s . c om // reads the sql-file from the classpath final InputStream inputStream = getClass().getResourceAsStream("/createSampleData.sql"); try { final Statement stat = conn.createStatement(); final BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); String str; StringBuilder sb = new StringBuilder(); int count = 0; while ((str = in.readLine()) != null) { sb.append(str); // make a linefeed at each readed line if (StringUtils.endsWith(str.trim(), ";")) { final String sql = sb.toString(); stat.addBatch(sql); sb = new StringBuilder(); allSql.put(Integer.valueOf(count++), sql); } else { sb.append("\n"); } } final int[] ar = stat.executeBatch(); final int i = ar.length; logger.info("Create DemoData"); logger.info("count batch updates : " + i); } finally { try { inputStream.close(); } catch (final IOException e) { logger.warn("", e); } } } catch (final BatchUpdateException e) { final BatchUpdateException be = e; final int[] updateCounts = be.getUpdateCounts(); if (updateCounts != null) { for (int i = 0; i < updateCounts.length; i++) { final int j = updateCounts[i]; if (j < 0) { logger.error("SQL errorcode: " + j + " -> in SQL\n" + allSql.get(Integer.valueOf(i))); } } } throw e; } finally { try { conn.close(); } catch (final SQLException e) { logger.warn("", e); } } }
From source file:mitm.common.util.DomainUtils.java
/** * Checks if the domain is valid for the domain type. If not valid null will be returned * if valid, leading white space will be removed. *///from ww w . j ava2 s.c o m public static String validate(String domain, DomainType domainType) { if (domain == null) { return null; } Pattern pattern = null; switch (domainType) { case FULLY_QUALIFIED: pattern = fullyQualifiedPattern; break; case WILD_CARD: pattern = wildcardPattern; break; case FRAGMENT: pattern = fragmentPattern; break; default: throw new IllegalArgumentException("Unknown domainType."); } Matcher matcher = pattern.matcher(domain); String validated = null; if (matcher.matches()) { validated = matcher.group(1); String trimmed = StringUtils.trim(validated); /* * A domain should not start or end with - */ if (StringUtils.startsWith(trimmed, "-") || StringUtils.endsWith(trimmed, "-")) { validated = null; } } return validated; }
From source file:jenkins.plugins.tanaguru.ProjectTanaguruAction.java
private String buildAuditResultUrl(String line, String webappUrl) { String auditId = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim(); if (StringUtils.endsWith(webappUrl, "/")) { return webappUrl + URL_PREFIX_RESULT + auditId; } else {/*from w w w. j ava2 s .com*/ return webappUrl + "/" + URL_PREFIX_RESULT + auditId; } }
From source file:com.thed.launcher.EggplantZBotScriptLauncher.java
@Override public void testcaseExecutionResult() { String scriptPath = LauncherUtils.getFilePathFromCommand(currentTestcaseExecution.getScriptPath()); logger.info("Script Path is " + scriptPath); File scriptFile = new File(scriptPath); String scriptName = scriptFile.getName().split("\\.")[0]; logger.info("Script Name is " + scriptName); File resultsFolder = new File( scriptFile.getParentFile().getParentFile().getAbsolutePath() + File.separator + "Results"); File statisticalFile = resultsFolder.listFiles(new FilenameFilter() { @Override// w ww . j a v a 2 s .com public boolean accept(File file, String s) { return StringUtils.endsWith(s, "Statistics.xml"); } })[0]; try { XPath xpath = XPathFactory.newInstance().newXPath(); Document statisticalDoc = getDoc(statisticalFile); String result = xpath.compile("/statistics/script[@name='" + scriptName + "']/LastStatus/text()") .evaluate(statisticalDoc, XPathConstants.STRING).toString(); logger.info("Result is " + result); String comments; if (StringUtils.equalsIgnoreCase(result, "Success")) { logger.info("Test success detected"); status = currentTestcaseExecution.getTcId() + ": " + currentTestcaseExecution.getScriptId() + " STATUS: Script Successfully Executed"; currentTcExecutionResult = new Integer(1); comments = " Successfully executed on " + agent.getAgentHostAndIp(); } else { logger.info("Test failure detected, getting error message"); status = currentTestcaseExecution.getTcId() + ": " + currentTestcaseExecution.getScriptId() + " STATUS: Script Successfully Executed"; currentTcExecutionResult = new Integer(2); comments = " Error in test: "; String lastRunDateString = xpath .compile("/statistics/script[@name='" + scriptName + "']/LastRun/text()") .evaluate(statisticalDoc); //Date lastRunDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(lastRunDateString); File historyFile = new File(resultsFolder.getAbsolutePath() + File.separator + scriptName + File.separator + "RunHistory.xml"); Document historyDoc = getDoc(historyFile); //xpath = XPathFactory.newInstance().newXPath(); String xpathExpr = "/runHistory[@script='" + scriptName + "']/run[contains(RunDate, '" + StringUtils.substringBeforeLast(lastRunDateString, " ") + "')]/ErrorMessage/text()"; logger.info("Using xPath to find errorMessage " + xpathExpr); comments += xpath.compile(xpathExpr).evaluate(historyDoc, XPathConstants.STRING); logger.info("Sending comments: " + comments); } if (currentTcExecutionResult != null) { ScriptUtil.updateTestcaseExecutionResult(url, currentTestcaseExecution, currentTcExecutionResult, comments); } } catch (Exception e) { logger.log(Level.SEVERE, "Error in reading process steams \n", e); } }