/** * @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); } }
/** * @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); }
@Override public boolean hasComponent(Type role, String hint) { return getComponentManager().hasComponent(role, hint); }
@Override public boolean hasComponent(Type role) { return getComponentManager().hasComponent(role); }
private boolean isStreamingTest(String inputSyntaxId, String outputSyntaxId) { return getComponentManager().hasComponent(StreamParser.class, inputSyntaxId) && getComponentManager().hasComponent(PrintRendererFactory.class, outputSyntaxId); }
@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; } }
/** * @param type the property type for which to find a serializer * @return the property serializer, if none could be found for the provided type the default one is returned * @throws ComponentLookupException when failing to lookup property serializer */ public XarObjectPropertySerializer getPropertySerializer(String type) throws ComponentLookupException { if (type != null) { ComponentManager componentManager = this.componentManagerProvider.get(); if (componentManager.hasComponent(XarObjectPropertySerializer.class, type)) { // First try to use the specified class type as hint. return getInstance(type, componentManager); } else { // In previous versions the class type was the full Java class name of the property class // implementation. Extract the hint by removing the Java package prefix and the Class suffix. String simpleType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class"); if (componentManager.hasComponent(XarObjectPropertySerializer.class, simpleType)) { return getInstance(simpleType, componentManager); } } } return this.defaultPropertySerializer; }
@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 ExtensionRepository getRepository(String repositoryId) { // Try internal repositories ExtensionRepository repository = this.standardRepositories.get(repositoryId); // Try component repositories ComponentManager componentManager = this.componentManagerProvider.get(); if (componentManager.hasComponent(ExtensionRepository.class, repositoryId)) { try { return componentManager.getInstance(ExtensionRepository.class, repositoryId); } catch (ComponentLookupException e) { this.logger.error("Failed to lookup component", e); } } // Try remote repositories if (repository == null) { repository = this.repositoryManager.getRepository(repositoryId); } return repository; }
/** * @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; } }
@Override public TranslationBundle getBundle(String bundleId) throws TranslationBundleDoesNotExistsException { String roleHint = ID_PREFIX + bundleId; if (this.componentManagerProvider.get().hasComponent(TranslationBundle.class, roleHint)) { try { return this.componentManagerProvider.get().getInstance(TranslationBundle.class, roleHint); } catch (ComponentLookupException e) { this.logger.debug("Failed to lookup component [{}] with hint [{}].", TranslationBundle.class, bundleId, e); } } return getOnDemandDocumentBundle(this.currentResolver.resolve(bundleId)); }
/** * 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); }
@Override public TranslationBundle getTranslationBundle(String bundleType, String bundleId) throws TranslationBundleDoesNotExistsException, TranslationBundleFactoryDoesNotExistsException { if (this.componentManagerProvider.get().hasComponent(TranslationBundle.class, bundleType + ':' + bundleId)) { try { return this.componentManagerProvider.get().<TranslationBundle> getInstance(TranslationBundle.class, bundleType + ':' + bundleId); } catch (ComponentLookupException e) { this.logger.error("Failed to lookup component", e); } } TranslationBundleFactory bundleFactory; try { bundleFactory = this.componentManagerProvider.get().getInstance(TranslationBundleFactory.class, bundleType); } catch (ComponentLookupException e) { throw new TranslationBundleFactoryDoesNotExistsException(String.format( "Failed to lookup BundleFactory for type [%s]", bundleType), e); } return bundleFactory.getBundle(bundleId); }
@Override public boolean hasComponent(Type roleType, String roleHint) { if (getComponentEntry(roleType, roleHint) != null) { return true; } return getParent() != null ? getParent().hasComponent(roleType, roleHint) : false; }
@Override public Macro<?> getMacro(MacroId macroId) throws MacroLookupException { // First search for a macro registered for the passed macro id. String macroHint = macroId.toString(); ComponentManager cm = this.componentManager.get(); try { if (cm.hasComponent(Macro.class, macroHint)) { return cm.getInstance(Macro.class, macroHint); } else { // Now search explicitly for a macro registered for all syntaxes. if (cm.hasComponent(Macro.class, macroId.getId())) { return cm.getInstance(Macro.class, macroId.getId()); } throw new MacroNotFoundException(String.format("No macro [%s] could be found.", macroId.toString())); } } catch (ComponentLookupException e) { throw new MacroLookupException(String.format("Macro [%s] failed to be instantiated.", macroId.toString()), e); } }
private XHTMLLinkTypeRenderer getXHTMLLinkTypeRenderer(ResourceReference reference) { XHTMLLinkTypeRenderer renderer = this.defaultLinkTypeRenderer; // TODO: This is probably not very performant since it's called at each begin/endLink. ComponentManager componentManager = this.componentManagerProvider.get(); if (componentManager.hasComponent(XHTMLLinkTypeRenderer.class, reference.getType().getScheme())) { try { renderer = this.componentManagerProvider.get().getInstance(XHTMLLinkTypeRenderer.class, reference.getType().getScheme()); } catch (ComponentLookupException e) { this.logger.error("Failed to initialize XHTML link type renderer", e); } } renderer.setHasLabel(this.hasLabel); renderer.setXHTMLWikiPrinter(getXHTMLWikiPrinter()); return renderer; } }
/** * 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 Syntax getRendererSyntax() throws Exception { Syntax syntax; if (getComponentManager().hasComponent(PrintRendererFactory.class, this.targetSyntaxId)) { PrintRendererFactory streamRendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, this.targetSyntaxId); syntax = streamRendererFactory.getSyntax(); } else { syntax = Syntax.valueOf(this.targetSyntaxId); } return syntax; }
/** * Get the parser for the passed Syntax. * * @param syntax the Syntax for which to find the Parser * @return the matching Parser that can be used to parse content in the passed Syntax * @throws MacroExecutionException if there's no Parser in the system for the passed Syntax */ protected Parser getSyntaxParser(Syntax syntax) throws MacroExecutionException { if (this.componentManager.hasComponent(Parser.class, syntax.toIdString())) { try { return this.componentManager.getInstance(Parser.class, syntax.toIdString()); } catch (ComponentLookupException e) { throw new MacroExecutionException( String.format("Failed to lookup Parser for syntax [%s]", syntax.toIdString()), e); } } else { throw new MacroExecutionException(String.format("Cannot find Parser for syntax [%s]", syntax.toIdString())); } } }
private BlockRenderer getContentRenderer() { if (this.componentManager != null) { MetaDataBlock metaDataBlock = getFirstBlock(new MetadataBlockMatcher(MetaData.SYNTAX), Axes.ANCESTOR_OR_SELF); if (metaDataBlock != null) { Syntax syntax = (Syntax) metaDataBlock.getMetaData().getMetaData(MetaData.SYNTAX); if (this.componentManager.hasComponent(BlockRenderer.class, syntax.toIdString())) { try { return this.componentManager.getInstance(BlockRenderer.class, syntax.toIdString()); } catch (ComponentLookupException e) { // Fall-back on the default content renderer; } } } } return this.contentRenderer; } }