0N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.util;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/Aimport java.lang.String;
0N/Aimport java.util.StringTokenizer;
0N/Aimport java.net.URL;
0N/Aimport java.net.URLClassLoader;
0N/Aimport java.net.MalformedURLException;
0N/A
0N/A/**
0N/A * A utility class for handle path list
0N/A *
0N/A */
0N/Apublic class PathList {
0N/A /**
0N/A * Utility method for appending path from pathFrom to pathTo.
0N/A *
0N/A * @param pathTo the target path
0N/A * @param pathSource the path to be appended to pathTo
0N/A * @return the resulting path
0N/A */
0N/A public static String appendPath(String pathTo, String pathFrom) {
0N/A if (pathTo == null || pathTo.length() == 0) {
0N/A return pathFrom;
0N/A } else if (pathFrom == null || pathFrom.length() == 0) {
0N/A return pathTo;
0N/A } else {
0N/A return pathTo + File.pathSeparator + pathFrom;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Utility method for converting a search path string to an array
0N/A * of directory and JAR file URLs.
0N/A *
0N/A * @param path the search path string
0N/A * @return the resulting array of directory and JAR file URLs
0N/A */
0N/A public static URL[] pathToURLs(String path) {
0N/A StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
0N/A URL[] urls = new URL[st.countTokens()];
0N/A int count = 0;
0N/A while (st.hasMoreTokens()) {
0N/A URL url = fileToURL(new File(st.nextToken()));
0N/A if (url != null) {
0N/A urls[count++] = url;
0N/A }
0N/A }
0N/A if (urls.length != count) {
0N/A URL[] tmp = new URL[count];
0N/A System.arraycopy(urls, 0, tmp, 0, count);
0N/A urls = tmp;
0N/A }
0N/A return urls;
0N/A }
0N/A
0N/A /**
0N/A * Returns the directory or JAR file URL corresponding to the specified
0N/A * local file name.
0N/A *
0N/A * @param file the File object
0N/A * @return the resulting directory or JAR file URL, or null if unknown
0N/A */
0N/A private static URL fileToURL(File file) {
0N/A String name;
0N/A try {
0N/A name = file.getCanonicalPath();
0N/A } catch (IOException e) {
0N/A name = file.getAbsolutePath();
0N/A }
0N/A name = name.replace(File.separatorChar, '/');
0N/A if (!name.startsWith("/")) {
0N/A name = "/" + name;
0N/A }
0N/A // If the file does not exist, then assume that it's a directory
0N/A if (!file.isFile()) {
0N/A name = name + "/";
0N/A }
0N/A try {
0N/A return new URL("file", "", name);
0N/A } catch (MalformedURLException e) {
0N/A throw new IllegalArgumentException("file");
0N/A }
0N/A }
0N/A}