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

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

Introduction

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

Prototype

public static String[] split(final String str, final String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:com.adguard.commons.utils.CharsetUtils.java

/**
 * Extracts Charset from Content-Type header value
 *
 * @param contentType    Content-Type header value
 * @param defaultCharset Will be returned if no charset found
 * @return Charset or defaultCharset/*from w w  w.j a v a  2 s  . co  m*/
 */
public static Charset forContentType(String contentType, Charset defaultCharset) {
    try {
        if (!StringUtils.isEmpty(contentType)) {
            String[] parts = StringUtils.split(contentType, ';');

            for (String t1 : parts) {
                String t = t1.trim();
                int index = t.toLowerCase().indexOf("charset=");
                if (index != -1) {
                    String charset = t.substring(index + 8);
                    String charset1 = StringUtils.split(charset, ",;")[0];
                    return forName(charset1, defaultCharset);
                }
            }
            return defaultCharset;
        }

        return defaultCharset;
    } catch (Exception ex) {
        log.debug(String.format("Cannot extract charset from %s", contentType), ex);
        return defaultCharset;
    }
}

From source file:de.micromata.mgc.jpa.hibernatesearch.impl.ListHibernateFieldInfoProvider.java

@Override
public Map<String, SearchColumnMetadata> getAdditionallySearchFields(EntityMetadata entm, String params) {
    Map<String, SearchColumnMetadata> ret = new HashMap<>();
    String[] fields = StringUtils.split(params, ',');
    for (String field : fields) {
        String fname = StringUtils.trim(field);
        ColumnMetadataBean cm = new ColumnMetadataBean(entm);
        cm.setName(fname);/*from  ww  w .  java 2s  .  c  om*/
        cm.setJavaType(String.class);
        SearchColumnMetadataBean mb = new SearchColumnMetadataBean(fname, cm);
        mb.setIndexed(true);
        mb.setIndexType(String.class);
        ret.put(fname, mb);
    }
    return ret;
}

From source file:io.wcm.testing.mock.sling.servlet.MockRequestPathInfo.java

@Override
public String[] getSelectors() {
    if (StringUtils.isEmpty(this.selectorString)) {
        return new String[0];
    } else {/*w  w  w . ja  va  2  s .  co  m*/
        return StringUtils.split(this.selectorString, ".");
    }
}

From source file:com.common.util.mapper.ConvertUtils.java

/**
 * Apache BeanUtilsConverter?,??,','/* w ww  . j  a  va 2s  .  c  o m*/
 */
public static void registerDateConverter(String patterns) {
    DateConverter dc = new DateConverter();
    dc.setUseLocaleFormat(true);
    dc.setPatterns(StringUtils.split(patterns, ","));
    org.apache.commons.beanutils.ConvertUtils.register(dc, Date.class);
}

From source file:name.martingeisse.stackd.common.network.SectionDataId.java

/**
 * Constructor./*  ww  w  .  ja  va2 s.c o  m*/
 * @param identifierText the text returned by {@link #getIdentifierText()}.
 * @throws IllegalArgumentException if the identifier text is malformed
 */
public SectionDataId(String identifierText) throws IllegalArgumentException {
    final String[] idTextSegments = StringUtils.split(identifierText, '_');
    if (idTextSegments.length != 4) {
        throw new IllegalArgumentException(identifierText);
    }
    try {
        int x = Integer.parseInt(idTextSegments[0]);
        int y = Integer.parseInt(idTextSegments[1]);
        int z = Integer.parseInt(idTextSegments[2]);
        type = SectionDataType.valueOf(idTextSegments[3]);
        sectionId = new SectionId(x, y, z);
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException("invalid SectionDataId: " + identifierText);
    } catch (final IllegalArgumentException e) {
        throw new IllegalArgumentException("invalid SectionDataId: " + identifierText);
    }
}

From source file:com.espe.distribuidas.telefonia.socket.ServerSocket.java

@OnMessage
public String handleMessage(String message) {
    System.out.println("mesaje: " + message);

    String[] datos = StringUtils.split(message, "|");

    String telefono = datos[0];//  w  w w . j  a  v  a2s .c  o  m
    double valor = Double.parseDouble(datos[1]);

    System.out.println(telefono + " ------ " + valor);

    Cliente c = this.clienteServicio.obtenerTelefonoPorNumero(telefono);

    if (c != null) {
        message = "cliente SI existe";
        System.out.println(message + " _> " + c.toString());

        Transaccion t = new Transaccion();
        t.setCliente(c);
        t.setFechaRecarga(new Date());
        t.setMonto(valor);
        double newSaldo = valor + c.getSaldo();
        t.setSaldoActual(newSaldo);

        this.transaccionServicio.insertarTransaccion(t);
        this.clienteServicio.actualizarSaldo(telefono, newSaldo);

        System.out.println("Transaccion realizada con exito " + t.toString());
        message = "OK";
    } else {
        message = "cliente NO existe";
        System.out.println(message);
        message = "NO";
    }

    String replyMessage = message;
    System.out.println("Mensaje  enviar:" + replyMessage);
    return replyMessage;
}

From source file:com.hb.weibo.rest.AccountRestController.java

@RequestMapping(value = "account/maintenance", method = RequestMethod.GET)
public String AccountManage(String content) {
    // ?content:nickname?loginerror?mobileyz
    String[] resultArray = StringUtils.split(content, "|");
    if (resultArray.length == 0 || resultArray.length != 7) {
        return "0";
    }/*from   www  .j  av a2 s  .co  m*/
    int type = Integer.parseInt(resultArray[4]);
    String username = resultArray[5];
    String typeString = resultArray[0];
    if (typeString.equals("nickname")) {
        String nick = resultArray[6];
        weiboAccountService.updateNick(nick, type, username);
        weiboOwnerService.updateFlag(1, "", type, username);
    } else if (typeString.equals("loginerror")) {
        String reason = resultArray[6];
        weiboOwnerService.updateFlag(1, reason, type, username);
    } else if (typeString.equals("mobileyz")) {
        String telephone = resultArray[6];
        weiboOwnerService.updateTelephone(telephone, type, username);
    } else {
        return "0";
    }
    return "1";
}

From source file:net.ontopia.topicmaps.nav2.plugins.VizPlugin.java

@Override
public void init() {
    message = getParameter("message");
    if (message == null)
        message = "Vizigation is disabled for this topic map";

    blocked = new CompactHashSet();
    String tmids = getParameter("blocked");
    if (tmids == null)
        return;/*from www . j a  va 2  s. co m*/

    String[] ids = StringUtils.split(tmids, ",");
    for (int ix = 0; ix < ids.length; ix++)
        blocked.add(ids[ix].trim());
}

From source file:de.jcup.egradle.codeassist.dsl.ApiMappingImporter.java

/**
 * Imports mapping/*from  w w w .j av a  2 s  .c  o m*/
 * 
 * @param stream
 * @return map never <code>null</code>. Map keys are shortnames, values are
 *         long names
 * @throws IOException
 */
public Map<String, String> importMapping(InputStream stream) throws IOException {
    Map<String, String> map = new TreeMap<>();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
        String line = "";
        while ((line = reader.readLine()) != null) {
            /* file contains as following "shortName:longName;" */
            String[] parts = StringUtils.split(line, ":;");
            if (parts == null) {
                continue;
            }
            if (parts.length < 2) {
                continue;
            }
            map.put(parts[0], parts[1]);
        }
        return map;
    }
}

From source file:com.thoughtworks.go.domain.Matcher.java

private void trimAndAdd(String matcherString) {
    for (String part : StringUtils.split(matcherString, SEPARATOR)) {
        this.matchers.add(part.trim());
    }//  w w w  .j a  va 2s  .  c om
}