Example usage for org.apache.commons.lang3 ExtendedCharSequenceUtils getSafeLength

List of usage examples for org.apache.commons.lang3 ExtendedCharSequenceUtils getSafeLength

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ExtendedCharSequenceUtils getSafeLength.

Prototype

public static final int getSafeLength(CharSequence seq) 

Source Link

Usage

From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java

protected SortedSet<File> ensureFoldersExistence(File appBase, NamedExtendedPlaceholderResolver propsResolver,
        ExtendedPlaceholderResolver sourcesResolver) {
    final SortedSet<File> createdFiles = verifyFolderProperty(ConfigUtils.GITCLOUD_BASE_PROP, appBase,
            ExtendedSetUtils.<File>sortedSet(ExtendedFileUtils.BY_ABSOLUTE_PATH_COMPARATOR));
    final String appBasePrefix = appBase.getAbsolutePath();
    final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
            SystemPropertyUtils.PLACEHOLDER_PREFIX, SystemPropertyUtils.PLACEHOLDER_SUFFIX,
            SystemPropertyUtils.VALUE_SEPARATOR, true);
    final ExtendedPlaceholderResolver resolver = new AggregatedExtendedPlaceholderResolver(propsResolver,
            sourcesResolver);/*from w  w  w  .  j  a  v  a 2 s  .  co  m*/
    ExtendedPlaceholderResolverUtils.forAllEntriesDo(propsResolver, new Closure<Map.Entry<String, String>>() {
        @Override
        @SuppressWarnings("synthetic-access")
        public void execute(Entry<String, String> e) {
            String propName = e.getKey(), propValue = e.getValue();
            if (StringUtils.isEmpty(propName) || (!propName.endsWith(".dir"))
                    || StringUtils.isEmpty(propValue)) {
                return;
            }

            String resolvedValue = helper.replacePlaceholders(propValue, resolver);
            if (ExtendedCharSequenceUtils.getSafeLength(resolvedValue) < appBasePrefix.length()) {
                return;
            }

            String pathValue = resolvedValue.replace('/', File.separatorChar); // just in case using '/'
            if (logger.isDebugEnabled()) {
                logger.debug("ensureFoldersExistence(" + propName + "): " + pathValue);
            }

            if (pathValue.startsWith(appBasePrefix)) {
                verifyFolderProperty(propName, new File(pathValue), createdFiles);
            }
        }
    });
    return createdFiles;
}