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

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

Introduction

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

Prototype

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

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:com.thruzero.common.core.utils.ExceptionUtilsExt.java

public static String findMethodAtClassFromTrace(final Class<?> clazz) {
    String result = findTraceAt(clazz);
    result = StringUtils.substringBefore(result, "(");
    return StringUtils.substringAfterLast(result, ".");
}

From source file:com.norconex.collector.http.redirect.impl.GenericRedirectURLProvider.java

@Override
public String provideRedirectURL(HttpRequest request, HttpResponse response, HttpContext context) {
    HttpRequest currentReq = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
    HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);

    String originalURL = toAbsoluteURI(currentHost, currentReq);

    //--- Location ---
    Header hl = response.getLastHeader(HttpHeaders.LOCATION);
    if (hl == null) {
        //TODO should throw exception instead?
        LOG.error("Redirect detected to a null Location for: " + toAbsoluteURI(currentHost, currentReq));
        return null;
    }// ww  w .  j a va  2s . c  om
    String redirectLocation = hl.getValue();

    //--- Charset ---
    String charset = null;
    Header hc = response.getLastHeader("Content-Type");
    if (hc != null) {
        String contentType = hc.getValue();
        if (contentType.contains(";")) {
            charset = StringUtils.substringAfterLast(contentType, "charset=");
        }
    }
    if (StringUtils.isBlank(charset)) {
        charset = fallbackCharset;
    }

    //--- Build/fix redirect URL ---
    String targetURL = HttpURL.toAbsolute(originalURL, redirectLocation);
    targetURL = resolveRedirectURL(targetURL, charset);

    if (LOG.isDebugEnabled()) {
        LOG.debug("URL redirect: " + originalURL + " -> " + targetURL);
    }
    return targetURL;
}

From source file:egovframework.com.utl.wed.filter.CkImageSaver.java

protected boolean isAllowFileType(String fileName) {
    boolean isAllow = false;
    if (allowFileTypeArr != null && allowFileTypeArr.length > 0) {
        for (String allowFileType : allowFileTypeArr) {
            if (StringUtils.equalsIgnoreCase(allowFileType, StringUtils.substringAfterLast(fileName, "."))) {
                isAllow = true;/*from www.  j  a v  a2  s  . c o m*/
                break;
            }
        }
    } else {
        isAllow = true;
    }

    return isAllow;
}

From source file:com.oneops.controller.jms.InductorPublisher.java

String getQueue(CmsWorkOrderSimpleBase wo) {
    String queueName = null;//from  ww w  .jav  a2s. c  om
    String location = wo.getCloud().getCiAttributes().get("location");
    if ("true".equals(System.getProperty(USE_SHARED_FLAG))) {
        String cloudName = StringUtils.substringAfterLast(location, "/");
        if (StringUtils.isNotBlank(cloudName)) {
            String prefix = StringUtils.substringBefore(cloudName, "-");
            String queuePrefix = System.getProperty(SHARED_QUEUE_PREFIX + prefix);
            if (StringUtils.isNotBlank(queuePrefix)) {
                queueName = queuePrefix + "." + SHARED_QUEUE;
            }
        }
        if (queueName == null)
            queueName = SHARED_QUEUE;
    } else {
        queueName = (location.replaceAll("/", ".") + QUEUE_SUFFIX).substring(1);
    }
    return queueName;
}

From source file:com.neocotic.blingaer.link.LinkServiceImpl.java

@Override
public Link fetchLinkForShortUrl(String shortUrl) throws IllegalArgumentException {
    if (validateUrl(shortUrl).hasErrors()) {
        throw new IllegalArgumentException("Invalid URL");
    }/*w  ww.  j a  v  a  2 s.c  o  m*/

    return LinkServiceFactory.getLinkService()
            .fetchLink(HashUtils.toNumber(StringUtils.substringAfterLast(shortUrl, "/")));
}

From source file:com.tascape.qa.th.db.TestCase.java

public String formatForLogPath() {
    return String.format("%s.%s.%s.%s", StringUtils.substringAfterLast(this.suiteClass, "."),
            StringUtils.substringAfterLast(this.testClass, "."), this.testMethod,
            this.testDataInfo.isEmpty() ? "" : StringUtils.substringAfterLast(this.testDataInfo, "#"));
}

From source file:cn.wanghaomiao.seimi.http.hc.HcDownloader.java

private Response renderResponse(HttpResponse httpResponse, Request request, HttpContext httpContext) {
    Response seimiResponse = new Response();
    HttpEntity entity = httpResponse.getEntity();
    seimiResponse.setSeimiHttpType(SeimiHttpType.APACHE_HC);
    seimiResponse.setRealUrl(getRealUrl(httpContext));
    seimiResponse.setUrl(request.getUrl());
    seimiResponse.setRequest(request);/* w w  w  . ja va2  s  .c  om*/
    seimiResponse.setMeta(request.getMeta());

    if (entity != null) {
        Header referer = httpResponse.getFirstHeader("Referer");
        if (referer != null) {
            seimiResponse.setReferer(referer.getValue());
        }
        String contentTypeStr = entity.getContentType().getValue().toLowerCase();
        if (contentTypeStr.contains("text") || contentTypeStr.contains("json")
                || contentTypeStr.contains("ajax")) {
            seimiResponse.setBodyType(BodyType.TEXT);
            try {
                seimiResponse.setData(EntityUtils.toByteArray(entity));
                ContentType contentType = ContentType.get(entity);
                Charset charset = contentType.getCharset();
                if (charset == null) {
                    seimiResponse.setContent(new String(seimiResponse.getData(), "ISO-8859-1"));
                    String docCharset = renderRealCharset(seimiResponse);
                    seimiResponse.setContent(
                            new String(seimiResponse.getContent().getBytes("ISO-8859-1"), docCharset));
                    seimiResponse.setCharset(docCharset);
                } else {
                    seimiResponse.setContent(new String(seimiResponse.getData(), charset));
                    seimiResponse.setCharset(charset.name());
                }
            } catch (Exception e) {
                logger.error("no content data");
            }
        } else {
            seimiResponse.setBodyType(BodyType.BINARY);
            try {
                seimiResponse.setData(EntityUtils.toByteArray(entity));
                seimiResponse.setContent(StringUtils.substringAfterLast(request.getUrl(), "/"));
            } catch (Exception e) {
                logger.error("no data can be read from httpResponse");
            }
        }
    }
    return seimiResponse;
}

From source file:de.blizzy.documentr.web.page.PageController.java

@RequestMapping(value = "/{projectName:" + DocumentrConstants.PROJECT_NAME_PATTERN + "}/" + "{branchName:"
        + DocumentrConstants.BRANCH_NAME_PATTERN + "}/" + "{path:" + DocumentrConstants.PAGE_PATH_URL_PATTERN
        + "}", method = { RequestMethod.GET, RequestMethod.HEAD })
@PreAuthorize("hasPagePermission(#projectName, #branchName, #path, VIEW)")
public String getPage(@PathVariable String projectName, @PathVariable String branchName,
        @PathVariable String path, Model model, HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    try {/*from  ww  w .ja  v  a2s . co m*/
        path = Util.toRealPagePath(path);
        PageMetadata metadata = pageStore.getPageMetadata(projectName, branchName, path);

        long lastEdited = metadata.getLastEdited().getTime();
        long authenticationCreated = AuthenticationUtil.getAuthenticationCreationTime(request.getSession());
        long projectEditTime = PageUtil.getProjectEditTime(projectName);
        long lastModified = Math.max(lastEdited, authenticationCreated);
        if (projectEditTime >= 0) {
            lastModified = Math.max(lastModified, projectEditTime);
        }

        long modifiedSince = request.getDateHeader("If-Modified-Since"); //$NON-NLS-1$
        if ((modifiedSince >= 0) && (lastModified <= modifiedSince)) {
            return ErrorController.notModified();
        }

        response.setDateHeader("Last-Modified", lastModified); //$NON-NLS-1$
        response.setDateHeader("Expires", 0); //$NON-NLS-1$
        response.setHeader("Cache-Control", "must-revalidate, private"); //$NON-NLS-1$ //$NON-NLS-2$

        Page page = pageStore.getPage(projectName, branchName, path, false);
        model.addAttribute("path", path); //$NON-NLS-1$
        model.addAttribute("pageName", //$NON-NLS-1$
                path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path); //$NON-NLS-1$ //$NON-NLS-2$
        model.addAttribute("parentPagePath", page.getParentPagePath()); //$NON-NLS-1$
        model.addAttribute("title", page.getTitle()); //$NON-NLS-1$
        String viewRestrictionRole = page.getViewRestrictionRole();
        model.addAttribute("viewRestrictionRole", //$NON-NLS-1$
                (viewRestrictionRole != null) ? viewRestrictionRole : StringUtils.EMPTY);
        model.addAttribute("commit", metadata.getCommit()); //$NON-NLS-1$
        return "/project/branch/page/view"; //$NON-NLS-1$
    } catch (PageNotFoundException e) {
        return ErrorController.notFound("page.notFound"); //$NON-NLS-1$
    }
}

From source file:com.vip.saturn.job.console.domain.RegistryCenterConfiguration.java

public void initNameAndNamespace(String nameAndNamespace) {
    this.namespace = StringUtils.substringAfterLast(nameAndNamespace, SLASH);
    this.name = StringUtils.substringBeforeLast(nameAndNamespace, SLASH);
}

From source file:com.thruzero.common.core.support.EntityPath.java

/**
 * Construct an instance from the given {@code entityPath}, which must begin but not end with a "/".
 *///from ww w  . ja va 2s  . c om
public EntityPath(String entityPath) {
    if (StringUtils.isEmpty(entityPath)) {
        throw new RuntimeException("Invalid entity path. Path can't be empty.");
    }

    // Ensure path begins with CONTAINER_PATH_SEPARATOR
    if (!entityPath.startsWith(ContainerPath.CONTAINER_PATH_SEPARATOR)) {
        entityPath = ContainerPath.CONTAINER_PATH_SEPARATOR + entityPath;
    }

    // split container and name
    String containerPathAsString = StringUtils.substringBeforeLast(entityPath,
            ContainerPath.CONTAINER_PATH_SEPARATOR);
    rootDataStorePath = null;
    containerPath = new ContainerPath(
            StringUtils.isEmpty(containerPathAsString) ? ContainerPath.CONTAINER_PATH_SEPARATOR
                    : containerPathAsString + ContainerPath.CONTAINER_PATH_SEPARATOR);
    entityName = StringUtils.substringAfterLast(entityPath, ContainerPath.CONTAINER_PATH_SEPARATOR);
}