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:org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor.java

/**
 * Squash operations for cgroups - e.g mount, add pid to cgroup etc .,
 * For now, we only implement squashing for 'add pid to cgroup' since this
 * is the only optimization relevant to launching containers
 *
 * @return single squashed cgroup operation. Null on failure.
 *//*from  w w w . j a  v  a  2 s  . c o m*/

public static PrivilegedOperation squashCGroupOperations(List<PrivilegedOperation> ops)
        throws PrivilegedOperationException {
    if (ops.size() == 0) {
        return null;
    }

    StringBuffer finalOpArg = new StringBuffer(PrivilegedOperation.CGROUP_ARG_PREFIX);
    boolean noTasks = true;

    for (PrivilegedOperation op : ops) {
        if (!op.getOperationType().equals(PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP)) {
            LOG.warn("Unsupported operation type: " + op.getOperationType());
            throw new PrivilegedOperationException("Unsupported operation type:" + op.getOperationType());
        }

        List<String> args = op.getArguments();
        if (args.size() != 1) {
            LOG.warn("Invalid number of args: " + args.size());
            throw new PrivilegedOperationException("Invalid number of args: " + args.size());
        }

        String arg = args.get(0);
        String tasksFile = StringUtils.substringAfter(arg, PrivilegedOperation.CGROUP_ARG_PREFIX);
        if (tasksFile == null || tasksFile.isEmpty()) {
            LOG.warn("Invalid argument: " + arg);
            throw new PrivilegedOperationException("Invalid argument: " + arg);
        }

        if (tasksFile.equals(PrivilegedOperation.CGROUP_ARG_NO_TASKS)) {
            //Don't append to finalOpArg
            continue;
        }

        if (noTasks == false) {
            //We have already appended at least one tasks file.
            finalOpArg.append(PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR);
            finalOpArg.append(tasksFile);
        } else {
            finalOpArg.append(tasksFile);
            noTasks = false;
        }
    }

    if (noTasks) {
        finalOpArg.append(PrivilegedOperation.CGROUP_ARG_NO_TASKS); //there
        // were no tasks file to append
    }

    PrivilegedOperation finalOp = new PrivilegedOperation(PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP,
            finalOpArg.toString());

    return finalOp;
}

From source file:org.apache.jackrabbit.core.query.lucene.FacetHandler.java

private void extractFacetInfo(NamedList<Object> info, SolrParams solrParams) {
    // Parse the queries
    _facetQuery = new LinkedHashMap<String, Long>();
    NamedList<Long> fq = (NamedList<Long>) info.get("facet_queries");
    if (fq != null) {
        for (Map.Entry<String, Long> entry : fq) {
            _facetQuery.put(entry.getKey(), entry.getValue());
        }//from   w w w.ja va  2  s.  c om
    }

    // Parse the facet info into fields
    // TODO?? The list could be <int> or <long>? If always <long> then we can switch to <Long>
    NamedList<NamedList<Number>> ff = (NamedList<NamedList<Number>>) info.get("facet_fields");
    Map<String, FieldType> fieldTypeMap = new HashMap<>();
    if (ff != null) {
        _facetFields = new ArrayList<FacetField>(ff.size());
        _limitingFacets = new ArrayList<FacetField>(ff.size());
        long minsize = totalSize;
        for (Map.Entry<String, NamedList<Number>> facet : ff) {
            String key = StringUtils.substringBeforeLast(facet.getKey(),
                    SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR);
            String fieldInIndex = StringUtils.substringAfterLast(facet.getKey(),
                    SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR);
            FacetField f = new FacetField(key);
            if (!fieldTypeMap.containsKey(key)) {
                try {
                    //Find a key like f.field_name#unknownumber.facet.nodetype
                    Pattern facetNodetype = Pattern.compile("f\\." + key + "#[0-9]+\\.facet\\.nodetype");
                    String nodetypeName = null;
                    Iterator<String> parameterNamesIterator = solrParams.getParameterNamesIterator();
                    while (parameterNamesIterator.hasNext()) {
                        String next = parameterNamesIterator.next();
                        if (facetNodetype.matcher(next).matches()) {
                            nodetypeName = solrParams.get(next);
                            break;
                        }
                    }
                    ExtendedPropertyDefinition epd = NodeTypeRegistry.getInstance().getNodeType(nodetypeName)
                            .getPropertyDefinition(key);
                    fieldTypeMap.put(key, getType(epd));
                } catch (NoSuchNodeTypeException e) {
                    log.error(e.getMessage(), e);
                }
            }
            for (Map.Entry<String, Number> entry : facet.getValue()) {
                String facetValue = entry.getKey();
                String query = fieldTypeMap.get(key).toInternal(entry.getKey());
                Matcher matcher = valueWithQuery.matcher(facetValue);
                if (matcher.matches()) {
                    query = matcher.group(2);
                    facetValue = matcher.replaceFirst("$1");
                }
                f.add(facetValue, entry.getValue().longValue());
                f.getValues().get(f.getValueCount() - 1).setFilterQuery(
                        ClientUtils.escapeQueryChars(fieldInIndex) + ":" + ClientUtils.escapeQueryChars(query));
            }

            _facetFields.add(f);
            FacetField nl = f.getLimitingFields(minsize);
            if (nl.getValueCount() > 0) {
                _limitingFacets.add(nl);
            }
        }
    }

    // Parse date facets
    NamedList<NamedList<Object>> df = (NamedList<NamedList<Object>>) info.get("facet_dates");
    if (df != null) {
        // System.out.println(df);
        _facetDates = new ArrayList<FacetField>(df.size());
        for (Map.Entry<String, NamedList<Object>> facet : df) {
            // System.out.println("Key: " + facet.getKey() + " Value: " + facet.getValue());
            NamedList<Object> values = facet.getValue();
            String gap = (String) values.get("gap");
            Date end = (Date) values.get("end");
            FacetField f = new FacetField(StringUtils.substringBeforeLast(facet.getKey(),
                    SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR), gap, end);

            for (Map.Entry<String, Object> entry : values) {
                try {
                    String key = StringUtils.substringBeforeLast(entry.getKey(),
                            SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR);
                    String query = StringUtils.substringAfterLast(entry.getKey(),
                            SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR);
                    f.add(key, Long.parseLong(entry.getValue().toString()));
                    if (!StringUtils.isEmpty(query)) {
                        String rangePrefix = null;
                        if (query.contains(RANGEFROM_EXCLUSIVE_PREFIX)) {
                            rangePrefix = RANGEFROM_EXCLUSIVE_PREFIX;
                        } else if (query.contains(RANGEFROM_INCLUSIVE_PREFIX)) {
                            rangePrefix = RANGEFROM_INCLUSIVE_PREFIX;
                        }
                        if (!StringUtils.isEmpty(rangePrefix)) {
                            f.getValues().get(f.getValueCount() - 1)
                                    .setFilterQuery(ClientUtils
                                            .escapeQueryChars(StringUtils.substringBefore(query, rangePrefix))
                                            + rangePrefix + StringUtils.substringAfter(query, rangePrefix));
                        }
                    }
                } catch (NumberFormatException e) {
                    // Ignore for non-number responses which are already handled above
                }
            }

            _facetDates.add(f);
        }
    }

    // Parse range facets
    NamedList<NamedList<Object>> rf = (NamedList<NamedList<Object>>) info.get("facet_ranges");
    if (rf != null) {
        // System.out.println(df);
        _facetRanges = new ArrayList<RangeFacet>(rf.size());
        for (Map.Entry<String, NamedList<Object>> facet : rf) {
            NamedList<Object> values = facet.getValue();
            Object rawGap = values.get("gap");

            RangeFacet rangeFacet;
            if (rawGap instanceof Number) {
                Number gap = (Number) rawGap;
                Number start = (Number) values.get("start");
                Number end = (Number) values.get("end");

                Number before = (Number) values.get("before");
                Number after = (Number) values.get("after");

                rangeFacet = new RangeFacet.Numeric(StringUtils.substringBeforeLast(facet.getKey(),
                        SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR), start, end, gap, before, after);
            } else {
                String gap = (String) rawGap;
                Date start = (Date) values.get("start");
                Date end = (Date) values.get("end");

                Number before = (Number) values.get("before");
                Number after = (Number) values.get("after");

                rangeFacet = new RangeFacet.Date(StringUtils.substringBeforeLast(facet.getKey(),
                        SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR), start, end, gap, before, after);
            }

            NamedList<Integer> counts = (NamedList<Integer>) values.get("counts");
            for (Map.Entry<String, Integer> entry : counts) {
                try {
                    String key = StringUtils.substringBeforeLast(entry.getKey(),
                            SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR);
                    String query = StringUtils.substringAfterLast(entry.getKey(),
                            SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR);

                    rangeFacet.addCount(key, entry.getValue());

                    if (!StringUtils.isEmpty(query)) {
                        String rangePrefix = null;
                        if (query.contains(RANGEFROM_EXCLUSIVE_PREFIX)) {
                            rangePrefix = RANGEFROM_EXCLUSIVE_PREFIX;
                        } else if (query.contains(RANGEFROM_INCLUSIVE_PREFIX)) {
                            rangePrefix = RANGEFROM_INCLUSIVE_PREFIX;
                        }
                        if (!StringUtils.isEmpty(rangePrefix)) {
                            ((RangeFacet.Count) rangeFacet.getCounts().get(rangeFacet.getCounts().size() - 1))
                                    .setFilterQuery(ClientUtils
                                            .escapeQueryChars(StringUtils.substringBefore(query, rangePrefix))
                                            + rangePrefix + StringUtils.substringAfter(query, rangePrefix));
                        }
                    }
                } catch (NumberFormatException e) {
                    // Ignore for non-number responses which are already handled above
                }
            }

            _facetRanges.add(rangeFacet);
        }
    }
}

From source file:org.apache.jackrabbit.core.query.lucene.JahiaIndexingConfigurationImpl.java

private void processExcludeConfiguration(Element element, NamespaceRegistry namespaceRegistry)
        throws RepositoryException {
    String nodeType = element.getAttribute("nodetype");
    if (StringUtils.isNotEmpty(nodeType)) {
        if (excludesTypesByPath.isEmpty()) {
            excludesTypesByPath = new HashSet<>();
        }//from   w  ww .  j  a  v a  2 s  .co  m
        String path = element.getAttribute("path");
        Boolean isRegexp = Boolean.valueOf(element.getAttribute("isRegexp"));
        NameFactory nf = NameFactoryImpl.getInstance();
        Name nodeTypeName = null;
        try {
            if (!nodeType.startsWith("{")) {
                nodeTypeName = nf.create(namespaceRegistry.getURI(StringUtils.substringBefore(nodeType, ":")),
                        StringUtils.substringAfter(nodeType, ":"));
            } else {
                nodeTypeName = nf.create(nodeType);
            }
        } catch (NamespaceException e) {
            logger.error("Cannot parse namespace for " + nodeType, e);
        } catch (IllegalArgumentException iae) {
            logger.error("Illegal node type name: " + nodeType, iae);
        }
        excludesTypesByPath.add(new ExcludedType(nodeTypeName, path, isRegexp));
    }
}

From source file:org.apache.jackrabbit.core.query.lucene.JahiaLuceneQueryFactoryImpl.java

private boolean checkIndexedAcl(Map<String, Boolean> checkedAcls, IndexedNodeInfo infos)
        throws RepositoryException {
    boolean canRead = true;

    String[] acls = infos.getAclUuid() != null ? Patterns.SPACE.split(infos.getAclUuid())
            : ArrayUtils.EMPTY_STRING_ARRAY;
    ArrayUtils.reverse(acls);//from   ww w.  ja v a2 s. c om

    for (String acl : acls) {
        if (acl.contains("/")) {
            // ACL indexed contains a single user ACE, get the username
            String singleUser = StringUtils.substringAfter(acl, "/");
            acl = StringUtils.substringBefore(acl, "/");
            if (singleUser.contains("/")) {
                // Granted roles are specified in the indexed entry
                String roles = StringUtils.substringBeforeLast(singleUser, "/");
                singleUser = StringUtils.substringAfterLast(singleUser, "/");
                if (!singleUser.equals(session.getUserID())) {
                    // If user does not match, skip this ACL
                    continue;
                } else {
                    // If user matches, check if one the roles gives the read permission
                    for (String role : StringUtils.split(roles, '/')) {
                        if (((JahiaAccessManager) session.getAccessControlManager()).matchPermission(
                                Sets.newHashSet(Privilege.JCR_READ + "_" + session.getWorkspace().getName()),
                                role)) {
                            // User and role matches, read is granted
                            return true;
                        }
                    }
                }
            } else {
                if (!singleUser.equals(session.getUserID())) {
                    // If user does not match, skip this ACL
                    continue;
                }
                // Otherwise, do normal ACL check.
            }
        }
        // Verify first if this acl has already been checked
        Boolean aclChecked = checkedAcls.get(acl);
        if (aclChecked == null) {
            try {
                canRead = session.getAccessManager().canRead(null, new NodeId(acl));
                checkedAcls.put(acl, canRead);
            } catch (RepositoryException e) {
            }
        } else {
            canRead = aclChecked;
        }
        break;
    }
    return canRead;
}

From source file:org.apache.jackrabbit.core.query.lucene.JahiaLuceneQueryFactoryImpl.java

private Query resolveSingleMixedInclusiveExclusiveRangeQuery(String expression) {
    Query qobj = null;// w w w . j a va 2s .c  o m
    boolean inclusiveEndRange = expression.endsWith("]");
    boolean exclusiveEndRange = expression.endsWith("}");
    int inclusiveBeginRangeCount = StringUtils.countMatches(expression, "[");
    int exclusiveBeginRangeCount = StringUtils.countMatches(expression, "{");
    if (((inclusiveEndRange && exclusiveBeginRangeCount == 1 && inclusiveBeginRangeCount == 0)
            || (exclusiveEndRange && inclusiveBeginRangeCount == 1 && exclusiveBeginRangeCount == 0))) {
        String fieldName = (inclusiveEndRange || exclusiveEndRange)
                ? StringUtils.substringBefore(expression, inclusiveEndRange ? ":{" : ":[")
                : "";
        if (fieldName.indexOf(' ') == -1) {
            fieldName = fieldName.replace("\\:", ":");
            String rangeExpression = StringUtils.substringBetween(expression, inclusiveEndRange ? "{" : "[",
                    inclusiveEndRange ? "]" : "}");
            String part1 = StringUtils.substringBefore(rangeExpression, " TO");
            String part2 = StringUtils.substringAfter(rangeExpression, "TO ");
            SchemaField sf = new SchemaField(fieldName, JahiaQueryParser.STRING_TYPE);
            qobj = JahiaQueryParser.STRING_TYPE.getRangeQuery(null, sf, part1.equals("*") ? null : part1,
                    part2.equals("*") ? null : part2, !inclusiveEndRange, inclusiveEndRange);
        }
    }
    return qobj;
}

From source file:org.apache.jackrabbit.core.query.lucene.JahiaSearchIndex.java

@Override
protected void doInit() throws IOException {
    Set<Name> ignoredTypes = new HashSet<>();
    NameFactory nf = NameFactoryImpl.getInstance();
    if (SKIP_VERSION_INDEX && isVersionIndex()) {
        ignoredTypes.add(nf.create(Name.NS_REP_URI, "versionStorage"));
        ignoredTypes.add(nf.create(Name.NS_NT_URI, "versionHistory"));
        ignoredTypes.add(nf.create(Name.NS_NT_URI, "version"));
        ignoredTypes.add(nf.create(Name.NS_NT_URI, "versionLabels"));
        ignoredTypes.add(nf.create(Name.NS_NT_URI, "frozenNode"));
        ignoredTypes.add(nf.create(Name.NS_NT_URI, "versionedChild"));
    }// w w w  .ja v a 2s. co  m
    if (ignoredTypesString != null) {
        for (String s : StringUtils.split(ignoredTypesString, ", ")) {
            try {
                if (!s.startsWith("{")) {
                    try {
                        ignoredTypes.add(nf.create(
                                getContext().getNamespaceRegistry().getURI(StringUtils.substringBefore(s, ":")),
                                StringUtils.substringAfter(s, ":")));
                    } catch (NamespaceException e) {
                        log.error("Cannot parse namespace for " + s, e);
                    }
                } else {
                    ignoredTypes.add(nf.create(s));
                }
            } catch (IllegalArgumentException iae) {
                log.error("Illegal node type name: " + s, iae);
            }
        }
    }
    this.ignoredTypes = ignoredTypes.isEmpty() ? null : ignoredTypes;
    super.doInit();
}

From source file:org.apache.jackrabbit.server.JahiaBasicCredentialsProvider.java

/**
 * Creates the {@link SimpleCredentials} object for the provided username and password considering the impersonation case.
 * /*from  w w  w .jav a2 s .  c o  m*/
 * @param user
 *            the received username
 * @param password
 *            the user password
 * @return the {@link SimpleCredentials} object for the provided username and password considering the impersonation case
 */
protected Credentials createCredentials(String user, char[] password) {
    SimpleCredentials credentials = null;
    if (user != null && user.contains(IMPERSONATOR)) {
        credentials = new SimpleCredentials(StringUtils.substringBefore(user, IMPERSONATOR),
                ArrayUtils.EMPTY_CHAR_ARRAY);

        credentials.setAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE,
                new SimpleCredentials(StringUtils.substringAfter(user, IMPERSONATOR), password));
    } else {
        credentials = new SimpleCredentials(user, password);
    }

    return credentials;
}

From source file:org.apache.lens.cube.parse.CandidateTableResolver.java

private static Date getFactColumnStartTime(CandidateTable table, String factCol) {
    Date startTime = null;/*w  w w  .  j av  a 2 s  . co  m*/
    if (table instanceof StorageCandidate) {
        for (String key : ((StorageCandidate) table).getFact().getProperties().keySet()) {
            if (key.contains(MetastoreConstants.FACT_COL_START_TIME_PFX)) {
                String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_START_TIME_PFX);
                if (factCol.equals(propCol)) {
                    startTime = MetastoreUtil.getDateFromProperty(
                            ((StorageCandidate) table).getFact().getProperties().get(key), false, true);
                }
            }
        }
    }
    return startTime;
}

From source file:org.apache.lens.cube.parse.CandidateTableResolver.java

private static Date getFactColumnEndTime(CandidateTable table, String factCol) {
    Date endTime = null;//from w w w  .j a v  a  2 s . c  o  m
    if (table instanceof StorageCandidate) {
        for (String key : ((StorageCandidate) table).getFact().getProperties().keySet()) {
            if (key.contains(MetastoreConstants.FACT_COL_END_TIME_PFX)) {
                String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_END_TIME_PFX);
                if (factCol.equals(propCol)) {
                    endTime = MetastoreUtil.getDateFromProperty(
                            ((StorageCandidate) table).getFact().getProperties().get(key), false, true);
                }
            }
        }
    }
    return endTime;
}

From source file:org.apache.lens.cube.parse.QueriedPhraseContext.java

public static Date getFactColumnStartTime(CandidateTable table, String factCol) {
    Date startTime = null;//w ww .  j av  a 2 s.co m
    if (table instanceof CandidateFact) {
        for (String key : ((CandidateFact) table).fact.getProperties().keySet()) {
            if (key.contains(MetastoreConstants.FACT_COL_START_TIME_PFX)) {
                String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_START_TIME_PFX);
                if (factCol.equals(propCol)) {
                    startTime = ((CandidateFact) table).fact.getDateFromProperty(key, false, true);
                }
            }
        }
    }
    return startTime;
}