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

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

Introduction

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

Prototype

public static String removeStart(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:org.ligoj.app.plugin.req.squash.SquashPluginResource.java

@Override
public String getLastVersion() throws IOException {
    try (CurlProcessor curl = new CurlProcessor()) {
        final String tagsAsJson = curl.get(publicServer
                + "/2.0/repositories/nx/squashtest-tm/refs/tags?pagelen=1&q=name~%22squash-tm-%22&sort=-target.date",
                "Content-Type:application/json");
        return StringUtils.removeStart(new ObjectMapper()
                .readValue(StringUtils.defaultIfEmpty(tagsAsJson, "{\"values\":[]}"), BitBucketTags.class)
                .getValues().stream().findFirst().map(BitBucketTag::getName).orElse("squash-tm-"),
                "squash-tm-");
    }//from w  w w  .  j av  a  2  s  . c  o  m
}

From source file:org.ligoj.app.plugin.vm.azure.AbstractAzureToolPluginResource.java

/**
 * Return an Azure resource. Return <code>null</code> when the resource is not found. Authentication should be
 * proceeded before for authenticated query.
 * //from  w  ww  .j av a  2 s  .  c om
 * @param processor
 *            The processor used to query the resource.
 * @param method
 *            The HHTTP method.
 * @param url
 *            The base URL.
 * @param resource
 *            The internal resource URL appended to the base URL parameter. DUplicate '/' are handled.
 * @return The requested azure resource or <code>null</code> when the resource is not found.
 */
protected String execute(final CurlProcessor processor, final String method, final String url,
        final String resource) {
    // Get the resource using the preempted authentication
    final CurlRequest request = new CurlRequest(method, StringUtils.removeEnd(
            StringUtils.appendIfMissing(url, "/") + StringUtils.removeStart(resource, "/"), "/"), null);
    request.setSaveResponse(true);

    // Execute the requests
    processor.process(request);
    return request.getResponse();
}

From source file:org.maven.i18nbinder.plugin.I18nBinderMojo.java

private String reduceFileNameAndCreateDirectoryPath(String fileName, File targetPackageDirectory) {
    String reducedFileName = StringUtils.removeStart(fileName, this.packageName + ".");

    ///*from  w w w  .j ava 2s .c o  m*/
    fileName = reducedFileName;
    File directory = targetPackageDirectory;
    String[] tokens = fileName.split("\\.");
    for (int ii = 0; ii < tokens.length - 1; ii++) {
        String directoryName = tokens[ii];
        directory = new File(directory, directoryName);
        if (!directory.exists()) {
            directory.mkdir();
        }
    }
    fileName = StringUtils.join(Arrays.copyOf(tokens, tokens.length - 1), "/") + (tokens.length > 1 ? "/" : "")
            + tokens[tokens.length - 1];

    //
    return reducedFileName.replaceAll("\\.", "/");
}

From source file:org.meri.wro4j.nogroups.fix.FixedWildcardExpanderModelTransformer.java

public Function<Collection<File>, Void> createExpanderHandler(final Group group, final Resource resource,
        final String baseNameFolder) {
    LOG.debug("createExpanderHandler using baseNameFolder: {}\n for resource {}", baseNameFolder, resource);
    final Function<Collection<File>, Void> handler = new Function<Collection<File>, Void>() {
        public Void apply(final Collection<File> files) {
            if (baseNameFolder == null) {
                // replacing group with empty list since the original uri has no associated resources.
                //No BaseNameFolder found
                LOG.warn("The resource {} is probably invalid, removing it from the group.", resource);
                group.replace(resource, new ArrayList<Resource>());
            } else {
                final List<Resource> expandedResources = new ArrayList<Resource>();
                LOG.debug("baseNameFolder: {}", baseNameFolder);
                for (final File file : files) {
                    final String resourcePath = getFullPathNoEndSeparator(resource);
                    LOG.debug("\tresourcePath: {}", resourcePath);
                    LOG.debug("\tfile path: {}", file.getPath());
                    final String computedResourceUri = resourcePath
                            + StringUtils.removeStart(file.getPath(), baseNameFolder).replace('\\', '/');

                    final Resource expandedResource = Resource.create(computedResourceUri, resource.getType());
                    LOG.debug("\texpanded resource: {}", expandedResource);
                    expandedResources.add(expandedResource);
                }//from  www. ja v  a  2s . c  o m
                LOG.debug("\treplace resource {}", resource);
                group.replace(resource, expandedResources);
            }
            return null;
        }

        private String getFullPathNoEndSeparator(final Resource resource) {
            String result = FilenameUtils.getFullPathNoEndSeparator(resource.getUri());
            if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result))
                return "";

            return result;
        }
    };
    return handler;
}

From source file:org.molasdin.wbase.hibernate.util.RestrictionsHelper.java

private static Pair<String, MatchMode> wildToNormal(String value, MatchMode mode) {
    boolean starts = value.startsWith("*");
    boolean ends = value.endsWith("*") && !value.endsWith("\\*");
    value = StringUtils.removeStart(value, "*").replaceFirst("^\\*", "*");
    value = ends ? StringUtils.removeEnd(value, "*") : value.replaceFirst("\\\\[*]$", "*");
    if (starts && ends) {
        mode = MatchMode.ANYWHERE;/* www.j a v  a2 s  .c om*/
    } else if (starts) {
        mode = MatchMode.END;
    } else if (ends) {
        mode = MatchMode.START;
    }
    return Pair.of(value, mode);
}

From source file:org.omnaest.i18nbinder.I18nBinder.java

private String reduceFileNameAndCreateDirectoryPath(String fileName) {
    fileName = StringUtils.removeStart(fileName, this.packageName + ".");
    File directory = new File(this.baseNameInTargetPlattform);
    String[] tokens = fileName.split("\\.");
    for (int ii = 0; ii < tokens.length - 1; ii++) {
        String directoryName = tokens[ii];
        directory = new File(directory, directoryName);
        if (!directory.exists()) {
            directory.mkdir();/* w  ww  .  j a  v a  2  s. c  o  m*/
        }
    }
    fileName = StringUtils.join(Arrays.copyOf(tokens, tokens.length - 1), "/") + (tokens.length > 1 ? "/" : "")
            + tokens[tokens.length - 1];
    return fileName;
}

From source file:org.omnaest.i18nbinder.internal.FacadeCreatorHelperTest.java

@Test
public void testCreateI18nInterfaceFacadeFromPropertyFiles() throws IOException {
    ///*  w w w .j  a  v a 2 s. c om*/
    final String packageBaseFolder = "org\\omnaest\\i18nbinder\\internal";

    //
    final String fileNameLocaleGroupPattern = null;
    final List<Integer> groupingPatternGroupingGroupIndexList = null;
    final String baseNameInTargetPlattform = "i18n";
    final String baseFolderIgnoredPath = new File("").getAbsolutePath() + "\\target\\test-classes\\"
            + packageBaseFolder + "\\";
    final String packageName = "org.omnaest.i18nbinder.internal.facade";
    final String javaFacadeFileName = "I18nFacade";
    final boolean externalizeTypes = true;
    final String propertyFileEncoding = "utf-8";

    Map<String, String> facadeFromPropertyFiles = FacadeCreatorHelper
            .createI18nInterfaceFacadeFromPropertyFiles(this.propertyFileSet, new LocaleFilter(),
                    fileNameLocaleGroupPattern, groupingPatternGroupingGroupIndexList,
                    baseNameInTargetPlattform, baseFolderIgnoredPath, packageName, javaFacadeFileName,
                    externalizeTypes, propertyFileEncoding);

    //    
    for (String fileName : facadeFromPropertyFiles.keySet()) {
        //
        final String basePath = new File("").getAbsolutePath() + "\\src\\test\\java\\" + packageBaseFolder
                + "\\facade\\";
        final String fileContent = facadeFromPropertyFiles.get(fileName);

        //
        if (fileName.contains(".")) {
            fileName = StringUtils.removeStart(fileName, packageName + ".");
            File directory = new File(basePath);
            String[] tokens = fileName.split("\\.");
            for (int ii = 0; ii < tokens.length - 1; ii++) {
                String directoryName = tokens[ii];
                directory = new File(directory, directoryName);
                if (!directory.exists()) {
                    directory.mkdir();
                }
            }
            fileName = StringUtils.join(Arrays.copyOf(tokens, tokens.length - 1), "/")
                    + (tokens.length > 1 ? "/" : "") + tokens[tokens.length - 1];
        }

        final File file = new File(basePath, fileName + ".java");
        FileUtils.writeStringToFile(file, fileContent, "utf-8");
    }

}

From source file:org.omnaest.i18nbinder.internal.LocaleFilter.java

public boolean isLocaleAccepted(String locale) {
    locale = StringUtils.removeStart(locale, "_");
    locale = StringUtils.removeEnd(locale, "_");
    return this.pattern.matcher(locale).matches();
}

From source file:org.omnaest.utils.download.URIHelper.java

/**
 * Creates a new {@link Uri} which is based on the given base address and a relative path
 * //from   w  w  w. j a v  a2 s .  com
 * @param baseAddress
 * @param relativePath
 * @return
 */
public static URI createUri(URI baseAddress, String relativePath) {
    //
    URI retval = null;

    //
    if (baseAddress != null && relativePath != null) {
        try {
            //
            String baseAddressAsString = baseAddress.toString();
            if (!baseAddressAsString.endsWith("/")) {
                baseAddress = new URI(baseAddress.toString() + "/");
            }

            //
            relativePath = StringUtils.removeStart(relativePath, "/");

            //
            retval = baseAddress.normalize().resolve(relativePath).normalize();
        } catch (Exception e) {
        }
    }

    //
    return retval;
}

From source file:org.pepstock.jem.ant.tasks.ValueParser.java

/**
 * Parses the value of variables into SCRIPT JCL and loads datasets into data descriptions
 * @param dd data description to load/* ww w.  j  a  va  2s .  co m*/
 * @param valueParm value of property in metadata
 * @throws AntException if any error occurs
 */
public static final void loadDataDescription(DataDescription dd, String valueParm) throws AntException {
    // trim value
    String value = valueParm.trim();

    // init of variables to load dd
    String[] dsn = null;
    String disposition = null;
    String dataSource = null;
    boolean isSysout = false;
    // this boolean is set to true 
    // because if it's not able to parse the content,
    // the wjole string will be the content of dataset
    boolean isText = true;

    // parses using comma
    String[] stmtTokens = StringUtils.split(value, COMMAND_SEPARATOR);
    if (stmtTokens != null && stmtTokens.length > 0) {
        // scans all tokes
        for (int i = 0; i < stmtTokens.length; i++) {
            String token = stmtTokens[i].trim();
            // is datasetname?
            if (StringUtils.startsWithIgnoreCase(token, DSN_PREFIX)) {
                // gets all string after DSN and =
                String subToken = getValue(token, DSN_PREFIX);
                if (subToken != null) {
                    // sets that is not a text
                    isText = false;

                    String subValue = null;
                    // checks if the content is inside of brackets
                    if (subToken.startsWith("(") && subToken.endsWith(")")) {
                        // gets content inside brackets
                        subValue = StringUtils.removeEnd(StringUtils.removeStart(subToken, "("), ")");
                    } else {
                        // only 1 datasets
                        subValue = subToken;
                    }
                    // parses values
                    dsn = StringUtils.split(subValue, VALUE_SEPARATOR);
                }
            } else if (StringUtils.startsWithIgnoreCase(token, DISP_PREFIX)) {
                // sets that is not a text
                isText = false;
                // saves disposition
                disposition = getValue(token, DISP_PREFIX);
            } else if (StringUtils.startsWithIgnoreCase(token, DATASOURCE_PREFIX)) {
                // sets that is not a text
                isText = false;
                // saves data sourceinfo
                dataSource = getValue(token, DATASOURCE_PREFIX);
            } else if (StringUtils.startsWithIgnoreCase(token, SYSOUT)) {
                // sets that is not a text
                isText = false;
                // sets is a sysout
                isSysout = true;
            }
        }
    }
    // content of file
    if (isText) {
        dd.setDisposition(Disposition.SHR);
        DataSet ds = createDataSet(dd, null, valueParm);
        dd.addDataSet(ds);
    } else {
        // disposition DISP= is mandatory, always
        if (disposition == null) {
            throw new AntException(AntMessage.JEMA072E, dd.getName());
        }
        dd.setDisposition(disposition);

        // if sets SYSOUT but also DSN=, this is not allowed
        if (isSysout && dsn != null) {
            throw new AntException(AntMessage.JEMA073E, dd.getName());
        }
        // sets sysout
        dd.setSysout(isSysout);
        // if not sysout, loads datasets
        // datasource can be set ONLY with 1 dataset
        if (!isSysout && dsn != null) {
            if (dsn.length > 1 && dataSource != null) {
                throw new AntException(AntMessage.JEMA074E, dd.getName());
            }
            // loads all datasets and set datasource
            for (int k = 0; k < dsn.length; k++) {
                DataSet ds = createDataSet(dd, dsn[k], null);
                dd.addDataSet(ds);
                // doesn't check anything because
                // already done before
                if (dataSource != null) {
                    ds.setDatasource(dataSource);
                }
            }
        }
    }
}