}
private void compile(File inDir, File outDir, File mapFile, String locale) throws HelpException {
String xmlFiles[] = inDir.list(new DialogUtils.ExtensionFilter("xml", false));
Transformer transformer = null;
DocumentBuilder db = null;
PrintWriter mapPrinter = null;
log.debug("generating help file with locale [" + locale + "]");
try {
log.debug("loading xml parser ..");
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (Exception e) {
throw new HelpException("Error while loading an XML parser", e);
}
try {
log.debug("creating map file [" + mapFile.getPath() + "] ..");
mapPrinter = new PrintWriter(new BufferedOutputStream(new FileOutputStream(mapFile)));
mapPrinter.println("<?xml version='1.0' encoding='ISO-8859-1' ?>");
mapPrinter.println(
"<!DOCTYPE map PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\""
+ " \"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n");
mapPrinter.println("<!-- Do not change, this file is automatically generated -->");
mapPrinter.println("<map version=\"1.0\">");
} catch (Exception e) {
throw new HelpException("Error while creating the map file", e);
}
try {
log.debug("loading transformer ..");
URL xslFile = getClass().getResource("/resources/xmlgui/help.xsl");
transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xslFile.openStream()));
transformer.setParameter("locale", locale);
} catch (Exception e) {
throw new HelpException("Error while constructing the transformer", e);
}
for (int i = 0; i < xmlFiles.length; i++) {
String xmlFile = xmlFiles[i];
String idName = xmlFile.substring(0, xmlFile.length() - 4);
File sourceFile = new File(inDir.getPath() + "/" + xmlFile);
File outputFile = new File(outDir.getPath() + "/" + idName + "." + locale + ".html");
Document document = null;
log.debug("loading help file [" + xmlFile + "]");
try {
document = db.parse(sourceFile);
mapPrinter.println(
" <mapID target=\""
+ document.getDocumentElement().getAttribute("id")
+ "\" url=\""
+ outputFile.getName()