List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty
public static boolean isNotEmpty(final Collection<?> coll)
From source file:org.craftercms.engine.scripting.impl.ScriptUrlTemplateScannerImpl.java
public void findScripts(Context context, ContentStoreService storeService, ScriptFactory scriptFactory, String folder, List<String> scriptUrls) { List<Item> items = storeService.findChildren(context, null, folder, null, null); String scriptFileExtension = scriptFactory.getScriptFileExtension(); if (CollectionUtils.isNotEmpty(items)) { for (Item item : items) { if (!item.isFolder() && item.getName().endsWith(scriptFileExtension)) { scriptUrls.add(item.getUrl()); } else if (item.isFolder()) { findScripts(context, storeService, scriptFactory, item.getUrl(), scriptUrls); }/*from w w w. j a va2 s. c o m*/ } } }
From source file:org.craftercms.engine.security.CrafterPageAccessManager.java
/** * Checks if the user has sufficient rights to access the specified page: * * <ol>// w w w .j a v a 2 s . c o m * <li>If the page doesn't contain any required role, no authentication is needed.</li> * <li>If the page has the role "Anonymous", no authentication is needed.</li> * <li>If the page has the role "Authenticated", just authentication is needed.</li> * <li>If the page has any other the roles, the user needs to have any of those roles.</li> * </ol> */ @RunIfSecurityEnabled public void checkAccess(SiteItem page) throws AuthenticationRequiredException, AccessDeniedException { String pageUrl = page.getStoreUrl(); Profile profile = null; Authentication auth = SecurityUtils.getCurrentAuthentication(); if (auth != null) { profile = auth.getProfile(); } List<String> authorizedRoles = getAuthorizedRolesForPage(page); if (CollectionUtils.isNotEmpty(authorizedRoles) && !containsRole("anonymous", authorizedRoles)) { // If profile == null it is anonymous if (profile == null) { throw new AuthenticationRequiredException( "User is anonymous but page '" + pageUrl + "' requires authentication"); } if (!containsRole("authenticated", authorizedRoles) && !profile.hasAnyRole(authorizedRoles)) { throw new AccessDeniedException("User '" + profile.getUsername() + "' is not authorized " + "to view page '" + pageUrl + "'"); } } }
From source file:org.craftercms.engine.service.context.SiteContextFactory.java
protected ConfigurableApplicationContext getApplicationContext(SiteContext siteContext, URLClassLoader classLoader, HierarchicalConfiguration config, String[] applicationContextPaths, ResourceLoader resourceLoader) { try {/*from w ww .j a v a 2 s. c om*/ List<Resource> resources = new ArrayList<>(); for (String path : applicationContextPaths) { Resource resource = resourceLoader.getResource(path); if (resource.exists()) { resources.add(resource); } } if (CollectionUtils.isNotEmpty(resources)) { String siteName = siteContext.getSiteName(); logger.info("--------------------------------------------------"); logger.info("<Loading application context for site: " + siteName + ">"); logger.info("--------------------------------------------------"); GenericApplicationContext appContext = new GenericApplicationContext(mainApplicationContext); appContext.setClassLoader(classLoader); if (config != null) { MutablePropertySources propertySources = appContext.getEnvironment().getPropertySources(); propertySources.addFirst(new ApacheCommonsConfiguration2PropertySource("siteConfig", config)); } XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); for (Resource resource : resources) { reader.loadBeanDefinitions(resource); } appContext.refresh(); logger.info("--------------------------------------------------"); logger.info("</Loading application context for site: " + siteName + ">"); logger.info("--------------------------------------------------"); return appContext; } else { return null; } } catch (Exception e) { throw new SiteContextCreationException( "Unable to load application context for site '" + siteContext.getSiteName() + "'", e); } }
From source file:org.craftercms.engine.service.context.SiteContextFactory.java
protected Scheduler scheduleJobs(SiteContext siteContext) { String siteName = siteContext.getSiteName(); try {/*from w ww .j ava 2 s .c o m*/ List<JobContext> allJobContexts = new ArrayList<>(); for (ScriptJobResolver jobResolver : jobResolvers) { List<JobContext> jobContexts = jobResolver.resolveJobs(siteContext); if (CollectionUtils.isNotEmpty(jobContexts)) { allJobContexts.addAll(jobContexts); } } if (CollectionUtils.isNotEmpty(allJobContexts)) { Scheduler scheduler = SchedulingUtils.createScheduler(siteName + "_scheduler"); logger.info("--------------------------------------------------"); logger.info("<Scheduling job scripts for site: " + siteName + ">"); logger.info("--------------------------------------------------"); for (JobContext jobContext : allJobContexts) { scheduler.scheduleJob(jobContext.getDetail(), jobContext.getTrigger()); logger.info("Scheduled job: " + jobContext + " for site '" + siteName + "'"); } scheduler.start(); logger.info("--------------------------------------------------"); logger.info("</Scheduling job scripts for site: " + siteName + ">"); logger.info("--------------------------------------------------"); return scheduler; } } catch (Exception e) { logger.error("Unable to schedule jobs for site '" + siteName + "'", e); } return null; }
From source file:org.craftercms.engine.service.context.SiteContextManager.java
public void createContexts(Collection<String> siteNames) { logger.info("=================================================="); logger.info("<CREATING SITE CONTEXTS>"); logger.info("=================================================="); if (CollectionUtils.isNotEmpty(siteNames)) { for (String siteName : siteNames) { try { // If the site context doesn't exist (it's new), it will be created createContext(siteName, false); } catch (Exception e) { logger.error("Error creating site context for site '" + siteName + "'", e); }//w w w . j av a 2 s. co m } } logger.info("=================================================="); logger.info("</CREATING SITE CONTEXTS>"); logger.info("=================================================="); }
From source file:org.craftercms.engine.service.context.SiteContextManager.java
protected void destroyContexts(Collection<String> siteNames) { logger.info("=================================================="); logger.info("<DESTROYING SITE CONTEXTS>"); logger.info("=================================================="); if (CollectionUtils.isNotEmpty(siteNames)) { for (String siteName : siteNames) { try { destroyContext(siteName); } catch (Exception e) { logger.error("Error destroying site context for site '" + siteName + "'", e); }//from w w w.ja v a 2 s .c o m } } logger.info("=================================================="); logger.info("</DESTROYING SITE CONTEXTS>"); logger.info("=================================================="); }
From source file:org.craftercms.engine.service.impl.SiteItemServiceImpl.java
@Override public SiteItem getSiteItem(String url, ItemProcessor processor, Predicate<Item> predicate) { if (CollectionUtils.isNotEmpty(defaultPredicates)) { List<Predicate<Item>> predicates = new ArrayList<>(defaultPredicates); if (predicate != null) { predicates.add(predicate);//w w w. j a va 2 s . c o m } predicate = PredicateUtils.allPredicate(predicates); } if (CollectionUtils.isNotEmpty(defaultProcessors)) { ItemProcessorPipeline processorPipeline = new ItemProcessorPipeline(new ArrayList<>(defaultProcessors)); if (processor != null) { processorPipeline.addProcessor(processor); } processor = processorPipeline; } Item item = storeService.findItem(getSiteContext().getContext(), null, url, processor); if (item != null && (predicate == null || predicate.evaluate(item))) { return createItemWrapper(item); } else { return null; } }
From source file:org.craftercms.engine.service.impl.SiteItemServiceImpl.java
@Override public SiteItem getSiteTree(String url, int depth, ItemFilter filter, ItemProcessor processor) { if (CollectionUtils.isNotEmpty(defaultFilters)) { CompositeItemFilter compositeFilter = new CompositeItemFilter(new ArrayList<>(defaultFilters)); if (filter != null) { compositeFilter.addFilter(filter); }//from w w w .j a va 2 s .c om filter = compositeFilter; } if (CollectionUtils.isNotEmpty(defaultProcessors)) { ItemProcessorPipeline processorPipeline = new ItemProcessorPipeline(new ArrayList<>(defaultProcessors)); if (processor != null) { processorPipeline.addProcessor(processor); } processor = processorPipeline; } Tree tree = storeService.findTree(getSiteContext().getContext(), null, url, depth, filter, processor); if (tree != null) { return createItemWrapper(tree); } else { return null; } }
From source file:org.craftercms.engine.service.impl.SiteItemServiceImpl.java
@Deprecated @Override//w w w . j av a2s. c om public SiteItem getSiteTree(String url, int depth, String includeByNameRegex, String excludeByNameRegex, Map<String, String> nodeXPathAndExpectedValuePairs) { CompositeItemFilter compositeFilter = new CompositeItemFilter(); if (CollectionUtils.isNotEmpty(defaultFilters)) { for (ItemFilter defaultFilter : defaultFilters) { compositeFilter.addFilter(defaultFilter); } } if (StringUtils.isNotEmpty(includeByNameRegex)) { compositeFilter.addFilter(new IncludeByNameItemFilter(includeByNameRegex)); } if (StringUtils.isNotEmpty(excludeByNameRegex)) { compositeFilter.addFilter(new ExcludeByNameItemFilter(excludeByNameRegex)); } if (MapUtils.isNotEmpty(nodeXPathAndExpectedValuePairs)) { for (Map.Entry<String, String> pair : nodeXPathAndExpectedValuePairs.entrySet()) { compositeFilter.addFilter(new ExpectedNodeValueItemFilter(pair.getKey(), pair.getValue())); } } Tree tree = storeService.findTree(getSiteContext().getContext(), null, url, depth, compositeFilter, null); if (tree != null) { return createItemWrapper(tree); } else { return null; } }
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. ja va 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; }