Search in sources :

Example 66 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class CreateAction method getEditMode.

/**
 * @param template the template to create document from
 * @param resolver the resolver to use to resolve the template document reference
 * @param context the context of the current request
 * @return the default edit mode for a document created from the passed template
 * @throws XWikiException in case something goes wrong accessing template document
 */
private String getEditMode(String template, DocumentReferenceResolver<String> resolver, XWikiContext context) throws XWikiException {
    // Determine the edit action (edit/inline) for the newly created document, if a template is passed it is
    // used to determine the action. Default is 'edit'.
    String editAction = "edit";
    XWiki xwiki = context.getWiki();
    if (!StringUtils.isEmpty(template)) {
        DocumentReference templateReference = resolver.resolve(template);
        if (xwiki.exists(templateReference, context)) {
            editAction = xwiki.getDocument(templateReference, context).getDefaultEditMode(context);
        }
    }
    return editAction;
}
Also used : XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 67 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class CreateActionRequestHandler method getNewDocumentReference.

/**
 * @return the document reference of the new document to be created, {@code null} if a no document can be created
 *         (because the conditions are not met)
 */
public DocumentReference getNewDocumentReference() {
    DocumentReference result = null;
    if (StringUtils.isEmpty(name)) {
        // Can`t do anything without a name.
        return null;
    }
    // The new values, after the processing needed for ND below, to be used when creating the document reference.
    SpaceReference newSpaceReference = spaceReference;
    String newName = name;
    // Special handling for old spaces or new Nested Documents.
    if (isSpace) {
        EntityReference parentSpaceReference = spaceReference;
        if (parentSpaceReference == null) {
            parentSpaceReference = context.getDoc().getDocumentReference().getWikiReference();
        }
        // The new space's reference.
        newSpaceReference = new SpaceReference(name, parentSpaceReference);
        // The new document's name set to the new space's homepage. In Nested Documents, this leads to the new ND's
        // reference name.
        newName = WEBHOME;
    }
    if (newSpaceReference == null) {
        // documents can be top-level.
        return null;
    }
    // that there is no template is ok.
    if (hasTemplate() || availableTemplateProviders.isEmpty()) {
        result = new DocumentReference(newName, newSpaceReference);
    }
    return result;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 68 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class XWikiAuthServiceImpl method createUser.

protected String createUser(String user, XWikiContext context) throws XWikiException {
    String createuser = getParam("auth_createuser", context);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Create user param is " + createuser);
    }
    if (createuser != null) {
        String wikiname = context.getWiki().clearName(user, true, true, context);
        XWikiDocument userdoc = context.getWiki().getDocument(new DocumentReference(context.getWikiId(), "XWiki", wikiname), context);
        if (userdoc.isNew()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("User page does not exist for user " + user);
            }
            if ("empty".equals(createuser)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Creating emptry user for user " + user);
                }
                context.getWiki().createEmptyUser(wikiname, "edit", context);
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("User page already exists for user " + user);
            }
        }
        return wikiname;
    }
    return user;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 69 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class XWikiAuthServiceImpl method getContextUserName.

private String getContextUserName(Principal principal, XWikiContext context) {
    String contextUserName;
    if (principal != null) {
        // Ensures that the wiki part is removed if specified in the Principal name and if it's not the same wiki
        // as the current wiki.
        DocumentReference userDocumentReference = this.currentDocumentReferenceResolver.resolve(principal.getName());
        contextUserName = this.compactWikiEntityReferenceSerializer.serialize(userDocumentReference);
    } else {
        contextUserName = null;
    }
    return contextUserName;
}
Also used : DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 70 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class XWikiRightServiceImpl method addMemberGroups.

private void addMemberGroups(String wiki, String prefixedFullName, DocumentReference userOrGroupDocumentReference, Collection<String> grouplist, XWikiContext context) throws XWikiException {
    XWikiGroupService groupService = context.getWiki().getGroupService(context);
    Map<String, Collection<String>> grouplistcache = (Map<String, Collection<String>>) context.get("grouplist");
    if (grouplistcache == null) {
        grouplistcache = new HashMap<String, Collection<String>>();
        context.put("grouplist", grouplistcache);
    }
    // the key is for the entity <code>prefixedFullName</code> in current wiki
    String key = wiki + ":" + prefixedFullName;
    Collection<String> tmpGroupList = grouplistcache.get(key);
    if (tmpGroupList == null) {
        String currentWiki = context.getWikiId();
        try {
            context.setWikiId(wiki);
            Collection<DocumentReference> groupReferences = groupService.getAllGroupsReferencesForMember(userOrGroupDocumentReference, 0, 0, context);
            tmpGroupList = new ArrayList<String>(groupReferences.size());
            for (DocumentReference groupReference : groupReferences) {
                tmpGroupList.add(this.entityReferenceSerializer.serialize(groupReference));
            }
        } catch (Exception e) {
            LOGGER.error("Failed to get groups for user or group [{}] in wiki [{}]", prefixedFullName, wiki, e);
            tmpGroupList = Collections.emptyList();
        } finally {
            context.setWikiId(currentWiki);
        }
        grouplistcache.put(key, tmpGroupList);
    }
    grouplist.addAll(tmpGroupList);
}
Also used : Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) XWikiRightNotFoundException(com.xpn.xwiki.user.api.XWikiRightNotFoundException) XWikiGroupService(com.xpn.xwiki.user.api.XWikiGroupService)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42