net.sf.okapi.lib.xliff2.core

## Class Part

- java.lang.Object
- - net.sf.okapi.lib.xliff2.core.Part

- Direct Known Subclasses:
    Segment

      public class Part
      extends java.lang.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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Part.GetTarget` Options when getting a target which does not exists yet.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Part(Part original)` Copy constructor.
    `Part(Store store)` Creates a new part with an empty source.
    `Part(Store store, java.lang.String sourceContent)` Creates a new part with a given plain text source.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getId()` Gets the id for this part.
    `java.lang.String` | `getId(boolean createIfNeeded)` Gets the id for this part.
    `boolean` | `getPreserveWS()` Indicates if the whitespace of this part's content must be preserved.
    `Fragment` | `getSource()` Gets the source fragment for this part.
    `Tags` | `getSourceTags()` Gets all the source tags for the unit where this part is.
    `Store` | `getStore()` Gets the store for this part.
    `Fragment` | `getTarget()` Gets the target fragment for this part.
    `Fragment` | `getTarget(Part.GetTarget creationOption)` Gets the target fragment for this part, and possibly create it if it does not exists yet.
    `int` | `getTargetOrder()` Gets the target order for this part.
    `Tags` | `getTargetTags()` Gets all the target tags for the unit where this part is.
    `boolean` | `hasTarget()` Indicates if this part has a target.
    `boolean` | `isSegment()` Indicates if this part is a segment or an ignorable.
    `void` | `removeMarkers(boolean target, java.lang.String type)` Removes the markers in the source or target content of this part.
    `void` | `setId(java.lang.String id)` Sets the id for this part.
    `void` | `setPreserveWS(boolean preserveWS)` Sets the flag indicating if the whitespace of this part's content must be preserved.
    `Fragment` | `setSource(Fragment fragment)` Sets the fragment of the source for this part.
    `Fragment` | `setSource(java.lang.String plainText)` Sets the source for this part as a new fragment made of a plain text string.
    `Fragment` | `setTarget(Fragment fragment)` Sets the fragment of the target for this part.
    `Fragment` | `setTarget(java.lang.String plainText)` Sets the target for this part as a new fragment made of a plain text string.
    `void` | `setTargetOrder(int targetOrder)` Sets the target order value for this part.
    `void` | `showProtectedContent()` Expands all `PCont` references in this part into normal content.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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,
              java.lang.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 java.lang.String getId()

      Gets the id for this part.
      Returns:
        the id for this part if one exists, return null otherwise.

    - #### getId

          public java.lang.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(java.lang.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(java.lang.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(java.lang.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,
                           java.lang.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.