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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations