KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > xmlEngine > FormatRead


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.xmlEngine;
13
14 import java.util.Hashtable JavaDoc;
15 import java.text.DecimalFormat JavaDoc;
16 import java.text.DecimalFormatSymbols JavaDoc;
17
18 import org.xml.sax.helpers.DefaultHandler JavaDoc;
19 import org.xml.sax.Attributes JavaDoc;
20
21 import org.apache.log4j.Logger ;
22
23 public class FormatRead extends DefaultHandler JavaDoc {
24   Hashtable JavaDoc<String JavaDoc, FormatCouple> hasFormats;
25
26   static Logger log4jFormatRead = Logger.getLogger(FormatRead.class);
27
28   public FormatRead(Hashtable JavaDoc<String JavaDoc, FormatCouple> hasFormats) {
29     this.hasFormats = hasFormats;
30   }
31
32   public void startElement(java.lang.String JavaDoc uri,
33       java.lang.String JavaDoc name,
34       java.lang.String JavaDoc qName,
35       Attributes JavaDoc amap) {
36     log4jFormatRead.info("FormatRead: startElement is called:" + name);
37
38     if (name.equals("Number")) {
39       String JavaDoc formatName = null;
40       char decimal = '.';
41       char grouping = ',';
42       String JavaDoc formatOutput = null;
43       String JavaDoc 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 JavaDoc dfs = new DecimalFormatSymbols JavaDoc();
60       dfs.setDecimalSeparator(decimal);
61       dfs.setGroupingSeparator(grouping);
62       DecimalFormatSymbols JavaDoc dfsEsp = new DecimalFormatSymbols JavaDoc();
63       dfsEsp.setDecimalSeparator('.');
64       dfsEsp.setGroupingSeparator(',');
65       FormatCouple fc;
66       fc= new FormatCouple(new DecimalFormat JavaDoc(formatOutput,dfs), new DecimalFormat JavaDoc(formatInternal,dfsEsp));
67       hasFormats.put(formatName, fc);
68     } //number
69
}
70 }
71
72
Popular Tags