1 5 package org.exoplatform.text.template; 6 7 import java.util.List ; 8 import java.io.IOException ; 9 import java.io.Writer ; 10 11 16 public class ListFormater implements ObjectFormater { 17 private String starItemSeparator_ ; 18 private String endItemSeparator_ ; 19 private ObjectFormater valueFormater_ ; 20 21 public ListFormater(String startItemSeparator, String endItemSeparator) { 22 starItemSeparator_ = startItemSeparator ; 23 endItemSeparator_ = endItemSeparator; 24 } 25 26 public void format(Writer w, Object obj) throws IOException { 27 List list = (List ) obj ; 28 for(int i = 0; i < list.size() ; i++) { 29 Object valueObj = list.get(i) ; 30 if(starItemSeparator_ != null) w.write(starItemSeparator_); 31 if(valueFormater_ == null )w.write(valueObj.toString()); 32 else valueFormater_.format(w, valueObj) ; 33 if(endItemSeparator_ != null)w.write(endItemSeparator_) ; 34 } 35 } 36 37 public ObjectFormater setValueFormater(ObjectFormater formater) { 38 valueFormater_ = formater ; 39 return this ; 40 } 41 } | Popular Tags |