📄 formsubmission.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * FormSubmission.java * * Created on 14 April 2003, 00:32 */package crms.form;import java.util.*;import java.text.*;import java.lang.reflect.*;import crms.util.*;import org.w3c.dom.*;/** * * @author dmurphy */public class FormSubmission { private HashMap results = new HashMap(); private String formName = null; public static SimpleDateFormat df = new SimpleDateFormat("d MMMM, yyyy"); public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); /** Creates a new instance of FormSubmission */ public FormSubmission() { } public void setFieldValue(String fieldName, String value) { results.put(fieldName.toLowerCase(), value); } public void setFormName(String name) { this.formName = name; } public String getFormName() { return formName; } public StringBuffer toXML() { StringBuffer buf = new StringBuffer(); Iterator it = results.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String value = (String) results.get(key); buf.append("<form-submit>\n"); buf.append(" <fields>\n"); buf.append(" <field name='" + key + "'>"); buf.append(value); buf.append("</field>\n"); buf.append(" </fields>\n"); buf.append("</form-submit>\n"); } return buf; } public Iterator fieldNames() { return results.keySet().iterator(); } public String getFieldValue(String fieldName) { String value = (String) results.get(fieldName); return value; } public static FormSubmission buildFromXML(Node formSubmitNode) { FormSubmission result = new FormSubmission(); NodeList fields = XMLUtil.getChildNodesNamed("fields","field", formSubmitNode); for (int i=0; i < fields.getLength(); i++) { Node fieldNode = fields.item(i); String name = XMLUtil.getAttributeValue("name", fieldNode); String value = XMLUtil.getTextForNode(fieldNode); result.setFieldValue(name, value); } return result; } public void applyTo(Object object) { Method[] methods = object.getClass().getDeclaredMethods(); for (int i=0; i < methods.length; i++) { Method method = methods[i]; if (method.getName().startsWith("set")) { String propertyName = method.getName().substring(3).toLowerCase(); String fieldValue = (String)results.get(propertyName); if (fieldValue == null) { continue; } Class[] types = method.getParameterTypes(); Object args[] = {}; if (types[0].equals(Integer.class)) { args = new Object[] { new Integer(fieldValue) }; } else if (types[0].equals(Date.class)) { Date dateValue = null; try { if ( propertyName.indexOf("time") >= 0) { dateValue = tf.parse(fieldValue); } else { dateValue = df.parse(fieldValue); } } catch (ParseException ex) { throw new RuntimeException(ex); } args = new Object[] { dateValue }; } else { args = new Object[] { fieldValue }; } try { method.invoke(object, args); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { throw new RuntimeException(ex); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -