Skip to main content
summaryrefslogtreecommitdiffstats
blob: d179a574ae306f7b92271aaafa0cde9cf2eb1f04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*******************************************************************************
 * Copyright (c) 2005, 2015 Intel Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Intel Corporation - initial API and implementation
 *     IBM Corporation - 122967 [Help] Remote help system
 *     IBM Corporation - Use IndexDocumentReader
 *     IBM Corporation - [Bug 297921
 *******************************************************************************/
package org.eclipse.help.internal.index;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.help.internal.dynamic.DocumentReader;
import org.xml.sax.SAXException;

public class IndexFileParser {

	private DocumentReader reader;

    public IndexContribution parse(IndexFile indexFile) throws IOException, SAXException, ParserConfigurationException {
		if (reader == null) {
			reader = new IndexDocumentReader();
		}
		InputStream in = indexFile.getInputStream();
		if (in != null) {
			try {
				Index index = (Index)reader.read(in);
				IndexContribution contrib = new IndexContribution();
		    	contrib.setId('/' + indexFile.getPluginId() + '/' + indexFile.getFile());
				contrib.setIndex(index);
				contrib.setLocale(indexFile.getLocale());
				return contrib;
			} finally {
				in.close();
			}
		}
    	else {
    		throw new FileNotFoundException();
    	}
    }
}

Back to the top