Class TextUnit

    • Constructor Detail

      • TextUnit

        public TextUnit()
      • TextUnit

        public TextUnit​(String id)
        Creates a new TextUnit object with its identifier.
        Parameters:
        id - the identifier of this resource.
      • TextUnit

        public TextUnit​(String id,
                        String sourceText)
        Creates a new TextUnit object with its identifier and a text.
        Parameters:
        id - the identifier of this resource.
        sourceText - the initial text of the source.
      • TextUnit

        public TextUnit​(String id,
                        String sourceText,
                        boolean isReferent)
        Creates a new TextUnit object with its ID, a text, and a flag indicating if it is a referent or not.
        Parameters:
        id - the identifier of this resource.
        sourceText - the initial text of the source (can be null).
        isReferent - indicates if this resource is a referent (i.e. is referred to by another resource) or not.
      • TextUnit

        public TextUnit​(String id,
                        String sourceText,
                        boolean isReferent,
                        String mimeType)
        Creates a new TextUnit object with its identifier, a text, a flag indicating if it is a referent or not, and a given MIME type.
        Parameters:
        id - the identifier of this resource.
        sourceText - the initial text of the source (can be null).
        isReferent - indicates if this resource is a referent (i.e. is referred to by another resource) or not.
        mimeType - the MIME type identifier for the content of this TextUnit.
      • TextUnit

        public TextUnit​(String id,
                        TextContainer source,
                        boolean isReferent,
                        String mimeType)
        Creates a new TextUnit object with its identifier, a text, a flag indicating if it is a referent or not, and a given MIME type.
        Parameters:
        id - the identifier of this resource.
        source - the initial text container of the source (can be null).
        isReferent - indicates if this resource is a referent (i.e. is referred to by another resource) or not.
        mimeType - the MIME type identifier for the content of this TextUnit.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Description copied from interface: ITextUnit
        Indicates if the source text of this TextUnit is empty.
        Specified by:
        isEmpty in interface ITextUnit
        Returns:
        true if the source text of this TextUnit is empty, false otherwise.
      • setSource

        public TextContainer setSource​(TextContainer textContainer)
        Description copied from interface: ITextUnit
        Sets the source object for this TextUnit. Any existing source object is overwritten.
        Specified by:
        setSource in interface ITextUnit
        Parameters:
        textContainer - the source object to set.
        Returns:
        the source object that has been set.
      • setSourceContent

        public TextFragment setSourceContent​(TextFragment content)
        Description copied from interface: ITextUnit
        Sets the content of the source for this TextUnit.
        Specified by:
        setSourceContent in interface ITextUnit
        Parameters:
        content - the new content to set.
        Returns:
        the new content of the source for this TextUnit.
      • createTarget

        public TextContainer createTarget​(LocaleId targetLocale,
                                          boolean overwriteExisting,
                                          int creationOptions)
        Description copied from interface: ITextUnit
        Creates or get the target for this TextUnit.

        If a variant source exists for the target locale, creationOptions apply to the variant source.

        Specified by:
        createTarget in interface ITextUnit
        Parameters:
        targetLocale - the target locale.
        overwriteExisting - true to overwrite any existing target for the given locale. False to not create a new target object if one already exists for the given locale.
        creationOptions - creation options:
        • CREATE_EMPTY: Create an empty target object.
        • COPY_PROPERTIES: Copy the source properties.
        • COPY_CONTENT: Copy the text of the source (and any associated in-line code), but not the segmenation.
        • COPY_SEGMENTATION: Copy the source segmentation.
        • COPY_SEGMENTED_CONTENT: Same as (COPY_CONTENT|COPY_SEGMENTATION).
        • COPY_ALL: Same as (COPY_SEGMENTED_CONTENT|COPY_PROPERTIES).
        Returns:
        the target object that was created, or retrieved.
      • getTarget

        public TextContainer getTarget​(LocaleId locId)
        Description copied from interface: ITextUnit
        Gets the target object for this text unit for a given locale. If the target does not exists a null is retruned.
        Specified by:
        getTarget in interface ITextUnit
        Parameters:
        locId - the locale to query.
        Returns:
        the target object for this text unit for the given locale, or null if the target does not exist.
        See Also:
        ITextUnit.createTarget(LocaleId, boolean, int)
      • setTarget

        public TextContainer setTarget​(LocaleId locId,
                                       TextContainer text)
        Description copied from interface: ITextUnit
        Sets the target object for this text unit for a given locale.

        If the target does not exists, one is created. Any existing content for the given locale is overwritten. To set a target object based on the source, use the ITextUnit.createTarget(LocaleId, boolean, int) method.

        Specified by:
        setTarget in interface ITextUnit
        Parameters:
        locId - the target locale.
        text - the target content to set.
        Returns:
        the target content that has been set.
      • removeTarget

        public void removeTarget​(LocaleId locId)
        Description copied from interface: ITextUnit
        Removes a given target object from this text unit. If the given locale does not exist in this text unit nothing happens. Variant source for this target locale will not be affected.
        Specified by:
        removeTarget in interface ITextUnit
        Parameters:
        locId - the target locale to remove.
      • hasTarget

        public boolean hasTarget​(LocaleId locId)
        Description copied from interface: ITextUnit
        Indicates if there is a target object for a given locale for this text unit.
        Specified by:
        hasTarget in interface ITextUnit
        Parameters:
        locId - the locale to query.
        Returns:
        true if a target object exists for the given locale, false otherwise.
      • setTargetContent

        public TextFragment setTargetContent​(LocaleId locId,
                                             TextFragment content)
        Description copied from interface: ITextUnit
        Sets the content of the target for a given locale for this TextUnit.

        If the target does not exists, one is created. Any existing content for the given locale is overwritten. To set a target object based on the source, use the ITextUnit.createTarget(LocaleId, boolean, int) method.

        Specified by:
        setTargetContent in interface ITextUnit
        Parameters:
        locId - the locale to set.
        content - the new content to set.
        Returns:
        the new content for the given target locale for this text unit.
      • getSourceSegments

        public ISegments getSourceSegments()
        Description copied from interface: ITextUnit
        Gets the segments for the source. Un-segmented content return a single segment.
        Specified by:
        getSourceSegments in interface ITextUnit
        Returns:
        an object implementing ISegments for the source content.
      • getSourceSegment

        public Segment getSourceSegment​(String segId,
                                        boolean createIfNeeded)
        Description copied from interface: ITextUnit
        Gets the source segment for a given segment id.

        If the segment does not exists, one is created if createIfNeeded is true.

        Specified by:
        getSourceSegment in interface ITextUnit
        Parameters:
        segId - the id of the segment to retrieve.
        createIfNeeded - true to append a segment at the end of the content and return it if the segment does not exist yet. False to return null when the segment does not exists.
        Returns:
        the found or created segment, or null.
      • getTargetSegments

        public ISegments getTargetSegments​(LocaleId trgLoc)
        Description copied from interface: ITextUnit
        Get the segments for a given target. Un-segmented content return a single segment. If the target does not exists, one is created, with the same segments as the source, but empty.
        Specified by:
        getTargetSegments in interface ITextUnit
        Parameters:
        trgLoc - the locale of the target to retrieve.
        Returns:
        an object implementing ISegments for the given target content.
      • getTargetSegment

        public Segment getTargetSegment​(LocaleId trgLoc,
                                        String segId,
                                        boolean createIfNeeded)
        Description copied from interface: ITextUnit
        Gets the segment for a given segment id in a given target.

        If the target does not exists, one is created.

        If the segment does not exists, one is created if createIfNeeded is true.

        Specified by:
        getTargetSegment in interface ITextUnit
        Parameters:
        trgLoc - the target locale to look up.
        segId - the id of the segment to retrieve.
        createIfNeeded - true to append a segment at the end of the target content and return it if the segment does not exist yet. False to return null when the segment does not exists.
        Returns:
        the found or created segment, or null.
      • toString

        public String toString()
        Gets the string representation of the default source container. If the container is segmented, the representation shows the merged segments. Inline codes are also included.
        Overrides:
        toString in class BaseNameable
        Returns:
        the string representation of the source container.
      • clone

        public TextUnit clone()
        Clones this TextUnit.
        Specified by:
        clone in interface ITextUnit
        Overrides:
        clone in class Object
        Returns:
        A new TextUnit object that is a copy of this one.
      • removeAllSegmentations

        public void removeAllSegmentations()
        Description copied from interface: ITextUnit
        Removes all segmentations (source and targets) in this text unit. All entries are converted to non-segmented entries.
        Specified by:
        removeAllSegmentations in interface ITextUnit
      • createSourceSegmentation

        public void createSourceSegmentation​(ISegmenter segmenter)
        Description copied from interface: ITextUnit
        Segments the default source content based on the rules provided by a given ISegmenter.
        Specified by:
        createSourceSegmentation in interface ITextUnit
        Parameters:
        segmenter - the segmenter to use to create the segments.
      • createTargetSegmentation

        public void createTargetSegmentation​(ISegmenter segmenter,
                                             LocaleId targetLocale)
        Description copied from interface: ITextUnit
        Segments the specified target content based on the rules provided by a given ISegmenter.
        Specified by:
        createTargetSegmentation in interface ITextUnit
        Parameters:
        segmenter - the segmenter to use to create the segments.
        targetLocale - LocaleId of the target we want to segment.
      • removeSourceProperty

        public void removeSourceProperty​(String name)
        Description copied from interface: IWithSourceProperties
        Removes a source property of a given name. If the property does not exists nothing happens.
        Specified by:
        removeSourceProperty in interface IWithSourceProperties
        Parameters:
        name - The name of the property to remove.
      • hasSourceProperty

        public boolean hasSourceProperty​(String name)
        Description copied from interface: IWithSourceProperties
        Indicates if a source property exists for a given name.
        Specified by:
        hasSourceProperty in interface IWithSourceProperties
        Parameters:
        name - The name of the source property to query.
        Returns:
        True if a source property exists, false otherwise.
      • getTargetProperty

        public Property getTargetProperty​(LocaleId locId,
                                          String name)
        Description copied from interface: IWithTargetProperties
        Gets the target property for a given name and target locale.
        Specified by:
        getTargetProperty in interface IWithTargetProperties
        Parameters:
        locId - the locale of the property to retrieve.
        name - The name of the property to retrieve. This name is case-sensitive.
        Returns:
        The property or null if it does not exist.
      • setTargetProperty

        public Property setTargetProperty​(LocaleId locId,
                                          Property property)
        Description copied from interface: IWithTargetProperties
        Sets a target property. If a property already exists it is overwritten.
        Specified by:
        setTargetProperty in interface IWithTargetProperties
        Parameters:
        locId - The target locale for which this property should be set.
        property - The new property to set. This name is case-sensitive.
        Returns:
        The property that has been set.
      • removeTargetProperty

        public void removeTargetProperty​(LocaleId locId,
                                         String name)
        Description copied from interface: IWithTargetProperties
        Removes a target property of a given name. If the property does not exists nothing happens.
        Specified by:
        removeTargetProperty in interface IWithTargetProperties
        Parameters:
        locId - The target locale for which this property should be set.
        name - The name of the property to remove.
      • getTargetPropertyNames

        public Set<String> getTargetPropertyNames​(LocaleId locId)
        Description copied from interface: IWithTargetProperties
        Gets the names of all the properties for a given target locale in this resource.
        Specified by:
        getTargetPropertyNames in interface IWithTargetProperties
        Parameters:
        locId - the target locale to query.
        Returns:
        all the names of the target properties for the given locale in this resource.
      • hasTargetProperty

        public boolean hasTargetProperty​(LocaleId locId,
                                         String name)
        Description copied from interface: IWithTargetProperties
        Indicates if a property exists for a given name and target locale.
        Specified by:
        hasTargetProperty in interface IWithTargetProperties
        Parameters:
        locId - the target locale to query.
        name - the name of the property to query.
        Returns:
        true if a property exists, false otherwise.