@Override public ITocContribution[] getTocContributions(String locale) { List<ITocContribution> contributions = new ArrayList<>(); TocFile[] tocFiles = getTocFiles(locale); TocFileParser parser = new TocFileParser(); for (int i=0;i<tocFiles.length;++i) { try { ITocContribution toc = parser.parse(tocFiles[i]); contributions.add(toc); } catch (Throwable t) { String locationInfo = ""; //$NON-NLS-1$ if (t instanceof SAXParseException) { SAXParseException spe = (SAXParseException) t; locationInfo = " at line " + spe.getLineNumber() //$NON-NLS-1$ + ", column " + spe.getColumnNumber(); //$NON-NLS-1$ } String pluginId = tocFiles[i].getPluginId(); String file = tocFiles[i].getFile(); String msg = "Error reading help table of contents file /\"" //$NON-NLS-1$ + ResourceLocator.getErrorPath(pluginId, file, locale) + locationInfo + "\" (skipping file)"; //$NON-NLS-1$ HelpPlugin.logError(msg, t); } } return contributions.toArray(new ITocContribution[contributions.size()]); }
public static String[] collectExtraDocuments(TocFile tocFile) { String dir = HrefUtil.normalizeDirectoryHref(tocFile.getPluginId(), tocFile.getExtraDir()); String locale = tocFile.getLocale();
public TocContribution parse(TocFile tocFile) throws IOException, SAXException, ParserConfigurationException { if (reader == null) { reader = new DocumentReader(); } try (InputStream in = tocFile.getInputStream()) { if (in != null) { Toc toc = (Toc) reader.read(in); TocContribution contribution = new TocContribution(); contribution.setCategoryId(tocFile.getCategory()); contribution.setContributorId(tocFile.getPluginId()); contribution.setExtraDocuments(DocumentFinder.collectExtraDocuments(tocFile)); contribution.setId(HrefUtil.normalizeHref(tocFile.getPluginId(), tocFile.getFile())); contribution.setLocale(tocFile.getLocale()); contribution.setToc(toc); contribution.setPrimary(tocFile.isPrimary()); return contribution; } else { throw new FileNotFoundException(); } } } }