1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.util;
24  
25  import com.liferay.portal.kernel.util.StringUtil;
26  
27  import java.io.BufferedReader;
28  import java.io.File;
29  import java.io.InputStreamReader;
30  
31  import org.apache.tools.ant.DirectoryScanner;
32  
33  /**
34   * <a href="Java2Html.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class Java2Html {
40  
41      public static void main(String[] args) {
42          new Java2Html(args);
43      }
44  
45      public Java2Html(String[] args) {
46          if ((args == null) || (args.length != 3)) {
47              return;
48          }
49  
50          String batchFile = args[0];
51          String srcDir = args[1];
52          String outDir = args[2];
53          //String projectName = args[3];
54  
55          //batchFile = StringUtil.replace(batchFile, "/", "\\");
56  
57          try {
58              Runtime rt = Runtime.getRuntime();
59  
60              String javaHome = System.getProperty("java.home");
61  
62              if (javaHome.endsWith("\\jre") || javaHome.endsWith("/jre")) {
63                  javaHome = javaHome.substring(0, javaHome.length() - 4);
64              }
65  
66              Process p = rt.exec(
67                  batchFile +
68                  " -js " + srcDir +
69                  " -d " + outDir +
70                  " -jd " + javaHome + "/docs/api" +
71                      " http://java.sun.com/products/jdk/1.4/docs/api" +
72                  " -m 4 -t 4" +
73                  //" -n " + projectName +
74                  " -nf");
75  
76              // Read process input to ensure process is completed before
77              // proceding to next step
78  
79              BufferedReader br = new BufferedReader(
80                  new InputStreamReader(p.getInputStream()));
81  
82              while (br.readLine() != null) {
83              }
84  
85              br.close();
86  
87              DirectoryScanner ds = new DirectoryScanner();
88  
89              ds.setIncludes(new String[] {"**\\*.java.html"});
90              ds.setBasedir(outDir);
91  
92              ds.scan();
93  
94              String[] files = ds.getIncludedFiles();
95  
96              for (int i = 0; i < files.length; i++) {
97                  File file = new File(outDir + "/" + files[i]);
98  
99                  String content = FileUtil.read(file);
100 
101                 content = StringUtil.replace(
102                     content, "java2html.css", "java2html.css");
103 
104                 FileUtil.write(file, content);
105             }
106         }
107         catch (Exception e) {
108             e.printStackTrace();
109         }
110 
111         System.exit(0);
112     }
113 
114 }