Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/dtdbuilder/PublicMapping.java
32287 views
/*1* Copyright (c) 1998, 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.dtdbuilder;2627import javax.swing.text.html.parser.*;28import java.io.File;29import java.io.IOException;30import java.io.FileInputStream;31import java.io.InputStream;32import java.io.InputStreamReader;33import java.io.BufferedReader;34import java.util.Hashtable;3536/**37* A class for mapping public identifiers to locations.38* Note: I'm not sure if there is a more natural mapping39* then this. Maybe we should use properties instead?40*41* @author Arthur van Hoff42*/43final class PublicMapping {4445String baseStr;46Hashtable<String, String> tab = new Hashtable<>();4748/**49* Create a mapping.50*/51public PublicMapping (String baseStr, String mapFile) throws IOException {52// System.err.println("start loading " + baseStr);53this.baseStr = baseStr;54load(new FileInputStream(baseStr+mapFile));55// System.err.println("stop loading");56}5758/**59* Load a set of mappings from a stream.60*/61public void load(InputStream in) throws IOException {62InputStreamReader reader = new InputStreamReader(in);63BufferedReader data = new BufferedReader(reader);6465for (String ln = data.readLine() ; ln != null ; ln = data.readLine()) {66if (ln.startsWith("PUBLIC")) {67int len = ln.length();68int i = 6;69while ((i < len) && (ln.charAt(i) != '"')) i++;70int j = ++i;71while ((j < len) && (ln.charAt(j) != '"')) j++;72String id = ln.substring(i, j);73i = ++j;74while ((i < len) && ((ln.charAt(i) == ' ') || (ln.charAt(i) == '\t'))) i++;75j = i + 1;76while ((j < len) && (ln.charAt(j) != ' ') && (ln.charAt(j) != '\t')) j++;77String where = ln.substring(i, j);78put(id, baseStr + where);79}80}81data.close();82}8384/**85* Add a mapping from a public identifier to a path.86*/87public void put(String id, String str) {8889// System.err.println("ADD = '" + id + "' = " + str);90tab.put(id, str);91if (str.endsWith(".dtd")) {92int i = str.lastIndexOf(File.separator);93if (i >= 0) {94tab.put(str.substring(i + 1, str.length() - 4), str);95}96}97}9899/**100* Map a public identifier to a path.. You can also map101* a DTD file name (without the .dtd) to its path.102*/103public String get(String id) {104// System.err.println(" id = "+id);105return tab.get(id);106}107}108109110