Search in sources :

Example 1 with UIExtensionFilter

use of org.xwiki.uiextension.UIExtensionFilter in project xwiki-platform by xwiki.

the class UIExtensionScriptService method getExtensions.

/**
 * Retrieves the list of {@link UIExtension} for a given Extension Point.
 *
 * Examples:
 * <ul>
 * <li>Get only the {@link UIExtension}s with the given IDs for the Extension Point "platform.example"
 * <pre>$services.uix.getExtensions('platform.example', {'select' : 'id1, id2, id3'})</pre></li>
 * <li>Get all the {@link UIExtension}s for the Extension Point "platform.example" except the
 * {@link UIExtension}s with the IDs "id2" and "id3"
 * <pre>$services.uix.getExtensions('platform.example', {'exclude' : 'id2, id3'})</pre></li>
 * <li>Get all the {@link UIExtension}s for the Extension Point "platform.example" and order them by one of their
 * parameter
 * <pre>$services.uix.getExtensions('platform.example', {'sortByParameter' : 'parameterKey'})</pre></li>
 * <li>Get only the {@link UIExtension}s with the given IDs for the Extension Point "platform.example" and order
 * them by one of their parameter
 * <pre>$services.uix.getExtensions('platform.example',
 * {'select' : 'id1, id2, id3', 'sortByParameter' : 'parameterKey'})</pre></li>
 * </ul>
 *
 * @param extensionPointId The ID of the Extension Point to retrieve the {@link UIExtension}s for
 * @param filters Optional filters to apply before retrieving the list
 * @return the list of {@link UIExtension} for the given Extension Point
 */
public List<UIExtension> getExtensions(String extensionPointId, Map<String, String> filters) {
    List<UIExtension> extensions = getExtensions(extensionPointId);
    for (Map.Entry<String, String> entry : filters.entrySet()) {
        String filterHint = entry.getKey();
        try {
            UIExtensionFilter filter = contextComponentManagerProvider.get().getInstance(UIExtensionFilter.class, filterHint);
            extensions = filter.filter(extensions, this.parseFilterParameters(entry.getValue()));
        } catch (ComponentLookupException e) {
            logger.warn("Unable to find a UIExtensionFilter for hint [{}] " + "while getting UIExtensions for extension point [{}]", filterHint, extensionPointId);
        }
    }
    return extensions;
}
Also used : UIExtensionFilter(org.xwiki.uiextension.UIExtensionFilter) UIExtension(org.xwiki.uiextension.UIExtension) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 UIExtension (org.xwiki.uiextension.UIExtension)1 UIExtensionFilter (org.xwiki.uiextension.UIExtensionFilter)1