001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.doctool;
017:
018: import java.io.File;
019: import java.io.PrintStream;
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: /**
024: * Supports two-phase creation of {@link DocTool} objects.
025: */
026: public class DocToolFactory {
027:
028: private final List classPathEntries = new ArrayList();
029:
030: private String fileBase;
031:
032: private String fileType;
033:
034: private boolean generateHtml;
035:
036: private final List htmlFileBases = new ArrayList();
037:
038: private final List imagePathEntries = new ArrayList();
039:
040: private File outDir;
041:
042: private File overviewFile;
043:
044: private final List packageNameEntries = new ArrayList();
045:
046: private final List srcPathEntries = new ArrayList();
047:
048: private String title;
049:
050: public DocToolFactory() {
051: }
052:
053: public void addHtmlFileBase(String filebase) {
054: htmlFileBases.add(filebase);
055: }
056:
057: public void addToClassPath(String path) {
058: classPathEntries.add(new File(path));
059: }
060:
061: public void addToImagePath(String path) {
062: imagePathEntries.add(new File(path));
063: }
064:
065: public void addToPackages(String packageName) {
066: this .packageNameEntries.add(packageName);
067: }
068:
069: public void addToSourcePath(String path) {
070: srcPathEntries.add(new File(path));
071: }
072:
073: public DocTool create(PrintStream out, PrintStream err) {
074: File localOutDir = outDir;
075: if (localOutDir == null) {
076: localOutDir = new File(System.getProperty("user.dir"),
077: "out");
078: out.println("Using default output directory: "
079: + localOutDir.getAbsolutePath());
080: }
081:
082: File[] classPath = null;
083: File[] sourcePath = null;
084: String[] packageNames = null;
085: if (fileType != null) {
086: // Generating a doc set implies other settings.
087: //
088: if (fileBase == null) {
089: err
090: .println("A file base must be specified when generating doc");
091: return null;
092: }
093: // if (overviewFile == null) {
094: // err
095: // .println("An overview file must be specified when generating doc; if
096: // you don't have one, use this:");
097: // err.println("<html><body>");
098: // err.println(" " + fileBase + "documentation");
099: // err.println(" @id " + fileBase + "-doc");
100: // err.println(" @title Documentation for " + fileBase);
101: // err.println("</body></html>");
102: // return null;
103: // }
104: classPath = (File[]) classPathEntries.toArray(new File[0]);
105: sourcePath = (File[]) srcPathEntries.toArray(new File[0]);
106: packageNames = (String[]) packageNameEntries
107: .toArray(new String[0]);
108: }
109:
110: if (generateHtml) {
111: if (title == null) {
112: out
113: .println("A title must be specified when generating html");
114: return null;
115: }
116:
117: if (htmlFileBases.isEmpty()) {
118: out.println("No html filebases were specified");
119: return null;
120: }
121: }
122:
123: String[] htmlFileBaseArray = (String[]) htmlFileBases
124: .toArray(new String[0]);
125:
126: // Handle -imagepath
127: //
128: List localImagePathEntries = new ArrayList(imagePathEntries);
129: if (localImagePathEntries.isEmpty()) {
130: out
131: .println("No image path specified; using only the output dir");
132: }
133:
134: localImagePathEntries.add(localOutDir);
135: File[] imagePath = (File[]) imagePathEntries
136: .toArray(new File[0]);
137:
138: return new DocTool(out, err, localOutDir, generateHtml, title,
139: htmlFileBaseArray, fileType, fileBase, overviewFile,
140: sourcePath, classPath, packageNames, imagePath);
141: }
142:
143: public String getFileType() {
144: return fileType;
145: }
146:
147: public void setFileBase(String fileBase) {
148: this .fileBase = fileBase;
149: }
150:
151: public void setFileType(String fileType) {
152: this .fileType = fileType;
153: }
154:
155: public void setGenerateHtml(boolean generateHtml) {
156: this .generateHtml = generateHtml;
157: }
158:
159: public void setOutDir(String outDirPath) {
160: this .outDir = new File(outDirPath);
161: }
162:
163: public void setOverviewFile(String overviewFile) {
164: this .overviewFile = new File(overviewFile);
165: }
166:
167: public void setTitle(String title) {
168: this.title = title;
169: }
170: }
|