1 5 package org.exoplatform.faces.search.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.ResourceBundle ; 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 22 public class SearchSummaryRenderer extends HtmlBasicRenderer { 23 24 public void encodeChildren(FacesContext context, UIComponent component) throws IOException { 25 UISearchSummary uiSummary = (UISearchSummary) component; 26 ResponseWriter w = context.getResponseWriter(); 27 ResourceBundle 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 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 title = dhandler.getTitle() ; 45 if(title == null || title.length() == 0) { 46 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 |