Java Code Examples for org.apache.commons.lang3.StringUtils#stripEnd()

The following examples show how to use org.apache.commons.lang3.StringUtils#stripEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicPermissionImpl.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
public TopicPermissionImpl(@NotNull final String topic, @NotNull final PermissionType type, @NotNull final Qos qos,
                           @NotNull final MqttActivity activity, @NotNull final Retain retain,
                           @NotNull final SharedSubscription sharedSubscription, @NotNull final String sharedGroup) {
    this.topic = topic;
    this.type = type;
    this.qos = qos;
    this.activity = activity;
    this.retain = retain;
    this.sharedSubscription = sharedSubscription;
    this.sharedGroup = sharedGroup;

    //these are used to speed up the evaluation of permissions
    final String strippedPermissionTopic = StringUtils.stripEnd(topic, "/");
    splitTopic = StringUtils.splitPreserveAllTokens(strippedPermissionTopic, "/");
    containsWildcardCharacter = !StringUtils.containsNone(strippedPermissionTopic, "#+");
    isRootWildcard = strippedPermissionTopic.contains("#");
    endsWithWildcard = StringUtils.endsWith(strippedPermissionTopic, "/#");
}
 
Example 2
Source File: TokenizedTopicMatcher.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
public boolean matches(@NotNull final String topicSubscription, @NotNull final String actualTopic) throws InvalidTopicException {

        if (StringUtils.containsAny(actualTopic, "#+")) {
            throw new InvalidTopicException("The actual topic must not contain a wildard character (# or +)");
        }
        final String subscription = StringUtils.stripEnd(topicSubscription, "/");

        String topic = actualTopic;

        if (actualTopic.length() > 1) {
            topic = StringUtils.stripEnd(actualTopic, "/");

        }
        if (StringUtils.containsNone(topicSubscription, "#+")) {

            return subscription.equals(topic);
        }
        if (actualTopic.startsWith("$") && !topicSubscription.startsWith("$")) {
            return false;
        }
        return matchesWildcards(subscription, topic);
    }
 
Example 3
Source File: StaticAnalysisLabelProvider.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
@Override
public String apply(final Integer referenceBuild) {
    if (referenceBuild >= currentBuild) {
        return "1"; // fallback
    }
    else {
        String cleanUrl = StringUtils.stripEnd(resultUrl, "/");
        int subDetailsCount = StringUtils.countMatches(cleanUrl, "/");
        String backward = StringUtils.repeat("../", subDetailsCount + 2);
        String detailsUrl = StringUtils.substringBefore(cleanUrl, "/");

        String url = String.format("%s%d/%s", backward, referenceBuild, detailsUrl);
        return a(computeAge(referenceBuild))
                .withHref(StringUtils.stripEnd(url, "/")).render();
    }
}
 
Example 4
Source File: JavaCompilerUtils.java    From tracingplane-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static String formatIndentation(String str, String indentWith) {
    str = StringUtils.strip(str);
    String[] splits = StringUtils.splitPreserveAllTokens(str, "\n");
    int depth = 0;
    for (int i = 0; i < splits.length; i++) {
        // Unindent leading }'s
        String line = StringUtils.strip(splits[i]);
        while (line.startsWith("}")) {
            line = StringUtils.strip(line.substring(1));
            depth--;
        }

        // Indent line to correct depth
        splits[i] = StringUtils.repeat(indentWith, depth) + StringUtils.strip(splits[i]);
        splits[i] = StringUtils.stripEnd(splits[i], null); // in case empty line
        depth += StringUtils.countMatches(line, "{");
        depth -= StringUtils.countMatches(line, "}");
    }
    return StringUtils.join(splits, "\n");
}
 
Example 5
Source File: KeyManagerImpl.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function for listStatus to find key in TableCache.
 */
private void listStatusFindKeyInTableCache(
    Iterator<Map.Entry<CacheKey<String>, CacheValue<OmKeyInfo>>> cacheIter,
    String keyArgs, String startCacheKey, boolean recursive,
    TreeMap<String, OzoneFileStatus> cacheKeyMap, Set<String> deletedKeySet) {

  while (cacheIter.hasNext()) {
    Map.Entry<CacheKey<String>, CacheValue<OmKeyInfo>> entry =
        cacheIter.next();
    String cacheKey = entry.getKey().getCacheKey();
    if (cacheKey.equals(keyArgs)) {
      continue;
    }
    OmKeyInfo cacheOmKeyInfo = entry.getValue().getCacheValue();
    // cacheOmKeyInfo is null if an entry is deleted in cache
    if (cacheOmKeyInfo != null) {
      if (cacheKey.startsWith(startCacheKey) &&
          cacheKey.compareTo(startCacheKey) >= 0) {
        if (!recursive) {
          String remainingKey = StringUtils.stripEnd(cacheKey.substring(
              startCacheKey.length()), OZONE_URI_DELIMITER);
          // For non-recursive, the remaining part of key can't have '/'
          if (remainingKey.contains(OZONE_URI_DELIMITER)) {
            continue;
          }
        }
        OzoneFileStatus fileStatus = new OzoneFileStatus(
            cacheOmKeyInfo, scmBlockSize, !OzoneFSUtils.isFile(cacheKey));
        cacheKeyMap.put(cacheKey, fileStatus);
      }
    } else {
      deletedKeySet.add(cacheKey);
    }
  }
}
 
Example 6
Source File: WebAppContextPathMacro.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String getMacroValue(String str) {
    if (servletContext != null) {
        return StringUtils.stripEnd(servletContext.getContextPath(), "/");
    } else {
        return null;
    }
}
 
Example 7
Source File: Email.java    From EmailReplyParser with MIT License 5 votes vote down vote up
public String getHiddenText() {
	List<String> hiddenFragments = new ArrayList<String>();
	for (Fragment fragment : fragments) {
		if (fragment.isHidden())
			hiddenFragments.add(fragment.getContent());
	}
	return StringUtils.stripEnd(StringUtils.join(hiddenFragments,"\n"), null);
}
 
Example 8
Source File: RntbdRequestArgs.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public RntbdRequestArgs(final RxDocumentServiceRequest serviceRequest, final URI physicalAddress) {
    this.sample = Timer.start();
    this.activityId = UUID.fromString(serviceRequest.getActivityId());
    this.timeCreated = OffsetDateTime.now();
    this.nanoTimeCreated = System.nanoTime();
    this.lifetime = Stopwatch.createStarted();
    this.origin = physicalAddress.getScheme() + "://" + physicalAddress.getAuthority();
    this.physicalAddress = physicalAddress;
    this.replicaPath = StringUtils.stripEnd(physicalAddress.getPath(), "/");
    this.serviceRequest = serviceRequest;
    this.transportRequestId = instanceCount.incrementAndGet();
}
 
Example 9
Source File: BlameBlock.java    From onedev with MIT License 5 votes vote down vote up
@Override
public String toString() {
	StringBuilder builder = new StringBuilder();
	builder.append(commit.getHash()).append(": ");
	for (LinearRange range: ranges) 
		builder.append(range).append(", ");
	
	return StringUtils.stripEnd(builder.toString(), ", ");
}
 
Example 10
Source File: RemoteRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
public RemoteRepository( Locale locale, String id, String name, String url, String layout, String userName, String password,
                         int timeout )
{
    super( locale, id, name, layout );
    this.url = StringUtils.stripEnd(url,"/");
    this.userName = userName;
    this.password = password;
    this.timeout = timeout;
}
 
Example 11
Source File: TextToken.java    From jinjava with Apache License 2.0 5 votes vote down vote up
public String output() {
  if (isLeftTrim() && isRightTrim()) {
    return trim();
  } else if (isLeftTrim()) {
    return StringUtils.stripStart(content, null);
  } else if (isRightTrim()) {
    return StringUtils.stripEnd(content, null);
  }
  return content;
}
 
Example 12
Source File: CoreUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * FIXME not sure if this method does extract text from every possible variation
 * of a docx...
 */
public static String extractTextFromDocx(String filename) throws Docx4JException, JAXBException {
	WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(filename));
	MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

	String pageTxt = "";
	for (Object o : documentPart.getContent()) {
		if (o == null)
			continue;

		pageTxt += o.toString() + "\n";
	}

	return StringUtils.stripEnd(pageTxt, "\n");
}
 
Example 13
Source File: MemTask.java    From WebAndAppUITesting with GNU General Public License v3.0 4 votes vote down vote up
public MemTask() {

		file = StringUtils.stripEnd(getfileName(), ".java") + file;
		initFields(true, getFile());
	}
 
Example 14
Source File: MemTask.java    From WebAndAppUITesting with GNU General Public License v3.0 4 votes vote down vote up
public MemTask(boolean bWriteFile, String filename) {

		file = StringUtils.stripEnd(getfileName(), ".java") + file;
		initFields(bWriteFile, filename);
	}
 
Example 15
Source File: CpuTask.java    From WebAndAppUITesting with GNU General Public License v3.0 4 votes vote down vote up
public CpuTask(boolean bWriteFile, String filename) {

		file = StringUtils.stripEnd(getfileName(), ".java") + file;
		initFields(bWriteFile, filename);
	}
 
Example 16
Source File: RuntimeInfo.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public String getBaseHttpUrl() {
  return StringUtils.stripEnd(httpUrl, "/");
}
 
Example 17
Source File: HtmlForm.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
 *
 * Gets the request for a submission of this form with the specified SubmittableElement.
 * @param submitElement the element that caused the submit to occur
 * @return the request
 */
public WebRequest getWebRequest(final SubmittableElement submitElement) {
    final HtmlPage htmlPage = (HtmlPage) getPage();
    final List<NameValuePair> parameters = getParameterListForSubmit(submitElement);
    final HttpMethod method;
    final String methodAttribute = getMethodAttribute();
    if ("post".equalsIgnoreCase(methodAttribute)) {
        method = HttpMethod.POST;
    }
    else {
        if (!"get".equalsIgnoreCase(methodAttribute) && StringUtils.isNotBlank(methodAttribute)) {
            notifyIncorrectness("Incorrect submit method >" + getMethodAttribute() + "<. Using >GET<.");
        }
        method = HttpMethod.GET;
    }

    final BrowserVersion browser = getPage().getWebClient().getBrowserVersion();
    String actionUrl = getActionAttribute();
    String anchor = null;
    String queryFromFields = "";
    if (HttpMethod.GET == method) {
        if (actionUrl.contains("#")) {
            anchor = StringUtils.substringAfter(actionUrl, "#");
        }
        final Charset enc = getPage().getCharset();
        queryFromFields =
            URLEncodedUtils.format(Arrays.asList(NameValuePair.toHttpClient(parameters)), enc);

        // action may already contain some query parameters: they have to be removed
        actionUrl = StringUtils.substringBefore(actionUrl, "#");
        actionUrl = StringUtils.substringBefore(actionUrl, "?");
        parameters.clear(); // parameters have been added to query
    }
    URL url;
    try {
        if (actionUrl.isEmpty()) {
            url = WebClient.expandUrl(htmlPage.getUrl(), actionUrl);
        }
        else {
            url = htmlPage.getFullyQualifiedUrl(actionUrl);
        }

        if (!queryFromFields.isEmpty()) {
            url = UrlUtils.getUrlWithNewQuery(url, queryFromFields);
        }

        if (HttpMethod.GET == method && browser.hasFeature(FORM_SUBMISSION_URL_WITHOUT_HASH)
                && WebClient.URL_ABOUT_BLANK != url) {
            url = UrlUtils.getUrlWithNewRef(url, null);
        }
        else if (HttpMethod.POST == method
                && browser.hasFeature(FORM_SUBMISSION_URL_WITHOUT_HASH)
                && WebClient.URL_ABOUT_BLANK != url
                && StringUtils.isEmpty(actionUrl)) {
            url = UrlUtils.getUrlWithNewRef(url, null);
        }
        else if (anchor != null
                && WebClient.URL_ABOUT_BLANK != url) {
            url = UrlUtils.getUrlWithNewRef(url, anchor);
        }
    }
    catch (final MalformedURLException e) {
        throw new IllegalArgumentException("Not a valid url: " + actionUrl);
    }

    final WebRequest request = new WebRequest(url, method);
    request.setAdditionalHeader(HttpHeader.ACCEPT, browser.getHtmlAcceptHeader());
    request.setAdditionalHeader(HttpHeader.ACCEPT_ENCODING, "gzip, deflate");
    request.setRequestParameters(parameters);
    if (HttpMethod.POST == method) {
        request.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute()));
    }
    request.setCharset(getSubmitCharset());

    String referer = htmlPage.getUrl().toExternalForm();
    request.setAdditionalHeader(HttpHeader.REFERER, referer);

    if (HttpMethod.POST == method
            && browser.hasFeature(FORM_SUBMISSION_HEADER_ORIGIN)) {
        referer = StringUtils.stripEnd(referer, "/");
        request.setAdditionalHeader(HttpHeader.ORIGIN, referer);
    }
    if (HttpMethod.POST == method
            && browser.hasFeature(FORM_SUBMISSION_HEADER_CACHE_CONTROL_MAX_AGE)) {
        request.setAdditionalHeader(HttpHeader.CACHE_CONTROL, "max-age=0");
    }
    if (browser.hasFeature(FORM_SUBMISSION_HEADER_CACHE_CONTROL_NO_CACHE)) {
        request.setAdditionalHeader(HttpHeader.CACHE_CONTROL, "no-cache");
    }

    return request;
}
 
Example 18
Source File: CpuTask.java    From WebAndAppUITesting with GNU General Public License v3.0 4 votes vote down vote up
public CpuTask(boolean bWriteFile) {

		file = StringUtils.stripEnd(getfileName(), ".java") + file;
		initFields(bWriteFile, getFile());
	}
 
Example 19
Source File: CpuTask.java    From WebAndAppUITesting with GNU General Public License v3.0 4 votes vote down vote up
public CpuTask() {

		file = StringUtils.stripEnd(getfileName(), ".java") + file;
		initFields(true, getFile());
	}
 
Example 20
Source File: TextUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Removes the last occurrence of the the given string, including potential
 * trailing spaces.
 *
 * @param string the string, without potential trailing spaces.
 * @param remove the text to remove.
 * @return the chopped string.
 */
public static String removeLast( String string, String remove )
{
    string = StringUtils.stripEnd( string, " " );

    return StringUtils.removeEndIgnoreCase( string,  remove );
}