001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util;
022:
023: import com.liferay.portal.kernel.util.StringUtil;
024:
025: import java.io.BufferedReader;
026: import java.io.File;
027: import java.io.InputStreamReader;
028:
029: import org.apache.tools.ant.DirectoryScanner;
030:
031: /**
032: * <a href="Java2Html.java.html"><b><i>View Source</i></b></a>
033: *
034: * @author Brian Wing Shun Chan
035: *
036: */
037: public class Java2Html {
038:
039: public static void main(String[] args) {
040: new Java2Html(args);
041: }
042:
043: public Java2Html(String[] args) {
044: if ((args == null) || (args.length != 3)) {
045: return;
046: }
047:
048: String batchFile = args[0];
049: String srcDir = args[1];
050: String outDir = args[2];
051: //String projectName = args[3];
052:
053: //batchFile = StringUtil.replace(batchFile, "/", "\\");
054:
055: try {
056: Runtime rt = Runtime.getRuntime();
057:
058: String javaHome = System.getProperty("java.home");
059:
060: if (javaHome.endsWith("\\jre") || javaHome.endsWith("/jre")) {
061: javaHome = javaHome.substring(0, javaHome.length() - 4);
062: }
063:
064: Process p = rt.exec(batchFile + " -js " + srcDir + " -d "
065: + outDir + " -jd " + javaHome + "/docs/api"
066: + " http://java.sun.com/products/jdk/1.4/docs/api"
067: + " -m 4 -t 4" +
068: //" -n " + projectName +
069: " -nf");
070:
071: // Read process input to ensure process is completed before
072: // proceding to next step
073:
074: BufferedReader br = new BufferedReader(
075: new InputStreamReader(p.getInputStream()));
076:
077: while (br.readLine() != null) {
078: }
079:
080: br.close();
081:
082: DirectoryScanner ds = new DirectoryScanner();
083:
084: ds.setIncludes(new String[] { "**\\*.java.html" });
085: ds.setBasedir(outDir);
086:
087: ds.scan();
088:
089: String[] files = ds.getIncludedFiles();
090:
091: for (int i = 0; i < files.length; i++) {
092: File file = new File(outDir + "/" + files[i]);
093:
094: String content = FileUtil.read(file);
095:
096: content = StringUtil.replace(content, "stylesheet.css",
097: "java2html.css");
098:
099: FileUtil.write(file, content);
100: }
101: } catch (Exception e) {
102: e.printStackTrace();
103: }
104:
105: System.exit(0);
106: }
107:
108: }
|