KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > text > template > xhtml > LongTextPopupFormater


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

15 public class LongTextPopupFormater implements ObjectFormater {
16   private int maxLength_ ;
17   
18   public LongTextPopupFormater(int textSize) {
19     maxLength_ = textSize ;
20   }
21   
22   public void format(Writer JavaDoc w, Object JavaDoc obj) throws IOException JavaDoc {
23     String JavaDoc value = obj.toString() ;
24     if(value.length() < maxLength_) {
25       w.write(value) ;
26     } else {
27       w.write("<span title='");
28       w.write(value.toString()) ;
29       w.write("'>") ;
30       w.write(value.substring(0 , maxLength_)) ;
31       w.write(".....") ;
32       w.write("</span>") ;
33     }
34   }
35 }
Popular Tags