Java Code Examples for org.apache.commons.lang.StringUtils.substringAfterLast()

The following are Jave code examples for showing how to use substringAfterLast() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: JahiaDF   File: AreaTag.java   Source Code and License Vote up 7 votes
private JCRNodeWrapper getOrCreateAreaNode(String areaPath, JCRSessionWrapper session) throws RepositoryException {
    JCRNodeWrapper areaParentNode = session.getNode(StringUtils.substringBeforeLast(areaPath, "/"));
    String areaName = StringUtils.substringAfterLast(areaPath, "/");
    JCRNodeWrapper areaNode = null;
    try {
        areaNode = areaParentNode.getNode(areaName);
    } catch (PathNotFoundException e) {
        try {
            areaNode = areaParentNode.addNode(areaName, areaType);
            session.save();
        } catch (ItemExistsException e1) {
            // possible race condition when page is accessed concurrently in edit mode
            areaNode = areaParentNode.getNode(areaName);
        }
    }
    return areaNode;
}
 
Example 2
Project: canal-elasticsearch   File: SimpleEsAdapter.java   Source Code and License Vote up 6 votes
public SimpleEsAdapter(CanalConf canalConf) {

        String accept = canalConf.getAccept();
        String[] acceptArr = accept.split(DELIMITER);
        for (String str : acceptArr) {
            String[] strArr = str.split(CONNECTOR);
            if (strArr.length == 3) {
                String dataBaseTable = StringUtils.substringBeforeLast(str, CONNECTOR_TEP);
                String idColumn = StringUtils.substringAfterLast(str, CONNECTOR_TEP);
                idPair.put(dataBaseTable, idColumn);

                logger.info("Add accept :{}", str);
            }
        }

    }
 
Example 3
Project: Reer   File: AbstractTestDirectoryProvider.java   Source Code and License Vote up 5 votes
private String determinePrefix() {
    StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().endsWith("Test") || element.getClassName().endsWith("Spec")) {
            return StringUtils.substringAfterLast(element.getClassName(), ".") + "/unknown-test";
        }
    }
    return "unknown-test-class";
}
 
Example 4
Project: Reer   File: ArtifactFile.java   Source Code and License Vote up 5 votes
public ArtifactFile(File file, String version) {
    name = file.getName();
    extension = "";
    classifier = "";
    boolean done = false;

    int startVersion = StringUtils.lastIndexOf(name, "-" + version);
    if (startVersion >= 0) {
        int endVersion = startVersion + version.length() + 1;
        if (endVersion == name.length()) {
            name = name.substring(0, startVersion);
            done = true;
        } else if (endVersion < name.length() && name.charAt(endVersion) == '-') {
            String tail = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            classifier = StringUtils.substringBeforeLast(tail, ".");
            extension = StringUtils.substringAfterLast(tail, ".");
            done = true;
        } else if (endVersion < name.length() && StringUtils.lastIndexOf(name, ".") == endVersion) {
            extension = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            done = true;
        }
    }
    if (!done) {
        extension = StringUtils.substringAfterLast(name, ".");
        name = StringUtils.substringBeforeLast(name, ".");
    }
    if (classifier.length() == 0) {
        classifier = null;
    }
}
 
Example 5
Project: Reer   File: ClassTestResults.java   Source Code and License Vote up 5 votes
public String getSimpleName() {
    String simpleName = StringUtils.substringAfterLast(name, ".");
    if (simpleName.equals("")) {
        return name;
    }
    return simpleName;
}
 
Example 6
Project: Reer   File: HtmlReportRenderer.java   Source Code and License Vote up 5 votes
Resource addResource(URL source) {
    String urlString = source.toString();
    Resource resource = resources.get(urlString);
    if (resource == null) {
        String name = StringUtils.substringAfterLast(source.getPath(), "/");
        String type = StringUtils.substringAfterLast(source.getPath(), ".");
        if (type.equalsIgnoreCase("png") || type.equalsIgnoreCase("gif")) {
            type = "images";
        }
        String path = type + "/" + name;
        resource = new Resource(source, path);
        resources.put(urlString, resource);
    }
    return resource;
}
 
Example 7
Project: DBus   File: CheckFullPullEvent.java   Source Code and License Vote up 5 votes
private void fetchZkNodeRecursively(String parentNode, List<String> resultNodesInfo, CuratorFramework curator) throws Exception {
    List<String> children = curator.getChildren().forPath(parentNode);
    if (!children.isEmpty()) {
        for (String curNode : children) {
            fetchZkNodeRecursively(parentNode + "/" + curNode, resultNodesInfo, curator);
        }
    } else {
        String ver = StringUtils.substringAfterLast(parentNode, "/");
        if(isStr2Num(ver)) {
            resultNodesInfo.add(parentNode);
        }
    }
}
 
Example 8
Project: DBus   File: CheckFullPullEvent.java   Source Code and License Vote up 5 votes
/**
 * 获取全量拉取的最新节点
 * @param fullPullerRootNode
 * @param curator
 * @return 子节点的全路径,之前非全路径,后面的path部分进行了拼接
 * @throws Exception
 */
private List<String> filter(String fullPullerRootNode, CuratorFramework curator) throws Exception {
    List<String> flattedFullpullerNodeName = new ArrayList<>();

    //get all node list
    fetchZkNodeRecursively(fullPullerRootNode,flattedFullpullerNodeName, curator);

    HashMap<String, Integer> map = new HashMap<String, Integer>();
    for (String znode : flattedFullpullerNodeName) {
        String key = StringUtils.substringBeforeLast(znode, "/");
        String ver = StringUtils.substringAfterLast(znode, "/");
        Integer version = Integer.parseInt(ver);
        if (map.containsKey(key)) {
            Integer tempVersion = map.get(key);
            if (version > tempVersion) {
                map.put(key, version);
            }
        } else {
            map.put(key, version);
        }
    }

    List<String> wkList = new ArrayList<String>();
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        wkList.add(StringUtils.join(new String[] {entry.getKey(), String.valueOf(entry.getValue())}, "/"));
    }
    return wkList;
}
 
Example 9
Project: instalint   File: StandalonePluginIndex.java   Source Code and License Vote up 5 votes
private PluginReference getFromCacheOrCopy(final URL pluginUrl) {
  try (InputStream is = pluginUrl.openStream()) {
    String hash = org.sonarsource.sonarlint.core.util.StringUtils.md5(is);
    String filename = StringUtils.substringAfterLast(pluginUrl.getFile(), "/");
    fileCache.get(filename, hash, new FileCopier(pluginUrl));
    return new PluginReference(hash, filename);
  } catch (Exception e) {
    throw new IllegalStateException("Fail to copy plugin from URL: " + pluginUrl, e);
  }
}
 
Example 10
Project: sql-first-mapper   File: MiscUtils.java   Source Code and License Vote up 5 votes
/**
 * Split by dot and get last word
 *
 * @param stringWithDots string to get last word from
 * @return word after last dot
 */
public static String getLastWordAfterDot(String stringWithDots) {
    if (StringUtils.isBlank(stringWithDots)){
        return stringWithDots;
    }
    return stringWithDots.contains(".") ? StringUtils.substringAfterLast(stringWithDots, ".") : stringWithDots;
}
 
Example 11
Project: otter-G   File: AbstractRuleMonitor.java   Source Code and License Vote up 5 votes
protected boolean inPeriod(AlarmRule alarmRule) {
    String rule = alarmRule.getMatchValue();
    if (StringUtils.isEmpty(rule)) {
        log.info("rule is empty " + alarmRule);
        return false;
    }

    String periods = StringUtils.substringAfterLast(rule, "@");
    if (StringUtils.isEmpty(periods)) {
        // 没有时间要求,则任务在报警时间段内
        return isInPeriodWhenNoPeriod();
    }

    Calendar calendar = currentCalendar();
    periods = StringUtils.trim(periods);
    for (String period : StringUtils.split(periods, ",")) {
        String[] startAndEnd = StringUtils.split(period, "-");
        if (startAndEnd == null || startAndEnd.length != 2) {
            log.error("error period time format in rule : " + alarmRule);
            return isInPeriodWhenErrorFormat();
        }

        String start = startAndEnd[0];
        String end = startAndEnd[1];
        if (checkInPeriod(calendar, start, end)) {
            log.info("rule is in period : " + alarmRule);
            return true;
        }
    }

    log.info("rule is not in period : " + alarmRule);
    return false;
}
 
Example 12
Project: otter-G   File: BaseStageTest.java   Source Code and License Vote up 5 votes
protected Long initProcess() {
    String path = zookeeper.create(processPath + "/", new byte[0], CreateMode.PERSISTENT_SEQUENTIAL);

    // 创建为顺序的节点
    String processNode = StringUtils.substringAfterLast(path, "/");
    return StagePathUtils.getProcessId(processNode);// 添加到当前的process列表
}
 
Example 13
Project: maven-release-yearly-policy   File: YearlyVersionPolicy.java   Source Code and License Vote up 5 votes
private String incrementSubVersion(final String subVersion) {
    if (StringUtils.isNumeric(subVersion)) {
        return Integer.toString(Integer.parseInt(subVersion) + 1);
    }

    final String headVersionPart = StringUtils.substringBeforeLast(subVersion, ".");
    final String tailVersionPart = StringUtils.substringAfterLast(subVersion, ".");
    final Integer newSubVersion = Integer.parseInt(tailVersionPart) + 1;

    return headVersionPart + "." + newSubVersion.toString();
}
 
Example 14
Project: Reer   File: LibraryPublishArtifact.java   Source Code and License Vote up 4 votes
private static String determineExtension(File file) {
    return StringUtils.substringAfterLast(file.getName(), ".");
}
 
Example 15
Project: Reer   File: MavenArtifactNotationParserFactory.java   Source Code and License Vote up 4 votes
protected MavenArtifact parseFile(File file) {
    String extension = StringUtils.substringAfterLast(file.getName(), ".");
    return instantiator.newInstance(DefaultMavenArtifact.class, file, extension, null);
}
 
Example 16
Project: Reer   File: ReportGenerator.java   Source Code and License Vote up 4 votes
private void copyResource(String resourceName, File outputDirectory) {
    URL resource = getClass().getClassLoader().getResource("org/gradle/reporting/" + resourceName);
    String dir = StringUtils.substringAfterLast(resourceName, ".");
    GFileUtils.copyURLToFile(resource, new File(outputDirectory, dir + "/" + resourceName));
}
 
Example 17
Project: Reer   File: IvyArtifactNotationParserFactory.java   Source Code and License Vote up 4 votes
protected IvyArtifact parseFile(File file) {
    String extension = StringUtils.substringAfterLast(file.getName(), ".");
    return createDefaultIvyArtifact(file, extension, extension, null);
}
 
Example 18
Project: AEM-DataLayer   File: DefaultPageDataElement.java   Source Code and License Vote up 4 votes
@Override
public void updateDataLayer(DataLayer dataLayer) {
	EventInfo event = new EventInfo();
	event.setEventAction("pageLoad");
	event.setEventName("Page Load");
	dataLayer.getEvents().add(event);

	Page page = dataLayer.getPage();

	PageInfo pageInfo = new PageInfo();
	if (dataLayer.getConfig().getSetAuthor() == true) {
		pageInfo.setAuthor(dataLayer.getAEMPage().getLastModifiedBy());
	}

	List<String> breadcrumbs = new ArrayList<String>();
	com.day.cq.wcm.api.Page currentPage = dataLayer.getAEMPage();
	while (currentPage != null && currentPage.getDepth() > dataLayer.getConfig().getSiteRootLevel()) {
		breadcrumbs.add(currentPage.getTitle());
		currentPage = currentPage.getParent();
	}

	Collections.reverse(breadcrumbs);
	pageInfo.setBreadcrumbs(breadcrumbs.toArray(new String[breadcrumbs.size()]));

	currentPage = dataLayer.getAEMPage();
	ValueMap properties = currentPage.getContentResource().getValueMap();
	String path = DataLayerUtil.getSiteSubpath(currentPage, dataLayer.getConfig());

	pageInfo.setDestinationUrl(DataLayerUtil.getSiteUrl(currentPage, dataLayer.getConfig()));
	if (currentPage.getOnTime() != null) {
		pageInfo.setEffectiveDate(currentPage.getOnTime().getTime());
	} else if (properties.containsKey(JcrConstants.JCR_CREATED)) {
		pageInfo.setEffectiveDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
	}
	if (currentPage.getOffTime() != null) {
		pageInfo.setExpiryDate(currentPage.getOffTime().getTime());
	}
	if (properties.containsKey(JcrConstants.JCR_CREATED)) {
		pageInfo.setIssueDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
	}
	pageInfo.setLanguage(currentPage.getLanguage(false).toString());
	pageInfo.setPageId(path);
	pageInfo.setPageName(currentPage.getTitle());
	if (StringUtils.isNotEmpty(dataLayer.getConfig().getPublisher())) {
		pageInfo.setPublisher(dataLayer.getConfig().getPublisher());
	}
	pageInfo.setSysEnv(dataLayer.getConfig().getEnvironment());

	page.setPageInfo(pageInfo);

	String templateName = StringUtils.substringAfterLast(properties.get(NameConstants.NN_TEMPLATE, String.class),
			"/");
	List<String> tags = new ArrayList<String>();

	Category category = new Category();
	category.setPrimaryCategory(templateName);
	for (int i = 0; i < currentPage.getTags().length; i++) {
		category.put("tag" + i, currentPage.getTags()[i].getTitle());
		tags.add(currentPage.getTags()[i].getTitle());
	}
	page.setCategory(category);

	Map<String, Object> attributes = new HashMap<String, Object>();
	attributes.put("tags", tags.toArray(new String[tags.size()]));
	attributes.put("template", templateName);
	page.setAttributes(attributes);

}