List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.apache.syncope.client.lib.RestClientExceptionMapper.java
private SyncopeClientCompositeException checkSyncopeClientCompositeException(final Response response) { SyncopeClientCompositeException compException = SyncopeClientException.buildComposite(); // Attempts to read ErrorTO or List<ErrorTO> as entity... List<ErrorTO> errors = null; try {// ww w .j av a 2s. co m ErrorTO error = response.readEntity(ErrorTO.class); if (error != null) { errors = Collections.singletonList(error); } } catch (Exception e) { LOG.debug("Could not read {}, attempting to read composite...", ErrorTO.class.getName(), e); } if (errors == null) { try { errors = response.readEntity(new GenericType<List<ErrorTO>>() { }); } catch (Exception e) { LOG.debug("Could not read {} list, attempting to read headers...", ErrorTO.class.getName(), e); } } // ...if not possible, attempts to parse response headers if (errors == null) { List<String> exTypesInHeaders = response.getStringHeaders().get(RESTHeaders.ERROR_CODE); if (exTypesInHeaders == null) { LOG.debug("No " + RESTHeaders.ERROR_CODE + " provided"); return null; } List<String> exInfos = response.getStringHeaders().get(RESTHeaders.ERROR_INFO); Set<String> handledExceptions = new HashSet<>(); exTypesInHeaders.forEach(exTypeAsString -> { ClientExceptionType exceptionType = null; try { exceptionType = ClientExceptionType.fromHeaderValue(exTypeAsString); } catch (IllegalArgumentException e) { LOG.error("Unexpected value of " + RESTHeaders.ERROR_CODE + ": " + exTypeAsString, e); } if (exceptionType != null) { handledExceptions.add(exTypeAsString); SyncopeClientException clientException = SyncopeClientException.build(exceptionType); if (exInfos != null && !exInfos.isEmpty()) { for (String element : exInfos) { if (element.startsWith(exceptionType.name())) { clientException.getElements().add(StringUtils.substringAfter(element, ":")); } } } compException.addException(clientException); } }); exTypesInHeaders.removeAll(handledExceptions); if (!exTypesInHeaders.isEmpty()) { LOG.error("Unmanaged exceptions: " + exTypesInHeaders); } } else { for (ErrorTO error : errors) { SyncopeClientException clientException = SyncopeClientException.build(error.getType()); clientException.getElements().addAll(error.getElements()); compException.addException(clientException); } } if (compException.hasExceptions()) { return compException; } return null; }
From source file:org.apache.syncope.client.rest.RestClientExceptionMapper.java
private SyncopeClientCompositeException checkSyncopeClientCompositeException(final Response response) { List<Object> exTypesInHeaders = response.getHeaders().get(RESTHeaders.ERROR_CODE); if (exTypesInHeaders == null) { LOG.debug("No " + RESTHeaders.ERROR_CODE + " provided"); return null; }// www . j a v a2 s . co m final SyncopeClientCompositeException compException = SyncopeClientException.buildComposite(); final Set<String> handledExceptions = new HashSet<String>(); for (Object exceptionTypeValue : exTypesInHeaders) { final String exTypeAsString = (String) exceptionTypeValue; ClientExceptionType exceptionType = null; try { exceptionType = ClientExceptionType.fromHeaderValue(exTypeAsString); } catch (IllegalArgumentException e) { LOG.error("Unexpected value of " + RESTHeaders.ERROR_CODE + ": " + exTypeAsString, e); } if (exceptionType != null) { handledExceptions.add(exTypeAsString); final SyncopeClientException clientException = SyncopeClientException.build(exceptionType); if (response.getHeaders().get(RESTHeaders.ERROR_INFO) != null && !response.getHeaders().get(RESTHeaders.ERROR_INFO).isEmpty()) { for (Object value : response.getHeaders().get(RESTHeaders.ERROR_INFO)) { final String element = value.toString(); if (element.startsWith(exceptionType.getHeaderValue())) { clientException.getElements().add(StringUtils.substringAfter(value.toString(), ":")); } } } compException.addException(clientException); } } exTypesInHeaders.removeAll(handledExceptions); if (!exTypesInHeaders.isEmpty()) { LOG.error("Unmanaged exceptions: " + exTypesInHeaders); } if (compException.hasExceptions()) { return compException; } return null; }
From source file:org.apache.syncope.core.persistence.jpa.dao.AbstractAnyDAO.java
@Transactional(readOnly = true) @Override//from w ww . java 2s . c o m public A authFind(final String key) { if (key == null) { throw new NotFoundException("Null key"); } A any = find(key); if (any == null) { throw new NotFoundException(StringUtils.substringBefore( StringUtils.substringAfter(getClass().getSimpleName(), "JPA"), "DAO") + " " + key); } securityChecks(any); return any; }
From source file:org.apache.syncope.fit.core.reference.PrefixMappingItemTransformer.java
@Override public List<Object> beforePull(final MappingItem mappingItem, final AnyTO anyTO, final List<Object> values) { if (values == null || values.isEmpty() || values.get(0) == null) { return super.beforePull(mappingItem, anyTO, values); } else {//from ww w .j av a 2 s . c o m List<Object> newValues = new ArrayList<>(values); newValues.set(0, StringUtils.substringAfter(values.get(0).toString(), PREFIX)); return newValues; } }
From source file:org.apache.unomi.persistence.elasticsearch.conditions.ConditionContextHelper.java
@SuppressWarnings("unchecked") private static Object parseParameter(Map<String, Object> context, Object value) { if (value instanceof String) { if (((String) value).startsWith("parameter::") || ((String) value).startsWith("script::")) { String s = (String) value; if (s.startsWith("parameter::")) { return context.get(StringUtils.substringAfter(s, "parameter::")); } else if (s.startsWith("script::")) { String script = StringUtils.substringAfter(s, "script::"); if (!mvelExpressions.containsKey(script)) { ParserConfiguration parserConfiguration = new ParserConfiguration(); parserConfiguration.setClassLoader(ConditionContextHelper.class.getClassLoader()); mvelExpressions.put(script, MVEL.compileExpression(script, new ParserContext(parserConfiguration))); }//from w ww . j a v a 2 s . c om return MVEL.executeExpression(mvelExpressions.get(script), context); } } } else if (value instanceof Map) { Map<String, Object> values = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : ((Map<String, Object>) value).entrySet()) { Object parameter = parseParameter(context, entry.getValue()); if (parameter == null) { return null; } values.put(entry.getKey(), parameter); } return values; } else if (value instanceof List) { List<Object> values = new ArrayList<Object>(); for (Object o : ((List<?>) value)) { Object parameter = parseParameter(context, o); if (parameter != null) { values.add(parameter); } } return values; } return value; }
From source file:org.apache.unomi.services.actions.ActionExecutorDispatcher.java
@SuppressWarnings("unchecked") private Map<String, Object> parseMap(Event event, Map<String, Object> map) { Map<String, Object> values = new HashMap<>(); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { String s = (String) value; try { // check if we have special values if (s.contains(VALUE_NAME_SEPARATOR)) { final String valueType = StringUtils.substringBefore(s, VALUE_NAME_SEPARATOR); final String valueAsString = StringUtils.substringAfter(s, VALUE_NAME_SEPARATOR); final ValueExtractor extractor = valueExtractors.get(valueType); if (extractor != null) { value = extractor.extract(valueAsString, event); }/*from w ww .jav a 2s .com*/ } } catch (UnsupportedOperationException e) { throw e; } catch (Exception e) { throw new UnsupportedOperationException(e); } } else if (value instanceof Map) { value = parseMap(event, (Map<String, Object>) value); } values.put(entry.getKey(), value); } return values; }
From source file:org.blocks4j.reconf.infra.i18n.BundleSettings.java
public BundleSettings(Class<?> cls) { className = cls.getSimpleName();/* ww w.j a v a 2s . c om*/ String[] packages = StringUtils.split(cls.getPackage().getName(), '.'); if (packages.length == 0 || packages.length == 1) { throw new IllegalArgumentException("only meant to be used inside reconf"); } headPackageName = packages[3]; if (packages.length >= 2) { tailPackageName = StringUtils.substringAfter(cls.getPackage().getName(), "reconf." + headPackageName + "."); } else { tailPackageName = StringUtils.EMPTY; } }
From source file:org.codice.git.hook.PreCommit.java
public boolean executeHook(String[] args) throws Exception { if (!hasDirtyWords()) { // no dirty words; all accepted so bail! return false; }//ww w .j a v a 2 s . c o m LOGGER.finer("Executing the git diff to determine files with changes."); final String diff = repoHandler.getDiff(); final Set<String> foundWords = new HashSet<String>(); final Set<String> foundInFiles = new HashSet<String>(); final StringBuilder sb = new StringBuilder(); String currentFile = "???"; boolean dirty = false; LOGGER.log(Level.FINEST, "Diff for this commit: {0}", diff); for (final String line : StringUtils.split(diff, '\n')) { if (line.startsWith("+++ b/")) { if ((sb.length() > 0) && containsDirtyWords(sb.toString(), foundWords)) { dirty = true; foundInFiles.add(currentFile); } sb.setLength(0); currentFile = StringUtils.substringAfter(line, "+++ b/"); // continue which will allow us to validate the filename as well } sb.append(line).append('\n'); // accumulate all lines to check in one shot } if ((sb.length() > 0) && containsDirtyWords(sb.toString(), foundWords)) { dirty = true; foundInFiles.add(currentFile); } if (dirty) { LOGGER.log(Level.FINE, "Dirty words found: {0}", foundWords); LOGGER.log(Level.FINE, "Files with dirty words: {0}", foundInFiles); sb.setLength(0); Hook.appendDirtyWords(sb, foundWords).append("In files:%n"); for (final String f : foundInFiles) { sb.append('\t').append(f).append("%n"); } // the double formatting is to properly support %n in the string builder too! System.out.printf(String.format(ERR_MSG, sb)); return true; } else { LOGGER.info("Commit is clean."); System.out.println("Commit is clean."); return false; } }
From source file:org.craftercms.engine.navigation.impl.NavBreadcrumbBuilderImpl.java
protected String extractBreadcrumbUrl(String url, String root) { String indexFileName = SiteProperties.getIndexFileName(); String breadcrumbUrl = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, root), indexFileName);//from w w w.j ava2 s. c o m if (!breadcrumbUrl.startsWith("/")) { breadcrumbUrl = "/" + breadcrumbUrl; } return breadcrumbUrl; }
From source file:org.craftercms.engine.targeting.impl.CandidateTargetedUrlsResolverImpl.java
@Override public List<String> getUrls(String targetedUrl) { List<String> candidateUrls = new ArrayList<>(); String rootFolder = TargetingUtils.getMatchingRootFolder(targetedUrl); if (StringUtils.isNotEmpty(rootFolder)) { String relativeTargetedUrl = StringUtils.substringAfter(targetedUrl, rootFolder); TargetedUrlComponents urlComp = targetedUrlStrategy.parseTargetedUrl(relativeTargetedUrl); if (urlComp != null) { String prefix = UrlUtils.concat(rootFolder, urlComp.getPrefix()); String suffix = urlComp.getSuffix(); String targetId = urlComp.getTargetId(); String fallbackTargetId = targetIdManager.getFallbackTargetId(); List<String> candidateTargetIds = candidateTargetIdsResolver.getTargetIds(targetId, fallbackTargetId);/*www. j ava 2 s.c o m*/ if (CollectionUtils.isNotEmpty(candidateTargetIds)) { for (String candidateTargetId : candidateTargetIds) { candidateUrls.add(targetedUrlStrategy.buildTargetedUrl(prefix, candidateTargetId, suffix)); } } else { candidateUrls.add(targetedUrl); } } else { candidateUrls.add(targetedUrl); } } else { candidateUrls.add(targetedUrl); } return candidateUrls; }