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:onetimepad.frame.java
public static String init(String username, Publisher publisher, RecieveMessages messageRetriever, MessageQueue<String> queue) { String routingKey = StringUtils.substring(new BigInteger(100, random).toString(32), 0, 10); String channel;/* w w w. ja va 2s .c o m*/ try { messageRetriever.startup(routingKey, username, queue); publisher.sendMessage(username, routingKey, username); while (queue.isEmpty()) { //wait till queue is not empty Thread.sleep(10); } String message = queue.get(); publisher.sendMessage(username, "update;" + routingKey, username); while (queue.isEmpty()) { //wait till queue is not empty Thread.sleep(10); } message = queue.get(); List<String> messageEntry = Arrays.asList(message.split(":")); channel = messageEntry.get(0); messageRetriever.stop(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); channel = null; } return channel; }
From source file:org.alfresco.dataprep.UserService.java
/** * Utility to invite a enterprise user to Site and accept the invitation * /*from w w w . java 2 s. com*/ * @param invitingUserName user identifier * @param invitingUserPassword user password * @param userToInvite user label * @param siteName site identifier which invite user. * @param role user role * @return true if invite is successful */ public boolean inviteUserToSiteAndAccept(final String invitingUserName, final String invitingUserPassword, final String userToInvite, final String siteName, final String role) { if (StringUtils.isEmpty(invitingUserName) || StringUtils.isEmpty(invitingUserPassword) || StringUtils.isEmpty(userToInvite) || StringUtils.isEmpty(siteName) || StringUtils.isEmpty(role)) { throw new IllegalArgumentException("Null Parameters: Please correct"); } AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); String url = client.getApiUrl() + "invite/start?inviteeFirstName=" + userToInvite + "&inviteeLastName=" + DEFAULT_LAST_NAME + "&inviteeEmail=" + userToInvite + "&inviteeUserName=" + userToInvite + "&siteShortName=" + siteName + "&inviteeSiteRole=" + role + "&serverPath=" + client.getHost() + "&acceptUrl=" + PAGE_ACCEPT_URL + "&rejectUrl=" + PAGE_REJECT_URL; if (logger.isTraceEnabled()) { logger.trace("Invite user: " + userToInvite + " using Url - " + url); } HttpGet get = new HttpGet(url); try { HttpResponse response = client.execute(invitingUserName, invitingUserPassword, get); switch (response.getStatusLine().getStatusCode()) { case HttpStatus.SC_OK: if (logger.isTraceEnabled()) { logger.trace("User successfully invited: " + userToInvite); } String alfVersion = client.getAlfrescoVersion(); double v = Double.valueOf(StringUtils.substring(alfVersion, 0, 3)); if (v >= 5.1) { return true; } else { String result = client.readStream(response.getEntity()).toJSONString(); String inviteId = client.getParameterFromJSON(result, "inviteId", ""); String inviteTicket = client.getParameterFromJSON(result, "inviteTicket", ""); return acceptSiteInvitation(inviteId, inviteTicket); } default: logger.error("Unable to invite user: " + response.toString()); break; } } finally { get.releaseConnection(); client.close(); } return false; }
From source file:org.apache.cassandra.index.TargetParser.java
public static Pair<ColumnDefinition, IndexTarget.Type> parse(CFMetaData cfm, String target) { // if the regex matches then the target is in the form "keys(foo)", "entries(bar)" etc // if not, then it must be a simple column name and implictly its type is VALUES Matcher matcher = TARGET_REGEX.matcher(target); String columnName;// w ww . j ava 2s .co m IndexTarget.Type targetType; if (matcher.matches()) { targetType = IndexTarget.Type.fromString(matcher.group(1)); columnName = matcher.group(2); } else { columnName = target; targetType = IndexTarget.Type.VALUES; } // in the case of a quoted column name the name in the target string // will be enclosed in quotes, which we need to unwrap. It may also // include quote characters internally, escaped like so: // abc"def -> abc""def. // Because the target string is stored in a CQL compatible form, we // need to un-escape any such quotes to get the actual column name if (columnName.startsWith(QUOTE)) { columnName = StringUtils.substring(StringUtils.substring(columnName, 1), 0, -1); columnName = TWO_QUOTES.matcher(columnName).replaceAll(QUOTE); } // if it's not a CQL table, we can't assume that the column name is utf8, so // in that case we have to do a linear scan of the cfm's columns to get the matching one if (cfm.isCQLTable()) return Pair.create(cfm.getColumnDefinition(new ColumnIdentifier(columnName, true)), targetType); else for (ColumnDefinition column : cfm.allColumns()) if (column.name.toString().equals(columnName)) return Pair.create(column, targetType); return null; }
From source file:org.apache.jmeter.protocol.mqtt.utilities.Utils.java
/** * Creates a UUID. The UUID is modified to avoid "ClientId longer than 23 characters" for MQTT. * * @return A UUID as a string.// w w w .j a v a 2s . c o m */ public static String UUIDGenerator() { String clientId = System.currentTimeMillis() + "." + System.getProperty("user.name"); clientId = StringUtils.substring(clientId, 0, 23); return clientId; }
From source file:org.apache.lens.cube.parse.TestQuery.java
private String extractJoinStringFromQuery(String queryTrimmed) { int joinStartIndex = getMinIndexOfJoinType(); int joinEndIndex = getMinIndexOfClause(); if (joinStartIndex == -1 && joinEndIndex == -1) { return queryTrimmed; }/*www.j a va 2 s .c o m*/ return StringUtils.substring(queryTrimmed, joinStartIndex, joinEndIndex); }
From source file:org.apache.nifi.registry.security.util.CertificateUtils.java
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username/*from ww w .j ava2 s. c o m*/ */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java
/** * * @param originalElementHtml//w w w . j a va2 s . c o m * @param truncatedElementHtml * @param indexOfElementToClose * @return */ private String closeInnerElement(String originalElementHtml, String truncatedElementHtml) { int startPos = truncatedElementHtml.length(); int indexOfElementCloser = StringUtils.indexOf(originalElementHtml, ESCAPED_CLOSE_TAG, startPos); int indexOfElementAutoCloser = StringUtils.indexOf(originalElementHtml, AUTO_CLOSE_TAG_OCCUR, startPos); String innerClosedElement = StringUtils.substring(originalElementHtml, 0, (indexOfElementCloser + ESCAPED_CLOSE_TAG.length())); // if the current element is auto-close, return current well-closed element if (indexOfElementAutoCloser == (indexOfElementCloser - 1)) { return innerClosedElement; } // if the current element is not auto-close, get the name of it and // and properly close it int indexOfElementOpenTagOpener = StringUtils.lastIndexOf(originalElementHtml, ESCAPED_OPEN_TAG, startPos); int indexOfElementOpenTagClose = StringUtils.indexOf(originalElementHtml, ' ', indexOfElementOpenTagOpener); String elementName = StringUtils.substring(originalElementHtml, indexOfElementOpenTagOpener + ESCAPED_OPEN_TAG.length(), indexOfElementOpenTagClose); return closeElement(innerClosedElement, elementName); }
From source file:org.asqatasun.rules.cssvisitor.CssPropertyPresenceCSSVisitor.java
@Override protected void checkCSSExpressionMemberTermSimple(CSSExpressionMemberTermSimple exprMember) { String contentValue = exprMember.getOptimizedValue(); // Some attributes (like "content") declare their content within "" // These characters are removed to work on the appropriate content if (contentValue.startsWith("\"") && contentValue.endsWith("\"")) { contentValue = StringUtils.substring(contentValue, 1, contentValue.length() - 1).trim(); }//from w w w.j a v a 2s . c om if (StringUtils.isNotBlank(contentValue)) { addCssCodeRemark(solutionOnDetection, messageOnDetection, contentValue); } else { getSolutionHandler().addTestSolution(TestSolution.PASSED); } }
From source file:org.asqatasun.rules.domelement.DomElement.java
public String getDisplayableBgColor() { if (StringUtils.startsWith(getBgColor(), BACKGROUND_IMAGE_KEY)) { return StringUtils.substring(getBgColor(), getBgColor().indexOf(":") + 1, getBgColor().length()); }/*from w w w. j a v a 2 s . c om*/ return getBgColor(); }
From source file:org.asqatasun.rules.elementchecker.contrast.helper.ContrastHelper.java
/** * //from w w w .ja v a 2 s . c o m * @param color * @return */ public static Color getColorFromString(final String color) { if (StringUtils.equalsIgnoreCase(color, TRANSPARENT_KEY)) { return Color.WHITE; } String[] comps = StringUtils.substring(color, StringUtils.indexOf(color, OPEN_PARENTHESE) + 1, StringUtils.indexOf(color, CLOSE_PARENTHESE)).split(COMPOSANT_SEPARATOR); return new Color(Integer.valueOf(comps[0].trim()), Integer.valueOf(comps[1].trim()), Integer.valueOf(comps[2].trim())); }