|
|
|
@ -2,90 +2,77 @@ package org.gcube.portlets.user.workspace.client.util;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapaATisti.cnr.it
|
|
|
|
|
* May 8, 2014
|
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it May 8, 2014
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class GroupNameUtilSeparator {
|
|
|
|
|
|
|
|
|
|
private String stringSeparator = "/";
|
|
|
|
|
|
|
|
|
|
private String stringSeparator = "/";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param separator - the string separator
|
|
|
|
|
*/
|
|
|
|
|
public GroupNameUtilSeparator(String separator) {
|
|
|
|
|
|
|
|
|
|
if(separator!=null && !separator.isEmpty())
|
|
|
|
|
|
|
|
|
|
if (separator != null && !separator.isEmpty())
|
|
|
|
|
this.stringSeparator = separator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return Either subsequence of name from separatorStartIndex (including separator) to end,
|
|
|
|
|
* or name passed in input if split.length < separatorStartIndex
|
|
|
|
|
* @see main
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Return Either subsequence of name from separatorStartIndex (including
|
|
|
|
|
* separator) to end, or name passed in input if split.length is less of
|
|
|
|
|
* separatorStartIndex
|
|
|
|
|
*
|
|
|
|
|
* @param name
|
|
|
|
|
* @param separatorStartIndex - start index must be 1
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* name
|
|
|
|
|
* @param separatorStartIndex
|
|
|
|
|
* start
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* error
|
|
|
|
|
*/
|
|
|
|
|
public String getSubsequenceName(String name, int separatorStartIndex) throws Exception{
|
|
|
|
|
|
|
|
|
|
if(separatorStartIndex<1)
|
|
|
|
|
throw new Exception("Invalid start separator index: "+separatorStartIndex);
|
|
|
|
|
|
|
|
|
|
if(name==null)
|
|
|
|
|
throw new Exception("Invalid name: "+name);
|
|
|
|
|
|
|
|
|
|
public String getSubsequenceName(String name, int separatorStartIndex) throws Exception {
|
|
|
|
|
|
|
|
|
|
if (separatorStartIndex < 1)
|
|
|
|
|
throw new Exception("Invalid start separator index: " + separatorStartIndex);
|
|
|
|
|
|
|
|
|
|
if (name == null)
|
|
|
|
|
throw new Exception("Invalid name: " + name);
|
|
|
|
|
|
|
|
|
|
String[] split = name.split(stringSeparator);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*for (String sp : split) {
|
|
|
|
|
System.out.println("split: "+sp);
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(split==null || split.length==0)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* for (String sp : split) { System.out.println("split: "+sp); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (split == null || split.length == 0)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String displayName ="";
|
|
|
|
|
String displayName = "";
|
|
|
|
|
|
|
|
|
|
if (split.length > separatorStartIndex) {
|
|
|
|
|
|
|
|
|
|
if(split.length>separatorStartIndex){
|
|
|
|
|
|
|
|
|
|
for (int i = separatorStartIndex; i < split.length; i++) {
|
|
|
|
|
displayName+= stringSeparator+split[i];
|
|
|
|
|
displayName += stringSeparator + split[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
displayName = name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param args
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
GroupNameUtilSeparator filter = new GroupNameUtilSeparator("/");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String name = "/gcube/devsec/devVRE";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String displayedName = filter.getSubsequenceName(name, 2);
|
|
|
|
|
System.out.println("display name: "+displayedName);
|
|
|
|
|
|
|
|
|
|
System.out.println("display name: " + displayedName);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|