1 11 12 package org.eclipse.help.internal.webapp.data; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.help.IIndexEntry; 18 import org.eclipse.help.ITopic; 19 import org.eclipse.help.UAContentFilter; 20 import org.eclipse.help.internal.base.HelpEvaluationContext; 21 22 25 26 public class EnabledTopicUtils { 27 28 33 public static boolean isEnabled(ITopic topic) { 34 if (!topic.isEnabled(HelpEvaluationContext.getContext())) { 35 return false; 36 } 37 if (topic.getHref() != null) { 38 return true; 39 } 40 ITopic[] subtopics = topic.getSubtopics(); 42 for (int i = 0; i < subtopics.length; i++) { 43 if (isEnabled(subtopics[i])) { 44 return true; 45 } 46 } 47 return false; 48 } 49 50 55 public static boolean isEnabled(IIndexEntry entry) { 56 if (UAContentFilter.isFiltered(entry, HelpEvaluationContext.getContext())) { 57 return false; 58 } 59 ITopic[] topics = entry.getTopics(); 60 for (int i=0;i<topics.length;++i) { 61 if (isEnabled(topics[i])) { 62 return true; 63 } 64 } 65 IIndexEntry[] subentries = entry.getSubentries(); 66 for (int i=0;i<subentries.length;++i) { 67 if (isEnabled(subentries[i])) { 68 return true; 69 } 70 } 71 return false; 72 } 73 74 79 public static IIndexEntry[] getEnabled(IIndexEntry[] entries) { 80 for (int i=0;i<entries.length;++i) { 81 if (!isEnabled(entries[i])) { 82 List list = new ArrayList (entries.length); 83 for (int j=0;j<entries.length;++j) { 84 if (j < i || isEnabled(entries[j])) { 85 list.add(entries[j]); 86 } 87 } 88 return (IIndexEntry[])list.toArray(new IIndexEntry[list.size()]); 89 } 90 } 91 return entries; 92 } 93 94 99 public static ITopic[] getEnabled(ITopic[] topics) { 100 for (int i=0;i<topics.length;++i) { 101 if (!isEnabled(topics[i])) { 102 List list = new ArrayList (topics.length); 103 for (int j=0;j<topics.length;++j) { 104 if (j < i || isEnabled(topics[j])) { 105 list.add(topics[j]); 106 } 107 } 108 return (ITopic[])list.toArray(new ITopic[list.size()]); 109 } 110 } 111 return topics; 112 } 113 114 } 115 | Popular Tags |