Example usage for org.apache.commons.lang StringUtils substringAfter

List of usage examples for org.apache.commons.lang StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfter.

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:com.comcast.cats.monitor.reboot.BarcelonaRebootMonitor.java

/**
 * Parse the snmp result to detect reboot.
 * /*from  w  w  w .  j  av a 2s  . c  om*/
 * Examples of expected results : "18:54:41.36", "2 days, 18:54:41.36",
 * "1 day, 18:54:41.36"
 */
@Override
protected void parseRebootInfo(String snmpQueryResult) {
    logger.debug("snmpQueryResult " + snmpQueryResult);

    long upTime = 0;
    String upTimeDays = null;
    String upTimehours;
    try {
        if (snmpQueryResult != null && !snmpQueryResult.isEmpty()) {

            Pattern pattern = Pattern.compile(REBOOT_DETECTION_REGEX_STRING);
            Matcher matcher = pattern.matcher(snmpQueryResult);

            if (matcher.find()) {
                // seperate the days information and the time information.
                upTimeDays = StringUtils.substringBefore(snmpQueryResult, matcher.group()).trim();
                upTimehours = StringUtils.substringAfter(snmpQueryResult, matcher.group()).trim();
            } else {
                upTimehours = snmpQueryResult.trim();
            }

            upTime = calculateUptime(upTimeDays, upTimehours);

            long timeInterval = calculcateMonitorTimeIntervalInMillis();
            logger.debug("timeInterval sec " + (timeInterval / (1000)));
            logger.debug("upTime sec " + (upTime) / 1000);

            if (timeInterval > upTime) {
                logger.debug("Reboot Happened");
                RebootStatistics stats = new RebootStatistics(new Date());
                stats.setMonitorType(REBOOT_TYPE);
                stats.setMessage("UP Time " + snmpQueryResult, settop.getHostMacAddress());
                stats.setUptime(upTime / 1000);
                alarm(stats);
            } else {
                logger.trace("NO Reboot Happened");
            }
        } else {
            logger.debug("SNMP detection failed : No response from settop " + snmpQueryResult);
        }
    } catch (ParseException e) {
        logger.trace("Result not in an expected format : " + e.getMessage());
    } catch (NumberFormatException e) {
        logger.trace("Result not in an expected format : " + e.getMessage());
    }

    ((Calendar) getState()).setTime(new Date());
}

From source file:info.magnolia.setup.for4_5.UpdateUserManagers.java

@Override
protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException {

    Session session = ctx.getJCRSession(RepositoryConstants.CONFIG);

    for (Node node : NodeUtil.getNodes(
            session.getRootNode().getNode("server").getNode("security").getNode("userManagers"),
            NodeTypes.ContentNode.NAME)) {
        if (node.hasProperty("class")) {
            String className = node.getProperty("class").getString();
            if (className.equals("info.magnolia.cms.security.MgnlUserManager")
                    || className.equals("info.magnolia.cms.security.SystemUserManager")) {
                PropertyExistsDelegateTask updateTask = new PropertyExistsDelegateTask("", "",
                        RepositoryConstants.CONFIG,
                        "/server" + StringUtils.substringAfter(node.getPath(), "/server"),
                        "maxFailedLoginAttempts", null,
                        new NewPropertyTask("", "", RepositoryConstants.CONFIG,
                                "/server" + StringUtils.substringAfter(node.getPath(), "/server"),
                                "maxFailedLoginAttempts", "5"));
                PropertyExistsDelegateTask updateTask2 = new PropertyExistsDelegateTask("", "",
                        RepositoryConstants.CONFIG,
                        "/server" + StringUtils.substringAfter(node.getPath(), "/server"), "lockTimePeriod",
                        null,/*from   ww w . j av  a  2s .c om*/
                        new NewPropertyTask("", "", RepositoryConstants.CONFIG,
                                "/server" + StringUtils.substringAfter(node.getPath(), "/server"),
                                "lockTimePeriod", "0"));
                updateTask.execute(ctx);
                updateTask2.execute(ctx);
            }
        }
    }
}

From source file:com.safetys.framework.jmesa.limit.LimitActionFactory.java

public FilterSet getFilterSet() {
    FilterSet filterSet = new FilterSet();

    String clear = LimitUtils.getValue(parameters.get(prefixId + Action.CLEAR.toParam()));
    if (StringUtils.isNotEmpty(clear)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Cleared out the filters.");
        }/*ww w .  j a  va  2s .  c o m*/
        return filterSet;
    }

    for (Object param : parameters.keySet()) {
        String parameter = (String) param;
        if (parameter.startsWith(prefixId + Action.FILTER.toParam())) {
            String value = LimitUtils.getValue(parameters.get(parameter));
            if (StringUtils.isNotBlank(value)) {
                String property = StringUtils.substringAfter(parameter, prefixId + Action.FILTER.toParam());
                Filter filter = new Filter(property, value);
                filterSet.addFilter(filter);
            }
        }
    }

    return filterSet;
}

From source file:info.magnolia.cms.util.RequestFormUtil.java

/**
 * The url is not always properly decoded. This method does the job.
 * @param request// w ww  .  j a  va2s. c om
 * @param charset
 * @return decoded map of all values
 */
public static Map getURLParametersDecoded(HttpServletRequest request, String charset) {
    Map map = new HashMap();
    String queryString = request.getQueryString();
    if (queryString != null) {
        String[] params = request.getQueryString().split("&");
        for (int i = 0; i < params.length; i++) {
            String name = StringUtils.substringBefore(params[i], "=");
            String value = StringUtils.substringAfter(params[i], "=");
            try {
                value = URLDecoder.decode(value, charset);
            } catch (UnsupportedEncodingException e) {
                // nothing: return value as is
            }
            map.put(name, value);
        }
    }
    return map;
}

From source file:com.justinmobile.core.dao.support.PropertyFilter.java

private void buildFilterName(String filterName) {
    // ????/*from   w w  w .  j  a va  2 s.co  m*/
    String aliasPart = StringUtils.substringBefore(filterName, "_");
    if (ALIAS.equals(aliasPart)) {
        String allPart = StringUtils.substringAfter(filterName, "_");
        String firstPart = StringUtils.substringBefore(allPart, "_");
        this.aliasName = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
        String joinTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());
        this.joinType = Enum.valueOf(JoinType.class, joinTypeCode).getValue();
        filterName = StringUtils.substringAfter(allPart, "_");
    }
    // ?????matchTypepropertyTypeCode
    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }
    // ??OR
    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    Assert.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);
}

From source file:com.github.fritaly.graphml4j.samples.GradleDependenciesWithGroups.java

private static Artifact createArtifact(String value) {
    // Examples of input values:
    // "org.springframework:spring-core:3.2.0.RELEASE (*)"
    // "com.acme:acme-logging:1.16.0 -> 1.16.3 (*)"
    // "junit:junit:3.8.1 -> 4.8.1"
    // "sun-jaxb:jaxb-impl:2.2"

    if (value.endsWith(" (*)")) {
        // Ex: "org.springframework:spring-core:3.2.0.RELEASE (*)" => "org.springframework:spring-core:3.2.0.RELEASE"
        value = value.replace(" (*)", "");
    }/*from w  w  w  . ja v a  2  s .c om*/
    if (value.contains(" -> ")) {
        // Ex: "junit:junit:3.8.1 -> 4.8.1" => "junit:junit:4.8.1"
        final String version = StringUtils.substringAfter(value, " -> ");

        value = StringUtils.substringBeforeLast(value, ":") + ":" + version;
    }

    return new Artifact(value);
}

From source file:com.amalto.core.query.user.UserQueryHelper.java

public static Condition buildCondition(UserQueryBuilder queryBuilder, IWhereItem whereItem,
        MetadataRepository repository) {
    if (whereItem == null) {
        return TRUE;
    }/*from www.j a v  a 2  s . c  o  m*/
    if (whereItem instanceof WhereAnd || whereItem instanceof WhereOr) { // Handle ANDs and ORs
        List<IWhereItem> whereItems = ((WhereLogicOperator) whereItem).getItems();
        Condition current;
        // TMDM-7513: Prevent incorrect conditions (choose right constant condition depending on operator).
        if (whereItem instanceof WhereAnd) {
            current = TRUE;
        } else {
            current = FALSE;
        }
        for (IWhereItem item : whereItems) {
            if (whereItem instanceof WhereAnd) {
                current = and(current, buildCondition(queryBuilder, item, repository));
            } else {
                current = or(current, buildCondition(queryBuilder, item, repository));
            }
        }
        return current;
    } else if (whereItem instanceof WhereCondition) {
        WhereCondition whereCondition = (WhereCondition) whereItem;
        String operator = whereCondition.getOperator();
        String value = whereCondition.getRightValueOrPath();
        boolean isNotCondition = WhereCondition.PRE_NOT.equals(whereCondition.getStringPredicate());
        // Get metadata information for building query
        String leftPath = whereCondition.getLeftPath();
        ComplexTypeMetadata leftType;
        if (leftPath.contains("/")) { //$NON-NLS-1$
            String leftTypeName = leftPath.substring(0, leftPath.indexOf('/'));
            if (".".equals(leftTypeName)) { //$NON-NLS-1$
                // When using ".", uses first type in select
                leftTypeName = queryBuilder.getSelect().getTypes().get(0).getName();
            }
            leftType = repository.getComplexType(leftTypeName);
        } else {
            leftType = queryBuilder.getSelect().getTypes().get(0);
        }
        String leftFieldName = StringUtils.substringAfter(leftPath, "/"); //$NON-NLS-1$
        // Full text query handling
        if (WhereCondition.FULLTEXTSEARCH.equals(operator)) {
            if (StringUtils.isEmpty(leftPath) || "/".equals(leftPath) || StringUtils.isEmpty(leftFieldName)) { //$NON-NLS-1$
                // Special case for full text: left path is actually the keyword for full text search.
                return fullText(value);
            } else {
                return fullText(leftType.getField(leftFieldName), value);
            }
        }
        if (leftPath.indexOf('/') == -1) {
            throw new IllegalArgumentException(
                    "Incorrect XPath '" + leftPath + "'. An XPath like 'Entity/element' was expected."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        boolean isPerformingTypeCheck = false;
        if (leftFieldName.endsWith("xsi:type") || leftFieldName.endsWith("tmdm:type")) { //$NON-NLS-1$ //$NON-NLS-2$
            isPerformingTypeCheck = true;
        }
        List<TypedExpression> fields;
        if (UserQueryBuilder.ALL_FIELD.equals(leftFieldName)) {
            Collection<FieldMetadata> list = leftType.getFields();
            fields = new LinkedList<TypedExpression>();
            for (FieldMetadata fieldMetadata : list) {
                if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
                    fields.add(new Field(fieldMetadata));
                }
            }
        } else {
            fields = getInnerField(leftPath);
        }
        if (fields == null) {
            fields = getFields(leftType, leftFieldName);
        }
        Condition condition = null;
        for (TypedExpression field : fields) {
            // Field comparisons
            if (!isRealXpath(repository, whereCondition.getRightValueOrPath())) { // Value based comparison
                if (isPerformingTypeCheck) {
                    if (!WhereCondition.EMPTY_NULL.equals(whereCondition.getOperator())) {
                        if (!(field instanceof Alias)) {
                            throw new IllegalArgumentException(
                                    "Expected field '" + leftFieldName + "' to be an alias.");
                        }
                        Alias alias = (Alias) field;
                        if (!(alias.getTypedExpression() instanceof Type)) {
                            throw new IllegalArgumentException(
                                    "Expected alias '" + leftFieldName + "' to be an alias of type.");
                        }
                        Type fieldExpression = (Type) alias.getTypedExpression();
                        ComplexTypeMetadata typeForCheck = (ComplexTypeMetadata) fieldExpression.getField()
                                .getFieldMetadata().getType();
                        if (!typeForCheck.getName().equals(value)) {
                            for (ComplexTypeMetadata subType : typeForCheck.getSubTypes()) {
                                if (subType.getName().equals(value)) {
                                    typeForCheck = subType;
                                    break;
                                }
                            }
                        }
                        condition = isa(fieldExpression.getField().getFieldMetadata(), typeForCheck);
                    } else {
                        // TMDM-6831: Consider a "emptyOrNull(type)" as a "isa(field, actual_field_type)".
                        Alias alias = (Alias) field;
                        if (!(alias.getTypedExpression() instanceof Type)) {
                            throw new IllegalArgumentException(
                                    "Expected alias '" + leftFieldName + "' to be an alias of type.");
                        }
                        Type fieldExpression = (Type) alias.getTypedExpression();
                        condition = emptyOrNull(fieldExpression);
                    }
                } else {
                    boolean isFk = field instanceof Field
                            && ((Field) field).getFieldMetadata() instanceof ReferenceFieldMetadata;
                    if (!isFk
                            && (field instanceof Field && !StorageMetadataUtils.isValueAssignable(value,
                                    ((Field) field).getFieldMetadata()))
                            && !WhereCondition.EMPTY_NULL.equals(operator)) {
                        LOGGER.warn(
                                "Skip '" + leftFieldName + "' because it can't accept value '" + value + "'");
                        continue;
                    }
                    if (WhereCondition.CONTAINS.equals(operator)) {
                        condition = add(condition, contains(field, value));
                    } else if (WhereCondition.CONTAINS_SENTENCE.equals(operator)) {
                        condition = add(condition, contains(field, value));
                    } else if (WhereCondition.EQUALS.equals(operator)) {
                        condition = add(condition, eq(field, value));
                    } else if (WhereCondition.GREATER_THAN.equals(operator)) {
                        condition = add(condition, gt(field, value));
                    } else if (WhereCondition.GREATER_THAN_OR_EQUAL.equals(operator)) {
                        condition = add(condition, gte(field, value));
                    } else if (WhereCondition.LOWER_THAN.equals(operator)) {
                        condition = add(condition, lt(field, value));
                    } else if (WhereCondition.LOWER_THAN_OR_EQUAL.equals(operator)) {
                        condition = add(condition, lte(field, value));
                    } else if (WhereCondition.NOT_EQUALS.equals(operator)) {
                        condition = add(condition, neq(field, value));
                    } else if (WhereCondition.STARTSWITH.equals(operator)) {
                        condition = add(condition, startsWith(field, value));
                    } else if (WhereCondition.EMPTY_NULL.equals(operator)) {
                        condition = add(condition, emptyOrNull(field));
                    } else {
                        throw new NotImplementedException("'" + operator + "' support not implemented.");
                    }
                }
            } else {
                // Right value is another field name
                String rightTypeName = StringUtils.substringBefore(whereCondition.getRightValueOrPath(), "/"); //$NON-NLS-1$
                String rightFieldName = StringUtils.substringAfter(whereCondition.getRightValueOrPath(), "/"); //$NON-NLS-1$
                FieldMetadata leftField = leftType.getField(leftFieldName);
                ComplexTypeMetadata rightType = repository.getComplexType(rightTypeName);
                if (rightType == null) {
                    throw new IllegalArgumentException("Path '" + whereCondition.getRightValueOrPath()
                            + "' seems invalid (entity '" + rightTypeName + "' does not exist).");
                }
                FieldMetadata rightField = rightType.getField(rightFieldName);
                if (WhereCondition.EQUALS.equals(operator)) {
                    condition = add(condition, eq(leftField, rightField));
                } else if (WhereCondition.LOWER_THAN_OR_EQUAL.equals(operator)) {
                    condition = add(condition, lte(leftField, rightField));
                } else if (WhereCondition.JOINS.equals(operator)) {
                    if (field instanceof Field) {
                        FieldMetadata fieldMetadata = ((Field) field).getFieldMetadata();
                        if (!(fieldMetadata instanceof ReferenceFieldMetadata)) {
                            throw new IllegalArgumentException(
                                    "Field '" + leftFieldName + "' is not a FK field.");
                        }
                        queryBuilder.join(field, ((ReferenceFieldMetadata) fieldMetadata).getReferencedField());
                    } else {
                        throw new IllegalArgumentException(
                                "Can not perform not on '" + leftFieldName + "' because it is not a field.");
                    }
                } else {
                    throw new NotImplementedException(
                            "'" + operator + "' support not implemented for field to field comparison.");
                }
            }
        }
        if (condition == null) {
            return TRUE;
        }
        if (isNotCondition) {
            return not(condition);
        } else {
            return condition;
        }
    } else {
        throw new NotImplementedException(
                "No support for where item of type " + whereItem.getClass().getName());
    }
}

From source file:com.github.bluetiger9.nosql.benchmarking.clients.document.mongodb.MongoDBClient.java

private static ServerAddress getServerAddress(String server) throws UnknownHostException {
    final String host = StringUtils.substringBefore(server, ":");
    final String port = StringUtils.substringAfter(server, ":");
    if (!StringUtils.isBlank(port)) {
        return new ServerAddress(host, Integer.parseInt(port));
    } else {/*from  www. j ava 2 s.  c om*/
        return new ServerAddress(host);
    }
}

From source file:info.magnolia.cms.filters.Mapping.java

private Matcher findMatcher(HttpServletRequest request) {
    String uri = null;// ww  w .j a v  a 2 s .com
    WebContext ctx = MgnlContext.getWebContextOrNull();
    if (ctx != null) {
        uri = ctx.getAggregationState().getCurrentURI();
    }
    if (uri == null) {
        // the web context is not available during installation
        uri = StringUtils.substringAfter(request.getRequestURI(), request.getContextPath());
    }
    return findMatcher(uri);
}

From source file:info.magnolia.voting.voters.BasePatternVoter.java

protected String resolveURIFromValue(Object value) {
    String uri = null;//w w  w. ja v a 2 s . c  o m
    if (value instanceof String) {
        uri = (String) value;
    } else {
        if (MgnlContext.hasInstance()) {
            uri = MgnlContext.getAggregationState().getCurrentURI();
        } else {
            if (value instanceof HttpServletRequest) {
                HttpServletRequest request = (HttpServletRequest) value;
                uri = StringUtils.substringAfter(request.getRequestURI(), request.getContextPath());
            }
        }
    }
    return uri;
}