use of org.eclipse.mylyn.wikitext.mediawiki.WikiTemplateResolver in project mylyn.docs by eclipse.
the class WikiToDocTask method execute.
@Override
public void execute() throws ConfigurationException {
if (dest == null) {
// $NON-NLS-1$
throw new ConfigurationException(Messages.getString("WikiToDocTask_specify_dest"));
}
if (wikiBaseUrl == null) {
// $NON-NLS-1$
throw new ConfigurationException(Messages.getString("WikiToDocTask_specify_wikiBaseUrl"));
}
if (paths.isEmpty()) {
// $NON-NLS-1$
throw new ConfigurationException(Messages.getString("WikiToDocTask_specify_paths"));
}
if (getInternalLinkPattern() == null) {
setInternalLinkPattern(computeDefaultInternalLinkPattern());
}
Set<String> pathNames = new HashSet<String>();
for (Path path : paths) {
if (path.name == null) {
// $NON-NLS-1$
throw new ConfigurationException(Messages.getString("WikiToDocTask_path_must_have_name"));
}
if (path.name != null) {
if (!pathNames.add(path.name)) {
throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_path_name_must_be_unique"), // $NON-NLS-1$
path.name));
}
}
if (!path.includeInUnifiedToc && path.getTocParentName() != null) {
throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_tocParentName_not_in_unified_toc"), // $NON-NLS-1$
path.name));
}
}
if (generateUnifiedToc) {
for (Path path : paths) {
if (path.getTocParentName() != null) {
if (!pathNames.contains(path.getTocParentName())) {
throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_unknown_tocParentName"), // $NON-NLS-1$
path.getTocParentName()));
}
}
}
}
MediaWikiLanguage markupLanguage = (MediaWikiLanguage) createMarkupLanguage();
WikiTemplateResolver templateResolver = new WikiTemplateResolver();
templateResolver.setWikiBaseUrl(wikiBaseUrl);
markupLanguage.getTemplateProviders().add(templateResolver);
markupLanguage.setTemplateExcludes(templateExcludes);
for (Stylesheet stylesheet : stylesheets) {
if (stylesheet.url == null && stylesheet.file == null) {
// $NON-NLS-1$
throw new BuildException(Messages.getString("WikiToDocTask_stylesheet_file_or_url"));
}
if (stylesheet.url != null && stylesheet.file != null) {
// $NON-NLS-1$
throw new BuildException(Messages.getString("WikiToDocTask_stylesheet_not_both"));
}
if (stylesheet.file != null) {
if (!stylesheet.file.exists()) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_stylesheet_file_not_exist"), stylesheet.file));
}
if (!stylesheet.file.isFile()) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_stylesheet_file_not_file"), stylesheet.file));
}
if (!stylesheet.file.canRead()) {
throw new BuildException(MessageFormat.format(Messages.getString("WikiToDocTask_stylesheet_file_cannot_read"), // $NON-NLS-1$
stylesheet.file));
}
}
}
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format("Cannot create dest folder: {0}", dest.getAbsolutePath()));
}
}
if (tocFile == null) {
// $NON-NLS-1$
tocFile = new File(dest, "toc.xml");
}
Map<String, String> pathNameToContent = new HashMap<String, String>();
Map<String, SplitOutlineItem> pathNameToOutline = new HashMap<String, SplitOutlineItem>();
for (Path path : paths) {
getProject().log(// $NON-NLS-1$
MessageFormat.format(Messages.getString("WikiToDocTask_fetching_content_for_page"), path.name), Project.MSG_VERBOSE);
URL pathUrl = computeRawUrl(path.name);
try {
Reader input = createInputReader(pathUrl);
try {
String content = readFully(input);
content = preprocessMarkup(path, content);
pathNameToContent.put(path.name, content);
final File targetFile = computeHtmlOutputFile(path);
SplitOutlineItem outline = computeOutline(path, markupLanguage, targetFile, content);
outline.setResourcePath(targetFile.getAbsolutePath());
pathNameToOutline.put(path.name, outline);
} finally {
input.close();
}
} catch (final IOException e) {
// $NON-NLS-1$
final String message = MessageFormat.format("Cannot read from {0}: {1}", pathUrl, e.getMessage());
throw new BuildException(message, e);
}
}
for (Path path : paths) {
// $NON-NLS-1$
getProject().log(// $NON-NLS-1$
MessageFormat.format(Messages.getString("WikiToDocTask_processing_page"), path.name), Project.MSG_DEBUG);
String markupContent = pathNameToContent.get(path.name);
if (isValidate()) {
performValidation(markupLanguage, path, markupContent);
}
Set<String> imageFilenames = null;
if (!fetchImages) {
// $NON-NLS-1$
getProject().log(Messages.getString("WikiToDocTask_skipping_images"), Project.MSG_WARN);
} else {
imageFilenames = fetchImages(markupLanguage, path);
}
markupToDoc(markupLanguage, path, markupContent, pathNameToOutline, imageFilenames);
if (path.isGenerateToc()) {
createToc(path, pathNameToOutline.get(path.name));
}
}
if (generateUnifiedToc) {
createToc(paths, pathNameToOutline);
}
}
Aggregations