KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > taglibs > util > StrToObj


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.taglibs.util;
14
15 import javax.servlet.jsp.PageContext JavaDoc;
16 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
17
18 import org.apache.commons.lang.StringUtils;
19
20
21 /**
22  * @author Vinzenz Wyser
23  * @author Fabrizio Giustina
24  * @version $Revision $ ($Author $)
25  */

26 public class StrToObj extends BodyTagSupport JavaDoc {
27
28     /**
29      * Stable serialVersionUID.
30      */

31     private static final long serialVersionUID = 222L;
32
33     private String JavaDoc var;
34
35     private String JavaDoc delims;
36
37     public void setVar(String JavaDoc var) {
38         this.var = var;
39     }
40
41     public void setDelims(String JavaDoc delims) {
42         this.delims = delims;
43     }
44
45     /**
46      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
47      */

48     public int doEndTag() {
49         String JavaDoc str = getBodyContent().getString();
50         if (StringUtils.isNotEmpty(str)) {
51             String JavaDoc[] obj = str.split(StringUtils.defaultString(this.delims, "\n")); //$NON-NLS-1$
52
pageContext.setAttribute(this.var, obj, PageContext.PAGE_SCOPE);
53
54         }
55         else {
56             pageContext.setAttribute(this.var, StringUtils.EMPTY, PageContext.PAGE_SCOPE);
57         }
58         return EVAL_PAGE;
59     }
60
61     /**
62      * @see javax.servlet.jsp.tagext.BodyTagSupport#release()
63      */

64     public void release() {
65         this.var = null;
66         this.delims = null;
67         super.release();
68     }
69 }
70
Popular Tags