Search in sources :

Example 51 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project celements-blog by celements.

the class BlogService method getArticleEngine.

private IArticleEngineRole getArticleEngine() throws ArticleLoadException {
    IArticleEngineRole engine = null;
    String engineHint = getContext().getWiki().getXWikiPreference("blog_article_engine", "blog.article.engine", null, getContext());
    try {
        Map<String, IArticleEngineRole> engineMap = componentManager.lookupMap(IArticleEngineRole.class);
        engine = engineMap.get(engineHint);
        if (engine == null) {
            engine = engineMap.get("default");
        }
    } catch (ComponentLookupException exc) {
        LOGGER.error("Error looking up engine components", exc);
    }
    if (engine != null) {
        LOGGER.info("getArticleEngine: got engine '" + engine + "' for hint '" + engineHint + "'");
        return engine;
    } else {
        throw new ArticleLoadException("Unable to load engine for hint");
    }
}
Also used : IArticleEngineRole(com.celements.blog.article.IArticleEngineRole) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ArticleLoadException(com.celements.blog.article.ArticleLoadException)

Example 52 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class EditableGadgetRenderer method getGadgetContentRenderer.

/**
 * @return the renderer corresponding to the "annotated" version of the current target syntax
 */
protected BlockRenderer getGadgetContentRenderer() {
    // Get the current syntax
    Syntax currentTargetSyntax = renderingContext.getTargetSyntax();
    if (currentTargetSyntax == null) {
        // (it should never happen actually)
        return defaultGadgetContentRenderer;
    }
    // Get the annotated syntax corresponding to the current target syntax
    String annotatedTargetSyntax = currentTargetSyntax.toIdString();
    if (!StringUtils.startsWith(annotatedTargetSyntax, ANNOTATED_SYNTAXES_PREFIX)) {
        annotatedTargetSyntax = ANNOTATED_SYNTAXES_PREFIX + annotatedTargetSyntax;
    }
    try {
        return componentManager.getInstance(BlockRenderer.class, annotatedTargetSyntax);
    } catch (ComponentLookupException e) {
        logger.warn("Failed to load the syntax [{}].", annotatedTargetSyntax);
        // Failback to the default renderer
        return defaultGadgetContentRenderer;
    }
}
Also used : ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Syntax(org.xwiki.rendering.syntax.Syntax)

Example 53 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultEditorManager method getEditor.

@Override
public <D> Editor<D> getEditor(Type dataType, String hint) {
    DefaultParameterizedType editorType = new DefaultParameterizedType(null, Editor.class, dataType);
    ComponentManager componentManager = this.componentManagerProvider.get();
    if (componentManager.hasComponent(editorType, hint)) {
        try {
            return componentManager.getInstance(editorType, hint);
        } catch (ComponentLookupException e) {
            throw new RuntimeException(String.format("Failed to look up the [%s] editor with hint [%s]", dataType.getTypeName(), hint), e);
        }
    } else {
        // No such editor component found.
        return null;
    }
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 54 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultColorThemeCache method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        // Create the cache
        CacheConfiguration configuration = new CacheConfiguration(LESS_COLOR_THEMES_CACHE_ID);
        CacheFactory cacheFactory = cacheManager.getCacheFactory();
        super.cache = cacheFactory.newCache(configuration);
        // The Color Theme only depends on colors which do not depend on the XWikiContext. So we don't handle the
        // XWikiContext in this cache.
        super.isContextHandled = false;
    } catch (ComponentLookupException | CacheException e) {
        throw new InitializationException(String.format("Failed to initialize LESS color themes cache [%s].", LESS_COLOR_THEMES_CACHE_ID), e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) CacheFactory(org.xwiki.cache.CacheFactory) InitializationException(org.xwiki.component.phase.InitializationException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

Example 55 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCache method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        CacheConfiguration configuration = new CacheConfiguration(LESS_FILES_CACHE_ID);
        CacheFactory cacheFactory = cacheManager.getCacheFactory();
        this.cache = cacheFactory.newCache(configuration);
    } catch (ComponentLookupException | CacheException e) {
        throw new InitializationException(String.format("Failed to initialize LESS skin files cache [%s].", LESS_FILES_CACHE_ID), e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) CacheFactory(org.xwiki.cache.CacheFactory) InitializationException(org.xwiki.component.phase.InitializationException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)104 ComponentManager (org.xwiki.component.manager.ComponentManager)24 Test (org.junit.Test)15 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)10 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 InitializationException (org.xwiki.component.phase.InitializationException)8 ArrayList (java.util.ArrayList)7 XWikiException (com.xpn.xwiki.XWikiException)5 HashMap (java.util.HashMap)5 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)5 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)5 FilterException (org.xwiki.filter.FilterException)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)4 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 WikiReference (org.xwiki.model.reference.WikiReference)4