Class Part

  • Direct Known Subclasses:
    Segment

    public class Part
    extends Object
    Represents a part of a unit. A part corresponds to an <ignorable> or a <segment> element. See the class Segment for a part that is a segment.
    • Constructor Detail

      • Part

        public Part​(Part original)
        Copy constructor.
        Parameters:
        original - the original part to duplicate.
      • Part

        public Part​(Store store)
        Creates a new part with an empty source.
        Parameters:
        store - the store associated with the new part (cannot be null).
      • Part

        public Part​(Store store,
                    String sourceContent)
        Creates a new part with a given plain text source.
        Parameters:
        store - the store associated with the new part (cannot be null).
        sourceContent - the plain text source content of the new part.
    • Method Detail

      • getId

        public String getId()
        Gets the id for this part.
        Returns:
        the id for this part if one exists, return null otherwise.
      • getId

        public String getId​(boolean createIfNeeded)
        Gets the id for this part.
        Parameters:
        createIfNeeded - true to assign automatically an id if none is already set, false to get null if there is no id set.
        Returns:
        the id for this part (can be null if createIfNeeded is false).
      • setId

        public void setId​(String id)
        Sets the id for this part.
        Parameters:
        id - the new id for this part (can be null). No check is done for uniqueness.
      • getPreserveWS

        public boolean getPreserveWS()
        Indicates if the whitespace of this part's content must be preserved.
        Returns:
        true if the whitespace must be preserved, false if the whitespace can be modified.
      • setPreserveWS

        public void setPreserveWS​(boolean preserveWS)
        Sets the flag indicating if the whitespace of this part's content must be preserved.
        Parameters:
        preserveWS - true to preserve the whitespace, false otherwise.
      • getSource

        public Fragment getSource()
        Gets the source fragment for this part.
        Returns:
        the source fragment for this part (never null).
      • setSource

        public Fragment setSource​(Fragment fragment)
        Sets the fragment of the source for this part. The fragment must have the same store as the part.
        Parameters:
        fragment - the fragment to set.
        Returns:
        the new source fragment.
      • setSource

        public Fragment setSource​(String plainText)
        Sets the source for this part as a new fragment made of a plain text string.
        Parameters:
        plainText - the plain text source content to set.
        Returns:
        the new source fragment.
      • hasTarget

        public boolean hasTarget()
        Indicates if this part has a target.
        Returns:
        true if this part has a target, false otherwise.
      • getTarget

        public Fragment getTarget​(Part.GetTarget creationOption)
        Gets the target fragment for this part, and possibly create it if it does not exists yet.
        Parameters:
        creationOption - action to take if no target exists yet for this part.
        Returns:
        the target fragment or null.
        See Also:
        getTarget()
      • getTarget

        public Fragment getTarget()
        Gets the target fragment for this part.
        • Use this when you know the target exists.
        • Use getTarget(GetTarget) to create the fragment if needed.
        Returns:
        the target fragment or null
        See Also:
        getTarget(GetTarget)
      • setTarget

        public Fragment setTarget​(Fragment fragment)
        Sets the fragment of the target for this part. The fragment must have the same store as the part.
        Parameters:
        fragment - the fragment to set.
        Returns:
        the new target fragment.
      • setTarget

        public Fragment setTarget​(String plainText)
        Sets the target for this part as a new fragment made of a plain text string.
        Parameters:
        plainText - the plain text target content to set.
        Returns:
        the new target fragment.
      • getSourceTags

        public Tags getSourceTags()
        Gets all the source tags for the unit where this part is.
        Returns:
        all the source tags for the unit where this part is.
      • getTargetTags

        public Tags getTargetTags()
        Gets all the target tags for the unit where this part is.
        Returns:
        all the target tags for the unit where this part is.
      • setTargetOrder

        public void setTargetOrder​(int targetOrder)
        Sets the target order value for this part. Zero means the default source order.
        Parameters:
        targetOrder - the new target order for this part.
      • getTargetOrder

        public int getTargetOrder()
        Gets the target order for this part. Zero means the default source order.
        Returns:
        the target order for this part.
      • getStore

        public Store getStore()
        Gets the store for this part.
        Returns:
        the store for this part (never null).
      • isSegment

        public boolean isSegment()
        Indicates if this part is a segment or an ignorable.
        Returns:
        true if this part is a segment, false otherwise.
      • removeMarkers

        public void removeMarkers​(boolean target,
                                  String type)
        Removes the markers in the source or target content of this part.
        Parameters:
        target - true to remove from the target, false to remove from the source.
        type - the type of markers to remove (or null to remove all markers).
      • showProtectedContent

        public void showProtectedContent()
        Expands all PCont references in this part into normal content. This is done on both source and target.