use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method validate.
public boolean validate(String[] classNames, XWikiContext context) throws XWikiException {
boolean isValid = true;
if ((classNames == null) || (classNames.length == 0)) {
for (DocumentReference classReference : getXObjects().keySet()) {
BaseClass bclass = context.getWiki().getXClass(classReference, context);
List<BaseObject> objects = getXObjects(classReference);
for (BaseObject obj : objects) {
if (obj != null) {
isValid &= bclass.validateObject(obj, context);
}
}
}
} else {
for (String className : classNames) {
List<BaseObject> objects = getXObjects(getCurrentMixedDocumentReferenceResolver().resolve(className));
if (objects != null) {
for (BaseObject obj : objects) {
if (obj != null) {
BaseClass bclass = obj.getXClass(context);
isValid &= bclass.validateObject(obj, context);
}
}
}
}
}
String validationScript = "";
XWikiRequest req = context.getRequest();
if (req != null) {
validationScript = req.get("xvalidation");
}
if ((validationScript == null) || (validationScript.trim().equals(""))) {
validationScript = getValidationScript();
}
if ((validationScript != null) && (!validationScript.trim().equals(""))) {
isValid &= executeValidationScript(context, validationScript);
}
return isValid;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method updateXObjectFromRequest.
/**
* Adds an object from an new object creation form.
*
* @since 2.2.3
*/
public BaseObject updateXObjectFromRequest(EntityReference classReference, String prefix, int num, XWikiContext context) throws XWikiException {
DocumentReference absoluteClassReference = resolveClassReference(classReference);
int nb;
BaseObject oldobject = getXObject(absoluteClassReference, num);
if (oldobject == null) {
nb = createXObject(classReference, context);
oldobject = getXObject(absoluteClassReference, nb);
} else {
nb = oldobject.getNumber();
}
BaseClass baseclass = oldobject.getXClass(context);
String newPrefix = prefix + LOCAL_REFERENCE_SERIALIZER.serialize(absoluteClassReference) + "_" + nb;
BaseObject newobject = (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), newPrefix), oldobject);
newobject.setNumber(oldobject.getNumber());
newobject.setGuid(oldobject.getGuid());
setXObject(nb, newobject);
return newobject;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method mergeXClass.
/**
* @since 2.2M1
*/
public void mergeXClass(XWikiDocument templatedoc) {
BaseClass bclass = getXClass();
BaseClass tbclass = templatedoc.getXClass();
if (tbclass != null) {
if (bclass == null) {
setXClass(tbclass.clone());
} else {
getXClass().merge(tbclass.clone());
}
}
setMetaDataDirty(true);
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWiki method createUser.
/**
* Create a new user.
*
* @param userName the name of the user (without the space)
* @param map extra datas to add to user profile object
* @param userRights the right of the user on his own profile page
* @param context see {@link XWikiContext}
* @return
* <ul>
* <li>1: ok</li>
* <li>-3: user already exists</li>
* </ul>
* @throws XWikiException failed to create the new user
*/
public int createUser(String userName, Map<String, ?> map, String userRights, XWikiContext context) throws XWikiException {
BaseClass userClass = getUserClass(context);
String content = "";
Syntax syntax = getDefaultDocumentSyntaxInternal();
return createUser(userName, map, new EntityReference(userClass.getDocumentReference().getName(), EntityType.DOCUMENT), content, syntax, userRights, context);
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWiki method createUser.
/**
* Create a new user.
*
* @param userName the name of the user (without the space)
* @param map extra datas to add to user profile object
* @param parentReference the parent of the user profile
* @param content the content of the user profile
* @param syntax the syntax of the provided content
* @param userRights the right of the user on his own profile page
* @param context see {@link XWikiContext}
* @return
* <ul>
* <li>1: ok</li>
* <li>-3: user already exists</li>
* </ul>
* @throws XWikiException failed to create the new user
*/
public int createUser(String userName, Map<String, ?> map, EntityReference parentReference, String content, Syntax syntax, String userRights, XWikiContext context) throws XWikiException {
BaseClass userClass = getUserClass(context);
try {
// TODO: Verify existing user
XWikiDocument doc = getDocument(new DocumentReference(context.getWikiId(), "XWiki", userName), context);
if (!doc.isNew()) {
// TODO: throws Exception
return -3;
}
DocumentReference userClassReference = userClass.getDocumentReference();
BaseObject userObject = doc.newXObject(userClassReference.removeParent(userClassReference.getWikiReference()), context);
userClass.fromMap(map, userObject);
doc.setParentReference(parentReference);
doc.setContent(content);
doc.setSyntax(syntax);
// Set the user itself as the creator of the document, so that she has the CREATOR right on her user page.
doc.setCreatorReference(doc.getDocumentReference());
// (it may be an administrator).
if (context.getUserReference() != null) {
doc.setAuthorReference(context.getUserReference());
} else {
// Except if the current user is guest (which means the user registered herself)
doc.setAuthorReference(doc.getDocumentReference());
}
// The information from the user profile needs to be indexed using the proper locale. If multilingual is
// enabled then the user can choose the desired locale (from the list of supported locales) before
// registering. An administrator registering users can do the same. Otherwise, if there is only one locale
// supported then that langage will be used.
doc.setDefaultLocale(context.getLocale());
protectUserPage(doc.getFullName(), userRights, doc, context);
saveDocument(doc, localizePlainOrKey("core.comment.createdUser"), context);
// Now let's add the user to XWiki.XWikiAllGroup
setUserDefaultGroup(doc.getFullName(), context);
return 1;
} catch (Exception e) {
Object[] args = { "XWiki." + userName };
throw new XWikiException(XWikiException.MODULE_XWIKI_USER, XWikiException.ERROR_XWIKI_USER_CREATE, "Cannot create user {0}", e, args);
}
}
Aggregations