本文整理汇总了Java中org.apache.commons.lang3.StringUtils.substringBetween方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.substringBetween方法的具体用法?Java StringUtils.substringBetween怎么用?Java StringUtils.substringBetween使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.substringBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private Privilege parse(String expression) {
Privilege privilege = new Privilege();
privilege.setMsName(appName);
String[] inputParams = StringUtils.split(expression, ",");
for (int i = 0; i < inputParams.length; i++) {
if (i == inputParams.length - 1) {
if (StringUtils.contains(inputParams[i], "'")) {
privilege.setKey(StringUtils.substringBetween(inputParams[i], "'")
.replace("@msName", appName.toUpperCase()));
} else {
privilege.setKey(inputParams[i].replace("@msName", appName.toUpperCase()));
}
} else {
String resource = StringUtils.substringBetween(inputParams[i], "'");
if (StringUtils.isNotEmpty(resource)) {
privilege.getResources().add(resource);
}
}
}
return privilege;
}
示例2: constructPatternId
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String constructPatternId(String patternResourcePath, String patternsPath, String templateName, String jsonDataFileName) {
final String patternPath = StringUtils.substringAfter(patternResourcePath, patternsPath + SLASH);
final StringBuilder patternIdBuilder = new StringBuilder();
if (StringUtils.endsWith(patternPath, HTML_EXT)) {
patternIdBuilder.append(StringUtils.substringBeforeLast(patternPath, HTML_EXT));
} else {
patternIdBuilder.append(patternPath);
}
if (StringUtils.isNotBlank(templateName)) {
patternIdBuilder.append(SLASH).append(templateName);
}
if (StringUtils.isNotBlank(jsonDataFileName)) {
final String patternFileName = StringUtils.substringAfterLast(patternPath, SLASH);
final String fileNameWithoutExt = StringUtils.substringBeforeLast(patternFileName, HTML_EXT);
final String dataFileSuffix = StringUtils.substringBetween(jsonDataFileName, fileNameWithoutExt
+ SELECTOR, DATA_EXT);
patternIdBuilder.append(SLASH).append(StringUtils.defaultString(dataFileSuffix, fileNameWithoutExt));
}
return StringUtils.replace(patternIdBuilder.toString(), SLASH, PATTERN_ID_REPLACEMENT);
}
示例3: buildElements
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public void buildElements(String servletName, String urlContent) {
if (urlContent == null) {
throw new NullPointerException("urlContent is null");
}
if (! urlContent.contains("/session/")) {
throw new IllegalArgumentException("Request does not contain /session/ subpath in path");
}
session = StringUtils.substringBetween(urlContent, "/session/", "/");
if (session == null) {
throw new IllegalArgumentException("Request does not contain session id");
}
}
示例4: getToken
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String getToken(String username, String password) {
try {
String url = TestConfiguration.masterUrl() + "/oauth/authorize?response_type=token&client_id=openshift-challenging-client";
List<Header> headers = HttpClient.get(url)
.basicAuth(username, password)
.preemptiveAuth()
.disableRedirect()
.responseHeaders();
Optional<Header> location = headers.stream().filter(h -> "Location".equals(h.getName())).findFirst();
if (location.isPresent()) {
LOGGER.debug("Location: {}", location.get().getValue());
String token = StringUtils.substringBetween(location.get().getValue(), "#access_token=", "&");
LOGGER.info("Oauth token: {}", token);
return token;
}
LOGGER.info("Location header with token not found");
return null;
} catch (IOException e) {
LOGGER.error("Error getting token from master", e);
return null;
}
}
示例5: syncCheck
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private String[] syncCheck() throws IOException {
Map<String, Object> request = new HashMap<>();
request.put("r", new Date().getTime());
request.put("sid", initData.get("wxsid"));
request.put("uin", initData.get("wxuin"));
request.put("skey", initData.get("skey"));
request.put("deviceid", initData.get("deviceID"));
request.put("synckey", syncKeyStr);
request.put("_", new Date().getTime());
String url = "https://" + syncHost + "/cgi-bin/mmwebwx-bin/synccheck?" + NetUtils.getUrlParamsByMap(request, false);
log.trace("url: " + url);
String response = NetUtils.request(url);
log.trace("syncCheck response: " + response);
String retcode = StringUtils.substringBetween(response, "retcode:\"", "\",");
String selector = StringUtils.substringBetween(response, "selector:\"", "\"}");
return new String[]{retcode, selector};
}
示例6: getJsonData
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String getJsonData(String input, String startTag, String endTag)
{
if(StringUtils.isNotBlank(startTag) && StringUtils.isNotBlank(endTag))
{
return StringUtils.substringBetween(input,startTag, endTag);
}
return null;
}
示例7: internalVerifyClientOK
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void internalVerifyClientOK(final RegisteredService service, final boolean basicAuth, final boolean refreshToken, final boolean json)
throws Exception {
final Principal principal = createPrincipal();
final OAuthCode code = addCode(principal, service);
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.AUTHORIZATION_CODE.name().toLowerCase());
if (basicAuth) {
final String auth = CLIENT_ID + ':' + CLIENT_SECRET;
final String value = Base64.encodeBase64String(auth.getBytes(StandardCharsets.UTF_8));
mockRequest.addHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BASIC_HEADER_PREFIX + value);
} else {
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.CLIENT_SECRET, CLIENT_SECRET);
}
mockRequest.setParameter(OAuth20Constants.CODE, code.getId());
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
oAuth20AccessTokenController.handleRequest(mockRequest, mockResponse);
assertNull(this.ticketRegistry.getTicket(code.getId()));
assertEquals(HttpStatus.SC_OK, mockResponse.getStatus());
final String body = mockResponse.getContentAsString();
final String accessTokenId;
if (json) {
assertEquals(MediaType.APPLICATION_JSON_VALUE, mockResponse.getContentType());
assertTrue(body.contains('"' + OAuth20Constants.ACCESS_TOKEN + "\":\"AT-"));
if (refreshToken) {
assertTrue(body.contains('"' + OAuth20Constants.REFRESH_TOKEN + "\":\"RT-"));
}
assertTrue(body.contains('"' + OAuth20Constants.EXPIRES_IN + "\":7"));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + "\":\"", "\",\"");
} else {
assertEquals(MediaType.TEXT_PLAIN_VALUE, mockResponse.getContentType());
assertTrue(body.contains(OAuth20Constants.ACCESS_TOKEN + "=AT-"));
if (refreshToken) {
assertTrue(body.contains(OAuth20Constants.REFRESH_TOKEN + "=RT-"));
}
assertTrue(body.contains(OAuth20Constants.EXPIRES_IN + '='));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + '=', "&");
}
final AccessToken accessToken = this.ticketRegistry.getTicket(accessTokenId, AccessToken.class);
assertEquals(principal, accessToken.getAuthentication().getPrincipal());
final int timeLeft = getTimeLeft(body, refreshToken, json);
assertTrue(timeLeft >= TIMEOUT - 10 - DELTA);
}
示例8: internalVerifyUserAuth
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void internalVerifyUserAuth(final boolean refreshToken, final boolean json) throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.PASSWORD.name().toLowerCase());
mockRequest.setParameter(USERNAME, GOOD_USERNAME);
mockRequest.setParameter(PASSWORD, GOOD_PASSWORD);
mockRequest.addHeader(CasProtocolConstants.PARAMETER_SERVICE, REDIRECT_URI);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
oAuth20AccessTokenController.handleRequest(mockRequest, mockResponse);
assertEquals(200, mockResponse.getStatus());
final String body = mockResponse.getContentAsString();
final String accessTokenId;
if (json) {
assertEquals("application/json", mockResponse.getContentType());
assertTrue(body.contains('"' + OAuth20Constants.ACCESS_TOKEN + "\":\"AT-"));
if (refreshToken) {
assertTrue(body.contains('"' + OAuth20Constants.REFRESH_TOKEN + "\":\"RT-"));
}
assertTrue(body.contains('"' + OAuth20Constants.EXPIRES_IN + "\":7"));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + "\":\"", "\",\"");
} else {
assertEquals("text/plain", mockResponse.getContentType());
assertTrue(body.contains(OAuth20Constants.ACCESS_TOKEN + '='));
if (refreshToken) {
assertTrue(body.contains(OAuth20Constants.REFRESH_TOKEN + '='));
}
assertTrue(body.contains(OAuth20Constants.EXPIRES_IN + '='));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + '=', "&");
}
final AccessToken accessToken = this.ticketRegistry.getTicket(accessTokenId, AccessToken.class);
assertEquals(GOOD_USERNAME, accessToken.getAuthentication().getPrincipal().getId());
final int timeLeft = getTimeLeft(body, refreshToken, json);
assertTrue(timeLeft >= TIMEOUT - 10 - DELTA);
}
示例9: internalVerifyRefreshTokenOk
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void internalVerifyRefreshTokenOk(final OAuthRegisteredService service, final boolean json) throws Exception {
final Principal principal = createPrincipal();
final RefreshToken refreshToken = addRefreshToken(principal, service);
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.REFRESH_TOKEN.name().toLowerCase());
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.CLIENT_SECRET, CLIENT_SECRET);
mockRequest.setParameter(OAuth20Constants.REFRESH_TOKEN, refreshToken.getId());
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
oAuth20AccessTokenController.handleRequest(mockRequest, mockResponse);
assertEquals(200, mockResponse.getStatus());
final String body = mockResponse.getContentAsString();
final String accessTokenId;
if (json) {
assertEquals("application/json", mockResponse.getContentType());
assertTrue(body.contains('"' + OAuth20Constants.ACCESS_TOKEN + "\":\"AT-"));
assertFalse(body.contains('"' + OAuth20Constants.REFRESH_TOKEN + "\":\"RT-"));
assertTrue(body.contains('"' + OAuth20Constants.EXPIRES_IN + "\":7"));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + "\":\"", "\",\"");
} else {
assertEquals("text/plain", mockResponse.getContentType());
assertTrue(body.contains(OAuth20Constants.ACCESS_TOKEN + '='));
assertFalse(body.contains(OAuth20Constants.REFRESH_TOKEN + '='));
assertTrue(body.contains(OAuth20Constants.EXPIRES_IN + '='));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + '=', "&");
}
final AccessToken accessToken = this.ticketRegistry.getTicket(accessTokenId, AccessToken.class);
assertEquals(principal, accessToken.getAuthentication().getPrincipal());
final int timeLeft = getTimeLeft(body, false, json);
assertTrue(timeLeft >= TIMEOUT - 10 - DELTA);
}
示例10: showAdminFunctions
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Shows administrator functions with the specified context.
*
* @param request
* the specified request
* @param context
* the specified context
*/
@RequestMapping(value = { "/admin-article.do", "/admin-article-list.do", "/admin-comment-list.do",
"/admin-link-list.do", "/admin-page-list.do", "/admin-others.do", "/admin-draft-list.do",
"/admin-user-list.do", "/admin-category-list.do", "/admin-plugin-list.do", "/admin-main.do",
"/admin-about.do" }, method = RequestMethod.GET)
public void showAdminFunctions(final HttpServletRequest request, final HttpServletResponse response) {
final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
final String requestURI = request.getRequestURI();
final String templateName = StringUtils.substringBetween(requestURI, Latkes.getContextPath() + '/', ".")
+ ".ftl";
logger.trace("Admin function[templateName={}]", templateName);
renderer.setTemplateName(templateName);
final Locale locale = Latkes.getLocale();
final Map<String, String> langs = langPropsService.getAll(locale);
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put("isMySQL", RuntimeDatabase.MYSQL == Latkes.getRuntimeDatabase());
dataModel.putAll(langs);
Keys.fillRuntime(dataModel);
dataModel.put(Option.ID_C_LOCALE_STRING, locale.toString());
fireFreeMarkerActionEvent(templateName, dataModel);
renderer.render(request, response);
}
示例11: buildFromString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Builds a Savepoint from a String
*
* @param savepointStrthe
* String containing a SavepointHttp.toString()
* @return a SavepointHttp
*/
public static Savepoint buildFromString(String savepointStr) {
if (savepointStr == null) {
throw new IllegalArgumentException("Savepoint can not be null!");
}
if (!savepointStr.contains("[id=") || !savepointStr.contains(", name")
|| !savepointStr.endsWith("]")) {
throw new IllegalArgumentException(
"Savepoint String is not conform to pattern [id=theId, name=theName]: "
+ savepointStr);
}
String idStr = StringUtils.substringBetween(savepointStr, "[id=",
", name=");
if (idStr == null) {
throw new IllegalArgumentException("id as String can not be null!");
}
idStr = idStr.trim();
int id = Integer.parseInt(idStr);
String name = StringUtils
.substringBetween(savepointStr, ", name=", "]");
if (name == null) {
throw new IllegalArgumentException("name can not be null!");
}
name = name.trim();
SavepointHttp savepointHttp = new SavepointHttp(id, name);
return savepointHttp;
}
示例12: getLessonAndGroupInfoFromSpan
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private String[] getLessonAndGroupInfoFromSpan(Element span) {
String[] subjectNameArray = span.text().split(" ");
String groupName = subjectNameArray[subjectNameArray.length - 1];
return new String[]{
span.text().replace(" " + groupName, ""),
StringUtils.substringBetween(groupName, "[", "]")
};
}
示例13: getUuid
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public WechatBot getUuid() throws IOException {
loginUrl = loginUrl + new Date().getTime();
log.trace("loginUrl: " + loginUrl);
String response = NetUtils.request(loginUrl);
// e.g: window.QRLogin.code = 200; window.QRLogin.uuid = "wejZcbBd2w==";
String code = StringUtils.substringBetween(response, "window.QRLogin.code = ", ";");
uuid = StringUtils.substringBetween(response, "window.QRLogin.uuid = \"", "\";");
log.debug("window.QRLogin.code = " + code);
log.debug("window.QRLogin.uuid = " + uuid);
return this;
}
示例14: waitForLogin
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public WechatBot waitForLogin() throws IOException, InterruptedException {
String url = StringUtils.join("https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=", uuid, "&tip=1&_=", new Date().getTime());
log.trace("login url: " + url);
while (true) {
String response = NetUtils.request(url);
log.trace("response: " + response);
// 登陆过程中
if (StringUtils.startsWith(response, "window.code=")) {
String code = StringUtils.substringBetween(response, "window.code=", ";");
log.debug("code: " + code);
if (StringUtils.equals(code, SUCCESS)) {
log.info("登陆成功");
response = NetUtils.request(url);
redirectUrl = StringUtils.substringBetween(response, "window.redirect_uri=\"", "\";");
if (StringUtils.isNotEmpty(redirectUrl)) {
log.debug("redirectUrl: " + redirectUrl);
break;
}
} else if (StringUtils.equals(code, SCANED))
log.info("请点击确认按钮");
else if (StringUtils.equals(code, TIMEOUT)) {
log.info("登陆超时");
System.exit(-1);
} else {
log.info("未知错误");
log.error(response);
System.exit(-1);
}
}
// 轮询时间 1s
Thread.sleep(1000);
}
return this;
}
示例15: getLabels
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private static Set<String> getLabels(String line) {
String open = "#{";
String close = "}#";
Set<String> labels = new HashSet<>();
String label = StringUtils.substringBetween(line, open, close);
while (StringUtils.isNotBlank(label)) {
labels.add(label);
line = StringUtils.replace(line, open + label + close, "");
label = StringUtils.substringBetween(line, open, close);
}
return labels;
}