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

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

Introduction

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

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:edu.sjsu.cohort6.openstack.server.filter.BasicAuthenticationFilter.java

@Override
public void handle(Request request, Response response) throws Exception {
    final String encodedHeader = StringUtils.substringAfter(request.headers("Authorization"), "Basic");

    if (!authenticatedWith(credentialsFrom(encodedHeader))) {
        //response.header("WWW-Authenticate", "Basic"); -- intentionally commenting out since we dont want
        // the browser to prompt.
        halt(HttpConstants.HTTP_NOT_AUTHORIZED);
    }/*from ww w.  ja va 2s  . com*/
}

From source file:com.inkubator.hrm.util.HrmUserInfoUtil.java

public static Boolean isValidRemoteAddress() throws Exception {
    HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance()
            .getExternalContext().getRequest();
    String ipClient = IpUtil.getIpFromRequest(httpServletRequest);
    String riversIp = StringUtils.reverse(ipClient);
    String ipHeaderReverse = StringUtils.substringAfter(riversIp, ".");
    String ipEnd = StringUtils.substringBefore(riversIp, ".");
    int ipLast = Integer.parseInt(StringUtils.reverse(ipEnd));
    LOGGER.info("Nilai Ip " + IpUtil.getIpFromRequest(httpServletRequest));
    String ip = StringUtils.remove(ipHeaderReverse, ".");
    int ipHeader = Integer.parseInt(StringUtils.reverse(ip));
    IpPermitService ipPermitService = (IpPermitService) ServiceWebUtil.getService("ipPermitService");
    List<IpPermit> dataToCheck = ipPermitService.getByIpHeader(ipHeader);
    for (IpPermit ipPermit : dataToCheck) {
        int fromAddres2 = ipPermit.getUntilAddress1();
        int untilAddress2 = ipPermit.getUntilAddress2();
        if (ipLast >= fromAddres2 && ipLast <= untilAddress2) {
            return Boolean.TRUE;
        }/*from   w  w w . j a va2  s  .  co  m*/
    }
    return Boolean.FALSE;
}

From source file:io.github.bluemarlin.ui.searchtree.SearchFile.java

public SearchFile(File file) throws IOException {
    List<String> lines = FileUtils.readLines(file, "UTF-8");

    List<String> comments = lines.stream().filter(l -> l.startsWith("`")).collect(Collectors.toList());

    renderer = comments.stream().filter(c -> c.contains("$renderer")).findFirst().orElse("default");

    if ("default".equals(renderer)) {
        renderer = BluemarlinConfig.defaultRenderer();
    } else {/*  w  ww.  j  a v a2 s  .co m*/
        renderer = StringUtils.substringAfter(renderer, "=");
    }

    int twentyMinsInMillis = 20 * 60 * 1000;
    long timeNowInMillis = (new Date()).getTime();
    String twentyMinsAgoInMillis = String.valueOf(timeNowInMillis - twentyMinsInMillis);
    jsonSearch = lines.stream().filter(l -> !l.startsWith("`"))
            .map(l -> l.replace("$DEFAULT_LEAGUE", BluemarlinConfig.defaultLeague()))
            .map(l -> l.replace("$TWENTY_MINS_AGO_IN_MILLISEC", twentyMinsAgoInMillis))
            .collect(Collectors.joining(System.lineSeparator()));
}

From source file:com.inkubator.hrm.service.impl.RiwayatAccessMessagesListener.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
public void onMessage(Message message) {
    try {//from  www . ja  v  a2s.  c o  m
        TextMessage textMessage = (TextMessage) message;
        String json = textMessage.getText();
        RiwayatAkses riwayatAccess = (RiwayatAkses) jsonConverter.getClassFromJson(json, RiwayatAkses.class);
        riwayatAccess.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(14)));
        String data = StringUtils.substringAfter(riwayatAccess.getPathUrl(), riwayatAccess.getContextPath());
        HrmMenu hrmMenu = hrmMenuDao.getByPathRelative(data);
        riwayatAccess.setHrmMenu(hrmMenu);
        //            String b = StringUtils.reverse(riwayatAccess.getPathUrl());
        //            String c = StringUtils.substringBefore(b, "/");
        //            String d = StringUtils.reverse(c);
        //            riwayatAccess.setName(d);
        //            if (StringUtils.containsOnly(c, "htm")) {
        //                d = StringUtils.substringAfter(c, ".");
        //                riwayatAccess.setName(StringUtils.reverse(d));
        //            }
        riwayatAksesDao.save(riwayatAccess);
    } catch (JMSException | NumberFormatException ex) {
        LOGGER.error("Error", ex);
    }
}

From source file:com.yqboots.fss.core.support.FileItemConsumer.java

/**
 * {@inheritDoc}//from www  .ja v  a 2 s .  co m
 */
@Override
public void accept(final Path path) {
    final File file = path.toFile();
    final FileItem item = new FileItem();
    item.setName(file.getName());

    String relativePath = StringUtils.substringAfter(file.getPath(), root.toString());
    item.setPath(relativePath.replace("\\", "/"));
    item.setLength(file.length());
    item.setLastModifiedDate(
            LocalDateTime.ofInstant(new Date(file.lastModified()).toInstant(), ZoneId.systemDefault()));
    items.add(item);
}

From source file:io.knotx.launcher.SystemPropsConfiguration.java

private boolean onlyPropertyForIdentifier(Entry<Object, Object> entry, String identifier) {
    boolean result = false;

    String key = (String) entry.getKey();
    if (key.startsWith(identifier)) {
        if (StringUtils.isBlank(StringUtils.substringAfter(key, identifier + "."))) {
            LOGGER.warn("-D{}={} does not have specified key after Service name", key, entry.getValue());
        } else {/*  w  ww. j ava2  s  .c  om*/
            result = true;
        }
    }

    return result;
}

From source file:com.u2apple.rt.db.service.RecognitionErrorDetectServcie.java

private String getModelByProductId(String productId) {
    String brand = null;//from  w w  w . j av a  2s  .c  om
    if (StringUtils.isNotBlank(productId)) {
        brand = StringUtils.substringAfter(productId, "-");
    }
    return brand;
}

From source file:com.muk.services.processor.BasicAuthPrincipalProcessor.java

@Override
public void process(Exchange exchange) throws Exception {
    @SuppressWarnings("unchecked")
    final List<Header> httpHeaders = exchange.getIn().getHeader("org.restlet.http.headers", List.class);

    String userpass = "bad:creds";
    for (final Header header : httpHeaders) {
        if (header.getName().toLowerCase().equals(HttpHeaders.AUTHORIZATION.toLowerCase())) {
            userpass = new String(Base64.decodeBase64(
                    (StringUtils.substringAfter(header.getValue(), " ").getBytes(StandardCharsets.UTF_8))),
                    StandardCharsets.UTF_8);
            break;
        }//from   w w w.jav  a  2s  .  co m
    }

    final String[] tokens = userpass.split(":");

    // create an Authentication object
    // build a new bearer token type
    final UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(tokens[0],
            tokens[1]);

    // wrap it in a Subject
    final Subject subject = new Subject();
    subject.getPrincipals().add(authToken);

    // place the Subject in the In message
    exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject);
}

From source file:lolthx.autohome.buy.AutohomePriceListFetch.java

@Override
public void parse(String result, Task task) throws Exception {
    if (StringUtils.isBlank(result)) {
        return;/*from  w  ww.  ja v  a  2  s .  c  o  m*/
    }

    Date start = task.getStartDate();
    Date end = task.getEndDate();

    Document doc = Jsoup.parse(result);
    Elements lis = doc.select("li.price-item");

    AutohomePriceInfoBean bean = new AutohomePriceInfoBean();

    for (Element li : lis) {

        try {
            Elements postTimeEl = li.select("div.user-name span");
            String postTime = "";
            if (!postTimeEl.isEmpty()) {
                postTime = StringUtils.trim(
                        StringUtils.substringBefore(postTimeEl.first().text(), "?").replaceAll("", ""));

                if (!isTime(postTime, start, end)) {
                    continue;
                }
            }
            bean.setPostTime(postTime);
            bean.setUrl(task.getUrl());
            bean.setForumId(StringUtils.substringBefore(task.getExtra(), ":"));
            bean.setProjectName(task.getProjectName());
            bean.setKeyword(StringUtils.substringAfter(task.getExtra(), ":"));

            // post id
            Elements id = li.select("div.price-share a.share");
            if (!id.isEmpty()) {
                String idStr = id.first().attr("data-target");
                idStr = StringUtils.substringAfterLast(idStr, "_");
                if (StringUtils.isBlank(idStr)) {
                    continue;
                }

                bean.setId(idStr);
            }

            // 
            Elements user = li.select("div.user-name a");
            if (!user.isEmpty()) {
                String userUrl = user.first().absUrl("href");
                String userId = StringUtils.substringAfterLast(userUrl, "/");
                String userName = user.first().text();

                bean.setUserId(userId);
                bean.setUserUrl(userUrl);
                bean.setUserName(userName);
            }

            Elements dataLis = li.select("div.price-item-bd li");
            for (Element dataLi : dataLis) {
                String data = dataLi.text();

                if (StringUtils.startsWith(data, "")) {
                    bean.setCar(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setPrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setGuidePrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "?")) {
                    bean.setTotalPrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setPurchaseTax(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "?")) {
                    bean.setCommercialInsurance(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setVehicleUseTax(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setCompulsoryInsurance(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setLicenseFee(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "?")) {
                    bean.setPromotion(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setBuyTime(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    String area = StringUtils.trim(StringUtils.substringAfter(data, ""));
                    String[] pAndC = StringUtils.splitByWholeSeparator(area, ",", 2);

                    if (pAndC.length == 1) {
                        bean.setBuyProvince(pAndC[0]);
                        bean.setBuyCity(pAndC[0]);
                    }

                    if (pAndC.length == 2) {
                        bean.setBuyProvince(pAndC[0]);
                        bean.setBuyCity(pAndC[1]);
                    }

                }
                if (StringUtils.startsWith(data, "")) {
                    Elements level = dataLi.select("span.level");
                    // 
                    if (!level.isEmpty()) {
                        bean.setSellerComment(level.first().text());
                    }

                    // ?
                    Elements seller = dataLi.select("a.title");
                    if (!seller.isEmpty()) {
                        String sellerUrl = seller.first().absUrl("href");
                        String sellerName = seller.first().text();
                        String sellerId = StringUtils.substringAfterLast(sellerUrl, "/");

                        bean.setSellerId(sellerId);
                        bean.setSellerName(sellerName);
                        bean.setSellerUrl(sellerUrl);
                    }

                    // ?
                    Elements sellerPhone = dataLi.select("em.phone-num");
                    if (!sellerPhone.isEmpty()) {
                        bean.setSellerPhone(sellerPhone.first().text());
                    }

                    // ?
                    // Elements sellerAddress =
                    // dataLi.select("em.phone-num");

                }
                if (StringUtils.startsWith(data, "?")) {
                    bean.setBuyFeeling(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
            }
            bean.saveOnNotExist();
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
    }
}

From source file:com.iorga.iraj.json.ContextParamsContextCaller.java

public ContextParamsContextCaller(final String elementName, final AnnotatedElement annotatedElement,
        final Class<?> declaringClass, final ContextParams contextParamsAnnotation) {
    final ContextPath contextPathAnnotation = annotatedElement.getAnnotation(ContextPath.class);
    // First we have to know what is the first context path part of the target annotated member
    final String nextPath;
    if (contextPathAnnotation != null) {
        // the context path is not null, let's take the first element as a key for the context map
        final String contextPath = contextPathAnnotation.value();
        contextMapKey = StringUtils.substringBefore(contextPath, ".");
        nextPath = StringUtils.substringAfter(contextPath, ".");
    } else {/*from w w w .j  av  a  2  s  . c o m*/
        // No @ContextPath, let's take the elementName
        contextMapKey = elementName;
        nextPath = null;
    }

    // Now search the @ContextParam corresponding to the targetAnnotatedMember
    ContextCaller nextContextCaller = null;
    Type returnType = null;
    for (final ContextParam contextParam : contextParamsAnnotation.value()) {
        String contextName = contextParam.name();
        final Class<?> contextClass = contextParam.value();
        if (StringUtils.isBlank(contextName)) {
            contextName = StringUtils.uncapitalize(contextClass.getSimpleName());
        }
        if (contextMapKey.equals(contextName)) {
            // we have our @ContextParam now let's try to know if there is a "nextContextCaller"
            if (StringUtils.isEmpty(nextPath)) {
                // finished to handle the path, there is no other caller
                nextContextCaller = null;
                returnType = TemplateUtils.getGenericType(contextParam);
            } else {
                nextContextCaller = new ObjectContextCaller(contextClass, nextPath);
                returnType = nextContextCaller.getReturnType();
            }
            break;
        }
    }
    if (returnType == null) {
        throw new IllegalArgumentException(
                "Couln't find the @ContextParam corresponding to " + contextMapKey + " in " + declaringClass);
    } else {
        this.nextContextCaller = nextContextCaller;
        this.returnType = returnType;
    }
}