make/jdk/src/classes/build/tools/cldrconverter/SupplementalMetadataParseHandler.java
author naoto
Wed, 11 Apr 2018 09:14:47 -0700
changeset 49574 6a6ee36037ac
child 49918 8b9c78f0a712
permissions -rw-r--r--
8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone Reviewed-by: erikj, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49574
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     1
/*
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     4
 *
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    10
 *
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    15
 * accompanied this code).
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    16
 *
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    20
 *
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    23
 * questions.
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    24
 */
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    25
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    26
package build.tools.cldrconverter;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    27
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    28
import java.io.File;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    29
import java.io.IOException;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    30
import java.util.stream.Stream;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    31
import org.xml.sax.Attributes;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    32
import org.xml.sax.InputSource;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    33
import org.xml.sax.SAXException;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    34
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    35
/**
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    36
 * Handles parsing of files in Locale Data Markup Language for
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    37
 * SupplementalMetadata.xml
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    38
 */
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    39
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    40
class SupplementalMetadataParseHandler extends AbstractLDMLHandler<Object> {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    41
    @Override
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    42
    public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    43
        // avoid HTTP traffic to unicode.org
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    44
        if (systemID.startsWith(CLDRConverter.SPPL_LDML_DTD_SYSTEM_ID)) {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    45
            return new InputSource((new File(CLDRConverter.LOCAL_SPPL_LDML_DTD)).toURI().toString());
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    46
        }
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    47
        return null;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    48
    }
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    49
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    50
    @Override
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    51
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    52
        switch (qName) {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    53
        case "zoneAlias":
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    54
            String reason = attributes.getValue("reason");
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    55
            if ("deprecated".equals(reason)) {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    56
                put(attributes.getValue("type"), attributes.getValue("replacement"));
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    57
            }
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    58
            pushIgnoredContainer(qName);
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    59
            break;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    60
        default:
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    61
            // treat anything else as a container
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    62
            pushContainer(qName, attributes);
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    63
            break;
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    64
        }
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    65
    }
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    66
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    67
    public Stream<String> deprecatedMap() {
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    68
        return keySet().stream()
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    69
                .map(k -> String.format("        \"%s\", \"%s\",", k, get(k)))
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    70
                .sorted();
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    71
    }
6a6ee36037ac 8189784: Parsing with Java 9 AKST timezone returns the SystemV variant of the timezone
naoto
parents:
diff changeset
    72
}