KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
8 import java.io.Writer JavaDoc;
9
10 /**
11  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
12  * @since Feb 3, 2005
13  * @version $Id$
14  */

15 public class ArrayFormater implements ObjectFormater {
16   private String JavaDoc starItemSeparator_ ;
17   private String JavaDoc endItemSeparator_ ;
18   private ObjectFormater valueFormater_ ;
19   
20   public ArrayFormater(String JavaDoc startItemSeparator, String JavaDoc endItemSeparator) {
21     starItemSeparator_ = startItemSeparator ;
22     endItemSeparator_ = endItemSeparator;
23   }
24   
25   public void format(Writer JavaDoc w, Object JavaDoc obj) throws IOException JavaDoc {
26     Object JavaDoc[] list = (Object JavaDoc[]) obj ;
27     for(int i = 0; i < list.length ; i++) {
28       if(starItemSeparator_ != null) w.write(starItemSeparator_);
29       if(valueFormater_ == null )w.write(list[i].toString());
30       else valueFormater_.format(w, list[i]) ;
31       if(endItemSeparator_ != null)w.write(endItemSeparator_) ;
32     }
33   }
34   
35   public ObjectFormater setValueFormater(ObjectFormater formater) {
36     valueFormater_ = formater ;
37     return this ;
38   }
39 }
Popular Tags