* Examples, where workingCopyLabel is "wc": *
* "Myfile.txt" becomes "Myfile wc.txt", "Myfile" becomes "Myfile wc". *
* In the event that fileName is empty or null, the workingCopyLabel is used for the new working copy name *
* Example: "" becomes "wc".
*
* @param name String
* @param workingCopyLabel String
* @return String
*/
public static String createWorkingCopyName(String name, final String workingCopyLabel)
{
if (workingCopyLabel != null && workingCopyLabel.length() != 0)
{
if (name != null && name.length() != 0)
{
int index = name.lastIndexOf(EXTENSION_CHARACTER);
if (index > 0)
{
// Insert the working copy label before the file extension
name = name.substring(0, index) + " " + workingCopyLabel + name.substring(index);
}
else
{
// Simply append the working copy label onto the end of the existing name
name = name + " " + workingCopyLabel;
}
}
else
{
name = workingCopyLabel;
}
}
else
{
throw new IllegalArgumentException("workingCopyLabel is null or empty");
}
return name;
}
/**
* Get original name from the working copy name and the cm:workingCopyLabel
* that was used to create it.
*
* @param workingCopyName String
* @param workingCopyLabel String
* @return original name
*/
private String getNameFromWorkingCopyName(String workingCopyName, String workingCopyLabel)
{
String workingCopyLabelRegEx = workingCopyLabel.replaceAll("\\(", "\\\\(");
workingCopyLabelRegEx = workingCopyLabelRegEx.replaceAll("\\)", "\\\\)");
if (workingCopyName.contains(" " + workingCopyLabel))
{
workingCopyName = workingCopyName.replaceFirst(" " + workingCopyLabelRegEx, "");
}
else if (workingCopyName.contains(workingCopyLabel))
{
workingCopyName = workingCopyName.replaceFirst(workingCopyLabelRegEx, "");
}
return workingCopyName;
}
/**
* Has the working copy name changed compared to the original name
*
* @param workingCopyName working copy name
* @param origName original name
* @param wcLabel that was inserted into origName to create the original working copy name
* @return true => if changed
*/
private boolean hasWorkingCopyNameChanged(String workingCopyName, String origName, String wcLabel)
{
String origWorkingCopyName = createWorkingCopyName(origName, wcLabel);
return !workingCopyName.equals(origWorkingCopyName);
}
/**
* Get the working copy label.
*
* @return the working copy label
*/
public static String getWorkingCopyLabel()
{
return I18NUtil.getMessage(MSG_WORKING_COPY_LABEL);
}
@Override
public