Class Document
- java.lang.Object
-
- com.xpn.xwiki.api.Api
-
- com.xpn.xwiki.api.Document
-
public class Document extends Api
This class represents a document or page in the wiki. This is a security and usability wrapper which wrapsXWikiDocument
In scripting, an object representing the document in which the script resides will be bound to a variable called doc.- Version:
- $Id: 140824b7df59c3f3df8ec0c34eea9b7cf9f5f48f $
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
currentObj
Convenience object used by object related methods.protected XWikiDocument
doc
The XWikiDocument object wrapped by this API.protected XWikiDocument
initialDoc
The XWikiDocument object wrapped by this API.
-
Constructor Summary
Constructors Constructor Description Document(XWikiDocument doc, XWikiContext context)
Document constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Attachment
addAttachment(String fileName, byte[] data)
Attachment
addAttachment(String fileName, InputStream iStream)
int
addAttachments()
int
addAttachments(String fieldName)
Object
addObjectFromRequest()
Object
addObjectFromRequest(String className)
Object
addObjectFromRequest(String className, String prefix)
List<Object>
addObjectsFromRequest(String className)
List<Object>
addObjectsFromRequest(String className, String prefix)
boolean
checkAccess(String right)
boolean
convertSyntax(String targetSyntaxId)
Convert the current document content from its current syntax to the new syntax passed as parameter.int
createNewObject(String classname)
Creates a New XWiki Object of the given classnamevoid
delete()
void
deleteAsAuthor()
Delete the document if thecontent author
of the script calling this method has permission to do so.protected void
deleteDocument()
Remove document from the wiki.void
deleteWithProgrammingRights()
String
display(String fieldname)
Displays the given field.String
display(String fieldname, Object obj)
Displays the given field of the given object The display mode will be decided depending on page context (edit or inline context will display in edit, view context in view) This function can return html inside and html macroString
display(String fieldname, String mode)
Displays the given field in the given mode.String
display(String fieldname, String mode, Object obj)
Displays the given field of the given object in the given mode.String
display(String fieldname, String type, Object obj, String wrappingSyntaxId)
Displays the given field of the given object using the given mode and syntax rendering The display mode will be decided depending on page context (edit or inline context will display in edit, view context in view) This function can return html inside and html macroString
display(String fieldname, String mode, String prefix)
Displays the given field in the given mode.String
display(String fieldname, String mode, String prefix, Object obj)
Displays the given field of the given object in the given mode.String
displayDocument()
String
displayDocument(boolean restricted)
String
displayDocument(org.xwiki.rendering.syntax.Syntax targetSyntax)
String
displayDocument(org.xwiki.rendering.syntax.Syntax targetSyntax, boolean restricted)
String
displayEdit(PropertyClass pclass, String prefix, Collection object)
String
displayForm(String className)
String
displayForm(String className, String header, String format)
String
displayForm(String className, String header, String format, boolean linebreak)
String
displayHidden(PropertyClass pclass, String prefix, Collection object)
String
displayPrettyName(String fieldname)
Displays the pretty name of the given field.String
displayPrettyName(String fieldname, boolean showMandatory)
Displays the pretty name of the given field.String
displayPrettyName(String fieldname, boolean showMandatory, boolean before)
Displays the pretty name of the given field.String
displayPrettyName(String fieldname, boolean showMandatory, boolean before, Object obj)
Displays the pretty name of the given field of the given object.String
displayPrettyName(String fieldname, boolean showMandatory, Object obj)
Displays the pretty name of the given field of the given object.String
displayPrettyName(String fieldname, Object obj)
Displays the pretty name of the given field of the given object.String
displayRendered(PropertyClass pclass, String prefix, Collection object)
String
displayTooltip(String fieldname)
Displays the tooltip of the given field.String
displayTooltip(String fieldname, Object obj)
Displays the tooltip of the given field of the given object.String
displayView(PropertyClass pclass, String prefix, Collection object)
void
dropPermissions()
Drop permissions for the remainder of the rendering cycle.boolean
equals(Object arg0)
Object
get(String classOrFieldName)
Renders the passed xproperty as HTML.String
getActiveClass()
String
getArchive()
Attachment
getAttachment(String filename)
List<AttachmentDiff>
getAttachmentDiff(Document origdoc, Document newdoc)
List<Attachment>
getAttachmentList()
String
getAttachmentRevisionURL(String filename, String version)
Get an old revision of an attachment.String
getAttachmentRevisionURL(String filename, String version, String queryString)
Get an old revision of an attachment.String
getAttachmentURL(String filename)
Return the relative URL of download for the the given attachment name.String
getAttachmentURL(String filename, String action)
Get the relative URL of the given action for the the given attachment name.String
getAttachmentURL(String filename, String action, String queryString)
Get the relative URL of an action on an attachment.String
getAuthor()
Get fullName of the profile document of the author of the current version of the document.DocumentReference
getAuthorReference()
DocumentAuthors
getAuthors()
List<DocumentReference>
getBackLinkedReferences()
Retrieve the references of the page containing a link to the current page.List<String>
getBacklinks()
List<String>
getChildren()
Get document children.List<String>
getChildren(int nb, int start)
Get document children.List<DocumentReference>
getChildrenReferences()
Get document children references.List<List<ObjectDiff>>
getClassDiff(Document origdoc, Document newdoc)
String
getComment()
Vector<Object>
getComments()
Vector<Object>
getComments(boolean asc)
String
getContent()
Get raw content of the document, i.e.String
getContentAuthor()
Get fullName of the profile document of the author of the content modification of this document version.DocumentReference
getContentAuthorReference()
List<org.suigeneris.jrcs.diff.delta.Delta>
getContentDiff(Document origdoc, Document newdoc)
Date
getContentUpdateDate()
Get the date when the content modification has been done on this document version.Date
getCreationDate()
String
getCreator()
Get fullName of the profile document of the document creator.DocumentReference
getCreatorReference()
DocumentStats
getCurrentMonthPageStats(String action)
Get statistics about the number of request for the current page during the current month.List<RefererStats>
getCurrentMonthRefStats()
Get referer statistics for the current document during the current month.DocumentStats
getCurrentMonthSpaceStats(String action)
Get statistics about the number of request for the current space during the current month.Date
getDate()
String
getDefaultEditMode()
Gets the default edit mode for this document.String
getDefaultEditURL()
String
getDefaultLanguage()
Deprecated.since 8.0M1, usegetDefaultLocale()
insteadLocale
getDefaultLocale()
String
getDefaultTemplate()
TODO document this or mark it deprecatedString
getDisplayTitle()
Get document title.protected XWikiDocument
getDoc()
Get a clone of the XWikiDocument wrapped by this API.XWikiDocument
getDocument()
Get the XWikiDocument wrapped by this API.XWikiDocumentArchive
getDocumentArchive()
Get the archive of this document's history.DocumentReference
getDocumentReference()
returns the DocumentReference for the current documentDocumentReference
getDocumentReferenceWithLocale()
Document
getDocumentRevision(String revision)
Allow to easily access any revision of a documentString
getEditURL(String action, String mode)
String
getEditURL(String action, String mode, String locale)
String
getEscapedContent()
Get the document's content XML-escaped.String
getExternalURL()
Get the external URL to do a given action on this document.String
getExternalURL(String action)
Get the external URL to do a given action on this document.String
getExternalURL(String action, String queryString)
Get the URL to do a given action on this document.Object
getFirstObject(String fieldname)
Get the first object that contains the given fieldnameString
getFormat()
TODO document this or mark it deprecatedString
getFullName()
Get the fullName of the document.long
getId()
return the ID of the document.List<String>
getIncludedMacros()
List<String>
getIncludedPages()
String
getLanguage()
Deprecated.since 5.4M1 usegetLocale()
insteadList<org.suigeneris.jrcs.diff.delta.Delta>
getLastChanges()
List<String>
getLinkedPages()
List<XWikiLink>
getLinks()
Locale
getLocale()
Get the locale of the document.int
getLocalReferenceMaxLength()
boolean
getLocked()
Date
getLockingDate()
String
getLockingUser()
List<MetaDataDiff>
getMetaDataDiff(Document origdoc, Document newdoc)
String
getName()
Deprecated.since 11.0, usegetDocumentReference()
insteadObject
getObject(String classname)
Get the first object matching the given classnameObject
getObject(String classname, boolean create)
get the object of the given className.Object
getObject(String classname, int nb)
Get the object matching the given classname and given object numberObject
getObject(String classname, String key, String value)
Get the first object of a given classname that has a field name matching the given value When none found this method will return nullObject
getObject(String classname, String key, String value, boolean failover)
Get the first object of a given classname that has a field name matching the given valueObject
getObject(ObjectReference objectReference)
Object
getObject(ObjectReference objectReference, boolean create)
List<List<ObjectDiff>>
getObjectDiff(Document origdoc, Document newdoc)
int
getObjectNumbers(String classname)
Vector<Object>
getObjects(String className)
Get the list of objects for a given classname classnameVector<Object>
getObjects(String classname, String key, String value)
Select a subset of objects from a given class, filtered on a "key = value" criteria.PageReference
getPageReference()
PageReference
getPageReferenceWithLocale()
String
getParent()
Get the name of the parent of this document.DocumentReference
getParentReference()
String
getParentURL()
String
getPlainTitle()
Returns the document title as plain textString
getPrefixedFullName()
Get the complete fullName of the document.Document
getPreviousDocument()
Allow to easily access the previous revision of a documentString
getPreviousVersion()
Get a string representing the previous version of the document.org.suigeneris.jrcs.rcs.Version
getRCSVersion()
Get a Version object representing the current version of the document.String
getRealLanguage()
Deprecated.since 8.0M1, usegetRealLocale()
insteadLocale
getRealLocale()
Gets the real locale of the document.String[]
getRecentRevisions()
String[]
getRecentRevisions(int nb)
String
getRenderedContent()
String
getRenderedContent(boolean transformationContextIsolated)
Execute and render the document in the current context.String
getRenderedContent(String text)
Deprecated.since 1.6M1 usegetRenderedContent(String, String)
String
getRenderedContent(String text, String syntaxId)
String
getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId)
String
getRenderedContent(org.xwiki.rendering.syntax.Syntax targetSyntax)
List<org.suigeneris.jrcs.diff.delta.Delta>
getRenderedContentDiff(Document origdoc, Document newdoc)
String
getRenderedContentRestricted(String text, String syntaxId)
Render a text in a restricted mode, where script macros are completely disabled.String
getRenderedTitle(String syntaxId)
Returns the title of the document rendered through wiki syntax and velocityRevisionInfo
getRevisionInfo(String version)
Get information about a document version : author, date, etc.org.suigeneris.jrcs.rcs.Version[]
getRevisions()
List<String>
getRevisions(RevisionCriteria criteria)
Get document versions matching criterias like author, minimum creation date, etc.List<DocumentSection>
getSections()
Get the top sections contained in the document.String
getSpace()
Return the full local space reference of the Document.org.xwiki.rendering.syntax.Syntax
getSyntax()
String
getSyntaxId()
Deprecated.since 2.3M1 usegetSyntax()
insteadList<String>
getTagList()
String
getTags()
List<String>
getTagsPossibleValues()
String
getTemplate()
TODO document this or mark it deprecatedString
getTextArea()
String
getTitle()
Get the value of the title field of the document.Map<String,Map<String,Object>>
getTOC(int init, int max, boolean numbered)
Returns data needed for a generation of Table of Content for this document.String
getTranslatedContent()
String
getTranslatedContent(String locale)
Document
getTranslatedDocument()
Document
getTranslatedDocument(String locale)
List<Locale>
getTranslationLocales()
String
getURL()
Get the URL of this document.String
getURL(String action)
Get the URL to do a given action on this document.String
getURL(String action, String queryString)
Get the URL to do a given action on this document.String
getValidationScript()
Retrieves the validation script associated with this document, a Velocity script that is executed when validating the document data.Object
getValue(String fieldName)
Object
getValue(String fieldName, Object object)
String
getVersion()
Get a string representing the current version of the document.String
getVersionHashCode()
String
getWiki()
Get the name wiki where the document is stored.org.xwiki.rendering.block.XDOM
getXDOM()
NOTE: This method caches the XDOM and returns a clone that can be safely modified.String
getXMLContent()
List<org.suigeneris.jrcs.diff.delta.Delta>
getXMLDiff(Document origdoc, Document newdoc)
protected Vector<Object>
getXObjects(List<BaseObject> objects)
Class
getxWikiClass()
Class[]
getxWikiClasses()
Map<String,Vector<Object>>
getxWikiObjects()
Get the list of all objects available in this document organized in a Map by classnameboolean
hasAccess(Right right)
Verifies if the context user has the access identified byright
on the current context document.boolean
hasAccess(Right right, DocumentReference userReference)
Verifies if the user identified byuserReference
has the access identified byright
on this document.boolean
hasAccessLevel(String level)
boolean
hasAccessLevel(String level, String user)
Check if the current user has an access level on a given document.void
insertText(String text, String marker)
boolean
isAdvancedContent()
boolean
isCreator(String username)
boolean
isCurrentLocalUserPage()
boolean
isCurrentUserCreator()
boolean
isCurrentUserPage()
boolean
isFromCache()
boolean
isHidden()
Indicates whether the document is 'hidden' or not, meaning that it should not be returned in public search results or appear in the User Interface in general.boolean
isMinorEdit()
boolean
isMostRecent()
boolean
isNew()
boolean
isProgrammaticContent()
boolean
isRestricted()
boolean
isTranslation()
Object
newObject(String classname)
Creates a New XWiki Object of the given classnameboolean
removeObject(Object object)
Remove an XObject from the document.boolean
removeObjects(String className)
Remove all the objects of a given type (XClass) from the document.void
rename(String newDocumentName, List<String> backlinkDocumentNames)
Rename the current document and all the links pointing to it in the list of passed backlink documents.void
rename(String newDocumentName, List<String> backlinkDocumentNames, List<String> childDocumentNames)
Same asrename(String, List)
but the list of documents having the current document as their parent is passed in parameter.void
rename(DocumentReference newReference)
Rename the current document and all the backlinks leading to it.void
rename(DocumentReference newReference, List<DocumentReference> backlinkDocumentNames, List<DocumentReference> childDocumentNames)
Same asrename(String, List)
but the list of documents having the current document as their parent is passed in parameter.boolean
same(XWikiDocument document)
Check if the passed one is the one wrapped by thisDocument
.void
save()
void
save(String comment)
void
save(String comment, boolean minorEdit)
void
saveAsAuthor()
Save the document if the current author of the script calling this method has permission to do so.void
saveAsAuthor(String comment)
Save the document if the current author of the script calling this method has permission to do so.void
saveAsAuthor(String comment, boolean minorEdit)
Save the document if the current author of the script calling this method has permission to do so.protected void
saveDocument(String comment, boolean minorEdit)
void
saveWithProgrammingRights()
void
saveWithProgrammingRights(String comment)
void
saveWithProgrammingRights(String comment, boolean minorEdit)
void
set(String fieldname, Object value)
void
set(String fieldname, Object value, Object obj)
void
setComment(String comment)
void
setContent(String content)
void
setContent(org.xwiki.rendering.block.XDOM content)
void
setCustomClass(String customClass)
void
setDefaultLocale(Locale defaultLocale)
void
setDefaultTemplate(String dtemplate)
void
setHidden(boolean hidden)
Indicates whether the document should be 'hidden' or not, meaning that it should not be returned in public search results or appear in the User Interface in general.void
setMinorEdit(boolean isMinor)
void
setParent(String parent)
void
setSyntax(org.xwiki.rendering.syntax.Syntax syntax)
void
setSyntaxId(String syntaxId)
void
setTitle(String title)
void
setValidationScript(String validationScript)
Sets a new validation script for this document, a Velocity script that is executed when validating the document data.String
toString()
String
toXML()
org.dom4j.Document
toXMLDocument()
Object
updateObjectFromRequest(String className)
Object
updateObjectFromRequest(String className, String prefix)
List<Object>
updateObjectsFromRequest(String className)
List<Object>
updateObjectsFromRequest(String className, String prefix)
void
use(Object object)
Setting the current object to the given object.void
use(String className)
Setting the current object to the first object of the given class name.void
use(String className, int nb)
Setting the current object to the object of the given class name and the given number.boolean
validate()
boolean
validate(String[] classNames)
-
Methods inherited from class com.xpn.xwiki.api.Api
convert, convert, convert, convertAttachments, getAuthorizationManager, getContextualAuthorizationManager, getXWikiContext, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
-
-
-
-
Field Detail
-
initialDoc
protected XWikiDocument initialDoc
The XWikiDocument object wrapped by this API.
-
doc
protected XWikiDocument doc
The XWikiDocument object wrapped by this API.
-
currentObj
protected Object currentObj
Convenience object used by object related methods.
-
-
Constructor Detail
-
Document
public Document(XWikiDocument doc, XWikiContext context)
Document constructor.- Parameters:
doc
- The XWikiDocument object to wrap.context
- The current request context.
-
-
Method Detail
-
getDocument
public XWikiDocument getDocument()
Get the XWikiDocument wrapped by this API. This function is accessible only if you have the programming rights give access to the priviledged API of the Document.- Returns:
- The XWikiDocument wrapped by this API.
-
getDoc
protected XWikiDocument getDoc()
Get a clone of the XWikiDocument wrapped by this API.- Returns:
- A clone of the XWikiDocument wrapped by this API.
-
getId
public long getId()
return the ID of the document. this ID is unique across the wiki.- Returns:
- the id of the document.
-
getDocumentReference
public DocumentReference getDocumentReference()
returns the DocumentReference for the current document- Returns:
- the DocumentReference of the current document
- Since:
- 2.3M1
-
getDocumentReferenceWithLocale
public DocumentReference getDocumentReferenceWithLocale()
- Returns:
- the
DocumentReference
of the document also containing the documentLocale
- Since:
- 9.3RC1
-
getPageReference
public PageReference getPageReference()
- Returns:
- the reference of the document as
PageReference
without theLocale
- Since:
- 10.6RC1
-
getPageReferenceWithLocale
public PageReference getPageReferenceWithLocale()
- Returns:
- the reference of the document as
PageReference
including theLocale
- Since:
- 10.6RC1
-
getName
@Deprecated public String getName()
Deprecated.since 11.0, usegetDocumentReference()
instead- Returns:
- the last part of the document's reference. For example if the reference of a document is
MySpace.Mydoc
, the returned name isMyDoc
. For a nested document, the last part of the reference is alwaysWebHome
and thus the returned name isWebhome
. It's better to usegetPageReference()
orgetDocumentReference()
, e.g. withgetPageReference().getName()
orgetDocumentReference().getName()
. To get the space name of the nested document you can usegetPageReference().getName()
orgetDocumentReference().getParent().getName()
. - See Also:
getPageReference()
,getDocumentReference()
-
getSpace
public String getSpace()
Return the full local space reference of the Document. For example a document located in sub-spacespace11
of spacespace1
will returnspace1.space11
.- Returns:
- the name of the spaces of the document
-
getWiki
public String getWiki()
Get the name wiki where the document is stored.- Returns:
- The name of the wiki where this document is stored.
- Since:
- 1.1.2, 1.2M2
-
getFullName
public String getFullName()
Get the fullName of the document. If a document is named "MyDoc" in space "MySpace", the fullname is "MySpace.MyDoc". In a wiki, all the documents have a different fullName.- Returns:
- fullName of the document.
-
getPrefixedFullName
public String getPrefixedFullName()
Get the complete fullName of the document. The real full name of the document containing the name of the wiki where the document is stored. For a document stored in the wiki "xwiki", in space "MySpace", named "MyDoc", its complete full name is "xwiki:MySpace.MyDoc".- Returns:
- The complete fullName of the document.
- Since:
- 1.1.2, 1.2M2
-
getRCSVersion
public org.suigeneris.jrcs.rcs.Version getRCSVersion()
Get a Version object representing the current version of the document.- Returns:
- A Version object representing the current version of the document
-
getVersion
public String getVersion()
Get a string representing the current version of the document.- Returns:
- A string representing the current version of the document.
-
getPreviousVersion
public String getPreviousVersion()
Get a string representing the previous version of the document.- Returns:
- A string representing the previous version of the document. If this is the first version then it returns null.
-
getTitle
public String getTitle()
Get the value of the title field of the document.- Returns:
- The value of the title field of the document.
-
getDisplayTitle
public String getDisplayTitle()
Get document title. If a title has not been provided through the title field, it looks for a section title in the document's content and if not found return the page name. The returned title is also interpreted which means it's allowed to use Velocity, Groovy, etc syntax within a title.- Returns:
- The document title as XHTML
-
getPlainTitle
public String getPlainTitle()
Returns the document title as plain text- Returns:
- the document title as plain text (all markup removed)
- Since:
- 3.0M1
-
getRenderedTitle
public String getRenderedTitle(String syntaxId) throws XWikiException
Returns the title of the document rendered through wiki syntax and velocity- Returns:
- the title rendered through wiki syntax and velocity
- Throws:
XWikiException
- See Also:
XWikiDocument.getRenderedTitle(Syntax, XWikiContext)
-
getFormat
public String getFormat()
TODO document this or mark it deprecated
-
getAuthor
public String getAuthor()
Get fullName of the profile document of the author of the current version of the document. Example: XWiki.Admin.- Returns:
- The fullName of the profile document of the effective metadata author of the current version of the document.
-
getAuthorReference
public DocumentReference getAuthorReference()
- Returns:
- the document author reference
- Since:
- 6.4RC1
-
getContentAuthor
public String getContentAuthor()
Get fullName of the profile document of the author of the content modification of this document version. Example: XWiki.Admin.- Returns:
- The fullName of the profile document of the author of the content modification in this document version.
-
getContentAuthorReference
public DocumentReference getContentAuthorReference()
- Returns:
- the document content author reference
- Since:
- 6.4RC1
-
getDate
public Date getDate()
- Returns:
- The date when this document version has been modified.
-
getContentUpdateDate
public Date getContentUpdateDate()
Get the date when the content modification has been done on this document version. A content update excludes modifications to meta data fields or comments of the document.- Returns:
- The date where the content modification has been done on this document version.
-
getCreationDate
public Date getCreationDate()
- Returns:
- the original creation date of the document.
-
getParent
public String getParent()
Get the name of the parent of this document.- Returns:
- The name of the parent of this document.
-
getParentReference
public DocumentReference getParentReference()
- Returns:
- the parent reference or null if the parent is not set
- Since:
- 7.3M1
-
getCreator
public String getCreator()
Get fullName of the profile document of the document creator.- Returns:
- The fullName of the profile document of the document creator.
-
getCreatorReference
public DocumentReference getCreatorReference()
- Returns:
- the document creator reference
- Since:
- 6.4RC1
-
getContent
public String getContent()
Get raw content of the document, i.e. the content that is visible through the wiki editor.- Returns:
- The raw content of the document.
-
getXDOM
public org.xwiki.rendering.block.XDOM getXDOM()
NOTE: This method caches the XDOM and returns a clone that can be safely modified.- Returns:
- the XDOM corresponding to the document's string content
- Since:
- 7.0RC1
-
getSyntax
public org.xwiki.rendering.syntax.Syntax getSyntax()
- Returns:
- The syntax representing the syntax used for the document's content
- Since:
- 2.3M1
-
getSyntaxId
@Deprecated public String getSyntaxId()
Deprecated.since 2.3M1 usegetSyntax()
insteadGet the Syntax id representing the syntax used for the document. For example "xwiki/1.0" represents the first version XWiki syntax while "xwiki/2.0" represents version 2.0 of the XWiki Syntax.- Returns:
- The syntax id representing the syntax used for the document.
-
getLanguage
@Deprecated public String getLanguage()
Deprecated.since 5.4M1 usegetLocale()
insteadSame asgetLocale()
but as String.- Returns:
- the locale of the document.
-
getLocale
public Locale getLocale()
Get the locale of the document. If the document is a translation it returns the locale set for it, otherwise, it returns the root locale.- Returns:
- the locale of the document
- Since:
- 5.4M1
-
getTemplate
public String getTemplate()
TODO document this or mark it deprecated
-
getRealLanguage
@Deprecated public String getRealLanguage() throws XWikiException
Deprecated.since 8.0M1, usegetRealLocale()
insteadSame asgetRealLocale()
but as String.- Returns:
- the real locale
- Throws:
XWikiException
-
getRealLocale
public Locale getRealLocale()
Gets the real locale of the document. The real locale is either the default locale field when the locale field is empty (when the document is the default document) or the locale field otherwise when the document is a translation document- Returns:
- the actual locale of the document
- Since:
- 8.0M1
-
getDefaultLanguage
@Deprecated public String getDefaultLanguage()
Deprecated.since 8.0M1, usegetDefaultLocale()
insteadSame asgetDefaultLocale()
but as String.- Returns:
- the locale of the default document
-
getDefaultLocale
public Locale getDefaultLocale()
- Returns:
- the Locale of the default version of the document (usually
Locale.ROOT
orLocale.ENGLISH
) - Since:
- 8.0M1
-
setDefaultLocale
public void setDefaultLocale(Locale defaultLocale)
- Parameters:
defaultLocale
- the locale content in the default document version- Since:
- 11.9RC1
-
getDefaultTemplate
public String getDefaultTemplate()
TODO document this or mark it deprecated
-
getComment
public String getComment()
- Returns:
- the comment of of the document version
-
isMinorEdit
public boolean isMinorEdit()
- Returns:
- true if the this document version was a minor edit.
-
getTranslationLocales
public List<Locale> getTranslationLocales() throws XWikiException
- Returns:
- the list of locales for which this document has a translation; the original (default) locale is not included
- Throws:
XWikiException
- if retrieving the document translations from the database fails- Since:
- 12.4RC1
-
getTranslatedContent
public String getTranslatedContent() throws XWikiException
- Returns:
- the translated document's content if the wiki is multilingual, the locale is first checked in the URL, the cookie, the user profile and finally the wiki configuration if not, the locale is the one on the wiki configuration.
- Throws:
XWikiException
-
getTranslatedContent
public String getTranslatedContent(String locale) throws XWikiException
- Returns:
- the translated content in the given locale
- Throws:
XWikiException
-
getTranslatedDocument
public Document getTranslatedDocument(String locale) throws XWikiException
- Returns:
- the translated document in the given locale
- Throws:
XWikiException
-
getTranslatedDocument
public Document getTranslatedDocument() throws XWikiException
- Returns:
- the tranlated Document if the wiki is multilingual, the locale is first checked in the URL, the cookie, the user profile and finally the wiki configuration if not, the locale is the one on the wiki configuration.
- Throws:
XWikiException
-
displayDocument
public String displayDocument(org.xwiki.rendering.syntax.Syntax targetSyntax) throws XWikiException
- Parameters:
targetSyntax
- the syntax in which to render the document content- Returns:
- the content of the current document rendered.
- Throws:
XWikiException
- Since:
- 11.3RC1
-
displayDocument
public String displayDocument(org.xwiki.rendering.syntax.Syntax targetSyntax, boolean restricted) throws XWikiException
- Parameters:
targetSyntax
- the syntax in which to render the document contentrestricted
- seeDocumentDisplayerParameters.isTransformationContextRestricted()
.- Returns:
- the content of the current document rendered.
- Throws:
XWikiException
- Since:
- 11.5RC1
-
displayDocument
public String displayDocument() throws XWikiException
- Returns:
- the content of the current document rendered.
- Throws:
XWikiException
- Since:
- 11.3RC1
-
displayDocument
public String displayDocument(boolean restricted) throws XWikiException
- Parameters:
restricted
- seeDocumentDisplayerParameters.isTransformationContextRestricted()
.- Returns:
- the content of the current document rendered.
- Throws:
XWikiException
- Since:
- 11.5RC1
-
getRenderedContent
public String getRenderedContent() throws XWikiException
- Returns:
- the content of the document or its translations rendered.
- Throws:
XWikiException
-
getRenderedContent
public String getRenderedContent(boolean transformationContextIsolated) throws XWikiException
Execute and render the document in the current context.The code is executed with right of this document content author.
- Parameters:
transformationContextIsolated
- seeDocumentDisplayerParameters.isTransformationContextIsolated()
- Returns:
- the result
- Throws:
XWikiException
- when failing to display the document- Since:
- 8.4RC1
-
getRenderedContent
@Deprecated public String getRenderedContent(String text) throws XWikiException
Deprecated.since 1.6M1 usegetRenderedContent(String, String)
- Parameters:
text
- the text to render- Returns:
- the given text rendered in the context of this document
- Throws:
XWikiException
-
getRenderedContent
public String getRenderedContent(String text, String syntaxId) throws XWikiException
- Parameters:
text
- the text to rendersyntaxId
- the id of the Syntax used by the passed text (for example: "xwiki/1.0")- Returns:
- the given text rendered in the context of this document using the passed Syntax
- Throws:
XWikiException
- Since:
- 1.6M1
-
getRenderedContentRestricted
public String getRenderedContentRestricted(String text, String syntaxId) throws XWikiException
Render a text in a restricted mode, where script macros are completely disabled.- Parameters:
text
- the text to rendersyntaxId
- the id of the Syntax used by the passed text (for example: "xwiki/1.0")- Returns:
- the given text rendered in the context of this document using the passed Syntax
- Throws:
XWikiException
- Since:
- 4.2M1
-
getRenderedContent
public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId) throws XWikiException
- Parameters:
text
- the text to rendersourceSyntaxId
- the id of the Syntax used by the passed text (for example: "xwiki/1.0")targetSyntaxId
- the id of the syntax in which to render the document content- Returns:
- the given text rendered in the context of this document using the passed Syntax
- Throws:
XWikiException
- Since:
- 2.0M3
-
getRenderedContent
public String getRenderedContent(org.xwiki.rendering.syntax.Syntax targetSyntax) throws XWikiException
- Parameters:
targetSyntax
- the syntax in which to render the document content- Returns:
- the rendered content
- Throws:
XWikiException
- error when rendering content
-
getEscapedContent
public String getEscapedContent() throws XWikiException
Get the document's content XML-escaped.- Returns:
- an XML-escaped version of the content of this document.
- Throws:
XWikiException
-
getArchive
public String getArchive() throws XWikiException
- Returns:
- the archive of this document's history in string format
- Throws:
XWikiException
-
getDocumentArchive
public XWikiDocumentArchive getDocumentArchive() throws XWikiException
Get the archive of this document's history. This function is accessible only if you have the programming rights.- Returns:
- the archive of this document's history as an
XWikiDocumentArchive
. - Throws:
XWikiException
-
isNew
public boolean isNew()
- Returns:
- true if the document is a new one (ie it has never been saved) or false otherwise
-
getAttachmentURL
public String getAttachmentURL(String filename)
Return the relative URL of download for the the given attachment name.- Parameters:
filename
- the name of the attachment- Returns:
- A String with the URL or null if the file name is empty
-
getAttachmentURL
public String getAttachmentURL(String filename, String action)
Get the relative URL of the given action for the the given attachment name.- Parameters:
filename
- the name of the attachment.action
- what to do to the file for example "delattachment", "download" or "downloadrev".- Returns:
- a string representation of a URL to do the given operation or null if the file name is empty
-
getAttachmentURL
public String getAttachmentURL(String filename, String action, String queryString)
Get the relative URL of an action on an attachment. the given action for the the given attachment name with "queryString" parameters- Parameters:
filename
- the name of the attachment.action
- what to do to the file for example "delattachment", "download" or "downloadrev"queryString
- parameters added to the URL, the "rev" parameter is used to specify a revision if using the "downloadrev" action. The query string must not begin with an ? character.- Returns:
- a string representation of a URL to do the given operation or null if the file name is empty
-
getAttachmentRevisionURL
public String getAttachmentRevisionURL(String filename, String version)
Get an old revision of an attachment.- Parameters:
filename
- the name of the attachment.version
- a revision number such as "1.1" or "1.2".- Returns:
- the URL for accessing to the archive of the attachment "filename" at the version "version" or null if the file name is empty
-
getAttachmentRevisionURL
public String getAttachmentRevisionURL(String filename, String version, String queryString)
Get an old revision of an attachment.- Parameters:
filename
- the name of the attachment.version
- a revision number such as "1.1" or "1.2".queryString
- additional query parameters to pass in the request.- Returns:
- the URL for accessing to the archive of the attachment "filename" at the version "version" with the given queryString parameters or null if the file name is empty
-
getURL
public String getURL()
Get the URL of this document.- Returns:
- the URL to view this document, this will be a relative URL for example: /xwiki/bin/view/Main/WebHome
- See Also:
for an absolute URL which can used outside of the site.
-
getURL
public String getURL(String action)
Get the URL to do a given action on this document.- Parameters:
action
- what to do to the document for example "view", "edit" or "inline".- Returns:
- the URL of this document with the given action.
- See Also:
for an absolute URL which can used outside of the site.
-
getURL
public String getURL(String action, String queryString)
Get the URL to do a given action on this document.- Parameters:
action
- what to do to the document for example "view", "edit" or "inline".queryString
- parameters to pass in the request eg:paramA=value1¶mB=value2
- Returns:
- the URL of this document with the given action and queryString as parameters.
- See Also:
for an absolute URL which can used outside of the site.
-
getExternalURL
public String getExternalURL()
Get the external URL to do a given action on this document.- Returns:
- the full URL of the document, sutable for use at external websites for example: http://www.xwiki.org/xwiki/bin/view/Main/WebHome
- See Also:
for a relative URL which can only be used inside of the site.
-
getExternalURL
public String getExternalURL(String action)
Get the external URL to do a given action on this document.- Parameters:
action
- what to do to the document for example "view", "edit" or "inline".- Returns:
- the URL of this document with the given action.
- See Also:
for a relative URL which can only be used inside of the site.
-
getExternalURL
public String getExternalURL(String action, String queryString)
Get the URL to do a given action on this document.- Parameters:
action
- what to do to the document for example "view", "edit" or "inline".queryString
- parameters to pass in the request eg:paramA=value1¶mB=value2
- Returns:
- the URL of this document with the given action and queryString as parameters.
- See Also:
for a relative URL which can only be used inside of the site.
-
getParentURL
public String getParentURL() throws XWikiException
- Returns:
- the relative URL of the parent document of this document
- Throws:
XWikiException
-
getxWikiClass
public Class getxWikiClass()
- Returns:
- the XClass associated to this document when the document represents an XWiki Class
-
getxWikiClasses
public Class[] getxWikiClasses()
- Returns:
- the array of XClasses representing the objects of this document
-
createNewObject
public int createNewObject(String classname) throws XWikiException
Creates a New XWiki Object of the given classname- Parameters:
classname
- the classname used- Returns:
- the number of the object created
- Throws:
XWikiException
-
newObject
public Object newObject(String classname) throws XWikiException
Creates a New XWiki Object of the given classname- Parameters:
classname
- the classname used- Returns:
- the object created
- Throws:
XWikiException
-
isFromCache
public boolean isFromCache()
- Returns:
- true of the document has been loaded from cache
-
getObjectNumbers
public int getObjectNumbers(String classname)
- Parameters:
classname
- the classname used- Returns:
- the number of objects available for a given classname
-
getxWikiObjects
public Map<String,Vector<Object>> getxWikiObjects()
Get the list of all objects available in this document organized in a Map by classname- Returns:
- the map of objects
-
getXObjects
protected Vector<Object> getXObjects(List<BaseObject> objects)
-
getObjects
public Vector<Object> getObjects(String className)
Get the list of objects for a given classname classname- Returns:
- the vector of objects
-
getFirstObject
public Object getFirstObject(String fieldname)
Get the first object that contains the given fieldname- Parameters:
fieldname
- name of the field to find in the object- Returns:
- the XWiki Object
-
getObject
public Object getObject(String classname, String key, String value, boolean failover)
Get the first object of a given classname that has a field name matching the given value- Parameters:
classname
- name of the class of the object to look forkey
- name of the field to find in the objectvalue
- value of the field to find in the objectfailover
- true if the first object will be given when none found- Returns:
- the XWiki Object
-
getObjects
public Vector<Object> getObjects(String classname, String key, String value)
Select a subset of objects from a given class, filtered on a "key = value" criteria.- Parameters:
classname
- The type of objects to return.key
- The name of the property used for filtering.value
- The required value.- Returns:
- A Vector of
objects
matching the criteria. If no objects are found, or if the key is an empty String, then an empty vector is returned.
-
getObject
public Object getObject(String classname, String key, String value)
Get the first object of a given classname that has a field name matching the given value When none found this method will return null- Parameters:
classname
- name of the class of the object to look forkey
- name of the field to find in the objectvalue
- value of the field to find in the object- Returns:
- the XWiki Object
-
getObject
public Object getObject(String classname)
Get the first object matching the given classname- Parameters:
classname
- name of the class of the object to look for- Returns:
- the XWiki Object
-
getObject
public Object getObject(String classname, boolean create)
get the object of the given className. If there is no object of this className and the create parameter at true, the object is created.- Parameters:
classname
- name of the class of the object to look forcreate
- true of the object should be created when it does not exist- Returns:
- the XWiki Object
-
getObject
public Object getObject(String classname, int nb)
Get the object matching the given classname and given object number- Parameters:
classname
- name of the class of the objectnb
- number of the object- Returns:
- the XWiki Object
-
getObject
public Object getObject(ObjectReference objectReference)
- Parameters:
objectReference
- the object reference- Returns:
- the XWiki object from this document that matches the specified object reference
- Since:
- 12.3RC1
-
getObject
@Unstable public Object getObject(ObjectReference objectReference, boolean create)
- Parameters:
objectReference
- the object referencecreate
- if true, the object will be created when missing- Returns:
- the XWiki object from this document that matches the specified object reference
- Since:
- 14.0RC1
-
getXMLContent
public String getXMLContent() throws XWikiException
- Throws:
XWikiException
-
toXML
public String toXML() throws XWikiException
- Throws:
XWikiException
-
toXMLDocument
public org.dom4j.Document toXMLDocument() throws XWikiException
- Throws:
XWikiException
-
getRevisions
public org.suigeneris.jrcs.rcs.Version[] getRevisions() throws XWikiException
- Throws:
XWikiException
-
getRecentRevisions
public String[] getRecentRevisions() throws XWikiException
- Throws:
XWikiException
-
getRecentRevisions
public String[] getRecentRevisions(int nb) throws XWikiException
- Throws:
XWikiException
-
getRevisions
public List<String> getRevisions(RevisionCriteria criteria) throws XWikiException
Get document versions matching criterias like author, minimum creation date, etc.- Parameters:
criteria
- criteria used to match versions- Returns:
- a list of matching versions
- Throws:
XWikiException
-
getRevisionInfo
public RevisionInfo getRevisionInfo(String version) throws XWikiException
Get information about a document version : author, date, etc.- Parameters:
version
- the version you want to get information about- Returns:
- a new RevisionInfo object
- Throws:
XWikiException
-
getAttachmentList
public List<Attachment> getAttachmentList()
-
use
public void use(Object object)
Setting the current object to the given object. Following calls to display() will use this object as the reference for finding properties.- Parameters:
object
- Object to use as a reference for further display calls
-
use
public void use(String className)
Setting the current object to the first object of the given class name. Following calls to display() will use this object as the reference for finding properties.- Parameters:
className
- class used to find the first object to use as the reference for display calls
-
use
public void use(String className, int nb)
Setting the current object to the object of the given class name and the given number. Following calls to display() will use this object as the reference for finding properties.- Parameters:
className
- class used to find the object to use as the reference for display callsnb
- number of the object to use as the reference for display calls
-
getActiveClass
public String getActiveClass()
- Returns:
- the className of the current active object use for display calls.
-
displayPrettyName
public String displayPrettyName(String fieldname)
Displays the pretty name of the given field. This function uses the active object or will find the first object that has the given field.- Parameters:
fieldname
- fieldname to display the pretty name of- Returns:
- the pretty name display of the field.
-
displayPrettyName
public String displayPrettyName(String fieldname, Object obj)
Displays the pretty name of the given field of the given object.- Parameters:
fieldname
- fieldname to display the pretty name ofobj
- Object to find the class to display the pretty name of- Returns:
- the pretty name display of the field.
-
displayPrettyName
public String displayPrettyName(String fieldname, boolean showMandatory)
Displays the pretty name of the given field. This function uses the active object or will find the first object that has the given field. with the optional addition of a mandatory field.- Parameters:
fieldname
- fieldname to display the pretty name ofshowMandatory
- true to display a mandatory sign- Returns:
- the pretty name display of the field.
-
displayPrettyName
public String displayPrettyName(String fieldname, boolean showMandatory, Object obj)
Displays the pretty name of the given field of the given object. with the optional addition of a mandatory field.- Parameters:
fieldname
- fieldname to display the pretty name ofobj
- Object to find the class to display the pretty name ofshowMandatory
- true to display a mandatory sign- Returns:
- the pretty name display of the field.
-
displayPrettyName
public String displayPrettyName(String fieldname, boolean showMandatory, boolean before)
Displays the pretty name of the given field. This function uses the active object or will find the first object that has the given field. with the optional addition of a mandatory field before or after the field- Parameters:
fieldname
- fieldname to display the pretty name ofshowMandatory
- true to display a mandatory signbefore
- true if the mandatory sign should be before the field- Returns:
- the pretty name display of the field.
-
displayPrettyName
public String displayPrettyName(String fieldname, boolean showMandatory, boolean before, Object obj)
Displays the pretty name of the given field of the given object. with the optional addition of a mandatory field before or after the field- Parameters:
fieldname
- fieldname to display the pretty name ofshowMandatory
- true to display a mandatory signbefore
- true if the mandatory sign should be before the fieldobj
- Object to find the class to display the pretty name of- Returns:
- the pretty name display of the field.
-
displayTooltip
public String displayTooltip(String fieldname)
Displays the tooltip of the given field. This function uses the active object or will find the first object that has the given field.- Parameters:
fieldname
- fieldname to display the tooltip of- Returns:
- the tooltip display of the field.
-
displayTooltip
public String displayTooltip(String fieldname, Object obj)
Displays the tooltip of the given field of the given object.- Parameters:
fieldname
- fieldname to display the tooltip ofobj
- Object to find the class to display the tooltip of- Returns:
- the tooltip display of the field.
-
display
public String display(String fieldname)
Displays the given field. The display mode will be decided depending on page context (edit or inline context will display in edit, view context in view) This function uses the active object or will find the first object that has the given field. This function can return html inside and html macro- Parameters:
fieldname
- fieldname to display- Returns:
- the display of the field.
-
display
public String display(String fieldname, String mode)
Displays the given field in the given mode. This function uses the active object or will find the first object that has the given field. This function can return html inside and html macro- Parameters:
fieldname
- fieldname to displaymode
- display mode to use (view, edit, hidden, search)- Returns:
- the display of the field.
-
display
public String display(String fieldname, String mode, String prefix)
Displays the given field in the given mode. This function uses the active object or will find the first object that has the given field. This function can return html inside and html macro A given prefix is added to the field names when these are forms.- Parameters:
fieldname
- fieldname to displaymode
- display mode to use (view, edit, hidden, search)prefix
- prefix to use for the form names- Returns:
- the display of the field.
-
display
public String display(String fieldname, Object obj)
Displays the given field of the given object The display mode will be decided depending on page context (edit or inline context will display in edit, view context in view) This function can return html inside and html macro- Parameters:
fieldname
- fieldname to displayobj
- object from which to take the field- Returns:
- the display of the field.
-
display
public String display(String fieldname, String type, Object obj, String wrappingSyntaxId)
Displays the given field of the given object using the given mode and syntax rendering The display mode will be decided depending on page context (edit or inline context will display in edit, view context in view) This function can return html inside and html macro- Parameters:
fieldname
- the name of the field to displaytype
- the type of the field to displayobj
- the object containing the field to displaywrappingSyntaxId
- the syntax of the content in which the result will be included. This to take care of some escaping depending of the syntax.- Returns:
- the rendered field
-
display
public String display(String fieldname, String mode, Object obj)
Displays the given field of the given object in the given mode. This function can return html inside and html macro- Parameters:
fieldname
- fieldname to displaymode
- display mode to use (view, edit, hidden, search)obj
- the object containing the field to display- Returns:
- the display of the field.
-
display
public String display(String fieldname, String mode, String prefix, Object obj)
Displays the given field of the given object in the given mode. This function can return html inside and html macro A given prefix is added to the field names when these are forms.- Parameters:
fieldname
- fieldname to displaymode
- display mode to use (view, edit, hidden, search)prefix
- prefix to use for the form namesobj
- the object containing the field to display- Returns:
- the display of the field.
-
displayForm
public String displayForm(String className, String header, String format, boolean linebreak)
-
displayRendered
public String displayRendered(PropertyClass pclass, String prefix, Collection object) throws XWikiException
- Throws:
XWikiException
-
displayView
public String displayView(PropertyClass pclass, String prefix, Collection object)
-
displayEdit
public String displayEdit(PropertyClass pclass, String prefix, Collection object)
-
displayHidden
public String displayHidden(PropertyClass pclass, String prefix, Collection object)
-
getAttachment
public Attachment getAttachment(String filename)
-
getContentDiff
public List<org.suigeneris.jrcs.diff.delta.Delta> getContentDiff(Document origdoc, Document newdoc) throws XWikiException, org.suigeneris.jrcs.diff.DifferentiationFailedException
- Throws:
XWikiException
org.suigeneris.jrcs.diff.DifferentiationFailedException
-
getXMLDiff
public List<org.suigeneris.jrcs.diff.delta.Delta> getXMLDiff(Document origdoc, Document newdoc) throws XWikiException, org.suigeneris.jrcs.diff.DifferentiationFailedException
- Throws:
XWikiException
org.suigeneris.jrcs.diff.DifferentiationFailedException
-
getRenderedContentDiff
public List<org.suigeneris.jrcs.diff.delta.Delta> getRenderedContentDiff(Document origdoc, Document newdoc) throws XWikiException, org.suigeneris.jrcs.diff.DifferentiationFailedException
- Throws:
XWikiException
org.suigeneris.jrcs.diff.DifferentiationFailedException
-
getMetaDataDiff
public List<MetaDataDiff> getMetaDataDiff(Document origdoc, Document newdoc) throws XWikiException
- Throws:
XWikiException
-
getObjectDiff
public List<List<ObjectDiff>> getObjectDiff(Document origdoc, Document newdoc)
-
getClassDiff
public List<List<ObjectDiff>> getClassDiff(Document origdoc, Document newdoc)
-
getAttachmentDiff
public List<AttachmentDiff> getAttachmentDiff(Document origdoc, Document newdoc)
-
getLastChanges
public List<org.suigeneris.jrcs.diff.delta.Delta> getLastChanges() throws XWikiException, org.suigeneris.jrcs.diff.DifferentiationFailedException
- Throws:
XWikiException
org.suigeneris.jrcs.diff.DifferentiationFailedException
-
getCurrentMonthPageStats
public DocumentStats getCurrentMonthPageStats(String action)
Get statistics about the number of request for the current page during the current month.- Parameters:
action
- the type of request for which to retrieve statistics: view, edit...- Returns:
- the statistics object holding information for this document and the current month
-
getCurrentMonthSpaceStats
public DocumentStats getCurrentMonthSpaceStats(String action)
Get statistics about the number of request for the current space during the current month.- Parameters:
action
- the type of request for which to retrieve statistics: view, edit...- Returns:
- the statistics object holding information for the document's space and the current month
-
getCurrentMonthRefStats
public List<RefererStats> getCurrentMonthRefStats()
Get referer statistics for the current document during the current month.- Returns:
- a list of referer statistics for the document's space
-
checkAccess
public boolean checkAccess(String right)
-
hasAccessLevel
public boolean hasAccessLevel(String level)
-
hasAccessLevel
public boolean hasAccessLevel(String level, String user)
Description copied from class:Api
Check if the current user has an access level on a given document.- Overrides:
hasAccessLevel
in classApi
- Parameters:
level
- The name of the right to verify (eg "programming", "admin", "register", etc).user
- The document for which to verify the right.- Returns:
true
if the current user has the specified right,false
otherwise.
-
hasAccess
public boolean hasAccess(Right right, DocumentReference userReference)
Verifies if the user identified byuserReference
has the access identified byright
on this document. Note that this method does not overrideApi.hasAccess(Right, DocumentReference)
: they share same signature but on theApi
one theDocumentReference
parameter is about the entity where to check the right, while here it's about the user to check right for.
-
hasAccess
@Unstable public boolean hasAccess(Right right)
Verifies if the context user has the access identified byright
on the current context document.- Parameters:
right
- the right to check- Returns:
true
if the user has the specified right on this document,false
otherwise- Since:
- 14.10, 14.4.7
-
getLocked
public boolean getLocked()
-
getLockingUser
public String getLockingUser()
-
getLockingDate
public Date getLockingDate()
-
get
public Object get(String classOrFieldName)
Renders the passed xproperty as HTML. Note that if you need the raw value, you should callgetValue(String)
instead.- Parameters:
classOrFieldName
- the xproperty (aka field) name to render or an xclass reference- Returns:
- the rendered xproperty as HTML if an xobject exists with that xproperty. Otherwise considers that the passed parameter is an xclass reference and return the xobject for it or null if none exist
- See Also:
getValue(String)
,getValue(String, Object)
-
getValue
public Object getValue(String fieldName)
- Parameters:
fieldName
- the xproperty (aka field) name for which to get the value- Returns:
- the raw value of the passed xproperty found in the current xobject or in the first xobject containing such a field
- See Also:
getValue(String, Object)
-
getValue
public Object getValue(String fieldName, Object object)
- Parameters:
fieldName
- the xproperty (aka field) name for which to get the valueobject
- the specific xobject from which to get the xproperty value- Returns:
- the raw value of the passed xproperty
- See Also:
getValue(String)
-
getTextArea
public String getTextArea()
-
getTOC
public Map<String,Map<String,Object>> getTOC(int init, int max, boolean numbered)
Returns data needed for a generation of Table of Content for this document.- Parameters:
init
- an intial level where the TOC generation should start atmax
- maximum level TOC is generated fornumbered
- if should generate numbering for headings- Returns:
- a map where an heading (title) ID is the key and value is another map with two keys: text, level and numbering
-
getTags
public String getTags()
-
insertText
public void insertText(String text, String marker) throws XWikiException
- Throws:
XWikiException
-
same
public boolean same(XWikiDocument document)
Check if the passed one is the one wrapped by thisDocument
.- Parameters:
document
- the document to compare- Returns:
- true if passed document is the wrapped one
- Since:
- 8.3M1
-
getBacklinks
public List<String> getBacklinks() throws XWikiException
- Throws:
XWikiException
-
getBackLinkedReferences
public List<DocumentReference> getBackLinkedReferences() throws XWikiException
Retrieve the references of the page containing a link to the current page.- Returns:
- a list of references of the page containing a link to the current page.
- Throws:
XWikiException
- in case of problem to perform the query.- Since:
- 12.5RC1
-
getLinks
public List<XWikiLink> getLinks() throws XWikiException
- Throws:
XWikiException
-
getSections
public List<DocumentSection> getSections() throws XWikiException
Get the top sections contained in the document.The section are filtered by xwiki.section.depth property on the maximum depth of the sections to return. This method is usually used to get "editable" sections.
- Returns:
- the sections in the current document
- Throws:
XWikiException
-
getChildren
public List<String> getChildren() throws XWikiException
Get document children. Children are documents with the current document as parent.- Returns:
- The list of children for the current document.
- Throws:
XWikiException
- Since:
- 1.8 Milestone 2
-
getChildrenReferences
public List<DocumentReference> getChildrenReferences() throws XWikiException
Get document children references. Children are documents with the current document as parent.- Returns:
- The list of children for the current document.
- Throws:
XWikiException
- in case of problem to query the children.- Since:
- 12.5RC1
-
getChildren
public List<String> getChildren(int nb, int start) throws XWikiException
Get document children. Children are documents with the current document as parent. Where a document has a large number of children, one may desire to return a certain number of children (nb) and skip some number (start) of the first results.- Parameters:
nb
- The number of results to return.start
- The number of results to skip before we begin returning results.- Returns:
- The list of children for the current document.
- Throws:
XWikiException
-
getDefaultEditMode
public String getDefaultEditMode() throws XWikiException
Gets the default edit mode for this document. An edit mode (other than the default "edit") can be enforced by creating anXWiki.EditModeClass
object in the current document, with the appropriate value for the defaultEditMode property, or by adding this object in a sheet included by the document. This function also falls back on the oldSheetClass
, deprecated since 3.1M2, which can be attached to included documents to specify that the current document should be edited inline.- Returns:
- the default edit mode for this document ("edit" or "inline" usually)
- Throws:
XWikiException
- since XWiki 6.3M1 it's not used anymore and "edit" is returned in case of error, with an error log
-
getDefaultEditURL
public String getDefaultEditURL() throws XWikiException
- Throws:
XWikiException
-
getEditURL
public String getEditURL(String action, String mode) throws XWikiException
- Throws:
XWikiException
-
isCurrentUserCreator
public boolean isCurrentUserCreator()
-
isCurrentUserPage
public boolean isCurrentUserPage()
-
isCurrentLocalUserPage
public boolean isCurrentLocalUserPage()
-
isCreator
public boolean isCreator(String username)
-
setTitle
public void setTitle(String title)
-
setCustomClass
public void setCustomClass(String customClass)
-
setParent
public void setParent(String parent)
-
setContent
public void setContent(String content)
-
setContent
public void setContent(org.xwiki.rendering.block.XDOM content) throws XWikiException
- Parameters:
content
- the content as XDOM- Throws:
XWikiException
- when failing to convert the XDOM to String content- Since:
- 7.0RC1
-
setSyntax
public void setSyntax(org.xwiki.rendering.syntax.Syntax syntax)
- Parameters:
syntax
- the Syntax representing the syntax used for the current document's content.- Since:
- 2.3M1
-
setSyntaxId
public void setSyntaxId(String syntaxId)
- Parameters:
syntaxId
- the Syntax id representing the syntax used for the current document. For example "xwiki/1.0" represents the first version XWiki syntax while "xwiki/2.0" represents version 2.0 of the XWiki Syntax.
-
setDefaultTemplate
public void setDefaultTemplate(String dtemplate)
-
setComment
public void setComment(String comment)
-
setMinorEdit
public void setMinorEdit(boolean isMinor)
-
save
public void save() throws XWikiException
- Throws:
XWikiException
-
save
public void save(String comment) throws XWikiException
- Throws:
XWikiException
-
save
public void save(String comment, boolean minorEdit) throws XWikiException
- Throws:
XWikiException
-
saveWithProgrammingRights
public void saveWithProgrammingRights() throws XWikiException
- Throws:
XWikiException
-
saveWithProgrammingRights
public void saveWithProgrammingRights(String comment) throws XWikiException
- Throws:
XWikiException
-
saveWithProgrammingRights
public void saveWithProgrammingRights(String comment, boolean minorEdit) throws XWikiException
- Throws:
XWikiException
-
saveAsAuthor
public void saveAsAuthor() throws XWikiException
Save the document if the current author of the script calling this method has permission to do so. The author of this document is also set to the said author.- Throws:
XWikiException
- if script author is not allowed to save the document or if save operation fails.- Since:
- 2.3M2
-
saveAsAuthor
public void saveAsAuthor(String comment) throws XWikiException
Save the document if the current author of the script calling this method has permission to do so. The author of this document is also set to the said author.- Parameters:
comment
- The comment to display in document history (what did you change in the document)- Throws:
XWikiException
- if script author is not allowed to save the document or if save operation fails.- Since:
- 2.3M2
-
saveAsAuthor
public void saveAsAuthor(String comment, boolean minorEdit) throws XWikiException
Save the document if the current author of the script calling this method has permission to do so. The author of this document is also set to the said author.- Parameters:
comment
- The comment to display in document history (what did you change in the document)minorEdit
- Set true to advance the document version number by 0.1 or false to advance version to the next integer + 0.1 eg: 25.1- Throws:
XWikiException
- if script author is not allowed to save the document or if save operation fails.- Since:
- 2.3M2
-
saveDocument
protected void saveDocument(String comment, boolean minorEdit) throws XWikiException
- Throws:
XWikiException
-
addObjectFromRequest
public Object addObjectFromRequest() throws XWikiException
- Throws:
XWikiException
-
addObjectFromRequest
public Object addObjectFromRequest(String className) throws XWikiException
- Throws:
XWikiException
-
addObjectsFromRequest
public List<Object> addObjectsFromRequest(String className) throws XWikiException
- Throws:
XWikiException
-
addObjectFromRequest
public Object addObjectFromRequest(String className, String prefix) throws XWikiException
- Throws:
XWikiException
-
addObjectsFromRequest
public List<Object> addObjectsFromRequest(String className, String prefix) throws XWikiException
- Throws:
XWikiException
-
updateObjectFromRequest
public Object updateObjectFromRequest(String className) throws XWikiException
- Throws:
XWikiException
-
updateObjectsFromRequest
public List<Object> updateObjectsFromRequest(String className) throws XWikiException
- Throws:
XWikiException
-
updateObjectFromRequest
public Object updateObjectFromRequest(String className, String prefix) throws XWikiException
- Throws:
XWikiException
-
updateObjectsFromRequest
public List<Object> updateObjectsFromRequest(String className, String prefix) throws XWikiException
- Throws:
XWikiException
-
isAdvancedContent
public boolean isAdvancedContent()
-
isProgrammaticContent
public boolean isProgrammaticContent()
-
removeObject
public boolean removeObject(Object object)
Remove an XObject from the document. The changes are not persisted until the document is saved.- Parameters:
object
- the object to remove- Returns:
true
if the object was successfully removed,false
if the object was not found in the current document.
-
removeObjects
public boolean removeObjects(String className)
Remove all the objects of a given type (XClass) from the document. The object counter is left unchanged, so that future objects will have new (different) numbers. However, on some storage engines the counter will be reset if the document is removed from the cache and reloaded from the persistent storage.- Parameters:
className
- The class name of the objects to be removed.- Returns:
true
if the objects were successfully removed,false
if no object from the target class was in the current document.
-
deleteDocument
protected void deleteDocument() throws XWikiException
Remove document from the wiki. Reinitcloned
.- Throws:
XWikiException
-
delete
public void delete() throws XWikiException
- Throws:
XWikiException
-
deleteAsAuthor
public void deleteAsAuthor() throws XWikiException
Delete the document if thecontent author
of the script calling this method has permission to do so. The deleter is also set to the said content author.- Throws:
XWikiException
- if script author is not allowed to delete the document or if save operation fails.- Since:
- 2.3M2
-
deleteWithProgrammingRights
public void deleteWithProgrammingRights() throws XWikiException
- Throws:
XWikiException
-
getVersionHashCode
public String getVersionHashCode()
-
addAttachments
public int addAttachments() throws XWikiException
- Throws:
XWikiException
-
addAttachments
public int addAttachments(String fieldName) throws XWikiException
- Throws:
XWikiException
-
addAttachment
public Attachment addAttachment(String fileName, InputStream iStream)
-
addAttachment
public Attachment addAttachment(String fileName, byte[] data)
-
validate
public boolean validate() throws XWikiException
- Throws:
XWikiException
-
validate
public boolean validate(String[] classNames) throws XWikiException
- Throws:
XWikiException
-
getValidationScript
public String getValidationScript()
Retrieves the validation script associated with this document, a Velocity script that is executed when validating the document data.- Returns:
- A
String
representation of the validation script, or an empty string if there is no such script.
-
setValidationScript
public void setValidationScript(String validationScript)
Sets a new validation script for this document, a Velocity script that is executed when validating the document data.- Parameters:
validationScript
- The new validation script, which can be an empty string ornull
if the script should be removed.
-
rename
public void rename(DocumentReference newReference) throws XWikiException
Rename the current document and all the backlinks leading to it. Will also change parent field in all documents which list the document we are renaming as their parent. Seerename(String, java.util.List, java.util.List)
for more details.- Parameters:
newReference
- the reference to the new document- Throws:
XWikiException
- in case of an error- Since:
- 2.3M2
-
rename
public void rename(String newDocumentName, List<String> backlinkDocumentNames) throws XWikiException
Rename the current document and all the links pointing to it in the list of passed backlink documents. The renaming algorithm takes into account the fact that there are several ways to write a link to a given page and all those forms need to be renamed. For example the following links all point to the same page:- [Page]
- [Page?param=1]
- [currentwiki:Page]
- [currentwiki:CurrentSpace.Page]
Note: links without a space are renamed with the space added and all documents which have the document being renamed as parent have their parent field set to "currentwiki:CurrentSpace.Page".
- Parameters:
newDocumentName
- the new document name. If the space is not specified then defaults to the current space.backlinkDocumentNames
- the list of documents to parse and for which links will be modified to point to the new renamed document.- Throws:
XWikiException
- in case of an error
-
rename
public void rename(String newDocumentName, List<String> backlinkDocumentNames, List<String> childDocumentNames) throws XWikiException
Same asrename(String, List)
but the list of documents having the current document as their parent is passed in parameter.- Parameters:
newDocumentName
- the new document name. If the space is not specified then defaults to the current space.backlinkDocumentNames
- the list of documents to parse and for which links will be modified to point to the new renamed document.childDocumentNames
- the list of documents whose parent field will be set to the new document name.- Throws:
XWikiException
- in case of an error
-
rename
public void rename(DocumentReference newReference, List<DocumentReference> backlinkDocumentNames, List<DocumentReference> childDocumentNames) throws XWikiException
Same asrename(String, List)
but the list of documents having the current document as their parent is passed in parameter.- Parameters:
newReference
- the reference to the new documentbacklinkDocumentNames
- the list of reference to documents to parse and for which links will be modified to point to the new renamed documentchildDocumentNames
- the list of references to documents whose parent field will be set to the new document reference- Throws:
XWikiException
- in case of an error- Since:
- 2.3M2
-
getDocumentRevision
public Document getDocumentRevision(String revision)
Allow to easily access any revision of a document- Parameters:
revision
- the version to access- Returns:
- the document corresponding to the requested revision or
null
if the revision does not exist or access is denied.
-
getPreviousDocument
public Document getPreviousDocument() throws XWikiException
Allow to easily access the previous revision of a document- Returns:
- Document
- Throws:
XWikiException
-
isMostRecent
public boolean isMostRecent()
- Returns:
- is document most recent. false if and only if there are older versions of this document.
-
isRestricted
@Unstable public boolean isRestricted()
- Returns:
- if rendering transformations shall be executed in restricted mode and the title not be executed
- Since:
- 14.10.7, 15.2RC1
-
convertSyntax
public boolean convertSyntax(String targetSyntaxId) throws XWikiException
Convert the current document content from its current syntax to the new syntax passed as parameter.- Parameters:
targetSyntaxId
- the syntax to convert to (eg "xwiki/2.0", "xhtml/1.0", etc)- Throws:
XWikiException
- if an exception occurred during the conversion process
-
isHidden
public boolean isHidden()
Indicates whether the document is 'hidden' or not, meaning that it should not be returned in public search results or appear in the User Interface in general.- Returns:
true
if the document is hidden,false
otherwise.
-
setHidden
public void setHidden(boolean hidden)
Indicates whether the document should be 'hidden' or not, meaning that it should not be returned in public search results or appear in the User Interface in general.- Parameters:
hidden
-true
if the document should be 'hidden',false
otherwise.
-
dropPermissions
public void dropPermissions()
Drop permissions for the remainder of the rendering cycle. After this is called:- 1.
Api.hasProgrammingRights()
will always return false. - 2.
XWiki.getDocumentAsAuthor(org.xwiki.model.reference.DocumentReference)
,XWiki.getDocumentAsAuthor(String)
,saveAsAuthor()
,saveAsAuthor(String)
,saveAsAuthor(String, boolean)
, anddeleteAsAuthor()
will perform all of their actions as if the document's content author was the guest user (XWiki.XWikiGuest).
This sandboxing will expire at the end of the rendering cycle and can be suspended by beginning a new rendering cycle. A rendering cycle can be begin by calling
getRenderedContent(String)
,display(String)
(or variations thereof) or by invoking the include macro or usingXWiki.includeTopic(String)
NOTE: Even if you include the same document, permissions will be regained. What this does is sandbox the remainder of the code on the page because although it can temporarily suspend the permissions drop, it cannot get itself to be executed with permissions because if it calls itself, it will hit the drop function first.
If you are interested in a more secure sandboxing method where code is guaranteed not to have permissions for the remainder of the request, you should consider
Context.dropPermissions()
.- Since:
- 3.2M2
- 1.
-
isTranslation
public boolean isTranslation()
- Returns:
- true if this document is a translation of the main document (i.e. returned by
getTranslatedDocument(String)
); false if this is actually the main document (i.e. returned byXWiki.getDocument(DocumentReference)
. - Since:
- 6.2M2
-
getLocalReferenceMaxLength
public int getLocalReferenceMaxLength()
- Returns:
- the maximum authorized length for a document full name (see
getFullName()
). - Since:
- 11.4RC1
-
getAuthors
@Unstable public DocumentAuthors getAuthors()
- Returns:
- the authors of the document.
- Since:
- 14.0RC1
-
-