Search in sources :

Example 71 with ComponentLookupException

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

the class UIExtensionScriptService method getExtensions.

/**
 * Retrieves all the {@link UIExtension}s for a given Extension Point.
 *
 * @param extensionPointId The ID of the Extension Point to retrieve the {@link UIExtension}s for
 * @return the list of {@link UIExtension} for the given Extension Point
 */
public List<UIExtension> getExtensions(String extensionPointId) {
    UIExtensionManager manager = this.uiExtensionManager;
    ComponentManager componentManager = contextComponentManagerProvider.get();
    if (componentManager.hasComponent(UIExtensionManager.class, extensionPointId)) {
        try {
            // Look for a specific UI extension manager for the given extension point
            manager = componentManager.getInstance(UIExtensionManager.class, extensionPointId);
        } catch (ComponentLookupException e) {
            this.logger.error("Failed to initialize UI extension manager", e);
        }
    }
    return manager.get(extensionPointId);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) UIExtensionManager(org.xwiki.uiextension.UIExtensionManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 72 with ComponentLookupException

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

the class DefaultIconSetCache method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        CacheConfiguration configuration = new CacheConfiguration(ICON_SET_CACHE_ID);
        CacheFactory cacheFactory = cacheManager.getCacheFactory();
        this.cache = cacheFactory.newCache(configuration);
    } catch (ComponentLookupException | CacheException e) {
        throw new InitializationException("Failed to initialize the IconSet Cache.", 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 73 with ComponentLookupException

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

the class ModelScriptServiceTest method createDocumentReferenceWithDeprecatedHint.

@Test
public void createDocumentReferenceWithDeprecatedHint() throws Exception {
    when(this.componentManager.getInstance(DocumentReferenceResolver.TYPE_REFERENCE, "current/reference")).thenThrow(new ComponentLookupException("error"));
    DocumentReference reference = new DocumentReference("wiki", "space", "page");
    // Make sure backward compatibility is preserved.
    when(this.componentManager.getInstance(DocumentReferenceResolver.class, "current/reference")).thenReturn(this.resolver);
    when(this.resolver.resolve(reference)).thenReturn(reference);
    Assert.assertEquals(reference, this.service.createDocumentReference("wiki", "space", "page", "current/reference"));
    // Verify that we log a warning!
    verify(this.logger).warn("Deprecated usage of DocumentReferenceResolver with hint [{}]. " + "Please consider using a DocumentReferenceResolver that takes into account generic types.", "current/reference");
}
Also used : ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 74 with ComponentLookupException

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

the class ModelScriptServiceTest method getEntityReferenceValueWithInvalidHint.

@Test
public void getEntityReferenceValueWithInvalidHint() throws Exception {
    when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "invalid")).thenThrow(new ComponentLookupException("error"));
    Assert.assertNull(this.service.getEntityReferenceValue(EntityType.WIKI, "invalid"));
}
Also used : ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Test(org.junit.Test)

Example 75 with ComponentLookupException

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

the class ModelScriptService method createDocumentReference.

/**
 * Create a Document Reference from a passed wiki, list of spaces and page names, which can be empty strings or null
 * in which case they are resolved against the Resolver having the hint passed as parameter. Valid hints are for
 * example "default", "current", "currentmixed".
 *
 * @param wiki the wiki reference name to use (can be empty or null)
 * @param spaces the spaces list to use (can be empty or null)
 * @param page the page reference name to use (can be empty or null)
 * @param hint the hint of the Resolver to use in case any parameter is empty or null
 * @return the typed Document Reference object or null if no Resolver with the passed hint could be found
 *
 * @since 7.2M2
 */
public DocumentReference createDocumentReference(String wiki, List<String> spaces, String page, String hint) {
    EntityReference reference = null;
    if (!StringUtils.isEmpty(wiki)) {
        reference = new EntityReference(wiki, EntityType.WIKI);
    }
    if (spaces != null && !spaces.isEmpty()) {
        for (String space : spaces) {
            reference = new EntityReference(space, EntityType.SPACE, reference);
        }
    }
    if (!StringUtils.isEmpty(page)) {
        reference = new EntityReference(page, EntityType.DOCUMENT, reference);
    }
    DocumentReference documentReference;
    try {
        DocumentReferenceResolver<EntityReference> resolver = this.componentManager.getInstance(DocumentReferenceResolver.TYPE_REFERENCE, hint);
        documentReference = resolver.resolve(reference);
    } catch (ComponentLookupException e) {
        try {
            // Ensure backward compatibility with older scripts that use hints like "default/reference" because at
            // the time they were written we didn't have support for generic types in component role.
            DocumentReferenceResolver<EntityReference> drr = this.componentManager.getInstance(DocumentReferenceResolver.class, hint);
            documentReference = drr.resolve(reference);
            this.logger.warn("Deprecated usage of DocumentReferenceResolver with hint [{}]. " + "Please consider using a DocumentReferenceResolver that takes into account generic types.", hint);
        } catch (ComponentLookupException ex) {
            documentReference = null;
        }
    }
    return documentReference;
}
Also used : DocumentReferenceResolver(org.xwiki.model.reference.DocumentReferenceResolver) EntityReference(org.xwiki.model.reference.EntityReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference)

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