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:org.craftercms.engine.url.ToTargetedUrlTransformer.java

@Override
public String transformUrl(Context context, CachingOptions cachingOptions, String url)
        throws UrlTransformationException {
    if (SiteProperties.isTargetingEnabled() && !TargetingUtils.excludePath(url)) {
        String rootFolder = TargetingUtils.getMatchingRootFolder(url);
        if (StringUtils.isNotEmpty(rootFolder)) {
            String relativeUrl = StringUtils.substringAfter(url, rootFolder);
            String targetedUrl = targetedUrlStrategy.toTargetedUrl(relativeUrl, forceCurrentTargetId);

            return UrlUtils.concat(rootFolder, targetedUrl);
        }/*from  ww w .j av  a2 s  . c  om*/
    }

    return url;
}

From source file:org.craftercms.engine.util.breadcrumb.BreadcrumbBuilder.java

public List<BreadcrumbItem> buildBreadcrumb(final String url) {
    final Context context = SiteContext.getCurrent().getContext();

    return cacheTemplate.getObject(context, new Callback<List<BreadcrumbItem>>() {

        @Override//from www.ja va 2  s  .  co  m
        public List<BreadcrumbItem> execute() {
            String indexFileName = SiteProperties.getIndexFileName();
            CachingAwareList<BreadcrumbItem> breadcrumb = new CachingAwareList<BreadcrumbItem>();
            String breadcrumbUrl = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, homePath),
                    indexFileName);
            String[] breadcrumbUrlComponents = breadcrumbUrl.split("/");
            String currentUrl = homePath;

            for (String breadcrumbUrlComponent : breadcrumbUrlComponents) {
                if (StringUtils.isNotEmpty(breadcrumbUrlComponent)) {
                    currentUrl += "/" + breadcrumbUrlComponent;
                }

                Item item = storeService.getItem(context, UrlUtils.concat(currentUrl, indexFileName));
                if (item != null && item.getDescriptorDom() != null) {
                    String breadcrumbName = item.queryDescriptorValue(breadcrumbNameXPathQuery);
                    if (StringUtils.isEmpty(breadcrumbName)) {
                        if (StringUtils.isNotEmpty(breadcrumbUrlComponent)) {
                            breadcrumbName = StringUtils
                                    .capitalize(breadcrumbUrlComponent.replace("-", " ").replace(".xml", ""));
                        } else {
                            breadcrumbName = HOME_BREADCRUMB_NAME;
                        }
                    }

                    breadcrumb.add(new BreadcrumbItem(currentUrl, breadcrumbName));
                    breadcrumb.addDependencyKey(item.getKey());
                }
            }

            return breadcrumb;
        }

    }, url, BREADCRUMB_CONST_KEY_ELEM);
}

From source file:org.craftercms.studio.impl.v1.asset.processing.AssetProcessingConfigReaderImpl.java

private Map<String, String> getProcessorParams(HierarchicalConfiguration processorConfig) {
    Map<String, String> params = new HashMap<>();
    Iterator<String> keysIter = processorConfig.getKeys();
    String paramsPrefix = PROCESSOR_PARAMS_CONFIG_KEY + ".";

    while (keysIter.hasNext()) {
        String key = keysIter.next();

        if (key.startsWith(paramsPrefix)) {
            String paramName = StringUtils.substringAfter(key, paramsPrefix);
            String paramValue = processorConfig.getString(key);

            params.put(paramName, paramValue);
        }/*from  www  .jav  a2 s .  com*/
    }

    return params;
}

From source file:org.cryptomator.crypto.aes256.Aes256Cryptor.java

/**
 * @see #encryptPathComponent(String, SecretKey, CryptorIOSupport)
 *//*from w  ww . j  a va2  s.  c  o m*/
private String decryptPathComponent(final String encrypted, final SecretKey key, CryptorIOSupport ioSupport)
        throws IllegalBlockSizeException, BadPaddingException, IOException {
    final String ivAndCiphertext;
    if (encrypted.endsWith(LONG_NAME_FILE_EXT)) {
        final String basename = StringUtils.removeEnd(encrypted, LONG_NAME_FILE_EXT);
        final String crc32 = StringUtils.substringBefore(basename, LONG_NAME_PREFIX_SEPARATOR);
        final String uuid = StringUtils.substringAfter(basename, LONG_NAME_PREFIX_SEPARATOR);
        final String metadataFilename = crc32 + METADATA_FILE_EXT;
        final LongFilenameMetadata metadata = this.getMetadata(ioSupport, metadataFilename);
        ivAndCiphertext = metadata.getEncryptedFilenameForUUID(UUID.fromString(uuid));
    } else if (encrypted.endsWith(BASIC_FILE_EXT)) {
        ivAndCiphertext = StringUtils.removeEndIgnoreCase(encrypted, BASIC_FILE_EXT);
    } else {
        throw new IllegalArgumentException("Unsupported path component: " + encrypted);
    }

    final String partialIvStr = StringUtils.substringBefore(ivAndCiphertext, IV_PREFIX_SEPARATOR);
    final String ciphertext = StringUtils.substringAfter(ivAndCiphertext, IV_PREFIX_SEPARATOR);
    final ByteBuffer iv = ByteBuffer.allocate(AES_BLOCK_LENGTH);
    iv.put(ENCRYPTED_FILENAME_CODEC.decode(partialIvStr));

    final Cipher cipher = this.aesCtrCipher(key, iv.array(), Cipher.DECRYPT_MODE);
    final byte[] encryptedBytes = ENCRYPTED_FILENAME_CODEC.decode(ciphertext);
    final byte[] paddedCleartextBytes = cipher.doFinal(encryptedBytes);

    // remove NULL padding (not valid in file names anyway)
    final int beginOfPadding = ArrayUtils.indexOf(paddedCleartextBytes, (byte) 0x00);
    if (beginOfPadding == -1) {
        return new String(paddedCleartextBytes, StandardCharsets.UTF_8);
    } else {
        final byte[] cleartextBytes = Arrays.copyOf(paddedCleartextBytes, beginOfPadding);
        return new String(cleartextBytes, StandardCharsets.UTF_8);
    }
}

From source file:org.debux.webmotion.server.WebMotionServer.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
    HttpServletResponse httpServletResponse = ((HttpServletResponse) response);
    ServerContext serverContext = getServerContext(httpServletRequest);

    String uri = null;/*www  .j a v  a 2s.  c  o  m*/
    DispatcherType dispatcherType = request.getDispatcherType();
    if (dispatcherType == DispatcherType.INCLUDE) {
        uri = (String) httpServletRequest.getAttribute(HttpContext.ATTRIBUTE_INCLUDE_REQUEST_URI);
    }
    if (uri == null) {
        uri = httpServletRequest.getRequestURI();
    }

    String contextPath = httpServletRequest.getContextPath();
    String url = StringUtils.substringAfter(uri, contextPath);
    log.debug("Pass in filter = " + url);

    // Search if url is exclude path
    for (String path : serverContext.getExcludePaths()) {
        if (url.startsWith(path)) {
            url = PATH_SERVLET + url;
            break;
        }
    }

    if (url.startsWith(PATH_DEPLOY) || url.startsWith(PATH_ERROR) || url.equals("/")) {
        log.debug("Is deploy");
        doAction(httpServletRequest, httpServletResponse);

    } else if (url.startsWith(PATH_STATIC)) {
        log.debug("Is static");
        doResource(httpServletRequest, httpServletResponse);

    } else if (url.startsWith(PATH_SERVLET)) {
        log.debug("Is servlet");
        chain.doFilter(request, response);

    } else {
        String webappPath = serverContext.getWebappPath();
        File file = new File(webappPath, url);
        if (file.exists()) {
            // css js html png jpg jpeg xml ...
            log.debug("Is file");
            chain.doFilter(request, response);
        } else {
            log.debug("Is default");
            doAction(httpServletRequest, httpServletResponse);
        }
    }
}

From source file:org.debux.webmotion.site.Showcase.java

protected String getFile(String name) throws IOException {
    InputStream stream = Showcase.class.getClassLoader().getResourceAsStream(name);
    String content = IOUtils.toString(stream);
    content = content.replace("/test", "");
    if (content.contains("#L" + "%\n */\n")) {
        content = StringUtils.substringAfter(content, "#L" + "%\n */\n");
    }//from   ww w  .  j av  a2s.c  o m
    if (content.contains("#L" + "%\n  -->\n")) {
        content = StringUtils.substringAfter(content, "#L" + "%\n  -->\n");
    }
    if (content.contains("# #L" + "%\n###\n")) {
        content = StringUtils.substringAfter(content, "# #L%\n###\n");
    }
    if (content.contains("<%--\n  #%" + "L")) {
        content = StringUtils.substringAfter(content, "  #L" + "%\n  --%>\n");
    }
    return content;
}

From source file:org.dederem.common.service.VersionAnalyseService.java

/**
 * Read method for "Packages" file.//www.  ja v  a 2s.  c o m
 *
 * @param input
 *            InputStream on the text file
 * @return The object populated with the content of the file.
 * @throws IOException
 *             I/O error.
 */
public final DebVersion analyzeFile(final String suite, final InputStream input) throws IOException {
    final DebVersion result = new DebVersion();

    final Map<String, StringBuilder> data = new HashMap<>();
    StringBuilder lastData = null; // NOPMD - init

    final BufferedReader reader = new BufferedReader(new InputStreamReader(input, Charsets.UTF_8));
    String line = reader.readLine();
    while (line != null) {
        if (line.isEmpty()) {
            // manage the end of the bloc
            final DebPackageDesc pkgDesc = this.readPackageDesc(data);
            if (pkgDesc != null) {
                // check if file already present in the repository
                final DebPackageDesc local = this.repoService.getPackageInLocalRepo(suite,
                        pkgDesc.getDebPackage());
                if (local == null) {
                    // add the package to package list.
                    result.getPackages().add(pkgDesc);
                } else {
                    if (this.repoService.checkPackageEquality(pkgDesc, local)) {
                        // add the package to package list.
                        result.getPackages().add(local);
                    } else {
                        // add the package to package list.
                        result.getPackages().add(pkgDesc);
                    }
                }
            }
            data.clear();
        } else {
            // manage a new entry in the current bloc
            if (Character.isWhitespace(line.charAt(0))) {
                if (lastData != null) {
                    lastData.append(line);
                }
            } else {
                final String key = StringUtils.substringBefore(line, ":");
                final String value = StringUtils.substringAfter(line, ":");
                lastData = new StringBuilder(value);
                data.put(key, lastData);
            }
        }
        line = reader.readLine();
    }
    result.setSuite(suite);
    return result;
}

From source file:org.fabrician.enabler.util.DockerActivationInfo.java

public DockerActivationInfo inject() {
    info.setProperty(Entry.docker_name.name(), docker.getName());
    info.setProperty(Entry.docker_id.name(), docker.getId());
    info.setProperty(Entry.docker_created.name(), docker.getCreated());
    info.setProperty(Entry.docker_image.name(), docker.getImage());
    info.setProperty(Entry.docker_config.name(),
            StringUtils.substringAfter(docker.getContainerConfig().toString(), "Config"));
    info.setProperty(Entry.docker_state.name(),
            StringUtils.substringAfter(docker.getState().toString(), "State"));
    info.setProperty(Entry.docker_status.name(),
            "Up " + TimeUtil.formatDurationMsg(docker.getState().getStartedAt()));
    info.setProperty(Entry.docker_host_config.name(),
            StringUtils.substringAfter(docker.getHostConfig().toString(), "HostConfig"));
    info.setProperty(Entry.docker_networks.name(),
            StringUtils.substringAfter(docker.getNetworkSettings().toString(), "NetworkSettings"));
    info.setProperty(Entry.docker_volumes.name(), docker.getVolumes().toString());
    info.setProperty(Entry.docker_vol_rw.name(), docker.getvolumesRW().toString());
    return this;
}

From source file:org.flowable.app.rest.service.api.repository.AppDeploymentCollectionResource.java

public Map<String, String> splitQueryString(String queryString) {
    if (StringUtils.isEmpty(queryString)) {
        return Collections.emptyMap();
    }//w w  w .ja va 2  s  . c om
    Map<String, String> queryMap = new HashMap<>();
    for (String param : queryString.split("&")) {
        queryMap.put(StringUtils.substringBefore(param, "="), decode(StringUtils.substringAfter(param, "=")));
    }
    return queryMap;
}

From source file:org.gbif.ipt.action.manage.MappingAction.java

/**
 * Normalizes an incoming column name so that it can later be compared against a ConceptTerm's simpleName.
 * This method converts the incoming string to lower case, and will take the substring up to, but no including the
 * first ":".//from w  ww. j  a  va  2 s.c om
 * 
 * @param col column name
 * @return the normalized column name, or null if the incoming name was null or empty
 */
String normalizeColumnName(String col) {
    if (!Strings.isNullOrEmpty(col)) {
        col = NORM_TERM.matcher(col.toLowerCase()).replaceAll("");
        if (col.contains(":")) {
            col = StringUtils.substringAfter(col, ":");
        }
        return col;
    }
    return null;
}