List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer.java
private Property property(final XMLEventReader reader, final StartElement start, final EdmType edmType, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final boolean isCollection) throws XMLStreamException, EdmPrimitiveTypeException, DeserializerException { final Property property = new Property(); if (propertyValueQName.equals(start.getName())) { // retrieve name from context final Attribute context = start.getAttributeByName(contextQName); if (context != null) { property.setName(StringUtils.substringAfterLast(context.getValue(), "/")); }/*from w w w . j a v a2s.c om*/ } else { property.setName(start.getName().getLocalPart()); } valuable(property, reader, start, edmType, isNullable, maxLength, precision, scale, isUnicode, isCollection); return property; }
From source file:org.apache.sling.testing.mock.sling.loader.ContentLoader.java
/** * Detected mime type from name (file extension) using Mime Type service. * Fallback to application/octet-stream. * @param name Node name/*from ww w . j a v a 2 s .co m*/ * @return Mime type (never null) */ private String detectMimeTypeFromName(String name) { String mimeType = null; String fileExtension = StringUtils.substringAfterLast(name, "."); if (bundleContext != null && StringUtils.isNotEmpty(fileExtension)) { ServiceReference<MimeTypeService> ref = bundleContext.getServiceReference(MimeTypeService.class); if (ref != null) { MimeTypeService mimeTypeService = (MimeTypeService) bundleContext.getService(ref); mimeType = mimeTypeService.getMimeType(fileExtension); } } return StringUtils.defaultString(mimeType, CONTENTTYPE_OCTET_STREAM); }
From source file:org.apache.struts2.convention.DefaultResultMapBuilder.java
/** * Creates any result types from the resources available in the web application. This scans the * web application resources using the servlet context. * * @param actionClass The action class the results are being built for. * @param results The results map to put the result configs created into. * @param resultPath The calculated path to the resources. * @param resultPrefix The prefix for the result. This is usually <code>/resultPath/actionName</code>. * @param actionName The action name which is used only for logging in this implementation. * @param packageConfig The package configuration which is passed along in order to determine * @param resultsByExtension The map of extensions to result type configuration instances. *//* w w w .ja v a 2s . com*/ protected void createFromResources(Class<?> actionClass, Map<String, ResultConfig> results, final String resultPath, final String resultPrefix, final String actionName, PackageConfig packageConfig, Map<String, ResultTypeConfig> resultsByExtension) { if (LOG.isTraceEnabled()) { LOG.trace("Searching for results in the Servlet container at [#0]" + " with result prefix of [#1]", resultPath, resultPrefix); } // Build from web application using the ServletContext @SuppressWarnings("unchecked") Set<String> paths = servletContext.getResourcePaths(flatResultLayout ? resultPath : resultPrefix); if (paths != null) { for (String path : paths) { if (LOG.isTraceEnabled()) { LOG.trace("Processing resource path [#0]", path); } String fileName = StringUtils.substringAfterLast(path, "/"); if (StringUtils.isBlank(fileName) || StringUtils.startsWith(fileName, ".")) { if (LOG.isTraceEnabled()) LOG.trace("Ignoring file without name [#0]", path); continue; } else if (fileName.lastIndexOf(".") > 0) { String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); if (conventionsService.getResultTypesByExtension(packageConfig).get(suffix) == null) { if (LOG.isDebugEnabled()) LOG.debug("No result type defined for file suffix : [#0]. Ignoring file #1", suffix, fileName); continue; } } makeResults(actionClass, path, resultPrefix, results, packageConfig, resultsByExtension); } } // Building from the classpath String classPathLocation = resultPath.startsWith("/") ? resultPath.substring(1, resultPath.length()) : resultPath; if (LOG.isTraceEnabled()) { LOG.trace( "Searching for results in the class path at [#0]" + " with a result prefix of [#1] and action name [#2]", classPathLocation, resultPrefix, actionName); } ResourceFinder finder = new ResourceFinder(classPathLocation, getClassLoaderInterface()); try { Map<String, URL> matches = finder.getResourcesMap(""); if (matches != null) { Test<URL> resourceTest = getResourceTest(resultPath, actionName); for (Map.Entry<String, URL> entry : matches.entrySet()) { if (resourceTest.test(entry.getValue())) { if (LOG.isTraceEnabled()) { LOG.trace("Processing URL [#0]", entry.getKey()); } String urlStr = entry.getValue().toString(); int index = urlStr.lastIndexOf(resultPrefix); String path = urlStr.substring(index); makeResults(actionClass, path, resultPrefix, results, packageConfig, resultsByExtension); } } } } catch (IOException ex) { if (LOG.isErrorEnabled()) LOG.error("Unable to scan directory [#0] for results", ex, classPathLocation); } }
From source file:org.apache.struts2.convention.PackageBasedActionConfigBuilder.java
/** * Creates a single ActionConfig object. * * @param pkgCfg The package the action configuration instance will belong to. * @param actionClass The action class. * @param actionName The name of the action. * @param actionMethod The method that the annotation was on (if the annotation is not null) or * the default method (execute). * @param annotation The ActionName annotation that might override the action name and possibly *///from w w w. ja v a 2s .c om protected void createActionConfig(PackageConfig.Builder pkgCfg, Class<?> actionClass, String actionName, String actionMethod, Action annotation) { String className = actionClass.getName(); if (annotation != null) { actionName = annotation.value() != null && annotation.value().equals(Action.DEFAULT_VALUE) ? actionName : annotation.value(); actionName = StringUtils.contains(actionName, "/") && !slashesInActionNames ? StringUtils.substringAfterLast(actionName, "/") : actionName; if (!Action.DEFAULT_VALUE.equals(annotation.className())) { className = annotation.className(); } } ActionConfig.Builder actionConfig = new ActionConfig.Builder(pkgCfg.getName(), actionName, className); actionConfig.methodName(actionMethod); if (LOG.isDebugEnabled()) { LOG.debug("Creating action config for class [#0], name [#1] and package name [#2] in namespace [#3]", actionClass.toString(), actionName, pkgCfg.getName(), pkgCfg.getNamespace()); } //build interceptors List<InterceptorMapping> interceptors = interceptorMapBuilder.build(actionClass, pkgCfg, actionName, annotation); actionConfig.addInterceptors(interceptors); //build results Map<String, ResultConfig> results = resultMapBuilder.build(actionClass, annotation, actionName, pkgCfg.build()); actionConfig.addResultConfigs(results); //add params if (annotation != null) actionConfig.addParams(StringTools.createParameterMap(annotation.params())); //add exception mappings from annotation if (annotation != null && annotation.exceptionMappings() != null) actionConfig.addExceptionMappings(buildExceptionMappings(annotation.exceptionMappings(), actionName)); //add exception mapping from class ExceptionMappings exceptionMappings = actionClass.getAnnotation(ExceptionMappings.class); if (exceptionMappings != null) actionConfig.addExceptionMappings(buildExceptionMappings(exceptionMappings.value(), actionName)); //add pkgCfg.addActionConfig(actionName, actionConfig.build()); //check if an action with the same name exists on that package (from XML config probably) PackageConfig existingPkg = configuration.getPackageConfig(pkgCfg.getName()); if (existingPkg != null) { // there is a package already with that name, check action ActionConfig existingActionConfig = existingPkg.getActionConfigs().get(actionName); if (existingActionConfig != null && LOG.isWarnEnabled()) LOG.warn("Duplicated action definition in package [#0] with name [#1].", pkgCfg.getName(), actionName); } //watch class file if (isReloadEnabled()) { URL classFile = actionClass.getResource(actionClass.getSimpleName() + ".class"); fileManager.monitorFile(classFile); loadedFileUrls.add(classFile.toString()); } }
From source file:org.apache.syncope.client.console.widgets.AnyByRealmWidget.java
private Bar build(final Map<String, Integer> usersByRealm, final Map<String, Integer> groupsByRealm, final String anyType1, final Map<String, Integer> any1ByRealm, final String anyType2, final Map<String, Integer> any2ByRealm) { List<String> labels = new ArrayList<>(); List<Integer> userValues = new ArrayList<>(); List<Integer> groupValues = new ArrayList<>(); List<Integer> any1Values = new ArrayList<>(); List<Integer> any2Values = new ArrayList<>(); Set<String> realmSet = new HashSet<>(); realmSet.addAll(usersByRealm.keySet()); realmSet.addAll(groupsByRealm.keySet()); if (any1ByRealm != null) { realmSet.addAll(any1ByRealm.keySet()); }//from w w w . j a va2s.c om if (any2ByRealm != null) { realmSet.addAll(any2ByRealm.keySet()); } List<String> realms = new ArrayList<>(realmSet); Collections.sort(realms); for (int i = 0; i < realms.size() && i < MAX_REALMS; i++) { labels.add(StringUtils.prependIfMissing(StringUtils.substringAfterLast(realms.get(i), "/"), "/")); userValues.add(usersByRealm.get(realms.get(i))); groupValues.add(groupsByRealm.get(realms.get(i))); if (any1ByRealm != null) { any1Values.add(any1ByRealm.get(realms.get(i))); } if (any2ByRealm != null) { any2Values.add(any2ByRealm.get(realms.get(i))); } } Bar bar = new Bar(); bar.getOptions().setScaleBeginAtZero(true); bar.getOptions().setScaleShowGridLines(true); bar.getOptions().setScaleGridLineWidth(1); bar.getOptions().setBarShowStroke(true); bar.getOptions().setBarStrokeWidth(2); bar.getOptions().setBarValueSpacing(5); bar.getOptions().setBarDatasetSpacing(1); bar.getOptions().setResponsive(true); bar.getOptions().setMaintainAspectRatio(true); bar.getOptions().setMultiTooltipTemplate("<%= datasetLabel %> - <%= value %>"); bar.getData().setLabels(labels); List<BarDataSet> datasets = new ArrayList<>(); LabeledBarDataSet userDataSet = new LabeledBarDataSet(userValues); userDataSet.setFillColor("orange"); userDataSet.setLabel(getString("users")); datasets.add(userDataSet); LabeledBarDataSet groupDataSet = new LabeledBarDataSet(groupValues); groupDataSet.setFillColor("red"); groupDataSet.setLabel(getString("groups")); datasets.add(groupDataSet); if (anyType1 != null) { LabeledBarDataSet any1DataSet = new LabeledBarDataSet(any1Values); any1DataSet.setFillColor("green"); any1DataSet.setLabel(anyType1); datasets.add(any1DataSet); } if (anyType2 != null) { LabeledBarDataSet any2DataSet = new LabeledBarDataSet(any2Values); any2DataSet.setFillColor("aqua"); any2DataSet.setLabel(anyType2); datasets.add(any2DataSet); } bar.getData().setDatasets(datasets); return bar; }
From source file:org.apache.syncope.core.logic.scim.SearchCondVisitor.java
private boolean schemaEquals(final Resource resource, final String value, final String schema) { return resource == null ? value.contains(":") ? StringUtils.substringAfterLast(value, ":").equalsIgnoreCase(schema) : value.equalsIgnoreCase(schema) : value.equalsIgnoreCase(schema) || (resource.schema() + ":" + value).equalsIgnoreCase(schema); }
From source file:org.apache.syncope.core.rest.cxf.JavaDocUtils.java
public static URL[] getJavaDocURLs() { URL[] result = null;//from w w w. j a v a2s . c o m ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); if (classLoader instanceof URLClassLoader) { List<URL> javaDocURLs = new ArrayList<>(); for (URL url : ((URLClassLoader) classLoader).getURLs()) { String filename = StringUtils.substringAfterLast(url.toExternalForm(), "/"); if (filename.startsWith("syncope-") && filename.endsWith("-javadoc.jar")) { javaDocURLs.add(url); } } if (!javaDocURLs.isEmpty()) { result = javaDocURLs.toArray(new URL[javaDocURLs.size()]); } } return result; }
From source file:org.apache.syncope.fit.core.MultitenancyITCase.java
@Test public void createResourceAndPull() { // read connector ConnInstanceTO conn = adminClient.getService(ConnectorService.class) .read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage()); assertNotNull(conn);/* w ww . j a v a 2 s . c o m*/ assertEquals("LDAP", conn.getDisplayName()); // prepare resource ResourceTO resource = new ResourceTO(); resource.setKey("new-ldap-resource"); resource.setConnector(conn.getKey()); try { ProvisionTO provisionTO = new ProvisionTO(); provisionTO.setAnyType(AnyTypeKind.USER.name()); provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME); resource.getProvisions().add(provisionTO); MappingTO mapping = new MappingTO(); mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'"); provisionTO.setMapping(mapping); ItemTO item = new ItemTO(); item.setIntAttrName("username"); item.setExtAttrName("cn"); item.setPurpose(MappingPurpose.BOTH); mapping.setConnObjectKeyItem(item); item = new ItemTO(); item.setPassword(true); item.setIntAttrName("password"); item.setExtAttrName("userPassword"); item.setPurpose(MappingPurpose.BOTH); item.setMandatoryCondition("true"); mapping.add(item); item = new ItemTO(); item.setIntAttrName("key"); item.setPurpose(MappingPurpose.BOTH); item.setExtAttrName("sn"); item.setMandatoryCondition("true"); mapping.add(item); item = new ItemTO(); item.setIntAttrName("email"); item.setPurpose(MappingPurpose.BOTH); item.setExtAttrName("mail"); mapping.add(item); // create resource Response response = adminClient.getService(ResourceService.class).create(resource); assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); resource = adminClient.getService(ResourceService.class).read(resource.getKey()); assertNotNull(resource); // create pull task PullTaskTO task = new PullTaskTO(); task.setName("LDAP Pull Task"); task.setActive(true); task.setDestinationRealm(SyncopeConstants.ROOT_REALM); task.setResource(resource.getKey()); task.setPullMode(PullMode.FULL_RECONCILIATION); task.setPerformCreate(true); response = adminClient.getService(TaskService.class).create(task); assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); task = adminClient.getService(TaskService.class) .read(StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true); assertNotNull(resource); // pull ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), task.getKey(), 50, false); // verify execution status String status = execution.getStatus(); assertNotNull(status); assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status)); // verify that pulled user is found PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class) .search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient .getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()) .build()); assertNotNull(matchingUsers); assertEquals(1, matchingUsers.getResult().size()); } finally { adminClient.getService(ResourceService.class).delete(resource.getKey()); } }
From source file:org.apereo.openlrs.model.event.EventConversionService.java
private String parseContextXApi(Statement xapi) { String context = null;/*from w ww . j a v a2 s . co m*/ XApiContext xApiContext = xapi.getContext(); if (xApiContext != null) { XApiContextActivities xApiContextActivities = xApiContext.getContextActivities(); if (xApiContextActivities != null) { List<XApiObject> parentContext = xApiContextActivities.getParent(); if (parentContext != null && !parentContext.isEmpty()) { for (XApiObject object : parentContext) { String id = object.getId(); if (StringUtils.contains(id, "portal/site/")) { context = StringUtils.substringAfterLast(id, "/"); break; } } } } } return context; }
From source file:org.apereo.openlrs.model.event.EventConversionService.java
private String parseVerbXApi(Statement xapi) { String verb = null;// w w w . j av a 2 s . c om XApiVerb xApiVerb = xapi.getVerb(); if (xApiVerb != null) { Map<String, String> display = xApiVerb.getDisplay(); if (display != null && !display.isEmpty()) { verb = display.get("en-US"); } if (StringUtils.isBlank(verb)) { String id = xApiVerb.getId(); if (StringUtils.isNotBlank(id)) { verb = StringUtils.substringAfterLast(id, "/"); } } } return verb; }