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

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

Introduction

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

Prototype

public static String trim(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null .

The String is trimmed using String#trim() .

Usage

From source file:org.alfresco.po.share.ShareDialogueAikau.java

/**
 * Click Button with the name/*from  w w  w .  j  a  v  a  2  s  . co m*/
 * 
 * @param buttonName
 * @return HtmlPage
 */
public HtmlPage clickActionByName(String buttonName) {
    boolean buttonFound = false;
    try {
        List<WebElement> dialogButtons = findDisplayedElements(DIALOGUE_BUTTONS);

        // Iterate over the dialogButtons and click the button that matches the named dialog button name
        for (WebElement button : dialogButtons) {
            if (buttonName.equalsIgnoreCase(StringUtils.trim(button.getText()))) {
                button.click();
                buttonFound = true;
                break;
            }
        }

        if (buttonFound) {
            return factoryPage.getPage(driver);
        } else {
            throw new PageOperationException("Not able find the button " + buttonName);
        }
    } catch (TimeoutException e) {
        throw new PageOperationException("Not able find the button ", e);
    } catch (StaleElementReferenceException ser) {
        LOGGER.info("StaleElementReferenceException while finding Dialogue Button", ser);
        return clickActionByName(buttonName);
    }
}

From source file:org.aliuge.crawler.extractor.selector.IFConditions.java

/**
 * ???//from w  w w.j  a v  a 2s .  c o  m
 * 
 * @param depend
 * @return
 */
public boolean test(Map<String, Object> selectContent) throws ExtractException {
    TreeMap<Integer, String> conIndex = Maps.newTreeMap();
    Queue<SimpleExpression> expressionQueue = Queues.newArrayDeque();
    Queue<String> logicQueue = Queues.newArrayDeque();
    // a=b and c=d or c=e or x=y
    int index = 0;
    for (String co : cond) {
        index = 0;
        while ((index = conditions.indexOf(co, index + 1)) > -1) {
            int i = index;
            conIndex.put(i, co);
        }
    }
    index = 0;
    for (Entry<Integer, String> entry : conIndex.entrySet()) {
        String subExp = conditions.substring(index, entry.getKey());
        for (String op : operations) {
            int i = subExp.indexOf(op);
            if (i > -1) {
                String[] ss = subExp.split(op);
                if (null == selectContent.get(ss[0].trim())) {
                    throw new ExtractException("?????["
                            + this.conditions + "] " + ss[0]);
                }
                expressionQueue
                        .add(new SimpleExpression(StringUtils.trim((String) selectContent.get(ss[0].trim())),
                                StringUtils.trim(ss[1]), op));
                logicQueue.add(StringUtils.trim(entry.getValue()));
            }
        }
        index = entry.getKey() + entry.getValue().length();
    }
    // ??
    String subExp = conditions.substring(index);
    for (String op : operations) {
        int i = subExp.indexOf(op);
        if (i > -1) {
            String[] ss = subExp.split(op);
            if (null == selectContent.get(ss[0].trim())) {
                throw new ExtractException("?????[" + this.conditions
                        + "] " + ss[0]);
            }
            expressionQueue.add(new SimpleExpression(StringUtils.trim((String) selectContent.get(ss[0].trim())),
                    StringUtils.trim(ss[1]), op));
        }
    }
    boolean b;
    try {
        b = expressionQueue.poll().test();
        while (!expressionQueue.isEmpty()) {
            b = cacl(b, logicQueue.poll(), expressionQueue.poll());
        }
        return b;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:org.apache.bookkeeper.common.util.affinity.impl.IsolatedProcessors.java

static SortedSet<Integer> parseProcessorRange(String range) {
    SortedSet<Integer> processors = new TreeSet<>();

    for (String part : StringUtils.trim(range).split(",")) {
        if (part.contains("-")) {
            // This is a range, eg: 1-5 with both edges included
            String[] parts = part.split("-");
            int first = Integer.parseInt(parts[0]);
            int last = Integer.parseInt(parts[1]);

            for (int i = first; i <= last; i++) {
                processors.add(i);//  w w w.  j  av a 2 s .c  o m
            }
        } else if (!part.isEmpty()) {
            processors.add(Integer.parseInt(part));
        }
    }

    return processors;
}

From source file:org.apache.bookkeeper.common.util.affinity.impl.IsolatedProcessors.java

/**
 * Instruct Linux to disable a particular CPU. This is used to disable hyper-threading on a particular core, by
 * shutting down the cpu that shares the same core.
 *///  w w w. j a  v a 2s  .c  o m
private static void changeCpuStatus(int cpu, boolean enable) throws IOException {
    Path cpuPath = Paths.get(String.format("/sys/devices/system/cpu/cpu%d/online", cpu));

    boolean currentState = Integer
            .parseInt(StringUtils.trim(new String(Files.readAllBytes(cpuPath), ENCODING))) != 0;

    if (currentState != enable) {
        Files.write(cpuPath, (enable ? "1\n" : "0\n").getBytes(ENCODING), StandardOpenOption.TRUNCATE_EXISTING);
        log.info("{} CPU {}", enable ? "Enabled" : "Disabled", cpu);
    }
}

From source file:org.apache.bookkeeper.common.util.affinity.impl.ProcessorsInfo.java

static ProcessorsInfo parseCpuInfo(String cpuInfoString) {
    ProcessorsInfo pi = new ProcessorsInfo();

    for (String cpu : cpuInfoString.split("\n\n")) {
        int cpuId = -1;
        int coreId = -1;

        for (String line : cpu.split("\n")) {
            String[] parts = line.split(":", 2);
            String key = StringUtils.trim(parts[0]);
            String value = StringUtils.trim(parts[1]);

            if (key.equals("core id")) {
                coreId = Integer.parseInt(value);
            } else if (key.equals("processor")) {
                cpuId = Integer.parseInt(value);
            } else {
                // ignore
            }/* ww w .j  a  v  a 2  s. c  om*/
        }

        checkArgument(cpuId >= 0);
        checkArgument(coreId >= 0);
        pi.cpus.put(cpuId, coreId);
    }

    return pi;
}

From source file:org.apache.falcon.entity.store.FeedLocationStore.java

@Override
public void onAdd(Entity entity) throws FalconException {
    if (entity.getEntityType() == EntityType.FEED) {
        Feed feed = (Feed) entity;//from   w  w  w .  ja v a2  s . c  o m
        List<Cluster> clusters = feed.getClusters().getClusters();
        for (Cluster cluster : clusters) {
            if (DeploymentUtil.getCurrentClusters().contains(cluster.getName())) {
                List<Location> clusterSpecificLocations = FeedHelper
                        .getLocations(FeedHelper.getCluster(feed, cluster.getName()), feed);
                if (clusterSpecificLocations != null) {
                    for (Location location : clusterSpecificLocations) {
                        if (location != null && StringUtils.isNotBlank(location.getPath())) {
                            FeedLookupResult.FeedProperties value = new FeedLookupResult.FeedProperties(
                                    feed.getName(), location.getType(), cluster.getName());
                            store.insert(StringUtils.trim(location.getPath()), value);
                            LOG.debug("Inserted location: {} for feed: {} and cluster: {}", location.getPath(),
                                    feed.getName(), cluster.getName());
                        }
                    }
                }
            }
        }
    }
}

From source file:org.apache.falcon.resource.AbstractEntityManager.java

/**
 * Given the location of data, returns the feed.
 * @param type type of the entity, is valid only for feeds.
 * @param instancePath location of the data
 * @return Feed Name, type of the data and cluster name.
 *//*from   w  w w  .  j ava  2  s .  c o  m*/
public FeedLookupResult reverseLookup(String type, String instancePath) {
    try {
        EntityType entityType = EntityType.getEnum(type);
        if (entityType != EntityType.FEED) {
            LOG.error("Reverse Lookup is not supported for entitytype: {}", type);
            throw new IllegalArgumentException("Reverse lookup is not supported for " + type);
        }

        instancePath = StringUtils.trim(instancePath);
        String instancePathWithoutSlash = instancePath.endsWith("/") ? StringUtils.removeEnd(instancePath, "/")
                : instancePath;
        // treat strings with and without trailing slash as same for purpose of searching e.g.
        // /data/cas and /data/cas/ should be treated as same.
        String instancePathWithSlash = instancePathWithoutSlash + "/";
        FeedLocationStore store = FeedLocationStore.get();
        Collection<FeedLookupResult.FeedProperties> feeds = new ArrayList<>();
        Collection<FeedLookupResult.FeedProperties> res = store.reverseLookup(instancePathWithoutSlash);
        if (res != null) {
            feeds.addAll(res);
        }
        res = store.reverseLookup(instancePathWithSlash);
        if (res != null) {
            feeds.addAll(res);
        }
        FeedLookupResult result = new FeedLookupResult(APIResult.Status.SUCCEEDED, "SUCCESS");
        FeedLookupResult.FeedProperties[] props = feeds.toArray(new FeedLookupResult.FeedProperties[0]);
        result.setElements(props);
        return result;

    } catch (IllegalArgumentException e) {
        throw FalconWebException.newException(e, Response.Status.BAD_REQUEST);
    } catch (Throwable throwable) {
        LOG.error("reverse look up failed", throwable);
        throw FalconWebException.newException(throwable, Response.Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.apache.falcon.util.ApplicationProperties.java

@Override
public String getProperty(String key) {
    return StringUtils.trim(super.getProperty(key));
}

From source file:org.apache.falcon.util.ApplicationProperties.java

@Override
public String getProperty(String key, String defaultValue) {
    return StringUtils.trim(super.getProperty(key, defaultValue));
}

From source file:org.apache.fineract.infrastructure.dataexport.helper.DataExportUtils.java

/**
 * Search and replace string using the searchList string array and replacementList string array
 * //from   www .  j av  a 2  s  . c  o m
 * @param string
 * @param searchList
 * @param replacementList
 * @return replacement string for the specified string
 */
public static String searchAndReplaceString(final String string, final String[] searchList,
        final String[] replacementList) {
    // replace all occurrences of the strings the "searchList" array with 
    // their corresponding string in the "replacementList" array
    final String replacementString = StringUtils.replaceEach(string, searchList, replacementList);

    // finally, trim the string
    return StringUtils.trim(replacementString);
}