if (conf.getProxyUser().length() > 0) {
System.setProperty(HttpClient.PROXY_USER_KEY, conf.getProxyUser());
System.setProperty(HttpClient.PROXY_PASSWORD_KEY, conf.getProxyPassword());
}
}
LogUtil logUtil = new LogUtil(LogUtil.DEFAULT_LOGGER_NAMES);
logUtil.setLevel(conf.getLogLevel());
logUtil.setUseParentHandler(false);
String logFile = conf.getLogFile();
FileHandler fileHandler = null;
if (conf.isLogEnabled() && logFile.length() > 0) {
try {
fileHandler = new FileHandler(logFile, conf.getMaxLogSize() * 1024, 1, true);
fileHandler.setFormatter(new LogFormatter());
logUtil.addHandler(fileHandler);
} catch (IOException e) {
logger.warning("Could not create log file " + e.getMessage());
}
}
for (int i = 0; (i < jxlDocuments.length) && running; i++) {
try {
net.sf.jpluck.jxl.Document jxlDocument = jxlDocuments[i];
if (jxlDocument.getUserAgent() != null) {
System.setProperty("http.agent", jxlDocument.getUserAgent());
} else {
System.setProperty("http.agent", conf.getUserAgent());
}
String s = "Starting conversion: " + jxlDocument.getName();
if (jxlDocument.getJXL() != null) {
File f = jxlDocument.getJXL().getFile();
if (f != null) {
s += " (" + f.getAbsolutePath() + ")";
}
logger.info(s);
}
jxlDocument.init();
fireConversionStarted(jxlDocument, i + 1, jxlDocuments.length);
String name = jxlDocument.getName();
if (jxlDocument.isRemoveAccents()) {
name = Database.convertToDatabaseName(name);
}
Document document = new Document(name, ClientConfiguration.getDefault().getCompression());
Date date = jxlDocument.getDate();
if (date != null) {
document.setCreationDate(date);
document.setModificationDate(date);
}
spider = new Spider(document, jxlDocument, httpCache, cookieStore, maxConnections,
Spider.DEFAULT_MAX_PARSE_THREADS, httpTimeout);
try {
for (Iterator iterator = spiderListenerList.iterator(); iterator.hasNext();) {
SpiderListener spiderListener = (SpiderListener) iterator.next();
spider.addSpiderListener(spiderListener);
}
if (!running) {
break;
}
spider.run();
} finally {
for (Iterator iterator = spiderListenerList.iterator(); iterator.hasNext();) {
SpiderListener spiderListener = (SpiderListener) iterator.next();
spider.removeSpiderListener(spiderListener);
}
}
boolean success = false;
if (!running) {
break;
}
String uri = jxlDocument.getStartingURI().toString();
if (document.contains(uri)) {
try {
document.setHome(uri);
document.setOutputEncoding(jxlDocument.getOutputEncoding());
document.setIncludeImageAltText(jxlDocument.isIncludeAltText());
document.setCategories(jxlDocument.getCategories());
document.setDefaultLinkColor(jxlDocument.getLinkColor());
document.setUnresolvedLinkColor(jxlDocument.getUnresolvedLinkColor());
document.setRemoveUnresolvedLinks(jxlDocument.isRemoveUnresolvedLinks());
document.setIncludeURIInfo(jxlDocument.isIncludeURIInfo());
document.setBackup(jxlDocument.isSetBackupBit());
document.setEncoding(jxlDocument.getOutputEncoding());
// Sort bookmarks for sites
if (jxlDocument instanceof Site) {
Site site = (Site) jxlDocument;
if (site.isSortBookmarks()) {
document.sortBookmarks();
}
}
fireGenerationStarted(jxlDocument);
for (Iterator it = recordListenerList.iterator(); it.hasNext();) {
document.addRecordListener((RecordListener) it.next());
}
document.setFilename(jxlDocument.getFilename());
long size = destination.write(document);
jxlDocument.converted(size);
fireGenerationCompleted(jxlDocument);
logger.info("Completed conversion: " + jxlDocument.getName());
success = true;
} catch (Exception e) {
logger.severe("Could not generate document: " + e.getClass() + " " + e.getMessage());
e.printStackTrace();
} finally {
for (Iterator it = recordListenerList.iterator(); it.hasNext();) {
document.removeRecordListener((RecordListener) it.next());
}
}
} else {
logger.severe(jxlDocument.getName() + ": could not load starting URI " + jxlDocument.getUri() +
". Document cannot be generated.");
}
if (!success) {
failCount++;
}
fireConversionCompleted(jxlDocument, i + 1, jxlDocuments.length, success);
} catch (Exception e) {
logger.severe("Error initializing transformation:\n" + e.getClass().getName() + ": " +
e.getMessage());
e.printStackTrace();
}
TemporaryFile.clean();
}
closeHttpCache();
fireStatusMessage("Completed");
running = false;
conversionActive = false;
fireConversionFinished();
logUtil.close();
if (fileHandler != null) {
logUtil.removeHandler(fileHandler);
}
if ((window != null) && (failCount == 0) && ClientConfiguration.getDefault().isAutoCloseConversion()) {
window.hide();
}
}