KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > toc > TocFileParser


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.toc;
12
13 import java.io.FileNotFoundException JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16
17 import javax.xml.parsers.ParserConfigurationException JavaDoc;
18
19 import org.eclipse.help.internal.dynamic.DocumentReader;
20 import org.xml.sax.SAXException JavaDoc;
21 import org.xml.sax.helpers.DefaultHandler JavaDoc;
22
23 public class TocFileParser extends DefaultHandler JavaDoc {
24
25     private DocumentReader reader;
26
27     public TocContribution parse(TocFile tocFile) throws IOException JavaDoc, SAXException JavaDoc, ParserConfigurationException JavaDoc {
28         if (reader == null) {
29             reader = new DocumentReader();
30         }
31         InputStream JavaDoc 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 JavaDoc();
46         }
47     }
48 }
49
Popular Tags