/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.apache.kato.anttasks.xmlgen;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.DocErrorReporter;
import com.sun.javadoc.PackageDoc;
import com.sun.javadoc.RootDoc;
public class XMLJavaDocDoclet {
private static File output=null;
public static boolean validOptions(String options[][],
DocErrorReporter reporter) {
for (int i = 0; i < options.length; i++) {
String[] opt = options[i];
if (opt[0].equals("-outfile")) {
output = new File(opt[1]);
}
}
return output!=null;
}
public static boolean start(RootDoc root) throws IOException {
output.getParentFile().mkdirs();
Writer fw = new OutputStreamWriter(new FileOutputStream(output), "UTF8");
XMLWriter writer=new XMLWriter(fw);
writer.open();
//<String,PackageDoc>
Map map=new TreeMap();
ClassDoc[] classes=root.classes();
for(int i=0; i < classes.length; i++) {
ClassDoc c = classes[i];
PackageDoc owner=c.containingPackage();
String name=owner.name();
if(map.containsKey(name)==false) {
map.put(name,owner);
}
}
Iterator valueIt = map.values().iterator();
while (valueIt.hasNext()) {
PackageDoc p = (PackageDoc) valueIt.next();
writer.addPackageContents(p);
}
writer.close();
return true;
}
public static int optionLength(String option) {
if(option.equals("-outfile")) {
return 2;
}
return 2;
}
}