1 11 package org.eclipse.help.internal.toc; 12 13 import java.io.FileNotFoundException ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 17 import javax.xml.parsers.ParserConfigurationException ; 18 19 import org.eclipse.help.internal.dynamic.DocumentReader; 20 import org.xml.sax.SAXException ; 21 import org.xml.sax.helpers.DefaultHandler ; 22 23 public class TocFileParser extends DefaultHandler { 24 25 private DocumentReader reader; 26 27 public TocContribution parse(TocFile tocFile) throws IOException , SAXException , ParserConfigurationException { 28 if (reader == null) { 29 reader = new DocumentReader(); 30 } 31 InputStream in = tocFile.getInputStream(); 32 if (in != null) { 33 Toc toc = (Toc)reader.read(in); 34 TocContribution contribution = new TocContribution(); 35 contribution.setCategoryId(tocFile.getCategory()); 36 contribution.setContributorId(tocFile.getPluginId()); 37 contribution.setExtraDocuments(DocumentFinder.collectExtraDocuments(tocFile)); 38 contribution.setId(HrefUtil.normalizeHref(tocFile.getPluginId(), tocFile.getFile())); 39 contribution.setLocale(tocFile.getLocale()); 40 contribution.setToc(toc); 41 contribution.setPrimary(tocFile.isPrimary()); 42 return contribution; 43 } 44 else { 45 throw new FileNotFoundException (); 46 } 47 } 48 } 49 | Popular Tags |