List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n characters from the end of the String.
The returned substring starts with the character in the start position and ends before the end position.
From source file:com.thoughtworks.go.domain.label.PipelineLabel.java
public void updateLabel(Map<CaseInsensitiveString, String> namedRevisions, int pipelineCounter) { this.label = interpolateLabel(namedRevisions, pipelineCounter); this.label = StringUtils.substring(label, 0, 255); }
From source file:com.github.cherimojava.orchidae.util.FileUtil.java
public File getFileHandle(String id) { String substring = StringUtils.substring(id, 0, subfolders * foldernameSize); return new File(files.getUnchecked(substring), StringUtils.substring(id, subfolders * foldernameSize)); }
From source file:common.util.PropertyFilter.java
/** * @param filterName//from ww w. j a v a 2 s. co m * @param value */ public PropertyFilter(final String filterName, final String value) { String matchTypeStr; String matchPattenCode = LikeMatchPatten.ALL.toString(); String matchTypeCode; String propertyTypeCode; if (filterName.contains("LIKE") && filterName.charAt(0) != 'L') { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchPattenCode = StringUtils.substring(matchTypeStr, 0, 1); matchTypeCode = StringUtils.substring(matchTypeStr, 1, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } else { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); likeMatchPatten = Enum.valueOf(LikeMatchPatten.class, matchPattenCode); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with rules, not get more types of property.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with the rules, attribute value types can not be.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, PARAM_PREFIX); propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); Validate.isTrue(propertyNames.length > 0, "filter name: " + filterName + "Not prepared in accordance with the rules, property names can not be."); this.propertyValue = ConvertUtils.convert(value, propertyType); }
From source file:de.micromata.genome.util.types.Converter.java
/** * Kuerzt den Text auf angegebene UTF8 byte Laenge. Hierbei wird versucht die maximale Stringlnge zu ermitteln * * @param text the text// w ww . j av a 2 s . c om * @param length the length * @return the string */ public static String trimUtf8Exact(String text, int length) { if (text == null) { return ""; } text = StringUtils.substring(text, 0, length); byte[] bytes = bytesFromString(text); while (bytes.length > length) { text = text.substring(0, text.length() - 1); bytes = bytesFromString(text); } return text; }
From source file:com.sunlights.common.utils.PropertyFilter.java
/** * @param filterName/*from w w w . j av a 2 s. c o m*/ * @param value */ public PropertyFilter(final String filterName, final String value) { String matchTypeStr; String matchPattenCode = LikeMatchPatten.ALL.toString(); String matchTypeCode; String propertyTypeCode; if (filterName.contains("LIKE") && filterName.charAt(0) != 'L') { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchPattenCode = StringUtils.substring(matchTypeStr, 0, 1); matchTypeCode = StringUtils.substring(matchTypeStr, 1, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } else { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); likeMatchPatten = Enum.valueOf(LikeMatchPatten.class, matchPattenCode); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with rules, not get more types of property.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with the rules, attribute value types can not be.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, PARAM_PREFIX); propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); Validate.isTrue(propertyNames.length > 0, "filter name: " + filterName + "Not prepared in accordance with the rules, property names can not be."); this.propertyValue = ConvertUtils.convert(value, propertyType); }
From source file:com.nhncorp.lucy.security.xss.listener.SecurityUtils.java
/** * @param element/*w ww. j av a 2 s . c o m*/ * @param srcUrl * @param isWhiteUrl * @return */ public static boolean checkVulnerable(Element element, String srcUrl, boolean isWhiteUrl) { boolean isVulnerable = false; // embed/object ? (XSSFILTERSUS-109) if (isWhiteUrl) { } else { String type = element.getAttributeValue("type").trim(); type = StringUtils.strip(type, "'\""); if (type != null && type.length() != 0) { //? type ?? if (!(isAllowedType(type) || props.values().contains(type))) { isVulnerable = true; } } else { //? ? String url = StringUtils.strip(srcUrl, "'\""); String extension = getExtension(url); if (StringUtils.containsAny(extension, specialCharArray)) { int pos = StringUtils.indexOfAny(extension, specialCharArray); if (pos != -1) { extension = StringUtils.substring(extension, 0, pos); } } if (StringUtils.isEmpty(extension)) { // ? MIME TYPE ? ? , . ? hole ? ? ? ? . } else { type = getTypeFromExtension(extension); if (StringUtils.isEmpty(type)) { type = props.getProperty(extension); if (type != null) { type = type.trim(); } } //? type ?? if (StringUtils.isEmpty(type)) { isVulnerable = true; } else { element.putAttribute("type", "\"" + type + "\""); } } } } return isVulnerable; }
From source file:io.wcm.devops.conga.generator.plugins.fileheader.AbstractFileHeader.java
@Override public final Void apply(FileContext file, FileHeaderContext context) { String lineBreak = StringUtils.defaultString(getLineBreak()); try {/*from w ww . ja va 2 s. c o m*/ String content = FileUtils.readFileToString(file.getFile(), file.getCharset()); List<String> sanitizedCommentLines; if (context.getCommentLines() == null) { sanitizedCommentLines = ImmutableList.of(); } else { sanitizedCommentLines = context.getCommentLines().stream().map(line -> sanitizeComment(line)) .filter(line -> line != null) .map(line -> StringUtils.defaultString(getCommentLinePrefix()) + line + lineBreak) .collect(Collectors.toList()); } int insertPosition = getInsertPosition(content); content = StringUtils.substring(content, 0, insertPosition) + StringUtils.defaultString(getCommentBlockStart()) + StringUtils.join(sanitizedCommentLines, "") + StringUtils.defaultString(getCommentBlockEnd()) + StringUtils.defaultString(getBlockSuffix()) + StringUtils.substring(content, insertPosition); file.getFile().delete(); FileUtils.write(file.getFile(), content, file.getCharset()); } catch (IOException ex) { throw new GeneratorException("Unable to add file header to " + FileUtil.getCanonicalPath(file), ex); } return null; }
From source file:com.cognifide.aet.job.common.comparators.w3chtml5.parser.W3cHtml5IssueDeserializer.java
@Override public W3cHtml5Issue deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext jsonDeserializationContext) { JsonObject jo = json.getAsJsonObject(); String type = getAsString(jo, TYPE); String subtype = getAsString(jo, SUBTYPE); String message = getAsString(jo, MESSAGE); String extract = getAsString(jo, EXTRACT); int lastLine = getAsInt(jo, LAST_LINE); int lastColumn = getAsInt(jo, LAST_COLUMN); int hiliteStart = getAsInt(jo, HILITE_START); int hiliteLength = getAsInt(jo, HILITE_LENGTH); String beforeHilite = StringUtils.substring(extract, 0, hiliteStart); String hilite = StringUtils.substring(extract, hiliteStart, hiliteStart + hiliteLength); String afterHilite = StringUtils.substring(extract, hiliteStart + hiliteLength); // problem with left and right double quotation mark not being displayed correctly message = StringUtils.replaceEach(message, new String[] { "\u00E2\u20AC\u015B", "\u00E2\u20AC" + "\u0165" }, new String[] { "", "" }); // messages often contain HTML entities, escaping them, so they are displayed literally message = StringEscapeUtils.escapeHtml4(message); return new W3cHtml5Issue(lastLine, lastColumn, message, beforeHilite, afterHilite, hilite, null, W3cHtml5IssueType.getType(type, subtype)); }
From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java
public static String getNormalizedHeaderName(String name) { return StringUtils.substring(name, 0, HEADER_NAME_LENGTH).toUpperCase(); }
From source file:com.sinpo.xnfc.Util.java
/** * ??// w w w. ja v a 2 s . c o m * @param str * @param blockSize ???? * @return */ public static String reverse(String str, int blockSize) { if (str != null && (str.length() % blockSize) == 0) { Log.d("REVERSE STR", str); String revStr = StringUtils.reverse(str); int len = revStr.length(); StringBuilder r = new StringBuilder(); int start = 0; int end = blockSize; do { r.append(StringUtils.reverse(StringUtils.substring(revStr, start, end))); end += blockSize; start += blockSize; } while (len - end >= 0); return r.toString(); } return null; }