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

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

Introduction

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

Prototype

public static String strip(String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

Usage

From source file:com.neusoft.mid.clwapi.threadwork.MtMsgSendWorkThread.java

public void run() {
    if (null != msgInfo) {

        logger.info("VINS?:" + msgInfo.getVin());
        String[] vinArray = StringUtils.split(StringUtils.strip(msgInfo.getVin()), "|");
        logger.info("???" + vinArray.length + "");
        // ?./*www.  ja  v a  2 s  . co  m*/
        String batchId = UUID.randomUUID().toString().replaceAll("-", "");
        for (String vin : vinArray) {
            String msgId = createMsgId();
            MDC.put("SUB_ID", "[" + msgId + "]");
            try {
                logger.info("vin:" + vin + "");
                TerminalViBean terminalInfo = (TerminalViBean) msgMapper.getRealVehcileByVin(vin);
                // ????
                if (isMsgPassable(vin, terminalInfo)) {
                    logger.info("VIN:" + vin + "??????");
                    SendCommandInfo info = initDiaoduCommandInfo(vin, msgInfo.getMsg(), msgInfo.getType(),
                            terminalInfo.getSimCardNum(), batchId, msgId, msgInfo.getUserId());
                    if (null != info) {
                        // ?????
                        sendDeliverMsgService.sendCommandToCoreService(info);

                    } else {
                        logger.info("???,??");
                    }
                } else {
                    logger.info("VIN:" + vin + "????");
                }
            } catch (DataAccessException e) {
                logger.error("??vin:" + vin + "?", e);
            } catch (Exception e) {
                logger.error("vin:" + vin + "??", e);
            }
            MDC.remove("SUB_ID");
        }
    }

}

From source file:de.softwareforge.pgpsigner.key.Key.java

public String getName() {

    Iterator it = getUserIds();/*from   w ww  . j  a va2 s .c om*/

    if (!it.hasNext()) {
        return null;
    }

    String userId = (String) it.next();

    int leftIndex = userId.indexOf('<');

    if (leftIndex == -1) {
        return "PGP key owner (unknown id)";
    }

    return StringUtils.strip(userId.substring(0, leftIndex));
}

From source file:de.eod.jliki.users.servlets.CaptchaValidator.java

/**
 * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
 * {@inheritDoc}/*from  w  w w. j  a v  a2s.c  om*/
 */
@Override
public final void validate(final FacesContext context, final UIComponent component, final Object value) {
    final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    final String sessionId = request.getSession().getId();
    final Locale sessionLocale = request.getLocale();
    final String val = StringUtils.strip((String) value);

    if (!CaptchaService.getInstance().validateResponseForID(sessionId, val)) {
        throw new ValidatorException(Messages.createFacesMessage(FacesMessage.SEVERITY_ERROR,
                "user.register.captcha.mismatch", sessionLocale));
    }
}

From source file:com.processpuzzle.fundamental_types.domain.ParameterDefinition.java

public static ParameterDefinition parse(String definitionText) throws ClassNotFoundException {
    Pattern namePattern = Pattern.compile("([a-z]|[A-Z]|[0-9])+\\s*:");
    Matcher nameFinder = namePattern.matcher(definitionText);
    String name = null;//from  w w w .j ava2  s  .co  m
    if (nameFinder.find()) {
        name = StringUtils.strip(nameFinder.group().substring(0, nameFinder.end() - 1));
    }

    Pattern typePattern = Pattern.compile(":\\s*([^]]+)(\\[|=)");
    Matcher typeFinder = typePattern.matcher(definitionText);
    String type = null;
    if (typeFinder.find()) {
        type = "java.lang."
                + StringUtils.strip(typeFinder.group().substring(1, typeFinder.group().length() - 1));
    }

    Pattern multiplicityPattern = Pattern.compile("\\[([^]]+)\\]");
    Matcher multiplicityFinder = multiplicityPattern.matcher(definitionText);
    String multiplicity = null;
    if (multiplicityFinder.find()) {
        multiplicity = StringUtils
                .strip(multiplicityFinder.group().substring(1, multiplicityFinder.group().length() - 1));
    }

    Pattern descriptionPattern = Pattern.compile("//([A-Z]|[a-z]|\\s|\\.)*");
    Matcher descriptionFinder = descriptionPattern.matcher(definitionText);
    String description = null;
    if (descriptionFinder.find()) {
        description = StringUtils.strip(descriptionFinder.group().substring(2));
    }

    return new ParameterDefinition(name, type, multiplicity, description);
}

From source file:com.adaptris.core.services.system.AddMetaDataValue.java

@Override
public OutputStream startCapture(final AdaptrisMessage msg) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();

    // Construct a new OutputStream that will set the metadata value when closed
    return new RunAfterCloseOutputStream(bos, new IORunnable() {
        @Override//from w  ww  .  j a  va  2 s.  c  o m
        public void run() throws IOException {
            String result = getResultAsString(bos.toByteArray());
            if (strip()) {
                result = StringUtils.strip(result);
            }
            msg.addMetadata(metadataKey, result);
        }

        private String getResultAsString(byte[] result) throws IOException {
            if (StringUtils.isEmpty(encoding)) {
                return new String(result);
            } else {
                return new String(result, encoding);
            }
        }
    });
}

From source file:com.neusoft.mid.clwapi.service.tacks.TacksServiceImpl.java

/**
 * ???./*from  w ww .  jav a  2s .co m*/
 * 
 * @param token
 *            ?.
 * 
 * @param vin
 *            vin?.
 * 
 * @param date
 *            ,?yyyymmdd.
 * @return ??.
 */
@Override
public Response getVinTacksList(String token, String vin, String date) {
    vin = StringUtils.strip(vin);
    date = StringUtils.strip(date);
    logger.info("-vin?:" + vin + ",:" + date);

    try {
        TimeUtil.parseStringToDate(date, HttpConstant.DAY_FORMAT);
    } catch (ParseException e) {
        logger.error(
                "-" + date + "?yyyyMMdd?" + e.getMessage());
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    List<TackListInfo> resultList = tcMapper.getCarRunRecs(date, vin);
    if (CheckRequestParam.isEmpty(resultList)) {
        logger.info("-VIN:" + vin + "" + date
                + "");
        return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                .header("Pragma", "no-cache").build();
    }

    TackListResp resp = new TackListResp();
    resp.setResultList(resultList);

    return Response.ok(JacksonUtils.toJsonRuntimeException(resp)).header(HttpHeaders.CACHE_CONTROL, "no-store")
            .header("Pragma", "no-cache").build();
}

From source file:com.moz.fiji.schema.tools.synth.DictionaryLoader.java

/**
 * Loads the dictionary from an input stream.
 *
 * @param inputStream The input stream of words, one per line.
 * @return The list of words from the stream.
 * @throws IOException If there is an error reading the words from the stream.
 *//*www.j  a va2 s .  co  m*/
public List<String> load(InputStream inputStream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
    List<String> dict = new ArrayList<String>();
    while (reader.ready()) {
        dict.add(StringUtils.strip(reader.readLine()));
    }
    return dict;
}

From source file:com.neusoft.mid.clwapi.threadwork.PhotoSendWorkThread.java

public void run() {
    if (null != msgInfo) {

        logger.info("VINS?:" + msgInfo.getVin());
        String[] vinArray = StringUtils.split(StringUtils.strip(msgInfo.getVin()), "|");
        logger.info("???" + vinArray.length + "");

        logger.info("??:" + msgInfo.getType());
        String[] channelArray = StringUtils.split(StringUtils.strip(msgInfo.getType()), "|");
        logger.info("???" + channelArray.length + "?");
        // ?./*from  ww w . ja v  a2  s  .  c om*/
        String batchId = UUID.randomUUID().toString().replaceAll("-", "");
        for (String vinTemp : vinArray) {
            String vin = StringUtils.strip(vinTemp);
            // ????
            try {
                logger.info("vin:" + vin + "");
                TerminalViBean terminalInfo = (TerminalViBean) msgMapper.getRealVehcileByVin(vin);
                // ????
                if (isPicPassable(vin, terminalInfo)) {
                    logger.info("VIN:" + vin + "??????");
                    for (String channelTemp : channelArray) {
                        String msgId = createMsgId();
                        MDC.put("SUB_ID", "[" + msgId + "]");
                        String channel = StringUtils.strip(channelTemp);
                        SendCommandInfo info = initPicCommandInfo(vin, channel, terminalInfo.getSimCardNum(),
                                batchId, usrInfo, msgId);
                        if (null != info) {
                            // ?????
                            DeliverMsgResult respResult = sendDeliverMsgService.sendCommandToCoreService(info);
                            // ?????.
                            if (null != respResult && "0".equals(respResult.getCode())) {
                                logger.info("VIN:" + vin + ",channel:" + channel + "???");
                            } else {
                                logger.error("?VIN:" + vin + ",channel:" + channel
                                        + "?");
                            }
                        } else {
                            logger.error("?VIN:" + vin + ",channel:" + channel
                                    + "??");
                        }
                    }

                } else {
                    logger.info("VIN:" + vin + "????");
                }
            } catch (DataAccessException e) {
                logger.error("??vin:" + vin + "?", e);
            } catch (Exception e) {
                logger.error("vin:" + vin + "??", e);
            }
        }
    }
}

From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionDto.java

public void setName(final String name) {
    this.name = StringUtils.strip(name);
}

From source file:com.neusoft.mid.clwapi.service.news.NewsServiceImpl.java

/**
 * ???//from www.j  a va2s  .  co  m
 * 
 * @param token
 *            
 * @param body
 *            ?
 * @return
 */
@Override
public Object getNewsSummaryInfo(String token, String body) {
    logger.info("????");

    // ??
    NewsRequ iNewsRequ = JacksonUtils.fromJsonRuntimeException(body, NewsRequ.class);
    // ??
    iNewsRequ.setEndTime(StringUtils.strip(iNewsRequ.getEndTime()));
    iNewsRequ.setStartTime(StringUtils.strip(iNewsRequ.getStartTime()));
    iNewsRequ.setNum(StringUtils.strip(iNewsRequ.getNum()));
    iNewsRequ.setType(StringUtils.strip(iNewsRequ.getType()));

    // ??
    logger.info("??");
    if (StringUtils.isEmpty(iNewsRequ.getType())) {
        logger.error("??");
        throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
    } else if (StringUtils.isEmpty(iNewsRequ.getStartTime()) || StringUtils.isEmpty(iNewsRequ.getEndTime())) {
        logger.error("????");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    } else if (HttpConstant.TIME_15_DAY_AGO.equalsIgnoreCase(iNewsRequ.getStartTime())
            && !HttpConstant.TIME_ZERO.equals(iNewsRequ.getEndTime())) {
        logger.error(
                "??-dd15????0");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    // numNumnull??num?
    if (StringUtils.isEmpty(iNewsRequ.getNum())) {
        iNewsRequ.setNum(null);
    } else if (!StringUtils.isNumeric(iNewsRequ.getNum())) {
        logger.error("??num?");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    // ????
    if (!HttpConstant.TIME_ZERO.equals(iNewsRequ.getStartTime())
            && !HttpConstant.TIME_15_DAY_AGO.equalsIgnoreCase(iNewsRequ.getStartTime())) {
        try {
            TimeUtil.parseStringToDate(iNewsRequ.getStartTime(), HttpConstant.TIME_FORMAT);
        } catch (ParseException e) {
            logger.error("????" + e.getMessage());
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }
    }
    if (!HttpConstant.TIME_ZERO.equals(iNewsRequ.getEndTime())) {
        try {
            TimeUtil.parseStringToDate(iNewsRequ.getEndTime(), HttpConstant.TIME_FORMAT);
        } catch (ParseException e) {
            logger.error("?????" + e.getMessage());
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }
    }

    if (HttpConstant.TIME_ZERO.equals(iNewsRequ.getStartTime())) {
        iNewsRequ.setStartTime(null);
    } else if (HttpConstant.TIME_15_DAY_AGO.equalsIgnoreCase(iNewsRequ.getStartTime())) {
        Date dBTime = iCommonMapper.getDBTime();
        Date fifteenDayAgo = TimeUtil.get15Ago(dBTime);
        String startTime = TimeUtil.formatDateToString(fifteenDayAgo, HttpConstant.TIME_FORMAT);
        iNewsRequ.setStartTime(startTime);
    }
    if (HttpConstant.TIME_ZERO.equals(iNewsRequ.getEndTime())) {
        iNewsRequ.setEndTime(null);
    }

    // Type
    if (iNewsRequ.getType().equalsIgnoreCase("-1")) {
        iNewsRequ.setType(null);
    } else if (iNewsRequ.getType().equals("0") || iNewsRequ.getType().equals("1")) {
        // ??????
    } else {
        logger.error("??type");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    // 0

    logger.info("??");
    logger.info("???");

    // ???
    List<NewsInfo> list = iNewsMapper.getNewsList(iNewsRequ);
    logger.debug("list=" + (list == null ? "NULL" : list.size()));

    if (list == null || list.size() == 0) {
        logger.info("???");
        return Response.noContent().build();
    }

    logger.info("????");
    logger.debug("???");
    if (logger.isDebugEnabled()) {
        Iterator<NewsInfo> it = list.iterator();
        while (it.hasNext()) {
            NewsInfo temp = it.next();
            logger.debug(temp.toString());
        }
    }

    // ?
    Map<String, List<NewsInfo>> map = new HashMap<String, List<NewsInfo>>();
    map.put("news", list);

    logger.info("?????");
    return JacksonUtils.toJsonRuntimeException(map);
}