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.ms.commons.message.impl.sms.MobileMessage.java

/**
 * ?/*from   w w w  . j a v a  2 s  . c o  m*/
 * 
 * @param from ???
 * @param to ??
 * @param message ?, ??210
 * @param testKey ?IP
 */
public MobileMessage(String from, String[] to, String message, String testKey, SmsMsgSendType smsMsgSendType) {
    this.from = from;
    if (to == null || to.length < 1) {
        throw new IllegalArgumentException("???");
    }

    /**
     * ????
     */
    for (int i = 0; i < to.length; i++) {
        if (!MessageUtil.isValidateMobileNumber(to[i]) || StringUtils.isEmpty(to[i])) {
            logger.warn("??<" + to[i] + "<!");
            to[i] = null;
        }
    }

    this.message = StringUtils.trimToEmpty(message);
    if (message == null || message.length() > MessageConstants.MAX_TEXT_MSG_LENGTH) {
        throw new IllegalArgumentException("Message?????"
                + MessageConstants.MAX_TEXT_MSG_LENGTH + "");
    }

    this.to = MessageUtil.removeEmptyElement(to);
    this.testKey = testKey;
    this.smsMsgSendType = smsMsgSendType;
}

From source file:com.alibaba.otter.common.push.AbstractSubscribeManager.java

protected static String generateKey(String dataId, String groupId) {
    return StringUtils.trimToEmpty(dataId) + "_" + StringUtils.trimToEmpty(groupId);
}

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

private static SqlAgentMessage executeProcedure(String procedimiento, Long rastro, Object[] args,
        boolean logging) {
    Bitacora.trace(SqlAgent.class, "executeProcedure", procedimiento, rastro);
    Utils.traceObjectArray(args);/* ww  w .ja  v  a  2 s  .  c  om*/
    String procedure = StringUtils.trimToEmpty(procedimiento);
    //      String archivo = logging ? getLogFileName(rastro) : null;
    String archivo = null;
    CondicionEjeFunEnumeration condicion = CondicionEjeFunEnumeration.EJECUCION_EN_PROGRESO;
    String mensaje = TLC.getBitacora().info(CBM.PROCESS_EXECUTION_BEGIN, procedure);
    boolean ok = Auditor.grabarRastroProceso(rastro, condicion, archivo, mensaje);
    if (ok) {
        try {
            // <editor-fold defaultstate="collapsed">
            //              Object resultado = TLC.getAgenteSql().executeProcedure(procedure, args);
            //              if (resultado == null) {
            //                  condicion = CondicionEjeFunEnumeration.EJECUTADO_CON_ERRORES;
            //                  mensaje = TLC.getBitacora().error(CBM.PROCESS_EXECUTION_ABEND, procedure);
            //              } else {
            //                  condicion = CondicionEjeFunEnumeration.EJECUTADO_SIN_ERRORES;
            //                  if (resultado instanceof Number) {
            //                      mensaje = TLC.getBitacora().info(procedure + " = " + resultado);
            //                  } else if (resultado instanceof ResultSet) {
            //                      ResultSet resultSet = (ResultSet) resultado;
            //                      if (resultSet.next()) {
            //                          mensaje = TLC.getBitacora().info(procedure + " = " + resultSet.getObject(1));
            //                      } else {
            //                          mensaje = TLC.getBitacora().info(procedure + " = " + STP.STRING_VALOR_NULO);
            //                      }
            //                  } else {
            //                      mensaje = TLC.getBitacora().info(CBM.PROCESS_EXECUTION_END, procedure);
            //                  }
            //              }
            // </editor-fold>
            Object resultado = TLC.getAgenteSql().executeProcedure(procedure, args);
            if (resultado == null) {
                condicion = CondicionEjeFunEnumeration.EJECUTADO_CON_ERRORES;
                mensaje = TLC.getBitacora().error(CBM.PROCESS_EXECUTION_ABEND, procedure);
            } else {
                condicion = CondicionEjeFunEnumeration.EJECUTADO_SIN_ERRORES;
                mensaje = TLC.getBitacora().info(CBM.PROCESS_EXECUTION_END, procedure);
                if (resultado instanceof ResultSet) {
                    ResultSet resultSet = (ResultSet) resultado;
                    if (resultSet.next()) {
                        mensaje += " (" + resultSet.getObject(1) + ") ";
                    }
                } else if (resultado.getClass().isPrimitive()) {
                    mensaje += " (" + resultado + ") ";
                }
            }
        } catch (Exception ex) {
            condicion = CondicionEjeFunEnumeration.EJECUTADO_CON_ERRORES;
            mensaje = ThrowableUtils.getString(ex);
            TLC.getBitacora().fatal(ex);
            TLC.getBitacora().fatal(CBM.PROCESS_EXECUTION_ABEND, procedure);
        } finally {
            Auditor.grabarRastroProceso(rastro, condicion, archivo, mensaje);
            //              DB.close(resultSet);
        }
    } else {
        condicion = CondicionEjeFunEnumeration.EJECUCION_CANCELADA;
        mensaje = TLC.getBitacora().error(CBM.PROCESS_EXECUTION_ABEND, procedure);
    }
    SqlAgentMessage message = new SqlAgentMessage(procedure);
    message.setArgumentos(args);
    message.setRastro(rastro);
    message.setCondicion(condicion);
    message.setArchivo(archivo);
    message.setMensaje(mensaje);
    return message;
}

From source file:gate.corpora.JSONTweetFormat.java

@Override
public void unpackMarkup(gate.Document doc) throws DocumentFormatException {
    if ((doc == null) || (doc.getSourceUrl() == null && doc.getContent() == null)) {
        throw new DocumentFormatException("GATE document is null or no content found. Nothing to parse!");
    }/*www .j a  v  a  2  s. com*/

    setNewLineProperty(doc);
    String jsonString = StringUtils.trimToEmpty(doc.getContent().toString());
    try {
        // Parse the String
        List<Tweet> tweets = TweetUtils.readTweets(jsonString);
        Map<Tweet, Long> tweetStarts = new HashMap<Tweet, Long>();

        // Put them all together to make the unpacked document content
        StringBuilder concatenation = new StringBuilder();
        for (Tweet tweet : tweets) {
            tweetStarts.put(tweet, (long) concatenation.length());
            concatenation.append(tweet.getString()).append("\n\n");
        }

        // Set new document content 
        DocumentContent newContent = new DocumentContentImpl(concatenation.toString());
        doc.edit(0L, doc.getContent().size(), newContent);

        AnnotationSet originalMarkups = doc.getAnnotations(GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
        // Create Original markups annotations for each tweet
        for (Tweet tweet : tweets) {
            for (PreAnnotation preAnn : tweet.getAnnotations()) {
                preAnn.toAnnotation(originalMarkups, tweetStarts.get(tweet));
            }
        }
    } catch (InvalidOffsetException e) {
        throw new DocumentFormatException(e);
    } catch (IOException e) {
        throw new DocumentFormatException(e);
    }
}

From source file:hudson.plugins.sonar.model.LightProjectConfig.java

public String getProjectSrcEncoding() {
    return StringUtils.trimToEmpty(projectSrcEncoding);
}

From source file:chiliad.parser.pdf.extractor.text.TextExtractor.java

private MToken toMToken(Token token) {
    MToken mToken = new MToken();
    mToken.setText(StringUtils.normalizeSpace(StringUtils.trimToEmpty(token.getText())));
    mToken.setFontFamily(token.getFontFamily());
    mToken.setFontName(token.getFontName());
    mToken.setFontSizeInPt(token.getFontSizeInPt());
    mToken.setFontWeight(token.getFontWeight());
    mToken.setNonStrokingColor(MToken.colorToRgba(token.getNonStrokingColor()));
    mToken.setStrokingColor(MToken.colorToRgba(token.getStrokingColor()));
    mToken.setX(token.getPositionStartX());
    mToken.setY(token.getPositionStartY());
    mToken.setWidth(token.getWidth());/*from  w ww.  j  a  v  a2  s  .c o  m*/
    mToken.setHeight(token.getHeight());
    return mToken;
}

From source file:hudson.plugins.sonar.model.LightProjectConfig.java

public String getProjectBinDir() {
    return StringUtils.trimToEmpty(projectBinDir);
}

From source file:com.edgenius.wiki.render.handler.PageInfoHandler.java

public List<RenderPiece> handle(RenderContext renderContext, Map<String, String> values)
        throws RenderHandlerException {
    if (page == null) {
        throw new RenderHandlerException("Invalid content. {pageinfo} must inside a page.");
    }//from ww w  .  j a v  a  2  s .c o  m
    String type = StringUtils.trim(values.get(NameConstants.TYPE));
    if (StringUtils.isEmpty(type)
            || (!NameConstants.CREATOR.equals(type) && !NameConstants.MODIFIER.equals(type))) {
        log.warn("Unable to find valid type parameter from PageInfoMacro");
        throw new RenderHandlerException(
                "Type parameter is invalid, either creator or modifier. Sample {pageinfo:type=creator}");
    }

    User user = (NameConstants.CREATOR.equals(type)) ? page.getCreator() : page.getModifier();
    if (user == null) {
        //anonymous user
        user = userReadingService.getUser(-1);
    }
    Date date = (NameConstants.CREATOR.equals(type)) ? page.getCreatedDate() : page.getModifiedDate();

    String value = StringUtils.trimToEmpty(values.get("value"));

    List<RenderPiece> pieces = new ArrayList<RenderPiece>();
    pieces.add(new TextModel("<div class=\"macroPageinfo\" " + NameConstants.WAJAX + "=\""
            + RichTagUtil.buildWajaxAttributeString(this.getClass().getName(), values) + "\">"));

    StringBuffer buf = new StringBuffer();

    if (value.length() == 0 || "portrait".equals(value)) {
        String portraitUrl = UserUtil.getPortraitUrl(user.getPortrait());
        buf.append("<div class=\"portrait\">")
                .append(GwtUtils.getUserPortraitHTML(portraitUrl, user.getFullname(), -1)).append("</div>");
        pieces.add(new TextModel(buf.toString()));
    }

    if (value.length() == 0 || "name".equals(value)) {
        String msg = NameConstants.CREATOR.equals(type) ? messageService.getMessage("created.by")
                : messageService.getMessage("last.updated.by");
        pieces.add(new TextModel("<div class=\"name\">" + msg + " "));
        pieces.add(WikiUtil.createUserLinkModel(user));
        pieces.add(new TextModel("</div>"));
    }

    if ((value.length() == 0 || "date".equals(value)) && date != null) {
        buf = new StringBuffer();
        String showDate = DateUtil.toDisplayDateWithPrep(WikiUtil.getUser(), date, messageService);
        buf.append("<div class=\"date\">").append(showDate).append("</div>");
        pieces.add(new TextModel(buf.toString()));
    }

    if ("status".equals(value)) {
        buf = new StringBuffer();
        buf.append("<div class=\"status\">").append(user.getSetting().getStatus()).append("</div>");
        pieces.add(new TextModel(buf.toString()));
    }
    pieces.add(new TextModel("</div>"));

    return pieces;
}

From source file:com.hangum.tadpole.login.core.dialog.FindPasswordDialog.java

@Override
protected void okPressed() {
    String strEmail = StringUtils.trimToEmpty(textEmail.getText());
    if (logger.isInfoEnabled())
        logger.info("Find password dialog" + strEmail);

    if (!checkValidation()) {
        MessageDialog.openWarning(getShell(), CommonMessages.get().Confirm,
                Messages.get().FindPasswordDialog_6);
        textEmail.setFocus();//from   w w w. j a v  a 2s .  co  m
        return;
    }

    UserDAO userDao = new UserDAO();
    userDao.setEmail(strEmail);
    String strTmpPassword = Utils.getUniqueDigit(12);
    userDao.setPasswd(strTmpPassword);

    try {
        TadpoleSystem_UserQuery.updateUserPasswordWithID(userDao);
        sendEmailAccessKey(strEmail, strTmpPassword);
        MessageDialog.openInformation(getShell(), CommonMessages.get().Confirm, Messages.get().SendMsg);
    } catch (Exception e) {
        logger.error("password initialize and send email ", e);

        MessageDialog.openError(getShell(), CommonMessages.get().Error,
                String.format(Messages.get().SendMsgErr, e.getMessage()));
    }

    super.okPressed();
}

From source file:com.eyeq.pivot4j.util.MarkupWriter.java

/**
 * @param attributeName/*  ww w  . jav  a  2  s.  c om*/
 * @param attributeValue
 */
public void writeAttribute(String attributeName, String attributeValue) {
    writer.print(' ');
    writer.print(attributeName);
    writer.print("=\"");
    writer.print(StringUtils.trimToEmpty(attributeValue));
    writer.print("\"");
}