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);
}
}
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);
}
}
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()));
}
}
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;
}
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);
}
}
Aggregations