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.thruzero.common.core.infonode.builder.TokenStreamInfoNodeBuilder.java

protected InfoNodeElement initLeafNode(final String tokenStream, final String separator,
        final InfoNodeElement targetNode) {
    // TODO-p1(george) Rewrite this using RegEx
    String attributeStream = StringUtils.substringBetween(tokenStream, "[@", "]");
    String elementName;/*from  w ww. j av a2  s .c  om*/
    String elementValue;

    // handle the attributes
    if (StringUtils.isEmpty(attributeStream)) {
        elementName = StringUtils.trimToNull(StringUtils.substringBefore(tokenStream, "="));
        elementValue = StringUtils.trimToNull(StringUtils.substringAfter(tokenStream, "="));
    } else {
        StringTokenizer st1 = new StringTokenizer(attributeStream, separator);

        while (st1.hasMoreTokens()) {
            String attributeSpec = st1.nextToken();
            StringTokenizer st2 = new StringTokenizer(attributeSpec, "=");

            if (!st2.hasMoreTokens()) {
                throw new TokenStreamException(
                        "Malformed Token Stream (missing attribute name and value): " + tokenStream);
            }
            String attributeName = StringUtils.removeStart(st2.nextToken().trim(), "@");

            String attributeValue = null;
            if (st2.hasMoreTokens()) {
                attributeValue = trimQuotes(st2.nextToken().trim());
            }

            if (StringUtils.isEmpty(attributeValue)) {
                throw new TokenStreamException(
                        "Malformed Token Stream (missing attribute value): " + tokenStream);
            }

            targetNode.setAttribute(attributeName, attributeValue);
        }

        elementName = StringUtils.trimToNull(StringUtils.substringBefore(tokenStream, "["));
        elementValue = StringUtils.trimToNull(StringUtils.substringAfter(tokenStream, "]"));
    }

    // set the element name
    if (elementName == null) {
        throw new TokenStreamException("Malformed Token Stream (missing element name): " + tokenStream);
    }
    targetNode.setName(elementName);

    // set the element value
    if (elementValue != null) {
        elementValue = StringUtils.removeStart(elementValue, "=");
        targetNode.setText(elementValue);
    }

    return targetNode;
}

From source file:bear.core.BearMain.java

static Optional<ClassLoader> createDepsClassLoader(List<File> folders) {
    File bootstrapFile = new File(BEAR_DIR, "bootstrap.properties");

    if (!bootstrapFile.exists())
        return Optional.absent();

    FileInputStream fis = null;/*from   w  ww.j a  va2 s.co m*/

    try {
        Properties properties = new Properties();

        fis = new FileInputStream(bootstrapFile);

        properties.load(fis);

        Set<Map.Entry<String, String>> entries = (Set) properties.entrySet();

        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();

            if (!key.startsWith("logger."))
                continue;

            key = StringUtils.substringAfter(key, "logger.");

            LoggingBooter.changeLogLevel(key, Level.toLevel(entry.getValue()));
        }

        String property = "bearMain.customFolders";

        String customFolders = properties.getProperty(property, null);

        if (customFolders != null) {
            List<String> temp = COMMA_SPLITTER.splitToList(customFolders);

            for (String s : temp) {
                File file = new File(s);

                if (!file.exists()) {
                    throw new NoSuchFileException("dir does not exist (:" + property + "): " + s);
                }

                folders.add(file);
            }
        }

        return new MavenBooter(properties).loadArtifacts(properties);
    } catch (Exception e) {
        throw Exceptions.runtime(e);
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:ambroafb.general.AnnotiationUtils.java

private static boolean checkValidationForContentMapEditorAnnotation(Field field, Object currSceneController) {
    boolean contentIsCorrect = false;
    Annotations.ContentMapEditor annotation = field.getAnnotation(Annotations.ContentMapEditor.class);
    Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController);
    MapEditor mapEditorComboBox = (MapEditor) typeAndContent[0];
    String editorContent = (String) typeAndContent[1];
    String keyPart = StringUtils.substringBefore(editorContent, mapEditorComboBox.getDelimiter()).trim();
    String valuePart = StringUtils.substringAfter(editorContent, mapEditorComboBox.getDelimiter()).trim();

    boolean keyMatch = Pattern.matches(mapEditorComboBox.getKeyPattern(), keyPart);
    boolean valueMatch = Pattern.matches(mapEditorComboBox.getValuePattern(), valuePart);
    String explain;/*from   ww  w  .j  a v a  2s. c  o m*/
    if (!keyMatch || !valueMatch) {
        explain = (!keyMatch) ? annotation.explainKey() : annotation.explainValue();
        changeNodeTitleLabelVisual(mapEditorComboBox, explain);
    } else if ((keyPart.isEmpty() && !valuePart.isEmpty()) || (!keyPart.isEmpty() && valuePart.isEmpty())) {
        explain = annotation.explainEmpty();
        changeNodeTitleLabelVisual(mapEditorComboBox, explain);
    } else {
        changeNodeTitleLabelVisual(mapEditorComboBox, "");
        contentIsCorrect = true;
    }
    return contentIsCorrect;
}

From source file:com.quancheng.saluki.registry.consul.ConsulRegistry.java

private GrpcURL buildURL(ConsulService service) {
    try {/*from w  w w . ja v a  2 s  .c o  m*/
        for (String tag : service.getTags()) {
            if (StringUtils.indexOf(tag, Constants.PROVIDERS_CATEGORY) != -1) {
                String toUrlPath = StringUtils.substringAfter(tag, Constants.PROVIDERS_CATEGORY);
                GrpcURL salukiUrl = GrpcURL.valueOf(GrpcURL.decode(toUrlPath));
                return salukiUrl;
            }
        }
    } catch (Exception e) {
        log.error("convert consul service to url fail! service:" + service, e);
    }
    return null;
}

From source file:de.blizzy.documentr.web.system.SystemController.java

private SortedMap<String, SortedMap<String, String>> getMacroSettingsFromRequest(WebRequest webRequest) {
    Map<String, String[]> params = webRequest.getParameterMap();
    SortedMap<String, SortedMap<String, String>> allMacroSettings = Maps.newTreeMap();
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(MACRO_KEY_PREFIX)) {
            String[] values = entry.getValue();
            if (values.length == 0) {
                values = new String[] { StringUtils.EMPTY };
            }//from   w  w w  . j av a 2  s  . co  m
            key = key.substring(MACRO_KEY_PREFIX.length());
            String macroName = StringUtils.substringBefore(key, "."); //$NON-NLS-1$
            key = StringUtils.substringAfter(key, "."); //$NON-NLS-1$
            SortedMap<String, String> macroSettings = allMacroSettings.get(macroName);
            if (macroSettings == null) {
                macroSettings = Maps.newTreeMap();
                allMacroSettings.put(macroName, macroSettings);
            }
            macroSettings.put(key, values[0]);
        }
    }
    return allMacroSettings;
}

From source file:ambroafb.general.StagesContainer.java

private static List<String> getFirstLevelChildrenFor(String ownerPath) {
    List<String> children = new ArrayList<>();
    SortedSet<Object> sortedKeys = new TreeSet<>(bidmap.keySet());
    sortedKeys.stream().forEach((key) -> {
        String path = (String) key;
        String pathAfterFirstSlash = StringUtils.substringAfter(path, ownerPath + pathDelimiter);
        if (!path.equals(ownerPath) && path.startsWith(ownerPath)
                && !pathAfterFirstSlash.contains(pathDelimiter) && ((Stage) bidmap.get(path)).isShowing()) {
            children.add(path);/*from  w  w w  .  ja  va 2 s.co m*/
        }
    });
    return children;
}

From source file:de.micromata.tpsb.doc.parser.JavaDocUtil.java

public static String getScenarioSuiteFileContent(String projectRoot, TestStepInfo stepInfo,
        AnnotationInfo annotation) {/*  w  w  w  .j a  v  a  2 s  .  co m*/
    StringBuilder sb = new StringBuilder();
    String fileName = (String) annotation.getParams().get("filePattern");
    if (fileName == null) {
        return null;
    }
    fileName = TypeUtils.unqoteString(fileName);
    String dirPart = StringUtils.substringBefore(fileName, "${0}");
    String suffixPart = StringUtils.substringAfter(fileName, "${0}");

    File dir = lookupFileOrDir(projectRoot, dirPart);
    if (dir == null || dir.isDirectory() == false) {
        return sb.toString();
    }
    File[] files = dir.listFiles();
    if (files == null || files.length == 0) {
        return sb.toString();
    }
    for (File f : files) {
        if (f.getName().endsWith(suffixPart) == false) {
            continue;
        }
        try {
            String content = FileUtils.readFileToString(f);
            AnnotationInfo scenarioAnot = TpsbEnvUtils.getAnnotation(stepInfo.getTestBuilderMethod(),
                    "TpsbScenarioFile");
            content = renderScenarioFile(f, scenarioAnot, content);
            sb.append(
                    "\n\n===================================================================================\n")//
                    .append("<h3>Testscenario: ").append(StringUtils.substringBefore(f.getName(), suffixPart))
                    .append("</h3>\n\n")//
                    .append(content);

        } catch (IOException ex) {
            log.warn("Scanrio file can't be read: " + f.getAbsolutePath() + "; " + ex.getMessage(), ex);
        }
    }
    return sb.toString();
}

From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java

public static String getClassName(String code) {
    String className = StringUtils.substringBefore(code, "{");
    if (StringUtils.isBlank(className)) {
        return className;
    }/*from  ww  w  .j  a  v  a  2 s  . c  o m*/
    if (StringUtils.contains(code, " class ")) {
        className = StringUtils.substringAfter(className, " class ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else if (StringUtils.contains(className, " implements ")) {
            className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " interface ")) {
        className = StringUtils.substringAfter(className, " interface ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " enum ")) {
        className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
    } else {
        return StringUtils.EMPTY;
    }
    return className;
}

From source file:com.kodebeagle.javaparser.MethodInvocationResolver.java

private String getTarget(Expression expression) {
    String target = "";
    if (expression != null) {
        target = expression.toString();/*from   w  ww  . j  av  a  2  s  . com*/
        if (target.contains("this.")) {
            target = StringUtils.substringAfter(target, "this.");
        }
    }
    return target;
}

From source file:com.evolveum.midpoint.web.component.wizard.resource.component.synchronization.SynchronizationReactionEditor.java

protected void initLayout(PageResourceWizard parentPage) {
    Label label = new Label(ID_LABEL, new ResourceModel("SynchronizationReactionEditor.label.edit"));
    add(label);//from   w  w w.  j  av  a  2  s .c  o  m

    TextField name = new TextField<>(ID_NAME, new PropertyModel<String>(getModel(), "name"));
    name.add(new ReactionListUpdateBehavior());
    parentPage.addEditingEnabledBehavior(name);
    add(name);

    TextArea description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(getModel(), "description"));
    parentPage.addEditingEnabledBehavior(description);
    add(description);

    DropDownChoice situation = new DropDownChoice<>(ID_SITUATION, new PropertyModel<>(getModel(), "situation"),
            WebComponentUtil.createReadonlyModelFromEnum(SynchronizationSituationType.class),
            new EnumChoiceRenderer<>(this));
    situation.setNullValid(true);
    situation.add(new ReactionListUpdateBehavior());
    parentPage.addEditingEnabledBehavior(situation);
    situation.add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ((PageResourceWizard) getPageBase()).refreshIssues(target);
        }
    });
    add(situation);

    MultiValueDropDownPanel channel = new MultiValueDropDownPanel<String>(ID_CHANNEL,
            new PropertyModel<>(getModel(), "channel"), true, parentPage.getReadOnlyModel()) {

        @Override
        protected String createNewEmptyItem() {
            return "";
        }

        @Override
        protected IModel<List<String>> createChoiceList() {
            return new AbstractReadOnlyModel<List<String>>() {

                @Override
                public List<String> getObject() {
                    return WebComponentUtil.getChannelList();
                }
            };
        }

        @Override
        protected IChoiceRenderer<String> createRenderer() {
            return CHANNEL_RENDERER;
        }
    };
    add(channel);
    TriStateComboPanel synchronize = new TriStateComboPanel(ID_SYNCHRONIZE,
            new PropertyModel<>(getModel(), "synchronize"));
    synchronize.getBaseFormComponent().add(new ReactionListUpdateBehavior());
    parentPage.addEditingEnabledBehavior(synchronize);
    add(synchronize);

    CheckBox reconcile = new CheckBox(ID_RECONCILE, new PropertyModel<>(getModel(), "reconcile"));
    parentPage.addEditingEnabledBehavior(reconcile);
    add(reconcile);

    DropDownChoice objectTemplateRef = new DropDownChoice<>(ID_OBJECT_TEMPLATE_REF,
            new PropertyModel<>(getModel(), "objectTemplateRef"),
            new AbstractReadOnlyModel<List<ObjectReferenceType>>() {

                @Override
                public List<ObjectReferenceType> getObject() {
                    return WebModelServiceUtils.createObjectReferenceList(ObjectTemplateType.class,
                            getPageBase(), objectTemplateMap);
                }
            }, new ObjectReferenceChoiceRenderer(objectTemplateMap));
    objectTemplateRef.setNullValid(true);
    parentPage.addEditingEnabledBehavior(objectTemplateRef);
    add(objectTemplateRef);

    MultiValueTextEditPanel action = new MultiValueTextEditPanel<SynchronizationActionType>(ID_ACTION,
            new PropertyModel<>(getModel(), "action"), null, false, true, parentPage.getReadOnlyModel()) {

        @Override
        protected IModel<String> createTextModel(final IModel<SynchronizationActionType> model) {
            return new Model<String>() {

                @Override
                public String getObject() {
                    SynchronizationActionType action = model.getObject();
                    if (action == null) {
                        return null;
                    }
                    StringBuilder sb = new StringBuilder();
                    sb.append(action.getName() != null ? action.getName() : "-");
                    if (action.getHandlerUri() != null) {
                        sb.append(" (").append(StringUtils.substringAfter(action.getHandlerUri(), "#"))
                                .append(")");
                    }
                    return sb.toString();
                }
            };
        }

        @Override
        protected void performAddValueHook(AjaxRequestTarget target, SynchronizationActionType added) {
            target.add(parentStep.getReactionList());
            ((PageResourceWizard) getPageBase()).refreshIssues(target);
        }

        @Override
        protected void performRemoveValueHook(AjaxRequestTarget target,
                ListItem<SynchronizationActionType> item) {
            target.add(parentStep.getReactionList());
            ((PageResourceWizard) getPageBase()).refreshIssues(target);
        }

        @Override
        protected SynchronizationActionType createNewEmptyItem() {
            return new SynchronizationActionType();
        }

        @Override
        protected void editPerformed(AjaxRequestTarget target, SynchronizationActionType object) {
            actionEditPerformed(target, object);
        }
    };
    action.setOutputMarkupId(true);
    add(action);

    Label situationTooltip = new Label(ID_T_SITUATION);
    situationTooltip.add(new InfoTooltipBehavior());
    add(situationTooltip);

    Label channelTooltip = new Label(ID_T_CHANNEL);
    channelTooltip.add(new InfoTooltipBehavior());
    add(channelTooltip);

    Label synchronizeTooltip = new Label(ID_T_SYNCHRONIZE);
    synchronizeTooltip.add(new InfoTooltipBehavior());
    add(synchronizeTooltip);

    Label reconcileTooltip = new Label(ID_T_RECONCILE);
    reconcileTooltip.add(new InfoTooltipBehavior());
    add(reconcileTooltip);

    Label objTemplateTooltip = new Label(ID_T_OBJ_TEMPLATE);
    objTemplateTooltip.add(new InfoTooltipBehavior());
    add(objTemplateTooltip);

    Label actionTooltip = new Label(ID_T_ACTION);
    actionTooltip.add(new InfoTooltipBehavior());
    add(actionTooltip);

    initModals();
}