1 11 package org.eclipse.help.internal.index; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Comparator ; 16 import java.util.Stack ; 17 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.help.IIndex; 20 import org.eclipse.help.ITopic; 21 import org.eclipse.help.internal.HelpPlugin; 22 import org.eclipse.help.internal.model.ITocElement; 23 24 25 31 public class IndexBuilder { 32 33 private Collection contributedIndexFiles; 34 private Collection unprocessedIndexFiles; 35 private Index index; 36 private IndexEntry current; 37 private Stack entries; 38 private ITocElement[] tocs; 39 40 43 public IndexBuilder(Comparator comparator) { 44 unprocessedIndexFiles = new ArrayList (); 45 index = new Index(comparator); 46 entries = new Stack (); 47 tocs = HelpPlugin.getTocManager().getTocs(Platform.getNL()); 48 } 49 50 public void build(Collection contributedIndexFiles) { 51 this.contributedIndexFiles = contributedIndexFiles; 52 unprocessedIndexFiles.addAll(this.contributedIndexFiles); 53 while (!unprocessedIndexFiles.isEmpty()) { 54 IndexFile indexFile = (IndexFile) unprocessedIndexFiles.iterator().next(); 55 indexFile.build(this); 56 } 57 } 58 59 62 public void buildIndexFile(IndexFile file) { 63 unprocessedIndexFiles.remove(file); 64 IndexFileParser parser = new IndexFileParser(this); 65 parser.parse(file); 66 } 67 72 protected void addIndexEntry(String keyword) { 73 Index currIndex = current == null ? index : current; 74 IndexEntry newEntry = currIndex.addEntry(keyword); 75 if(current != null) entries.push(current); 76 current = newEntry; 77 } 78 79 protected void exitIndexEntry() { 80 if(entries.empty()) 81 current = null; 82 else 83 current = (IndexEntry)entries.pop(); 84 } 85 86 protected void addTopic(String label, String href, String location) { 87 boolean emptyLabel = label == null || label.length() == 0; 88 boolean emptyLocation = location == null || location.length() == 0; 89 90 if ( emptyLabel || emptyLocation ) { 91 for (int i = 0; i < tocs.length; i++) { 92 ITopic topic = tocs[i].getTopic(href); 93 if (topic != null) { 94 if(emptyLabel) { 95 label = topic.getLabel(); 96 emptyLabel = false; 97 } 98 if(emptyLocation) { 99 location = tocs[i].getLabel(); 100 emptyLocation = false; 101 } 102 } 103 } 104 } 105 106 if(emptyLocation) location = ""; if(emptyLabel) label = ""; if (current != null) { 109 current.addTopic(label,href,location); 110 } 111 } 112 113 128 131 protected IIndex getBuiltIndex() { 132 return index; 133 } 134 135 } 136 | Popular Tags |