Search in sources :

Example 1 with WikiComponentException

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

the class EditorWikiComponent method initialize.

/**
 * Initializes the editor component based on the definition provided by the specified document.
 *
 * @param editorReference the reference to the wiki page that defines the editor (i.e. that has a
 *            {@code XWiki.EditorClass} object)
 * @throws WikiComponentException if the editor component fails to be initialized
 */
public void initialize(DocumentReference editorReference) throws WikiComponentException {
    if (this.editorReference != null) {
        throw new WikiComponentException("This editor component is already initialized.");
    }
    this.editorReference = editorReference;
    try {
        XWikiContext xcontext = this.xcontextProvider.get();
        initialize(xcontext.getWiki().getDocument(editorReference, xcontext));
    } catch (XWikiException e) {
        throw new WikiComponentException("Failed to load the editor document.", e);
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with WikiComponentException

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

the class EditorWikiComponent method initialize.

private void initialize(BaseObject editorObject) throws WikiComponentException {
    this.descriptorBuilder.setId(editorObject.getStringValue("roleHint"));
    this.descriptorBuilder.setIcon(editorObject.getStringValue("icon"));
    this.descriptorBuilder.setCategory(editorObject.getStringValue("category"));
    this.scope = WikiComponentScope.fromString(editorObject.getStringValue("scope"));
    String dataTypeName = editorObject.getStringValue("dataType");
    try {
        Type dataType = ReflectionUtils.unserializeType(dataTypeName, Thread.currentThread().getContextClassLoader());
        this.roleType = new DefaultParameterizedType(null, Editor.class, dataType);
    } catch (ClassNotFoundException e) {
        throw new WikiComponentException(String.format("The [%s] data type does not exist.", dataTypeName), e);
    }
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Editor(org.xwiki.edit.Editor) AbstractEditor(org.xwiki.edit.AbstractEditor)

Example 3 with WikiComponentException

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

the class EditorWikiComponent method initialize.

private void initialize(XWikiDocument editorDocument) throws WikiComponentException {
    this.authorReference = editorDocument.getAuthorReference();
    BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE);
    if (editorObject != null) {
        initialize(editorObject);
    } else {
        throw new WikiComponentException(String.format("The document [%s] is missing the XWiki.EditorClass object.", editorDocument.getDocumentReference()));
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 4 with WikiComponentException

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

the class DefaultWikiComponentBuilder method buildComponents.

@Override
public List<WikiComponent> buildComponents(DocumentReference reference) throws WikiComponentException {
    List<WikiComponent> components = new ArrayList<WikiComponent>();
    if (!this.componentBridge.hasProgrammingRights(reference)) {
        throw new WikiComponentException("Registering wiki components requires programming rights");
    }
    DefaultWikiComponent rawComponent = new DefaultWikiComponent(reference, componentBridge.getAuthorReference(reference), componentBridge.getRoleType(reference), componentBridge.getRoleHint(reference), componentBridge.getScope(reference));
    rawComponent.setHandledMethods(componentBridge.getHandledMethods(reference));
    rawComponent.setImplementedInterfaces(componentBridge.getDeclaredInterfaces(reference));
    rawComponent.setDependencies(componentBridge.getDependencies(reference));
    rawComponent.setSyntax(componentBridge.getSyntax(reference));
    // Create the method invocation handler of the proxy
    InvocationHandler handler = new DefaultWikiComponentInvocationHandler(rawComponent, contextComponentManager);
    // Prepare a list containing the interfaces the component implements
    List<Class<?>> implementedInterfaces = new ArrayList<Class<?>>();
    // Add the main role
    Class<?> roleTypeClass = ReflectionUtils.getTypeClass(rawComponent.getRoleType());
    // Add the component role
    implementedInterfaces.add(ReflectionUtils.getTypeClass(roleTypeClass));
    // Add the additional interfaces declared through XObjects
    implementedInterfaces.addAll(rawComponent.getImplementedInterfaces());
    // Add the interfaces from the java class itself (interfaces implemented by DefaultWikiComponent)
    implementedInterfaces.addAll(Arrays.asList(rawComponent.getClass().getInterfaces()));
    // Create the proxy
    Class<?>[] implementedInterfacesArray = implementedInterfaces.toArray(new Class<?>[0]);
    WikiComponent component = (WikiComponent) Proxy.newProxyInstance(roleTypeClass.getClassLoader(), implementedInterfacesArray, handler);
    components.add(component);
    return components;
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) WikiComponent(org.xwiki.component.wiki.WikiComponent) ArrayList(java.util.ArrayList) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 5 with WikiComponentException

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

the class PanelWikiUIExtensionComponentBuilder method buildComponents.

@Override
public List<WikiComponent> buildComponents(BaseObject baseObject) throws WikiComponentException {
    String content = baseObject.getStringValue("content");
    Syntax syntax = baseObject.getOwnerDocument().getSyntax();
    DocumentReference documentReference = baseObject.getOwnerDocument().getDocumentReference();
    DocumentReference authorReference = baseObject.getOwnerDocument().getAuthorReference();
    XDOM xdom = this.parser.parse(content, syntax, documentReference);
    try {
        return Collections.<WikiComponent>singletonList(new PanelWikiUIExtension(baseObject.getReference(), authorReference, xdom, syntax, this.componentManager));
    } catch (ComponentLookupException e) {
        throw new WikiComponentException(String.format("Failed to initialize Panel UI extension [%s]", baseObject), e);
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) XDOM(org.xwiki.rendering.block.XDOM) WikiComponent(org.xwiki.component.wiki.WikiComponent) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Syntax(org.xwiki.rendering.syntax.Syntax) 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