/** * @return true if we're in wiki mode (ie there's no implementing class for {@link * org.xwiki.rendering.wiki.WikiModel}) */ private boolean isInWikiMode() { boolean result = true; try { this.componentManager.lookup(WikiModel.class); } catch (ComponentLookupException e) { result = false; } return result; }
/** * {@inheritDoc} * * @see Initializable#initialize() */ public void initialize() throws InitializationException { // Try to find a WikiModel implementation and set it if it can be found. If not it means we're in // non wiki mode (i.e. no attachment in wiki documents and no links to documents for example). try { this.wikiModel = this.componentManager.lookup(WikiModel.class); } catch (ComponentLookupException e) { // There's no WikiModel implementation available. this.wikiModel stays null. } }
/** * @return true if we're in wiki mode (ie there's no implementing class for {@link * org.xwiki.rendering.wiki.WikiModel}) */ private boolean isInWikiMode() { boolean result = true; try { this.componentManager.lookup(WikiModel.class); } catch (ComponentLookupException e) { result = false; } return result; } }
/** * @return true if we're in wiki mode (ie there's no implementing class for {@link WikiModel}) */ private boolean isInWikiMode() { boolean result = true; try { this.componentManager.lookup(WikiModel.class); } catch (ComponentLookupException e) { result = false; } return result; } }
/** * {@inheritDoc} * * @see Initializable#initialize() */ public void initialize() throws InitializationException { // Try to find a WikiModel implementation and set it if it can be found. If not it means we're in // non wiki mode (i.e. no attachment in wiki documents and no links to documents for example). try { this.wikiModel = this.componentManager.lookup(WikiModel.class); } catch (ComponentLookupException e) { // There's no WikiModel implementation available. this.wikiModel stays null. } }
/** * {@inheritDoc} * * @see Initializable#initialize() */ public void initialize() throws InitializationException { // Try to find a WikiModel implementation and set it if it can be found. If not it means we're in // non wiki mode (i.e. no attachment in wiki documents and no links to documents for example). try { this.wikiModel = this.componentManager.lookup(WikiModel.class); } catch (ComponentLookupException e) { // There's no WikiModel implementation available. this.wikiModel stays null. } }
private ExtensionHandler getExtensionHandler(LocalExtension localExtension) throws ComponentLookupException { // Load extension return this.componentManager.lookup(ExtensionHandler.class, localExtension.getType().toString().toLowerCase()); }
/** * {@inheritDoc} * @see org.xwiki.script.service.ScriptServiceManager#get(String) */ public ScriptService get(String serviceName) throws ScriptServiceNotFoundException { ScriptService scriptService; try { scriptService = this.componentManager.lookup(ScriptService.class, serviceName); } catch (ComponentLookupException e) { throw new ScriptServiceNotFoundException("Failed to locate Script Service [" + serviceName + "]", e); } return scriptService; } }
/** * TODO: This is only a temporary work around, we need to use a component-based init mechanism instead. Note that we * need DB access to be available (at component initialization) to make this possible. * <p> * This method is protected to be able to skip it in unit tests. */ protected void registerWikiMacros() { try { WikiMacroInitializer wikiMacroInitializer = Utils.getComponentManager().lookup(WikiMacroInitializer.class); wikiMacroInitializer.registerExistingWikiMacros(); } catch (Exception ex) { LOG.error("Error while registering wiki macros.", ex); } }
public void shutdown() throws Exception { Execution execution = (Execution) getComponentManager().lookup(Execution.ROLE); execution.removeContext(); // Make sure we mark the component manager for garbage collection as otherwise each JUnit test will // have an instance of the Component Manager (will all the components it's holding), leading to // out of memory errors when there are lots of tests... this.componentManager = null; }
/** * {@inheritDoc} * * @see org.xwiki.rendering.macro.MacroManager#exists(org.xwiki.rendering.macro.MacroId) */ public boolean exists(MacroId macroId) { String macroHint = macroId.toString(); boolean hasMacro = true; try { getComponentManager().lookup(Macro.class, macroHint); } catch (ComponentLookupException ex) { hasMacro = false; } return hasMacro; }
/** * @return the RemoteObservationManager */ public RemoteObservationManager getRemoteObservationManager() { if (this.remoteObservationManager == null) { try { this.remoteObservationManager = componentManager.lookup(RemoteObservationManager.class); } catch (ComponentLookupException e) { getLogger().error("Failed to lookup RemoteObservationManager componenent.", e); } } return remoteObservationManager; }
public void initialize() throws Exception { // Initialize the Execution Context ExecutionContextManager ecm = (ExecutionContextManager) getComponentManager().lookup(ExecutionContextManager.ROLE); Execution execution = (Execution) getComponentManager().lookup(Execution.ROLE); ExecutionContext ec = new ExecutionContext(); // Make sure we push this empty context in the Execution component before we call the initialization // so that we don't get any NPE if some initializer code asks to get the Execution Context. This // happens for example with the Velocity Execution Context initializer which in turns calls the Velocity // Context initializers and some of them look inside the Execution Context. execution.setContext(ec); ecm.initialize(ec); }
/** * @return the {@link StreamParser} to use to parser the input content */ protected StreamParser getStreamParser() { StreamParser streamParser; try { streamParser = this.componentManager.lookup(StreamParser.class, getSyntax().toIdString()); } catch (ComponentLookupException e) { throw new RuntimeException("Failed to create [" + getSyntax().toString() + "] renderer", e); } return streamParser; }
private String computeAltAttributeValue(ResourceReference reference) { String label; try { URILabelGenerator uriLabelGenerator = this.componentManager.lookup(URILabelGenerator.class, reference.getType().getScheme()); label = uriLabelGenerator.generateLabel(reference); } catch (ComponentLookupException e) { label = reference.getReference(); } return label; } }
private String computeAltAttributeValue(ResourceReference reference) { String label; try { URILabelGenerator uriLabelGenerator = this.componentManager.lookup(URILabelGenerator.class, reference.getType().getScheme()); label = uriLabelGenerator.generateLabel(reference); } catch (ComponentLookupException e) { label = reference.getReference(); } return label; } }
private synchronized Task executeTask(String taskId, Request request) throws TaskException { if (this.currentTask != null && this.currentTask.getStatus() != Status.FINISHED) { throw new TaskException("A task is already running"); } try { this.currentTask = this.componentManager.lookup(Task.class, taskId); } catch (ComponentLookupException e) { throw new TaskException("Failed to lookup any Task for role hint [" + taskId + "]", e); } this.currentTask.start(request); return this.currentTask; } }
public void addRepository(ExtensionRepositoryId repositoryId) throws ExtensionRepositoryException { try { ExtensionRepositoryFactory repositoryFactory = this.componentManager.lookup(ExtensionRepositoryFactory.class, repositoryId.getType()); addRepository(repositoryFactory.createRepository(repositoryId)); } catch (ComponentLookupException e) { throw new ExtensionRepositoryException("Unsupported repository type[" + repositoryId.getType() + "]", e); } }
private XHTMLLinkTypeRenderer getXHTMLLinkTypeRenderer(ResourceReference reference) { XHTMLLinkTypeRenderer renderer; // TODO: This is probably not very performant since it's called at each begin/endLink. try { renderer = this.componentManager.lookup(XHTMLLinkTypeRenderer.class, reference.getType().getScheme()); } catch (ComponentLookupException e) { // There's no specific XHTML Link Type Renderer for the passed link type, use the default renderer. renderer = this.defaultLinkTypeRenderer; } renderer.setHasLabel(this.hasLabel); renderer.setXHTMLWikiPrinter(getXHTMLWikiPrinter()); return renderer; } }
/** * @param event event object containing the new component descriptor * @param descriptor the component descriptor removed from component manager */ private void componentAdded(ComponentDescriptorAddedEvent event, ComponentDescriptor<EventListener> descriptor) { try { EventListener eventListener = this.componentManager.lookup(EventListener.class, event.getRoleHint()); if (getListener(eventListener.getName()) != eventListener) { addListener(eventListener); } } catch (ComponentLookupException e) { getLogger().error("Failed to lookup event listener corresponding to the component registration event", e); } }