@Override 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.getInstance(WikiModel.class); } catch (ComponentLookupException e) { // There's no WikiModel implementation available. this.wikiModel stays null. } }
@Override public List<AuditEventProcessor> get() { try { return this.componentManager.<AuditEventProcessor>getInstanceList(AuditEventProcessor.class); } catch (ComponentLookupException ex) { throw new RuntimeException("Failed to look up audit event processors", ex); } } }
@Override public ScriptService get(String serviceName) { ScriptService scriptService = null; if (this.componentManager.get().hasComponent(ScriptService.class, serviceName)) { try { scriptService = this.componentManager.get().getInstance(ScriptService.class, serviceName); } catch (Exception e) { this.logger.error("Failed to lookup script service for role hint [{}]", serviceName, e); } } else { this.logger.debug("No script service registered for role hint [{}]", serviceName); } return scriptService; } }
/** * @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; }
/** * @param syntaxId the syntax for which to verify if there's a Parser * @return true if a Parser exists for the passed syntax, false otherwise */ private boolean hasParserForSyntax(String syntaxId) { return this.componentManager.hasComponent(Parser.class, syntaxId); }
/** * Register components associated to the provided class if there is not already one. * * @param componentImplementation the implementation of the component * @param componentManager the component manager against which to register the components * @throws Exception in case of an error during registration * @since 7.2M2 */ public void registerComponentIfDontExist(Class<?> componentImplementation, ComponentManager componentManager) throws Exception { List<ComponentDescriptor> descriptors = this.loader.getComponentsDescriptors(componentImplementation); for (ComponentDescriptor descriptor : descriptors) { if (!componentManager.hasComponent(descriptor.getRoleType(), descriptor.getRoleHint())) { componentManager.registerComponent(descriptor); } } }
private Map<String, EntityListAddonWebObjectBuilder> getBuilders() { if (builders != null) { return builders; } try { builders = componentManager.getInstanceMap(EntityListAddonWebObjectBuilder.class); return builders; } catch (ComponentLookupException e) { throw new RuntimeException("Failed to initialize entity list addon transformer", e); } }
/** * @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; } }
/** * @param syntaxId the syntax for which to verify if there's a Renderer * @return true if a Renderer exists for the passed syntax, false otherwise */ private boolean hasRendererForSyntax(String syntaxId) { return this.componentManager.hasComponent(BlockRenderer.class, syntaxId); } }
@Override public Map<String, Vocabulary> get() { try { return this.cm.get().getInstanceMap(Vocabulary.class); } catch (ComponentLookupException e) { return Collections.emptyMap(); } } }
private XarObjectPropertySerializer getInstance(String type, ComponentManager componentManager) throws ComponentLookupException { return componentManager.getInstance(XarObjectPropertySerializer.class, type); } }
@Override public TranslationBundle getBundle(String bundleId) throws TranslationBundleDoesNotExistsException { String id = ID + ':' + bundleId; if (this.contextComponentManagerProvider.get().hasComponent(TranslationBundle.class, id)) { try { return this.contextComponentManagerProvider.get().getInstance(TranslationBundle.class, id); } catch (ComponentLookupException e) { this.logger.debug("Failed to lookup component [{}] with hint [{}].", TranslationBundle.class, bundleId, e); } } throw new TranslationBundleDoesNotExistsException(String.format("Can't find any JAR resource for jar [%s]", bundleId)); } }
@Override public Collection<Visibility> listAllVisibilityOptions() { try { Collection<Visibility> result = new TreeSet<>(); result.addAll(this.componentManager.get().<Visibility>getInstanceList(Visibility.class)); return result; } catch (ComponentLookupException ex) { return Collections.emptyList(); } }
/** * {@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. } }
@Override public boolean hasComponent(Type role) { return getComponentManager().hasComponent(role); }
/** * @return the list of available CAPTCHA implementation names */ public List<String> getCaptchaNames() { List<String> names = new ArrayList<>(); try { names = new ArrayList<>(componentManager.getInstanceMap(Captcha.class).keySet()); } catch (Exception e) { logger.error("Failed to get list of captcha names", e); } return names; }
public static void initializeComponent(ComponentManager componentManager) throws Exception { TestUtils.componentManager = componentManager; TestUtils.relativeReferenceResolver = TestUtils.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "relative"); TestUtils.referenceResolver = TestUtils.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING); TestUtils.referenceSerializer = TestUtils.componentManager.getInstance(EntityReferenceSerializer.TYPE_STRING); }
/** * @param roleHint the {@link Tree} role hint * @return the {@link Tree} component implementation with the specified hint */ public Tree get(String roleHint) { ComponentManager contextComponentManager = this.contextComponentManagerProvider.get(); if (contextComponentManager.hasComponent(Tree.class, roleHint)) { try { return contextComponentManager.getInstance(Tree.class, roleHint); } catch (ComponentLookupException e) { this.logger.warn("Failed to load the specified tree component. Root cause is [{}]", ExceptionUtils.getRootCauseMessage(e)); } } return null; } }
@Nonnull @Override public Collection<Visibility> listAllVisibilityOptions() { try { return new TreeSet<>(this.componentManager.get().getInstanceList(Visibility.class)); } catch (final ComponentLookupException ex) { return Collections.emptyList(); } }
/** * @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; } }