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:net.leegorous.jsc.JSC.java

public List normalizePath(String path) {
    List result = null;//from  w  w w .ja  v  a 2 s  .c o m
    if (path != null) {
        result = new ArrayList();
        path = path.replaceAll("[\\r\\n]", ";");
        String[] li = StringUtils.split(path, " ;");
        for (int i = 0; i < li.length; i++) {
            String str = StringUtils.trimToNull(li[i]);
            if (str != null)
                result.add(str);
        }
    }
    return result;
}

From source file:ch.entwine.weblounge.kernel.mail.SmtpService.java

/**
 * Callback from the OSGi <code>ConfigurationAdmin</code> on configuration
 * changes.//from  ww w .  j a va2s  . c  o m
 * 
 * @param properties
 *          the configuration properties
 * @throws ConfigurationException
 *           if configuration fails
 */
@Override
public void updated(Dictionary properties) throws ConfigurationException {

    // Read the mail server properties
    mailProperties.clear();

    // The mail host is mandatory
    String propName = getConfigurationKey(OPT_SMTP_HOST);
    mailHost = StringUtils.trimToNull((String) properties.get(propName));
    if (mailHost == null) {
        mailHost = DEFAULT_SMTP_HOST;
        logger.debug("Mail server defaults to '{}'", mailHost);
    } else {
        logger.debug("Mail host is {}", mailHost);
    }
    mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_HOST), mailHost);

    // Mail port
    propName = getConfigurationKey(OPT_SMTP_PORT);
    String mailPort = StringUtils.trimToNull((String) properties.get(propName));
    if (mailPort == null) {
        mailPort = DEFAULT_SMTP_PORT;
        logger.debug("Mail server port defaults to '{}'", mailPort);
    } else {
        logger.debug("Mail server port is '{}'", mailPort);
    }
    mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_PORT), mailPort);

    // TSL over SMTP support
    propName = getConfigurationKey(OPT_SMTP_TLS);
    String smtpStartTLSStr = StringUtils.trimToNull((String) properties.get(propName));
    boolean smtpStartTLS = Boolean.parseBoolean(smtpStartTLSStr);
    if (smtpStartTLS) {
        mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_TLS) + ".enable", "true");
        logger.debug("TLS over SMTP is enabled");
    } else {
        logger.debug("TLS over SMTP is disabled");
    }

    // Mail user
    propName = getConfigurationKey(OPT_SMTP_USER);
    mailUser = StringUtils.trimToNull((String) properties.get(propName));
    if (mailUser != null) {
        mailProperties.put(getJavaMailKey(OPT_SMTP_USER), mailUser);
        logger.debug("Mail user is '{}'", mailUser);
    } else {
        logger.debug("Sending mails to {} without authentication", mailHost);
    }

    // Mail password
    propName = getConfigurationKey(OPT_SMTP_PASSWORD);
    mailPassword = StringUtils.trimToNull((String) properties.get(propName));
    if (mailPassword != null) {
        mailProperties.put(getJavaMailKey(OPT_SMTP_PASSWORD), mailPassword);
        logger.debug("Mail password set");
    }

    // Mail sender
    propName = getConfigurationKey(OPT_SMTP_FROM);
    String mailFrom = StringUtils.trimToNull((String) properties.get(propName));
    if (mailFrom == null) {
        try {
            mailFrom = "weblounge@" + InetAddress.getLocalHost().getCanonicalHostName();
            logger.info("Mail sender defaults to '{}'", mailFrom);
        } catch (UnknownHostException e) {
            logger.error("Error retreiving localhost hostname used to create default sender address: {}",
                    e.getMessage());
            throw new ConfigurationException(OPT_SMTP_FROM,
                    "Error retreiving localhost hostname used to create default sender address");
        }
    } else {
        logger.debug("Mail sender is '{}'", mailFrom);
    }
    mailProperties.put(getJavaMailKey(OPT_SMTP_FROM), mailFrom);

    // Authentication
    propName = getConfigurationKey(OPT_SMTP_AUTH);
    mailProperties.put(getJavaMailSmtpKey(OPT_SMTP_AUTH), Boolean.toString(mailUser != null));

    // Mail debugging
    propName = getConfigurationKey(OPT_SMTP_DEBUG);
    String mailDebug = StringUtils.trimToNull((String) properties.get(propName));
    if (mailDebug != null) {
        boolean mailDebugEnabled = Boolean.parseBoolean(mailDebug);
        mailProperties.put(getJavaMailKey(OPT_SMTP_DEBUG), Boolean.toString(mailDebugEnabled));
        logger.info("Mail debugging is {}", mailDebugEnabled ? "enabled" : "disabled");
    }

    defaultMailSession = null;
    logger.info("Mail service configured with {}", mailHost);

    // Test
    propName = getConfigurationKey(OPT_SMTP_TEST);
    String mailTest = StringUtils.trimToNull((String) properties.get(propName));
    if (mailTest != null) {
        try {
            sendTestMessage(mailTest);
        } catch (MessagingException e) {
            logger.error("Error sending test message to " + mailTest + ": " + e.getMessage());
            throw new ConfigurationException(OPT_SMTP_PREFIX + MAIL_TRANSPORT + OPT_SMTP_HOST,
                    "Failed to send test message to " + mailTest);
        }
    }
}

From source file:com.google.code.configprocessor.processing.ModifyAction.java

public String getReplace() {
    return StringUtils.trimToNull(replace);
}

From source file:com.opengamma.web.config.WebConfigsResource.java

@SuppressWarnings("unchecked")
private FlexiBean search(PagingRequest request, ConfigSearchSortOrder so, String name, String typeName,
        List<String> configIdStrs, UriInfo uriInfo) {
    FlexiBean out = createRootData();/*from w  w w  .ja  v a 2 s .c o m*/

    @SuppressWarnings("rawtypes")
    ConfigSearchRequest searchRequest = new ConfigSearchRequest();
    typeName = StringUtils.trimToNull(typeName);
    if (typeName != null) {
        Class<?> typeClazz = data().getTypeMap().get(typeName);
        searchRequest.setType(typeClazz);
    } else {
        searchRequest.setType(Object.class);
    }
    searchRequest.setPagingRequest(request);
    searchRequest.setSortOrder(so);
    searchRequest.setName(StringUtils.trimToNull(name));
    out.put("searchRequest", searchRequest);
    out.put("type", typeName);
    for (String configIdStr : configIdStrs) {
        searchRequest.addConfigId(ObjectId.parse(configIdStr));
    }

    if (data().getUriInfo().getQueryParameters().size() > 0) {
        ConfigSearchResult<Object> searchResult = null;
        if (searchRequest.getType() != null) {
            searchResult = data().getConfigMaster().search(searchRequest);
        } else {
            searchResult = new ConfigSearchResult<Object>();
            searchResult.setPaging(Paging.of(searchRequest.getPagingRequest(), searchResult.getDocuments()));
        }
        out.put("searchResult", searchResult);
        out.put("paging", new WebPaging(searchResult.getPaging(), uriInfo));
    }
    return out;
}

From source file:com.opengamma.web.exchange.WebExchangeResource.java

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)//from ww  w .  j av a  2s. c  o  m
public Response putJSON(@FormParam("name") String name, @FormParam("idscheme") String idScheme,
        @FormParam("idvalue") String idValue, @FormParam("regionscheme") String regionScheme,
        @FormParam("regionvalue") String regionValue) {
    if (data().getExchange().isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }

    name = StringUtils.trimToNull(name);
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    if (name == null || idScheme == null || idValue == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    updateExchange(name, idScheme, idValue, regionScheme, regionValue);
    return Response.ok().build();
}

From source file:adalid.util.i18n.Mapper.java

private String locale(String name) {
    String substringBeforeLast = StringUtils.substringBeforeLast(name, ".");
    String substringAfter = StringUtils.substringAfter(substringBeforeLast, "_");
    return StringUtils.trimToNull(substringAfter);
}

From source file:com.opengamma.web.position.TradeJsonConverter.java

private static ZoneOffset getOffset(JSONObject tradeJson, String fieldName) throws JSONException {
    ZoneOffset premiumOffset = ZoneOffset.UTC;
    if (tradeJson.has(fieldName)) {
        String offsetId = StringUtils.trimToNull(tradeJson.getString(fieldName));
        if (offsetId != null) {
            premiumOffset = ZoneOffset.of(offsetId);
        }//from  ww  w. jav  a  2 s  .  c o  m
    }
    return premiumOffset;
}

From source file:net.sf.eclipsecs.ui.config.ResolvablePropertyEditDialog.java

/**
 * {@inheritDoc}//from   w w  w .java  2s  .com
 */
protected void okPressed() {

    if (StringUtils.trimToNull(mTxtName.getText()) == null) {
        this.setErrorMessage(Messages.ResolvablePropertyEditDialog_msgMissingName);
        return;
    }
    if (StringUtils.trimToNull(mTxtValue.getText()) == null) {
        this.setErrorMessage(Messages.ResolvablePropertyEditDialog_msgMissingValue);
        return;
    }

    //
    // Get the entered value.
    //
    mProperty.setPropertyName(mTxtName.getText());
    mProperty.setValue(mTxtValue.getText());

    super.okPressed();
}

From source file:ch.entwine.weblounge.dispatcher.impl.DispatcherServiceImpl.java

/**
 * Callback for OSGi's declarative services component activation.
 * //from   w  w w .  jav a 2s  .  c om
 * @param context
 *          the component context
 * @throws Exception
 *           if component activation fails
 */
void activate(ComponentContext context) throws Exception {
    BundleContext bundleContext = context.getBundleContext();
    logger.info("Activating weblounge dispatcher");

    Dictionary<String, String> initParams = new Hashtable<String, String>();
    initParams.put(SharedHttpContext.ALIAS, "/");
    initParams.put(SharedHttpContext.SERVLET_NAME, "default");
    initParams.put(SharedHttpContext.CONTEXT_ID, SharedHttpContext.WEBLOUNGE_CONTEXT_ID);
    initParams.put(SharedHttpContext.PATTERN, ".*");
    dispatcherServiceRegistration = bundleContext.registerService(Servlet.class.getName(), dispatcher,
            initParams);

    instanceName = StringUtils.trimToNull(context.getBundleContext().getProperty(OPT_INSTANCE_NAME));
    if (instanceName != null)
        logger.info("Instance name is '{}'", instanceName);
    else
        logger.debug("No explicit instance name has been set");
    dispatcher.setName(instanceName);

    logger.debug("Weblounge dispatcher activated");
}

From source file:mitm.application.djigzo.james.matchers.VerifyHMACHeader.java

@Override
public void init() throws MessagingException {
    getLogger().info("Initializing matcher: " + getMatcherName());

    String condition = getCondition();

    if (StringUtils.isBlank(condition)) {
        throw new MessagingException("Usage: header, value [,secret]");
    }/*from  ww w .  ja  v a2  s .co  m*/

    parameters = StringUtils.split(condition, ',');

    if (parameters.length < 3) {
        throw new MessagingException("Usage: header, value ,secret");
    }

    header = StringUtils.trimToNull(parameters[0]);

    if (header == null) {
        throw new MessagingException("header is missing");
    }

    value = StringUtils.trimToNull(parameters[1]);

    if (value == null) {
        throw new MessagingException("value is missing");
    }

    secret = StringUtils.trimToNull(parameters[2]);

    if (secret == null) {
        throw new MessagingException("secret is missing");
    }

    securityFactory = SecurityFactoryFactory.getSecurityFactory();
}