001/* 002 * Copyright (c) 2009-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.util; 031 032import java.io.File; 033import java.io.FileWriter; 034import java.io.IOException; 035 036/** 037 * a class to do some documentation tranformations 038 */ 039public class DocUtil { 040 /** 041 * the constructor 042 */ 043 public DocUtil(File dir) throws IOException { 044 File index = new File(dir, "index.html"); 045 String html = "<html><head><title>Documentation Index</title></head><body><ul>"; 046 FileWriter fw = new FileWriter(index); 047 fw.write(html); 048 fw.flush(); 049 createIndex(dir, fw); 050 fw.write("</ul></body></html>"); 051 fw.flush(); 052 fw.close(); 053 } 054 055 /** 056 * this method will index all of the documentation files it finds in the 057 * provided directory. the index will be placed in the dir with the other 058 * files 059 */ 060 public File[] createIndex(File dir, FileWriter fw) throws IOException { 061 File[] dirlist = dir.listFiles(); 062 System.out.println("dirlist size: " + dirlist.length); 063 for (int i = 0; i < dirlist.length; i++) { 064 System.out.println("dirlist: " + dirlist[i].getName()); 065 if (dirlist[i].isDirectory()) { 066 System.out.println("recursing"); 067 createIndex(dirlist[i], fw); 068 } else { 069 if (!dirlist[i].getName().equals("index.html")) { 070 System.out.println("writing"); 071 fw.write("<li><a href=\"" + dirlist[i].getPath() + "\">" 072 + dirlist[i].getName() + "</a></li>"); 073 } 074 } 075 } 076 System.out.println("returning"); 077 return null; 078 } 079 080 /** 081 * main 082 */ 083 public static void main(String[] args) { 084 String dir = args[0]; 085 File f = new File(dir); 086 if (!f.isDirectory()) { 087 System.err.println("The first argument must be a directory."); 088 System.exit(1); 089 } 090 try { 091 System.out.println("using directory: " + f.getAbsolutePath()); 092 new DocUtil(f); 093 } catch (Exception e) { 094 System.err.println("Could not complete the documentation: " 095 + e.getMessage()); 096 } 097 } 098 099}