Search in sources :

Example 91 with BaseClass

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;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 92 with BaseClass

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;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 93 with BaseClass

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);
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass)

Example 94 with BaseClass

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);
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) EntityReference(org.xwiki.model.reference.EntityReference) RegexEntityReference(org.xwiki.model.reference.RegexEntityReference) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) Syntax(org.xwiki.rendering.syntax.Syntax)

Example 95 with BaseClass

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

BaseClass (com.xpn.xwiki.objects.classes.BaseClass)100 DocumentReference (org.xwiki.model.reference.DocumentReference)42 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)41 BaseObject (com.xpn.xwiki.objects.BaseObject)40 XWikiException (com.xpn.xwiki.XWikiException)26 XWikiContext (com.xpn.xwiki.XWikiContext)24 ArrayList (java.util.ArrayList)18 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)16 XWiki (com.xpn.xwiki.XWiki)15 Test (org.junit.Test)15 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 EntityReference (org.xwiki.model.reference.EntityReference)10 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)9 BaseProperty (com.xpn.xwiki.objects.BaseProperty)9 List (java.util.List)9 ToString (org.suigeneris.jrcs.util.ToString)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 Before (org.junit.Before)6 TextAreaClass (com.xpn.xwiki.objects.classes.TextAreaClass)5 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)5