Example usage for org.apache.commons.lang StringUtils trimToNull

List of usage examples for org.apache.commons.lang StringUtils trimToNull

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trimToNull.

Prototype

public static String trimToNull(String str) 

Source Link

Document

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

Usage

From source file:edu.amc.sakai.user.ResourcePropertiesEditStub.java

public ResourcePropertiesEditStub(Properties defaultConfig, Properties configOverrides) {
    super();/*from  w  w w.j  a  va2s. c  om*/
    if (defaultConfig != null && !(defaultConfig.isEmpty())) {
        for (Enumeration i = defaultConfig.propertyNames(); i.hasMoreElements();) {
            String propertyName = (String) i.nextElement();
            String propertyValue = StringUtils.trimToNull((String) defaultConfig.getProperty(propertyName));
            if (propertyValue == null) {
                continue;
            }
            String[] propertyValues = propertyValue.split(";");
            if (propertyValues.length > 1) {
                for (String splitPropertyValue : propertyValues) {
                    super.addPropertyToList(propertyName, splitPropertyValue);
                }
            } else {
                super.addProperty(propertyName, propertyValue);
            }
        }
    }

    if (configOverrides != null && !(configOverrides.isEmpty())) {
        // slightly different... configOverrides are treated as complete
        // overwrites of existing values.
        for (Enumeration i = configOverrides.propertyNames(); i.hasMoreElements();) {
            String propertyName = (String) i.nextElement();
            super.removeProperty(propertyName);
            String propertyValue = StringUtils.trimToNull((String) configOverrides.getProperty(propertyName));
            String[] propertyValues = propertyValue.split(";");
            if (propertyValues.length > 1) {
                for (String splitPropertyValue : propertyValues) {
                    super.addPropertyToList(propertyName, splitPropertyValue);
                }
            } else {
                super.addProperty(propertyName, propertyValue);
            }
        }
    }
}

From source file:com.seyren.core.service.notification.PushoverNotificationService.java

@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts)
        throws NotificationFailedException {
    String pushoverAppApiToken = StringUtils.trimToNull(seyrenConfig.getPushoverAppApiToken());
    String pushoverUserKey = StringUtils.trimToNull(subscription.getTarget());
    String pushoverMsgTitle = formatMsgTitle(check);
    String pushoverMsgBody = "Check details : " + seyrenConfig.getBaseUrl() + "/#/checks/" + check.getId();
    String pushoverMsgPriority = getMsgPriority(check);

    if (pushoverAppApiToken == null) {
        LOGGER.warn("Pushover App API Token must be provided");
        return;/*from www. j av  a 2 s. c  o m*/
    }

    if (pushoverUserKey == null || pushoverUserKey.length() != 30) {
        LOGGER.warn("Invalid or missing Pushover user key");
        return;
    }

    HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
    HttpPost post = new HttpPost("https://api.pushover.net/1/messages.json");

    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("token", pushoverAppApiToken));
        nameValuePairs.add(new BasicNameValuePair("user", pushoverUserKey));
        nameValuePairs.add(new BasicNameValuePair("title", pushoverMsgTitle));
        nameValuePairs.add(new BasicNameValuePair("message", pushoverMsgBody));
        nameValuePairs.add(new BasicNameValuePair("priority", pushoverMsgPriority));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        client.execute(post);
    } catch (IOException e) {
        throw new NotificationFailedException("Sending notification to Pushover failed.", e);
    } finally {
        HttpClientUtils.closeQuietly(client);
    }
}

From source file:com.benasmussen.maven.plugin.i18n.io.AbstractResourceWriter.java

public String getFilename(ResourceEntry resourceEntry, String locale) {
    StringBuilder sb = new StringBuilder(resourceEntry.getName());

    if (StringUtils.trimToNull(locale) != null && !ResourceEntry.DEFAULT_LOCALE.equalsIgnoreCase(locale)) {
        sb.append("_");
        sb.append(locale);//from   w w w . j a  v  a  2  s. co  m
    }
    sb.append(getFilenameSuffix());

    return sb.toString();
}

From source file:com.jive.myco.seyren.core.service.notification.HubotNotificationService.java

@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts)
        throws NotificationFailedException {
    String hubotUrl = StringUtils.trimToNull(seyrenConfig.getHubotUrl());

    if (hubotUrl == null) {
        LOGGER.warn("Hubot URL needs to be set before sending notifications to Hubot");
        return;//from w  ww . j  a va 2s  .co m
    }

    Map<String, Object> body = new HashMap<String, Object>();
    body.put("seyrenUrl", seyrenConfig.getBaseUrl());
    body.put("check", check);
    body.put("subscription", subscription);
    body.put("alerts", alerts);
    body.put("rooms", subscription.getTarget().split(","));

    HttpClient client = HttpClientBuilder.create().build();

    HttpPost post = new HttpPost(hubotUrl + "/seyren/alert");
    try {
        HttpEntity entity = new StringEntity(MAPPER.writeValueAsString(body), ContentType.APPLICATION_JSON);
        post.setEntity(entity);
        client.execute(post);
    } catch (IOException e) {
        throw new NotificationFailedException("Sending notification to Hubot at " + hubotUrl + " failed.", e);
    } finally {
        HttpClientUtils.closeQuietly(client);
    }
}

From source file:com.bluexml.xforms.generator.forms.rendered.RenderedLine.java

@Override
public void addRendered(Rendered rendered, Renderable renderable) {
    super.addRendered(rendered, renderable);
    Element renderedElement = rendered.getXformsElement();
    if (renderedElement != null) {
        Element lineElement = XFormsGenerator.createElement("div", XFormsGenerator.NAMESPACE_XHTML);

        String style;//  w  ww. j ava2 s  . c  o  m
        if (rendered.isReturnToLine()) {
            style = "xformstdclear";
        } else {
            style = "xformstdleft";
        }
        String childStyle = StringUtils.trimToNull(renderable.getDivStyle());
        if (childStyle != null) {
            style += " " + childStyle;
        }
        lineElement.setAttribute("class", style);

        lineElement.addContent(renderedElement);
        xformsElement.addContent(lineElement);
    }
}

From source file:net.sf.firemox.zone.ZoneConfiguration.java

/**
 * Create a new instance of this class from a steam.
 * /*from  w ww .j a va2  s  .  com*/
 * @param dbStream
 *          the stream containing the configuration.
 * @param zoneId
 *          the zone id of this configuration.
 * @throws IOException
 *           If some other I/O error occurs
 */
ZoneConfiguration(InputStream dbStream, int zoneId) throws IOException {
    this.zoneId = zoneId;
    zoneName = MToolKit.readString(dbStream);
    layoutClass = StringUtils.trimToNull(MToolKit.readString(dbStream));
    layoutConstraintYou = MToolKit.readString(dbStream);
    layoutConstraintOpponent = MToolKit.readString(dbStream);
}

From source file:com.jive.myco.seyren.core.service.notification.PushoverNotificationService.java

@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts)
        throws NotificationFailedException {
    String pushoverAppApiToken = StringUtils.trimToNull(seyrenConfig.getPushoverAppApiToken());
    String pushoverUserKey = StringUtils.trimToNull(subscription.getTarget());
    String pushoverMsgTitle = formatMsgTitle(check);
    String pushoverMsgBody = "Check details : " + seyrenConfig.getBaseUrl() + "/#/checks/" + check.getId();
    String pushoverMsgPriority = getMsgPriority(check);

    if (pushoverAppApiToken == null) {
        LOGGER.warn("Pushover App API Token must be provided");
        return;/*from  ww  w  .j ava  2s. c o m*/
    }

    if (pushoverUserKey == null || pushoverUserKey.length() != 30) {
        LOGGER.warn("Invalid or missing Pushover user key");
        return;
    }

    HttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost("https://api.pushover.net/1/messages.json");

    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("token", pushoverAppApiToken));
        nameValuePairs.add(new BasicNameValuePair("user", pushoverUserKey));
        nameValuePairs.add(new BasicNameValuePair("title", pushoverMsgTitle));
        nameValuePairs.add(new BasicNameValuePair("message", pushoverMsgBody));
        nameValuePairs.add(new BasicNameValuePair("priority", pushoverMsgPriority));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        client.execute(post);
    } catch (IOException e) {
        throw new NotificationFailedException("Sending notification to Pushover failed.", e);
    } finally {
        HttpClientUtils.closeQuietly(client);
    }
}

From source file:edu.wisc.nexus.auth.rut.RemoteUserTestingFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    final String remoteUser = StringUtils.trimToNull(FileUtils.readFileToString(this.remoteUserFile));

    if (remoteUser != null) {
        request = new RemoteUserHttpServletRequestWrapper((HttpServletRequest) request, remoteUser);
    }/*ww w  . java 2s  . c  om*/

    chain.doFilter(request, response);
}

From source file:com.bluexml.side.util.dependencies.ModuleConstraint.java

public ModuleConstraint(String id, String classifier, String tech_version, String moduleType,
        String versionNumMin, String versionNumMax) {
    setGroupAndArtifactId(id);/* w  w w  .  j av  a  2  s  .c  o  m*/
    this.tech_version = tech_version;
    this.moduleType = moduleType;
    this.classifier = classifier;
    if (StringUtils.trimToNull(versionNumMin) != null) {
        this.versionMin = new ModuleVersion(versionNumMin);
    }
    if (StringUtils.trimToNull(versionNumMax) != null) {
        this.versionMax = new ModuleVersion(versionNumMax);
    }
}

From source file:mitm.djigzo.web.validators.URIValidator.java

@Override
public void validate(Field field, String type, MessageFormatter formatter, String value)
        throws ValidationException {
    value = StringUtils.trimToNull(value);

    if (value != null) {
        value = value.trim();/*from  w  ww .  j  a v  a 2 s  .c om*/

        URIType uriType = URIUtils.URIType.valueOf(StringUtils.defaultString(type).toUpperCase());

        if (uriType == null) {
            uriType = URIType.FULL;
        }

        if (!URIUtils.isValidURI(value, uriType)) {
            throw new ValidationException(formatter.format(field.getLabel(), type));
        }
    }
}