View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/PresetFormValuesTag.java,v 1.5 2006/01/25 16:35:23 hkollmann Exp $
3    * $Revision: 1.5 $
4    * $Date: 2006/01/25 16:35:23 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib;
25  
26  import java.util.HashMap;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.PageContext;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.dbforms.util.ReflectionUtil;
33  import org.dbforms.util.Util;
34  
35  import org.dbforms.interfaces.DbEventInterceptorData;
36  import org.dbforms.interfaces.IPresetFormValues;
37  import org.dbforms.interfaces.IAddProperty;
38  
39  /***
40   * 
41   * @author Henner Kollmann
42   * 
43   * &lt;db:presetFormValues class=""
44   */
45  public class PresetFormValuesTag extends AbstractScriptHandlerTag
46  		implements IAddProperty, javax.servlet.jsp.tagext.TryCatchFinally {
47  
48  	private static final String sessionKey = "dbforms.org.tag.PresetFormValuesTag";
49      private static Log logCat = LogFactory.getLog(IsWebEventTag.class.getName());
50  
51  	private String className = null;
52  
53  	private HashMap properties = new HashMap();
54  
55  	/***
56  	 * classname of a class implementing the CustomFormatter Interface
57  	 * 
58  	 * @param className
59  	 */
60  	public void setClassName(String className) {
61  		this.className = className;
62  	}
63  
64  	public static void presetFormValues(DbEventInterceptorData data)
65  			throws JspException {
66  		PageContext pageContext = (PageContext) data
67  				.getAttribute(DbEventInterceptorData.PAGECONTEXT);
68  		if (pageContext != null) {
69  			PresetFormValuesTag tag = (PresetFormValuesTag) pageContext
70  					.getAttribute(sessionKey);
71  			if (tag != null) {
72  				tag.privatePresetFormValues(data);
73  			}
74  		}
75  	}
76  
77  	public void privatePresetFormValues(DbEventInterceptorData data)
78  			throws JspException {
79  		if (!Util.isNull(className)) {
80  			try {
81  				IPresetFormValues cf = (IPresetFormValues) ReflectionUtil
82  						.newInstance(className);
83  				cf.presetFormValues(properties, data);
84  			} catch (Exception e) {
85  			   logCat.error("privatePresetFormValues", e);
86  			}
87  		}
88  	}
89  
90  	public int doStartTag() throws JspException {
91  		properties.clear();
92  		return super.doStartTag();
93  	}
94  
95  	/***
96  	 * DOCUMENT ME!
97  	 * 
98  	 * @return DOCUMENT ME!
99  	 */
100 	public int doEndTag() throws JspException {
101 		if (!Util.isNull(className)) {
102 			pageContext.setAttribute(sessionKey, this);
103 		}
104 		return EVAL_PAGE;
105 	}
106 
107 	/***
108 	 * DOCUMENT ME!
109 	 */
110 	public void doFinally() {
111 		super.doFinally();
112 	}
113 
114 	public void addProperty(String name, String value) {
115 		properties.put(name, value);
116 	}
117 
118 }