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.incapture.apigen.slate.Rapture2SlateGenerator.java

private String readResource(String resource) throws IOException {
    InputStream stream = getClass().getResourceAsStream(resource);
    String data = StringUtils.strip(IOUtils.toString(stream));
    stream.close();//from  w  w  w .  j  a  v a  2 s.  c  om
    return data;
}

From source file:com.adobe.ac.pmd.rules.core.AbstractFlexRule.java

private String computeStrippedLine(final String violatedLine) {
    final String comment_token = getCurrentFile().isMxml() ? MXML_COMMENT_TOKEN : AS3_COMMENT_TOKEN;
    String strippedLine = violatedLine;

    if (violatedLine.indexOf(comment_token + " N") > 0) {
        strippedLine = StringUtils.strip(violatedLine.substring(violatedLine.indexOf(comment_token + " N")));
    } else if (violatedLine.indexOf(comment_token + "N") > 0) {
        strippedLine = StringUtils.strip(violatedLine.substring(violatedLine.indexOf(comment_token + "N")));
    }/*  w  w w.  j  a  v a  2s  .c  o m*/
    return strippedLine;
}

From source file:com.neusoft.mid.clwapi.service.statistics.StatisticsServiceImpl.java

/**
 * ??./*ww w  .  j  a  v  a2  s . c  om*/
 * 
 * @param token
 *            ?.
 * @param VIN
 *            VIN
 * @param month
 *            ,?yyyymm  LATEST_MONTH
 * @return ??.
 */
@Override
public Response getCarReport(String token, String VIN, String month) {
    VIN = StringUtils.strip(VIN);
    month = StringUtils.strip(month);
    String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
    logger.info("?-?ID:" + epid + ",VIN:" + VIN + "," + month);

    if (CheckRequestParam.isEmpty(epid)) {
        logger.info("?--?ID");
        throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
    }

    Date reportMonth;
    List<CarMonthData> infos;
    //?
    if (HttpConstant.LATEST_MONTH.equals(month)) {
        infos = stMapper.getValidCarReport(VIN);
        if (CheckRequestParam.isEmpty(infos)) {
            logger.info("?-VIN:" + VIN + "???");
            return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                    .header("Pragma", "no-cache").build();
        }

        try {
            reportMonth = TimeUtil.parseStringToDate(infos.get(0).getDateTime(), HttpConstant.MONTH_FORMAT_1);
        } catch (ParseException e) {
            logger.error("?-yyyyMM?" + e.getMessage());
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }
    } else {
        //?
        try {
            reportMonth = TimeUtil.parseStringToDate(month, HttpConstant.MONTH_FORMAT);
        } catch (ParseException e) {
            logger.error("?-yyyyMM?" + e.getMessage());
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }

        if (reportMonth.after(TimeUtil.getLastMonthD())) {
            logger.info("?-??" + month + "?");
            throw new ApplicationException(ErrorConstant.ERROR10004, Response.Status.BAD_REQUEST);
        }

        infos = stMapper.getCarMonthData(month, VIN);
        if (CheckRequestParam.isEmpty(infos)) {
            logger.info("?-VIN:" + VIN + "???");
            return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                    .header("Pragma", "no-cache").build();
        }
    }

    CarStatReport statInfo = convertCarResp(infos, reportMonth);
    if (CheckRequestParam.isEmpty(statInfo)) {
        logger.info("?-VIN:" + VIN + "???");
        return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                .header("Pragma", "no-cache").build();
    }
    return Response.ok(JacksonUtils.toJsonRuntimeException(statInfo))
            .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build();
}

From source file:com.neusoft.mid.clwapi.service.msg.MsgServiceImpl.java

/**
 * ????.//from w w  w  .  j av  a 2  s  .c o m
 * @param reqChannel
 */
public void checkPicChannel(String reqChannel) {
    String[] channelArray = StringUtils.split(StringUtils.strip(reqChannel), "|");
    for (String channelTemp : channelArray) {
        if (!("1".equals(channelTemp) || "2".equals(channelTemp) || "3".equals(channelTemp)
                || "4".equals(channelTemp))) {
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }
    }
}

From source file:com.neusoft.mid.clwapi.service.homePage.HomePageServiceImpl.java

/**
 * ??// w w w  .  j a v  a  2 s  . co  m
 * 
 * @param region
 *            ?(?uri)
 * @return ?
 */
@Override
public String getWeather(String token, String region) {
    logger.info("???");
    logger.info("??[ " + region + " ]?");

    region = StringUtils.strip(region);

    try {
        region = URLDecoder.decode(region, HttpConstant.CHARSET);
    } catch (UnsupportedEncodingException e) {
        logger.error("URL?" + e.getMessage());
        throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
    }
    logger.info("URL?[ " + region + " ]");

    if (region == null || region.equals("null")) {
        logger.error("?????NULL");
        throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
    }

    //2014-03-14 by wuxja ?
    MemcacheCache cache = (MemcacheCache) memcacheCacheManager.getCache("CLW_API_CACHE");
    WeatherInfoResp iWeatherInfoResp = null;
    logger.info("dd" + cache.get("WEATHER_" + region));
    if (cache.get("WEATHER_" + region) != null)
        iWeatherInfoResp = (WeatherInfoResp) cache.get("WEATHER_" + region).get();
    else {
        iWeatherInfoResp = WeatherReport.getWeatherInfo(region);
        iWeatherInfoResp.setValidSeconds(18000);
        cache.put("WEATHER_" + region, iWeatherInfoResp);
    }
    logger.info("????");
    return JacksonUtils.toJsonRuntimeException(iWeatherInfoResp);
}

From source file:com.activecq.experiments.redis.impl.RedisResourceProviderImpl.java

private void configure(final ComponentContext componentContext) {
    final Map<String, String> properties = (Map<String, String>) componentContext.getProperties();

    // Get Roots from Service properties
    this.roots = new ArrayList<String>();

    String[] rootsArray = PropertiesUtil.toStringArray(properties.get(ResourceProvider.ROOTS), new String[] {});
    for (String root : rootsArray) {
        root = StringUtils.strip(root);
        if (StringUtils.isBlank(root)) {
            continue;
        } else if (StringUtils.equals(root, "/")) {
            // Cowardly refusing to mount the root
            continue;
        }/*  ww w  .j  a  va 2s  .  c o  m*/

        this.roots.add(StringUtils.removeEnd(root, "/"));
    }
}

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

/**
 * ??//from w w  w .  ja  v a  2s . com
 * 
 * @param token
 *            
 * @param body
 *            ?
 * @return
 */
@Override
public String checkNewsInfo(String token, String body) {
    logger.info("???");
    logger.info("??");

    CheckNewsRequ iCheckNewsRequ = JacksonUtils.fromJsonRuntimeException(body, CheckNewsRequ.class);
    // ???ID
    iCheckNewsRequ.setUsrId(context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID));

    // ??
    if (StringUtils.isBlank(iCheckNewsRequ.getNewsId()) || StringUtils.isBlank(iCheckNewsRequ.getNewsTime())
            || StringUtils.isBlank(iCheckNewsRequ.getNewsType())) {
        logger.error("??");
        throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
    }

    // ?
    iCheckNewsRequ.setNewsId(StringUtils.strip(iCheckNewsRequ.getNewsId()));
    iCheckNewsRequ.setNewsTime(StringUtils.strip(iCheckNewsRequ.getNewsTime()));
    iCheckNewsRequ.setNewsType(StringUtils.strip(iCheckNewsRequ.getNewsType()));

    // ??
    logger.info("ID:" + iCheckNewsRequ.getUsrId());
    logger.info("?ID:" + iCheckNewsRequ.getNewsId());
    logger.info("??:" + iCheckNewsRequ.getNewsTime());
    logger.info("?:" + iCheckNewsRequ.getNewsType());

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

    // ?ID?ID??
    CheckNewsInfo iCheckNewsInfo = iNewsMapper.getCheckNewsInfo(iCheckNewsRequ);

    // ????
    if (iCheckNewsInfo == null) {
        logger.info("??");
        iNewsMapper.addCheckNewsInfo(iCheckNewsRequ);
        logger.info("?");
    } else {
        logger.info("???");
        // 
        iCheckNewsInfo.setCount(String.valueOf(Integer.valueOf(iCheckNewsInfo.getCount()) + 1));
        logger.debug("??" + iCheckNewsInfo.toString());
        iNewsMapper.updateCheckNewsInfo(iCheckNewsInfo);
        logger.info("?");
    }

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

    return HttpConstant.RESP_200;
}

From source file:io.apiman.plugins.keycloak_oauth_policy.KeycloakOauthPolicy.java

private String getRawAuthToken(ApiRequest request) {
    String rawToken = StringUtils.strip(request.getHeaders().get(AUTHORIZATION_KEY));

    if (rawToken != null && StringUtils.startsWithIgnoreCase(rawToken, BEARER)) {
        rawToken = StringUtils.removeStartIgnoreCase(rawToken, BEARER);
    } else {//from  www.  j a  v a 2s.c  om
        rawToken = request.getQueryParams().get(ACCESS_TOKEN_QUERY_KEY);
    }

    return rawToken;
}

From source file:biz.netcentric.cq.tools.actool.validators.impl.AuthorizableValidatorImpl.java

public boolean validateMembers(final AuthorizableConfigBean tmpPrincipalConfigBean)
        throws InvalidGroupNameException {
    final String currentPrincipal = tmpPrincipalConfigBean.getPrincipalID();
    final String currentEntryValue = tmpPrincipalConfigBean.getMembersStringFromConfig();
    if (StringUtils.isNotBlank(currentEntryValue)) {
        if (currentEntryValue != null) {

            final String[] groups = currentEntryValue.split(",");

            for (int i = 0; i < groups.length; i++) {

                // remove leading and trailing blanks from groupname
                groups[i] = StringUtils.strip(groups[i]);

                if (!Validators.isValidAuthorizableId(groups[i])) {
                    LOG.error(//from   w  ww . ja va2s. co  m
                            "Validation error while reading group property of authorizable:{}, invalid authorizable name: {}",
                            currentPrincipal, groups[i]);
                    throw new InvalidGroupNameException(
                            "Validation error while reading group property of authorizable: " + currentPrincipal
                                    + ", invalid group name: " + groups[i]);
                }
            }

            tmpPrincipalConfigBean.setMembers(groups);

        }
    }
    return true;
}

From source file:com.inet.web.service.mail.MailComposerService.java

/**
 * @param object//www  .  j  a va  2  s  .com
 * @return
 */
private IMessageComposer createComposer(JSONObject object, long contentId) {
    MailAcctConfigInfo configure = bridgeBO.loadMailConfig();
    String from = WebCommonService.toString(object, MailConstants.FROM);

    String displayName = StringService.hasLength(configure.getFullname()) ? configure.getFullname()
            : getFullName();

    // get mail configuration.
    AbstractMailFactory factory = MailConfigureFactory.createFactory();

    // create message composer.

    // priority
    String priorityStr = WebCommonService.toString(object, MailConstants.MAIL_PRIORITY);
    MailPriority priority = MailPriority.valueOf(priorityStr);

    IMessageComposer composer = factory.createMessage(true, priority);

    // set from address.
    composer.setFrom(new Address(displayName, from));

    //set subject
    composer.setSubject(StringUtils.strip(WebCommonService.toString(object, MailConstants.SUBJECT)));

    // set To address.
    String toAddress = WebCommonService.toString(object, MailConstants.TO);
    if (StringService.hasLength(toAddress)) {
        // parses to addresses.
        Address[] addresses = AddressParser.parseHeader(toAddress);
        for (Address addr : addresses) {
            composer.addTo(addr.getFullAddress());
        }
    }

    //set CC address.
    String ccAddress = WebCommonService.toString(object, MailConstants.CC);
    if (StringService.hasLength(ccAddress)) {
        // parses to addresses.
        Address[] addresses = AddressParser.parseHeader(ccAddress);
        for (Address addr : addresses) {
            composer.addCC(addr.getFullAddress());
        }
    }

    //set BCC address.
    String bccAddress = WebCommonService.toString(object, MailConstants.BCC);
    if (StringService.hasLength(bccAddress)) {
        // parses to addresses.
        Address[] addresses = AddressParser.parseHeader(bccAddress);
        for (Address addr : addresses) {
            composer.addBCC(addr.getFullAddress());
        }
    }

    //set body text
    String body = WebCommonService.toString(object, MailConstants.BODY_TEXT);

    // convert this html string to TEXT String
    composer.setBody(body);

    // set attachment
    addAttchment(composer, object, contentId);

    return composer;
}