/** * @deprecated since 2.2M1 use {@link #getXObject()} instead */ @Deprecated public BaseObject getxWikiObject() { return getXObject(getDocumentReference()); }
/** * @param source an xwiki document, that has just been updated. * @return true if and only if the xwiki document corresponds to a group. */ private boolean isGroupDocument(Object source) { XWikiDocument doc = (XWikiDocument) source; DocumentReference docRef = doc.getDocumentReference(); DocumentReference groupClass = resolver.resolve(XWikiConstants.GROUP_CLASS, docRef); List<BaseObject> objects = doc.getXObjects(groupClass); return objects != null && objects.size() > 0; }
@Override public boolean exists() { return !doc.isNew(); }
public String getTranslatedContent(String language, XWikiContext context) throws XWikiException { XWikiDocument tdoc = getTranslatedDocument(language, context); return tdoc.getContent(); }
/** * @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; }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue(OWNER, doc.getCreatorReference().toString()); } else { ownerObject.setStringValue(OWNER, ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for entity [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } } }
private void initialize(XWikiDocument editorDocument) throws WikiComponentException { this.authorReference = editorDocument.getAuthorReference(); BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE); if (editorObject != null) { initialize(editorObject); } else { throw new WikiComponentException(String.format( "The document [%s] is missing the XWiki.EditorClass object.", editorDocument.getDocumentReference())); } }
/** * @return the document's space + page name (eg "space.page") * @deprecated since 2.2M1 use {@link #getDocumentReference()} instead */ @Deprecated public String getFullName() { return this.localEntityReferenceSerializer.serialize(getDocumentReference()); }
@Override public PatientData<String> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); Map<String, String> result = new LinkedHashMap<>(); DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); result.put(DOCUMENT_NAME, doc.getDocumentReference().getName()); result.put(CREATION_DATE, dateFormatter.print(new DateTime(doc.getCreationDate()))); result.put(AUTHOR, (doc.getAuthorReference() != null) ? doc.getAuthorReference().getName() : UNKNOWN_USER); result.put(DATE, dateFormatter.print(new DateTime(doc.getDate()))); return new DictionaryPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
/** * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. * * @deprecated since 3.0M3 use {@link #getAuthorReference()} instead */ @Deprecated public String getAuthor() { String author; DocumentReference authorReference = getAuthorReference(); if (authorReference == null) { author = ""; } else { author = this.compactWikiEntityReferenceSerializer.serialize(authorReference, getDocumentReference()); } return author; }
/** * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. * * @deprecated since 3.0M3 use {@link #setAuthorReference} instead */ @Deprecated public void setAuthor(String author) { // Note: Consider "" or null as the same, i.e. the author not being set DocumentReference authorReference = null; if (author != null && author.length() > 0) { authorReference = this.explicitReferenceDocumentReferenceResolver.resolve( this.xClassEntityReferenceResolver.resolve(author, EntityType.DOCUMENT), getDocumentReference()); } if ((getAuthorReference() == null && authorReference != null) || (getAuthorReference() != null && !getAuthorReference().equals(authorReference))) { setMetaDataDirty(true); } setAuthorReference(authorReference); }
/** Either gets the existing consents holder object, or creates a new one. */ private BaseObject getXWikiConsentHolder(XWikiDocument doc) throws XWikiException { BaseObject holder = doc.getXObject(this.consentIdsHolderReference); if (holder == null) { holder = doc.newXObject(this.consentIdsHolderReference, this.contextProvider.get()); } return holder; }
/** * @since 2.2M1 */ public BaseObject getXObject(DocumentReference classReference, int nb) { try { return getXObjects().get(classReference).get(nb); } catch (Exception e) { return null; } }
/** * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. * * @deprecated since 3.0M2 use {@link #setCreatorReference} instead */ @Deprecated public void setCreator(String creator) { // Note: Consider "" or null as the same, i.e. the creator not being set DocumentReference creatorReference = null; if (creator != null && creator.length() > 0) { creatorReference = this.explicitReferenceDocumentReferenceResolver.resolve( this.xClassEntityReferenceResolver.resolve(creator, EntityType.DOCUMENT), getDocumentReference()); } if ((getCreatorReference() == null && creatorReference != null) || (getCreatorReference() != null && !getCreatorReference().equals(creatorReference))) { setMetaDataDirty(true); } setCreatorReference(creatorReference); }
/** * @since 2.2M1 */ public BaseObject getXObject(DocumentReference classReference, String key, String value) { return getXObject(classReference, key, value, false); }
private void setDescriptorDocMetadata(XWikiDocument descriptorDoc) { XWikiContext context = xcontextProvider.get(); // Set the document as hidden descriptorDoc.setHidden(true); // The document must have a creator if (descriptorDoc.getCreatorReference() == null) { descriptorDoc.setCreatorReference(context.getUserReference()); } // The document must have an author if (descriptorDoc.getAuthorReference() == null) { descriptorDoc.setAuthorReference(context.getUserReference()); } // Set the document parent if (descriptorDoc.getParentReference() == null) { EntityReference parentReference = new EntityReference("WebHome", EntityType.DOCUMENT); parentReference.appendParent(new EntityReference("WikiManager", EntityType.SPACE)); descriptorDoc.setParentReference(parentReference); } } }
/** * @deprecated since 2.2M2 use {@link #newXObject(EntityReference, XWikiContext)} */ @Deprecated public BaseObject newObject(String className, XWikiContext context) throws XWikiException { return newXObject( this.xClassEntityReferenceResolver.resolve(className, EntityType.DOCUMENT, getDocumentReference()), context); }
private void saveGroupDocument(XWikiDocument document, String message) throws WikiUserManagerException { // Get the XWiki objects XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); // The document should be hidden document.setHidden(true); // The document must have a creator if (document.getCreatorReference() == null) { document.setCreatorReference(xcontext.getUserReference()); } // The document must have an author if (document.getAuthorReference() == null) { document.setAuthorReference(xcontext.getUserReference()); } // Save the document try { xwiki.saveDocument(document, message, xcontext); } catch (XWikiException e) { throw new WikiUserManagerException("Fail to save the member group", e); } }
@Override public void setProperty( @Nonnull final XWikiDocument doc, @Nullable final DocumentReference classReference, @Nullable final String propertyName, @Nullable final Object propertyValue) { XWikiContext xcontext = this.xcontextProvider.get(); BaseObject obj = doc.getXObject(classReference, true, xcontext); if (obj != null) { obj.set(propertyName, propertyValue, xcontext); doc.setAuthorReference(getCurrentUser()); doc.setMetaDataDirty(true); } } }
/** * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. * * @deprecated since 3.0M2 use {@link #getCreatorReference()} instead */ @Deprecated public String getCreator() { String creator; DocumentReference creatorReference = getCreatorReference(); if (creatorReference == null) { creator = ""; } else { creator = this.compactWikiEntityReferenceSerializer.serialize(creatorReference, getDocumentReference()); } return creator; }