1 package org.apidesign.bck2brwsr.htmlpage;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Collections;
8 import java.util.TreeMap;
9 import javax.xml.parsers.DocumentBuilder;
10 import javax.xml.parsers.DocumentBuilderFactory;
11 import org.w3c.dom.Document;
12 import org.w3c.dom.Element;
13 import org.w3c.dom.Node;
14 import org.w3c.dom.NodeList;
17 private final Map<String,String> ids2Elems = new TreeMap<String, String>();
19 public Set<String> ids() {
20 return Collections.unmodifiableSet(ids2Elems.keySet());
23 public String tagNameForId(String id) {
24 return ids2Elems.get(id);
27 public static ProcessPage readPage(InputStream is) throws IOException {
28 DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
29 f.setValidating(false);
30 f.setIgnoringComments(true);
34 DocumentBuilder b = f.newDocumentBuilder();
36 } catch (IOException ex) {
38 } catch (Exception e) {
39 throw new IOException(e);
41 Element root = doc.getDocumentElement();
43 ProcessPage pp = new ProcessPage();
48 private void seekForIds(Element e) {
49 String val = e.getAttribute("id");
50 if (val != null && !val.isEmpty()) {
51 String prev = ids2Elems.put(val, e.getTagName());
53 NodeList arr = e.getChildNodes();
54 for (int i = 0; i < arr.getLength(); i++) {
55 final Node n = arr.item(i);
56 if (n instanceof Element) {
57 seekForIds((Element)n);