/* * @(#)DirectoryManager.java 1.5 98/04/28 * * Copyright 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ package com.sun.tools.doclets; import com.sun.javadoc.*; import java.io.*; import java.lang.*; /** * Handle the directory creations and the path string generations. * * @since JDK1.2 * @author Atul M Dambalkar */ public class DirectoryManager { public static final String fileseparator = "/"; public static final String pathseparator = File.separator; public static String createPathString(PackageDoc pd) { if (pd == null) { return "./"; } return getPath(pd.name()); } public static String createPathString(ClassDoc cd) { if (cd == null) { return "./"; } return getPath(cd.containingPackage().name()); } public static String getDirectoryPath(PackageDoc pd) { 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(pathseparator); } else { pathstr.append(ch); } } return pathstr.toString(); } public static String getPath(String name) { 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(fileseparator); } else { pathstr.append(ch); } } return pathstr.toString(); } public static String getRelativePath(String from, String to) { StringBuffer pathstr = new StringBuffer(); pathstr.append(getRelativePath(from)); pathstr.append(getPath(to)); pathstr.append(fileseparator); return pathstr.toString(); } public static String getRelativePath(String from) { 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(".." + fileseparator); } } pathstr.append(".." + fileseparator); return pathstr.toString(); } public static void createDirectory(String path) { 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); } } }