KickJava   Java API By Example, From Geeks To Geeks.

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


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.IUAElement;
19 import org.eclipse.help.internal.UAElement;
20 import org.eclipse.help.internal.dynamic.DocumentReader;
21 import org.eclipse.help.internal.index.Index;
22 import org.eclipse.help.internal.index.IndexContribution;
23 import org.xml.sax.SAXException JavaDoc;
24 import org.xml.sax.helpers.DefaultHandler JavaDoc;
25
26 /*
27  * Converts indexes serialized by the IndexServlet on remote help server back
28  * into model objects. The XML is similar to index XML files but not identical
29  * (it has all indexes in one, has indexContribution elements, etc.
30  */

31 public class RemoteIndexParser extends DefaultHandler JavaDoc {
32
33     private DocumentReader reader;
34     
35     /*
36      * Parses the given serialized indexes and returns generated model objects.
37      */

38     public IndexContribution[] parse(InputStream JavaDoc in) throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
39         if (reader == null) {
40             reader = new DocumentReader();
41         }
42         UAElement root = reader.read(in);
43         IUAElement[] children = root.getChildren();
44         IndexContribution[] contributions = new IndexContribution[children.length];
45         for (int i=0;i<children.length;++i) {
46             UAElement child = (UAElement)children[i];
47             IndexContribution contribution = new IndexContribution();
48             contribution.setId(child.getAttribute("id")); //$NON-NLS-1$
49
contribution.setLocale(child.getAttribute("locale")); //$NON-NLS-1$
50
contribution.setIndex((Index)child.getChildren()[0]);
51             contributions[i] = contribution;
52         }
53         return contributions;
54     }
55 }
56
Popular Tags