KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > base > remote > RemoteTocParser


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.base.remote;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import javax.xml.parsers.ParserConfigurationException JavaDoc;
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 JavaDoc;
25
26 public class RemoteTocParser {
27
28     private DocumentReader reader;
29     
30     public ITocContribution[] parse(InputStream JavaDoc in) throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
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 JavaDoc[] extraDocuments = new String JavaDoc[contribChildren.length - 1];
41             for (int j=0;j<extraDocuments.length;++j) {
42                 extraDocuments[j] = ((UAElement)contribChildren[j + 1]).getAttribute("href"); //$NON-NLS-1$
43
}
44             TocContribution contribution = new TocContribution();
45             contribution.setCategoryId(child.getAttribute("categoryId")); //$NON-NLS-1$
46
contribution.setContributorId(child.getAttribute("contributorId")); //$NON-NLS-1$
47
contribution.setExtraDocuments(extraDocuments);
48             contribution.setId(child.getAttribute("id")); //$NON-NLS-1$
49
contribution.setLocale(child.getAttribute("locale")); //$NON-NLS-1$
50
contribution.setPrimary("true".equals(child.getAttribute("isPrimary"))); //$NON-NLS-1$//$NON-NLS-2$
51
contribution.setToc((Toc)contribChildren[0]);
52             contributions[i] = contribution;
53         }
54         return contributions;
55     }
56 }
57
Popular Tags