use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class DocumentEventConverter method unserializeDeletdDocument.
private XWikiDocument unserializeDeletdDocument(Serializable remoteData, XWikiContext xcontext) throws XWikiException {
Map<String, Serializable> remoteDataMap = (Map<String, Serializable>) remoteData;
DocumentReference docReference = (DocumentReference) remoteDataMap.get(DOC_NAME);
XWikiDocument doc = new XWikiDocument(docReference);
XWikiDocument origDoc = new XWikiDocument(docReference);
// We have to get deleted document from the trash (hoping it is in the trash...)
XWiki xwiki = xcontext.getWiki();
XWikiRecycleBinStoreInterface store = xwiki.getRecycleBinStore();
XWikiDeletedDocument[] deletedDocuments = store.getAllDeletedDocuments(origDoc, xcontext, true);
if (deletedDocuments != null && deletedDocuments.length > 0) {
long index = deletedDocuments[0].getId();
origDoc = store.restoreFromRecycleBin(index, xcontext, true);
}
doc.setOriginalDocument(origDoc);
return doc;
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class DefaultAuthorExecutor method before.
@Override
public AutoCloseable before(DocumentReference authorReference) {
DefaultAuthorExecutorContext suContext;
XWikiContext xwikiContext = this.xcontextProvider.get();
if (xwikiContext != null) {
suContext = new DefaultAuthorExecutorContext();
// Make sure to have the right secure document
suContext.currentSecureDocument = (XWikiDocument) xwikiContext.get(XWikiDocument.CKEY_SDOC);
XWikiDocument secureDocument = new XWikiDocument(new DocumentReference(authorReference != null ? authorReference.getWikiReference().getName() : "xwiki", "SUSpace", "SUPage"));
secureDocument.setContentAuthorReference(authorReference);
secureDocument.setAuthorReference(authorReference);
secureDocument.setCreatorReference(authorReference);
xwikiContext.put(XWikiDocument.CKEY_SDOC, secureDocument);
// Make sure to disable XWikiContext#dropPermission hack
suContext.xwikiContextDropPermissionHack = xwikiContext.remove(XWikiConstant.DROPPED_PERMISSIONS);
// Make sure to disable Document#dropPermission hack
ExecutionContext econtext = this.execution.getContext();
if (econtext != null) {
suContext.documentDropPermissionHack = econtext.getProperty(XWikiConstant.DROPPED_PERMISSIONS);
econtext.removeProperty(XWikiConstant.DROPPED_PERMISSIONS);
}
} else {
suContext = null;
}
return suContext;
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class UserIterator method serializeUserAndGroupReferences.
private String serializeUserAndGroupReferences() {
StringBuilder buffer = new StringBuilder();
Iterator<DocumentReference> iterator = this.userAndGroupReferences.iterator();
while (iterator.hasNext()) {
DocumentReference reference = iterator.next();
buffer.append('[').append(reference).append(']');
if (iterator.hasNext()) {
buffer.append(',').append(' ');
}
}
return buffer.toString();
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class CommentSaveAction method action.
@Override
public boolean action(XWikiContext context) throws XWikiException {
// Get the XWiki utilities
XWiki xwiki = context.getWiki();
XWikiResponse response = context.getResponse();
XWikiRequest request = context.getRequest();
XWikiDocument doc = context.getDoc();
if (!csrfTokenCheck(context) || doc.isNew()) {
return false;
}
// Comment class reference
DocumentReference commentClass = new DocumentReference(context.getWikiId(), XWiki.SYSTEM_SPACE, XWikiDocument.COMMENTSCLASS_REFERENCE.getName());
// Edit comment
int commentId = getCommentIdFromRequest(request);
BaseObject commentObj = doc.getXObject(commentClass, commentId);
if (commentObj == null) {
return false;
}
// Check if the author is the current user or if the current user has the ADMIN right
String commentAuthor = commentObj.getStringValue("author");
DocumentReference authorReference = documentReferenceResolver.resolve(commentAuthor);
if (!authorReference.equals(context.getUserReference()) && !authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), context.getDoc().getDocumentReference())) {
return false;
}
// Edit the comment
commentObj.set(COMMENT_FIELD_NAME, request.getParameter(String.format("XWiki.XWikiComments_%d_comment", commentId)), context);
// Save it
xwiki.saveDocument(doc, localizationManager.getTranslationPlain("core.comment.editComment"), true, context);
// If xpage is specified then allow the specified template to be parsed.
if (context.getRequest().get("xpage") != null) {
return true;
}
// forward to edit
String redirect = Utils.getRedirect("edit", context);
sendRedirect(response, redirect);
return false;
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class CreateAction method doCreate.
/**
* Actually executes the create, after all preconditions have been verified.
*
* @param context the context of this action
* @param newDocument the document to be created
* @param isSpace whether the document is a space webhome or a page
* @param templateProvider the template provider to create from
* @throws XWikiException in case anything goes wrong accessing xwiki documents
*/
private void doCreate(XWikiContext context, XWikiDocument newDocument, boolean isSpace, BaseObject templateProvider) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiDocument doc = context.getDoc();
// resolver to use to resolve references received in request parameters
DocumentReferenceResolver<String> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, CURRENT_MIXED_RESOLVER_HINT);
String parent = getParent(request, doc, isSpace, context);
// get the title of the page to create, as specified in the parameters
String title = getTitle(request, newDocument, isSpace);
// get the template from the template parameter, to allow creation directly from template, without
// forcing to create a template provider for each template creation
String template = getTemplate(templateProvider, request);
// from the template provider, find out if the document should be saved before edited
boolean toSave = getSaveBeforeEdit(templateProvider);
String redirectParams = null;
String editMode = null;
if (toSave) {
XWiki xwiki = context.getWiki();
DocumentReference templateReference = resolver.resolve(template);
newDocument.readFromTemplate(templateReference, context);
if (!StringUtils.isEmpty(parent)) {
DocumentReference parentReference = resolver.resolve(parent);
newDocument.setParentReference(parentReference);
}
if (title != null) {
newDocument.setTitle(title);
}
DocumentReference currentUserReference = context.getUserReference();
newDocument.setAuthorReference(currentUserReference);
newDocument.setCreatorReference(currentUserReference);
xwiki.saveDocument(newDocument, context);
editMode = newDocument.getDefaultEditMode(context);
} else {
// put all the data in the redirect params, to be passed to the edit mode
redirectParams = getRedirectParameters(parent, title, template);
// Get the edit mode of the document to create from the specified template
editMode = getEditMode(template, resolver, context);
}
// Perform a redirection to the edit mode of the new document
String redirectURL = newDocument.getURL(editMode, redirectParams, context);
redirectURL = context.getResponse().encodeRedirectURL(redirectURL);
if (context.getRequest().getParameterMap().containsKey("ajax")) {
// If this template is displayed from a modal popup, send a header in the response notifying that a
// redirect must be performed in the calling page.
context.getResponse().setHeader("redirect", redirectURL);
} else {
// Perform the redirect
sendRedirect(context.getResponse(), redirectURL);
}
}
Aggregations