Package net.sf.okapi.common.resource
Class TextPart
- java.lang.Object
-
- net.sf.okapi.common.resource.TextPart
-
- All Implemented Interfaces:
Cloneable
,IResource
,IWithAnnotations
,IWithProperties
,IWithSkeleton
- Direct Known Subclasses:
Segment
public class TextPart extends Object implements IResource
Implements the base object for the parts that make up a content.
-
-
Field Summary
Fields Modifier and Type Field Description protected Annotations
annotations
String
id
Identifier of this segment.String
originalId
Some formats already have id's like xliff2protected Map<String,Property>
properties
TextFragment
text
Text fragment of this part.WhitespaceStrategy
whitespaceStrategy
-
Fields inherited from interface net.sf.okapi.common.IResource
COPY_ALL, COPY_CONTENT, COPY_PROPERTIES, COPY_SEGMENTATION, COPY_SEGMENTED_CONTENT, CREATE_EMPTY
-
-
Constructor Summary
Constructors Constructor Description TextPart()
Creates an empty part.TextPart(String text)
Creates a new TextPart with a given text string.TextPart(String id, TextFragment text)
Creates a new TextPart with a givenTextFragment
.TextPart(TextFragment text)
Creates a new TextPart with a givenTextFragment
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TextPart
clone()
Clone ofTextPart
Annotations
getAnnotations()
TextFragment
getContent()
Gets the text fragment for this part.String
getId()
Gets the identifier for this textpart.String
getOriginalId()
Map<String,Property>
getProperties()
WhitespaceStrategy
getWhitespaceStrategy()
boolean
isSegment()
Indicates if this part is aSegment
.boolean
preserveWhitespaces()
WARNING: The parentITextUnit
must be used in the case the whitespaceSrategy is INHERIT. We return false in the case of INHERIT because we have not specially set the whitespace handling TextPart and so it is the responsibility of the user to check the parent for the "real" value.void
setContent(TextFragment fragment)
Sets theTextFragment
for this part.void
setId(String id)
Sets the identifier of this resource.void
setOriginalId(String originalId)
void
setPreserveWhitespaces(boolean preserveWS)
Only use this method if you are overriding the parentITextUnit
whitespace handling.void
setWhitespaceStrategy(WhitespaceStrategy whitespaceStrategy)
String
toString()
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.okapi.common.resource.IWithAnnotations
annotationIterator, clear, getAnnotation, getAnnotationsTypesAsSet, hasAnnotation, hasAnnotations, remove, setAnnotation
-
Methods inherited from interface net.sf.okapi.common.resource.IWithProperties
getProperty, getPropertyNames, hasProperty, propertyIterator, removeProperty, setProperty
-
Methods inherited from interface net.sf.okapi.common.resource.IWithSkeleton
getSkeleton, setSkeleton
-
-
-
-
Field Detail
-
id
public String id
Identifier of this segment.
-
originalId
public String originalId
Some formats already have id's like xliff2
-
text
public TextFragment text
Text fragment of this part.
-
whitespaceStrategy
public WhitespaceStrategy whitespaceStrategy
-
annotations
protected Annotations annotations
-
-
Constructor Detail
-
TextPart
public TextPart()
Creates an empty part.
-
TextPart
public TextPart(TextFragment text)
Creates a new TextPart with a givenTextFragment
.- Parameters:
text
- theTextFragment
for this new part.
-
TextPart
public TextPart(String id, TextFragment text)
Creates a new TextPart with a givenTextFragment
.- Parameters:
text
- theTextFragment
for this new part.
-
TextPart
public TextPart(String text)
Creates a new TextPart with a given text string.- Parameters:
text
- the text for this new part.
-
-
Method Detail
-
getId
public String getId()
Gets the identifier for this textpart.
-
setId
public void setId(String id)
Description copied from interface:IResource
Sets the identifier of this resource.- Specified by:
setId
in interfaceIResource
- Parameters:
id
- the new identifier value.- See Also:
IResource.getId()
-
getContent
public TextFragment getContent()
Gets the text fragment for this part.- Returns:
- the text fragment for this part.
-
setContent
public void setContent(TextFragment fragment)
Sets theTextFragment
for this part.- Parameters:
fragment
- theTextFragment
to assign to this part. It must not be null.
-
getWhitespaceStrategy
public WhitespaceStrategy getWhitespaceStrategy()
-
setWhitespaceStrategy
public void setWhitespaceStrategy(WhitespaceStrategy whitespaceStrategy)
-
isSegment
public boolean isSegment()
Indicates if this part is aSegment
.- Returns:
- true if the part is a
Segment
, false if it is not.
-
getProperties
public Map<String,Property> getProperties()
- Specified by:
getProperties
in interfaceIWithProperties
- Returns:
Map
of properties for the implementer of interface
-
getAnnotations
public Annotations getAnnotations()
- Specified by:
getAnnotations
in interfaceIWithAnnotations
- Returns:
Annotations
for the implementer of interface
-
preserveWhitespaces
public boolean preserveWhitespaces()
WARNING: The parentITextUnit
must be used in the case the whitespaceSrategy is INHERIT. We return false in the case of INHERIT because we have not specially set the whitespace handling TextPart and so it is the responsibility of the user to check the parent for the "real" value.- Returns:
- true if the whitespace handling has been specifically set on this instance. False in all other cases.
-
setPreserveWhitespaces
public void setPreserveWhitespaces(boolean preserveWS)
Only use this method if you are overriding the parentITextUnit
whitespace handling.- Parameters:
preserveWS
- true to preserve whitespace, otherwise normalize
-
getOriginalId
public String getOriginalId()
-
setOriginalId
public void setOriginalId(String originalId)
-
-