Class StoreElementFilter

java.lang.Object
de.espirit.firstspirit.access.store.StoreElementFilter
All Implemented Interfaces:
Filter<StoreElement>, Filter.TypedFilter<StoreElement>, Serializable

public abstract class StoreElementFilter extends Object implements Filter.TypedFilter<StoreElement>
Since:
4.0.17
See Also:
Example:
Usage example:
import de.espirit.firstspirit.access.store.*;

import de.espirit.common.util.Listable;
import de.espirit.firstspirit.access.UserService;
import de.espirit.firstspirit.access.project.Project;
import de.espirit.firstspirit.access.store.Store.Type;
import de.espirit.firstspirit.access.store.pagestore.Page;
import de.espirit.firstspirit.access.store.pagestore.PageFolder;
import de.espirit.firstspirit.access.store.pagestore.PageStoreRoot;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


/**
 * Example how to use StoreElementFilter.
 *
 * @since 4.2.410
 */
public class StoreElementFilterExample {


	/**
	 * Example how to use a StoreElementFilter which filters PageFolders and Pages within the {@link PageStoreRoot PageStore} of the given {@link Project} using an iterator.<br/>
	 *
	 * <b>Important:</b> In case of usage in a Beanshell script the usage of an iterator is mandatory, because Beanshell doesn't support java "for each" syntax.
	 * For usage in java code the "for each" syntax is recommended -> see {@link #getFilteredChildren_ForEach(de.espirit.firstspirit.access.project.Project)} for details.
	 *
	 * @return the filtered storelements
	 * @see #getFilteredChildren_ForEach(de.espirit.firstspirit.access.project.Project)
	 * @since 4.2.410
	 */
	public Map<String, IDProvider> getFilteredChildren_Iterator(final Project project) {
		final UserService userService = project.getUserService();
		final Store currentPageStore = userService.getStore(Type.PAGESTORE, false);

		final StoreElementFilter filter = StoreElementFilter.on(PageFolder.class, Page.class);

		// get filtered children recursive
		final Listable<StoreElement> filteredListable = currentPageStore.getChildren(filter, true);

		final Map<String, IDProvider> result = new HashMap<String, IDProvider>();

		final Iterator<StoreElement> filteredIterator = filteredListable.iterator();
		while (filteredIterator.hasNext()) {
			// we filtered on Page and PageFolder, therefore we can cast to IdProvider without risk
			final IDProvider idProvider = (IDProvider) filteredIterator.next();
			if (idProvider.hasUid()) {
				result.put(idProvider.getUid(), idProvider);
			}
		}

		return result;
	}


	/**
	 * Example how to use a StoreElementFilter which filters PageFolders and Pages within the {@link PageStoreRoot PageStore} of the given {@link Project} using "for each" syntax.<br/>
	 *
	 * <b>Important:</b> In a Beanshell script the "for each" is not supported, therefore an iterator should be used -> see {@link #getFilteredChildren_Iterator(de.espirit.firstspirit.access.project.Project)} for details.
	 *
	 * @return the filtered storelements
	 * @see #getFilteredChildren_Iterator(de.espirit.firstspirit.access.project.Project)
	 * @since 4.2.410
	 */
	public Map<String, IDProvider> getFilteredChildren_ForEach(final Project project) {
		final UserService userService = project.getUserService();
		final Store currentPageStore = userService.getStore(Type.PAGESTORE, false);

		final StoreElementFilter filter = StoreElementFilter.on(PageFolder.class, Page.class);

		// get filtered children recursive
		final Listable<StoreElement> filteredListable = currentPageStore.getChildren(filter, true);

		final Map<String, IDProvider> result = new HashMap<String, IDProvider>();

		for (final StoreElement storeElement : filteredListable) {
			// we filtered on Page and PageFolder, therefore we can cast to IdProvider without risk
			final IDProvider idProvider = (IDProvider) storeElement;
			if (idProvider.hasUid()) {
				result.put(idProvider.getUid(), idProvider);
			}
		}

		return result;
	}
}
  • Field Details

  • Constructor Details

    • StoreElementFilter

      public StoreElementFilter()
      Since:
      4.0.17
    • StoreElementFilter

      public StoreElementFilter(Class<StoreElement> type)
      Since:
      4.0.26
  • Method Details