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

The following are Jave code examples for showing how to use substringBefore() 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.
+ Save this method
Example 1
Project: instalint   File: Version.java   View Source Code Vote up 8 votes
private Version(String version) {
  this.name = StringUtils.trimToEmpty(version);
  this.qualifier = StringUtils.substringAfter(this.name, "-");
  String numbers = StringUtils.substringBefore(this.name, "-");
  String[] split = StringUtils.split(numbers, '.');
  if (split.length >= 1) {
    major = split[0];
    normalizedMajor = normalizePart(major);
  }
  if (split.length >= 2) {
    minor = split[1];
    normalizedMinor = normalizePart(minor);
  }
  if (split.length >= 3) {
    patch = split[2];
    normalizedPatch = normalizePart(patch);
  }
  if (split.length >= 4) {
    patch2 = split[3];
    normalizedPatch2 = normalizePart(patch2);
  }
}
 
Example 2
Project: DBus   File: Support.java   View Source Code Vote up 6 votes
public static int[] getColumnLengthAndPrecision(Column column){
	int[] ret = new int[2];
	String data = StringUtils.substringBetween(column.getMysqlType(), "(",")");
	String length = StringUtils.substringBefore(data, ",");
	String precision = StringUtils.substringAfter(data, ",");
	String type = getColumnType(column).toUpperCase();
	if("SET".equals(type) || "ENUM".equals(type)){
		ret[0] = 0;
		ret[1] = 0;
	}else{
		if(StringUtils.isEmpty(length)){
			ret[0] = 0;
		}else{
			ret[0] = Integer.parseInt(length);
		}
		if(StringUtils.isEmpty(precision)){
			ret[1] = 0;
		}else{
			ret[1] = Integer.parseInt(precision);
		}
	}
	return ret;
}
 
Example 3
Project: otter-G   File: ConfigHelper.java   View Source Code Vote up 6 votes
public static String makeSQLPattern(ModeValue mode, String rawValue) {
    Assert.notNull(mode);
    Assert.notNull(rawValue);
    if (mode.getMode().isSingle()) {
        return rawValue;
    } else if (mode.getMode().isMulti()) {
        return StringUtils.substringBefore(rawValue, "[") + "%";
    } else if (mode.getMode().isWildCard()) {
        StringBuilder sb = new StringBuilder(rawValue.length());
        FOR_LOOP: for (int i = 0; i < rawValue.length(); i++) {
            String charString = String.valueOf(rawValue.charAt(i));
            if (isWildCard(charString)) {
                break FOR_LOOP;
            } else {
                sb.append(rawValue.charAt(i));
            }
        }
        return sb.toString() + "%";
    } else {
        throw new UnsupportedOperationException("unsupport mode:" + mode.getMode());
    }
}
 
Example 4
Project: maven-release-yearly-policy   File: YearlyVersionPolicy.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
public VersionPolicyResult getDevelopmentVersion(final VersionPolicyRequest versionPolicyRequest)
        throws PolicyException, VersionParseException {
    final VersionPolicyResult result = new VersionPolicyResult();
    final String version = versionPolicyRequest.getVersion();

    if (version.endsWith(snapshotPostfix)) {
        result.setVersion(version);
    } else {
        final String majorVersionComponent = StringUtils.substringBefore(version, ".");

        if (matchesYear(majorVersionComponent, currentYear)) {
            result.setVersion(incrementVersionWithinYear(version) + snapshotPostfix);
        } else {
            result.setVersion(firstOfYear() + snapshotPostfix);
        }
    }

    return result;
}
 
Example 5
Project: TakeoutService   File: CommonUtil.java   View Source Code Vote up 5 votes
/**
 * 直接输出内容的简便函数.

 * eg.
 * render("text/plain", "hello", "encoding:GBK");
 * render("text/plain", "hello", "no-cache:false");
 * render("text/plain", "hello", "encoding:GBK", "no-cache:false");
 * 
 * @param headers 可变的header数组,目前接受的值为"encoding:"或"no-cache:",默认值分别为UTF-8和true.
 */
public static void render(final HttpServletResponse response,final String contentType, final String content, final String... headers) {
	try {
		//分析headers参数
		String encoding = ENCODING_DEFAULT;
		boolean noCache = NOCACHE_DEFAULT;
		for (String header : headers) {
			String headerName = StringUtils.substringBefore(header, ":");
			String headerValue = StringUtils.substringAfter(header, ":");

			if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) {
				encoding = headerValue;
			} else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) {
				noCache = Boolean.parseBoolean(headerValue);
			} else
				throw new IllegalArgumentException(headerName + "不是一个合法的header类型");
		}

		//设置headers参数
		String fullContentType = contentType + ";charset=" + encoding;
		response.setContentType(fullContentType);
		if (noCache) {
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
		}

		PrintWriter writer = response.getWriter();
		writer.write(content);
		writer.flush();
		writer.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 6
Project: DBus   File: TableMatchContainer.java   View Source Code Vote up 5 votes
public void addTableRegex(String tableRegex){
	String[] tableRegexs = StringUtils.split(tableRegex, ",");
	for(String regex : tableRegexs){
		String localTbl = StringUtils.substringBefore(regex.trim(), ".");
		String partitionTblRegex = StringUtils.substringAfter(regex.trim(), ".");
		map.put(localTbl, partitionTblRegex);
	}
	
}
 
Example 7
Project: sling-org-apache-sling-query   File: ResourceMock.java   View Source Code Vote up 5 votes
@Override
public Resource getChild(String relPath) {
	if (StringUtils.contains(relPath, '/')) {
		String firstPart = StringUtils.substringBefore(relPath, "/");
		String rest = StringUtils.substringAfter(relPath, "/");
		if (children.containsKey(firstPart)) {
			return children.get(firstPart).getChild(rest);
		}
	} else if (children.containsKey(relPath)) {
		return children.get(relPath);
	}

	return null;
}
 
Example 8
Project: cas4.0.x-server-wechat   File: BaseOAuthWrapperController.java   View Source Code Vote up 5 votes
/**
 * Return the method to call according to the url.
 *
 * @param request the incoming http request
 * @return the method to call according to the url
 */
private String getMethod(final HttpServletRequest request) {
    String method = request.getRequestURI();
    if (method.indexOf("?") >= 0) {
        method = StringUtils.substringBefore(method, "?");
    }
    final int pos = method.lastIndexOf("/");
    if (pos >= 0) {
        method = method.substring(pos + 1);
    }
    return method;
}
 
Example 9
Project: wrdocletbase   File: WRTagTaglet.java   View Source Code Vote up 5 votes
/**
 * Split string to get tag set.
 * 
 * @param tags
 *            the String of tags to split.
 * @return set of tags.
 */
public static Set<String> getTagSet(String tags) {
	tags = StringUtils.substringBefore(tags, "\n");
	String[] tagArr = tags.split("[\\s,,;;]");
	Set<String> tagSet = new HashSet<String>();
	for (int i = 0; i < tagArr.length; i++) {
		String tag = tagArr[i].trim();
		if (!tag.isEmpty()) {
			tagSet.add(tag);
		}
	}
	return tagSet;
}
 
Example 10
Project: wrdocletbase   File: AbstractDocBuilder.java   View Source Code Vote up 5 votes
protected String getMQConsumerTopic(ClassDoc classDoc) {
	Tag[] tags = classDoc.tags(WRMqConsumerTaglet.NAME);
	if (tags.length == 0) {
		return "";
	}
	return StringUtils.substringBefore(tags[0].text(), "\n");
}
 
Example 11
Project: wrdocletbase   File: AbstractDocBuilder.java   View Source Code Vote up 5 votes
protected String getMQProducerTopic(ClassDoc classDoc) {
	Tag[] tags = classDoc.tags(WRMqProducerTaglet.NAME);
	if (tags.length == 0) {
		return "";
	}
	return StringUtils.substringBefore(tags[0].text(), "\n");
}
 
Example 12
Project: Ins_fb_pictureSpider_WEB   File: BaseUtils.java   View Source Code Vote up 5 votes
/**
 * 分析并设置contentType与headers.
 */
private static HttpServletResponse initResponseHeader(final String contentType, final String... headers) {
    //分析headers参数
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else {
            throw new IllegalArgumentException(headerName + "不是一个合法的header类型");
        }
    }

    HttpServletResponse response = ServletActionContext.getResponse();

    //设置headers参数
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);
    if (noCache) {
        ServletUtils.setDisableCacheHeader(response);
    }

    return response;
}
 
Example 13
Project: athena   File: ApplicationArchive.java   View Source Code Vote up 5 votes
private String compactDescription(String sentence) {
    if (StringUtils.isNotEmpty(sentence)) {
        if (StringUtils.contains(sentence, ".")) {
            return StringUtils.substringBefore(sentence, ".") + ".";
        } else {
            return sentence;
        }
    }
    return sentence;
}
 
Example 14
Project: maven-release-yearly-policy   File: YearlyVersionPolicy.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
public VersionPolicyResult getReleaseVersion(final VersionPolicyRequest versionPolicyRequest)
        throws PolicyException, VersionParseException {
    final String version = versionPolicyRequest.getVersion();
    final String cleanedVersion = StringUtils.removeEnd(version, snapshotPostfix);
    final String majorVersionComponent = StringUtils.substringBefore(cleanedVersion, ".");

    final String releaseVersion = matchesYear(majorVersionComponent, currentYear) ? cleanedVersion : firstOfYear();

    return new VersionPolicyResult()
            .setVersion(releaseVersion);
}
 
Example 15
Project: DBus   File: Support.java   View Source Code Vote up 4 votes
public static boolean isSupported(Column column){
	String type = StringUtils.substringBefore(column.getMysqlType(), "(");
	return SupportedMysqlDataType.isSupported(type);
}
 
Example 16
Project: DBus   File: Support.java   View Source Code Vote up 4 votes
public static String getColumnType(Column column){
	return StringUtils.substringBefore(column.getMysqlType(), "(");
}
 
Example 17
Project: DBus   File: Support.java   View Source Code Vote up 4 votes
public static void main(String[] args){
	String str="int";
	String length = StringUtils.substringBetween(str, "(",")");
	String precision = StringUtils.substringBefore(length, ",");
	String scale = StringUtils.substringAfter(length, ",");
}
 
Example 18
Project: instalint   File: Version.java   View Source Code Vote up 4 votes
public Version removeQualifier() {
  return new Version(StringUtils.substringBefore(this.toString(), "-"));
}