Search in sources :

Example 6 with WikiComponentException

use of org.xwiki.component.wiki.WikiComponentException in project xwiki-platform by xwiki.

the class WikiUIExtensionComponentBuilderTest method buildWikiLevelComponentsWithoutAdminRights.

@Test
public void buildWikiLevelComponentsWithoutAdminRights() throws Exception {
    BaseObject extensionObject = createExtensionObject("id", "extensionPointId", "content", "parameters", "wiki");
    try {
        this.mocker.getComponentUnderTest().buildComponents(extensionObject);
        fail("You shouldn't be able to register UI extensions at wiki level without wiki admin rights.");
    } catch (WikiComponentException expected) {
        assertEquals("Registering UI extensions at wiki level requires wiki administration rights", expected.getMessage());
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 7 with WikiComponentException

use of org.xwiki.component.wiki.WikiComponentException in project xwiki-platform by xwiki.

the class DefaultWikiComponentBridge method getDependencies.

@Override
public Map<String, ComponentDescriptor> getDependencies(DocumentReference reference) throws WikiComponentException {
    Map<String, ComponentDescriptor> dependencies = new HashMap<String, ComponentDescriptor>();
    XWikiDocument componentDocument = this.getDocument(reference);
    if (componentDocument.getObjectNumbers(DEPENDENCY_CLASS) > 0) {
        for (BaseObject dependency : componentDocument.getObjects(DEPENDENCY_CLASS)) {
            try {
                DefaultComponentDescriptor cd = new DefaultComponentDescriptor();
                cd.setRoleType(ReflectionUtils.unserializeType(dependency.getStringValue(COMPONENT_ROLE_TYPE_FIELD), Thread.currentThread().getContextClassLoader()));
                cd.setRoleHint(dependency.getStringValue(COMPONENT_ROLE_HINT_FIELD));
                dependencies.put(dependency.getStringValue(DEPENDENCY_BINDING_NAME_FIELD), cd);
            } catch (Exception e) {
                this.logger.warn("Interface [{}] not found, declared as dependency for wiki component [{}]", dependency.getStringValue(COMPONENT_ROLE_TYPE_FIELD), componentDocument.getDocumentReference());
            }
        }
    }
    return dependencies;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) HashMap(java.util.HashMap) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) ComponentDescriptor(org.xwiki.component.descriptor.ComponentDescriptor) XWikiException(com.xpn.xwiki.XWikiException) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 8 with WikiComponentException

use of org.xwiki.component.wiki.WikiComponentException in project xwiki-platform by xwiki.

the class DefaultWikiComponentBridge method getDeclaredInterfaces.

@Override
public List<Class<?>> getDeclaredInterfaces(DocumentReference reference) throws WikiComponentException {
    List<Class<?>> interfaces = new ArrayList<Class<?>>();
    XWikiDocument componentDocument = this.getDocument(reference);
    if (componentDocument.getObjectNumbers(INTERFACE_CLASS) > 0) {
        for (BaseObject iface : componentDocument.getObjects(INTERFACE_CLASS)) {
            if (!StringUtils.isBlank(iface.getStringValue(INTERFACE_NAME_FIELD))) {
                try {
                    Class<?> implemented = Class.forName(iface.getStringValue(INTERFACE_NAME_FIELD));
                    interfaces.add(implemented);
                } catch (Exception e) {
                    this.logger.warn("Interface [{}] not found, declared for wiki component [{}]", iface.getStringValue(INTERFACE_NAME_FIELD), componentDocument.getDocumentReference());
                }
            }
        }
    }
    return interfaces;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) XWikiException(com.xpn.xwiki.XWikiException) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 9 with WikiComponentException

use of org.xwiki.component.wiki.WikiComponentException in project xwiki-platform by xwiki.

the class DefaultWikiComponentBridge method getRoleType.

@Override
public Type getRoleType(DocumentReference reference) throws WikiComponentException {
    BaseObject componentObject = getComponentObject(reference);
    String role = componentObject.getStringValue(COMPONENT_ROLE_TYPE_FIELD);
    Type roleType;
    try {
        roleType = ReflectionUtils.unserializeType(role, Thread.currentThread().getContextClassLoader());
    } catch (ClassNotFoundException e) {
        throw new WikiComponentException(String.format("The role type [%s] does not exist", role), e);
    }
    return roleType;
}
Also used : Type(java.lang.reflect.Type) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 10 with WikiComponentException

use of org.xwiki.component.wiki.WikiComponentException in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListener method registerAllDocumentComponents.

/**
 * Register all the wiki components that come from a document in the current wiki.
 */
private void registerAllDocumentComponents() {
    try {
        // Retrieve all components definitions and register them.
        this.wikiComponentProviders = this.componentManager.getInstanceList(WikiComponentBuilder.class);
        for (WikiComponentBuilder provider : this.wikiComponentProviders) {
            for (DocumentReference reference : provider.getDocumentReferences()) {
                try {
                    List<WikiComponent> components = provider.buildComponents(reference);
                    this.wikiComponentManagerEventListenerHelper.registerComponentList(components);
                } catch (WikiComponentException e) {
                    this.logger.warn("Failed to build the wiki component located in the document [{}]: {}", reference, ExceptionUtils.getRootCauseMessage(e));
                }
            }
        }
    } catch (ComponentLookupException e) {
        this.logger.warn(String.format("Unable to get a list of registered WikiComponentBuilder: %s", e));
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) WikiComponentBuilder(org.xwiki.component.wiki.WikiComponentBuilder) WikiComponent(org.xwiki.component.wiki.WikiComponent) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

WikiComponentException (org.xwiki.component.wiki.WikiComponentException)18 BaseObject (com.xpn.xwiki.objects.BaseObject)7 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 WikiComponent (org.xwiki.component.wiki.WikiComponent)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 XWikiException (com.xpn.xwiki.XWikiException)3 Type (java.lang.reflect.Type)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ComponentDescriptor (org.xwiki.component.descriptor.ComponentDescriptor)2 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)2 WikiComponentBuilder (org.xwiki.component.wiki.WikiComponentBuilder)2 EntityReference (org.xwiki.model.reference.EntityReference)2 NotificationException (org.xwiki.notifications.NotificationException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 HashMap (java.util.HashMap)1 ComponentRepositoryException (org.xwiki.component.manager.ComponentRepositoryException)1 Initializable (org.xwiki.component.phase.Initializable)1