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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

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

Usage

From source file:org.codice.solr.xpath.XpathQueryParser.java

/**
 * Converts XPath into a Lucene query that will pre-filter based on xpath path and attribute
 * index fields. Further post filtering is needed for XPath functionality that cannot evaluated
 * against xpath index./*from w w  w . ja  v a2  s  .  c o m*/
 *
 * @param queryText
 *            XPath expression to convert into lucene path and attribute index query
 * @return Lucene query to pre-filter using xpath index
 */
private Query getLuceneQuery(final String queryText) {
    String xpath = queryText;

    // Assume root is context node since evaluation does not have a context item
    if (StringUtils.startsWith(xpath, "./")) {
        xpath = StringUtils.removeStart(xpath, ".");
    } else if (!StringUtils.startsWith(xpath, "/")) {
        xpath = "/" + xpath;
    }

    return null; // TODO DDF-1882 add lucene xpath pre-filtering
}

From source file:org.commonjava.maven.ext.core.impl.DependencyManipulator.java

/**
 * Apply a set of version overrides to a list of dependencies. Return a set of the overrides which were not applied.
 *
 * @param project The current Project//from  w w w  .  ja  va 2s  . c o m
 * @param dependencies The list of dependencies
 * @param explicitOverrides Any explicitOverrides to track for ignoring
 * @param overrides The map of dependency version overrides
 * @return The map of overrides that were not matched in the dependencies
 * @throws ManipulationException if an error occurs
 */
private Map<ArtifactRef, String> applyOverrides(final Project project,
        final HashMap<ArtifactRef, Dependency> dependencies, final WildcardMap<String> explicitOverrides,
        final Map<ArtifactRef, String> overrides) throws ManipulationException {
    // Duplicate the override map so unused overrides can be easily recorded
    final Map<ArtifactRef, String> unmatchedVersionOverrides = new LinkedHashMap<>(overrides);

    if (dependencies == null || dependencies.size() == 0) {
        return unmatchedVersionOverrides;
    }

    final CommonState commonState = session.getState(CommonState.class);
    final boolean strict = commonState.getStrict();

    // Apply matching overrides to dependencies
    for (final ArtifactRef dependency : dependencies.keySet()) {
        ProjectRef depPr = new SimpleProjectRef(dependency.getGroupId(), dependency.getArtifactId());

        // We might have junit:junit:3.8.2 and junit:junit:4.1 for differing override scenarios within the
        // overrides list. If strict mode alignment is enabled, using multiple overrides will work with
        // different modules. It is currently undefined what will happen if non-strict mode is enabled and
        // multiple versions are in the remote override list (be it from a bom or rest call). Actually, what
        // will most likely happen is last-wins.
        for (final Map.Entry<ArtifactRef, String> entry : overrides.entrySet()) {
            ProjectRef groupIdArtifactId = entry.getKey().asProjectRef();
            if (depPr.equals(groupIdArtifactId)) {
                final String oldVersion = dependencies.get(dependency).getVersion();
                final String overrideVersion = entry.getValue();
                final String resolvedValue = dependency.getVersionString();

                if (isEmpty(overrideVersion)) {
                    logger.warn("Unable to align with an empty override version for " + groupIdArtifactId
                            + "; ignoring");
                } else if (isEmpty(oldVersion)) {
                    logger.debug("Dependency is a managed version for " + groupIdArtifactId + "; ignoring");
                } else if (oldVersion.equals("${project.version}")
                        || (oldVersion.contains("$") && project.getVersion().equals(resolvedValue))) {
                    logger.warn(
                            "Dependency {} with original version {} and project version {} for {} references ${project.version} so skipping.",
                            dependency, oldVersion, project.getVersion(), project.getPom());
                }
                // If we have an explicitOverride, this will always override the dependency changes made here.
                // By avoiding the potential duplicate work it also avoids a possible property clash problem.
                else if (explicitOverrides.containsKey(depPr)) {
                    logger.debug(
                            "Dependency {} matches known explicit override so not performing initial override pass.",
                            depPr);
                    unmatchedVersionOverrides.remove(entry.getKey());
                }
                // If we're doing strict matching with properties, then the original parts should match.
                // i.e. assuming original resolved value is 1.2 and potential new value is 1.2.rebuild-1
                // then this is fine to continue. If the original is 1.2 and potential new value is 1.3.rebuild-1
                // then don't bother to attempt to cache the property as the strict check would fail.
                // This extra check avoids an erroneous "Property replacement clash" error.

                // Can't blindly compare resolvedValue [original] against ar as ar / overrideVersion is the new GAV. We don't
                // have immediate access to the original property so the closest that is feasible is verify strict matching.
                else if (strict && oldVersion.contains("$")
                        && !PropertiesUtils.checkStrictValue(session, resolvedValue, overrideVersion)) {
                    logger.debug(
                            "Original fully resolved version {} of {} does not match override version {} -> {} so ignoring",
                            resolvedValue, dependency, entry.getKey(), overrideVersion);
                    if (commonState.getFailOnStrictViolation()) {
                        throw new ManipulationException(
                                "For {} replacing original property version {} (fully resolved: {} ) with new version {} for {} violates the strict version-alignment rule!",
                                depPr.toString(), dependencies.get(dependency).getVersion(), resolvedValue,
                                entry.getKey().getVersionString(), entry.getKey().asProjectRef().toString());
                    } else {
                        logger.warn(
                                "Replacing original property version {} with new version {} for {} violates the strict version-alignment rule!",
                                resolvedValue, overrideVersion, dependencies.get(dependency).getVersion());
                    }
                } else {
                    if (!PropertiesUtils.cacheProperty(project, commonState, versionPropertyUpdateMap,
                            oldVersion, overrideVersion, entry.getKey(), false)) {
                        if (strict
                                && !PropertiesUtils.checkStrictValue(session, resolvedValue, overrideVersion)) {
                            if (commonState.getFailOnStrictViolation()) {
                                throw new ManipulationException(
                                        "Replacing original version {} in dependency {} with new version {} violates the strict version-alignment rule!",
                                        oldVersion, groupIdArtifactId.toString(), overrideVersion);
                            } else {
                                logger.warn(
                                        "Replacing original version {} in dependency {} with new version {} violates the strict version-alignment rule!",
                                        oldVersion, groupIdArtifactId, overrideVersion);
                            }
                        } else {
                            logger.debug("Altered dependency {} : {} -> {}", groupIdArtifactId, oldVersion,
                                    overrideVersion);

                            if (oldVersion.contains("${")) {
                                String suffix = PropertiesUtils.getSuffix(session);
                                String replaceVersion;

                                if (commonState.getStrictIgnoreSuffix() && oldVersion.contains(suffix)) {
                                    replaceVersion = StringUtils.substringBefore(oldVersion, suffix);
                                    replaceVersion += suffix
                                            + StringUtils.substringAfter(overrideVersion, suffix);
                                } else {
                                    replaceVersion = oldVersion
                                            + StringUtils.removeStart(overrideVersion, resolvedValue);
                                }
                                logger.debug("Resolved value is {} and replacement version is {} ",
                                        resolvedValue, replaceVersion);

                                // In this case the previous value couldn't be cached even though it contained a property
                                // as it was either multiple properties or a property combined with a hardcoded value. Therefore
                                // just append the suffix.
                                dependencies.get(dependency).setVersion(replaceVersion);
                            } else {
                                dependencies.get(dependency).setVersion(overrideVersion);
                            }
                        }
                    }
                    unmatchedVersionOverrides.remove(entry.getKey());
                }
            }
        }
    }

    return unmatchedVersionOverrides;
}

From source file:org.commonjava.maven.ext.core.util.PropertiesUtils.java

private static PropertyUpdate internalUpdateProperty(ManipulationSession session, Project p,
        boolean ignoreStrict, String key, String newValue, String resolvedValue, Properties props)
        throws ManipulationException {
    final CommonState state = session.getState(CommonState.class);
    final String oldValue = props.getProperty(key);

    logger.info("Updating property {} / {} with {} ", key, oldValue, newValue);

    PropertyUpdate found = PropertyUpdate.FOUND;

    // We'll only recursively resolve the property if its a single >${foo}<. If its one of
    // >${foo}value${foo}<
    // >${foo}${foo}<
    // >value${foo}<
    // >${foo}value<
    // it becomes hairy to verify strict compliance and to correctly split the old value and
    // update it with a portion of the new value.
    if (oldValue != null && oldValue.startsWith("${") && oldValue.endsWith("}")
            && !(StringUtils.countMatches(oldValue, "${") > 1)) {
        logger.debug("Recursively resolving {} ", oldValue.substring(2, oldValue.length() - 1));

        if (updateProperties(session, p, ignoreStrict, oldValue.substring(2, oldValue.length() - 1),
                newValue) == PropertyUpdate.NOTFOUND) {
            logger.error("Recursive property not found for {} with {} ", oldValue, newValue);
            return PropertyUpdate.NOTFOUND;
        }/*from   w w  w  .j a  va  2 s.  c  om*/
    } else {
        if (state.getStrict() && !ignoreStrict) {
            if (!checkStrictValue(session, resolvedValue, newValue)) {
                if (state.getFailOnStrictViolation()) {
                    throw new ManipulationException(
                            "Replacing original property version {} (fully resolved: {} ) with new version {} for {} violates the strict version-alignment rule!",
                            oldValue, resolvedValue, newValue, key);
                } else {
                    logger.warn(
                            "Replacing original property version {} with new version {} for {} violates the strict version-alignment rule!",
                            oldValue, newValue, key);
                    // Ignore the dependency override. As found has been set to true it won't inject
                    // a new property either.
                    return found;
                }
            }
        }

        // TODO: Does not handle explicit overrides.
        if (oldValue != null && oldValue.contains("${")
                && !(oldValue.startsWith("${") && oldValue.endsWith("}"))
                || (StringUtils.countMatches(oldValue, "${") > 1)) {
            // This block handles
            // >${foo}value${foo}<
            // >${foo}${foo}<
            // >value${foo}<
            // >${foo}value<
            // We don't attempt to recursively resolve those as tracking the split of the variables, combined
            // with the update and strict version checking becomes overly fragile.

            if (ignoreStrict) {
                throw new ManipulationException("NYI : handling for versions with explicit overrides ("
                        + oldValue + ") with multiple embedded properties is NYI. ");
            }
            if (resolvedValue.equals(newValue)) {
                logger.warn("Nothing to update as original key {} value matches new value {} ", key, newValue);
                found = PropertyUpdate.IGNORE;
            }
            newValue = oldValue + StringUtils.removeStart(newValue, resolvedValue);
            logger.info("Ignoring new value due to embedded property {} and appending {} ", oldValue, newValue);
        }

        props.setProperty(key, newValue);
    }
    return found;
}

From source file:org.commonjava.maven.ext.manip.impl.DependencyManipulator.java

/**
 * Apply a set of version overrides to a list of dependencies. Return a set of the overrides which were not applied.
 *
 * @param session The ManipulationSession
 * @param project The current Project/*from  ww w.j a v a 2  s .c  om*/
 * @param dependencies The list of dependencies
 * @param overrides The map of dependency version overrides
 * @param explicitOverrides Any explicitOverrides to track for ignoring    @return The map of overrides that were not matched in the dependencies
 * @throws ManipulationException if an error occurs
 */
private Map<ArtifactRef, String> applyOverrides(final ManipulationSession session, Project project,
        final List<Dependency> dependencies, final Map<ArtifactRef, String> overrides,
        WildcardMap<String> explicitOverrides) throws ManipulationException {
    // Duplicate the override map so unused overrides can be easily recorded
    final Map<ArtifactRef, String> unmatchedVersionOverrides = new LinkedHashMap<>();
    unmatchedVersionOverrides.putAll(overrides);

    if (dependencies == null) {
        return unmatchedVersionOverrides;
    }

    final DependencyState state = session.getState(DependencyState.class);
    final boolean strict = state.getStrict();

    // Apply matching overrides to dependencies
    for (final Dependency dependency : dependencies) {
        ProjectRef depPr = new SimpleProjectRef(dependency.getGroupId(), dependency.getArtifactId());

        // We might have junit:junit:3.8.2 and junit:junit:4.1 for differing override scenarios within the
        // overrides list. If strict mode alignment is enabled, using multiple overrides will work with
        // different modules. It is currently undefined what will happen if non-strict mode is enabled and
        // multiple versions are in the remote override list (be it from a bom or rest call). Actually, what
        // will most likely happen is last-wins.
        for (final Map.Entry<ArtifactRef, String> entry : overrides.entrySet()) {
            ProjectRef groupIdArtifactId = entry.getKey().asProjectRef();

            if (depPr.equals(groupIdArtifactId)) {
                final String oldVersion = dependency.getVersion();
                final String overrideVersion = entry.getValue();
                final String resolvedValue = PropertiesUtils.resolveProperties(session.getProjects(),
                        oldVersion);

                if (isEmpty(overrideVersion)) {
                    logger.warn("Unable to align with an empty override version for " + groupIdArtifactId
                            + "; ignoring");
                } else if (isEmpty(oldVersion)) {
                    logger.debug("Dependency is a managed version for " + groupIdArtifactId + "; ignoring");
                }
                // If we have an explicitOverride, this will always override the dependency changes made here.
                // By avoiding the potential duplicate work it also avoids a possible property clash problem.
                else if (explicitOverrides.containsKey(depPr)) {
                    logger.debug(
                            "Dependency {} matches known explicit override so not performing initial override pass.",
                            depPr);
                    unmatchedVersionOverrides.remove(entry.getKey());
                }
                // If we're doing strict matching with properties, then the original parts should match.
                // i.e. assuming original resolved value is 1.2 and potential new value is 1.2.rebuild-1
                // then this is fine to continue. If the original is 1.2 and potential new value is 1.3.rebuild-1
                // then don't bother to attempt to cache the property as the strict check would fail.
                // This extra check avoids an erroneous "Property replacement clash" error.

                // Can't blindly compare resolvedValue [original] against ar as ar / overrideVersion is the new GAV. We don't
                // have immediate access to the original property so the closest that is feasible is verify strict matching.
                else if (strict && oldVersion.contains("$")
                        && !PropertiesUtils.checkStrictValue(session, resolvedValue, overrideVersion)) {
                    logger.debug(
                            "Original fully resolved version {} of {} does not match override version {} -> {} so ignoring",
                            resolvedValue, dependency, entry.getKey(), overrideVersion);
                    if (state.getFailOnStrictViolation()) {
                        throw new ManipulationException(
                                "For {} replacing original property version {} (fully resolved: {} ) with new version {} for {} violates the strict version-alignment rule!",
                                depPr.toString(), dependency.getVersion(), resolvedValue,
                                entry.getKey().getVersionString(), entry.getKey().asProjectRef().toString());
                    } else {
                        logger.warn(
                                "Replacing original property version {} with new version {} for {} violates the strict version-alignment rule!",
                                resolvedValue, overrideVersion, dependency.getVersion());
                    }
                } else {
                    // Too much spurious logging with project.version.
                    if (!oldVersion.equals("${project.version}")) {
                        logger.info("Updating version {} for dependency {} from {}.", overrideVersion,
                                dependency, project.getPom());
                    }

                    if (!PropertiesUtils.cacheProperty(versionPropertyUpdateMap, oldVersion, overrideVersion,
                            entry.getKey(), false)) {
                        if (oldVersion.equals("${project.version}")) {
                            logger.debug("For dependency {} ; version is built in {} so skipping inlining {}",
                                    groupIdArtifactId, oldVersion, overrideVersion);
                        } else if (strict
                                && !PropertiesUtils.checkStrictValue(session, resolvedValue, overrideVersion)) {
                            if (state.getFailOnStrictViolation()) {
                                throw new ManipulationException(
                                        "Replacing original version {} in dependency {} with new version {} violates the strict version-alignment rule!",
                                        oldVersion, groupIdArtifactId.toString(), overrideVersion);
                            } else {
                                logger.warn(
                                        "Replacing original version {} in dependency {} with new version {} violates the strict version-alignment rule!",
                                        oldVersion, groupIdArtifactId, overrideVersion);
                            }
                        } else {
                            logger.debug("Altered dependency {} : {} -> {}", groupIdArtifactId, oldVersion,
                                    overrideVersion);

                            if (oldVersion.contains("${")) {
                                String suffix = PropertiesUtils.getSuffix(session);
                                String replaceVersion;

                                if (state.getStrictIgnoreSuffix() && oldVersion.contains(suffix)) {
                                    replaceVersion = StringUtils.substringBefore(oldVersion, suffix);
                                    replaceVersion += suffix
                                            + StringUtils.substringAfter(overrideVersion, suffix);
                                } else {
                                    replaceVersion = oldVersion
                                            + StringUtils.removeStart(overrideVersion, resolvedValue);
                                }
                                logger.debug("Resolved value is {} and replacement version is {} ",
                                        resolvedValue, replaceVersion);

                                // In this case the previous value couldn't be cached even though it contained a property
                                // as it was either multiple properties or a property combined with a hardcoded value. Therefore
                                // just append the suffix.
                                dependency.setVersion(replaceVersion);
                            } else {
                                dependency.setVersion(overrideVersion);
                            }
                        }
                    }
                    unmatchedVersionOverrides.remove(entry.getKey());
                }
            }
        }
    }

    return unmatchedVersionOverrides;
}

From source file:org.commonjava.maven.ext.manip.util.PropertiesUtils.java

/**
 * Recursively update properties.//from   w w  w.  j av a  2s . c om
 *
 * @param session the DependencyState
 * @param projects the current set of projects we are scanning.
 * @param ignoreStrict whether to ignore strict alignment.
 * @param key a key to look for.
 * @param newValue a value to look for.
 * @return {@code PropertyUpdate} enumeration showing status of any changes.
 * @throws ManipulationException if an error occurs
 */
public static PropertyUpdate updateProperties(ManipulationSession session, Set<Project> projects,
        boolean ignoreStrict, String key, String newValue) throws ManipulationException {
    final DependencyState state = session.getState(DependencyState.class);
    PropertyUpdate found = PropertyUpdate.NOTFOUND;

    final String resolvedValue = resolveProperties(new ArrayList<>(projects), "${" + key + '}');
    logger.debug("Fully resolvedValue is {} for {} ", resolvedValue, key);

    if ("project.version".equals(key)) {
        logger.warn("Not updating key {} with {} ", key, newValue);
        return PropertyUpdate.IGNORE;
    }

    for (final Project p : projects) {
        if (p.getModel().getProperties().containsKey(key)) {
            final String oldValue = p.getModel().getProperties().getProperty(key);

            logger.info("Updating property {} / {} with {} ", key, oldValue, newValue);

            found = PropertyUpdate.FOUND;

            // We'll only recursively resolve the property if its a single >${foo}<. If its one of
            // >${foo}value${foo}<
            // >${foo}${foo}<
            // >value${foo}<
            // >${foo}value<
            // it becomes hairy to verify strict compliance and to correctly split the old value and
            // update it with a portion of the new value.
            if (oldValue != null && oldValue.startsWith("${") && oldValue.endsWith("}")
                    && !(StringUtils.countMatches(oldValue, "${") > 1)) {
                logger.debug("Recursively resolving {} ", oldValue.substring(2, oldValue.length() - 1));

                if (updateProperties(session, projects, ignoreStrict,
                        oldValue.substring(2, oldValue.length() - 1), newValue) == PropertyUpdate.NOTFOUND) {
                    logger.error("Recursive property not found for {} with {} ", oldValue, newValue);
                    return PropertyUpdate.NOTFOUND;
                }
            } else {
                if (state.getStrict() && !ignoreStrict) {
                    if (!checkStrictValue(session, resolvedValue, newValue)) {
                        if (state.getFailOnStrictViolation()) {
                            throw new ManipulationException(
                                    "Replacing original property version {} (fully resolved: {} ) with new version {} for {} violates the strict version-alignment rule!",
                                    oldValue, resolvedValue, newValue, key);
                        } else {
                            logger.warn(
                                    "Replacing original property version {} with new version {} for {} violates the strict version-alignment rule!",
                                    oldValue, newValue, key);
                            // Ignore the dependency override. As found has been set to true it won't inject
                            // a new property either.
                            continue;
                        }
                    }
                }

                // TODO: Does not handle explicit overrides.
                if (oldValue != null && oldValue.contains("${")
                        && !(oldValue.startsWith("${") && oldValue.endsWith("}"))
                        || (StringUtils.countMatches(oldValue, "${") > 1)) {
                    // This block handles
                    // >${foo}value${foo}<
                    // >${foo}${foo}<
                    // >value${foo}<
                    // >${foo}value<
                    // We don't attempt to recursively resolve those as tracking the split of the variables, combined
                    // with the update and strict version checking becomes overly fragile.

                    if (ignoreStrict) {
                        throw new ManipulationException("NYI : handling for versions with explicit overrides ("
                                + oldValue + ") with multiple embedded properties is NYI. ");
                    }
                    if (resolvedValue.equals(newValue)) {
                        logger.warn("Nothing to update as original key {} value matches new value {} ", key,
                                newValue);
                        found = PropertyUpdate.IGNORE;
                        continue;
                    }
                    newValue = oldValue + StringUtils.removeStart(newValue, resolvedValue);
                    logger.info("Ignoring new value due to embedded property {} and appending {} ", oldValue,
                            newValue);
                }

                p.getModel().getProperties().setProperty(key, newValue);
            }
        }
    }
    return found;
}

From source file:org.cruxframework.crux.core.server.crawling.CrawlingFilter.java

/**
 * //from w  ww. ja  v  a2 s  . c  o  m
 * @param req
 * @return
 */
protected String getRequestedPage(ServletRequest req) {
    HttpServletRequest request = (HttpServletRequest) req;
    String result = request.getPathInfo();
    if (result == null) {
        result = request.getRequestURI();
    }
    if (result != null && result.length() > 0) {
        if (result.endsWith(".html") && !result.endsWith("hosted.html") && !result.endsWith("cache.html")) {
            if (result.startsWith("/")) {
                result = result.substring(1);
            }

            String contextPath = config.getServletContext().getContextPath();
            if (contextPath != null && contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }

            if (StringUtils.isNotBlank(contextPath) && result.startsWith(contextPath)) {
                result = StringUtils.removeStart(result, contextPath);
            }
            if (result.startsWith("/")) {
                result = result.substring(1);
            }
        } else {
            result = null;
        }
    } else {
        result = null;
    }
    return result;
}

From source file:org.cruxframework.crux.core.server.offline.AppcacheFilter.java

private long getDateModified(HttpServletRequest request) throws IOException {
    Long result;//from  w w w .j a v  a 2 s. c  o  m
    try {
        String file = request.getRequestURI();
        result = lastModifiedDates.get(file);

        if (result == null) {
            String contextPath = filterConfig.getServletContext().getContextPath();

            if (StringUtils.isNotBlank(contextPath) && file.startsWith(contextPath)) {
                file = StringUtils.removeStart(file, contextPath);
            }

            InputStream stream = filterConfig.getServletContext().getResourceAsStream(file);

            if (stream != null) {
                String content = StreamUtils.readAsUTF8(stream);
                int indexStart = content.indexOf("# Build Time [");
                int indexEnd = content.indexOf("]", indexStart);
                if (indexStart > 0 && indexEnd > 0) {
                    String dateStr = content.substring(indexStart + 14, indexEnd);
                    result = Long.parseLong(dateStr);
                    lastModifiedDates.put(file, result);
                } else {
                    result = 0l;
                }
            } else {
                result = 0l;
            }
        }
    } catch (Exception e) {
        result = 0l;
    }

    return result;
}

From source file:org.devproof.portal.core.module.theme.service.ThemeServiceImpl.java

private String getZipPath(Resource roots[], Resource current) throws IOException {
    String currentPath = current.getURL().getPath();
    for (Resource root : roots) {
        String rootPath = root.getURL().getPath();
        if (currentPath.startsWith(rootPath)) {
            return StringUtils.removeStart(currentPath, rootPath);
        }//from ww  w.j  ava2s  . com
    }
    return null;
}

From source file:org.eclipse.gyrex.cloud.internal.locking.ZooKeeperLock.java

/**
 * This method is only public for testing purposes. It must not be called by
 * clients./*from   www.  java 2 s . c o m*/
 * 
 * @noreference This method is not intended to be referenced by clients.
 */
public static String[] extractRecoveryKeyDetails(final String recoveryKey) {
    final String[] keySegments = StringUtils.splitByWholeSeparator(recoveryKey, SEPARATOR);
    if (keySegments.length < 2)
        throw new IllegalArgumentException("invalid recovery key format");
    final String lockName = keySegments[0];
    final String nodeContent = StringUtils.removeStart(recoveryKey, lockName.concat(SEPARATOR));

    if (StringUtils.isBlank(lockName) || StringUtils.isBlank(nodeContent))
        throw new IllegalArgumentException("invalid recovery key format");
    return new String[] { lockName, nodeContent };
}

From source file:org.eclipse.gyrex.cloud.internal.locking.ZooKeeperLock.java

private static int getSequenceNumber(final String nodeName) {
    return NumberUtils.toInt(StringUtils.removeStart(nodeName, LOCK_NAME_PREFIX), -1);
}