org.apache.commons.lang3.StringUtils#stripStart ( )源码实例Demo

下面列出了org.apache.commons.lang3.StringUtils#stripStart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private String prepareTemplate(String text, String lineDelimiter, boolean addGap) {
	boolean endWithLineDelimiter = text.endsWith(lineDelimiter);
	String[] lines = text.split(lineDelimiter);
	StringBuilder buf = new StringBuilder();
	for (int i = 0; i < lines.length; i++) {
		String line = lines[i];
		if (addGap) {
			String stripped = StringUtils.stripStart(line, WHITESPACES);
			if (stripped.startsWith(ASTERISK)) {
				if (!stripped.equals(ASTERISK)) {
					int index = line.indexOf(ASTERISK);
					buf.append(line.substring(0, index + 1));
					buf.append(" ${0}");
					buf.append(lineDelimiter);
				}
				addGap = false;
			}
		}
		buf.append(StringUtils.stripEnd(line, WHITESPACES));
		if (i < lines.length - 1 || endWithLineDelimiter) {
			buf.append(lineDelimiter);
		}
	}
	return buf.toString();
}
 
源代码2 项目: esigate   文件: FragmentRedirectStrategy.java
/**
 * For local redirects, converts to relative urls.
 * 
 * @param request
 *            must be an {@link OutgoingRequest}.
 */
@Override
public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
    URI uri = this.redirectStrategy.getLocationURI(request, response, context);

    String resultingPageUrl = uri.toString();

    DriverRequest driverRequest = ((OutgoingRequest) request).getOriginalRequest();

    // Remove context if present
    if (StringUtils.startsWith(resultingPageUrl, driverRequest.getVisibleBaseUrl())) {
        resultingPageUrl =
                "/"
                        + StringUtils.stripStart(
                                StringUtils.replace(resultingPageUrl, driverRequest.getVisibleBaseUrl(), ""), "/");
    }
    resultingPageUrl = ResourceUtils.getHttpUrlWithQueryString(resultingPageUrl, driverRequest, false);

    return UriUtils.createURI(ResourceUtils.getHttpUrlWithQueryString(resultingPageUrl, driverRequest, false));
}
 
源代码3 项目: htmlunit   文件: URLSearchParams.java
private void splitQuery(String params) {
    params = StringUtils.stripStart(params, "?");
    if (StringUtils.isEmpty(params)) {
        return;
    }

    // TODO: encoding
    final String[] parts = StringUtils.split(params, '&');
    for (String part : parts) {
        params_.add(splitQueryParameter(part));
    }
}
 
源代码4 项目: HtmlUnit-Android   文件: URLSearchParams.java
private void splitQuery(String params) {
    params = StringUtils.stripStart(params, "?");
    if (StringUtils.isEmpty(params)) {
        return;
    }

    // TODO: encoding
    final String[] parts = StringUtils.split(params, '&');
    for (int i = 0; i < parts.length; i++) {
        params_.add(splitQueryParameter(parts[i]));
    }
}
 
源代码5 项目: onedev   文件: GitFilter.java
protected void processRefs(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	File gitDir;
	boolean upload;
	
	sessionManager.openSession();
	try {
		String pathInfo = request.getRequestURI().substring(request.getContextPath().length());
		pathInfo = StringUtils.stripStart(pathInfo, "/");

		String projectInfo = pathInfo.substring(0, pathInfo.length() - INFO_REFS.length());
		Project project = getProject(request, response, projectInfo);
		String service = request.getParameter("service");
		
		gitDir = storageManager.getProjectGitDir(project.getId());

		if (service.contains("upload")) {
			checkPullPermission(request, project);
			writeInitial(response, service);
			upload = true;
		} else {
			if (!SecurityUtils.canWriteCode(project))
				throw new UnauthorizedException("You do not have permission to push to this project.");
			writeInitial(response, service);
			upload = false;
		}
	} finally {
		sessionManager.closeSession();
	}
	if (upload)
		new AdvertiseUploadRefsCommand(gitDir).output(response.getOutputStream()).call();
	else
		new AdvertiseReceiveRefsCommand(gitDir).output(response.getOutputStream()).call();
}
 
源代码6 项目: engine   文件: S3Prefix.java
public S3Prefix(String prefix) {
    if (!prefix.equals(DELIMITER)) {
        prefix = StringUtils.stripStart(prefix, DELIMITER);
        prefix = StringUtils.appendIfMissing(prefix, DELIMITER);
    }

    this.prefix = prefix;
}
 
源代码7 项目: jhdf   文件: HdfFile.java
@Override
public Node getByPath(String path) {
	// As its the file its ok to have a leading slash but strip it here to be
	// consistent with other groups
	path = StringUtils.stripStart(path, Constants.PATH_SEPARATOR);
	return rootGroup.getByPath(path);
}
 
源代码8 项目: jhdf   文件: HdfFile.java
@Override
public Dataset getDatasetByPath(String path) {
	// As its the file its ok to have a leading slash but strip it here to be
	// consistent with other groups
	path = StringUtils.stripStart(path, Constants.PATH_SEPARATOR);
	return rootGroup.getDatasetByPath(path);
}
 
@SuppressWarnings("rawtypes")
/**
 * Test that the mail action is correctly constructed when sending notifications emails about users requesting access to a specific site
 * @throws Exception
 */
public void testSendModeratedEmail() throws Exception
{                  
    Map<String, String> properties = buildDefaultProperties();
    inviteModeratedSender.sendMail(ENTERPRISE_EMAIL_TEMPLATE_PATH, SendModeratedInviteDelegate.EMAIL_SUBJECT_KEY, properties);

    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_FROM), eq(requesterMail));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TO_MANY), eq(SiteManagerGroup));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT), eq(SendModeratedInviteDelegate.EMAIL_SUBJECT_KEY));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT_PARAMS), eq(new Object[]{fullSiteName}));
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TEMPLATE), eq(emailTemplateNodeRef));

    ArgumentCaptor<Map> modelC = ArgumentCaptor.forClass(Map.class);
    verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TEMPLATE_MODEL), (Serializable)modelC.capture());

    String pendingInvitesLink = StringUtils.stripStart(MessageFormat.format(InviteModeratedSender.SHARE_PENDING_INVITES_LINK, StringUtils.EMPTY, shortSiteName), "/");
    
    // Check the model
    Map model = modelC.getValue();
    assertNotNull(model);
    assertEquals(false, model.isEmpty());
    assertNotNull(model.get("productName"));
    assertEquals(model.get("inviteeName"), requesterFirstName + " " + requesterLastName);
    assertEquals(model.get("siteName"), fullSiteName);
    assertEquals(model.get("sharePendingInvitesLink"), pendingInvitesLink);
 
}
 
源代码10 项目: sunbird-lms-service   文件: UserUtil.java
private static String baseN(BigDecimal num, int base) {
  if (num.doubleValue() == 0) {
    return "0";
  }
  double div = Math.floor(num.doubleValue() / base);
  String val = baseN(new BigDecimal(div), base);
  return StringUtils.stripStart(val, stripChars)
      + alphabet[num.remainder(new BigDecimal(base)).intValue()];
}
 
private ClientPreference determineClientPreference(HttpServletRequest request) {

        String preferHeader = request.getHeader("Prefer");

        preferHeader = StringUtils.lowerCase(preferHeader);
        if (!StringUtils.startsWith(preferHeader, "return=representation")) {
            return ClientPreference.CONTAINED_DESCRIPTIONS;
        }
        preferHeader = StringUtils.stripStart(preferHeader, "return=representation;");
        preferHeader = StringUtils.strip(preferHeader);
        preferHeader = StringUtils.stripStart(preferHeader, "include=");
        preferHeader = StringUtils.strip(preferHeader, "\"");

        String[] preferences = StringUtils.split(preferHeader);
        if (preferences.length == 0) {
            return ClientPreference.CONTAINED_DESCRIPTIONS;
        }

        if (ArrayUtils.contains(preferences, PREFER_CONTAINED_IRIS) && ArrayUtils.contains(preferences, PREFER_CONTAINED_DESCRIPTIONS)) {
            return null;
        }

        for (String preference : preferences) {
            if (StringUtils.equals(preference, PREFER_CONTAINED_DESCRIPTIONS)) {
                return ClientPreference.CONTAINED_DESCRIPTIONS;
            } else if (StringUtils.equals(preference, PREFER_MINIMAL_CONTAINER)) {
                return ClientPreference.MINIMAL_CONTAINER;
            } else if (StringUtils.equals(preference, PREFER_CONTAINED_IRIS)) {
                return ClientPreference.CONTAINED_IRIS;
            }
        }

        return null;
    }
 
源代码12 项目: levelup-java-examples   文件: LeftTrimString.java
@Test
public void trim_leading_spaces_from_string_apache_commons() {

	String leftTrimmedString = StringUtils.stripStart(
			"           The Waiting          ", " ");

	assertEquals("The Waiting          ", leftTrimmedString);
}
 
源代码13 项目: DataDefender   文件: Function.java
/**
 * Looks for a class/method in the passed Function parameter in the form
 * com.package.Class#methodName, com.package.Class.methodName, or
 * com.package.Class::methodName.
 *
 * @return
 * @throws ClassNotFoundException
 */
private List<Method> getFunctionCandidates(Class<?> returnType) 
    throws ClassNotFoundException {

    int index = StringUtils.lastIndexOfAny(functionName, "#", ".", "::");
    if (index == -1) {
        throw new IllegalArgumentException(
            "Function element is empty or incomplete: " + functionName
        );
    }

    String cn = functionName.substring(0, index);
    String fn = StringUtils.stripStart(functionName.substring(index), "#.:");
    int argCount = CollectionUtils.size(arguments);

    log.debug("Looking for function in class {} with name {} and {} parameters", cn, fn, argCount);
    Class<?> clazz = registry.getClassForName(cn);
    List<Method> methods = Arrays.asList(clazz.getMethods());

    return methods
        .stream()
        .filter((m) -> {
            if (!StringUtils.equals(fn, m.getName()) || !Modifier.isPublic(m.getModifiers())) {
                return false;
            }
            final int ac = (!isCombinerFunction || Modifier.isStatic(m.getModifiers())) ? argCount : 1;
            log.debug(
                "Candidate function {} needs {} parameters and gives {} return type, "
                + "looking for {} arguments and {} return type",
                () -> m.getName(),
                () -> m.getParameterCount(),
                () -> m.getReturnType(),
                () -> ac,
                () -> returnType
            );
            return (m.getParameterCount() == ac
                && TypeConverter.isConvertible(m.getReturnType(), returnType));
        })
        .collect(Collectors.toList());
}
 
源代码14 项目: tutorials   文件: RemoveLeadingAndTrailingZeroes.java
public static String removeLeadingZeroesWithApacheCommonsStripStart(String s) {
    String stripped = StringUtils.stripStart(s, "0");

    if (stripped.isEmpty() && !s.isEmpty()) {
        return "0";
    }

    return stripped;
}
 
源代码15 项目: jinjava   文件: TextToken.java
public String output() {
  if (isLeftTrim() && isRightTrim()) {
    return trim();
  } else if (isLeftTrim()) {
    return StringUtils.stripStart(content, null);
  } else if (isRightTrim()) {
    return StringUtils.stripEnd(content, null);
  }
  return content;
}
 
源代码16 项目: tutorials   文件: LTrimRTrimUnitTest.java
@Test
public void givenString_whenCallingStringUtilsStripStartEnd_thenReturnsTrue() {
    // Use StringUtils containsIgnoreCase to avoid case insensitive issues
    String ltrim = StringUtils.stripStart(src, null);
    String rtrim = StringUtils.stripEnd(src, null);

    // Compare the Strings obtained and the expected
    Assert.assertTrue(ltrimResult.equalsIgnoreCase(ltrim));
    Assert.assertTrue(rtrimResult.equalsIgnoreCase(rtrim));
}
 
源代码17 项目: tutorials   文件: LTrimRTrim.java
@Benchmark
public boolean apacheCommonsStringUtils() {
    String ltrim = StringUtils.stripStart(src, null);
    String rtrim = StringUtils.stripEnd(src, null);

    return checkStrings(ltrim, rtrim);
}
 
源代码18 项目: onedev   文件: GitFilter.java
private String getPathInfo(HttpServletRequest request) {
	String pathInfo = request.getRequestURI().substring(request.getContextPath().length());
	return StringUtils.stripStart(pathInfo, "/");
}
 
源代码19 项目: nexus-repository-r   文件: RPathUtils.java
/**
 * Removes slash if path starts with it
 */
public static String removeInitialSlashFromPath(final String path) {
  return StringUtils.stripStart(path, "/");
}
 
private SolrInputDocument collectClass(OWLGraphWrapper graph, OWLClass c) {

		String def = graph.getDef(c);
		String com = graph.getComment(c);
		String syns = StringUtils.join(graph.getOBOSynonymStrings(c, null), " ");
		String subs = StringUtils.join(graph.getSubsets(c), " ");
		
		ArrayList<String> alt_pps = new ArrayList<String>();
		alt_pps.add("alt_id");
		String alts = StringUtils.join(graph.getAnnotationPropertyValues(c, alt_pps), " ");

		ArrayList<String> rep_pps = new ArrayList<String>();
		rep_pps.add("replaced_by");
		String reps = StringUtils.join(graph.getAnnotationPropertyValues(c, rep_pps), " ");

		ArrayList<String> con_pps = new ArrayList<String>();
		con_pps.add("consider");
		String cons = StringUtils.join(graph.getAnnotationPropertyValues(c, con_pps), " ");

		// Okay, pull out all of the variations on the ID for what people might expect in the ontology.
		String gid = graph.getIdentifier(c);
		String gid_no_namespace = StringUtils.substringAfter(gid, ":");
		String gid_no_namespace_or_leading_zeros = StringUtils.stripStart(gid_no_namespace, "0");
		
		// All together now.
		ArrayList<String> all = new ArrayList<String>();
		all.add(gid_no_namespace);
		all.add(gid_no_namespace_or_leading_zeros);
		all.add(def);
		all.add(com);
		all.add(syns);
		all.add(subs);
		all.add(alts);
		all.add(reps);
		all.add(cons);

		// Watch out for "id" collision!
		SolrInputDocument general_doc = new SolrInputDocument();
		general_doc.addField("id", "general_ontology_class_" + gid);
		general_doc.addField("entity", graph.getIdentifier(c));
		general_doc.addField("entity_label", graph.getLabel(c));
		general_doc.addField("document_category", "general");
		general_doc.addField("category", "ontology_class");
		general_doc.addField("general_blob", StringUtils.join(all, " "));
		
		return general_doc;
	}
 
 同类方法