duke@1: /* ohair@554: * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.util; duke@1: duke@1: import java.io.File; duke@1: duke@1: /** duke@1: * This class is used to represent a source path which can contain only duke@1: * directories no zip files. If a zip file is specified in the command line it duke@1: * will not get reflected in the SourcePath. duke@1: * duke@1: * This code is not part of an API. duke@1: * It is implementation that is subject to change. duke@1: * Do not use it as an API duke@1: * duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public duke@1: class SourcePath { duke@1: private final char dirSeparator = File.pathSeparatorChar; duke@1: duke@1: /** duke@1: * The original class path string duke@1: */ duke@1: private String pathstr; duke@1: duke@1: /** duke@1: * List of source path entries. Each entry is a directory. duke@1: */ duke@1: private File[] sourcePath; duke@1: duke@1: duke@1: /** duke@1: * Build a source path from the specified path string on the command line. duke@1: */ duke@1: public SourcePath(String pathstr) { duke@1: init(pathstr); duke@1: } duke@1: duke@1: /** duke@1: * Build a default source path from the path strings specified by duke@1: * the properties env.class.path. duke@1: */ duke@1: public SourcePath() { duke@1: init(System.getProperty("env.class.path")); duke@1: } duke@1: duke@1: /** duke@1: * Initialize the SourcePath File array, which will contain only the duke@1: * directory names from the given path string. duke@1: * duke@1: * @param pathstr Path String. duke@1: */ duke@1: private void init(String pathstr) { duke@1: if (pathstr == null || pathstr.length() == 0) { duke@1: pathstr = "."; duke@1: } duke@1: duke@1: int noOfFileSep = 0; duke@1: int index = 0; duke@1: this.pathstr = pathstr; // Save original class path string duke@1: duke@1: // Count the number of path separators duke@1: while ((index = pathstr.indexOf(dirSeparator, index)) != -1) { duke@1: noOfFileSep++; duke@1: index++; duke@1: } duke@1: // Build the source path duke@1: File[] tempPath = new File[noOfFileSep + 1]; duke@1: int tempPathIndex = 0; duke@1: int len = pathstr.length(); duke@1: int sepPos = 0; duke@1: for (index = 0; index < len; index = sepPos + 1) { duke@1: sepPos = pathstr.indexOf(dirSeparator, index); duke@1: if (sepPos < 0) { duke@1: sepPos = len; duke@1: } duke@1: File file = new File(pathstr.substring(index, sepPos)); duke@1: if (file.isDirectory()) { duke@1: tempPath[tempPathIndex++] = file; duke@1: } // if it is really a file, ignore it. duke@1: } duke@1: sourcePath = new File[tempPathIndex]; duke@1: System.arraycopy((Object)tempPath, 0, (Object)sourcePath, duke@1: 0, tempPathIndex); duke@1: } duke@1: duke@1: /** duke@1: * Find the specified directory in the source path. duke@1: * duke@1: * @param name Name of the directory to be searched for in the source path. duke@1: * @return File Return the directory if found else return null. duke@1: */ duke@1: public File getDirectory(String name) { duke@1: for (int i = 0; i < sourcePath.length; i++) { duke@1: File directoryNeeded = new File(sourcePath[i], name); duke@1: if (directoryNeeded.isDirectory()) { duke@1: return directoryNeeded; duke@1: } duke@1: } duke@1: return null; duke@1: } duke@1: duke@1: /** duke@1: * Return original source path string. duke@1: */ duke@1: public String toString() { duke@1: return pathstr; duke@1: } duke@1: }