Search in sources :

Example 1 with WikiPropertyGroupManager

use of org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorBuilder method buildDescriptorObject.

@Override
public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) {
    List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects);
    BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0);
    DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document);
    if (descriptor != null) {
        // Create WikiAlias instances for the other XWikiServerClass objects
        for (BaseObject serverClassObject : normalizedServerClassObjects) {
            if (serverClassObject != null) {
                String descriptorAlias = extractWikiAlias(serverClassObject);
                descriptor.addAlias(descriptorAlias);
            }
        }
        // load properties
        descriptor.setMainPageReference(referenceResolver.resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)));
        descriptor.setPrettyName(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME));
        descriptor.setOwnerId(getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId()));
        descriptor.setDescription(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION));
        // load the property groups
        try {
            WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get();
            wikiPropertyGroupManager.loadForDescriptor(descriptor);
        } catch (WikiPropertyGroupException e) {
            logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e);
        }
    }
    return descriptor;
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiPropertyGroupManager(org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 2 with WikiPropertyGroupManager

use of org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorBuilder method save.

@Override
public XWikiDocument save(WikiDescriptor descriptor) throws WikiDescriptorBuilderException {
    XWikiContext context = xcontextProvider.get();
    XWiki xwiki = context.getWiki();
    XWikiDocument descriptorDoc = null;
    try {
        // Create the descriptor document
        descriptorDoc = wikiDescriptorDocumentHelper.getDocumentFromWikiId(descriptor.getId());
        // Create the server class object
        BaseObject obj = descriptorDoc.getXObject(DefaultWikiDescriptor.SERVER_CLASS, true, context);
        obj.set(XWikiServerClassDocumentInitializer.FIELD_SERVER, descriptor.getDefaultAlias(), context);
        obj.set(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE, referenceSerializer.serialize(descriptor.getMainPageReference()), context);
        obj.set(XWikiServerClassDocumentInitializer.FIELD_OWNER, getFullReference(descriptor.getOwnerId(), descriptor.getId()), context);
        obj.set(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME, descriptor.getPrettyName(), context);
        obj.set(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION, descriptor.getDescription(), context);
        // Create the aliases
        List<String> aliases = descriptor.getAliases();
        for (int i = 1; i < aliases.size(); ++i) {
            String alias = aliases.get(i);
            BaseObject objAlias = descriptorDoc.getXObject(DefaultWikiDescriptor.SERVER_CLASS, XWikiServerClassDocumentInitializer.FIELD_SERVER, alias, true);
            objAlias.set(XWikiServerClassDocumentInitializer.FIELD_SERVER, alias, context);
        }
        // Set the meta-data (creator, hidden flag, parent, etc...)
        setDescriptorDocMetadata(descriptorDoc);
        // Save the document
        xwiki.saveDocument(descriptorDoc, context);
        // Save the property groups
        WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get();
        wikiPropertyGroupManager.saveForDescriptor(descriptor);
    } catch (WikiManagerException e) {
        throw new WikiDescriptorBuilderException("Unable to load the descriptor document", e);
    } catch (XWikiException e) {
        throw new WikiDescriptorBuilderException("Unable to save the descriptor document", e);
    } catch (WikiPropertyGroupException e) {
        throw new WikiDescriptorBuilderException("Unable to save the property groups", e);
    }
    return descriptorDoc;
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiPropertyGroupManager(org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

BaseObject (com.xpn.xwiki.objects.BaseObject)2 WikiPropertyGroupManager (org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager)2 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1