KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > text > template > ListFormater


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.text.template;
6
7 import java.util.List JavaDoc ;
8 import java.io.IOException JavaDoc;
9 import java.io.Writer JavaDoc;
10
11 /**
12  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
13  * @since Feb 3, 2005
14  * @version $Id$
15  */

16 public class ListFormater implements ObjectFormater {
17   private String JavaDoc starItemSeparator_ ;
18   private String JavaDoc endItemSeparator_ ;
19   private ObjectFormater valueFormater_ ;
20   
21   public ListFormater(String JavaDoc startItemSeparator, String JavaDoc endItemSeparator) {
22     starItemSeparator_ = startItemSeparator ;
23     endItemSeparator_ = endItemSeparator;
24   }
25   
26   public void format(Writer JavaDoc w, Object JavaDoc obj) throws IOException JavaDoc {
27     List JavaDoc list = (List JavaDoc) obj ;
28     for(int i = 0; i < list.size() ; i++) {
29       Object JavaDoc 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