1 package be.dvw.administration.mvc.taglibs; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.dom4j.io.OutputFormat; 6 import org.dom4j.io.XMLWriter; 7 import org.dom4j.DocumentException; 8 9 import javax.servlet.jsp.JspException; 10 import javax.servlet.jsp.JspWriter; 11 import javax.servlet.jsp.tagext.BodyTagSupport; 12 import javax.xml.transform.TransformerException; 13 14 import be.dvw.administration.mvc.navigation.LeftMenu; 15 import be.dvw.administration.mvc.navigation.LeftMenuXSLTImpl; 16 import be.dvw.administration.services.scores.ScoreService; 17 import be.dvw.administration.services.scores.ScoreServiceCastorImpl; 18 import be.dvw.administration.services.instruments.InstrumentService; 19 import be.dvw.administration.services.instruments.InstrumentServiceCastorImpl; 20 import be.dvw.administration.Constants; 21 22 import java.io.UnsupportedEncodingException; 23 import java.io.IOException; 24 import java.io.Writer; 25 26 /*** 27 * Created by IntelliJ IDEA. 28 * User: Toon.Timbermont 29 * Date: Jul 30, 2005 30 * Time: 4:57:00 PM 31 * To change this template use File | Settings | File Templates. 32 */ 33 public class SummaryTag extends BodyTagSupport { 34 35 private static Log LOG = LogFactory.getLog(SummaryTag.class); 36 private String page; 37 private JspWriter out; 38 39 public int doStartTag() throws JspException { 40 41 LOG.debug("Executing the SummaryTag for page " + page); 42 43 try { 44 out = pageContext.getOut(); 45 46 if ( Constants.SCORE_PAGE.equals(page) ) 47 out.println(getScoresSummary()); 48 if ( Constants.INSTRUMENT_PAGE.equals(page)) 49 out.println(getInstrumentSummary()); 50 if ( Constants.PERSON_PAGE.equals(page) ) 51 out.println(getPersonSummary()); 52 53 } catch (IOException e) { 54 LOG.error("Exception", e); 55 } 56 57 return SKIP_BODY; 58 } 59 60 61 /*** 62 * Method giving the scores summary 63 * @return the phrase containing the key information about the scores. 64 * TODO make this phrase template & Il8N based 65 */ 66 private String getScoresSummary() 67 { 68 ScoreService scoreService = new ScoreServiceCastorImpl(); 69 StringBuffer strb = new StringBuffer(); 70 strb.append("Bibliotheek bevat "); 71 strb.append(scoreService.getTotalNumber()); 72 strb.append(" titels met een huidige waarde van "); 73 strb.append(scoreService.getCurrentValue()); 74 strb.append(" €"); 75 76 LOG.debug("Generated summary for scores"); 77 return strb.toString(); 78 } 79 80 /*** 81 * Method giving the Instrument summary 82 * @return the phrase containing the key information about the instruments. 83 * TODO make this phrase template & Il8N based 84 */ 85 private String getInstrumentSummary() 86 { 87 InstrumentService instrumentService = new InstrumentServiceCastorImpl(); 88 StringBuffer strb = new StringBuffer(); 89 strb.append("Instrumentarium bevat "); 90 strb.append(instrumentService.getTotalNumber()); 91 strb.append(" instrumenten met een huidige waarde van "); 92 strb.append(instrumentService.getCurrentValue()); 93 strb.append(" €"); 94 LOG.debug("Generated summary for instruments"); 95 return strb.toString(); 96 } 97 98 private String getPersonSummary() 99 { 100 return "Er zijn 214 personen waarvan 103 leden en 35 muzikanten opgeslaan"; 101 } 102 103 104 105 106 107 108 109 110 /*** 111 * Code executed when the tag reaches its end 112 * @return EVAL_PAGE : the rest of the page must be evaluated as well 113 * @throws JspException 114 */ 115 public int doEndTag() throws JspException { 116 return EVAL_PAGE; 117 } 118 119 public String getPage() { 120 return page; 121 } 122 123 public void setPage(String page) { 124 this.page = page; 125 } 126 }