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

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

Introduction

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

Prototype

public static String trimToEmpty(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:com.inktomi.wxmetar.MetarParser.java

public static Metar parseMetar(final String input) {
    Metar finalMetar = new Metar();

    // Trim any extra space off the input
    String inputMetar = StringUtils.trimToEmpty(input);

    // Just to be sure.
    inputMetar = inputMetar.toUpperCase();

    // Split the metar on spaces
    String[] tokens = StringUtils.split(inputMetar);

    if (null != tokens) {
        finalMetar = parseTokens(tokens);
    }//  w  w  w  .  j  a v a  2s.  co  m

    return finalMetar;
}

From source file:cc.kune.core.server.utils.FilenameUtils.java

/**
 * Check filename is not empty, or '.', or '..'
 * //ww  w  . ja  va 2  s.  c  o m
 * @param filename
 *          the filename
 */
public static void checkBasicFilename(final String filename) {
    if (TextUtils.empty(StringUtils.trimToEmpty(filename)) || filename.equals(".") || filename.equals("..")) {
        throw new NameNotPermittedException();
    }
}

From source file:com.egt.core.db.util.SqlAgent.java

public static Process executeProcedure(String procedimiento, long funcion, Object[] args) {
    Bitacora.trace(SqlAgent.class, "executeProcedure", procedimiento, String.valueOf(funcion));
    Utils.traceObjectArray(args);/*  ww w . j a v a  2s  .  c om*/
    Long rastro = null;
    Process process = null;
    try {
        procedimiento = StringUtils.trimToEmpty(procedimiento);
        if (STP.esIdentificadorArchivoValido(procedimiento)) {
            if (TLC.getControlador().esFuncionAutorizada(funcion)) {
                rastro = TLC.getControlador().ponerProcesoPendiente(funcion);
                String command = EA.getString(EAC.SQLPRC_RUNNER_DIR) + EA.getString(EAC.SQLPRC_RUNNER_CMD);
                command += " " + commandParameters(procedimiento, funcion, rastro, args);
                String[] envp = null;
                File dir = new File(EA.getString(EAC.SQLPRC_RUNNER_DIR));
                Bitacora.trace(command);
                Bitacora.trace(dir.getPath());
                process = Runtime.getRuntime().exec(command, envp, dir);
                TLC.getBitacora().info(CBM2.PROCESS_EXECUTION_REQUEST, procedimiento);
            } else {
                throw new ExcepcionAplicacion(
                        Bitacora.getTextoMensaje(CBM2.FUNCION_NO_AUTORIZADA, procedimiento));
            }
        } else {
            throw new ExcepcionAplicacion(
                    Bitacora.getTextoMensaje(CBM2.IDENTIFICADOR_ARCHIVO_INVALIDO, procedimiento));
        }
    } catch (Exception ex) {
        EnumCondicionEjeFun condicion = EnumCondicionEjeFun.EJECUCION_CANCELADA;
        String mensaje = ThrowableUtils.getString(ex);
        Auditor.grabarRastroProceso(rastro, condicion, null, mensaje);
        TLC.getBitacora().error(mensaje);
    }
    return process;
}

From source file:com.hangum.tadpole.commons.util.JSONUtil.java

/**
 * json normal string to pretty string/*from w  w w  . j  a va 2 s. c  o m*/
 * 
 * @param jsonString
 * @return
 */
public static String getPretty(String jsonString) {
    if (jsonString == null)
        return "";

    //      if(logger.isDebugEnabled()) {
    //         logger.debug("======================================================");
    //         logger.debug("==> ["+ jsonString + "]");
    //         logger.debug("======================================================");
    //      }
    try {
        JsonParser jp = new JsonParser();
        JsonElement je = jp.parse(StringUtils.trim(jsonString));

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String strGson = gson.toJson(je);
        System.out.println(StringUtils.trimToEmpty(strGson));

        if (strGson == null || "null".equals(strGson))
            strGson = "";

        return strGson;
    } catch (Exception e) {
        //         logger.error("pretty json", e);
    }

    return jsonString;

}

From source file:ips1ap101.lib.core.db.util.SqlAgent.java

public static Process executeProcedure(String procedimiento, long funcion, Object[] args) {
    Bitacora.trace(SqlAgent.class, "executeProcedure", procedimiento, String.valueOf(funcion));
    Utils.traceObjectArray(args);//w  ww  . j a v a2 s .  c  o m
    Long rastro = null;
    Process process = null;
    try {
        procedimiento = StringUtils.trimToEmpty(procedimiento);
        if (STP.esIdentificadorArchivoValido(procedimiento)) {
            if (TLC.getControlador().esFuncionAutorizada(funcion)) {
                rastro = TLC.getControlador().ponerProcesoPendiente(funcion);
                String path = Utils.sep(EA.getString(EAC.SQLPRC_RUNNER_DIR));
                String command = path + EA.getString(EAC.SQLPRC_RUNNER_CMD);
                command += " " + commandParameters(procedimiento, funcion, rastro, args);
                String[] envp = null;
                File dir = new File(path);
                Bitacora.trace(command);
                Bitacora.trace(dir.getPath());
                process = Runtime.getRuntime().exec(command, envp, dir);
                TLC.getBitacora().info(CBM.PROCESS_EXECUTION_REQUEST, procedimiento);
            } else {
                throw new ExcepcionAplicacion(
                        Bitacora.getTextoMensaje(CBM.FUNCION_NO_AUTORIZADA, procedimiento));
            }
        } else {
            throw new ExcepcionAplicacion(
                    Bitacora.getTextoMensaje(CBM.IDENTIFICADOR_ARCHIVO_INVALIDO, procedimiento));
        }
    } catch (Exception ex) {
        CondicionEjeFunEnumeration condicion = CondicionEjeFunEnumeration.EJECUCION_CANCELADA;
        String mensaje = ThrowableUtils.getString(ex);
        Auditor.grabarRastroProceso(rastro, condicion, null, mensaje);
        TLC.getBitacora().error(mensaje);
    }
    return process;
}

From source file:de.hybris.platform.secureportaladdon.cockpit.label.CMSSiteLabelProvider.java

@Override
protected String getItemLabel(final CMSSiteModel cmsSite) {
    return StringUtils.trimToEmpty(cmsSite.getName());
}

From source file:com.egt.core.db.util.Exporter.java

public static EnumFormatoArchivo getExportType(String formato) {
    String str = StringUtils.trimToEmpty(formato);
    EnumFormatoArchivo tipo = EnumFormatoArchivo.CSV;
    if (EnumFormatoArchivo.TXT.getExtension().equalsIgnoreCase(str)) {
        tipo = EnumFormatoArchivo.TXT;//  ww w  .j  ava2s .  com
    }
    return tipo;
}

From source file:net.logstash.logback.appender.DestinationParser.java

/**
 * Constructs {@link InetSocketAddress}es by parsing the given {@link String} value.
 * <p>// w  ww . j a v  a  2  s  .co m
 * The string is a comma separated list of destinations in the form of hostName[:portNumber].
 * <p>
 * 
 * For example, "host1.domain.com,host2.domain.com:5560"
 * <p>
 * 
 * If portNumber is not provided, then the given defaultPort will be used.
 */
public static List<InetSocketAddress> parse(String destinations, int defaultPort) {

    /*
     * Multiple destinations can be specified on one single line, separated by comma
     */
    String[] destinationStrings = StringUtils.split(StringUtils.trimToEmpty(destinations), ',');

    List<InetSocketAddress> destinationList = new ArrayList<InetSocketAddress>(destinationStrings.length);

    for (String entry : destinationStrings) {

        /*
         * For #134, check to ensure properties are defined when destinations
         * are set using properties. 
         */
        if (entry.contains(CoreConstants.UNDEFINED_PROPERTY_SUFFIX)) {
            throw new IllegalArgumentException(
                    "Invalid destination '" + entry + "': unparseable value (expected format 'host[:port]').");
        }

        Matcher matcher = DESTINATION_PATTERN.matcher(entry);
        if (!matcher.matches()) {
            throw new IllegalArgumentException(
                    "Invalid destination '" + entry + "': unparseable value (expected format 'host[:port]').");
        }
        String host = matcher.group(HOSTNAME_GROUP);
        String portString = matcher.group(PORT_GROUP);

        int port;
        try {
            port = (portString != null) ? Integer.parseInt(portString) : defaultPort;

        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(
                    "Invalid destination '" + entry + "': unparseable port (was '" + portString + "').");
        }

        destinationList.add(InetSocketAddress.createUnresolved(host, port));
    }

    return destinationList;
}

From source file:com.hangum.tadpole.rdb.core.editors.main.utils.SQLTextUtil.java

/**
 * cursor object arry// w  ww.j  a v  a2s. c  o  m
 * 
 * @param strQuery
 * @param intPosition
 * @param startIndex
 * @param endIndex
 * @return
 */
private static String[] cusrsotObjectArry(String strQuery, int intPosition, int startIndex, int endIndex) {
    String[] arryCursor = { "", "" };

    String strPosTxt = StringUtils.trimToEmpty(StringUtils.substring(strQuery, startIndex, endIndex));
    //      if(logger.isDebugEnabled()) logger.debug("==> postion char : " + strPosTxt);
    if (StringUtils.isEmpty(strPosTxt))
        return arryCursor;

    String strBeforeTxt = strQuery.substring(0, startIndex);
    String[] strArryBeforeTxt = StringUtils.split(strBeforeTxt, ' ');

    //    ? ?  .
    String strAfterTxt = strQuery.substring(startIndex);
    String[] strArryAfterTxt = StringUtils.split(strAfterTxt, ' ');

    if (strArryBeforeTxt.length == 0) {
        arryCursor[0] = removeSpecialChar(strArryAfterTxt[0]);
        arryCursor[1] = "";
    } else {
        arryCursor[0] = removeSpecialChar(strArryBeforeTxt[strArryBeforeTxt.length - 1]);
        arryCursor[1] = removeSpecialChar(strArryAfterTxt[0]);
    }
    return arryCursor;
}

From source file:com.edgenius.wiki.ext.calendar.CalendarEventJson.java

public static CalendarEventJson from(CalendarEvent evt) {
    CalendarEventJson json = new CalendarEventJson();
    json.eventID = evt.getUid();/* www  .  ja v a 2s .  c  o m*/
    json.subject = StringUtils.trimToEmpty(evt.getSubject());
    json.startDate = evt.getStart().getTime();
    json.endDate = evt.getEnd().getTime();
    json.color = evt.getCategory();
    json.isAllDayEvent = evt.isAllDayEvent();
    json.repeatRule = StringUtils.trimToEmpty(evt.getRepeatRule());
    json.location = StringUtils.trimToEmpty(evt.getLocation());
    json.content = StringUtils.trimToEmpty(evt.getContent());

    return json;
}