Package net.sf.okapi.common.skeleton
Class GenericSkeleton
- java.lang.Object
-
- net.sf.okapi.common.skeleton.GenericSkeleton
-
- Direct Known Subclasses:
ZipSkeleton
public class GenericSkeleton extends Object implements ISkeleton
Simple generic implementation of the ISkeleton interface. This class implements a skeleton as a list of parts: some are simple text storage string corresponding to the original code of the input document, others are placeholders for the content in the text units, or the values of modifiable properties.
-
-
Constructor Summary
Constructors Constructor Description GenericSkeleton()
Creates a new empty GenericSkeleton object.GenericSkeleton(String data)
Creates a new GenericSkeleton object and append some data to it.GenericSkeleton(GenericSkeleton skel)
Creates a new GenericSkeleton object and initialize it with the parts of an existing one passed as a parameter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(char data)
Adds a new part to this skeleton, and set a character data to it.void
add(String data)
Adds a new part to this skeleton, and set a string data to it.void
add(GenericSkeleton skel)
Adds to this skeleton all the parts of a given skeleton.void
add(GenericSkeletonPart part)
Adds a new part to this skeleton.void
addContentPlaceholder(ITextUnit textUnit)
Adds to this skeleton a placeholder for the source content of the resource to which this skeleton is attached.void
addContentPlaceholder(ITextUnit textUnit, LocaleId locId)
Adds to this skeleton a placeholder for the content (in a given locale) of the resource to which this skeleton is attached.void
addReference(IReferenceable referent)
Adds to this skeleton a reference to an existing resource send before the one to which this skeleton is attached to.GenericSkeletonPart
addValuePlaceholder(INameable referent, String propName, LocaleId locId)
Adds to this skeleton a place-holder for the value of a property (in a given locale) of the resource to which this skeleton is attached.void
append(char data)
Appends a character data to this skeleton.void
append(String data)
Appends a string of data to this skeleton.void
appendToFirstPart(String data)
Appends a string of data to the first skeleton part, a new part is created is none exists already.void
attachParent(INameable parent)
Attaches a parent resource to a skeleton part.void
changeSelfReferents(INameable newReferent)
Updates all the self-references to use the given referent.GenericSkeleton
clone()
Clones this GenericSkeleton object.protected void
copyFields(GenericSkeleton toSkel)
void
flushPart()
Forces the current part to be completed, so the next call to append data will start a new part.GenericSkeletonPart
getFirstPart()
Gets the first part of this skeleton, or null if there are none.GenericSkeletonPart
getLastPart()
Gets the last part of this skeleton, or null if there are none.IResource
getParent()
Gets the parent resource of this skeleton.List<GenericSkeletonPart>
getParts()
Gets a list of all the parts of this skeleton.boolean
isEmpty()
Indicates if this skeleton is empty or not.boolean
isEmpty(boolean ignoreWhitespaces)
Indicates if this skeleton is empty or not, considering the white-spaces or not.void
setParent(IResource parent)
Sets a parent of this skeleton object.protected void
setParts(ArrayList<GenericSkeletonPart> list)
String
toString()
Gets a string representation of the content of all the part of the skeleton.
-
-
-
Constructor Detail
-
GenericSkeleton
public GenericSkeleton()
Creates a new empty GenericSkeleton object.
-
GenericSkeleton
public GenericSkeleton(String data)
Creates a new GenericSkeleton object and append some data to it.- Parameters:
data
- the data to append.
-
GenericSkeleton
public GenericSkeleton(GenericSkeleton skel)
Creates a new GenericSkeleton object and initialize it with the parts of an existing one passed as a parameter.- Parameters:
skel
- the existing skeleton from which to copy the parts.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Indicates if this skeleton is empty or not.- Returns:
- true if this skeleton is empty, false if it has at least one part.
-
isEmpty
public boolean isEmpty(boolean ignoreWhitespaces)
Indicates if this skeleton is empty or not, considering the white-spaces or not.- Parameters:
ignoreWhitespaces
- true to ignore the white-spaces.- Returns:
- true if this skeleton is empty, false if it has at least one part.
-
add
public void add(String data)
Adds a new part to this skeleton, and set a string data to it. Empty or null data has no effect.- Parameters:
data
- the data to add.
-
add
public void add(GenericSkeletonPart part)
Adds a new part to this skeleton. Empty or null data has no effect.- Parameters:
part
- the part to add.
-
flushPart
public void flushPart()
Forces the current part to be completed, so the next call to append data will start a new part.
-
add
public void add(char data)
Adds a new part to this skeleton, and set a character data to it.- Parameters:
data
- the data to add.
-
add
public void add(GenericSkeleton skel)
Adds to this skeleton all the parts of a given skeleton.- Parameters:
skel
- the existing skeleton from which to copy the parts.
-
appendToFirstPart
public void appendToFirstPart(String data)
Appends a string of data to the first skeleton part, a new part is created is none exists already.- Parameters:
data
- the string data to append.
-
append
public void append(String data)
Appends a string of data to this skeleton. The text is added to the current part if the current part is already a data part, a new part is created is necessary.- Parameters:
data
- the string data to append.
-
append
public void append(char data)
Appends a character data to this skeleton. The text is added to the current part if the current part is already a data part, a new part is created is necessary.- Parameters:
data
- the character data to append.
-
addContentPlaceholder
public void addContentPlaceholder(ITextUnit textUnit)
Adds to this skeleton a placeholder for the source content of the resource to which this skeleton is attached.- Parameters:
textUnit
- the resource object.
-
addContentPlaceholder
public void addContentPlaceholder(ITextUnit textUnit, LocaleId locId)
Adds to this skeleton a placeholder for the content (in a given locale) of the resource to which this skeleton is attached.- Parameters:
textUnit
- the resource object.locId
- the locale; use null if the reference is the source.
-
addValuePlaceholder
public GenericSkeletonPart addValuePlaceholder(INameable referent, String propName, LocaleId locId)
Adds to this skeleton a place-holder for the value of a property (in a given locale) of the resource to which this skeleton is attached.- Parameters:
referent
- the resource object.propName
- the property name.locId
- the locale; use null for the source; LocaleId.EMPTY for resource-level property.- Returns:
- the added skeleton part.
-
changeSelfReferents
public void changeSelfReferents(INameable newReferent)
Updates all the self-references to use the given referent.- Parameters:
newReferent
- the new referent to use.
-
addReference
public void addReference(IReferenceable referent)
Adds to this skeleton a reference to an existing resource send before the one to which this skeleton is attached to.- Parameters:
referent
- the resource to refer to.
-
setParent
public void setParent(IResource parent)
Description copied from interface:ISkeleton
Sets a parent of this skeleton object. The parent is the resource that attaches this skeleton with SetSkeleton(). Normally the IResorce implementations set themselves as a parent for the skeleton.
-
attachParent
public void attachParent(INameable parent)
Attaches a parent resource to a skeleton part.- Parameters:
parent
- the parent resource to attach.
-
getParts
public List<GenericSkeletonPart> getParts()
Gets a list of all the parts of this skeleton.- Returns:
- the list of all the parts of this skeleton.
-
setParts
protected void setParts(ArrayList<GenericSkeletonPart> list)
-
toString
public String toString()
Gets a string representation of the content of all the part of the skeleton. This should be used for display only.
-
getLastPart
public GenericSkeletonPart getLastPart()
Gets the last part of this skeleton, or null if there are none.- Returns:
- the last part of this skeleton, or null if there are none.
-
getFirstPart
public GenericSkeletonPart getFirstPart()
Gets the first part of this skeleton, or null if there are none.- Returns:
- the first part of this skeleton, or null if there are none.
-
copyFields
protected void copyFields(GenericSkeleton toSkel)
-
clone
public GenericSkeleton clone()
Clones this GenericSkeleton object. Shallow copy is provided as the cloned skeleton can be coupled with its original via the parent field. After the cloned skeleton is attached to a parent resource which implementation invokes ISkeleton.setParent(), the copy becomes deep as the parent fields are updated with new values thus decoupling the original and the clone.
-
-