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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:org.apache.syncope.core.logic.scim.SearchCondVisitor.java

private SearchCond addresses(final String operator, final String left, final String right,
        final List<SCIMUserAddressConf> items) {

    if (left.endsWith(".type") && "eq".equals(operator)) {
        Optional<SCIMUserAddressConf> item = items.stream()
                .filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst();
        if (item.isPresent()) {
            AttributeCond attributeCond = new AttributeCond();
            attributeCond.setSchema(item.get().getFormatted());
            attributeCond.setType(AttributeCond.Type.ISNOTNULL);
            return SearchCond.getLeafCond(attributeCond);
        }/*from   w w w .j  a v a 2  s  .c om*/
    } else if (!conf.getUserConf().getEmails().isEmpty()
            && (MULTIVALUE.contains(left) || left.endsWith(".value"))) {

        List<SearchCond> orConds = new ArrayList<>();
        items.forEach(item -> {
            AttributeCond cond = new AttributeCond();
            cond.setSchema(item.getFormatted());
            cond.setExpression(StringUtils.strip(right, "\""));
            orConds.add(setOperator(cond, operator));
        });
        if (!orConds.isEmpty()) {
            return SearchCond.getOrCond(orConds);
        }
    }

    return null;
}

From source file:org.apache.syncope.core.logic.scim.SearchCondVisitor.java

private SearchCond transform(final String operator, final String left, final String right) {
    SearchCond result = null;/*from  ww w .  j  a  v a2 s  .co m*/

    if (MULTIVALUE.contains(StringUtils.substringBefore(left, "."))) {
        if (conf.getUserConf() == null) {
            throw new IllegalArgumentException(
                    "No " + SCIMUserConf.class.getName() + " provided, cannot continue");
        }

        switch (StringUtils.substringBefore(left, ".")) {
        case "emails":
            result = complex(operator, left, right, conf.getUserConf().getEmails());
            break;

        case "phoneNumbers":
            result = complex(operator, left, right, conf.getUserConf().getPhoneNumbers());
            break;

        case "ims":
            result = complex(operator, left, right, conf.getUserConf().getIms());
            break;

        case "photos":
            result = complex(operator, left, right, conf.getUserConf().getPhotos());
            break;

        case "addresses":
            result = addresses(operator, left, right, conf.getUserConf().getAddresses());
            break;

        default:
        }
    }

    if (result == null) {
        AttributeCond attributeCond = createAttributeCond(left);
        attributeCond.setExpression(StringUtils.strip(right, "\""));
        result = setOperator(attributeCond, operator);
    }

    if (result == null) {
        throw new IllegalArgumentException(
                "Could not handle (" + left + " " + operator + " " + right + ") for " + resource);
    }
    return result;
}

From source file:org.corpus_tools.peppermodules.ridgesModules.SOrderRelationAdderProperties.java

public Set<String> getSegmentations() {
    if (segmentations == null) {
        segmentations = new HashSet<String>();
        String segs = (String) this.getProperty(PROP_SEGMENTATION_LAYERS).getValue();
        if (segs != null) {
            segs = StringUtils.strip(segs, "{}");
            for (String seg : segs.split("\\s*,\\s*")) {
                segmentations.add(seg.trim());
            }// w  w w  . j av a  2 s . co  m
        }
    }

    return (segmentations);
}

From source file:org.craftercms.core.url.impl.LongToShortUrlTransformer.java

protected String getShortUrl(String longUrl) {
    String[] levels = StringUtils.strip(longUrl, "/").split("/");
    StringBuilder result = new StringBuilder();

    if (ArrayUtils.isNotEmpty(levels)) {
        for (String level : levels) {
            result.append("/")
                    .append(UrlUtils.getShortName(level, containsShortNameRegex, shortNameRegexGroup));
        }/* w w  w  . j a va  2s .c o m*/
    }

    if (longUrl.endsWith("/")) {
        result.append("/");
    }

    return result.toString();
}

From source file:org.craftercms.core.url.impl.ShortToLongUrlTransformer.java

protected String getLongUrl(Context context, CachingOptions cachingOptions, String shortUrl,
        boolean useShortNameIfLongNameNotFound) throws UrlTransformationException {
    String[] levels = StringUtils.strip(shortUrl, "/").split("/");
    StringBuilder result = new StringBuilder();

    if (ArrayUtils.isNotEmpty(levels)) {
        for (String level : levels) {
            String folderPath = result.toString();
            folderPath = StringUtils.isNotEmpty(folderPath) ? folderPath : "/";

            String longName = getLongName(context, cachingOptions, folderPath, level);
            if (StringUtils.isNotEmpty(longName)) {
                result.append("/").append(longName);
            } else if (useShortNameIfLongNameNotFound) {
                result.append("/").append(level);
            } else {
                return null;
            }/* w w  w  .ja  v  a2s.  co m*/
        }
    }

    if (shortUrl.endsWith("/")) {
        result.append("/");
    }

    return result.toString();
}

From source file:org.craftercms.engine.navigation.impl.RejectIndexFilesItemFilter.java

@Override
public boolean accepts(Item item, List<Item> acceptedItems, List<Item> rejectedItems,
        boolean runningBeforeProcessing) {
    String indexFileName = SiteProperties.getIndexFileName();
    String itemFileName = item.getName();

    if (indexFileName.equals(itemFileName)) {
        return false;
    } else if (SiteProperties.isTargetingEnabled() && targetedUrlStrategy.isFileNameBasedStrategy()) {
        TargetedUrlComponents targetedFileNameComponents = targetedUrlStrategy.parseTargetedUrl(itemFileName);
        if (targetedFileNameComponents != null) {
            String prefix = targetedFileNameComponents.getPrefix();
            String suffix = targetedFileNameComponents.getSuffix();
            String nonTargetedItemFileName = targetedUrlStrategy.buildTargetedUrl(prefix, null, suffix);

            nonTargetedItemFileName = StringUtils.strip(nonTargetedItemFileName, "/");

            if (indexFileName.equals(nonTargetedItemFileName)) {
                return false;
            }/*  w  w  w  .j ava2s . com*/
        }
    }

    return true;
}

From source file:org.dbgl.model.conf.Autoexec.java

void parseLines(final List<String> orgLines) {
    char driveletter = '\0';
    String remainder = StringUtils.EMPTY;
    String executable = StringUtils.EMPTY;
    String image1 = StringUtils.EMPTY;
    String image2 = StringUtils.EMPTY;
    String image3 = StringUtils.EMPTY;
    int exeIndex = -1;

    String customEchos = StringUtils.EMPTY;
    List<String> leftOvers = new ArrayList<String>();
    int customSection = -1;

    line: for (String orgLine : orgLines) {
        orgLine = orgLine.trim();//from  w  w  w . j  a  va 2  s. c om

        for (int i = 0; i < SECTIONS; i++) {
            if (orgLine.startsWith(CUSTOM_SECTION_MARKERS[i * 2])) {
                customSection = i;
                continue line;
            }
        }

        if (customSection > -1) {
            if (orgLine.startsWith(CUSTOM_SECTION_MARKERS[customSection * 2 + 1]))
                customSection = -1;
            else
                customSections[customSection] += orgLine + PlatformUtils.EOLN;
            continue;
        }

        orgLine = StringUtils.stripStart(orgLine, "@").trim();

        Matcher loadhighMatcher = LOADHIGH_PATRN.matcher(orgLine);
        Matcher loadfixMatcher = LOADFIX_PATRN.matcher(orgLine);
        Matcher bootMatcher = BOOT_PATRN.matcher(orgLine);

        if (loadhighMatcher.matches()) {
            loadhigh = true;
            orgLine = loadhighMatcher.group(1).trim();
        }

        if (loadfixMatcher.matches()) {
            if (!loadfix) {
                loadfixValue = 64;
                loadfix = true;
            }
            if (loadfixMatcher.group(1) != null) // -f
                continue;
            if (loadfixMatcher.group(2) != null) {
                try {
                    loadfixValue = Integer.parseInt(loadfixMatcher.group(2).trim().substring(1));
                } catch (NumberFormatException e) {
                    // use default value of 64
                }
            }
            if (loadfixMatcher.group(3) == null)
                continue;
            orgLine = loadfixMatcher.group(3).trim();
        }

        String line = orgLine.toLowerCase();

        if (StringUtils.isEmpty(line)) {
            continue;
        } else if (line.startsWith("mount ") || line.startsWith("imgmount ")) {
            addMount(orgLine);
        } else if ((line.endsWith(":") && line.length() == 2) || (line.endsWith(":\\") && line.length() == 3)) {
            driveletter = Character.toUpperCase(line.charAt(0));
            remainder = StringUtils.EMPTY;
        } else if (line.startsWith("cd\\")) {
            if (driveletter != '\0') {
                String add = PlatformUtils.toNativePath(orgLine).substring(2);
                if (add.startsWith("\\"))
                    remainder = add;
                else
                    remainder = new File(remainder, add).getPath();
            }
        } else if (line.startsWith("cd ")) {
            if (driveletter != '\0') {
                String add = PlatformUtils.toNativePath(orgLine).substring(3);
                if (add.startsWith("\\"))
                    remainder = add;
                else
                    remainder = new File(remainder, add).getPath();
            }
        } else if (line.startsWith("keyb ") || line.startsWith("keyb.com ")) {
            keyb = orgLine.substring(line.indexOf(' ') + 1);
        } else if (line.startsWith("mixer ") || line.startsWith("mixer.com ")) {
            mixer = orgLine.substring(line.indexOf(' ') + 1);
        } else if (line.startsWith("ipxnet ") || line.startsWith("ipxnet.com ")) {
            ipxnet = orgLine.substring(line.indexOf(' ') + 1);
        } else if (line.equals("pause")) {
            pause = true;
        } else if (line.startsWith("z:\\config.com")) {
            // just ignore
        } else if ((exeIndex = StringUtils.indexOfAny(line, FileUtils.EXECUTABLES)) != -1) {
            executable = orgLine;
            // If there is a space BEFORE executable name, strip everything before it
            int spaceBeforeIndex = executable.lastIndexOf(' ', exeIndex);
            if (spaceBeforeIndex != -1) {
                executable = executable.substring(spaceBeforeIndex + 1);
            }
            // If there is a space AFTER executable name, define it as being parameters
            int spaceAfterIndex = executable.indexOf(' ');
            if (spaceAfterIndex != -1) {
                params = orgLine.substring(spaceBeforeIndex + spaceAfterIndex + 2);
                executable = executable.substring(0, spaceAfterIndex);
            }
        } else if (bootMatcher.matches()) {
            Matcher bootImgsMatcher = BOOTIMGS_PATRN.matcher(bootMatcher.group(1).trim());
            if (bootImgsMatcher.matches()) {
                if (bootImgsMatcher.group(1) != null)
                    image1 = StringUtils.strip(bootImgsMatcher.group(1), "\"");
                if (bootImgsMatcher.group(2) != null)
                    image2 = StringUtils.strip(bootImgsMatcher.group(2), "\"");
                if (bootImgsMatcher.group(3) != null)
                    image3 = StringUtils.strip(bootImgsMatcher.group(3), "\"");
            }
            if (bootMatcher.group(2) != null)
                imgDriveletter = bootMatcher.group(2).trim().toUpperCase();
            if (StringUtils.isEmpty(image1) && StringUtils.isNotEmpty(imgDriveletter)) {
                char driveNumber = (char) ((int) imgDriveletter.charAt(0) - 17);
                String matchingImageMount = findImageMatchByDrive(driveNumber, imgDriveletter.charAt(0));
                if (matchingImageMount != null)
                    image1 = matchingImageMount;
            }
            if ("\\file".equals(image1)) {
                img1 = "file"; // for template if . was unavailable
            }
        } else if (line.equals("exit") || line.startsWith("exit ")) {
            exit = true;
        } else if (line.equals("echo off")) {
            // just ignore
        } else if (line.equals("echo") || line.startsWith("echo ") || line.startsWith("echo.")) {
            customEchos += orgLine + PlatformUtils.EOLN;
        } else if (line.startsWith(":") || line.equals("cd") || line.equals("cls") || line.startsWith("cls ")
                || line.startsWith("cls\\") || line.equals("rem") || line.startsWith("rem ")
                || line.startsWith("goto ") || line.startsWith("if errorlevel ")) {
            // just ignore
        } else {
            leftOvers.add(orgLine);
        }
    }

    if (StringUtils.isNotEmpty(customEchos) && !customEchos.equalsIgnoreCase("echo." + PlatformUtils.EOLN)) {
        customSections[1] += "@echo off" + PlatformUtils.EOLN + customEchos; // add echo commands to pre-launch custom section
        customSections[1] += "pause" + PlatformUtils.EOLN; // add pause statement to make it all readable
    }

    if (executable.equals(StringUtils.EMPTY) && !leftOvers.isEmpty()) {
        for (int i = 0; i < leftOvers.size(); i++) {
            executable = leftOvers.get(i).trim();
            if (i == (leftOvers.size() - 1)) { // the last executable should be the main game
                boolean isCalledBatch = executable.toLowerCase().startsWith("call ");
                if (isCalledBatch)
                    executable = executable.substring(5);
                int spaceAfterIndex = executable.indexOf(' ');
                if (spaceAfterIndex != -1) {
                    params = executable.substring(spaceAfterIndex + 1);
                    executable = executable.substring(0, spaceAfterIndex);
                }
                executable += isCalledBatch ? FileUtils.EXECUTABLES[2] : FileUtils.EXECUTABLES[0];
            } else {
                customSections[1] += executable + PlatformUtils.EOLN; // add other statements to pre-launch custom section
            }
        }
    }

    for (Mount mount : mountingpoints) {
        char mount_drive = mount.getDriveletter();
        String mountPath = mount.getHostPathAsString();
        if (driveMatches(executable, mount_drive, driveletter))
            main = splitInThree(executable, mountPath, remainder);
        else {
            if (mount.matchesImageMountPath(image1))
                img1 = image1;
            else if (driveMatches(image1, mount_drive, driveletter))
                img1 = splitInThree(image1, mountPath, remainder);
            if (mount.matchesImageMountPath(image2))
                img2 = image2;
            else if (driveMatches(image2, mount_drive, driveletter))
                img2 = splitInThree(image2, mountPath, remainder);
            if (mount.matchesImageMountPath(image3))
                img3 = image1;
            else if (driveMatches(image3, mount_drive, driveletter))
                img3 = splitInThree(image3, mountPath, remainder);
        }
    }

    if (exit == null)
        exit = false;
}

From source file:org.dbgl.model.Mount.java

public Mount(final String mount) throws InvalidMountstringException {
    init();// www .ja v  a  2  s . co  m
    Matcher mountMatcher = MOUNT_PATRN.matcher(mount);
    Matcher imgmountMatcher = IMGMOUNT_PATRN.matcher(mount);

    if (mountMatcher.matches()) {
        if (mountMatcher.group(1) != null) {
            unmounted = true;
            driveletter = Character.toUpperCase(mountMatcher.group(1).charAt(0));
            return;
        }
        driveletter = Character.toUpperCase(mountMatcher.group(2).charAt(0));
        String mountLocation = StringUtils.strip(PlatformUtils.toNativePath(mountMatcher.group(3)), "\"");
        if (FileUtils.isPhysFS(mountLocation))
            initForPhysFS(mountLocation);
        else
            path = new File[] { FileUtils.makeRelativeToDosroot(FileUtils.canonicalToDosroot(mountLocation)) };
        mountAs = StringUtils.defaultString(mountMatcher.group(4));
        label = StringUtils.defaultString(mountMatcher.group(5));
        lowlevelCD = StringUtils.defaultString(mountMatcher.group(6));
        freesize = StringUtils.defaultString(mountMatcher.group(7));
        useCD = StringUtils.defaultString(mountMatcher.group(8));
    } else if (imgmountMatcher.matches()) {
        mountingType = MountingType.IMAGE;
        driveletter = Character.toUpperCase(imgmountMatcher.group(1).charAt(0));
        String[] paths = StringUtils.stripAll(PlatformUtils.toNativePath(imgmountMatcher.group(2)).trim()
                .split("\\s(?=([^\"]*\"[^\"]*\")*[^\"]*$)"), "\"");
        path = new File[paths.length];
        for (int i = 0; i < paths.length; i++)
            path[i] = FileUtils.makeRelativeToDosroot(FileUtils.canonicalToDosroot(paths[i]));
        mountAs = StringUtils.defaultString(imgmountMatcher.group(3));
        if (mountAs.equalsIgnoreCase("cdrom"))
            mountAs = "iso";
        fs = StringUtils.defaultString(imgmountMatcher.group(4));
        size = StringUtils.defaultString(imgmountMatcher.group(5));
    } else {
        throw new InvalidMountstringException();
    }
}

From source file:org.dbgl.util.StringRelatedUtils.java

public static String[] textAreaToStringArray(final String contents, final String del) {
    return StringUtils.splitByWholeSeparator(StringUtils.strip(contents, del), del);
}

From source file:org.dbgl.util.StringRelatedUtils.java

public static String textAreaToString(final String contents, final String del, final String eoln) {
    return StringUtils.replace(StringUtils.strip(contents, del), del, eoln);
}