1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package build.tools.cldrconverter;
27
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.Set;
31 import org.xml.sax.Attributes;
32 import org.xml.sax.SAXException;
33 import org.xml.sax.SAXParseException;
34 import org.xml.sax.helpers.DefaultHandler;
35
36 /**
37 * This is an abstract class for general LDML parsing purpose.
38 * LDMLParseHandler, SupplementLDMLParseHandler, and NumberingLDMLParseHandler
39 * are the subclasses of this class.
40 */
41
42 abstract class AbstractLDMLHandler<V> extends DefaultHandler {
43 static final Map<String, String> DAY_OF_WEEK_MAP = new HashMap<>();
44 static {
45 DAY_OF_WEEK_MAP.put("sun", "1");
46 DAY_OF_WEEK_MAP.put("mon", "2");
47 DAY_OF_WEEK_MAP.put("tue", "3");
71 return data.get(key);
72 }
73
74 Set<String> keySet() {
75 return data.keySet();
76 }
77
78 /*
79 * It returns true if the data should be ignored based on the user
80 * defined acceptance level, which is listed with draft attribute in
81 * the cldr locale xml files.
82 * When the alt attribute is present, the data is always ignored since
83 * we always use the primary data
84 */
85 boolean isIgnored(Attributes attributes) {
86 if (attributes.getValue("alt") != null) {
87 return true;
88 }
89 String draftValue = attributes.getValue("draft");
90 if (draftValue != null) {
91 return CLDRConverter.draftType > CLDRConverter.DRAFT_MAP.get(draftValue);
92 }
93 return false;
94 }
95
96 void pushContainer(String qName, Attributes attributes) {
97 if (isIgnored(attributes) || currentContainer instanceof IgnoredContainer) {
98 currentContainer = new IgnoredContainer(qName, currentContainer);
99 } else {
100 currentContainer = new Container(qName, currentContainer);
101 }
102 }
103
104 void pushIgnoredContainer(String qName) {
105 currentContainer = new IgnoredContainer(qName, currentContainer);
106 }
107
108 void pushKeyContainer(String qName, Attributes attributes, String key) {
109 if (!pushIfIgnored(qName, attributes)) {
110 currentContainer = new KeyContainer(qName, currentContainer, key);
111 }
|
1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package build.tools.cldrconverter;
27
28 import build.tools.cldrconverter.CLDRConverter.DraftType;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.Set;
32 import org.xml.sax.Attributes;
33 import org.xml.sax.SAXException;
34 import org.xml.sax.SAXParseException;
35 import org.xml.sax.helpers.DefaultHandler;
36
37 /**
38 * This is an abstract class for general LDML parsing purpose.
39 * LDMLParseHandler, SupplementLDMLParseHandler, and NumberingLDMLParseHandler
40 * are the subclasses of this class.
41 */
42
43 abstract class AbstractLDMLHandler<V> extends DefaultHandler {
44 static final Map<String, String> DAY_OF_WEEK_MAP = new HashMap<>();
45 static {
46 DAY_OF_WEEK_MAP.put("sun", "1");
47 DAY_OF_WEEK_MAP.put("mon", "2");
48 DAY_OF_WEEK_MAP.put("tue", "3");
72 return data.get(key);
73 }
74
75 Set<String> keySet() {
76 return data.keySet();
77 }
78
79 /*
80 * It returns true if the data should be ignored based on the user
81 * defined acceptance level, which is listed with draft attribute in
82 * the cldr locale xml files.
83 * When the alt attribute is present, the data is always ignored since
84 * we always use the primary data
85 */
86 boolean isIgnored(Attributes attributes) {
87 if (attributes.getValue("alt") != null) {
88 return true;
89 }
90 String draftValue = attributes.getValue("draft");
91 if (draftValue != null) {
92 return DraftType.getDefault().ordinal() > DraftType.forKeyword(draftValue).ordinal();
93 }
94 return false;
95 }
96
97 void pushContainer(String qName, Attributes attributes) {
98 if (isIgnored(attributes) || currentContainer instanceof IgnoredContainer) {
99 currentContainer = new IgnoredContainer(qName, currentContainer);
100 } else {
101 currentContainer = new Container(qName, currentContainer);
102 }
103 }
104
105 void pushIgnoredContainer(String qName) {
106 currentContainer = new IgnoredContainer(qName, currentContainer);
107 }
108
109 void pushKeyContainer(String qName, Attributes attributes, String key) {
110 if (!pushIfIgnored(qName, attributes)) {
111 currentContainer = new KeyContainer(qName, currentContainer, key);
112 }
|