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:org.asqatasun.rules.elementchecker.ElementCheckerImpl.java
/** * @param element//from w w w . java2 s . co m * @param attr * @return an evidenceElement */ protected EvidenceElement getEvidenceElement(Element element, String attr) { EvidenceElement extraEe; String attrEE; // specific control with xml:lang attribute due to the ':' character if (StringUtils.equalsIgnoreCase(attr, AttributeStore.XML_LANG_ATTR)) { attrEE = StringUtils.replace(attr, ":", "-"); } else { attrEE = attr; } if (isElementTextRequested(attr)) { extraEe = processRemarkService.getEvidenceElement(attrEE, StringUtils .substring(getTextElementBuilder().buildTextFromElement(element), 0, MAX_TEXT_EE_SIZE)); } else if (isAttributeExternalResource(attr)) { extraEe = processRemarkService.getEvidenceElement(attrEE, buildAttributeContent(element, attr, true)); } else { extraEe = processRemarkService.getEvidenceElement(attrEE, buildAttributeContent(element, attr, false)); } return extraEe; }
From source file:org.asqatasun.rules.elementchecker.lang.LangChecker.java
/** * /*from w w w . j a va2s . c o m*/ * @param langDefinition * @return the language code (truncate language definition when option is * defined) */ protected String extractEffectiveLang(String langDefinition) { int separatorIndex = StringUtils.indexOf(langDefinition, '-'); if (separatorIndex != -1) { return StringUtils.substring(langDefinition, 0, separatorIndex); } return langDefinition; }
From source file:org.blocks4j.reconf.client.constructors.SimpleConstructor.java
public Object construct(MethodData data) throws Throwable { Class<?> returnClass = (Class<?>) data.getReturnType(); String trimmed = StringUtils.defaultString(StringUtils.trim(data.getValue())); if (!trimmed.startsWith("'") || !trimmed.endsWith("'")) { throw new RuntimeException(msg.format("error.invalid.string", data.getValue(), data.getMethod())); }//from ww w .j a v a2 s . c o m String wholeValue = StringUtils.substring(trimmed, 1, trimmed.length() - 1); if (String.class.equals(returnClass)) { return wholeValue; } if (null == data.getValue()) { return null; } if (Object.class.equals(returnClass)) { returnClass = String.class; } if (char.class.equals(data.getReturnType()) || Character.class.equals(data.getReturnType())) { if (StringUtils.length(wholeValue) == 1) { return CharUtils.toChar(wholeValue); } return CharUtils.toChar(StringUtils.replace(wholeValue, " ", "")); } if (primitiveBoxing.containsKey(returnClass)) { if (StringUtils.isBlank(wholeValue)) { return null; } Method parser = primitiveBoxing.get(returnClass).getMethod( "parse" + StringUtils.capitalize(returnClass.getSimpleName()), new Class<?>[] { String.class }); return parser.invoke(primitiveBoxing.get(returnClass), new Object[] { StringUtils.trim(wholeValue) }); } Method valueOf = null; try { valueOf = returnClass.getMethod("valueOf", new Class<?>[] { String.class }); } catch (NoSuchMethodException ignored) { } if (valueOf == null) { try { valueOf = returnClass.getMethod("valueOf", new Class<?>[] { Object.class }); } catch (NoSuchMethodException ignored) { } } if (null != valueOf) { if (StringUtils.isEmpty(wholeValue)) { return null; } return valueOf.invoke(data.getReturnType(), new Object[] { StringUtils.trim(wholeValue) }); } Constructor<?> constructor = null; try { constructor = returnClass.getConstructor(String.class); constructor.setAccessible(true); } catch (NoSuchMethodException ignored) { throw new IllegalStateException( msg.format("error.string.constructor", returnClass.getSimpleName(), data.getMethod())); } try { return constructor.newInstance(wholeValue); } catch (Exception e) { if (e.getCause() != null && e.getCause() instanceof NumberFormatException) { return constructor.newInstance(StringUtils.trim(wholeValue)); } throw e; } }
From source file:org.blocks4j.reconf.client.constructors.StringParser.java
public StringParser(MethodData arg) { this.data = arg; if (StringUtils.isEmpty(data.getValue())) { return;//from ww w.j a v a 2 s.c o m } String trimmed = StringUtils.defaultString(StringUtils.trim(data.getValue())); if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) { throw new RuntimeException(msg.format("error.complex.type", data.getMethod())); } String wholeValue = StringUtils.substring(trimmed, 1, trimmed.length() - 1); extractTokens(wholeValue); if (openClose.size() % 2 != 0) { throw new IllegalArgumentException( msg.format("error.invalid.string", data.getValue(), data.getMethod())); } }
From source file:org.blocks4j.reconf.client.setup.DatabaseURL.java
private static String getSecretKey(int keySize) { String key = LocalHostname.getName(); int missing = keySize - StringUtils.length(key); if (missing == 0) { return key; }/*from ww w . ja va 2s . co m*/ if (missing < 0) { return StringUtils.substring(key, 0, keySize); } return key + StringUtils.repeat("#", missing); }
From source file:org.cleverbus.api.entity.Message.java
@Override public String toString() { return new ToStringBuilder(this).append("msgId", msgId).append("state", state) .append("correlationId", correlationId).append("processId", processId) .append("msgTimestamp", msgTimestamp).append("receiveTimestamp", receiveTimestamp) .append("service", service == null ? null : service.getServiceName()) .append("operationName", operationName).append("objectId", objectId) .append("entityType", entityType != null ? entityType.getEntityType() : null) // .append("payload", StringUtils.substring(payload, 0, 500)) .append("sourceSystem", sourceSystem != null ? sourceSystem.getSystemName() : null) .append("startProcessTimestamp", startProcessTimestamp).append("failedCount", failedCount) .append("failedErrorCode", failedErrorCode) // .append("failedDesc", StringUtils.substring(payload, 0, 200)) .append("lastUpdateTimestamp", lastUpdateTimestamp) .append("customData", StringUtils.substring(customData, 0, 200)) .append("businessError", StringUtils.substring(businessError, 0, 200)) .append("parentMsgId", parentMsgId).append("parentBindingType", parentBindingType) .append("funnelComponentId", funnelComponentId).append("guaranteedOrder", guaranteedOrder) .append("excludeFailedState", excludeFailedState).append("processingPriority", processingPriority) .toString();//from www.j a v a2 s. c o m }
From source file:org.codenergic.theskeleton.post.impl.PostServiceImpl.java
@Override public PostEntity replyPost(String postId, PostEntity replyPost) { PostEntity post = findPostByIdOrThrow(postId); return postRepository.save(replyPost.setResponse(true).setPostStatus(PostStatus.PUBLISHED) .setTitle(StringUtils.substring(replyPost.getContent(), 0, 20)).setResponseTo(post)); }
From source file:org.codenergic.theskeleton.post.impl.PostServiceImpl.java
private String slugifyTitle(String title) { return StringUtils.substring(slugify.slugify(title), 0, 20); }
From source file:org.dbgl.gui.ShareConfDialog.java
private String extractConfFromTree(Tree tree) { SectionsWrapper sections = new SectionsWrapper(); for (TreeItem sectionItem : tree.getItems()) { if (sectionItem.getChecked()) { for (TreeItem node : sectionItem.getItems()) { if (node.getChecked()) { String[] v = StringUtils.split(node.getText(), '='); sections.setValue(StringUtils.substring(sectionItem.getText(), 1, -1), v[0], v[1]); }/*from w ww .ja v a2s .c o m*/ } } } return sections.toString(); }
From source file:org.eclipse.hawkbit.ui.common.UserDetailsFormatter.java
private static String trimAndFormatDetail(final String formatString, final int expectedDetailLength) { final String detail = StringUtils.defaultIfEmpty(formatString, ""); final String trimmedDetail = StringUtils.substring(detail, 0, expectedDetailLength); if (StringUtils.length(detail) > expectedDetailLength) { return trimmedDetail + TRIM_APPENDIX; }/*from ww w . ja v a2 s .com*/ return trimmedDetail; }