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.admin.VisibilityDropDown.java

/**
 * Instantiates a new visibility drop down.
 * /*from  ww w . j  ava  2s.c  om*/
 * @param driver the web driver
 * @param element the element
 */
public VisibilityDropDown(WebDriver driver, WebElement element) {
    this.driver = driver;
    this.value = SiteVisibility.getEnum(StringUtils.trim(element.getText()));
    this.control = element.findElement(CONTROL_ELEMENT);
    // The dropdown menu has the same id as the control element with '_dropdown' appended
    this.menuId = this.control.getAttribute("id") + MENU_ELEMENT_SUFFIX;
}

From source file:org.alfresco.po.share.admin.VisibilityDropDown.java

/**
 * Select a new visibility drop down value.
 * /*from  w ww  .  j  a v a2s .  co m*/
 * @param visibility the visibility
 */
public void selectValue(SiteVisibility visibility) {
    // Click the control to open the menu
    control.click();

    // Compose the selector for the drop down menu
    String menuSelector = StringUtils.replace(MENU_ELEMENT_SELECTOR_TEMPLATE, "?", this.menuId);

    // Find the menu
    WebElement menu = this.driver.findElement(By.cssSelector(menuSelector));

    // If the menu is not null and is displayed and is enabled
    if (PageUtils.usableElement(menu)) {

        // Within the menu element find the MENU_ROWS
        List<WebElement> menuRows = menu.findElements(MENU_ROWS);

        // Iterate over the menuRows and click the item that matches the required visibility
        for (WebElement menuRow : menuRows) {
            if (visibility.getDisplayValue()
                    .equals(StringUtils.trim(menuRow.findElement(MENU_LABEL).getText()))) {
                menuRow.click();
                this.value = visibility;
                break;
            }
        }
    }
}

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

/**
 * Gets the current page number.
 * 
 * @return the page number
 */
public Integer getPageNumber() {
    return Integer.parseInt(StringUtils.trim(pageNumber.getText()));
}

From source file:org.alfresco.po.share.search.FacetedSearchFacetGroup.java

/**
 * Instantiates a new faceted search facet group.
 *
 * @param facetGroup the facet group//from  w  w w. j a  v a 2 s.com
 */
public FacetedSearchFacetGroup(WebDriver driver, WebElement facetGroup) {
    this.groupLabel = facetGroup.findElement(GROUP_LABEL).getText();
    List<WebElement> facetFilters = facetGroup.findElements(FACET_FILTER);
    this.facets = new ArrayList<FacetedSearchFacet>();
    for (WebElement facetFilter : facetFilters) {
        WebElement link = facetFilter.findElement(FACET_FILTER_LABEL);
        String label = link.getText();
        int hits = Integer.parseInt(StringUtils.trim(facetFilter.findElement(FACET_FILTER_HITS).getText()));
        if (StringUtils.isNotEmpty(label)) {
            this.facets.add(new FacetedSearchFacet(driver, link, label, hits));
        }
    }
}

From source file:org.alfresco.po.share.search.FacetedSearchScopeMenu.java

/**
 * Scope by label.//from  w  w  w  . j  a v  a 2 s .  c o  m
 *
 * @param label the label to be scoped on
 * @return the html page
 */
public HtmlPage scopeByLabel(String label) {
    openMenu();
    boolean found = false;
    for (WebElement option : this.menuElements) {
        if (StringUtils.trim(option.getText()).equalsIgnoreCase(label)) {
            this.currentSelection = StringUtils.trim(option.getText());
            option.click();
            found = true;
            break;
        }
    }
    if (!found) {
        cancelMenu();
    }
    return factoryPage.getPage(this.driver);
}

From source file:org.alfresco.po.share.search.FacetedSearchScopeMenu.java

/**
 * Checks for scope label.// w  w  w. j  av  a  2 s  .  co m
 *
 * @param label the label
 * @return true, if successful
 */
public boolean hasScopeLabel(String label) {
    openMenu();
    boolean found = false;
    for (WebElement option : this.menuElements) {
        if (StringUtils.trim(option.getText()).equalsIgnoreCase(label)) {
            found = true;
            break;
        }
    }
    cancelMenu();
    return found;
}

From source file:org.alfresco.po.share.search.FacetedSearchSort.java

/**
 * Sort by label.//  ww w.  j av  a2  s  . c o  m
 *
 * @param label the label to be sorted on
 * @return the html page
 */
public HtmlPage sortByLabel(String label) {
    openMenu();
    boolean found = false;
    for (WebElement option : this.menuElements) {
        if (StringUtils.trim(option.getText()).equalsIgnoreCase(label)) {
            this.currentSelection = StringUtils.trim(option.getText());
            option.click();
            found = true;
            break;
        }
    }
    if (!found) {
        cancelMenu();
    }
    return factoryPage.getPage(this.driver);
}

From source file:org.alfresco.po.share.search.FacetedSearchView.java

/**
 * Select by label./*from  w  ww  .j a v a  2s . c  o m*/
 *
 * @param label the label to be sorted on
 * @return the html page
 */
public HtmlPage selectViewByLabel(String label) {
    openMenu();
    boolean found = false;
    List<WebElement> menuElements = driver.findElements(VIEW_TYPES);
    for (WebElement option : menuElements) {
        String value = StringUtils.trim(option.getText());
        if (label.equalsIgnoreCase(value)) {
            StringUtils.trim(option.getText());
            option.click();
            found = true;
            break;
        }
    }
    if (!found) {
        cancelMenu();
    }
    return factoryPage.getPage(this.driver);
}

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

/**
 * Instantiates a new select list.//from  w  w  w .java  2  s. com
 * 
 * @param webDrone the web driver
 * @param element the element
 */
public SelectList(WebDriver driver, WebElement element) {
    this.driver = driver;
    this.element = element;
    this.value = StringUtils.trim(element.getText());
    this.control = element.findElement(CONTROL_ELEMENT);
    // The dropdown menu has the same id as the control element with '_dropdown' appended
    this.menuId = this.control.getAttribute("id") + MENU_ELEMENT_SUFFIX;
}

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

/**
 * Select a new select list down value.//from   w w w . j  a v a 2s .  c o  m
 * 
 * @param value the value
 * @param selectExactMatch true if list item with exact matching text is required
 * @return true if the specified value is selected, else false
 */
public boolean selectValue(String value, boolean selectExactMatch) {
    // Click the control to open the menu
    control.click();

    // Compose the selector for the drop down menu
    String menuSelector = StringUtils.replace(MENU_ELEMENT_SELECTOR_TEMPLATE, "?", this.menuId);

    // Find the menu
    WebElement menu = this.driver.findElement(By.cssSelector(menuSelector));

    // If the menu is not null and is displayed and is enabled
    if (PageUtils.usableElement(menu)) {

        // Within the menu element find the MENU_ROWS
        List<WebElement> menuRows = menu.findElements(MENU_ROWS);

        // Iterate over the menuRows and click the item that matches the required visibility
        for (WebElement menuRow : menuRows) {
            String listItem = StringUtils.trim(menuRow.findElement(MENU_LABEL).getText());
            LOGGER.debug("List Item Value: " + listItem);
            if (value.equals(listItem)) {
                menuRow.click();
                this.value = value;
                return true;
            }

            if (!selectExactMatch) {
                if (listItem != null) {
                    if (listItem.startsWith(value)) {
                        menuRow.click();
                        this.value = value;
                        return true;
                    }
                }
            }
        }
    }

    return false;
}