Java Code Examples for org.apache.commons.lang3.StringUtils#removeEndIgnoreCase()

The following examples show how to use org.apache.commons.lang3.StringUtils#removeEndIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenRunnerFactory.java    From app-runner with MIT License 6 votes vote down vote up
public static Optional<MavenRunnerFactory> createIfAvailable(Config config) {
    HomeProvider homeProvider = config.javaHomeProvider();

    StringBuffer out = new StringBuffer();
    InvocationRequest request = new DefaultInvocationRequest()
        .setOutputHandler((str) -> out.append(str).append(" - "))
        .setErrorHandler((str) -> out.append(str).append(" - "))
        .setShowVersion(true)
        .setGoals(Collections.singletonList("--version"))
        .setBaseDirectory(new File("."));
    try {
        MavenRunner.runRequest(request, homeProvider);
        String versionInfo = StringUtils.removeEndIgnoreCase(out.toString(), " - ");
        return Optional.of(new MavenRunnerFactory(homeProvider, versionInfo));
    } catch (Exception e) {
        return Optional.empty();
    }
}
 
Example 2
Source File: PluginHelper.java    From fess with Apache License 2.0 6 votes vote down vote up
public Artifact getArtifactFromFileName(final ArtifactType artifactType, final String filename, final String url) {
    final String baseName = StringUtils.removeEndIgnoreCase(filename, ".jar");
    final List<String> nameList = new ArrayList<>();
    final List<String> versionList = new ArrayList<>();
    boolean isName = true;
    for (final String value : baseName.split("-")) {
        if (isName && value.length() > 0 && value.charAt(0) >= '0' && value.charAt(0) <= '9') {
            isName = false;
        }
        if (isName) {
            nameList.add(value);
        } else {
            versionList.add(value);
        }
    }
    return new Artifact(nameList.stream().collect(Collectors.joining("-")), versionList.stream().collect(Collectors.joining("-")), url);
}
 
Example 3
Source File: QQOauthPlugin.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Override
public OauthUser getOauthUser(String accessToken) {
	Assert.hasText(accessToken);
	Map<String, Object> parameterMap = new HashMap<>();
	parameterMap.put("access_token", accessToken);
	String responseString = get("https://graph.qq.com/oauth2.0/me", parameterMap);
	responseString = StringUtils.trim(responseString);
	responseString = StringUtils.removeStartIgnoreCase(responseString, "callback(");
	responseString = StringUtils.removeEndIgnoreCase(responseString, ");");
	JSONObject jsonObject = JSON.parseObject(responseString);

	String openid = jsonObject.getString("openid");
	OauthUser oauthUser = oauthUserService.findByOauthPluginIdAndUserId(getId(), openid);
	if (oauthUser == null) {
		Map<String, Object> apiMap = new HashMap<>();
		apiMap.put("access_token", accessToken);
		apiMap.put("oauth_consumer_key", jsonObject.getString("client_id"));
		apiMap.put("openid", openid);
		String apiString = get("https://graph.qq.com/user/get_user_info", apiMap);
		JSONObject userObject = JSON.parseObject(apiString);

		oauthUser = oauthUserService.newEntity();
		oauthUser.setOauthPluginId(getId());
		oauthUser.setUserId(openid);
		oauthUser.setUsername(openid);
		oauthUser.setName(userObject.getString("nickname"));
		oauthUser.setAvatarUrl(userObject.getString("figureurl_qq_2"));
	}

	return oauthUser;
}
 
Example 4
Source File: Utils.java    From para with Apache License 2.0 5 votes vote down vote up
/**
 * Quick and dirty singular to plural conversion.
 * @param singul a word
 * @return a guess of its plural form
 */
public static String singularToPlural(String singul) {
	if (!StringUtils.isAsciiPrintable(singul)) {
		return singul;
	}
	return (StringUtils.isBlank(singul) || singul.endsWith("es") || singul.endsWith("ies")) ? singul :
			(singul.endsWith("s") ? singul + "es" :
			(singul.endsWith("y") ? StringUtils.removeEndIgnoreCase(singul, "y") + "ies" :
									singul + "s"));
}
 
Example 5
Source File: RenderLinkDirective.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private String getPrettyPathForFile(FileModel fileModel)
{
    if (fileModel instanceof JavaClassFileModel)
    {
        JavaClassFileModel jcfm = (JavaClassFileModel) fileModel;
        if (jcfm.getJavaClass() == null)
            return fileModel.getPrettyPathWithinProject();
        else
            return jcfm.getJavaClass().getQualifiedName();
    }
    else if (fileModel instanceof ReportResourceFileModel)
    {
        return "resources/" + fileModel.getPrettyPath();
    }
    else if (fileModel instanceof JavaSourceFileModel)
    {
        JavaSourceFileModel javaSourceModel = (JavaSourceFileModel) fileModel;
        String filename = StringUtils.removeEndIgnoreCase(fileModel.getFileName(), ".java");
        String packageName = javaSourceModel.getPackageName();
        return packageName == null || packageName.isEmpty() ? filename : packageName + "." + filename;
    }
    // This is used for instance when showing unparsable files in the Issues Report.
    else if (fileModel instanceof ArchiveModel)
    {
        return fileModel.getPrettyPath();
    }
    else
    {
        return fileModel.getPrettyPathWithinProject();
    }
}
 
Example 6
Source File: RemoveEndIgnoreCase.java    From vscrawler with Apache License 2.0 4 votes vote down vote up
@Override
protected String handle(String input, String second) {
    return StringUtils.removeEndIgnoreCase(input, second);
}
 
Example 7
Source File: AppManager.java    From app-runner with MIT License 4 votes vote down vote up
public static String nameFromUrl(String gitUrl) {
    String name = StringUtils.removeEndIgnoreCase(StringUtils.removeEnd(gitUrl, "/"), ".git");
    name = name.substring(Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')) + 1);
    return name;
}
 
Example 8
Source File: SecurityUtils.java    From para with Apache License 2.0 4 votes vote down vote up
/**
 * Validates the signature of the request.
 * @param incoming the incoming HTTP request containing a signature
 * @param secretKey the app's secret key
 * @return true if the signature is valid
 */
public static boolean isValidSignature(HttpServletRequest incoming, String secretKey) {
	if (incoming == null || StringUtils.isBlank(secretKey)) {
		return false;
	}
	String auth = incoming.getHeader(HttpHeaders.AUTHORIZATION);
	String givenSig = StringUtils.substringAfter(auth, "Signature=");
	String sigHeaders = StringUtils.substringBetween(auth, "SignedHeaders=", ",");
	String credential = StringUtils.substringBetween(auth, "Credential=", ",");
	String accessKey = StringUtils.substringBefore(credential, "/");

	if (StringUtils.isBlank(auth)) {
		givenSig = incoming.getParameter("X-Amz-Signature");
		sigHeaders = incoming.getParameter("X-Amz-SignedHeaders");
		credential = incoming.getParameter("X-Amz-Credential");
		accessKey = StringUtils.substringBefore(credential, "/");
	}

	Set<String> headersUsed = new HashSet<>(Arrays.asList(sigHeaders.split(";")));
	Map<String, String> headers = new HashMap<>();
	for (Enumeration<String> e = incoming.getHeaderNames(); e.hasMoreElements();) {
		String head = e.nextElement().toLowerCase();
		if (headersUsed.contains(head)) {
			headers.put(head, incoming.getHeader(head));
		}
	}

	Map<String, String> params = new HashMap<>();
	for (Map.Entry<String, String[]> param : incoming.getParameterMap().entrySet()) {
		params.put(param.getKey(), param.getValue()[0]);
	}

	String path = incoming.getRequestURI();
	String endpoint = StringUtils.removeEndIgnoreCase(incoming.getRequestURL().toString(), path);
	String httpMethod = incoming.getMethod();
	InputStream entity;
	try {
		entity = new BufferedRequestWrapper(incoming).getInputStream();
		if (entity.available() <= 0) {
			entity = null;
		}
	} catch (IOException ex) {
		logger.error(null, ex);
		entity = null;
	}

	Signer signer = new Signer();
	Map<String, String> sig = signer.sign(httpMethod, endpoint, path, headers, params, entity, accessKey, secretKey);

	String auth2 = sig.get(HttpHeaders.AUTHORIZATION);
	String recreatedSig = StringUtils.substringAfter(auth2, "Signature=");

	boolean signaturesMatch = StringUtils.equals(givenSig, recreatedSig);
	if (Config.getConfigBoolean("debug_request_signatures", false)) {
		logger.info("Incoming client signature for request {} {}: {} == {} calculated by server, matching: {}",
				httpMethod, path, givenSig, recreatedSig, signaturesMatch);
	}
	return signaturesMatch;
}
 
Example 9
Source File: SystemEnvironment.java    From gocd with Apache License 2.0 4 votes vote down vote up
private String trimMegaFromSize(String sizeInMega) {
    return StringUtils.removeEndIgnoreCase(sizeInMega, "M");
}
 
Example 10
Source File: TextUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Removes the last occurrence of the word "or" from the given string,
 * including potential trailing spaces, case-insensitive.
 *
 * @param string the string.
 * @return the chopped string.
 */
public static String removeLastOr( String string )
{
    string = StringUtils.stripEnd( string, " " );

    return StringUtils.removeEndIgnoreCase( string, "or" );
}
 
Example 11
Source File: TextUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Removes the last occurrence of the word "and" from the given string,
 * including potential trailing spaces, case-insensitive.
 *
 * @param string the string.
 * @return the chopped string.
 */
public static String removeLastAnd( String string )
{
    string = StringUtils.stripEnd( string, " " );

    return StringUtils.removeEndIgnoreCase( string, "and" );
}
 
Example 12
Source File: TextUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Removes the last occurrence of comma (",") from the given string,
 * including potential trailing spaces.
 *
 * @param string the string.
 * @return the chopped string.
 */
public static String removeLastComma( String string )
{
    string = StringUtils.stripEnd( string, " " );

    return StringUtils.removeEndIgnoreCase( string, "," );
}
 
Example 13
Source File: TextUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Removes the last occurrence of the the given string, including potential
 * trailing spaces.
 *
 * @param string the string, without potential trailing spaces.
 * @param remove the text to remove.
 * @return the chopped string.
 */
public static String removeLast( String string, String remove )
{
    string = StringUtils.stripEnd( string, " " );

    return StringUtils.removeEndIgnoreCase( string,  remove );
}