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