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:com.epam.ta.reportportal.ws.resolver.FilterCriteriaResolver.java

@SuppressWarnings("unchecked")
private <T> Filter resolveAsList(MethodParameter methodParameter, NativeWebRequest webRequest) {
    Class<T> domainModelType = (Class<T>) methodParameter.getParameterAnnotation(FilterFor.class).value();

    Set<FilterCondition> filterConditions = webRequest.getParameterMap().entrySet().stream()
            .filter(parameter -> parameter.getKey().startsWith(DEFAULT_FILTER_PREFIX)
                    && parameter.getValue().length > 0)
            .map(parameter -> {/*from ww w  . j a  va  2 s.  c o  m*/
                final String[] tokens = parameter.getKey().split("\\.");
                checkTokens(tokens);
                String stringCondition = tokens[1];
                boolean isNegative = stringCondition.startsWith(NOT_FILTER_MARKER);

                Condition condition = getCondition(
                        isNegative ? StringUtils.substringAfter(stringCondition, NOT_FILTER_MARKER)
                                : stringCondition);
                String criteria = tokens[2];
                return new FilterCondition(condition, isNegative, parameter.getValue()[0], criteria);

            }).collect(Collectors.toSet());
    return new Filter(domainModelType, filterConditions);
}

From source file:io.treefarm.plugins.haxe.TestCompileMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    super.execute();

    if (munitCompiler.getHasRequirements()) {

        if (openflIsActive() && testTargets != null && testClasspath != null) {
            String logInfo = "Compiling tests for MassiveUnit using OpenFL ";
            logInfo += (testCoverage ? "WITH code coverage" : "WITHOUT code coverage") + ".";
            if (testDebug) {
                logInfo += "\n *** with debug, so only tests with @TestDebug will be built ***";
            }/*from   ww w  . ja v a2s.c  o  m*/
            getLog().info(logInfo);

            Set<String> classPaths = new HashSet<String>();
            String cleanClassPathList = "";
            try {
                List<String> displayHxml = openflCompiler.displayHxml(project, testTargets.iterator().next(),
                        nmml, null, null, null);
                for (String line : displayHxml) {
                    String classPath = StringUtils.substringAfter(line, "-cp ");
                    if (classPath.length() > 0) {
                        classPaths.add(classPath);
                    }
                }
            } catch (Exception e) {
                throw new MojoFailureException("Tests compilation failed", e);
            }

            compilerFlags = new ArrayList<String>();
            compilerFlags.add("-lib munit");
            compilerFlags.add("-lib hamcrest");
            if (testCoverage && classPaths.size() > 0) {
                compilerFlags.add("-lib mcover");
                compilerFlags.add("-D MCOVER");

                /*String mCoverDirective = "--macro mcover.MCover.coverage\\([\\'\\'],[\\'";
                //String mCoverDirective = "--macro mcover.MCover.coverage([''],['";
                Iterator<String> it = classPaths.iterator();
                String classPath;
                while(it.hasNext()) {
                classPath = it.next();
                if (!StringUtils.contains(classPath, ",")
                        && StringUtils.indexOf(classPath, "/") != 0) {
                    if (cleanClassPathList.length() > 0) {
                        cleanClassPathList += ",";
                    }
                    cleanClassPathList += classPath;
                }
                }
                        
                mCoverDirective += cleanClassPathList + "\\']\\)";
                //mCoverDirective += cleanClassPathList + "'],[''])";
                compilerFlags.add(mCoverDirective);
                getLog().info("mcover call: " + mCoverDirective);*/
            }
            compilerFlags.add("-cp " + testClasspath);

            try {
                if (testRunner == null) {
                    testRunner = TEST_RUNNER;
                }
                if (testHxml == null) {
                    testHxml = TEST_HXML;
                }

                List<String> displayHxml = openflCompiler.displayHxml(project, testTargets, nmml, compilerFlags,
                        testMain, testRunner);

                String hxmlDump = "";
                for (String hxmlLine : displayHxml) {
                    hxmlDump += hxmlLine + "\n";
                }

                File hxmlFile = new File(outputDirectory, testHxml);
                if (hxmlFile.exists()) {
                    FileUtils.deleteQuietly(hxmlFile);
                }
                hxmlFile.createNewFile();
                FileWriter fw = new FileWriter(hxmlFile.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(hxmlDump);
                bw.close();

                if (testResources != null) {
                    File resourcesFile = new File(outputDirectory.getParentFile(), testResources);
                    File tmpResourcesFile = new File(outputDirectory, "tmp_resources");
                    tmpResourcesFile.mkdirs();
                    FileUtils.copyDirectory(resourcesFile, new File(tmpResourcesFile, resourcesFile.getName()));
                    testResources = tmpResourcesFile.getAbsolutePath();
                }

                if (testBinPath == null) {
                    testBinPath = TEST_BIN_PATH;
                }
                File testBinFile = new File(outputDirectory, testBinPath);
                testBinPath = testBinFile.getAbsolutePath();

                munitCompiler.config(testClasspath, testBinPath, testBinPath, cleanClassPathList,
                        hxmlFile.getAbsolutePath(), testResources, testTemplates);
                openflCompiler.initialize(debug, verbose, false, false, true, testDebug);
                openflCompiler.compile(project, testTargets, nmml, compilerFlags, testMain, testRunner, true,
                        false, false);
            } catch (Exception e) {
                throw new MojoFailureException("Tests compilation failed", e);
            }
        } else {
            getLog().info("Compiling tests using MassiveUnit.");

            try {
                munitCompiler.initialize(testDebug, false);
                munitCompiler.setOutputDirectory(outputDirectory);
                munitCompiler.compile(project, null);
            } catch (Exception e) {
                throw new MojoFailureException("Tests compilation failed", e);
            }
        }
    } else {
        getLog().info("Compiling tests using standard Haxe unit testing.");

        if (testRunner == null || project.getTestCompileSourceRoots().size() == 0) {
            getLog().info("No test sources to compile");
            return;
        }

        String output = OutputNamesHelper.getTestOutput(project);
        EnumMap<CompileTarget, String> targets = new EnumMap<CompileTarget, String>(CompileTarget.class);
        targets.put(CompileTarget.neko, output);

        try {
            haxeCompiler.compile(project, targets, testRunner, true, true, verbose);
        } catch (Exception e) {
            throw new MojoFailureException("Tests compilation failed", e);
        }
    }
}

From source file:io.wcm.handler.url.suffix.impl.UrlSuffixUtil.java

/**
 * Decode value//from w  w w . j  a va  2 s  . com
 * @param suffixPart Suffix part
 * @return Decoded value
 */
public static String decodeValue(String suffixPart) {
    // value is the part *after* KEY_VALUE_DELIMITER
    String value = StringUtils.substringAfter(suffixPart, Character.toString(KEY_VALUE_DELIMITER));

    // un-escape special chars
    for (Map.Entry<String, String> entry : SPECIAL_CHARS_ESCAPEMAP.entrySet()) {
        value = StringUtils.replace(value, entry.getValue(), entry.getKey());
    }

    return value;
}

From source file:com.cognifide.qa.bb.scope.frame.FramePath.java

private FramePath addFrame(String path) {
    if (StringUtils.isEmpty(path)) {
        return this;
    }//w ww  .  j  a  v  a 2  s .co m
    final String firstPart = StringUtils.substringBefore(path, "/");
    final String rest = StringUtils.substringAfter(path, "/");

    List<FrameDescriptor> modifiedLocation = new ArrayList<>(frames);
    if (firstPart.isEmpty()) {
        modifiedLocation.clear();
    } else if (firstPart.matches("\\$[0-9]+")) {
        final int index = Integer.parseInt(firstPart.substring(1));
        modifiedLocation.add(new IndexedFrame(index));
    } else if ("$cq".equals(firstPart)) {
        modifiedLocation.clear();
        modifiedLocation.add(AemContentFrame.INSTANCE);
    } else if ("..".equals(firstPart) && !modifiedLocation.isEmpty()) {
        modifiedLocation.remove(modifiedLocation.size() - 1);
    } else {
        modifiedLocation.add(new NamedFrame(firstPart));
    }
    return new FramePath(modifiedLocation).addFrame(rest);
}

From source file:de.blizzy.documentr.markdown.macro.impl.NeighborsMacroTest.java

private void setupPages() throws IOException {
    setupPages(PAGES);//ww  w . j ava  2  s  .co m

    for (String page : PAGES) {
        List<String> childPages = Lists.newArrayList();
        String childPagePrefix = page + "/"; //$NON-NLS-1$
        for (String childPage : PAGES) {
            if (childPage.startsWith(childPagePrefix)) {
                String rest = StringUtils.substringAfter(childPage, childPagePrefix);
                if (!rest.contains("/")) { //$NON-NLS-1$
                    childPages.add(childPage);
                }
            }
        }
        Collections.sort(childPages);
        when(pageStore.listChildPagePaths(PROJECT, BRANCH, page)).thenReturn(childPages);
    }
}

From source file:com.github.benmanes.caffeine.cache.Stresser.java

private void status() {
    local.evictionLock.lock();/*from  www .  ja v  a  2s  .  c  o m*/
    int pendingWrites = local.writeBuffer().size();
    int drainStatus = local.drainStatus();
    local.evictionLock.unlock();

    LocalTime elapsedTime = LocalTime.ofSecondOfDay(stopwatch.elapsed(TimeUnit.SECONDS));
    System.out.printf("---------- %s ----------%n", elapsedTime);
    System.out.printf("Pending reads: %,d; writes: %,d%n", local.readBuffer.size(), pendingWrites);
    System.out.printf("Drain status = %s (%s)%n", STATUS[drainStatus], drainStatus);
    System.out.printf("Evictions = %,d%n", cache.stats().evictionCount());
    System.out.printf("Size = %,d (max: %,d)%n", local.data.mappingCount(), operation.maxEntries);
    System.out.printf("Lock = [%s%n", StringUtils.substringAfter(local.evictionLock.toString(), "["));
    System.out.printf("Pending tasks = %,d%n", ForkJoinPool.commonPool().getQueuedSubmissionCount());

    long maxMemory = Runtime.getRuntime().maxMemory();
    long freeMemory = Runtime.getRuntime().freeMemory();
    long allocatedMemory = Runtime.getRuntime().totalMemory();
    System.out.printf("Max Memory = %,d bytes%n", maxMemory);
    System.out.printf("Free Memory = %,d bytes%n", freeMemory);
    System.out.printf("Allocated Memory = %,d bytes%n", allocatedMemory);

    System.out.println();
}

From source file:keepinchecker.utility.EmailUtilities.java

protected static String getMailServer(String senderEmail) {
    String mailServer = "";

    List<String> googleDomains = Arrays.asList("gmail", "googlemail");
    List<String> microsoftDomains = Arrays.asList("hotmail", "outlook", "msn", "live", "passport");
    List<String> yahooDomains = Arrays.asList("yahoo", "ymail");
    List<String> aolDomains = Arrays.asList("aol", "aim");
    List<String> comcastDomains = Arrays.asList("comcast");
    List<String> verizonDomains = Arrays.asList("verizon");
    List<String> attDomains = Arrays.asList("att");

    // get the domain portion of the email
    String senderEmailDomain = StringUtils.substringAfter(senderEmail, "@");
    // remove the TLD portion
    senderEmailDomain = StringUtils.substringBeforeLast(senderEmailDomain, ".");

    if (googleDomains.contains(senderEmailDomain)) {
        mailServer = GOOGLE_MAIL_SERVER;
    } else if (microsoftDomains.contains(senderEmailDomain)) {
        mailServer = MICROSOFT_MAIL_SERVER;
    } else if (yahooDomains.contains(senderEmailDomain)) {
        mailServer = YAHOO_MAIL_SERVER;//  w  ww .  j a  v  a 2s .  c om
    } else if (aolDomains.contains(senderEmailDomain)) {
        mailServer = AOL_MAIL_SERVER;
    } else if (comcastDomains.contains(senderEmailDomain)) {
        mailServer = COMCAST_MAIL_SERVER;
    } else if (verizonDomains.contains(senderEmailDomain)) {
        mailServer = VERIZON_MAIL_SERVER;
    } else if (attDomains.contains(senderEmailDomain)) {
        mailServer = ATT_MAIL_SERVER;
    }

    return mailServer;
}

From source file:kenh.xscript.elements.Call.java

@Override
public int invoke() throws UnsupportedScriptException {

    logger.info(getInfo());/*from w w w. ja v a  2s.  c  o m*/

    this.getEnvironment().removeVariable(Return.VARIABLE_RETURN); // clear {return}

    // 1) find Method
    Map<String, Element> methods = this.getEnvironment().getMethods();
    String name = getAttribute(ATTRIBUTE_METHOD_NAME);
    if (StringUtils.isBlank(name)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method name is empty.");
        throw ex;
    }
    try {
        name = (String) this.getEnvironment().parse(name);
    } catch (Exception e) {
        throw new UnsupportedScriptException(this, e);
    }
    String var = getAttribute(ATTRIBUTE_RETURN_NAME);
    if (StringUtils.isNotBlank(var)) {
        try {
            var = StringUtils.trimToNull((String) this.getEnvironment().parse(var));
        } catch (Exception e) {
            throw new UnsupportedScriptException(this, e);
        }
    }

    Element e = methods.get(name);
    if (e == null || !(e instanceof Method)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this,
                "Could't find the method to invoke. [" + name + "]");
        throw ex;
    }

    // 2) handle the Method's parameter
    Method m = (Method) e;
    String[][] parameters = m.getParameters();

    Map<String, Object> new_vars = new LinkedHashMap();
    List<String> new_cons = new LinkedList();
    Vector parameterCallback = new Vector();

    for (String[] parameter : parameters) {
        String paraName = StringUtils.trimToEmpty(parameter[0]);
        if (StringUtils.isBlank(paraName))
            continue;

        boolean required = false;
        Object defaultValue = null;

        if (parameter.length > 1) {
            for (int i = 1; i < parameter.length; i++) {
                String modi = StringUtils.trimToEmpty(parameter[i]);
                if (modi.equals(Method.MODI_FINAL)) {
                    new_cons.add(paraName);
                }
                if (modi.equals(Method.MODI_REQUIRED)) {
                    required = true;
                }
                if ((modi.startsWith(Method.MODI_DEFAULT + "(") && modi.endsWith(")"))) {
                    String defaultValue_ = StringUtils.substringAfter(modi, Method.MODI_DEFAULT + "(");
                    defaultValue_ = StringUtils.substringBeforeLast(defaultValue_, ")");
                    try {
                        defaultValue = this.getEnvironment().parse(defaultValue_);
                    } catch (UnsupportedExpressionException e_) {
                        UnsupportedScriptException ex = new UnsupportedScriptException(this, e_);
                        throw ex;
                    }
                }
            }
        }

        String paraValue = this.getAttribute(paraName);
        Object paraObj = null;
        if (paraValue == null) {

            if (required) {
                UnsupportedScriptException ex = new UnsupportedScriptException(this,
                        "Missing parameter. [" + paraName + "]");
                throw ex;
            } else {
                if (defaultValue != null) {
                    new_vars.put(paraName, defaultValue);
                }
            }

        } else {
            try {
                paraObj = this.getEnvironment().parse(paraValue);
                new_vars.put(paraName, paraObj);
                if (paraObj instanceof kenh.expl.Callback) {
                    parameterCallback.add(paraObj);
                }

            } catch (UnsupportedExpressionException ex) {
                throw new UnsupportedScriptException(this, ex);
            }
        }

    }

    if (this.getAttributes().size() > new_vars.size()
            + (this.getAttributes().containsKey(ATTRIBUTE_RETURN_NAME) ? 2 : 1)) {
        java.util.Set<String> keys = this.getAttributes().keySet();
        String additional = "";
        for (String key : keys) {
            if (key.equals(ATTRIBUTE_METHOD_NAME))
                continue;
            if (key.equals(ATTRIBUTE_RETURN_NAME))
                continue;
            if (new_vars.containsKey(key))
                continue;
            additional = additional + key + ", ";
        }
        UnsupportedScriptException ex = new UnsupportedScriptException(this,
                "Unknown parameter. [" + StringUtils.substringBeforeLast(additional, ",") + "]");
        throw ex;
    }

    // 3) remove non-public variable in Environment. save Method's parameter in Environment.
    List<String> publics = this.getEnvironment().getPublics();
    List<String> constant = this.getEnvironment().getContants();

    Map<String, Object> keep_vars = new LinkedHashMap();
    List<String> keep_cons = new LinkedList();
    List<String> keep_pubs = new LinkedList();
    java.util.Set<String> keys = this.getEnvironment().getVariables().keySet();
    for (String key : keys) {
        if (!publics.contains(key)) {
            keep_vars.put(key, this.getEnvironment().getVariable(key));
            if (constant.contains(key))
                keep_cons.add(key);
        }
    }

    keys = keep_vars.keySet();
    for (String key : keys) {
        if (constant.contains(key))
            constant.remove(key);
        this.getEnvironment().removeVariable(key, false);
    }

    // public variable in Environment have the same name with Method's parameter
    for (String[] parameter : parameters) {
        String key = StringUtils.trimToEmpty(parameter[0]);
        if (this.getEnvironment().containsVariable(key)) {
            if (constant.contains(key)) {
                constant.remove(key);
                keep_cons.add(key);
            }
            publics.remove(key);
            keep_pubs.add(key);
            keep_vars.put(key, this.getEnvironment().removeVariable(key, false));
        }
        this.getEnvironment().setVariable(key, new_vars.get(key));
        if (new_cons.contains(key))
            constant.add(key);
    }

    // 4)invoke the Method's child elements.
    int r = m.processChildren();
    if (r != RETURN && r != NONE) {
        if (r == EXCEPTION) {
            Object ex = this.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION);
            if (ex instanceof Exception) {
                if (ex instanceof UnsupportedScriptException) {
                    throw (UnsupportedScriptException) ex;
                } else {
                    UnsupportedScriptException ex_ = new UnsupportedScriptException(this, (Exception) ex);
                    throw ex_;
                }
            }

        }

        UnsupportedScriptException ex = new UnsupportedScriptException(this,
                "Unsupported value is returned. [" + r + "]");
        throw ex;
    }

    Object returnObj = null;
    if (StringUtils.isNotBlank(var)) {
        if (r == RETURN) {
            returnObj = this.getEnvironment().getVariable(Return.VARIABLE_RETURN);
        } else {
            UnsupportedScriptException ex = new UnsupportedScriptException(this,
                    "The method does not have return value. [" + name + "]");
            throw ex;
        }
    }

    // 5) remove non-public variable from Environment. restore original variables
    List<String> remove_vars = new LinkedList();
    keys = this.getEnvironment().getVariables().keySet();
    for (String key : keys) {
        if (!publics.contains(key)) {
            remove_vars.add(key);
        }
    }

    for (String key : remove_vars) {
        if (constant.contains(key))
            constant.remove(key);
        Object obj = this.getEnvironment().getVariable(key);
        if (parameterCallback.contains(obj)) {
            this.getEnvironment().removeVariable(key, false);
        } else {
            this.getEnvironment().removeVariable(key);
        }
    }

    keys = keep_vars.keySet();
    for (String key : keys) {
        if (!constant.contains(key)) {
            if (!this.getEnvironment().containsVariable(key))
                this.getEnvironment().setVariable(key, keep_vars.get(key));
        }
        if (keep_cons.contains(key))
            constant.add(key);
        if (keep_pubs.contains(key))
            publics.add(key);
    }

    // 6) store {return}
    if (returnObj != null) {
        this.saveVariable(var, returnObj, null);
    }

    return NONE;
}

From source file:net.siegmar.japtproxy.fetcher.HttpClientConfigurer.java

protected Credentials buildCredentials(final String userInfo) throws InitializationException {
    final String username = StringUtils.substringBefore(userInfo, ":");
    final String password = StringUtils.substringAfter(userInfo, ":");

    return username.contains("\\") ? buildNTCredentials(username, password)
            : new UsernamePasswordCredentials(username, password);
}

From source file:com.neatresults.mgnltweaks.ui.action.SaveConfigAddNodeDialogAction.java

@Override
public void execute() throws ActionExecutionException {
    // First Validate
    validator.showValidation(true);/*from  www  . j ava  2s  .c o  m*/
    if (validator.isValid()) {

        // we support only JCR item adapters
        if (!(item instanceof JcrItemAdapter)) {
            return;
        }

        // don't save if no value changes occurred on adapter
        if (!((JcrItemAdapter) item).hasChangedProperties()) {
            return;
        }

        if (item instanceof AbstractJcrNodeAdapter) {
            // Saving JCR Node, getting updated node first
            AbstractJcrNodeAdapter nodeAdapter = (AbstractJcrNodeAdapter) item;
            try {
                String nodePath = ((String) nodeAdapter.getItemProperty("path").getValue()).trim();
                String nodeType = NodeTypes.ContentNode.NAME;
                if (nodeAdapter.getItemProperty("nodeType") != null) {
                    nodeType = ((String) nodeAdapter.getItemProperty("nodeType").getValue()).trim();
                }
                String parentNodeType = NodeTypes.Content.NAME;
                if (nodeAdapter.getItemProperty("parentNodeType") != null) {
                    parentNodeType = ((String) nodeAdapter.getItemProperty("parentNodeType").getValue()).trim();
                }
                Node node = nodeAdapter.getJcrItem();
                String propertyName = null;
                if (nodePath.contains("@")) {
                    propertyName = StringUtils.substringAfter(nodePath, "@").trim();
                    if (StringUtils.isEmpty(propertyName)) {
                        propertyName = null;
                    }
                    nodePath = StringUtils.substringBefore(nodePath, "@");
                }
                String nodeName = nodePath;
                if (nodePath.contains("/")) {
                    nodeName = StringUtils.substringAfterLast(nodePath, "/");
                    String parentPath = StringUtils.substringBeforeLast(nodePath, "/");
                    for (String parentName : parentPath.split("/")) {
                        node = JcrUtils.getOrAddNode(node, parentName, parentNodeType);
                    }
                }
                node = node.addNode(nodeName, nodeType);
                if (propertyName != null) {
                    String value = "";
                    if (nodeAdapter.getItemProperty("value") != null) {
                        value = ((String) nodeAdapter.getItemProperty("value").getValue());
                    }
                    node.setProperty(propertyName, value == null ? "" : value);
                }
                node.getSession().save();
                Location location = subAppContext.getLocation();
                String param = location.getParameter();
                param = node.getPath() + (propertyName != null ? ("@" + propertyName) : "") + ":"
                        + StringUtils.substringAfter(param, ":");
                location = new DefaultLocation(location.getAppType(), location.getAppName(),
                        location.getSubAppId(), param);
                adminEventBus.fireEvent(new LocationChangedEvent(location));
            } catch (RepositoryException e) {
                log.error("Could not save changes to node", e);
            }
            callback.onSuccess(getDefinition().getName());
        } else if (item instanceof JcrPropertyAdapter) {
            super.execute();
        }
    } else {
        log.debug("Validation error(s) occurred. No save performed.");
    }
}