Package org.xwiki.annotation.script
Class AnnotationScriptService
java.lang.Object
org.xwiki.annotation.script.AnnotationScriptService
- All Implemented Interfaces:
org.xwiki.script.service.ScriptService
@Component
@Named("annotations")
@Singleton
public class AnnotationScriptService
extends Object
implements org.xwiki.script.service.ScriptService
Wrapper for the annotation service functions to be exposed to scripting contexts.
- Since:
- 3.0RC1
- Version:
- $Id: e66808fa62973d78591536b58acaba7a243748cb $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAnnotation(String target, String selection, String selectionContext, int offset, String author, Map<String, Object> metadata) Adds an the specified annotation for the specified target.booleancanAddAnnotation(String wiki, String space, String page) Deprecated.booleancanAddAnnotation(DocumentReference reference) Checks if the current user can add an annotation on the document given by the reference.booleancanEditAnnotation(String annotationId, String wiki, String space, String page) Deprecated.since 7.2M3, usecanEditAnnotation(String, DocumentReference)insteadbooleancanEditAnnotation(String annotationId, DocumentReference reference) Checks if the current user can edit an annotation on the document given by wiki, space and page.getAnnotatedHTML(String sourceReference) Returns the XHTML of the requested source, along with annotations inserted asspanelements inside it.getAnnotatedRenderedContent(String sourceReference, String sourceSyntax, String outputSyntax, Collection<Annotation> annotations) Returns result obtained by rendering with annotations markers the source referenced by thesourceReferenceparsed insourceSyntax.getAnnotation(String target, String id) Returns the annotation identified byidon the specified target.getAnnotation(EntityReference reference, String id) Returns the annotation identified byidon the specified target.getAnnotations(String target) Returns all the annotations on the passed content.getValidAnnotations(String target) Shortcut function to get all annotations which are valid on the specified target, regardless of the updates the document and its annotations suffered from creation ('safe' or 'updated' state).booleanremoveAnnotation(String target, String annotationID) Remove an annotation given by its identifier, which should be unique among all annotations on the same target.booleanupdateAnnotation(String target, Annotation annotation) Updates the passed annotation with the new values.
-
Constructor Details
-
AnnotationScriptService
public AnnotationScriptService()
-
-
Method Details
-
addAnnotation
public boolean addAnnotation(String target, String selection, String selectionContext, int offset, String author, Map<String, Object> metadata) Adds an the specified annotation for the specified target.- Parameters:
target- serialized reference of the target of the annotationselection- HTML selection concerned by annotationsselectionContext- HTML selection contextoffset- offset of the selection in contextauthor- the author of the annotationmetadata- annotation metadata, as key, value pairs- Returns:
trueif the adding succeeds,falseif an exception occurs and the exception is saved on the xwiki context
-
getAnnotatedHTML
Returns the XHTML of the requested source, along with annotations inserted asspanelements inside it. It's a particular case ofgetAnnotatedRenderedContent(String, String, String, Collection)for unspecified input syntax,xhtml/1.0output syntax and the list of annotations returned bygetValidAnnotations(String)for this source reference.- Parameters:
sourceReference- reference to the source to be rendered in XHTML with annotations- Returns:
- rendered and annotated document or
nullif an exception occurs and the exception is saved on the xwiki context - See Also:
-
getAnnotatedRenderedContent
public String getAnnotatedRenderedContent(String sourceReference, String sourceSyntax, String outputSyntax, Collection<Annotation> annotations) Returns result obtained by rendering with annotations markers the source referenced by thesourceReferenceparsed insourceSyntax. The list of annotations to be added markers for is passed in theannotationsparameter. Note that no test is done on the actual target of the annotations in the passed list, they will all be rendered, as long as their selected text and context can be identified in the content.- Parameters:
sourceReference- the reference to the source to be rendered in XHTML with annotationssourceSyntax- the syntax to parse the source in. If this parameter is null, the default source syntax will be used, as returned by the target IO service.outputSyntax- the syntax to render in (e.g. "xhtml/1.0")annotations- the annotations to render on the content referred by thesourceReference. Can be the whole set of annotations on that source or a subset, filtered by various criteria- Returns:
- the annotated rendered source, or @code null} if an exception occurs and the exception is saved on the xwiki context
- See Also:
-
getAnnotation
Returns the annotation identified byidon the specified target.- Parameters:
target- the serialized reference to the content on which the annotation is addedid- the identifier of the annotation- Returns:
- the annotation identified by
id, ornullif an exception occurs and the exception is saved on the xwiki context - See Also:
-
getAnnotation
Returns the annotation identified byidon the specified target.- Parameters:
reference- the reference to the content on which the annotation is addedid- the identifier of the annotation- Returns:
- the annotation identified by
id, ornullif an exception occurs and the exception is saved on the xwiki context - See Also:
-
getAnnotations
Returns all the annotations on the passed content.- Parameters:
target- the string serialized reference to the content for which to get the annotations- Returns:
- all annotations which target the specified content, or
nullif an exception occurs and the exception is saved on the xwiki context - See Also:
-
getValidAnnotations
Shortcut function to get all annotations which are valid on the specified target, regardless of the updates the document and its annotations suffered from creation ('safe' or 'updated' state).- Parameters:
target- the string serialized reference to the content for which to get the annotations- Returns:
- all annotations which are valid on the specified content, or
nullif an exception occurs and the exception is saved on the xwiki context - See Also:
-
removeAnnotation
Remove an annotation given by its identifier, which should be unique among all annotations on the same target.- Parameters:
target- the string serialized reference to the content on which the annotation is addedannotationID- annotation identifier- Returns:
trueif removing succeeds,falseif an exception occurs and the exception is saved on the xwiki context- See Also:
-
updateAnnotation
Updates the passed annotation with the new values. Matching of the annotation is done by the annotation id field, among all annotations on the same target.- Parameters:
target- the string serialized reference to the content on which the annotation is addedannotation- the new description of the annotation to update, with a valid id- Returns:
trueif update succeeds,falseif an exception occurs and the exception is saved on the xwiki context- See Also:
-
canEditAnnotation
@Deprecated public boolean canEditAnnotation(String annotationId, String wiki, String space, String page) Deprecated.since 7.2M3, usecanEditAnnotation(String, DocumentReference)insteadChecks if the current user can edit an annotation on the document given by wiki, space and page. This function is a helper function, using wiki, space and page instead of the target to avoid target generation in velocity scripting.
TODO: annotations should only operate on targets, and velocity context should only operate with targets so that they can pass a target to this function. This also assumes refactoring of the REST service to always get target references instead of wiki, space and pages in the path.- Parameters:
annotationId- the id of the annotation to editwiki- the wiki of the document where the annotation is addedspace- the space of the document where the annotation is addedpage- the document page- Returns:
trueif the current user can edit the annotation identified by the id on the specified document,falseotherwise
-
canEditAnnotation
Checks if the current user can edit an annotation on the document given by wiki, space and page.- Parameters:
annotationId- the id of the annotation to editreference- the reference of the document where the annotation is added- Returns:
trueif the current user can edit the annotation identified by the id on the specified document,falseotherwise- Since:
- 7.2M3
-
canAddAnnotation
Deprecated.since 7.2M3, usecanAddAnnotation(DocumentReference)insteadChecks if the current user can add an annotation on the document given by the wiki, space and page. This function is a helper function, using wiki, space and page instead of the target to avoid target generation in velocity scripting.- Parameters:
wiki- the wiki of the document where the annotation is addedspace- the space of the document where the annotation is addedpage- the document page- Returns:
trueif the current user can add an annotation on the specified document,falseotherwise- See Also:
-
canAddAnnotation
Checks if the current user can add an annotation on the document given by the reference.- Parameters:
reference- the reference of the document where the annotation is added- Returns:
trueif the current user can add an annotation on the specified document,falseotherwise- Since:
- 7.2M3
- See Also:
-
canAddAnnotation(DocumentReference)instead