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.apache.nifi.minifi.bootstrap.configuration.notifiers.util.TestRestChangeNotifierCommon.java

@Test
public void testFileUpload() throws Exception {
    assertEquals(1, restChangeNotifier.getChangeListeners().size());
    Request request = new Request.Builder().url(url).post(RequestBody.create(MEDIA_TYPE_MARKDOWN, testString))
            .addHeader("charset", "UTF-8").build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful())
        throw new IOException("Unexpected code " + response);

    Headers responseHeaders = response.headers();
    for (int i = 0; i < responseHeaders.size(); i++) {
        System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
    }//from  w  ww .  j av a2  s .  c o  m

    assertEquals(
            "The result of notifying listeners:\nMockChangeListener successfully handled the configuration change\n",
            response.body().string());

    assertEquals(testString, StringUtils.trim(mockChangeListener.getConfFile()));
}

From source file:org.apache.pulsar.io.twitter.TwitterFireHoseConfig.java

public List<Long> getFollowings() {
    if (StringUtils.isBlank(followings)) {
        return Collections.emptyList();
    }/*from  w  w w.j  ava  2  s .co  m*/

    List<Long> result = new ArrayList<Long>();

    for (String s : StringUtils.split(followings, ",")) {
        try {
            result.add(Long.parseLong(StringUtils.trim(s)));
        } catch (NumberFormatException nfEx) {
            // Ignore these
        }
    }

    return CollectionUtils.isEmpty(result) ? Collections.emptyList() : result;
}

From source file:org.apache.sling.testing.mock.osgi.OsgiMetadataUtil.java

private static Map<String, Object> getProperties(Class clazz, Document metadata) {
    Map<String, Object> props = new HashMap<String, Object>();
    String query = getComponentXPathQuery(clazz) + "/property[@name!='' and @value!='']";
    NodeList nodes = queryNodes(metadata, query);
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            String name = getAttributeValue(node, "name");
            String value = getAttributeValue(node, "value");
            String type = getAttributeValue(node, "type");
            if (StringUtils.equals("Integer", type)) {
                props.put(name, Integer.parseInt(value));
            } else if (StringUtils.equals("Long", type)) {
                props.put(name, Long.parseLong(value));
            } else if (StringUtils.equals("Boolean", type)) {
                props.put(name, Boolean.parseBoolean(value));
            } else {
                props.put(name, value);/*from   w w w  . java2 s .com*/
            }
        }
    }
    query = getComponentXPathQuery(clazz) + "/property[@name!='' and text()!='']";
    nodes = queryNodes(metadata, query);
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            String name = getAttributeValue(node, "name");
            String[] value = StringUtils.split(StringUtils.trim(node.getTextContent()), "\n\r");
            for (int j = 0; j < value.length; j++) {
                value[j] = StringUtils.trim(value[j]);
            }
            props.put(name, value);
        }
    }
    return props;
}

From source file:org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner.java

/**
 * Find all node type definition classpath paths by searching all MANIFEST.MF files in the classpath and reading
 * the paths from the "Sling-Nodetypes" entry.
 * The order of the paths from each entry is preserved, but the overall order when multiple bundles define such an entry
 * is not deterministic and may not be correct according to the dependencies between the node type definitions.
 * @return List of node type definition class paths
 *//*  www . j  a  va 2 s.  com*/
private static List<String> findeNodeTypeDefinitions() {
    List<String> nodeTypeDefinitions = new ArrayList<String>();
    try {
        Enumeration<URL> resEnum = NodeTypeDefinitionScanner.class.getClassLoader()
                .getResources(JarFile.MANIFEST_NAME);
        while (resEnum.hasMoreElements()) {
            try {
                URL url = (URL) resEnum.nextElement();
                InputStream is = url.openStream();
                if (is != null) {
                    try {
                        Manifest manifest = new Manifest(is);
                        Attributes mainAttribs = manifest.getMainAttributes();
                        String nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes");
                        String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ",");
                        if (nodeTypeDefinitionArray != null) {
                            for (String nodeTypeDefinition : nodeTypeDefinitionArray) {
                                if (!StringUtils.isBlank(nodeTypeDefinition)) {
                                    nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition));
                                }
                            }
                        }
                    } finally {
                        is.close();
                    }
                }
            } catch (Throwable ex) {
                log.warn("Unable to read JAR manifest.", ex);
            }
        }
    } catch (IOException ex2) {
        log.warn("Unable to read JAR manifests.", ex2);
    }
    return nodeTypeDefinitions;
}

From source file:org.apache.syncope.installer.validators.ArchetypeValidator.java

@Override
public Status validateData(final InstallData installData) {
    final String mavenDir = StringUtils.trim(installData.getVariable("mvn.directory"));
    final String mavenGroupId = StringUtils.trim(installData.getVariable("mvn.groupid"));
    final String mavenArtifactId = StringUtils.trim(installData.getVariable("mvn.artifactid"));
    final String mavenSecretKey = StringUtils.trim(installData.getVariable("mvn.secretkey"));
    final String mavenAnonymousKey = StringUtils.trim(installData.getVariable("mvn.anonymous.key"));
    final String mavenJwsKey = StringUtils.trim(installData.getVariable("mvn.jws.key"));
    final String mavenAdminPassword = StringUtils.trim(installData.getVariable("mvn.syncope.admin.password"));
    final String mavenLogDirectory = StringUtils.trim(installData.getVariable("mvn.log.directory"));
    final String mavenBundleDirectory = StringUtils.trim(installData.getVariable("mvn.bundle.directory"));

    boolean verified = true;
    error = new StringBuilder("Required fields:\n");
    if (StringUtils.isBlank(mavenDir)) {
        error.append("Maven home directory\n");
        verified = false;/*  ww  w  .  j  a v a  2  s  .c o m*/
    } else if (!new File(mavenDir + "/bin/mvn").exists()) {
        error.append("Maven home directory not valid, check it please...\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenGroupId)) {
        error.append("GroupID\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenArtifactId)) {
        error.append("ArtifactID\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenSecretKey)) {
        error.append("SecretKey\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenAnonymousKey)) {
        error.append("AnonymousKey\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenJwsKey)) {
        error.append("JwsKey\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenAdminPassword)) {
        error.append("AdminPassword\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenLogDirectory)) {
        error.append("Logs directory\n");
        verified = false;
    }
    if (StringUtils.isBlank(mavenBundleDirectory)) {
        error.append("Bundles directory\n");
        verified = false;
    }

    return verified ? Status.OK : Status.ERROR;
}

From source file:org.apache.zeppelin.hopshive.HopsHiveInterpreter.java

protected ArrayList<String> splitSqlQueries(String sql) {
    ArrayList<String> queries = new ArrayList<>();
    StringBuilder query = new StringBuilder();
    char character;

    Boolean multiLineComment = false;
    Boolean singleLineComment = false;
    Boolean quoteString = false;/*from   w  w w  .j  av  a2s . c  o  m*/
    Boolean doubleQuoteString = false;

    for (int item = 0; item < sql.length(); item++) {
        character = sql.charAt(item);

        if ((singleLineComment && (character == '\n' || item == sql.length() - 1))
                || (multiLineComment && character == '/' && sql.charAt(item - 1) == '*')) {
            singleLineComment = false;
            multiLineComment = false;
            if (item == sql.length() - 1 && query.length() > 0) {
                queries.add(StringUtils.trim(query.toString()));
            }
            continue;
        }

        if (singleLineComment || multiLineComment) {
            continue;
        }

        if (character == '\'') {
            if (quoteString) {
                quoteString = false;
            } else if (!doubleQuoteString) {
                quoteString = true;
            }
        }

        if (character == '"') {
            if (doubleQuoteString && item > 0) {
                doubleQuoteString = false;
            } else if (!quoteString) {
                doubleQuoteString = true;
            }
        }

        if (!quoteString && !doubleQuoteString && !multiLineComment && !singleLineComment
                && sql.length() > item + 1) {
            if (character == '-' && sql.charAt(item + 1) == '-') {
                singleLineComment = true;
                continue;
            }

            if (character == '/' && sql.charAt(item + 1) == '*') {
                multiLineComment = true;
                continue;
            }
        }

        if (character == ';' && !quoteString && !doubleQuoteString) {
            queries.add(StringUtils.trim(query.toString()));
            query = new StringBuilder();
        } else if (item == sql.length() - 1) {
            query.append(character);
            queries.add(StringUtils.trim(query.toString()));
        } else {
            query.append(character);
        }
    }

    return queries;
}

From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java

@Override
public EvidenceElement getEvidenceElement(String evidenceCode, String evidenceValue) {
    return evidenceElementDataService.getEvidenceElement(StringUtils.trim(evidenceValue),
            getEvidence(evidenceCode));//from  w ww. j ava  2 s .com
}

From source file:org.asqatasun.rules.accessiweb22.Aw22Rule13012.java

/**
 * @param element/*from   www .  j av a 2  s  .c om*/
 * @return whether the given element is an immediate redirection
 */
private boolean isImmediateRedirection(Element element) {
    String contentAttributeContent = element.attr(CONTENT_ATTR);
    String[] contentAttributeValues = contentAttributeContent.split(SEMI_COLON_CHAR);
    return !(contentAttributeValues != null && contentAttributeValues.length == 2
            && Integer.valueOf(StringUtils.trim(contentAttributeValues[0])) > 0
            && contentAttributeValues[1].toLowerCase().startsWith(URL_STR));
}

From source file:org.asqatasun.rules.elementchecker.lang.detector.LanguageDetectionResult.java

private void computeNumberOfWords(String testedText) {
    String trimmedText = StringUtils.trim(testedText);
    if (StringUtils.isBlank(trimmedText)) {
        return;//from   ww w .  j av a  2  s .  c  om
    }
    numberOfWords = trimmedText.split("\\s+").length;
}

From source file:org.asqatasun.rules.elementchecker.lang.LangChecker.java

/**
 * /*from w  w  w  .  j  av  a2s .co  m*/
 * @param extractedText
 * @return 
 */
protected boolean isTextTestable(String extractedText) {
    if (StringUtils.isBlank(extractedText)) {
        return false;
    }
    String textToTest = StringUtils.trim(extractedText);
    Matcher m = nonAlphanumericPattern.matcher(textToTest);
    return !m.matches() && !GenericValidator.isEmail(textToTest) && !GenericValidator.isUrl(textToTest);
}