FileDocCategorySizeDatePackage
DirectoryManager.javaAPI DocExample8141Wed Apr 19 11:17:16 BST 2000com.sun.tools.doclets

DirectoryManager

public class DirectoryManager extends Object
Handle the directory creations and the path string generations.
since
JDK1.2
author
Atul M Dambalkar

Fields Summary
public static final String
urlfileseparator
The file separator string, "/", used in the formation of the URL path.
public static final String
fileseparator
The actual platform dependent file separator.
Constructors Summary
Methods Summary
public static voidcreateDirectory(java.lang.String path)
Given a path string create all the directories in the path. For example, if the path string is "java/applet", the method will create directory "java" and then "java/applet" if they don't exist. The file separator string "/" is platform dependent system property.

param
path Directory path string.

        if (path == null || path.length() == 0) {
            return;
        }
        File dir = new File(path);
        try {
            if (dir.exists()) {
                return;
            } else {
                if (dir.mkdirs()) {
                    return;
                } else {
                    HtmlDocWriter.configuration.message.error(
                                  "doclet.Unable_to_create_directory_0", path);
                    throw new DocletAbortException();
                }
            }
        } catch (SecurityException exc) {
            exc.printStackTrace();
            System.exit(1);
        } catch (DocletAbortException exc) {
            exc.printStackTrace();
            System.exit(1);
        } 
    
public static java.lang.StringcreatePathString(com.sun.javadoc.PackageDoc pd)
Given a PackageDoc, return its URL path string.

param
pd PackageDoc
see
#getPath(String)


                       
         
        if (pd == null) {
            return "";
        }
        return getPath(pd.name());
    
public static java.lang.StringcreatePathString(com.sun.javadoc.ClassDoc cd)
Given a ClassDoc, return its URL path string.

param
cd ClassDoc
see
#getPath(String)

        if (cd == null) {
            return "";
        }
        PackageDoc pd = cd.containingPackage();
        return (pd == null)? "": getPath(pd.name());
    
public static java.lang.StringgetBackPath(java.lang.String path)
Given a URL path string, this will return the reverse path. For example, if the URL path string is "java/lang" the method will return URL specific string "../".

        if (path == null || path.length() == 0) {
            return "";
        }
        StringBuffer backpath = new StringBuffer();
        for (int i = 0; i < path.length(); i++) {
            char ch = path.charAt(i);
            if (ch == '/") {
                backpath.append("..");
                backpath.append(urlfileseparator);
            }       // there is always a trailing fileseparator
        }
        return backpath.toString();
    
public static java.lang.StringgetDirectoryPath(com.sun.javadoc.PackageDoc pd)
Given a PackageDoc, return the directory name. If name of the package is "java.lang" then path will be "java/lang". If name of the package is "no_interior_dot" then path will be just "no_interior_dot". The file separator used is a platform dependent file separator.

param
pd PackageDoc
return
String The directory path for the package.

        if (pd == null) {
            return "";
        }
        String name = pd.name();
        StringBuffer pathstr = new StringBuffer();
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            if (ch == '.") {
                pathstr.append(fileseparator);
            } else {
                pathstr.append(ch);
            }
        }
        return pathstr.toString();
    
public static java.lang.StringgetPath(java.lang.String name)
Given any string, return the URL path string. For example, if the string is "com.sun.javadoc" then the URL path string will be "com/sun/javadoc" The URL path separator "/"(which is not platform specific) is used to separate the directory names.

param
name String.
return
String URL path string.

        if (name == null || name.length() == 0) {
            return "";
        }
        StringBuffer pathstr = new StringBuffer();
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            if (ch == '.") {
                pathstr.append(urlfileseparator);
            } else {
                pathstr.append(ch);
            }
        }
        return pathstr.toString();
    
public static java.lang.StringgetPathToClass(com.sun.javadoc.ClassDoc cd)
Given a class name return the full path to the class file. For example, if ClassDoc passed is for "java.lang.Object" then the string returned is "java/lang/Object.html".

param
cd ClassDoc.

        return getPathToPackage(cd.containingPackage(), cd.name() + ".html");
    
public static java.lang.StringgetPathToPackage(com.sun.javadoc.PackageDoc pd, java.lang.String filename)
Given a package name and a file name, return the full path to that file. For example, if PackageDoc passed is for "java.lang" and the filename passed is "package-summary.html", then the string returned is "java/lang/package-summary.html".

param
pd PackageDoc.
param
filename File name to be appended to the path of the package.

        StringBuffer buf = new StringBuffer();  
        String pathstr = createPathString(pd);
        if (pathstr.length() > 0) {
            buf.append(pathstr);
            buf.append("/");
        }
        buf.append(filename);
        return buf.toString();
    
public static java.lang.StringgetRelativePath(java.lang.String from, java.lang.String to)
Given two strings/(package names) return the relative path from one string to another. For example, if the parameter string "from" is "java.lang" and parameter string "to" is "java.applet" the method will return string "../../java/applet". The relative path returned is URL specific, and hence it uses "/" as file separator.

param
from "from" this directory(package) location.
param
to "to" this directory(package) location.
return
String relative path from "from" to "to".
see
#getRelativePath(String)
see
#getPath(String)

        StringBuffer pathstr = new StringBuffer();
        pathstr.append(getRelativePath(from));
        pathstr.append(getPath(to));
        pathstr.append(urlfileseparator);
        return pathstr.toString();
    
public static java.lang.StringgetRelativePath(java.lang.String from)
Given string(package name), return relative path string. For example, if the string "from" is "java.lang" the method will return "../../" relative path, till the directory, in which is output is getting generated. The returned string is URL specific. String from is nothing but the directory location

param
from "from" this directory(package) location.
return
String relative path from "from".
see
#getRelativePath(String, String)

        if (from == null || from.length() == 0) {
            return "";
        }
        StringBuffer pathstr = new StringBuffer();
        for (int i = 0; i < from.length(); i++) {
            char ch = from.charAt(i);
            if (ch == '.") {
                pathstr.append(".." + urlfileseparator);
            }     
        }
        pathstr.append(".." + urlfileseparator);
        return pathstr.toString();