KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > pageflow > UrlWriterTag


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.bridge.jsp.taglib.pageflow;
11
12
13 import javax.servlet.jsp.JspTagException JavaDoc;
14 import javax.servlet.jsp.JspException JavaDoc;
15 import javax.servlet.jsp.tagext.Tag JavaDoc;
16
17 import org.mmbase.bridge.jsp.taglib.Writer;
18 import org.mmbase.util.Casting;
19 import org.mmbase.util.logging.*;
20
21
22 /**
23  * True write version of mm:url (named mm:link). Meaning that in it's body ${_} is available (and that the body is evaluated).
24  * Can be used with EL. ${_} is only evaluated when used.
25  *
26  * @author Michiel Meeuwissen
27  * @version $Id: UrlWriterTag.java,v 1.11 2006/06/23 15:29:06 michiel Exp $
28  * @since MMBase-1.8
29  */

30
31 public class UrlWriterTag extends UrlTag implements Writer {
32     private static final Logger log = Logging.getLoggerInstance(UrlTag.class);
33
34     public int doStartTag() throws JspTagException JavaDoc {
35         super.doStartTag();
36         helper.setValue(new Comparable JavaDoc() {
37                             final UrlWriterTag t = UrlWriterTag.this;
38                             public String JavaDoc toString() {
39                                 try {
40                                     String JavaDoc string = t.getUrl();
41                                     // this means that it is written to page by ${_} and that consequently there _must_ be a body.
42
// this is needed when body is not buffered.
43
haveBody();
44                                     return string;
45                                 } catch (Throwable JavaDoc e){
46                                     return e.toString();
47                                 }
48                             }
49                             public int compareTo(Object JavaDoc o) {
50                                 return toString().compareTo(Casting.toString(o));
51                             }
52                         });
53         return EVAL_BODY; // lets try _not_ buffering the body.
54
// this may give unexpected results if ${_} is not used (or another tag calling 'haveBody')
55
// But the whole goal is to use ${_} and it is a waist to buffer for nothing.
56
}
57
58
59     protected void initDoEndTag() throws JspTagException JavaDoc {
60
61     }
62
63     public int doAfterBody() throws JspException JavaDoc {
64         return helper.doAfterBody();
65     }
66
67
68 }
69
Popular Tags