/** * Set cleaner common documents fields. * * @param doc document to modify * @return true if the fields have been modified, false otherwise */ private boolean setCleanerCommonDocumentsFields(XWikiDocument doc) { boolean needsUpdate = false; if (StringUtils.isBlank(doc.getAuthor())) { needsUpdate = true; doc.setAuthor(XWIKI_DEFAULT_ADMIN); } if (StringUtils.isBlank(doc.getCreator())) { needsUpdate = true; doc.setCreator(XWIKI_DEFAULT_ADMIN); } if (StringUtils.isBlank(doc.getParent())) { needsUpdate = true; doc.setParent("Scheduler.WebHome"); } return needsUpdate; }
private boolean setWikiMacroClassesDocumentFields(XWikiDocument doc, String title) { boolean needsUpdate = false; if (StringUtils.isBlank(doc.getCreator())) { needsUpdate = true; doc.setCreator(XWikiRightService.SUPERADMIN_USER); } if (StringUtils.isBlank(doc.getAuthor())) { needsUpdate = true; doc.setAuthorReference(doc.getCreatorReference()); } if (StringUtils.isBlank(doc.getParent())) { needsUpdate = true; doc.setParent("XWiki.XWikiClasses"); } if (StringUtils.isBlank(doc.getTitle())) { needsUpdate = true; doc.setTitle(title); } if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) { needsUpdate = true; doc.setContent("{{include document=\"XWiki.ClassSheet\" /}}"); doc.setSyntax(Syntax.XWIKI_2_0); } return needsUpdate; }
doc.setCreator(XWikiRightService.SUPERADMIN_USER);
protected void saveDocument(String comment, boolean minorEdit) throws XWikiException { XWikiDocument doc = getDoc(); doc.setAuthor(this.context.getUser()); if (doc.isNew()) { doc.setCreator(this.context.getUser()); } getXWikiContext().getWiki().saveDocument(doc, comment, minorEdit, getXWikiContext()); this.cloned = false; }
doc.setCreator(xwikiContext.getUser());
/** * Utility method for saving an {@link XWikiDocument}. This method takes care of setting authors and creators * appropriately. * * @param doc the {@link XWikiDocument} to be saved. * @param comment the edit comment. * @param isMinorEdit if the change in document is minor. * @throws Exception if an error occurs while saving the document. */ private void saveDocument(XWikiDocument doc, String comment, boolean isMinorEdit) throws Exception { doc.setAuthor(getCurrentUser()); if (doc.isNew()) { doc.setCreator(getCurrentUser()); } getContext().getWiki().saveDocument(doc, comment, isMinorEdit, getContext()); } }
@Override public Boolean deleteObject(String docName, String className, int number) throws XWikiGWTException { try { XWikiContext context = getXWikiContext(); if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docName, context)) { XWikiDocument doc = context.getWiki().getDocument(docName, context); BaseObject bObj = doc.getObject(className, number); if (!doc.removeObject(bObj)) return Boolean.valueOf(false); doc.setAuthor(context.getUser()); if (doc.isNew()) doc.setCreator(context.getUser()); context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.deleteObject"), context); return Boolean.valueOf(true); } else { return Boolean.valueOf(false); } } catch (Exception e) { throw getXWikiGWTException(e); } }
/** * save only the content of a document TODO manage translations * * @param fullName * @param content * @return */ public Boolean saveDocumentContent(String fullName, String content, String comment) throws XWikiGWTException { try { XWikiContext context = getXWikiContext(); if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), fullName, context)) { XWikiDocument doc = context.getWiki().getDocument(fullName, context); doc.setContent(content); doc.setAuthor(context.getUser()); if (doc.isNew()) doc.setCreator(context.getUser()); context.getWiki().saveDocument(doc, (comment == null) ? localizePlainOrKey("core.comment.updateContent") : comment, context); return Boolean.valueOf(true); } else { return Boolean.valueOf(false); } } catch (Exception e) { throw getXWikiGWTException(e); } }
XWikiRightService.SUPERADMIN_USER_FULLNAME, context); document.setCreator(feedEntryCreator); document.setAuthor(feedEntryCreator); document.setContentAuthor(feedEntryCreator);
doc.setCreator(XWikiRightService.SUPERADMIN_USER);
/** * {@inheritDoc} * * @see DocumentAccessBridge#setAttachmentContent(String, String, byte[]) */ @Deprecated public void setAttachmentContent(String documentReference, String attachmentFilename, byte[] attachmentData) throws Exception { XWikiContext xcontext = getContext(); XWikiDocument doc = xcontext.getWiki().getDocument(documentReference, xcontext); XWikiAttachment attachment = doc.getAttachment(attachmentFilename); if (attachment == null) { attachment = new XWikiAttachment(); doc.getAttachmentList().add(attachment); doc.setComment("Add new attachment " + attachmentFilename); } else { doc.setComment("Update attachment " + attachmentFilename); } attachment.setContent(attachmentData); attachment.setFilename(attachmentFilename); attachment.setAuthor(getCurrentUser()); attachment.setDoc(doc); doc.setAuthor(getCurrentUser()); if (doc.isNew()) { doc.setCreator(getCurrentUser()); } doc.saveAttachmentContent(attachment, xcontext); }
if ((getCreator().equals(context.getUser())) || (context.getWiki().getRightService().hasAdminRights(context))) { setCreator(creator);
doc.setCreator(CLASS_AUTHOR);
@Override public Boolean saveObject(XObject object) throws XWikiGWTException { try { XWikiContext context = getXWikiContext(); if (context.getWiki().getRightService() .hasAccessLevel("edit", context.getUser(), object.getName(), context)) { XWikiDocument doc = context.getWiki().getDocument(object.getName(), context); BaseObject bObject = newBaseObject(doc.getObject(object.getClassName(), object.getNumber()), object, context); doc.setObject(object.getClassName(), object.getNumber(), bObject); doc.setAuthor(context.getUser()); if (doc.isNew()) doc.setCreator(context.getUser()); context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateObject"), context); return Boolean.valueOf(true); } else { return Boolean.valueOf(false); } } catch (Exception e) { throw getXWikiGWTException(e); } }
template.setCreator(XWikiRightService.SUPERADMIN_USER); template.setAuthor(template.getCreator()); List<String> args = new ArrayList<String>(1);
public String addProjectContainer(String type, String parent, String name, String desc, String style, XWikiContext context) throws XWikiException { String uid = getNewProjectContainerUid(context); XWikiDocument containerDoc = context.getWiki().getDocument(FOLDERS_SPACE + "." + uid, context); BaseObject obj = containerDoc.newObject(CLASS_FOLDER, context); obj.set("uid", uid, context); obj.set("name", name, context); obj.set("style", style, context); obj.set("desc", desc, context); obj.set("parent", parent, context); containerDoc.setParent(parent); containerDoc.setCreator(context.getUser()); if (type == null || type.equals("")) { obj.set("type", FOLDERS_ROOT, context); } else { obj.set("type", type, context); } int indexMax = getLastProjectContainerIndex(parent, context) + 1; obj.set("order", indexMax, context); context.getWiki().saveDocument(containerDoc, context); this.flushFoldersCache(); return uid; }
public LDAPProfileXClass(XWikiContext context) throws XWikiException { this.context = context; XWikiDocument ldapClassDoc = context.getWiki().getDocument(LDAPPROFILECLASS_REFERENCE, context); this.ldapClass = ldapClassDoc.getXClass(); boolean needsUpdate = this.ldapClass.addTextField(LDAP_XFIELD_DN, LDAP_XFIELDPN_DN, 80); needsUpdate |= this.ldapClass.addTextField(LDAP_XFIELD_UID, LDAP_XFIELDPN_UID, 80); if (ldapClassDoc.getCreatorReference() == null) { needsUpdate = true; ldapClassDoc.setCreator(XWikiRightService.SUPERADMIN_USER); } if (ldapClassDoc.getAuthorReference() == null) { needsUpdate = true; ldapClassDoc.setAuthorReference(ldapClassDoc.getCreatorReference()); } if (!ldapClassDoc.isHidden()) { needsUpdate = true; ldapClassDoc.setHidden(true); } if (needsUpdate) { context.getWiki().saveDocument(ldapClassDoc, "Update LDAP user profile class", context); } }
/** * {@inheritDoc} * * @see org.xwiki.bridge.DocumentAccessBridge#setAttachmentContent(org.xwiki.model.reference.AttachmentReference, * byte[]) */ public void setAttachmentContent(AttachmentReference attachmentReference, byte[] attachmentData) throws Exception { XWikiContext xcontext = getContext(); XWikiDocument doc = xcontext.getWiki().getDocument(attachmentReference.getDocumentReference(), xcontext); XWikiAttachment attachment = doc.getAttachment(attachmentReference.getName()); if (attachment == null) { attachment = new XWikiAttachment(); doc.getAttachmentList().add(attachment); doc.setComment("Add new attachment " + attachmentReference.getName()); } else { doc.setComment("Update attachment " + attachmentReference.getName()); } attachment.setContent(attachmentData); attachment.setFilename(attachmentReference.getName()); attachment.setAuthor(getCurrentUser()); attachment.setDoc(doc); doc.setAuthor(getCurrentUser()); if (doc.isNew()) { doc.setCreator(getCurrentUser()); } doc.saveAttachmentContent(attachment, xcontext); }
} catch (Exception e) { doc = new XWikiDocument(new DocumentReference(context.getWikiId(), getClassSpace(), getClassName())); doc.setCreator(XWikiRightService.SUPERADMIN_USER); doc.setAuthor(doc.getCreator()); needsUpdate = true;
bobj.set("start", "", context); bobj.set("end", "", context); homeDoc.setCreator(context.getUser()); context.getWiki().saveDocument(homeDoc, context); ProjectApi newProject = new ProjectApi(new Project(homeDoc, plugin, context), context);