@Override public boolean exists() { return !doc.isNew(); }
public boolean isNew() { return doc.isNew(); }
/** * @return true if the document is a new one (ie it has never been saved) or false otherwise */ public boolean isNew() { return this.doc.isNew(); }
@Override public boolean exists() { return !parentDoc.isNew() && parentResource.getVirtualMembers().contains(this); }
/** * @return the syntax of the document * @since 2.3M1 */ public Syntax getSyntax() { // Can't be initialized in the XWikiDocument constructor because #getDefaultDocumentSyntax() need to create a // XWikiDocument object to get preferences from wiki preferences pages and would thus generate an infinite loop if (isNew() && this.syntax == null) { this.syntax = getDefaultDocumentSyntax(); } return this.syntax; }
/** * Get level right tree. * * @param doc the document containing rights preferences. * @param levelName the level right name ("view", "delete"...). * @param global indicate it is global rights (wiki or space) or document rights. * @param context the XWiki context. * @return the {@link LevelTree}. * @throws XWikiException error when browsing rights preferences. */ private LevelTree getLevel(XWikiDocument doc, String levelName, boolean global, XWikiContext context) throws XWikiException { if (doc.isNew()) { return null; } List<String> rights = new ArrayList<String>(); rights.add(levelName); Map<String, LevelTree> rightsMap = getLevelTreeMap(doc, rights, global, context); return rightsMap.get(levelName); }
@Override public E get(DocumentReference reference) { try { DocumentModelBridge document = this.bridge.getDocument(reference); if (document == null || ((XWikiDocument) document).isNew()) { return null; } return load(document); } catch (Exception ex) { this.logger.error("Failed to read document [{}]: {}", reference, ex.getMessage()); } return null; }
@Override public E get(DocumentReference reference) { try { DocumentModelBridge document = this.bridge.getDocument(reference); if (document == null || ((XWikiDocument) document).isNew()) { return null; } return load(document); } catch (Exception ex) { this.logger.error("Failed to read document [{}]: {}", reference, ex.getMessage()); } return null; }
/** * {@inheritDoc} * * @see XWikiAction#render(com.xpn.xwiki.XWikiContext) */ @Override public String render(XWikiContext context) throws XWikiException { if (context.getDoc().isNew()) { context.put("message", "nocommentwithnewdoc"); return "exception"; } return ""; }
/** * @param document the translation document */ private void translationDocumentUpdated(XWikiDocument document) { if (!document.getOriginalDocument().isNew()) { unregisterTranslationBundle(document.getOriginalDocument()); } if (!document.isNew()) { try { registerTranslationBundle(document); } catch (Exception e) { this.logger.error("Failed to register translation bundle from document [{}]", document.getDocumentReference(), e); } } }
public String getRawNotes(XWikiContext context) throws XWikiException { XWikiDocument noteDoc = context.getWiki().getDocument(doc.getSpace() + "." + PROJECT_NOTEDOC, context); if (!noteDoc.isNew()) { String stringNotes = (String) noteDoc.display("notes", context); return stringNotes; } else { return ""; } }
/** * Utility method for updating a wiki macro class definition document. * * @param doc xwiki document containing the wiki macro class. * @throws XWikiException if an error occurs while saving the document. */ private void update(XWikiDocument doc) throws Exception { XWikiContext xcontext = getContext(); if (doc.isNew()) { doc.setParent("XWiki.WebHome"); } xcontext.getWiki().saveDocument(doc, xcontext); } }
/** * Utility method for updating a wiki macro class definition document. * * @param doc xwiki document containing the wiki macro class. * @throws XWikiException if an error occurs while saving the document. */ private void update(XWikiDocument doc) throws Exception { XWikiContext xcontext = getContext(); if (doc.isNew()) { doc.setParent("XWiki.WebHome"); } xcontext.getWiki().saveDocument(doc, xcontext); } }
@Override public T getXObjectDocument(String itemName, int objectId, boolean validate, XWikiContext context) throws XWikiException { XWikiDocument doc = context.getWiki().getDocument(getItemDocumentDefaultFullName(itemName, context), context); if (doc.isNew() || !isInstance(doc)) { throw new XObjectDocumentDoesNotExistException(itemName + " object does not exist"); } return newXObjectDocument(doc, objectId, context); }
private void getProperties() { XWikiDocument doc = getGeneXClassDoc(); if (doc == null || doc.isNew()) { // Inaccessible or deleted document return; } BaseClass gene = doc.getXClass(); if (gene == null) { return; } StaticListClass statusProp = (StaticListClass) gene.get(STATUS_KEY); StaticListClass stategyProp = (StaticListClass) gene.get(STRATEGY_KEY); if (statusProp != null) { statusValues = statusProp.getList(this.context); } if (stategyProp != null) { strategyValues = stategyProp.getList(this.context); } }
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; }
/** * 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()); } }
protected void addUserToGroup(String userName, String groupName, XWikiContext context) throws XWikiException { BaseClass groupClass = getGroupClass(context); XWikiDocument groupDoc = getDocument(groupName, context); BaseObject memberObject = groupDoc.newXObject( this.localReferenceEntityReferenceSerializer.serialize(groupClass.getDocumentReference()), context); memberObject.setStringValue("member", userName); if (groupDoc.isNew()) { saveDocument(groupDoc, context.getMessageTool().get("core.comment.addedUserToGroup"), context); } else { // TODO Fix use of deprecated call. getHibernateStore().saveXWikiObject(memberObject, context, true); } try { XWikiGroupService gservice = getGroupService(context); gservice.addUserToGroup(userName, context.getDatabase(), groupName, context); } catch (Exception e) { LOG.error("Failed to update group service cache", e); } }
/** * Add a group from the request * @param context * @return */ public Group addGroup(XWikiContext context) throws XWikiException { XWikiRequest req = context.getRequest(); String name = req.get("XWiki.DirectoryGroupClass_0_name"); name = context.getWiki().clearName(name, context); XWikiDocument tmpDoc = context.getWiki().getDocument(DEFAULT_PLUGIN_SPACE, name, context); if (!tmpDoc.isNew()) throw new PluginException(UserDirectoryPlugin.class, ERROR_USERDIRECTORYPLUGIN_ALREADYEXIST, "This document already exist, try another name"); Document doc = tmpDoc.newDocument(context); doc.addObjectFromRequest("XWiki.DirectoryGroupClass"); doc.setContent(getTemplate(context)); doc.saveWithProgrammingRights(); return new Group(doc, context); }
public String inviteToGroup(String name, String firstName, String email, String group, XWikiContext context) throws XWikiException { String pageName = context.getWiki().convertUsername(email, context); XWikiUserManagementTools userTools = (XWikiUserManagementTools) context.getWiki().getPlugin("usermanagementtools", context); XWikiDocument doc = context.getWiki().getDocument(userTools.getUserSpace(context) + "." + pageName, context); if (doc.isNew()) { String userDocName = userTools.inviteUser(name, email, context); Document userDoc = context.getWiki().getDocument(userDocName, context).newDocument(context); userDoc.use("XWiki.XWikiUsers"); userDoc.set("first_name", firstName); userDoc.saveWithProgrammingRights(); } addUserToGroup(doc.getFullName(), group, context); return doc.getFullName(); }