KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > search > renderer > html > SearchSummaryRenderer


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.faces.search.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ResourceBundle JavaDoc;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ResponseWriter;
12 import org.exoplatform.faces.core.component.UIPageListIterator;
13 import org.exoplatform.faces.core.component.model.Parameter;
14 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
15 import org.exoplatform.faces.search.component.UISearchSummary;
16 import org.exoplatform.faces.search.component.model.DocumentDataHandler;
17 /**
18  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
19  * @since Aug 27, 2004
20  * @version $Id: SearchSummaryRenderer.java,v 1.3 2004/11/01 20:15:12 tuan08 Exp $
21  */

22 public class SearchSummaryRenderer extends HtmlBasicRenderer {
23
24   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
25     UISearchSummary uiSummary = (UISearchSummary) component;
26     ResponseWriter w = context.getResponseWriter();
27     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext());
28     UIPageListIterator uiPageIterator = uiSummary.getUIPageIterator() ;
29     Parameter docIndexParam = new Parameter(UISearchSummary.DOCUMENT_INDEX, "") ;
30     Parameter[] viewParams = {UISearchSummary.viewParam_, docIndexParam } ;
31     DocumentDataHandler dhandler = (DocumentDataHandler)uiPageIterator.getPageListDataHandler() ;
32     w.write("<div class='UISearchSummary'>") ;
33     String JavaDoc scoreIcon = res.getString("UISearchSummary.icon.score") ;
34     dhandler.begin() ;
35     if(dhandler.getAvailable() == 0){
36       w.write("<div class='no-results'>");
37       w. write(res.getString("UISearchSummary.label.no-result")) ;
38       w.write("</div>");
39     }
40     while(dhandler.nextRow()) {
41       docIndexParam.setValue(Integer.toString(dhandler.getCurrentRow())) ;
42       w.write("<div class='title'>");
43       w.write(res.getString("UISearchSummary.icon.module." + dhandler.getModule())) ;
44       String JavaDoc title = dhandler.getTitle() ;
45       if(title == null || title.length() == 0) {
46         //title = res.getString("UISearchSummary.lable.no-subject");
47
title = "No Subject";
48       }
49       linkRenderer_.render(w, uiSummary, title, viewParams);
50       w.write("</div>") ;
51       w.write("<div class='description'>");
52       w. write(dhandler.getDescription()) ;
53       w.write("</div>") ;
54       w.write("<div class='score'>") ;
55       int stars = Math.round(dhandler.getScore() * 5) ;
56       for(int i = 0; i < stars; i++) {
57         w.write(scoreIcon) ;
58       }
59       w.write("</div>") ;
60     }
61     dhandler.end() ;
62     w. write("<div style='text-align: right;'>") ;
63     uiPageIterator.encodeBegin(context) ;
64     w. write("</div>") ;
65     w.write("</div>") ;
66   }
67 }
Popular Tags