Search in sources :

Example 46 with ComponentLookupException

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

the class DefaultTranslationBundleContext method initializeCurrentBundles.

private SortedSet<TranslationBundle> initializeCurrentBundles() {
    SortedSet<TranslationBundle> currentBundles = new TreeSet<>();
    try {
        ComponentManager componentManager = this.componentManagerProvider.get();
        List<TranslationBundle> availableBundles = componentManager.<TranslationBundle>getInstanceList(TranslationBundle.class);
        currentBundles.addAll(availableBundles);
    } catch (ComponentLookupException e) {
        this.logger.error("Failed to lookup Bundle components", e);
    }
    return currentBundles;
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle) TreeSet(java.util.TreeSet) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 47 with ComponentLookupException

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

the class VelocityMacro method getFilter.

/**
 * @param parameters the velocity macros parameters
 * @return the velocity content filter
 * @since 2.0M1
 */
private VelocityMacroFilter getFilter(VelocityMacroParameters parameters) {
    String filterName = parameters.getFilter();
    if (StringUtils.isEmpty(filterName)) {
        filterName = this.configuration.getFilter();
        if (StringUtils.isEmpty(filterName)) {
            filterName = null;
        }
    }
    VelocityMacroFilter filter = null;
    if (filterName != null) {
        try {
            filter = getComponentManager().getInstance(VelocityMacroFilter.class, filterName);
        } catch (ComponentLookupException e) {
            this.logger.error("Can't find velocity macro filter", e);
        }
    }
    return filter;
}
Also used : VelocityMacroFilter(org.xwiki.rendering.macro.velocity.filter.VelocityMacroFilter) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 48 with ComponentLookupException

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

the class StandardExtendedURLResourceReferenceSerializerTest method serializeWhenNoMatchingSerializer.

@Test
public void serializeWhenNoMatchingSerializer() throws Exception {
    TestResourceReference resource = new TestResourceReference();
    ComponentManager componentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TestResourceReference.class, ExtendedURL.class), "standard")).thenThrow(new ComponentLookupException("error"));
    when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TestResourceReference.class, ExtendedURL.class))).thenThrow(new ComponentLookupException("error"));
    try {
        this.mocker.getComponentUnderTest().serialize(resource);
        fail("Should have thrown an exception here");
    } catch (UnsupportedResourceReferenceException expected) {
        assertEquals("Failed to find serializer for Resource Reference [type = [test], parameters = []] and " + "URL format [standard]", expected.getMessage());
    }
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 49 with ComponentLookupException

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

the class URIVfsResourceReferenceSerializer method serialize.

@Override
public URI serialize(VfsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
    URI resultURI;
    try {
        ResourceReferenceSerializer<VfsResourceReference, URI> serializer = this.componentManagerProvider.get().getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), String.format("truevfs/%s", reference.getURI().getScheme()));
        resultURI = serializer.serialize(reference);
    } catch (ComponentLookupException e) {
        // No serializer exist, we just don't perform any conversion!
        resultURI = reference.toURI();
    }
    return resultURI;
}
Also used : ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) URI(java.net.URI)

Example 50 with ComponentLookupException

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

the class VfsResourceReferenceSerializer method serialize.

@Override
public ExtendedURL serialize(VfsResourceReference resourceReference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
    ExtendedURL extendedURL;
    // We need to ensure that the URI contains absolute references since the VFS handler that will handle
    // the generated URL won't have any base reference to resolve any relative refeence.
    // 
    // Look for a scheme-specific serializer to convert from a relative URI into an absolute URI and if not found
    // then don't perform any transformation of the URI.
    URI uri = resourceReference.getURI();
    try {
        ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> schemeSpecificSerializer = this.componentManagerProvider.get().getInstance(TYPE, uri.getScheme());
        extendedURL = schemeSpecificSerializer.serialize(resourceReference);
    } catch (ComponentLookupException e) {
        extendedURL = super.serialize(resourceReference);
    }
    return extendedURL;
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtendedURL(org.xwiki.url.ExtendedURL) URI(java.net.URI)

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