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

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

Introduction

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

Prototype

public static String trimToEmpty(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .

Usage

From source file:de.jfachwert.post.Ort.java

private static String[] split(String name) {
    String input = StringUtils.trimToEmpty(name);
    String[] splitted = new String[] { "", input };
    if (input.contains(" ")) {
        try {/*from w w  w . ja va  2s  .  c  o m*/
            String plz = PLZ.validate(StringUtils.substringBefore(input, " "));
            splitted[0] = plz;
            splitted[1] = StringUtils.substringAfter(input, " ").trim();
        } catch (ValidationException ex) {
            LOG.log(Level.FINE, "no PLZ inside '" + name + "' found:", ex);
        }
    }
    return splitted;
}

From source file:ke.co.tawi.babblesms.server.beans.account.Account.java

/**
 * 
 * @param mobile 
 */
public void setMobile(String mobile) {
    this.mobile = StringUtils.trimToEmpty(mobile);
}

From source file:ch.elca.training.service.impl.ConfigurationProjectServiceImpl.java

public List<Project> findByQuery(ProjectQuery query) {
    List<Project> projects = new ArrayList<Project>();
    for (Project project : getAllProjects()) {
        String criteria = StringUtils.trimToEmpty(query.getMatchingText());
        if (StringUtils.containsIgnoreCase(project.getName(), criteria)
                || StringUtils.containsIgnoreCase(project.getLeader().getVisa(), criteria)
                || StringUtils.containsIgnoreCase(project.getGroup().getLeader().getVisa(), criteria)
                || StringUtils.containsIgnoreCase("" + project.getNumber(), criteria)) {
            projects.add(project);//w  ww  .j av a  2 s  . c o m
        }
    }

    return projects;
}

From source file:de.jfachwert.formular.Familienstand.java

/**
 * Liefert zu einem Schluessel den entsprechende Familienstand. Falls
 * nichts gefunden wird, wird NICHT_BEKANNT zurueckgeliefert.
 *
 * @param schluessel z.B. "LE"/*w  w w  .j ava2s .  co  m*/
 * @return Familienstand, z.B. LEDIG
 */
public static Familienstand of(String schluessel) {
    String normalized = StringUtils.trimToEmpty(schluessel);
    if (normalized.length() == 2) {
        return findSchluessel(normalized);
    } else {
        return findText(schluessel);
    }
}

From source file:com.esri.geoportal.commons.ags.client.AgsClient.java

/**
 * Generates token.//from   ww  w. j  a va2  s.  c o m
 *
 * @param minutes expiration in minutes.
 * @param credentials credentials.
 * @return token response
 * @throws URISyntaxException if invalid URL
 * @throws IOException if accessing token fails
 */
public TokenResponse generateToken(int minutes, SimpleCredentials credentials)
        throws URISyntaxException, IOException {
    HttpPost post = new HttpPost(rootUrl.toURI().resolve("tokens/generateToken"));
    HashMap<String, String> params = new HashMap<>();
    params.put("f", "json");
    if (credentials != null) {
        params.put("username", StringUtils.trimToEmpty(credentials.getUserName()));
        params.put("password", StringUtils.trimToEmpty(credentials.getPassword()));
    }
    params.put("client", "ip");
    params.put("ip", InetAddress.getLocalHost().getHostAddress());
    params.put("expiration", Integer.toString(minutes));
    HttpEntity entity = new UrlEncodedFormEntity(params.entrySet().stream()
            .map(e -> new BasicNameValuePair(e.getKey(), e.getValue())).collect(Collectors.toList()));
    post.setEntity(entity);

    try (CloseableHttpResponse httpResponse = httpClient.execute(post);
            InputStream contentStream = httpResponse.getEntity().getContent();) {
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(),
                    httpResponse.getStatusLine().getReasonPhrase());
        }
        String responseContent = IOUtils.toString(contentStream, "UTF-8");
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return mapper.readValue(responseContent, TokenResponse.class);
    }
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_browser.search.SignSearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate() " + this.hashCode());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_activity);
    if (null != savedInstanceState) {
        this.query = savedInstanceState.getString(QUERY);
    } else {/*from w w  w.j a  v  a2  s . co m*/
        final Intent intent = getIntent();
        this.query = StringUtils
                .trimToEmpty(StringUtils.stripToEmpty(intent.getStringExtra(SearchManager.QUERY)));
        Validate.notNull(this.query, "The query supplied to this activity is null!");
    }
    setupRecyclerView();
    setupSupportActionBar();
    this.signSearchTask = new SearchSignsTask(this);
    this.signSearchTask.execute(this.query);
}

From source file:com.nesscomputing.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent.java

protected void parseApplicationName() {
    int i = this.message.indexOf(' ');

    if (i > -1) {
        this.applicationName = StringUtils.trimToEmpty(this.message.substring(0, i));
        this.message = this.message.substring(i + 1);
    }// w  w  w  .j  a  v  a  2s .c  om

    if (SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(this.applicationName)) {
        this.applicationName = null;
    }
}

From source file:com.esri.geoportal.commons.csw.client.impl.ProfilesLoader.java

/**
 * Loads profiles./*w ww .  j av a  2 s . co  m*/
 * @return profiles
 * @throws IOException if loading profiles from configuration fails
 * @throws ParserConfigurationException if unable to obtain XML parser
 * @throws SAXException if unable to parse XML document
 * @throws XPathExpressionException if invalid XPath expression
 */
public Profiles load()
        throws IOException, ParserConfigurationException, SAXException, XPathExpressionException {
    LOG.info(String.format("Loading CSW profiles"));
    Profiles profiles = new Profiles();
    try (InputStream profilesXml = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream(CONFIG_FILE_PATH);) {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();

        Document profilesDom = builder.parse(new InputSource(profilesXml));

        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPath xpath = xPathfactory.newXPath();

        NodeList profilesNodeList = (NodeList) xpath.evaluate("/CSWProfiles/Profile", profilesDom,
                XPathConstants.NODESET);
        for (int pidx = 0; pidx < profilesNodeList.getLength(); pidx++) {
            Node profileNode = profilesNodeList.item(pidx);
            String id = StringUtils
                    .trimToEmpty((String) xpath.evaluate("ID", profileNode, XPathConstants.STRING));
            String name = StringUtils
                    .trimToEmpty((String) xpath.evaluate("Name", profileNode, XPathConstants.STRING));
            String namespace = StringUtils
                    .trimToEmpty((String) xpath.evaluate("CswNamespace", profileNode, XPathConstants.STRING));
            String description = StringUtils
                    .trimToEmpty((String) xpath.evaluate("Description", profileNode, XPathConstants.STRING));

            String getRecordsReqXslt = StringUtils.trimToEmpty((String) xpath
                    .evaluate("GetRecords/XSLTransformations/Request", profileNode, XPathConstants.STRING));
            String getRecordsRspXslt = StringUtils.trimToEmpty((String) xpath
                    .evaluate("GetRecords/XSLTransformations/Response", profileNode, XPathConstants.STRING));

            String getRecordByIdReqKVP = StringUtils.trimToEmpty(
                    (String) xpath.evaluate("GetRecordByID/RequestKVPs", profileNode, XPathConstants.STRING));
            String getRecordByIdRspXslt = StringUtils.trimToEmpty((String) xpath
                    .evaluate("GetRecordByID/XSLTransformations/Response", profileNode, XPathConstants.STRING));

            Profile prof = new Profile();
            prof.setId(id);
            prof.setName(name);
            prof.setDescription(description);
            prof.setGetRecordsReqXslt(getRecordsReqXslt);
            prof.setGetRecordsRspXslt(getRecordsRspXslt);
            prof.setKvp(getRecordByIdReqKVP);
            prof.setGetRecordByIdRspXslt(getRecordByIdRspXslt);

            profiles.add(prof);
        }
    }
    LOG.info(String.format("CSW profiles loaded."));
    return profiles;
}

From source file:ke.co.tawi.babblesms.server.beans.account.Account.java

/**
 * 
 * @param email 
 */
public void setEmail(String email) {
    this.email = StringUtils.trimToEmpty(email);
}

From source file:com.blackducksoftware.integration.hub.detect.detector.pip.PipInspectorTreeParser.java

public Optional<PipParseResult> parse(final List<String> pipInspectorOutputAsList, final String sourcePath) {
    PipParseResult parseResult = null;/*from   ww  w .j av  a 2s. c  om*/

    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final DependencyHistory history = new DependencyHistory();
    Dependency project = null;

    for (final String line : pipInspectorOutputAsList) {
        final String trimmedLine = StringUtils.trimToEmpty(line);
        if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR)
                || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX)
                || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX)
                || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
            parseErrorsFromLine(trimmedLine);
            continue;
        }

        final Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
        final int lineLevel = getLineLevel(trimmedLine);
        try {
            history.clearDependenciesDeeperThan(lineLevel);
        } catch (final IllegalStateException e) {
            logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
        }

        if (project == null) {
            project = currentDependency;
        } else if (project.equals(history.getLastDependency())) {
            graph.addChildToRoot(currentDependency);
        } else if (history.isEmpty()) {
            graph.addChildToRoot(currentDependency);
        } else {
            graph.addChildWithParents(currentDependency, history.getLastDependency());
        }

        history.add(currentDependency);
    }

    if (project != null) {
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP,
                sourcePath, project.externalId, graph).build();
        parseResult = new PipParseResult(project.name, project.version, codeLocation);
    }

    return Optional.ofNullable(parseResult);
}