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

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

Introduction

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

Prototype

public static String normalizeSpace(final String str) 

Source Link

Document

<p> Similar to <a href="http://www.w3.org/TR/xpath/#function-normalize-space">http://www.w3.org/TR/xpath/#function-normalize -space</a> </p> <p> The function returns the argument string with whitespace normalized by using <code> #trim(String) </code> to remove leading and trailing whitespace and then replacing sequences of whitespace characters by a single space.

Usage

From source file:org.structr.core.function.Functions.java

public static String cleanString(final Object input) {

    if (input == null) {

        return "";
    }/*from w  w  w  .  java  2s.  com*/

    String normalized = Normalizer.normalize(input.toString(), Normalizer.Form.NFD).replaceAll("\\<", "")
            .replaceAll("\\>", "").replaceAll("\\.", "").replaceAll("\\'", "-").replaceAll("\\?", "")
            .replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("\\{", "").replaceAll("\\}", "")
            .replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\+", "-").replaceAll("/", "-")
            .replaceAll("", "-").replaceAll("\\\\", "-").replaceAll("\\|", "-").replaceAll("'", "-")
            .replaceAll("!", "").replaceAll(",", "").replaceAll("-", " ").replaceAll("_", " ")
            .replaceAll("`", "-");

    String result = normalized.replaceAll("-", " ");
    result = StringUtils.normalizeSpace(result.toLowerCase());
    result = result.replaceAll("[^\\p{ASCII}]", "").replaceAll("\\p{P}", "-").replaceAll("\\-(\\s+\\-)+", "-");
    result = result.replaceAll(" ", "-");

    return result;
}

From source file:org.yamj.core.api.model.builder.SqlScalars.java

/**
 * Get the SQL as a string
 *
 * @return
 */
public String getSql() {
    return StringUtils.normalizeSpace(sql.toString());
}

From source file:org.yamj.core.tools.MetadataTools.java

/**
 * Convert a string to date to//  ww w.j  a va 2 s .c  o  m
 *
 * @param dateToParse
 * @return
 */
public static Date parseToDate(String dateToParse) {
    Date parsedDate = null;

    String parseDate = StringUtils.normalizeSpace(dateToParse);
    if (StringUtils.isNotBlank(parseDate)) {
        try {
            DateTime dateTime;
            if (parseDate.length() == 4 && StringUtils.isNumeric(parseDate)) {
                // assume just the year an append "-01-01" to the end
                dateTime = new DateTime(parseDate + "-01-01");
            } else {
                // look for the date as "dd MMMM yyyy (Country)" and remove the country
                Matcher m = DATE_COUNTRY.matcher(dateToParse);
                if (m.find()) {
                    parseDate = m.group(1);
                }
                dateTime = new DateTime(parseDate);
            }
            parsedDate = dateTime.toDate();
        } catch (Exception ex) {
            LOG.debug("Failed to parse date '{}', error: {}", dateToParse, ex.getMessage());
            LOG.trace("Error", ex);
        }
    }

    return parsedDate;
}

From source file:sonicScream.controllers.CategoryTabController.java

public void revertSound() {
    TreeItem<String> selectedNode = (TreeItem<String>) CategoryTabTreeView.getSelectionModel()
            .getSelectedItem();//from w w  w.  ja  v a2  s  .c  o  m
    if (!selectedNode.isLeaf()) {
        return; //Shouldn't even be possible, but just in case
    }
    //We use this later to find the correct node to select after a reversion.
    int nodeParentIndex = selectedNode.getParent().getParent().getChildren().indexOf(selectedNode.getParent());

    Script activeScript = (Script) CategoryTabComboBox.getValue();

    //get the index of the selected node relative to its parent.
    int selectedWaveIndex = selectedNode.getParent().getChildren().indexOf(selectedNode);
    VPKFileService vpkService = (VPKFileService) ServiceLocator.getService(VPKFileService.class);
    Script vpkScript = new Script(vpkService.getVPKEntry(activeScript.getVPKPath()), _category);
    List<TreeItem<String>> vpkWaves = TreeUtils.getWaveStrings(vpkScript.getRootNode()).orElse(null);
    if (vpkWaves != null && vpkWaves.size() > selectedWaveIndex) {
        TreeItem<String> selectedNodeInRoot = TreeUtils.getWaveStrings(activeScript.getRootNode()).get()
                .get(selectedWaveIndex);
        TreeItem<String> selectedNodeInVPKRoot = vpkWaves.get(selectedWaveIndex);
        String vpkNodeString = StringUtils.normalizeSpace((selectedNodeInVPKRoot.getValue()));
        selectedNodeInRoot.setValue(vpkNodeString);
        selectedNode.setValue(StringParsing.rootSoundToSimpleSound(vpkNodeString));
    }
    //if the index does NOT exist, remove the index from the root node, and
    //then do all the updating
    else {
        TreeItem<String> selectedNodeInRoot = TreeUtils.getWaveStrings(activeScript.getRootNode()).get()
                .get(selectedWaveIndex);
        selectedNodeInRoot.getParent().getChildren().remove(selectedNodeInRoot);
        selectedNode.getParent().getChildren().remove(selectedNode);
        //TODO: Delete the parent if it no longer has any children.
    }
}

From source file:sonicScream.utilities.ScriptParser.java

private static void parseLine(String line) throws NullPointerException {
    //System.out.println(line); //Enable this to write out scripts as they're parsed. Warning: Causes massive slowdown
    if (StringUtils.isBlank(line)) {
        return;//w  ww  .j a v  a 2  s  .  c  om
    }
    //Need this if we want braces commented out too
    if (line.trim().startsWith("//")) {
        try {
            TreeItem<String> newNode = new TreeItem<>(StringUtils.normalizeSpace(line));
            _currentNode = newNode;
            if (_currentNode != null) {
                _currentParent.getChildren().add(newNode);
            }
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
    } else if (line.contains("{")) {
        _currentParent = _currentNode;
    } else if (line.contains("}")) {
        _currentParent = _currentParent.getParent();
        if (_currentParent == null) {
            _currentParent = _rootItem;
        }
    } else {
        try {
            TreeItem<String> newNode = new TreeItem<>(StringUtils.normalizeSpace(line));
            _currentNode = newNode;
            if (_currentNode != null) {
                _currentParent.getChildren().add(newNode);
            }
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
    }
}