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

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

Introduction

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

Prototype

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

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:com.cognifide.aet.vs.mongodb.MongoDBClient.java

/**
 * Get collection of companies in AET system
 *
 * @return collection of companies names unless database names matches convention: $company_$project and
 * $company dosen't contain any underscrore characters
 *//*from  w w w  .  ja  v  a2s.c  o m*/
public Collection<String> getCompanies() {
    final Collection<String> companies = new ArrayList<>();

    for (String dbName : getAetsDBNames()) {
        if (!StringUtils.containsAny(dbName, DB_NAME_SEPARATOR)) {
            LOGGER.error(
                    "Database name format is incorrect. It must contain at least one underscore character. Couldn't fetch company name from database name. Skip.");
        }
        String companyName = StringUtils.substringBefore(dbName, DB_NAME_SEPARATOR);
        if (StringUtils.isBlank(companyName)) {
            LOGGER.error("Comapny name is blank. It couldn't've been fetched from database name [{}] ", dbName);
        } else if (StringUtils.isNotBlank(companyName)) {
            companies.add(companyName);
        }

    }

    return companies;
}

From source file:com.neatresults.mgnltweaks.ui.field.DialogIdSelectFieldFactory.java

@Override
public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() {

    List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>();
    try {//from w w  w.  j a  v a 2s  . c  o  m
        DialogDefinitionRegistry ddr = Components.getComponent(DialogDefinitionRegistry.class);

        Field registryField = ddr.getClass().getDeclaredField("registry");
        registryField.setAccessible(true);
        RegistryMap<String, DialogDefinitionProvider> registry = (RegistryMap<String, DialogDefinitionProvider>) registryField
                .get(ddr);

        for (String id : registry.keySet()) {

            SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
            FormDialogDefinition dialogDef = registry.get(id).getDialogDefinition();
            // directly defined label
            String label = dialogDef.getLabel();

            if (label == null) {
                // new i18n maybe?
                String name = dialogDef.getId().indexOf("/") > 0
                        ? StringUtils.substringAfterLast(dialogDef.getId(), "/")
                        : StringUtils.substringAfterLast(dialogDef.getId(), ":");
                String key = StringUtils.substringBefore(dialogDef.getId(), ":") + "." + name + ".label";
                label = i18n.translate(key);
                // old i18n maybe?
                if (key.equals(label)) {
                    // no .level suffix maybe?
                    label = i18n.translate(StringUtils.substringBeforeLast(key, "."));
                    if (StringUtils.substringBeforeLast(key, ".").equals(label)) {
                        String oldFormLabel = dialogDef.getForm().getLabel();
                        if (StringUtils.isNotBlank(oldFormLabel)) {
                            label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename())
                                    .get(oldFormLabel);
                        } else {
                            // some weird guessing
                            label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()).get(key);
                            if (label.startsWith("???")) {
                                // one last try - pbly old not translated dialog, get label from first tab
                                List<TabDefinition> tabs = dialogDef.getForm().getTabs();
                                if (tabs.size() > 0) {
                                    label = tabs.get(0).getLabel();
                                }
                            }
                        }
                    }
                }
            }
            field.setLabel(id + " (" + label + ")");
            field.setName(definition.getName());
            field.setValue(id);
            fields.add(field);
        }

    } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException
            | NoSuchFieldException e) {
        log.error(e.getMessage(), e);
        SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
        field.setName("It looks like an error has occured. Please contact admin or developers about it: "
                + e.getMessage());
        field.setValue(e.getMessage());
        fields.add(field);

    }
    return fields;
}

From source file:de.blizzy.documentr.markdown.HtmlSerializer.java

@Override
protected void printImageTag(SuperNode imageNode, String url) {
    String params = StringUtils.EMPTY;
    if (url.contains("|")) { //$NON-NLS-1$
        params = StringUtils.substringAfter(url, "|").trim(); //$NON-NLS-1$
        url = StringUtils.substringBefore(url, "|").trim(); //$NON-NLS-1$
    }//from   www . ja  va 2  s  .co m

    boolean thumbnail = params.contains(IMAGE_PARAM_THUMB);
    String altText = printChildrenToString(imageNode);
    String title = null;
    if (imageNode instanceof ExpImageNode) {
        title = StringUtils.defaultIfBlank(((ExpImageNode) imageNode).title, altText);
    }

    if (thumbnail) {
        printer.print("<ul class=\"thumbnails\"><li class=\"span3\"><a class=\"thumbnail\" href=\"") //$NON-NLS-1$
                .print(context.getAttachmentUri(url)).print("\">"); //$NON-NLS-1$
    }

    printer.print("<img src=\"").print(context.getAttachmentUri(url)).print("\""); //$NON-NLS-1$ //$NON-NLS-2$
    if (StringUtils.isNotBlank(altText)) {
        printer.print(" alt=\"").printEncoded(altText).print("\""); //$NON-NLS-1$ //$NON-NLS-2$
    }
    if (thumbnail) {
        printer.print(" data-lightbox=\"lightbox\" width=\"260\""); //$NON-NLS-1$
    }
    if (StringUtils.isNotBlank(title)) {
        printer.print(" rel=\"tooltip\" data-title=\"").printEncoded(title).print("\""); //$NON-NLS-1$ //$NON-NLS-2$
    }
    printer.print("/>"); //$NON-NLS-1$

    if (thumbnail) {
        printer.print("</a></li></ul>"); //$NON-NLS-1$
    }
}

From source file:ch.sbb.releasetrain.action.jenkins.JenkinsJobThread.java

private String callURL(final String urlin) {
    if (urlin.contains("badge/icon") || urlin.contains("/queue/api/json")) {
        if (log.isTraceEnabled()) {
            log.trace("calling state url: " + urlin);
        }/*from w ww . j a v a  2s.  com*/
    } else {
        if (log.isTraceEnabled()) {
            log.trace("calling url: " + urlin);
        }
        if (urlin.contains("/buildWithParameters")) {
            log.info("GO TO JOB:          " + StringUtils.substringBefore(urlin, "/buildWithParameters"));
            log.info("------!!!>          " + urlin);
        }
    }
    return http.getPageAsString(urlin);
}

From source file:com.google.dart.java2dart.util.JavaUtils.java

/**
 * @param binding the {@link ITypeBinding} to analyze.
 * @param runtime flag <code>true</code> if we need name for class loading, <code>false</code> if
 *          we need name for source generation.
 * @param withGenerics flag <code>true</code> if generics type arguments should be appended.
 * @return the fully qualified name of given {@link ITypeBinding}, or
 *         {@link #NO_TYPE_BINDING_NAME} .
 *///from w ww.  j  a v a 2s.c o  m
public static String getFullyQualifiedName(ITypeBinding binding, boolean runtime, boolean withGenerics) {
    // check if no binding
    if (binding == null) {
        return NO_TYPE_BINDING_NAME;
    }
    // check for primitive type
    if (binding.isPrimitive()) {
        return binding.getName();
    }
    // array
    if (binding.isArray()) {
        StringBuilder sb = new StringBuilder();
        // append element type qualified name
        ITypeBinding elementType = binding.getElementType();
        String elementTypeQualifiedName = getFullyQualifiedName(elementType, runtime);
        sb.append(elementTypeQualifiedName);
        // append dimensions
        for (int i = 0; i < binding.getDimensions(); i++) {
            sb.append("[]");
        }
        // done
        return sb.toString();
    }
    // object
    {
        String scope;
        ITypeBinding declaringType = binding.getDeclaringClass();
        if (declaringType == null) {
            IPackageBinding packageBinding = binding.getPackage();
            if (packageBinding == null || packageBinding.isUnnamed()) {
                scope = "";
            } else {
                scope = packageBinding.getName() + ".";
            }
        } else if (binding.isTypeVariable()) {
            return binding.getName();
        } else {
            // use '$', because we use this class name for loading class
            scope = getFullyQualifiedName(declaringType, runtime);
            if (runtime) {
                scope += "$";
            } else {
                scope += ".";
            }
        }
        // prepare "simple" name, without scope
        String jdtName = binding.getName();
        String name = StringUtils.substringBefore(jdtName, "<");
        if (withGenerics) {
            ITypeBinding[] typeArguments = binding.getTypeArguments();
            if (typeArguments.length != 0) {
                StringBuilder sb = new StringBuilder(name);
                sb.append("<");
                for (ITypeBinding typeArgument : typeArguments) {
                    if (sb.charAt(sb.length() - 1) != '<') {
                        sb.append(",");
                    }
                    String typeArgumentName = getFullyQualifiedName(typeArgument, runtime, withGenerics);
                    sb.append(typeArgumentName);
                }
                sb.append(">");
                name = sb.toString();
            }
        }
        // qualified name is scope plus "simple" name
        return scope + name;
    }
}

From source file:com.amalto.core.save.context.PartialDeleteSimulator.java

/**
 * "Source document" and "toDeleteDocument" may not be be able to share "toDeletePiovt". <br>
 * Like <b>"Kids/Kid[2]/Habits/Habit"</b> means to delete source document's <b>SECOND</b> kid's habits,<br> 
 * but "toDeleteDocument" should use <b>"Kids/Kid[1]/Habits/Habit"</b> to get the data to delete.
 * @return/*from  w ww. ja  va2  s  .com*/
 */
private String getPivotForToDeleteDocument() {
    if (toDeletePivot.contains("[") && toDeletePivot.contains("]")) { //$NON-NLS-1$ //$NON-NLS-2$
        StringBuilder pivot = new StringBuilder();
        StringTokenizer tokenizer = new StringTokenizer(toDeletePivot, "/"); //$NON-NLS-1$
        while (tokenizer.hasMoreElements()) {
            String element = (String) tokenizer.nextElement();
            pivot.append("/").append(StringUtils.substringBefore(element, "[")); //$NON-NLS-1$ //$NON-NLS-2$
            if (element.contains("[") && element.contains("]")) { //$NON-NLS-1$ //$NON-NLS-2$
                pivot.append("[1]"); //$NON-NLS-1$
            }
        }
        return pivot.toString().substring(1);
    } else {
        return toDeletePivot;
    }
}

From source file:com.neatresults.mgnltweaks.ui.field.NodeTypeSelectFieldFactory.java

@Override
public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() {

    List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>();
    try {/*from  w  w w.  j  a  v a2  s. c o m*/
        Field registryField = registry.getClass().getDeclaredField("registry");
        registryField.setAccessible(true);
        RegistryMap<String, DialogDefinitionProvider> registryMap = (RegistryMap<String, DialogDefinitionProvider>) registryField
                .get(this.registry);

        for (String id : registryMap.keySet()) {

            SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
            FormDialogDefinition dialogDef = registryMap.get(id).getDialogDefinition();
            // directly defined label
            String label = dialogDef.getLabel();

            if (label == null) {
                // new i18n maybe?
                String name = dialogDef.getId().indexOf("/") > 0
                        ? StringUtils.substringAfterLast(dialogDef.getId(), "/")
                        : StringUtils.substringAfterLast(dialogDef.getId(), ":");
                String key = StringUtils.substringBefore(dialogDef.getId(), ":") + "." + name + ".label";
                label = i18n.translate(key);
                // old i18n maybe?
                if (key.equals(label)) {
                    // no .level suffix maybe?
                    label = i18n.translate(StringUtils.substringBeforeLast(key, "."));
                    if (StringUtils.substringBeforeLast(key, ".").equals(label)) {
                        String oldFormLabel = dialogDef.getForm().getLabel();
                        if (StringUtils.isNotBlank(oldFormLabel)) {
                            label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename())
                                    .get(oldFormLabel);
                        } else {
                            // some weird guessing
                            label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()).get(key);
                            if (label.startsWith("???")) {
                                // one last try - pbly old not translated dialog, get label from first tab
                                List<TabDefinition> tabs = dialogDef.getForm().getTabs();
                                if (tabs.size() > 0) {
                                    label = tabs.get(0).getLabel();
                                }
                            }
                        }
                    }
                }
            }
            field.setLabel(id + " (" + label + ")");
            field.setName(definition.getName());
            field.setValue(id);
            fields.add(field);
        }

    } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException
            | NoSuchFieldException e) {
        log.error(e.getMessage(), e);
        SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
        field.setName("It looks like an error has occured. Please contact admin or developers about it: "
                + e.getMessage());
        field.setValue(e.getMessage());
        fields.add(field);

    }
    return fields;
}

From source file:com.xpn.xwiki.render.XWikiRadeoxRenderEngine.java

/**
 * @param name the name of a wiki page//from w ww  .j  av  a2s  .com
 * @return true if the page exists or false otherwise
 * @see org.radeox.api.engine.WikiRenderEngine#exists(String)
 */
public boolean exists(String name) {
    String database = getXWikiContext().getDatabase();
    try {
        int colonIndex = name.indexOf(":");
        if (colonIndex != -1) {
            String db = name.substring(0, colonIndex);
            name = name.substring(colonIndex + 1);
            getXWikiContext().setDatabase(db);
        }

        name = StringUtils.substringBefore(StringUtils.substringBefore(name, "?"), "#");

        XWikiDocument doc = new XWikiDocument();
        doc.setFullName(name);

        // If the document exists with the initial name, then we use this one
        if (getXWikiContext().getWiki().exists(doc.getFullName(), getXWikiContext())) {
            return true;
        }

        // If the document does not exists then we check the one converted (no accents and no spaces)
        doc.setFullName(noaccents(name));
        return getXWikiContext().getWiki().exists(doc.getFullName(), getXWikiContext());
    } catch (Exception e) {
        LOGGER.error("Failed to check if a document exists", e);

        return false;
    } finally {
        // Reset the current wiki to the original one
        getXWikiContext().setDatabase(database);
    }

}

From source file:com.epam.reportportal.extension.bugtracking.jira.JiraOAuthController.java

private static String getBaseUri(String url) {
    return StringUtils.substringBefore(url, "/api/v");
}

From source file:de.jfachwert.post.PLZ.java

private static String getLandeskennung(String plz) {
    return StringUtils.substringBefore(toLongString(plz), "-");
}