1 16 package org.apache.myfaces.custom.rssticker; 17 18 import java.io.IOException ; 19 20 import javax.faces.application.FacesMessage; 21 import javax.faces.component.UIComponent; 22 import javax.faces.context.FacesContext; 23 import javax.faces.context.ResponseWriter; 24 25 import org.apache.commons.digester.rss.Channel; 26 import org.apache.commons.digester.rss.Item; 27 28 import org.apache.myfaces.renderkit.RendererUtils; 29 import org.apache.myfaces.renderkit.html.HTML; 30 import org.apache.myfaces.renderkit.html.HtmlRenderer; 31 import org.apache.myfaces.renderkit.html.HtmlRendererUtils; 32 import org.apache.myfaces.util.MessageUtils; 33 34 44 public class HtmlRssTickerRenderer extends HtmlRenderer { 45 46 public static final String RENDERER_TYPE = "org.apache.myfaces.Ticker"; 47 private static final String NO_CONNECTION = "org.apache.myfaces.ticker.NOCONNECTION"; 48 49 public void encodeEnd(FacesContext facesContext, UIComponent component) 50 throws IOException { 51 RendererUtils.checkParamValidity(facesContext, component, 52 HtmlRssTicker.class); 53 54 HtmlRssTicker tickerComponent = (HtmlRssTicker) component; 55 56 ResponseWriter writer = facesContext.getResponseWriter(); 57 58 HtmlRendererUtils.writePrettyLineSeparator(facesContext); 59 60 tableBegin(facesContext, tickerComponent, writer); 61 rowBody(facesContext, tickerComponent, writer); 62 tableEnd(facesContext, tickerComponent, writer); 63 64 } 65 66 72 private void tableEnd(FacesContext facesContext, 73 HtmlRssTicker tickerComponent, ResponseWriter writer) 74 throws IOException { 75 writer.endElement(HTML.TBODY_ELEM); 76 writer.endElement(HTML.TABLE_ELEM); 77 } 78 79 84 private void rowBody(FacesContext facesContext, 85 HtmlRssTicker tickerComponent, ResponseWriter writer) 86 throws IOException { 87 88 Channel channel = tickerComponent.getChannel(); 89 90 if (channel != null) { 92 writer.startElement(HTML.THEAD_ELEM, tickerComponent); 93 writer.startElement(HTML.TR_ELEM, tickerComponent); 94 writer.startElement(HTML.TH_ELEM, tickerComponent); 95 96 writer.write((channel.getTitle() != null) ? channel.getTitle() : ""); 97 98 writer.endElement(HTML.TH_ELEM); 99 writer.endElement(HTML.TR_ELEM); 100 writer.endElement(HTML.THEAD_ELEM); 101 102 Item[] columns = tickerComponent.items(); 103 for (int i = 0; i < columns.length; i++) { 104 105 rowBegin(facesContext, tickerComponent, writer); 106 107 writer.startElement(HTML.TD_ELEM, tickerComponent); 108 writer.write("<a HREF=\"" + columns[i].getLink() 109 + "\" target=\"_new\">"); 110 writer.write(columns[i].getTitle()); 111 writer.write("</a>"); 112 writer.endElement(HTML.TD_ELEM); 113 rowEnd(facesContext, tickerComponent, writer); 114 } 115 } else { 116 FacesMessage facesMessage = MessageUtils.getMessage(FacesMessage.SEVERITY_INFO,NO_CONNECTION,null); 119 writer.write(facesMessage.getSummary()); 120 writer.write("<br/>"); 121 writer.write(facesMessage.getDetail()); 122 } 123 } 124 125 130 private void tableBegin(FacesContext facesContext, 131 HtmlRssTicker tickerComponent, ResponseWriter writer) 132 throws IOException { 133 writer.startElement(HTML.TABLE_ELEM, tickerComponent); 134 writer.startElement(HTML.TBODY_ELEM, tickerComponent); 135 } 136 137 142 private void rowEnd(FacesContext facesContext, 143 HtmlRssTicker tickerComponent, ResponseWriter writer) 144 throws IOException { 145 writer.endElement(HTML.TR_ELEM); 146 } 147 148 153 private void rowBegin(FacesContext facesContext, 154 HtmlRssTicker tickerComponent, ResponseWriter writer) 155 throws IOException { 156 writer.startElement(HTML.TR_ELEM, tickerComponent); 157 } 158 159 } | Popular Tags |