Search in sources :

Example 81 with BaseObject

use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.

the class WatchListStore method createWatchListObject.

/**
 * Creates a WatchList XWiki Object in the user's profile's page.
 *
 * @param user XWiki User
 * @param context Context of the request
 * @return the watchlist object that has been created
 * @throws XWikiException if the document cannot be saved
 */
public BaseObject createWatchListObject(String user, XWikiContext context) throws XWikiException {
    XWikiDocument userDocument = context.getWiki().getDocument(user, context);
    int nb = userDocument.createNewObject(WATCHLIST_CLASS, context);
    BaseObject wObj = userDocument.getObject(WATCHLIST_CLASS, nb);
    context.getWiki().saveDocument(userDocument, context.getMessageTool().get("watchlist.create.object"), true, context);
    return wObj;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 82 with BaseObject

use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.

the class XWiki method getObjectFromRequest.

// This functions adds an object from an new object creation form
public BaseObject getObjectFromRequest(String className, XWikiContext context) throws XWikiException {
    Map<String, String[]> map = Util.getObject(context.getRequest(), className);
    BaseClass bclass = context.getWiki().getClass(className, context);
    BaseObject newobject = (BaseObject) bclass.fromMap(map, context);
    return newobject;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 83 with BaseObject

use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.

the class XWiki method addUserToGroup.

protected void addUserToGroup(String userName, String groupName, XWikiContext context) throws XWikiException {
    XWikiDocument groupDoc = getDocument(groupName, context);
    DocumentReference groupClassReference = getGroupClass(context).getDocumentReference();
    BaseObject memberObject = groupDoc.newXObject(groupClassReference.removeParent(groupClassReference.getWikiReference()), context);
    memberObject.setStringValue("member", userName);
    this.saveDocument(groupDoc, localizePlainOrKey("core.comment.addedUserToGroup"), context);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 84 with BaseObject

use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.

the class XWiki method getServerURL.

public URL getServerURL(String database, XWikiContext context) throws MalformedURLException {
    String serverurl = null;
    // In virtual wiki path mode the server is the standard one
    if ("1".equals(getConfiguration().getProperty("xwiki.virtual.usepath", "1"))) {
        return null;
    }
    if (database != null) {
        String db = context.getWikiId();
        try {
            context.setWikiId(getDatabase());
            XWikiDocument doc = getDocument("XWiki.XWikiServer" + StringUtils.capitalize(database), context);
            BaseObject serverobject = doc.getXObject(VIRTUAL_WIKI_DEFINITION_CLASS_REFERENCE);
            if (serverobject != null) {
                String server = serverobject.getStringValue("server");
                if (server != null) {
                    String protocol = getConfiguration().getProperty("xwiki.url.protocol", null);
                    if (protocol == null) {
                        int iSecure = serverobject.getIntValue("secure", -1);
                        // Check the request object if the "secure" property is undefined.
                        boolean secure = iSecure == 1 || (iSecure < 0 && context.getRequest().isSecure());
                        protocol = secure ? "https" : "http";
                    }
                    long port = context.getURL().getPort();
                    if (port == 80 || port == 443) {
                        port = -1;
                    }
                    if (port != -1) {
                        serverurl = protocol + "://" + server + ":" + port + "/";
                    } else {
                        serverurl = protocol + "://" + server + "/";
                    }
                }
            }
        } catch (Exception ex) {
        } finally {
            context.setWikiId(db);
        }
    }
    if (serverurl != null) {
        return new URL(serverurl);
    } else {
        return null;
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) 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) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 85 with BaseObject

use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.

the class XWiki method validateUser.

public int validateUser(boolean withConfirmEmail, XWikiContext context) throws XWikiException {
    try {
        XWikiRequest request = context.getRequest();
        // Get the user document
        String username = convertUsername(request.getParameter("xwikiname"), context);
        if (username.indexOf('.') == -1) {
            username = "XWiki." + username;
        }
        XWikiDocument userDocument = getDocument(username, context);
        // Get the stored validation key
        BaseObject userObject = userDocument.getObject("XWiki.XWikiUsers", 0);
        String storedKey = userObject.getStringValue("validkey");
        // Get the validation key from the URL
        String validationKey = request.getParameter("validkey");
        PropertyInterface validationKeyClass = getClass("XWiki.XWikiUsers", context).get("validkey");
        if (validationKeyClass instanceof PasswordClass) {
            validationKey = ((PasswordClass) validationKeyClass).getEquivalentPassword(storedKey, validationKey);
        }
        // Compare the two keys
        if ((!storedKey.equals("") && (storedKey.equals(validationKey)))) {
            userObject.setIntValue("active", 1);
            saveDocument(userDocument, context);
            if (withConfirmEmail) {
                String email = userObject.getStringValue("email");
                String password = userObject.getStringValue("password");
                sendValidationEmail(username, password, email, request.getParameter("validkey"), "confirmation_email_content", context);
            }
            return 0;
        } else {
            return -1;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_VALIDATE_USER, "Exception while validating user", e, null);
    }
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) PasswordClass(com.xpn.xwiki.objects.classes.PasswordClass) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) 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

BaseObject (com.xpn.xwiki.objects.BaseObject)484 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)309 DocumentReference (org.xwiki.model.reference.DocumentReference)225 Test (org.junit.Test)137 XWikiException (com.xpn.xwiki.XWikiException)102 XWikiContext (com.xpn.xwiki.XWikiContext)99 ArrayList (java.util.ArrayList)92 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)69 EntityReference (org.xwiki.model.reference.EntityReference)42 XWiki (com.xpn.xwiki.XWiki)41 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)40 List (java.util.List)30 Date (java.util.Date)24 BaseProperty (com.xpn.xwiki.objects.BaseProperty)23 Document (com.xpn.xwiki.api.Document)22 HashMap (java.util.HashMap)21 QueryException (org.xwiki.query.QueryException)18 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)16 IOException (java.io.IOException)16 Vector (java.util.Vector)16