/** * Get the entity reference of the bounded component instance. * * @return the entity reference bounded to the component * @since 9.5RC1 */ default EntityReference getEntityReference() { return this.getDocumentReference(); }
private void cacheWikiComponent(WikiComponent component) { List<WikiComponent> wikiComponents = this.registeredComponents.get(component.getEntityReference()); if (wikiComponents == null) { wikiComponents = new ArrayList<>(); this.registeredComponents.put(component.getEntityReference(), wikiComponents); } if (!wikiComponents.contains(component)) { wikiComponents.add(component); } }
private void unregisterWikiComponent(Iterator<WikiComponent> iterator) throws WikiComponentException { WikiComponent wikiComponent = iterator.next(); // Save current context information DocumentReference currentUserReference = this.wikiComponentManagerContext.getCurrentUserReference(); EntityReference currentEntityReference = this.wikiComponentManagerContext.getCurrentEntityReference(); try { // Set the proper information so the component manager use the proper keys to find components to // unregister this.wikiComponentManagerContext.setCurrentUserReference(wikiComponent.getAuthorReference()); this.wikiComponentManagerContext.setCurrentEntityReference(wikiComponent.getEntityReference()); // Remove from the Component Manager getComponentManager(wikiComponent.getScope()).unregisterComponent(wikiComponent.getRoleType(), wikiComponent.getRoleHint()); // Remove from the wiki component cache iterator.remove(); } catch (ComponentLookupException e) { throw new WikiComponentException(String.format("Failed to find a component manager for scope [%s]", wikiComponent.getScope()), e); } finally { this.wikiComponentManagerContext.setCurrentUserReference(currentUserReference); this.wikiComponentManagerContext.setCurrentEntityReference(currentEntityReference); } }
Type roleType = component.getRoleType(); Class< ? > roleTypeClass = ReflectionUtils.getTypeClass(roleType); ComponentDescriptor componentDescriptor = createComponentDescriptor(roleType, component.getRoleHint()); this.wikiComponentManagerContext.setCurrentUserReference(component.getAuthorReference()); this.wikiComponentManagerContext.setCurrentEntityReference(component.getEntityReference()); getComponentManager(component.getScope()).registerComponent(componentDescriptor, roleTypeClass.cast(component)); } catch (ComponentLookupException e) { throw new WikiComponentException(String.format("Failed to find a component manager for scope [%s] wiki " + "component registration failed", component.getScope()), e); } catch (ComponentRepositoryException e) { throw new WikiComponentException("Failed to register wiki component against component repository", e);
/** * Register every given {@link WikiComponent} against the {@link WikiComponentManager}. * * @param components a list of components that should be registered */ public void registerComponentList(List<WikiComponent> components) { for (WikiComponent component : components) { // Register the component try { this.wikiComponentManager.registerWikiComponent(component); } catch (WikiComponentException e) { this.logger.warn("Unable to register component(s) from document [{}]: {}", component.getDocumentReference(), ExceptionUtils.getRootCauseMessage(e)); } } }
extensionId = wikiComponent.getDocumentReference(); } else { extensionId = resolver.resolve(extension.getId());