List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.apache.jackrabbit.core.query.lucene.JahiaIndexingConfigurationImpl.java
/** * Returns the analyzer configured for the property with this fieldName * (the string representation ,JCR-style name, of the given <code>Name</code> * prefixed with <code>FieldNames.FULLTEXT_PREFIX</code>)), * and <code>null</code> if none is configured, or the configured analyzer * cannot be found. If <code>null</code> is returned, the default Analyzer * is used./*www . j av a 2 s . com*/ * * @param fieldName the string representation ,JCR-style name, of the given <code>Name</code> * prefixed with <code>FieldNames.FULLTEXT_PREFIX</code>)) * @return the <code>analyzer</code> to use for indexing this property */ public Analyzer getPropertyAnalyzer(String fieldName) { Analyzer analyzer = StringUtils.contains(fieldName, FACET_EXPRESSION) ? keywordAnalyzer : super.getPropertyAnalyzer( StringUtils.startsWith(fieldName, SPELLCHECK_EXPRESSION) ? "0:FULL:SPELLCHECK" : fieldName); return analyzer; }
From source file:org.apache.jackrabbit.core.query.lucene.JahiaLuceneQueryFactoryImpl.java
protected Query getFullTextSearchQuery(FullTextSearch fts) throws RepositoryException { Query qobj = null;// w w w.j a v a 2s.c om if (StringUtils.startsWith(fts.getPropertyName(), "rep:filter(")) { try { StaticOperand expr = fts.getFullTextSearchExpression(); if (expr instanceof Literal) { String expression = ((Literal) expr).getLiteralValue().getString(); // check if query is a single range query with mixed inclusive/exclusive endpoints, then // directly create range query as the Lucene parser fails with ParseException (LUCENE-996) qobj = resolveSingleMixedInclusiveExclusiveRangeQuery(expression); if (qobj == null) { QueryParser qp = new JahiaQueryParser(FieldNames.FULLTEXT, new KeywordAnalyzer()); qp.setLowercaseExpandedTerms(false); qobj = qp.parse(expression); } } else { throw new RepositoryException("Unknown static operand type: " + expr); } } catch (ParseException e) { throw new RepositoryException(e); } } else { qobj = super.getFullTextSearchQuery(fts); } return qobj; }
From source file:org.apache.james.mailbox.inmemory.mail.InMemoryAnnotationMapper.java
private Predicate<MailboxAnnotationKey> filterAnnotationsByPrefix(final MailboxAnnotation input) { return new Predicate<MailboxAnnotationKey>() { @Override//from ww w.j a v a 2 s. c om public boolean apply(MailboxAnnotationKey key) { return key.equals(input.getKey()) || StringUtils.startsWith(input.getKey().asString(), key.asString() + "/"); } }; }
From source file:org.apache.jetspeed.portlets.sso.DefaultSSOSiteCredentialsProviderImpl.java
public List<SSOSiteCredentials> getSSOCredentials(HttpServletRequest request, String siteURL) { List<SSOSiteCredentials> ssoSiteCreds = new ArrayList<SSOSiteCredentials>(); HttpSession session = request.getSession(false); if (session == null) { return ssoSiteCreds; }//from ww w . ja v a2 s . com List<SSOSiteCredentials> ssoSiteCredsOfSubject = (List<SSOSiteCredentials>) session .getAttribute(SSOReverseProxyIFramePortlet.SUBJECT_SSO_SITE_CREDS); if (ssoSiteCredsOfSubject != null) { URI siteURI = URI.create(siteURL); for (SSOSiteCredentials ssoCreds : ssoSiteCredsOfSubject) { try { String siteBaseURL = ssoCreds.getBaseURL(); if (StringUtils.startsWith(siteURL, siteBaseURL) && ssoCreds.getHost().equals(siteURI.getHost()) && ssoCreds.getPort() == siteURI.getPort()) { ssoSiteCreds.add(ssoCreds); } } catch (Exception e) { if (log.isWarnEnabled()) { log.warn("Failed to match site uri. {}", e.toString()); } } } } if (!ssoSiteCreds.isEmpty()) { Collections.sort(ssoSiteCreds, new URLMatchDifferenceBasedComparator<SSOSiteCredentials>(siteURL)); } return ssoSiteCreds; }
From source file:org.apache.metron.stellar.common.shell.DefaultStellarAutoCompleter.java
/** * Is a given expression a built-in magic? * @param expression The expression./*from ww w . j a va2 s .co m*/ */ private boolean isMagic(String expression) { return StringUtils.startsWith(expression, "%"); }
From source file:org.apache.metron.stellar.common.shell.DefaultStellarAutoCompleter.java
/** * Is a given expression asking for function documentation? * @param expression The expression./*from w w w .j a v a 2s.c o m*/ */ private boolean isDoc(String expression) { return StringUtils.startsWith(expression, "?"); }
From source file:org.apache.ranger.plugin.policyengine.RangerPolicyRepository.java
private RangerServiceDef normalizeAccessTypeDefs(RangerServiceDef serviceDef, final String componentType) { if (serviceDef != null && StringUtils.isNotBlank(componentType)) { List<RangerServiceDef.RangerAccessTypeDef> accessTypeDefs = serviceDef.getAccessTypes(); if (CollectionUtils.isNotEmpty(accessTypeDefs)) { String prefix = componentType + AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR; List<RangerServiceDef.RangerAccessTypeDef> unneededAccessTypeDefs = null; for (RangerServiceDef.RangerAccessTypeDef accessTypeDef : accessTypeDefs) { String accessType = accessTypeDef.getName(); if (StringUtils.startsWith(accessType, prefix)) { String newAccessType = StringUtils.removeStart(accessType, prefix); accessTypeDef.setName(newAccessType); Collection<String> impliedGrants = accessTypeDef.getImpliedGrants(); if (CollectionUtils.isNotEmpty(impliedGrants)) { Collection<String> newImpliedGrants = null; for (String impliedGrant : impliedGrants) { if (StringUtils.startsWith(impliedGrant, prefix)) { String newImpliedGrant = StringUtils.removeStart(impliedGrant, prefix); if (newImpliedGrants == null) { newImpliedGrants = new ArrayList<String>(); }//from w w w . java 2 s . co m newImpliedGrants.add(newImpliedGrant); } } accessTypeDef.setImpliedGrants(newImpliedGrants); } } else if (StringUtils.contains(accessType, AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR)) { if (unneededAccessTypeDefs == null) { unneededAccessTypeDefs = new ArrayList<RangerServiceDef.RangerAccessTypeDef>(); } unneededAccessTypeDefs.add(accessTypeDef); } } if (unneededAccessTypeDefs != null) { accessTypeDefs.removeAll(unneededAccessTypeDefs); } } } return serviceDef; }
From source file:org.apache.ranger.plugin.policyengine.RangerPolicyRepository.java
private List<? extends RangerPolicy.RangerPolicyItem> normalizeAndPrunePolicyItems( List<? extends RangerPolicy.RangerPolicyItem> policyItems, final String componentType) { if (CollectionUtils.isNotEmpty(policyItems)) { final String prefix = componentType + AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR; List<RangerPolicy.RangerPolicyItem> itemsToPrune = null; for (RangerPolicy.RangerPolicyItem policyItem : policyItems) { List<RangerPolicy.RangerPolicyItemAccess> policyItemAccesses = policyItem.getAccesses(); if (CollectionUtils.isNotEmpty(policyItemAccesses)) { List<RangerPolicy.RangerPolicyItemAccess> accessesToPrune = null; for (RangerPolicy.RangerPolicyItemAccess access : policyItemAccesses) { String accessType = access.getType(); if (StringUtils.startsWith(accessType, prefix)) { String newAccessType = StringUtils.removeStart(accessType, prefix); access.setType(newAccessType); } else if (accessType.contains(AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR)) { if (accessesToPrune == null) { accessesToPrune = new ArrayList<RangerPolicy.RangerPolicyItemAccess>(); }/*from ww w . ja va 2s . com*/ accessesToPrune.add(access); } } if (accessesToPrune != null) { policyItemAccesses.removeAll(accessesToPrune); } if (policyItemAccesses.isEmpty() && !policyItem.getDelegateAdmin()) { if (itemsToPrune == null) { itemsToPrune = new ArrayList<RangerPolicy.RangerPolicyItem>(); } itemsToPrune.add(policyItem); } } } if (itemsToPrune != null) { policyItems.removeAll(itemsToPrune); } } return policyItems; }
From source file:org.apache.ranger.plugin.resourcematcher.RangerAbstractResourceMatcher.java
@Override boolean isMatch(String resourceValue, Map<String, Object> evalContext) { return StringUtils.startsWith(resourceValue, getExpandedValue(evalContext)); }
From source file:org.apache.ranger.plugin.util.RangerServiceNotFoundException.java
public static final void throwExceptionIfServiceNotFound(String serviceName, String exceptionMsg) throws RangerServiceNotFoundException { String expectedExceptionMsg = buildExceptionMsg(serviceName); if (StringUtils.startsWith(exceptionMsg, expectedExceptionMsg)) { throw new RangerServiceNotFoundException(serviceName); }/* w w w . j ava 2 s . c o m*/ }