List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.codahale.metrics.riemann.DropWizardRiemannReporter.java
private DropWizardRiemannReporter(MetricRegistry registry, Riemann riemann, Clock clock, TimeUnit rateUnit, TimeUnit durationUnit, Float ttl, String prefix, String separator, String localHost, List<String> tags, MetricFilter filter) {//ww w . j av a2 s . c o m super(registry, "riemann-reporter", filter, rateUnit, durationUnit); this.riemann = riemann; this.clock = clock; this.prefix = prefix; this.separator = separator; this.localHost = localHost; this.tags = tags; this.ttl = ttl; this.appName = StringUtils.substringAfterLast(prefix, "."); }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.TaskCachingAgent.java
@Override protected Map<String, Collection<CacheData>> generateFreshData(Collection<Task> tasks) { Collection<CacheData> dataPoints = new LinkedList<>(); Map<String, CacheData> clusterDataPoints = new HashMap<>(); for (Task task : tasks) { String taskId = StringUtils.substringAfterLast(task.getTaskArn(), "/"); Map<String, Object> attributes = convertTaskToAttributes(task); String key = Keys.getTaskKey(accountName, region, taskId); dataPoints.add(new DefaultCacheData(key, attributes, Collections.emptyMap())); String clusterName = StringUtils.substringAfterLast(task.getClusterArn(), "/"); Map<String, Object> clusterAttributes = EcsClusterCachingAgent .convertClusterArnToAttributes(accountName, region, task.getClusterArn()); key = Keys.getClusterKey(accountName, region, clusterName); clusterDataPoints.put(key, new DefaultCacheData(key, clusterAttributes, Collections.emptyMap())); }//from w ww .ja v a2 s . co m log.info("Caching " + dataPoints.size() + " tasks in " + getAgentType()); Map<String, Collection<CacheData>> dataMap = new HashMap<>(); dataMap.put(TASKS.toString(), dataPoints); log.info("Caching " + clusterDataPoints.size() + " ECS clusters in " + getAgentType()); dataMap.put(ECS_CLUSTERS.toString(), clusterDataPoints.values()); return dataMap; }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.TaskCachingAgent.java
public static Map<String, Object> convertTaskToAttributes(Task task) { String taskId = StringUtils.substringAfterLast(task.getTaskArn(), "/"); Map<String, Object> attributes = new HashMap<>(); attributes.put("taskId", taskId); attributes.put("taskArn", task.getTaskArn()); attributes.put("clusterArn", task.getClusterArn()); attributes.put("containerInstanceArn", task.getContainerInstanceArn()); attributes.put("group", task.getGroup()); attributes.put("containers", task.getContainers()); attributes.put("lastStatus", task.getLastStatus()); attributes.put("desiredStatus", task.getDesiredStatus()); attributes.put("startedAt", task.getStartedAt().getTime()); return attributes; }
From source file:com.yiji.openapi.sdk.util.Servlets.java
public static String getRequestPage(HttpServletRequest request) { return StringUtils.substringAfterLast(request.getRequestURI(), "/"); }
From source file:jodtemplate.template.expression.DefaultExpressionHandler.java
private VariableExpression createVariableExpressionNoCheck(final String expressionBody) { String defaultValue = StringUtils.substringAfterLast(expressionBody, DEFAULT_VALUE_SEPARATOR).trim(); defaultValue = StringUtils.remove(defaultValue, '"'); final String variableWithParams = StringUtils.substringBefore(expressionBody, DEFAULT_VALUE_SEPARATOR); final String variable = StringUtils.substringBefore(variableWithParams, PARAMS_VALUE_SEPARATOR); final String paramsString = StringUtils.substringAfter(variableWithParams, PARAMS_VALUE_SEPARATOR); final List<String> params = Arrays.asList(StringUtils.split(paramsString, PARAMS_VALUE_SEPARATOR)); final VariableExpression variableExpression = new VariableExpression(variable, params, defaultValue); return variableExpression; }
From source file:apm.generate.Generate.java
public static void parameters(String packageName, String moduleName, String className, String classAuthor, String functionName, String tableName, String entityContent, String flag) throws Exception { // ========== ?? ==================== // ??????/*from w w w . jav a 2 s . c om*/ // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? //String packageName = "lms.modules";//??? //String moduleName = "test"; //???sys String subModuleName = ""; // ?????? //String className = "test"; // ??user //String classAuthor = "htd"; // ThinkGem //String functionName = ""; //?? // ??? Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { //logger.error("????isEnable = true"); System.out.println("????isEnable = true"); return; } if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { //logger.error("??????????????"); System.out.println("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = new DefaultResourceLoader().getResource("").getFile(); while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) { projectPath = projectPath.getParentFile(); } //logger.info("Project Path: {}", projectPath); System.out.println("-------------------------------------------------"); System.out.println(":" + projectPath); // ? String tplPath = StringUtils.replace(projectPath + "/src/main/java/apm/generate/template", "/", separator); //logger.info("Template Path: {}", tplPath); System.out.println("?:" + tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); //logger.info("Java Path: {}", javaPath); System.out.println("Java:" + javaPath); // String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator); //logger.info("View Path: {}", viewPath); System.out.println(":" + viewPath); // ??? Configuration cfg = new Configuration(); cfg.setDirectoryForTemplateLoading(new File(tplPath)); // ??? Map<String, String> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); model.put("moduleName", 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", tableName); model.put("urlPrefix", "/" + model.get("className")); model.put("viewUrlPrefix", "/" + model.get("moduleName")); model.put("returnPrefix", "modules" + //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("viewUrlPrefix") + "/" + model.get("className")); model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("className")); String[] strs = entityContent.split("##"); model.put("columnContent", strs[0]); model.put("entityContent", strs[1]); System.out.println("-------------------------?------------------------"); Template template = null; String content = null; String filePath = null; if (flag.indexOf("entity") != -1 || flag.length() == 0) { // ? Entity template = cfg.getTemplate("entity.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + ".java"; writeFile(content, filePath); System.out.println("? Entity:" + filePath); } if (flag.indexOf("dao") != -1 || flag.length() == 0) { // ? Dao template = cfg.getTemplate("dao.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Dao.java"; writeFile(content, filePath); System.out.println("? Dao:" + filePath); } if (flag.indexOf("service") != -1 || flag.length() == 0) { // ? Service template = cfg.getTemplate("service.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Service.java"; writeFile(content, filePath); System.out.println("? Service:" + filePath); } if (flag.indexOf("controler") != -1 || flag.length() == 0) { // ? Controller template = cfg.getTemplate("controller.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Controller.java"; writeFile(content, filePath); System.out.println("? Controller:" + filePath); } if (flag.indexOf("form") != -1 || flag.length() == 0) { // ? ViewForm template = cfg.getTemplate("viewForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + model.get("className") + "Form.jsp"; writeFile(content, filePath); System.out.println("? ViewForm:" + filePath); } if (flag.indexOf("list") != -1 || flag.length() == 0) { // ? ViewList template = cfg.getTemplate("viewList.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + model.get("className") + "List.jsp"; writeFile(content, filePath); System.out.println("? ViewList:" + filePath); } }
From source file:com.gargoylesoftware.htmlunit.html.XmlSerializer.java
private String getFileExtension(final Page enclosedPage) { if (enclosedPage != null) { if (enclosedPage.isHtmlPage()) { return "html"; }/*w ww . j a v a2s .c o m*/ final URL url = enclosedPage.getUrl(); if (url.getPath().contains(".")) { return StringUtils.substringAfterLast(url.getPath(), "."); } } return ".unknown"; }
From source file:com.thinkbiganalytics.feedmgr.service.feed.datasource.DerivedDatasourceFactory.java
/** * Builds the list of data sources for the specified data transformation feed. * * @param feed the feed//from ww w. ja va 2 s .co m * @return the list of data sources */ @Nonnull private Set<Datasource.ID> ensureDataTransformationSourceDatasources(@Nonnull final FeedMetadata feed) { // Build the data sources from the view model final Set<Datasource.ID> datasources = new HashSet<>(); final Set<String> tableNames = Optional.ofNullable(feed.getDataTransformation()) .map(FeedDataTransformation::getTableNamesFromViewModel).orElse(Collections.emptySet()); if (!tableNames.isEmpty()) { DatasourceDefinition datasourceDefinition = datasourceDefinitionProvider .findByProcessorType(DATA_TRANSFORMATION_DEFINITION); if (datasourceDefinition != null) { tableNames.forEach(hiveTable -> { String schema = StringUtils.trim(StringUtils.substringBefore(hiveTable, ".")); String table = StringUtils.trim(StringUtils.substringAfterLast(hiveTable, ".")); String identityString = datasourceDefinition.getIdentityString(); Map<String, String> props = new HashMap<String, String>(); props.put("schema", schema); props.put("table", table); identityString = propertyExpressionResolver.resolveVariables(identityString, props); String desc = datasourceDefinition.getDescription(); if (desc != null) { desc = propertyExpressionResolver.resolveVariables(desc, props); } String title = identityString; DerivedDatasource derivedDatasource = datasourceProvider.ensureDerivedDatasource( datasourceDefinition.getDatasourceType(), identityString, title, desc, new HashMap<String, Object>(props)); if (derivedDatasource != null) { datasources.add(derivedDatasource.getId()); } }); } } // Build the data sources from the data source ids final List<String> datasourceIds = Optional.ofNullable(feed.getDataTransformation()) .map(FeedDataTransformation::getDatasourceIds).orElse(Collections.emptyList()); datasourceIds.stream().map(datasourceProvider::resolve).forEach(datasources::add); return datasources; }
From source file:info.magnolia.about.app.AboutPresenter.java
private String getMySQLEngineInfo(Connection connection, String[] connectionString) { PreparedStatement statement = null; ResultSet resultSet = null;// w w w.j ava 2 s. c o m try { statement = connection.prepareStatement( "SHOW TABLE STATUS FROM `" + StringUtils.substringAfterLast(connectionString[0], "/") + "`;"); resultSet = statement.executeQuery(); if (resultSet.next()) { String engine = resultSet.getString("Engine"); return " (" + engine + ")"; } } catch (SQLException e) { // can't get extra info, oh well } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } } catch (SQLException e) { } } return null; }
From source file:com.thinkbiganalytics.hive.service.HiveService.java
public QueryResult query(String query) throws DataAccessException { final DefaultQueryResult queryResult = new DefaultQueryResult(query); final List<QueryResultColumn> columns = new ArrayList<>(); final Map<String, Integer> displayNameMap = new HashMap<>(); if (query != null && !query.toLowerCase().startsWith("show")) { query = safeQuery(query);/*from w w w . ja va 2 s. co m*/ } try { // Setting in order to query complex formats like parquet jdbcTemplate.execute("set hive.optimize.index.filter=false"); jdbcTemplate.query(query, new RowMapper<Map<String, Object>>() { @Override public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { if (columns.isEmpty()) { ResultSetMetaData rsMetaData = rs.getMetaData(); for (int i = 1; i <= rsMetaData.getColumnCount(); i++) { String colName = rsMetaData.getColumnName(i); DefaultQueryResultColumn column = new DefaultQueryResultColumn(); column.setField(rsMetaData.getColumnName(i)); String displayName = rsMetaData.getColumnLabel(i); column.setHiveColumnLabel(displayName); //remove the table name if it exists displayName = StringUtils.substringAfterLast(displayName, "."); Integer count = 0; if (displayNameMap.containsKey(displayName)) { count = displayNameMap.get(displayName); count++; } displayNameMap.put(displayName, count); column.setDisplayName(displayName + "" + (count > 0 ? count : "")); column.setTableName(StringUtils.substringAfterLast(rsMetaData.getColumnName(i), ".")); column.setDataType(ParserHelper.sqlTypeToHiveType(rsMetaData.getColumnType(i))); columns.add(column); } queryResult.setColumns(columns); } Map<String, Object> row = new LinkedHashMap<>(); for (QueryResultColumn column : columns) { row.put(column.getDisplayName(), rs.getObject(column.getHiveColumnLabel())); } queryResult.addRow(row); return row; } }); } catch (DataAccessException dae) { dae.printStackTrace(); throw dae; } return queryResult; }