1 12 package org.openbravo.xmlEngine; 13 14 import java.util.Hashtable ; 15 import java.text.DecimalFormat ; 16 import java.text.DecimalFormatSymbols ; 17 18 import org.xml.sax.helpers.DefaultHandler ; 19 import org.xml.sax.Attributes ; 20 21 import org.apache.log4j.Logger ; 22 23 public class FormatRead extends DefaultHandler { 24 Hashtable <String , FormatCouple> hasFormats; 25 26 static Logger log4jFormatRead = Logger.getLogger(FormatRead.class); 27 28 public FormatRead(Hashtable <String , FormatCouple> hasFormats) { 29 this.hasFormats = hasFormats; 30 } 31 32 public void startElement(java.lang.String uri, 33 java.lang.String name, 34 java.lang.String qName, 35 Attributes amap) { 36 log4jFormatRead.info("FormatRead: startElement is called:" + name); 37 38 if (name.equals("Number")) { 39 String formatName = null; 40 char decimal = '.'; 41 char grouping = ','; 42 String formatOutput = null; 43 String formatInternal = null; 44 45 for (int i = 0; i < amap.getLength(); i++) { 46 log4jFormatRead.debug(" FormatRead (attribute list): attribute name=" + amap.getQName(i) + " value=" + amap.getValue(i)); 47 if (amap.getQName(i).equals("name")) { 48 formatName = amap.getValue(i); 49 } else if (amap.getQName(i).equals("decimal")) { 50 decimal = amap.getValue(i).charAt(0); 51 } else if (amap.getQName(i).equals("grouping")) { 52 grouping = amap.getValue(i).charAt(0); 53 } else if (amap.getQName(i).equals("formatOutput")) { 54 formatOutput = amap.getValue(i); 55 } else if (amap.getQName(i).equals("formatInternal")) { 56 formatInternal = amap.getValue(i); 57 } 58 } 59 DecimalFormatSymbols dfs = new DecimalFormatSymbols (); 60 dfs.setDecimalSeparator(decimal); 61 dfs.setGroupingSeparator(grouping); 62 DecimalFormatSymbols dfsEsp = new DecimalFormatSymbols (); 63 dfsEsp.setDecimalSeparator('.'); 64 dfsEsp.setGroupingSeparator(','); 65 FormatCouple fc; 66 fc= new FormatCouple(new DecimalFormat (formatOutput,dfs), new DecimalFormat (formatInternal,dfsEsp)); 67 hasFormats.put(formatName, fc); 68 } } 70 } 71 72 | Popular Tags |