use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class SxDocumentSource method getContent.
@Override
public String getContent() {
StringBuilder resultBuilder = new StringBuilder();
List<BaseObject> objects = this.document.getObjects(this.extension.getClassName());
if (objects != null) {
for (BaseObject sxObj : objects) {
if (sxObj == null) {
continue;
}
String sxContent = sxObj.getLargeStringValue(CONTENT_PROPERTY_NAME);
int parse = sxObj.getIntValue(PARSE_CONTENT_PROPERTY_NAME);
if ("LESS".equals(sxObj.getStringValue(CONTENT_TYPE_PROPERTY_NAME))) {
LESSCompiler lessCompiler = Utils.getComponent(LESSCompiler.class);
LESSResourceReferenceFactory lessResourceReferenceFactory = Utils.getComponent(LESSResourceReferenceFactory.class);
ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference(CONTENT_PROPERTY_NAME, sxObj.getReference());
LESSResourceReference lessResourceReference = lessResourceReferenceFactory.createReferenceForXObjectProperty(objectPropertyReference);
try {
sxContent = lessCompiler.compile(lessResourceReference, true, (parse == 1), false);
} catch (LESSCompilerException e) {
// Set the error message in a CSS comment to help the developer understand why its SSX is not
// working (it will work only if the CSS minifier is not used).
sxContent = String.format("/* LESS errors while parsing skin extension [%s]. */\n/* %s */", sxObj.getStringValue(NAME_PROPERTY_NAME), ExceptionUtils.getRootCauseMessage(e));
}
} else if (parse == 1) {
try {
StringWriter writer = new StringWriter();
VelocityManager velocityManager = Utils.getComponent(VelocityManager.class);
VelocityContext vcontext = velocityManager.getVelocityContext();
velocityManager.getVelocityEngine().evaluate(vcontext, writer, this.document.getPrefixedFullName(), sxContent);
sxContent = writer.toString();
} catch (XWikiVelocityException ex) {
LOGGER.warn("Velocity errors while parsing skin extension [{}] with content [{}]: ", this.document.getPrefixedFullName(), sxContent, ExceptionUtils.getRootCauseMessage(ex));
}
}
// Also add a newline, in case the different object contents don't end with a blank
// line, and could cause syntax errors when concatenated.
resultBuilder.append(sxContent + "\n");
}
}
return resultBuilder.toString();
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method removeMembers.
@Override
public void removeMembers(Collection<String> userIds, String wikiId) throws WikiUserManagerException {
// Get the group document
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
// Get the member objects
List<BaseObject> objects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
if (objects != null) {
// Get the member objects to remove
List<BaseObject> objectsToRemove = new ArrayList<>();
for (String userId : userIds) {
for (BaseObject object : objects) {
if (object == null) {
continue;
}
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD);
if (userId.equals(member)) {
objectsToRemove.add(object);
}
}
}
// Remove them
for (BaseObject object : objectsToRemove) {
groupDoc.removeXObject(object);
}
// Save the document
saveGroupDocument(groupDoc, "Remove some users from the group.");
}
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method addMembers.
@Override
public void addMembers(Collection<String> userIds, String wikiId) throws WikiUserManagerException {
Collection<String> members = getMembers(wikiId);
// Get the group document
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
// If the group does not contain any user yet, add an empty member (cf: XWIKI-6275).
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
if (memberObjects == null || memberObjects.isEmpty()) {
addMemberObject(groupDoc, "");
}
// Add members
for (String userId : userIds) {
if (!members.contains(userId)) {
// Add a member object
addMemberObject(groupDoc, userId);
}
}
// Save the document
saveGroupDocument(groupDoc, "Add members to the group.");
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method addMemberObject.
private void addMemberObject(XWikiDocument groupDoc, String userId) throws WikiUserManagerException {
try {
XWikiContext xcontext = xcontextProvider.get();
int objectNumber = groupDoc.createXObject(GROUPCLASS_REFERENCE, xcontext);
BaseObject object = groupDoc.getXObject(GROUPCLASS_REFERENCE, objectNumber);
object.set(GROUP_CLASS_MEMBER_FIELD, userId, xcontext);
} catch (XWikiException e) {
throw new WikiUserManagerException("Fail to add a member to the group", e);
}
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method getMembers.
@Override
public Collection<String> getMembers(String wikiId) throws WikiUserManagerException {
List<String> members = new ArrayList<>();
try {
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Add the wiki owner
members.add(descriptor.getOwnerId());
} catch (WikiManagerException e) {
throw new WikiUserManagerException(String.format("Failed to get the descriptor for [%s]", wikiId), e);
}
// Get the other members from the wiki AllGroup
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
if (memberObjects != null) {
for (BaseObject object : memberObjects) {
if (object == null) {
continue;
}
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD);
if (!member.isEmpty() && !members.contains(member)) {
members.add(member);
}
}
}
return members;
}
Aggregations