Package org.xwiki.annotation
Class Annotation
- java.lang.Object
-
- org.xwiki.annotation.Annotation
-
public class Annotation extends Object
This class wraps together the data needed to describe an annotation.- Since:
- 2.3M1
- Version:
- $Id: 1bb94e6bbafb1e9532860db8d5e8f4550ba0cd45 $
-
-
Field Summary
Fields Modifier and Type Field Description static String
AUTHOR_FIELD
The name of the field of this annotation author.static String
DATE_FIELD
The name of the field of this annotation serialized date.protected Map<String,Object>
fields
The values of the fields of this annotation.protected String
id
The unique identifier of this annotation, which should be unique among all the annotations on the same target.static String
ORIGINAL_SELECTION_FIELD
The name of the field of this annotation original selection.static String
PLAIN_TEXT_END_OFFSET_FIELD
The name of the field of this annotation end offset relative to the plain text.static String
PLAIN_TEXT_START_OFFSET_FIELD
The name of the field of this annotation start offset relative to the plain text.static String
SELECTION_FIELD
The name of the field of this annotation selection.static String
SELECTION_LEFT_CONTEXT_FIELD
The name of the field of this annotation selection context to the left of the annotation.static String
SELECTION_RIGHT_CONTEXT_FIELD
The name of the field of this annotation selection context to the right of the annotation.static String
STATE_FIELD
The name of the field of this annotation state.static String
TARGET_FIELD
The name of the field of this annotation's reference to the target content.
-
Constructor Summary
Constructors Constructor Description Annotation(String id)
Builds an annotation description for the annotation with the passed id: used for annotation updates where only a part of the fields my need to be set.Annotation(String initialSelection, String leftContext, String rightContext)
Builds an annotation for the passed selection in the context, used to pass an annotation to be added (which does not have an id yet since it hasn't been stored yet).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Object
get(String key)
String
getAuthor()
Date
getDate()
Set<String>
getFieldNames()
String
getId()
String
getOriginalSelection()
String
getSelection()
String
getSelectionInContext()
Helper method to get the selection of this annotation in its context, with the context left to the left and context right to the right.String
getSelectionLeftContext()
String
getSelectionRightContext()
AnnotationState
getState()
int
hashCode()
Object
set(String key, Object value)
Sets / adds a value in the fields of this annotation.void
setAuthor(String author)
Sets the author of this annotation.void
setDate(Date date)
void
setOriginalSelection(String originalSelection)
void
setSelection(String selection)
Sets the selection of this annotation.void
setSelection(String selection, String contextLeft, String contextRight)
Sets the selection of this annotation and the context along with it.void
setState(AnnotationState state)
String
toString()
-
-
-
Field Detail
-
SELECTION_FIELD
public static final String SELECTION_FIELD
The name of the field of this annotation selection.
The text on which this annotation is added.- See Also:
- Constant Field Values
-
SELECTION_LEFT_CONTEXT_FIELD
public static final String SELECTION_LEFT_CONTEXT_FIELD
The name of the field of this annotation selection context to the left of the annotation.
The context of the selection is used to uniquely localize an annotation on the content where is added. Or, if the context appears twice, semantically speaking it shouldn't make any difference if the annotation is displayed and handled in one or other of the occurrences.- See Also:
- Constant Field Values
-
SELECTION_RIGHT_CONTEXT_FIELD
public static final String SELECTION_RIGHT_CONTEXT_FIELD
The name of the field of this annotation selection context to the right of the annotation.
The context of the selection is used to uniquely localize an annotation on the content where is added. Or, if the context appears twice, semantically speaking it shouldn't make any difference if the annotation is displayed and handled in one or other of the occurrences.- See Also:
- Constant Field Values
-
STATE_FIELD
public static final String STATE_FIELD
The name of the field of this annotation state.
TODO: find out if it's the right place to put the state information, as it's a maintainer particular information.- See Also:
- Constant Field Values
-
ORIGINAL_SELECTION_FIELD
public static final String ORIGINAL_SELECTION_FIELD
The name of the field of this annotation original selection.- See Also:
- Constant Field Values
-
AUTHOR_FIELD
public static final String AUTHOR_FIELD
The name of the field of this annotation author.- See Also:
- Constant Field Values
-
DATE_FIELD
public static final String DATE_FIELD
The name of the field of this annotation serialized date.- See Also:
- Constant Field Values
-
TARGET_FIELD
public static final String TARGET_FIELD
The name of the field of this annotation's reference to the target content.- See Also:
- Constant Field Values
-
PLAIN_TEXT_START_OFFSET_FIELD
@Unstable public static final String PLAIN_TEXT_START_OFFSET_FIELD
The name of the field of this annotation start offset relative to the plain text.- Since:
- 13.10RC1
- See Also:
- Constant Field Values
-
PLAIN_TEXT_END_OFFSET_FIELD
@Unstable public static final String PLAIN_TEXT_END_OFFSET_FIELD
The name of the field of this annotation end offset relative to the plain text.- Since:
- 13.10RC1
- See Also:
- Constant Field Values
-
id
protected final String id
The unique identifier of this annotation, which should be unique among all the annotations on the same target.
-
-
Constructor Detail
-
Annotation
public Annotation(String id)
Builds an annotation description for the annotation with the passed id: used for annotation updates where only a part of the fields my need to be set.- Parameters:
id
- the id of this annotation
-
Annotation
public Annotation(String initialSelection, String leftContext, String rightContext)
Builds an annotation for the passed selection in the context, used to pass an annotation to be added (which does not have an id yet since it hasn't been stored yet).- Parameters:
initialSelection
- the selected text of this annotationleftContext
- the context to the left of the selection, which makes the selection uniquely identifiable in the content on which this annotation is added. Can be void if selection itself is uniquerightContext
- the context to the right of the selection, which makes the selection uniquely identifiable in the content on which this annotation is added. Can be void if selection itself is unique
-
-
Method Detail
-
getAuthor
public String getAuthor()
- Returns:
- author of annotation.
-
setAuthor
public void setAuthor(String author)
Sets the author of this annotation.- Parameters:
author
- the author of this annotation.
-
getDate
public Date getDate()
- Returns:
- date of annotation
-
setDate
public void setDate(Date date)
- Parameters:
date
- the serialized date to set
-
getState
public AnnotationState getState()
- Returns:
- state of annotation
-
setState
public void setState(AnnotationState state)
- Parameters:
state
- to set
-
getSelection
public String getSelection()
- Returns:
- selected text of this annotation
-
getSelectionInContext
public String getSelectionInContext()
Helper method to get the selection of this annotation in its context, with the context left to the left and context right to the right. This method ensures that a non-null value will be returned, even if some of the components of the selection are missing.- Returns:
- the selection of this annotation in its context, with the context left to the left and context right to the right
-
setSelection
public void setSelection(String selection, String contextLeft, String contextRight)
Sets the selection of this annotation and the context along with it.- Parameters:
selection
- the selection of this annotationcontextLeft
- the context to the left of the annotationcontextRight
- the context to the right of the annotation
-
setSelection
public void setSelection(String selection)
Sets the selection of this annotation.- Parameters:
selection
- the selection of the annotation
-
getSelectionLeftContext
public String getSelectionLeftContext()
- Returns:
- selection context to the left of annotation
-
getSelectionRightContext
public String getSelectionRightContext()
- Returns:
- selection context to the right of annotation
-
getId
public String getId()
- Returns:
- id of annotation
-
getOriginalSelection
public String getOriginalSelection()
- Returns:
- the originalSelection
-
setOriginalSelection
public void setOriginalSelection(String originalSelection)
- Parameters:
originalSelection
- the originalSelection to set
-
get
public Object get(String key)
- Parameters:
key
- the key of the field to get- Returns:
- the value of the field
-
set
public Object set(String key, Object value)
Sets / adds a value in the fields of this annotation.- Parameters:
key
- the key of the fieldvalue
- the value to set for the field- Returns:
- the old value of this field, or null if none was set
-
-