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:gov.nih.nci.caintegrator.external.caarray.GenericSingleSamplePerFileParser.java

private void extractValue(SupplementalDataFile supplementalDataFile, PlatformVendorEnum vendor,
        Map<String, float[]> dataMap, String[] fields, String probeName) {
    String valueField = StringUtils.trim(fields[headerToIndexMap.get(supplementalDataFile.getValueHeader())]);
    if ((PlatformVendorEnum.AGILENT == vendor && probeName.startsWith("A_")
            || PlatformVendorEnum.AGILENT != vendor) && NumberUtils.isNumber(valueField)) {
        dataMap.put(probeName, ArrayUtils.add(dataMap.get(probeName), NumberUtils.toFloat(valueField)));
    }//from  w ww .jav a  2  s.  c om
}

From source file:com.ottogroup.bi.streaming.sink.kafka.KafkaProducerBuilder.java

/**
 * Adds a new key/value pair to properties
 * @param key//from   www .j ava2  s.  c om
 * @param value
 * @return
 */
public KafkaProducerBuilder<T> addProperty(final String key, final String value) {
    if (StringUtils.isNotBlank(key) && value != null)
        this.properties.put(StringUtils.lowerCase(StringUtils.trim(key)), value);
    return this;
}

From source file:com.navercorp.pinpoint.web.batch.BatchConfiguration.java

private void readPropertyValues(Properties properties) {
    logger.info("pinpoint-batch.properties read.");

    batchServerIp = readString(properties, "batch.server.ip", null);
    String[] flinkServers = StringUtils.split(readString(properties, "batch.flink.server", null), ",");
    if (flinkServers == null) {
        this.flinkServerList = Collections.emptyList();
    } else {/*from  w  w w  .  j  a v  a2 s.c o m*/
        this.flinkServerList = new ArrayList<>(flinkServers.length);
        for (String flinkServer : flinkServers) {
            if (!StringUtils.isEmpty(flinkServer)) {
                this.flinkServerList.add(StringUtils.trim(flinkServer));
            }
        }
    }
}

From source file:com.nesscomputing.migratory.migration.sql.SqlScript.java

List<String> readLines(final Reader reader) throws IOException {
    final List<String> lines = Lists.newArrayList();

    final BufferedReader bufferedReader = new BufferedReader(reader);
    String line;//from  w  w  w .j  a  v a 2 s  . c om

    boolean inMultilineComment = false;
    while ((line = StringUtils.trim(bufferedReader.readLine())) != null) {
        if (!inMultilineComment) {
            if (isCommentDirective(line) || line.startsWith("--")) {
                LOG.trace("Ignored '%s'", line);
                continue;
            } else if (line.contains("--")) {
                lines.add(StringUtils.trim(line.substring(0, line.indexOf("--"))));
            } else if (line.startsWith("/*")) {
                inMultilineComment = true;
                LOG.trace("Start Multiline ignore at  '%s'", line);
                if (line.endsWith("*/")) {
                    LOG.trace("...and then immediately ending it");
                    inMultilineComment = false;
                }
                continue;
            } else {
                LOG.trace("Adding '%s' to output", line);
                lines.add(line);
            }
        } else {
            if (line.endsWith("*/")) {
                LOG.trace("Ending Multiline ignore at  '%s'", line);
                inMultilineComment = false;
            }
        }
    }

    return lines;
}

From source file:de.micromata.genome.gwiki.web.tags.GWikiAuthTag.java

@Override
public int doStartTag() throws JspException {
    GWikiContext ctx = getWikiContext();
    GWikiAuthorization auth = ctx.getWikiWeb().getAuthorization();

    if (StringUtils.isNotBlank(pageId) == true) {
        GWikiElementInfo pid = ctx.getWikiWeb().findElementInfo(pageId);
        if (pid == null || auth.isAllowToView(ctx, pid) == false) {
            return Tag.SKIP_BODY;
        }/*from  ww w  .  j  a  va2 s  . c  o m*/
        return Tag.EVAL_BODY_INCLUDE;
    }
    @SuppressWarnings("unused")
    GWikiElementInfo ei = ctx.getCurrentElement() != null ? ctx.getCurrentElement().getElementInfo() : null;
    /* The User must not have any if rights */
    if (StringUtils.isNotBlank(ifHasNot) == true) {
        for (String right : splitRights(ifHasNot)) {
            if (auth.isAllowTo(ctx, StringUtils.trim(right))) {
                return Tag.SKIP_BODY;
            }
        }
        return Tag.EVAL_BODY_INCLUDE;
    }

    /* The user must have all rights */
    if (StringUtils.isNotBlank(ifHasAll)) {

        boolean hasAll = true;
        for (String right : splitRights(ifHasAll)) {
            hasAll &= auth.isAllowTo(ctx, StringUtils.trim(right));
        }
        if (hasAll) {
            return Tag.EVAL_BODY_INCLUDE;
        }
        return Tag.SKIP_BODY;
    }

    if (StringUtils.isNotBlank(ifHasAny)) {

        for (String rigth : splitRights(ifHasAny)) {
            if (auth.isAllowTo(ctx, StringUtils.trim(rigth))) {
                return Tag.EVAL_BODY_INCLUDE;
            }
        }
        return Tag.SKIP_BODY;
    }
    return Tag.EVAL_BODY_INCLUDE;
}

From source file:com.dominion.salud.pedicom.negocio.repositories.impl.PedidosRepositoryImpl.java

public List<Pedidos> findTransNCentro(Pedidos ped) {
    int dias = 30;
    List<LinParInt> list = linParIntRepository.getModulos();
    for (LinParInt lin : list) {
        if (lin.getLinParIntPK().getTipo().equals("LISTADO_DIAS")) {
            dias = Integer.parseInt(StringUtils.trim(lin.getParametro()));
        }/*from   ww w.j a  v  a2 s . c  om*/
    }

    return entityManager
            .createQuery("from Pedidos where centros.linea = :centroid and fechaPedido > :fecha", Pedidos.class)
            .setParameter("fecha", DateUtils.addDays(new Date(), -dias))
            .setParameter("centroid", ped.getCentros().getLinea()).getResultList();
}

From source file:com.dominion.salud.pedicom.negocio.tools.MAILService.java

/**
 * configura el ciente de correo y envia el correo con un adjunto
 *
 * @param to//  ww  w.  jav  a2 s .c  om
 * @param attach el archivo que se adjunta en el correo
 * @param centro nombre del centro desde el que se envia
 * @throws Exception
 */
public void sendByMail(String to, Object attach, String centro) throws Exception {
    logger.debug("          Iniciando la configuracion del mail con sus parametros correspondientes ,"
            + " obtenemos los parametros de environment");

    String dataBase = routingDataSource.dbActual();
    allDataSources.getDatasources();

    Datasources dat = null;
    for (Datasources datas : allDataSources.getDatasources()) {
        if (datas.getNombreDatasource().equals(dataBase)) {
            dat = datas;
            break;
        }
    }
    if (StringUtils.isBlank(StringUtils.trim(dat.getHost()))) {
        throw new Exception(
                "El host es [" + StringUtils.trim(dat.getHost()) + "] , error de host desconocido o erroneo");
    }
    logger.debug("          El host es [" + StringUtils.trim(dat.getHost()) + "]");

    if (StringUtils.isBlank(StringUtils.trim(dat.getUsernameEmail()))) {
        throw new Exception("El usuario es [" + StringUtils.trim(dat.getUsernameEmail())
                + "], error de login en el correo , usuario desconocido o erroneo");
    }
    logger.debug("          El usuario es [" + StringUtils.trim(dat.getUsernameEmail()) + "]");

    if (StringUtils.isBlank(StringUtils.trim(dat.getPasswordEmail()))) {
        throw new Exception("La contrasea es [" + StringUtils.trim(dat.getPasswordEmail())
                + "], error de login en el correo , contrasea desconocida o erronea");
    }
    logger.debug("          La contrasea es [" + StringUtils.trim(dat.getPasswordEmail()) + "]");

    if (StringUtils.isBlank(to)) {
        throw new Exception("El destinatario es [" + to + "], no se especificaron destinatarios.");
    }
    logger.debug("          El destinatario es [" + to + "]");

    /*if (dat.getPort()== null) {
    throw new Exception("El puerto es [" + StringUtils.trim(environment.getProperty("mail.port")) + "], el puerto del servidor de correo falla");
    }*/
    logger.debug("          El puerto es [" + dat.getPort() + "]");

    /*if (StringUtils.isBlank(StringUtils.trim(environment.getProperty("mail.TLS")))) {
    throw new Exception("El TLS es [" + StringUtils.trim(environment.getProperty("mail.TLS")) + "]");
    }*/
    logger.debug("          El TLS es [" + dat.getTLS() + "]");

    System.setProperty("mail.imap.auth.plain.disable", "true");

    MultiPartEmail email = new MultiPartEmail();
    email.setHostName(StringUtils.trim(dat.getHost()));
    email.setAuthenticator(new DefaultAuthenticator(StringUtils.trim(dat.getUsernameEmail()),
            StringUtils.trim(dat.getPasswordEmail())));
    email.setFrom(StringUtils.trim(StringUtils.trim(dat.getUsernameEmail())), centro);
    email.setDebug(true);
    email.setSmtpPort(dat.getPort());
    email.setStartTLSEnabled(dat.getTLS());
    email.setSSLOnConnect(dat.getSSL());
    DataSource source = null;
    if (attach != null) {
        logger.debug("          Adjuntando pdf");
        source = new ByteArrayDataSource((InputStream) attach, "application/pdf");
        email.attach(source, "Pedido de centro " + centro + ".pdf", "Pedido de centro " + centro);
    }
    email.setSubject("Pedido de centro [" + centro + "]");
    logger.debug("          Realizando envio");
    email.addTo(to);
    email.send();

    try {
        if (!StringUtils.isBlank(StringUtils.trim(dat.getMailCC()))) {
            logger.debug("          Enviando a CC: " + dat.getMailCC());
            MultiPartEmail emailCC = new MultiPartEmail();
            emailCC.setHostName(StringUtils.trim(dat.getHost()));
            emailCC.setAuthenticator(new DefaultAuthenticator(StringUtils.trim(dat.getUsernameEmail()),
                    StringUtils.trim(dat.getPasswordEmail())));
            emailCC.setFrom(StringUtils.trim(StringUtils.trim(dat.getUsernameEmail())), centro);
            emailCC.setDebug(true);
            emailCC.setSmtpPort(dat.getPort());
            emailCC.setStartTLSEnabled(dat.getTLS());
            emailCC.setSSLOnConnect(dat.getSSL());
            if (attach != null) {
                logger.debug("          Adjuntando pdf a copia");
                emailCC.attach(source, "Pedido de centro " + centro + ".pdf", "Pedido de centro " + centro);
            }
            emailCC.setSubject("Pedido de centro " + centro);
            emailCC.addCc(StringUtils.split(StringUtils.trim(dat.getMailCC()), ","));
            emailCC.send();
        }
    } catch (Exception e) {
        logger.warn("          Se han producido errores al enviar los CC: " + e.toString());
    }
    logger.debug("     Finalizando envio email");

}

From source file:com.xpn.xwiki.XWikiConfig.java

/**
 * {@inheritDoc}/*  w w w . ja  v  a  2  s  .c  o  m*/
 * <p>
 * This method trims the spaces around the value.
 * </p>
 * 
 * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
 */
@Override
public String getProperty(String key, String defaultValue) {
    return StringUtils.trim(super.getProperty(key, defaultValue));
}

From source file:com.adguard.filter.rules.FilterRule.java

/**
 * Creates filter rule.//from  w w w.  j a v  a2s .  com
 * If this rule text is not valid - returns null.
 *
 * @param ruleText Rule text
 * @return Filter rule of the proper type
 */
public static FilterRule createRule(String ruleText) {

    ruleText = StringUtils.trim(ruleText);

    if (StringUtils.isBlank(ruleText) || StringUtils.length(ruleText) < MIN_RULE_LENGTH
            || StringUtils.startsWith(ruleText, COMMENT) || StringUtils.startsWith(ruleText, META_START)
            || StringUtils.contains(ruleText, MASK_OBSOLETE_SCRIPT_INJECTION)
            || StringUtils.contains(ruleText, MASK_OBSOLETE_STYLE_INJECTION)) {
        return null;
    }

    try {
        if (StringUtils.startsWith(ruleText, MASK_WHITE_LIST)) {
            return new UrlFilterRule(ruleText);
        }

        if (StringUtils.contains(ruleText, MASK_CONTENT_RULE)) {
            return new ContentFilterRule(ruleText);
        }

        if (StringUtils.contains(ruleText, MASK_CSS_RULE)
                || StringUtils.contains(ruleText, MASK_CSS_EXCEPTION_RULE)
                || StringUtils.contains(ruleText, MASK_CSS_INJECT_RULE)
                || StringUtils.contains(ruleText, MASK_CSS_INJECT_EXCEPTION_RULE)) {
            return new CssFilterRule(ruleText);
        }

        if (StringUtils.contains(ruleText, MASK_SCRIPT_RULE)) {
            return new ScriptFilterRule(ruleText);
        }

        return new UrlFilterRule(ruleText);
    } catch (Exception ex) {
        LoggerFactory.getLogger(FilterRule.class).warn("Error creating filter rule {}:\r\n{}", ruleText, ex);
        return null;
    }
}

From source file:com.sonicle.webtop.core.bol.OUpgradeStatement.java

public OUpgradeStatement(String tag, String serviceId, short sequenceNo, String scriptName,
        String statementDataSource, String statementType, String statementBody) {
    setTag(tag);/*  w  ww.j  a va  2  s.  c om*/
    setServiceId(serviceId);
    setSequenceNo(sequenceNo);
    setScriptName(scriptName);
    setStatementDataSource(statementDataSource);
    setStatementType(statementType);
    setStatementBody(StringUtils.trim(statementBody));
}