1 13 package com.tonbeller.wcf.ui; 14 15 import java.util.Date ; 16 17 import org.w3c.dom.Document ; 18 import org.w3c.dom.Element ; 19 20 import com.tonbeller.wcf.format.FormatException; 21 import com.tonbeller.wcf.format.FormatHandler; 22 import com.tonbeller.wcf.format.Formatter; 23 import com.tonbeller.wcf.utils.XoplonNS; 24 25 29 public abstract class EditCtrl extends TypedCtrl { 30 31 32 public static void setValue(Element element, String value) { 33 XoplonNS.setAttribute(element, "value", value); 34 } 35 36 37 public static String getValue(Element element) { 38 return XoplonNS.getAttribute(element, "value"); 39 } 40 41 42 public static void setMaxLength(Element element, int maxLength) { 43 XoplonNS.setAttribute(element, "maxlength", String.valueOf(maxLength)); 44 } 45 46 47 public static int getMaxLength(Element element) { 48 return Integer.parseInt(XoplonNS.getAttribute(element, "maxlength")); 49 } 50 51 52 protected static Element createValueHolder(Document doc, String tagName, String type) { 53 Element retVal = XoplonCtrl.createCtrl(doc, tagName); 54 XoplonNS.setAttribute(retVal, "type", type); 55 return retVal; 56 } 57 58 59 protected static Element createValueHolder(Document doc, String tagName) { 60 return createValueHolder(doc, tagName, "string"); 61 } 62 63 64 public static void setValue(Formatter formatter, Element element, Object value) throws FormatException { 65 FormatHandler formatHandler = formatter.getHandler(getType(element)); 66 String formatString = getFormatString(element); 67 String valueString = formatHandler.format(value, formatString); 68 XoplonNS.setAttribute(element, "value", valueString); 69 } 70 71 72 public static Object getValue(Formatter formatter, Element element) throws FormatException { 73 String className = getType(element); 74 FormatHandler parser = formatter.getHandler(className); 75 String formatString = getFormatString(element); 76 return parser.parse(XoplonNS.getAttribute(element, "value"), formatString); 77 } 78 public static boolean getBoolean(Formatter fmt, Element elem) throws FormatException { 79 return ((Boolean )getValue(fmt, elem)).booleanValue(); 80 } 81 public static int getInt(Formatter fmt, Element elem) throws FormatException { 82 return ((Number )getValue(fmt, elem)).intValue(); 83 } 84 public static double getDouble(Formatter fmt, Element elem) throws FormatException { 85 return ((Number )getValue(fmt, elem)).doubleValue(); 86 } 87 public static Date getDate(Formatter fmt, Element elem) throws FormatException { 88 return (Date )getValue(fmt, elem); 89 } 90 public static String getString(Formatter fmt, Element elem) throws FormatException { 91 return getValue(elem); 92 } 93 94 public static void setBoolean(Formatter fmt, Element elem, boolean value) throws FormatException { 95 setValue(fmt, elem, new Boolean (value)); 96 } 97 public static void setInt(Formatter fmt, Element elem, int value) throws FormatException { 98 setValue(fmt, elem, new Integer (value)); 99 } 100 public static void setDouble(Formatter fmt, Element elem, double value) throws FormatException { 101 setValue(fmt, elem, new Double (value)); 102 } 103 public static void setDate(Formatter fmt, Element elem, Date value) throws FormatException { 104 setValue(fmt, elem, value); 105 } 106 public static void setString(Formatter fmt, Element elem, String value) throws FormatException { 107 setValue(elem, value); 108 } 109 } 110 | Popular Tags |