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

The following examples show how to use org.apache.commons.lang3.StringUtils#prependIfMissing() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public Response push(final AnyQuery anyQuery, final CSVPushSpec spec) {
    String realm = StringUtils.prependIfMissing(anyQuery.getRealm(), SyncopeConstants.ROOT_REALM);

    SearchCond searchCond = StringUtils.isBlank(anyQuery.getFiql())
            ? null
            : getSearchCond(anyQuery.getFiql(), realm);

    StreamingOutput sout = (os) -> logic.push(
            searchCond,
            anyQuery.getPage(),
            anyQuery.getSize(),
            getOrderByClauses(anyQuery.getOrderBy()),
            realm,
            spec,
            os);

    return Response.ok(sout).
            type(RESTHeaders.TEXT_CSV).
            header(HttpHeaders.CONTENT_DISPOSITION,
                    "attachment; filename=" + AuthContextUtils.getDomain() + ".csv").
            build();
}
 
Example 2
Source Project: syncope   File: AbstractAnyService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public PagedResult<TO> search(final AnyQuery anyQuery) {
    String realm = StringUtils.prependIfMissing(anyQuery.getRealm(), SyncopeConstants.ROOT_REALM);

    // if an assignable query is provided in the FIQL string, start anyway from root realm
    boolean isAssignableCond = StringUtils.isBlank(anyQuery.getFiql())
            ? false
            : -1 != anyQuery.getFiql().indexOf(SpecialAttr.ASSIGNABLE.toString());

    SearchCond searchCond = StringUtils.isBlank(anyQuery.getFiql())
            ? null
            : getSearchCond(anyQuery.getFiql(), realm);

    Pair<Integer, List<TO>> result = getAnyLogic().search(
            searchCond,
            anyQuery.getPage(),
            anyQuery.getSize(),
            getOrderByClauses(anyQuery.getOrderBy()),
            isAssignableCond ? SyncopeConstants.ROOT_REALM : realm,
            anyQuery.getDetails());

    return buildPagedResult(result.getRight(), anyQuery.getPage(), anyQuery.getSize(), result.getLeft());
}
 
Example 3
Source Project: tutorials   File: StringUtilsUnitTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenString_whenAppendingAndPrependingIfMissing_thenCorrect() {
    String string = "baeldung.com";
    String stringWithSuffix = StringUtils.appendIfMissing(string, ".com");
    String stringWithPrefix = StringUtils.prependIfMissing(string, "www.");
    assertEquals("baeldung.com", stringWithSuffix);
    assertEquals("www.baeldung.com", stringWithPrefix);
}
 
Example 4
@Override
public String buildTargetedUrl(String prefix, String targetId, String suffix) {
    String targetedUrl = "";

    if (StringUtils.isNotEmpty(prefix)) {
        targetedUrl = UrlUtils.concat(targetedUrl, prefix);
    }
    if (StringUtils.isNotEmpty(targetId)) {
        targetedUrl = UrlUtils.concat(targetedUrl, targetId);
    }
    if (StringUtils.isNotEmpty(suffix)) {
        targetedUrl = UrlUtils.concat(targetedUrl, suffix);
    }

    targetedUrl = StringUtils.prependIfMissing(targetedUrl, "/");

    return targetedUrl;
}
 
Example 5
@Override
public String buildTargetedUrl(String prefix, String targetId, String suffix) {
    String targetedUrl = "";

    if (StringUtils.isNotEmpty(prefix)) {
        targetedUrl += prefix;
    }
    if (StringUtils.isNotEmpty(targetId)) {
        if (StringUtils.isNotEmpty(targetedUrl)) {
            targetedUrl = StringUtils.appendIfMissing(targetedUrl, targetIdSeparator);
        }

        targetedUrl += targetId;
    }
    if (StringUtils.isNotEmpty(suffix)) {
        targetedUrl += StringUtils.prependIfMissing(suffix, ".");
    }

    targetedUrl = StringUtils.prependIfMissing(targetedUrl, "/");

    return targetedUrl;
}
 
Example 6
Source Project: metron   File: StringFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(List<Object> strings) {

  String prefixed;
  switch (strings.size()) {
    case 2: prefixed = StringUtils.prependIfMissing((String) strings.get(0), (String) strings.get(1));
      break;
    case 3: prefixed = StringUtils.prependIfMissing((String) strings.get(0), (String) strings.get(1), (String) strings.get(2));
      break;
    default: throw new IllegalArgumentException("[PREPEND_IF_MISSING] incorrect arguments: " + strings.toString() + "\nUsage: PREPEND_IF_MISSING <String> <prefix> [<prefix>...]");
  }
  return prefixed;
}
 
Example 7
Source Project: vividus   File: ResourceUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static String ensureRootPath(String resourceName)
{
    return StringUtils.prependIfMissing(resourceName, "/");
}
 
Example 8
@Override
public boolean handleMouseClick(String[] annotationParts, Navigatable navigatable,
		ServiceProvider serviceProvider) {

	ProjectDataService projectDataService =
		serviceProvider.getService(ProjectDataService.class);
	ProjectData projectData = projectDataService.getProjectData();

	// default folder is the root folder
	DomainFolder folder = projectData.getRootFolder();

	// Get program name and folder from program comment annotation 
	// handles forward and back slashes and with and without first slash
	String programText = getProgramText(annotationParts);
	String programName = FilenameUtils.getName(programText);
	String path = FilenameUtils.getFullPathNoEndSeparator(programText);
	if (path.length() > 0) {
		path = StringUtils.prependIfMissing(FilenameUtils.separatorsToUnix(path), "/");
		folder = projectData.getFolder(path);
	}

	if (folder == null) {
		Msg.showInfo(getClass(), null, "No Folder: " + path,
			"Unable to locate folder by the name \"" + path);
		return true;
	}

	DomainFile programFile = findProgramByName(programName, folder);

	if (programFile == null) {
		Msg.showInfo(getClass(), null, "No Program: " + programName,
			"Unable to locate a program by the name \"" + programName +
				"\".\nNOTE: Program name is case-sensitive. ");
		return true;
	}

	SymbolPath symbolPath = getSymbolPath(annotationParts);
	navigate(programFile, symbolPath, navigatable, serviceProvider);

	return true;
}
 
Example 9
protected static String slashify(String file) {
  // For backwards compatibility/consistency we need to add a leading /
  return StringUtils.prependIfMissing(file, "/");
}
 
Example 10
Source Project: olingo-odata4   File: JsonDeserializer.java    License: Apache License 2.0 4 votes vote down vote up
protected String getJSONAnnotation(final String string) {
  return StringUtils.prependIfMissing(string, "@");
}