All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sunlabs.brazil.template.FormTemplate Maven / Gradle / Ivy

The newest version!
/*
 * FormTemplate.java
 *
 * Brazil project web application toolkit,
 * export version: 2.3 
 * Copyright (c) 1998-2006 Sun Microsystems, Inc.
 *
 * Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License Version 
 * 1.0 (the "License"). You may not use this file except in compliance with 
 * the License. A copy of the License is included as the file "license.terms",
 * and also available at http://www.sun.com/
 * 
 * The Original Code is from:
 *    Brazil project web application toolkit release 2.3.
 * The Initial Developer of the Original Code is: suhler.
 * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
 * All Rights Reserved.
 * 
 * Contributor(s): cstevens, rinaldo, suhler.
 *
 * Version:  2.4
 * Created by suhler on 98/10/26
 * Last modified by suhler on 06/11/13 15:05:11
 *
 * Version Histories:
 *
 * 2.4 06/11/13-15:05:11 (suhler)
 *   substitute all unknown attributes
 *
 * 2.3 05/11/28-09:15:16 (suhler)
 *   add 
to allow the value derived from the request * properties to be looked-up with the desired prefix * * 2.2 02/12/19-11:36:50 (suhler) * run size= through format.subst * * 2.1 02/10/01-16:36:42 (suhler) * version change * * 1.23 02/07/24-10:46:09 (suhler) * doc updates * * 1.22 02/05/01-11:28:41 (suhler) * fix sccs version info * * 1.21 02/04/25-13:43:56 (suhler) * doc fixes * * 1.20 01/09/10-14:02:51 (suhler) * bug in value=${..} substitutions * * 1.19 01/09/03-20:21:30 (suhler) * fixed bug in ${...} processing * * 1.18 01/08/28-20:55:38 (suhler) * input fields to ${...} substitutions on value= if corrosponding * property isn't set * * 1.17 01/08/07-11:00:38 (suhler) * do ${...} substitutions in value attribute of

* If the enclosing <form> tag has the attribute "prepend", then * "prepend" is tacked on the front of each variable name before its * value is looked-up. The "prepend" attribute is then removed from the * form tag. * * @author Stephen Uhler * @version @(#)FormTemplate.java 2.4 */ public class FormTemplate extends Template { String selectName; // The name of the current select variable String selectValue; // The name of the current select variable value String prepend = ""; // What to prepend the values with int total; // total for elements examined int changed; // elements whose initial values have been changed /** * Save a reference to our request properties. */ public boolean init(RewriteContext hr) { selectName = null; total = 0; changed = 0; return true; } /** * Look for a "prepend" attrubute, remember its value, then remove it * from the tag. */ public void tag_form(RewriteContext hr) { String p = hr.get("prepend"); if (p != null) { hr.remove("prepend"); if (p.endsWith(".")) { prepend = p; } else { prepend = p + "."; } } else { prepend = ""; } hr.substAttributeValues(); } /** * Forget about the "prepend" value */ public void tag_slash_form(RewriteContext hr) { prepend = ""; } /** * Look for <input name=[x] value=[v]> and replace the * value with the entry in the request properties. If no value is supplied, * no substitution is done. * If value contains any ${..} constructs, the substituted * value is used instead of the value in the corrosponding request property. */ public void tag_input(RewriteContext hr) { total++; String origValue = hr.get("value"); if (origValue != null) { hr.put("value", origValue); } String name = hr.get("name"); if (name == null) { return; } else { hr.put("name", name); } String value = hr.request.props.getProperty(prepend + name); if (value == null) { return; } changed++; String type = hr.get("type", false); if ("radio".equals(type) || "checkbox".equals(type)) { log(hr,type + " " + value + " ? " + hr.get("value", false)); if (value.equals(origValue)) { hr.put("checked", ""); } else { hr.remove("checked"); } } else { hr.put("value", value); String size = hr.get("size"); if (size != null) { hr.put("size",size); } } } /** * Remember the variable name for the next group of option tags. */ public void tag_select(RewriteContext hr) { selectName = hr.get("name"); if (selectName != null) { selectValue = hr.request.props.getProperty(prepend + selectName); hr.put("name", selectName); log(hr, "For selection (" + selectName + ") have value :" + selectValue); } } /** * Forget the variable name for the next group of option tags */ public void tag_slash_select(RewriteContext hr) { selectName = null; } /** * Look at the option tag, set the "selected" attribute as needed. * In order for this to work, the VALUE tag *must* be used * Do ${...} substitutions on the value. */ public void tag_option(RewriteContext hr) { String value = hr.get("value"); if (value != null) { hr.put("value", value); } if (selectName == null || selectValue == null || value == null) { return; } if (value.equals(selectValue)) { hr.put("selected", ""); } else { hr.remove("selected"); } } /** * This is for debugging only !! */ public boolean done(RewriteContext hr) { log(hr, hr.request.url + " (form template) " + changed + "/" + total + " changed"); return true; } /** * simple interface to server logging */ private void log(RewriteContext hr, String msg) { hr.request.log(Server.LOG_DIAGNOSTIC, hr.prefix + "formTemplate: " + msg); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy