Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/cldrconverter/MetaZonesParseHandler.java
32287 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.cldrconverter;2627import java.io.File;28import java.io.IOException;29import org.xml.sax.Attributes;30import org.xml.sax.InputSource;31import org.xml.sax.SAXException;3233class MetaZonesParseHandler extends AbstractLDMLHandler<String> {34private String tzid, metazone;3536MetaZonesParseHandler() {37}3839@Override40public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {41// avoid HTTP traffic to unicode.org42if (systemID.startsWith(CLDRConverter.SPPL_LDML_DTD_SYSTEM_ID)) {43return new InputSource((new File(CLDRConverter.LOCAL_SPPL_LDML_DTD)).toURI().toString());44}45return null;46}4748// metaZone: ID -> metazone49// per locale: ID -> names, metazone -> names50@Override51public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {52switch (qName) {53case "timezone":54tzid = attributes.getValue("type");55pushContainer(qName, attributes);56break;5758case "usesMetazone":59// Ignore any historical zone names (for now)60if (attributes.getValue("to") == null) {61metazone = attributes.getValue("mzone");62}63pushIgnoredContainer(qName);64break;6566case "version":67case "generation":68pushIgnoredContainer(qName);69break;7071default:72// treat anything else as a container73pushContainer(qName, attributes);74break;75}76}7778@Override79public void endElement(String uri, String localName, String qName) throws SAXException {80assert qName.equals(currentContainer.getqName()) : "current=" + currentContainer.getqName() + ", param=" + qName;81switch (qName) {82case "timezone":83if (tzid == null || metazone == null) {84throw new InternalError();85}86put(tzid, metazone);87break;88}89currentContainer = currentContainer.getParent();90}91}929394