1 11 package org.eclipse.help.internal.base.remote; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 16 import javax.xml.parsers.ParserConfigurationException ; 17 18 import org.eclipse.help.ITocContribution; 19 import org.eclipse.help.IUAElement; 20 import org.eclipse.help.internal.UAElement; 21 import org.eclipse.help.internal.dynamic.DocumentReader; 22 import org.eclipse.help.internal.toc.Toc; 23 import org.eclipse.help.internal.toc.TocContribution; 24 import org.xml.sax.SAXException ; 25 26 public class RemoteTocParser { 27 28 private DocumentReader reader; 29 30 public ITocContribution[] parse(InputStream in) throws ParserConfigurationException , SAXException , IOException { 31 if (reader == null) { 32 reader = new DocumentReader(); 33 } 34 UAElement root = reader.read(in); 35 IUAElement[] children = root.getChildren(); 36 ITocContribution[] contributions = new ITocContribution[children.length]; 37 for (int i=0;i<children.length;++i) { 38 UAElement child = (UAElement)children[i]; 39 IUAElement[] contribChildren = child.getChildren(); 40 String [] extraDocuments = new String [contribChildren.length - 1]; 41 for (int j=0;j<extraDocuments.length;++j) { 42 extraDocuments[j] = ((UAElement)contribChildren[j + 1]).getAttribute("href"); } 44 TocContribution contribution = new TocContribution(); 45 contribution.setCategoryId(child.getAttribute("categoryId")); contribution.setContributorId(child.getAttribute("contributorId")); contribution.setExtraDocuments(extraDocuments); 48 contribution.setId(child.getAttribute("id")); contribution.setLocale(child.getAttribute("locale")); contribution.setPrimary("true".equals(child.getAttribute("isPrimary"))); contribution.setToc((Toc)contribChildren[0]); 52 contributions[i] = contribution; 53 } 54 return contributions; 55 } 56 } 57 | Popular Tags |