use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class JARTranslationBundleFactoryListener method extensionDeleted.
/**
* @param extension the installed extension
* @param namespace the namespace where the extension has been installed
*/
private void extensionDeleted(InstalledExtension extension, String namespace) {
try {
ComponentDescriptor<TranslationBundle> descriptor = createComponentDescriptor(extension);
ComponentManager componentManager = this.componentManagerManager.getComponentManager(namespace, false);
componentManager.unregisterComponent(descriptor);
} catch (Exception e) {
this.logger.error("Failed to create TranslationBundle descriptor for extension [{}]", extension, e);
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class JARTranslationBundleFactoryListener method extensionAdded.
/**
* @param extension the uninstalled extension
* @param namespace the namespace from where the extension has been uninstalled
*/
private void extensionAdded(InstalledExtension extension, String namespace) {
try {
File jarFile = new File(extension.getFile().getAbsolutePath());
ComponentManager componentManager = this.componentManagerManager.getComponentManager(namespace, false);
if (componentManager == null) {
componentManager = this.rootComponentManager;
}
JARFileTranslationBundle bundle = new JARFileTranslationBundle(jarFile, componentManager, this.translationParser);
ComponentDescriptor<TranslationBundle> descriptor = createComponentDescriptor(jarFile.toURI().toURL());
componentManager.registerComponent(descriptor, bundle);
} catch (Exception e) {
this.logger.error("Failed to register a TranslationBundle component for extension [{}] on namespace [{}]", extension, namespace, e);
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class LocalizationScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mock(ComponentManager.class);
Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(componentManager);
renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
localizationContext = mocker.getInstance(LocalizationContext.class);
localizationManager = mocker.getInstance(LocalizationManager.class);
localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
translation = mock(Translation.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
printer.print("print result");
return null;
}
}).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
environment = mocker.getInstance(Environment.class);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class XWikiRestletServlet method createApplication.
@Override
protected Application createApplication(Context context) {
Context applicationContext = context.createChildContext();
/* Retrieve the component manager and make it available in the restlet application context. */
ComponentManager componentManager = getComponentManager();
applicationContext.getAttributes().put(Constants.XWIKI_COMPONENT_MANAGER, componentManager);
JaxRsApplication application;
try {
application = componentManager.getInstance(JaxRsApplication.class);
} catch (ComponentLookupException e) {
log("Failed to lookup default JAX-RS Application", e);
return null;
}
application.setContext(applicationContext);
// Make the servlet available
try {
JaxRsServletProvider applicationProvider = componentManager.getInstance(JaxRsServletProvider.class);
applicationProvider.setApplication(this);
} catch (ComponentLookupException e) {
log("Failed to lookup JaxRsApplicationProvider. Dyncamically added/removed resources won'tbe supported", e);
}
return application;
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class MainResourceReferenceHandlerManagerTest method handleWithOrder.
@Test
public void handleWithOrder() throws Exception {
// First Handler component will lower priority
ResourceReferenceHandler testHandler = mock(ResourceReferenceHandler.class, "handler1");
when(testHandler.getSupportedResourceReferences()).thenReturn(Arrays.asList(new ResourceType("test")));
// Second Handler component will higher priority so that it's executed first
ResourceReferenceHandler beforeTestHandler = mock(ResourceReferenceHandler.class, "handler2");
when(beforeTestHandler.getSupportedResourceReferences()).thenReturn(Arrays.asList(new ResourceType("test")));
// We return 1 to mean that the second Handler has a higher priority than the first Handler
when(beforeTestHandler.compareTo(testHandler)).thenReturn(-1);
ComponentManager contextComponentManager = this.componentManager.getInstance(ComponentManager.class, "context");
when(contextComponentManager.<ResourceReferenceHandler>getInstanceList(new DefaultParameterizedType(null, ResourceReferenceHandler.class, ResourceType.class))).thenReturn(Arrays.asList(testHandler, beforeTestHandler));
ResourceReference reference = mock(ResourceReference.class);
when(reference.getType()).thenReturn(new ResourceType("test"));
this.componentManager.getComponentUnderTest().handle(reference);
// Verify that the second Action is called (since it has a higher priority).
verify(beforeTestHandler).handle(same(reference), any(ResourceReferenceHandlerChain.class));
}
Aggregations