Get Tree Path
1625 ワード
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer();
sb.insert(0, "/leaf4");
sb.insert(0, "/leaf3");
sb.insert(0, "/leaf2");
sb.insert(0, "/leaf1");
sb.insert(0, "/root");
System.out.println(sb) ;
System.out.println(new Test().getResourcePath("10010101"));
}
public String getResourcePath(String resourceid){
// Dto dto = new BaseDto();
String _resourceid = null ;
StringBuffer path = new StringBuffer() ;
_resourceid = resourceid ;
int testid = 1 ;
while(_resourceid!="01"){
// dto = (BaseDto) g4Dao.queryForObject("Rms.queryEaResourceByResourceID", _resourceid );
// _resourceid = dto.getAsString("resourceid") ;
_resourceid = getResource(testid) ;
if(path!=null && path.length()!=0)
path = path.insert(0,"/").insert(0, _resourceid);
testid++ ;
}
return path.insert(0,"/").toString() ;
}
public String getResource(int resourceid){
switch(resourceid){
case 1:
return "10010101" ;
case 2:
return "100101" ;
case 3:
return "1001" ;
case 4:
return "01" ;
}
return "01" ;
}
}