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:kenh.xscript.ScriptUtils.java

public static void main(String[] args) {
    String file = null;//from w  w  w .j a v a  2s.c  o m

    for (String arg : args) {
        if (StringUtils.startsWithAny(StringUtils.lowerCase(arg), "-f:", "-file:")) {
            file = StringUtils.substringAfter(arg, ":");
        }
    }

    Element e = null;
    try {
        if (StringUtils.isBlank(file)) {

            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle("xScript");
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.setFileFilter(new FileFilter() {
                public boolean accept(File f) {
                    if (f.isDirectory()) {
                        return true;
                    } else if (f.isFile() && StringUtils.endsWithIgnoreCase(f.getName(), ".xml")) {
                        return true;
                    }
                    return false;
                }

                public String getDescription() {
                    return "xScript (*.xml)";
                }
            });

            int returnVal = chooser.showOpenDialog(null);
            chooser.requestFocus();

            if (returnVal == JFileChooser.CANCEL_OPTION)
                return;

            File f = chooser.getSelectedFile();

            e = getInstance(f, null);
        } else {
            e = getInstance(new File(file), null);
        }
        //debug(e);
        //System.out.println("----------------------");

        int result = e.invoke();
        if (result == Element.EXCEPTION) {
            Object obj = e.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION);
            if (obj != null && obj instanceof Throwable) {
                System.err.println();
                ((Throwable) obj).printStackTrace();

            } else {
                System.err.println();
                System.err.println("Unknown EXCEPTION is thrown.");
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();

        System.err.println();

        if (ex instanceof UnsupportedScriptException) {
            UnsupportedScriptException ex_ = (UnsupportedScriptException) ex;
            if (ex_.getElement() != null) {
                debug(ex_.getElement(), System.err);
            }
        }
    } finally {
        if (e != null)
            e.getEnvironment().callback();
    }
}

From source file:com.threewks.thundr.googleapis.prediction.PredictionDataHelper.java

public static String emailDomain(String emailAddress) {
    return StringUtils.substringAfter(emailAddress, "@");
}

From source file:com.neatresults.mgnltweaks.NeatUtil.java

public static String templateIdToPath(String templateId) {
    if (StringUtils.contains(templateId, ":")) {
        return "/modules/" + StringUtils.substringBefore(templateId, ":") + "/templates/"
                + StringUtils.substringAfter(templateId, ":");
    }/*  w  ww . j a va 2s.  co m*/
    return null;
}

From source file:com.mirth.connect.server.util.Pre22PasswordChecker.java

/**
 * The pre-2.2 password has been migrated to the following
 * format://from  www. ja va2 s .  c  om
 * 
 * SALT_ + 8-bit salt + base64(sha(salt + password))
 * 
 * To compare:
 * 
 * 1. Strip the known pre-2.2 prefix
 * 2. Get the first 8-bits and Base64 decode it, this the salt
 * 3. Get the remaining bits and Base64 decode it, this is the hash
 * 4. Pass it into the pre-2.2 password checker algorithm
 * 
 * @param plainPassword The plain text password to check against the hash
 * @param encodedPassword The hashed password
 * @return true if the password matches the hash using the pre-2.2 algorithm, false otherwise
 */
public static boolean checkPassword(String plainPassword, String encodedPassword) throws Exception {
    String saltHash = StringUtils.substringAfter(encodedPassword, SALT_PREFIX);
    String encodedSalt = StringUtils.substring(saltHash, 0, SALT_LENGTH);
    byte[] decodedSalt = Base64.decodeBase64(encodedSalt);
    byte[] decodedHash = Base64.decodeBase64(StringUtils.substring(saltHash, encodedSalt.length()));

    if (Arrays.equals(decodedHash, DigestUtils.sha(ArrayUtils.addAll(decodedSalt, plainPassword.getBytes())))) {
        return true;
    }

    return false;
}

From source file:me.camerongray.teamlocker.server.RequestCredentials.java

public RequestCredentials(Request request) {
    String[] credentials = new String(Base64.getDecoder()
            .decode(StringUtils.substringAfter(request.headers("Authorization"), "Basic").trim())).split(":");
    this.username = credentials[0];
    this.password = (credentials.length > 1) ? credentials[1] : "";
}

From source file:com.widowcrawler.core.util.DomainUtils.java

public static boolean isBaseDomain(String baseDomain, String url) {
    try {//from   w w w .j a  v a2 s  . c om
        baseDomain = StringUtils.lowerCase(StringUtils.trim(baseDomain));
        String domain = StringUtils.lowerCase(StringUtils.trimToNull(new URI(url).getHost()));

        if (domain == null) {
            logger.info("Returning false because url's domain is null");
            return false;
        }

        while (StringUtils.isNotBlank(domain)) {
            if (StringUtils.equals(baseDomain, domain)) {
                return true;
            }

            domain = StringUtils.substringAfter(domain, ".");
        }

        return false;

    } catch (URISyntaxException ex) {
        logger.error("Could not determine base domain relationship. Returning default of false.", ex);
        return false;
    }
}

From source file:com.thinkbiganalytics.servicemonitor.rest.client.cdh.ClouderaRootResourceManager.java

/**
 * Will attempt to get configured api version. If that fails it will fall back to API v1.
 *///from ww w . ja va2s . c  o  m
static ClouderaRootResource getRootResource(ApiRootResource apiRootResource) {

    String version = apiRootResource.getCurrentVersion();
    Integer numericVersion = new Integer(StringUtils.substringAfter(version, "v"));
    RootResourceV1 rootResource = null;
    Integer maxVersion = 10;
    if (numericVersion > maxVersion) {
        numericVersion = maxVersion;
    }

    try {
        rootResource = (RootResourceV1) MethodUtils.invokeMethod(apiRootResource, "getRootV" + numericVersion);
    } catch (Exception ignored) {

    }
    if (rootResource == null) {
        LOG.info("Unable to get RootResource for version {}, returning version 1", numericVersion);
        rootResource = apiRootResource.getRootV1();
    }

    return new DefaultClouderaRootResource(rootResource);

}

From source file:com.epam.ta.reportportal.database.entity.user.UserRole.java

public static Optional<UserRole> findByAuthority(String name) {
    if (Strings.isNullOrEmpty(name)) {
        return Optional.empty();
    }/*from   ww w .  jav  a2  s.  c  om*/
    return findByName(StringUtils.substringAfter(name, ROLE_PREFIX));
}

From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java

/**
 * Parse a timer string to a Joda time period
 *
 * @param timer      a string indicating a time unit (i.e. 5 sec)
 * @param periodType the Period unit to use.
 *///  w  w w .  ja  v a 2s .  com
public static Period timerStringToPeriod(String timer, PeriodType periodType) {
    String cronString = null;
    Integer time = Integer.parseInt(StringUtils.substringBefore(timer, " "));
    String units = StringUtils.substringAfter(timer, " ").toLowerCase();
    //time to years,days,months,hours,min, sec
    Integer days = 0;
    Integer hours = 0;
    Integer min = 0;
    Integer sec = 0;
    Period p = null;
    if (units.startsWith("sec")) {
        p = Period.seconds(time);
    } else if (units.startsWith("min")) {
        p = Period.minutes(time);
    } else if (units.startsWith("hr") || units.startsWith("hour")) {
        p = Period.hours(time);
    } else if (units.startsWith("day")) {
        p = Period.days(time);
    }
    if (periodType != null) {
        p = p.normalizedStandard(periodType);
    } else {
    }
    return p;
}

From source file:io.wcm.devops.conga.model.util.MapExpander.java

/**
 * Get object from map with "deep" access resolving dots in the key as nested map keys.
 * @param map Map/*  www.j a  v  a 2  s  . co  m*/
 * @param key Key with dots
 * @return Value or null
 */
@SuppressWarnings("unchecked")
public static Object getDeep(Map<String, Object> map, String key) {
    if (map.containsKey(key)) {
        return ObjectUtils.defaultIfNull(map.get(key), "");
    }
    if (StringUtils.contains(key, ".")) {
        String keyPart = StringUtils.substringBefore(key, ".");
        String keySuffix = StringUtils.substringAfter(key, ".");
        Object resultKeyPart = map.get(keyPart);
        if (resultKeyPart != null && resultKeyPart instanceof Map) {
            return getDeep((Map<String, Object>) resultKeyPart, keySuffix);
        }
    }
    return null;
}