Example usage for org.apache.commons.lang3 StringUtils stripStart

List of usage examples for org.apache.commons.lang3 StringUtils stripStart

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils stripStart.

Prototype

public static String stripStart(final String str, final String stripChars) 

Source Link

Document

Strips any of a set of characters from the start of a String.

A null input String returns null .

Usage

From source file:groovy.com.robotics.api.FastScreenshot.java

/**
 * Take screenshots and store them a directory.
 * Directory path should NOT be a multi level path.
 * @param directory Directory to store screenshots in.
 * @param n_shots Number of screenshots to take.
 * @param n_threads Number of threads to use.
 * @param delay_us Delay before first screenshot is taken.
 * @param interval_us Delay between screenshots.
 *//*from   w  w  w . j  a  v  a  2 s. co  m*/
public static void takeScreenshots(String directory, int n_shots, int n_threads, int delay_us,
        int interval_us) {
    _takeScreenshots(StringUtils.stripEnd(StringUtils.stripStart(directory, "/"), "/"), n_shots,
            Math.min(n_threads, n_shots), delay_us, interval_us);
}

From source file:io.relution.jenkins.awssqs.model.entities.codecommit.CodeCommitEvent.java

public CodeCommitEvent(final Record record, final Reference reference) {
    final String arn = record.getEventSourceARN();
    final String[] tokens = arn.split(":", 6);

    this.host = String.format(HOST, tokens[3]);
    this.path = String.format(PATH, tokens[5]);

    final String name = reference.getName();
    this.branch = StringUtils.stripStart(name, "refs/");
}

From source file:net.eledge.android.europeana.search.model.enums.DocType.java

@Override
public String toString() {
    return StringUtils.stripStart(super.toString(), "_");
}

From source file:com.flysystem.core.adapter.AbstractAdapter.java

public String applyPathPrefix(String path) {
    path = StringUtils.stripStart(path, "\\/");
    if (path.length() == 0) {
        return getPathPrefix() != null ? getPathPrefix() : "";
    }/* ww w .  j  av a 2s.  co m*/
    return getPathPrefix() + path;
}

From source file:io.wcm.devops.conga.plugins.aem.util.ContentElementHandler.java

@Override
public void resource(String path, Map<String, Object> properties) {
    if (StringUtils.equals(path, "/")) {
        root = new ContentElementImpl(null, properties);
    } else {//  ww  w  .j a  va2  s  .c  om
        if (root == null) {
            throw new RuntimeException("Root resource not set.");
        }
        Matcher matcher = PATH_PATTERN.matcher(path);
        if (!matcher.matches()) {
            throw new RuntimeException("Unexpected path:" + path);
        }
        String relativeParentPath = StringUtils.stripStart(matcher.group(1), "/");
        String name = matcher.group(4);
        ContentElement parent;
        if (StringUtils.isEmpty(relativeParentPath)) {
            parent = root;
        } else {
            parent = root.getChild(relativeParentPath);
        }
        if (parent == null) {
            throw new RuntimeException("Parent '" + relativeParentPath + "' does not exist.");
        }
        parent.getChildren().put(name, new ContentElementImpl(name, properties));
    }
}

From source file:com.adobe.acs.commons.util.datadefinitions.impl.LowercaseWithDashesDefinitionBuilderImpl.java

@Override
public final ResourceDefinition convert(final String data) {
    final String title = data;

    String name = data;//from   w  ww  .  j a  v  a  2s . c  o m
    name = StringUtils.stripToEmpty(name);
    name = StringUtils.lowerCase(name);
    name = StringUtils.replace(name, "&", " and ");
    name = StringUtils.replace(name, "/", " or ");
    name = StringUtils.replace(name, "%", " percent ");
    name = name.replaceAll("[^a-z0-9-]+", "-");
    name = StringUtils.stripEnd(name, "-");
    name = StringUtils.stripStart(name, "-");

    final BasicResourceDefinition dataDefinition = new BasicResourceDefinition(name);

    dataDefinition.setTitle(title);

    return dataDefinition;
}

From source file:com.technophobia.substeps.model.Arguments.java

public static Object evaluateExpression(String expressionWithDelimiters) {

    ParameterSubstitution parameterSubstituionConfig = NewSubstepsExecutionConfig
            .getParameterSubstituionConfig();

    // TODO - check that the expression doesn't contain any of the bad words
    // or and eq ne lt gt le ge div mod not null true false new var return
    // any of those words need to be qutoed or ['  ']
    // http://commons.apache.org/proper/commons-jexl/reference/syntax.html

    // try evaluating this expression against the executionContext

    // TODO check flag to see whether we can evaluate things from the ec

    if (expressionWithDelimiters != null && parameterSubstituionConfig.substituteParameters()
            && expressionWithDelimiters.startsWith(parameterSubstituionConfig.startDelimiter())) {
        String expression = StringUtils.stripStart(
                StringUtils.stripEnd(expressionWithDelimiters, parameterSubstituionConfig.endDelimiter()),
                parameterSubstituionConfig.startDelimiter());

        JexlContext context = new MapContext(ExecutionContext.flatten());

        JexlExpression e = jexl.createExpression(expression);

        return e.evaluate(context);
    } else {/* w  w w  .  j  a v  a  2  s  .c  om*/
        return expressionWithDelimiters;
    }
}

From source file:com.hybris.mobile.app.commerce.barcode.CommerceBarcodeCheckerFactory.java

/**
 * Return the product value if the barcode value matches one of the pre-configured regular expression
 *
 * @param barcodeValue//from ww  w .j  a va2s . c om
 * @param barcodeSymbology
 * @return
 */
private static String getProductCode(String barcodeValue, String barcodeSymbology) {

    // For product codes, we have to remove the leading/trailing 0 of specific barcode symbologies

    // These barcodes have leading '0's and a trailing '0' that needs to be accounted for (stripped out).
    if (StringUtils.equals(barcodeSymbology, Constants.BarCodeSymbology.EAN_13.getCodeSymbology())) {
        barcodeValue = StringUtils.stripStart(barcodeValue, "0");
        barcodeValue = StringUtils.removeEnd(barcodeValue, "0");
    }
    // These barcodes have leading '0's that needs to be accounted for (stripped out).
    else if (StringUtils.equals(barcodeSymbology, Constants.BarCodeSymbology.ITF.getCodeSymbology())) {
        barcodeValue = StringUtils.stripStart(barcodeValue, "0");
    }
    // These barcodes have a trailing '0' that needs to be accounted for (stripped out).
    else if (StringUtils.equals(barcodeSymbology, Constants.BarCodeSymbology.EAN_8.getCodeSymbology())) {
        barcodeValue = StringUtils.removeEnd(barcodeValue, "0");
    }

    // Trying to get a product code from the barcode value
    return RegexUtils.getProductCode(barcodeValue);

}

From source file:io.knotx.repository.impl.FilesystemRepositoryConnectorProxyImpl.java

@Override
public void process(ClientRequest request, Handler<AsyncResult<ClientResponse>> result) {
    final String localFilePath = catalogue + StringUtils.stripStart(request.getPath(), "/");
    final Optional<String> contentType = Optional.ofNullable(MimeMapping.getMimeTypeForFilename(localFilePath));

    LOGGER.trace("Fetching file `{}` from local repository.", localFilePath);

    ObservableFuture<Buffer> fileObservable = RxHelper.observableFuture();
    fileObservable/* w  ww . ja va 2 s. co m*/
            .map(buffer -> new ClientResponse().setStatusCode(HttpResponseStatus.OK.code())
                    .setHeaders(headers(contentType)).setBody(buffer))
            .defaultIfEmpty(new ClientResponse().setStatusCode(HttpResponseStatus.NOT_FOUND.code()))
            .subscribe(response -> result.handle(Future.succeededFuture(response)), error -> {
                LOGGER.error(ERROR_MESSAGE, error);
                result.handle(Future.succeededFuture(processError(error)));
            });

    fileSystem.readFile(localFilePath, fileObservable.toHandler());
}

From source file:io.github.swagger2markup.extensions.DynamicContentExtension.java

/**
 * Builds extension sections//ww w  .j a v  a  2 s . co m
 *
 * @param extensionMarkupLanguage the MarkupLanguage of the snippets content
 * @param contentPath the path where the content files reside
 * @param prefix      extension file prefix
 * @param levelOffset import markup level offset
 */
public void extensionsSection(MarkupLanguage extensionMarkupLanguage, Path contentPath, final String prefix,
        int levelOffset) {
    final Collection<String> filenameExtensions = globalContext.getConfig().getMarkupLanguage()
            .getFileNameExtensions().stream().map(fileExtension -> StringUtils.stripStart(fileExtension, "."))
            .collect(Collectors.toList());

    DirectoryStream.Filter<Path> filter = entry -> {
        String fileName = entry.getFileName().toString();
        return fileName.startsWith(prefix) && FilenameUtils.isExtension(fileName, filenameExtensions);
    };

    try (DirectoryStream<Path> extensionFiles = Files.newDirectoryStream(contentPath, filter)) {

        if (extensionFiles != null) {
            List<Path> extensions = Lists.newArrayList(extensionFiles);
            Collections.sort(extensions, Ordering.natural());

            for (Path extension : extensions) {
                importContent(extension, (reader) -> contentContext.getMarkupDocBuilder().importMarkup(reader,
                        extensionMarkupLanguage, levelOffset));
            }
        }
    } catch (IOException e) {
        if (logger.isDebugEnabled())
            logger.debug("Failed to read extension files from directory {}", contentPath);
    }
}