1 13 package org.eclipse.help.internal.webapp.data; 14 15 import java.io.IOException ; 16 import java.io.Writer ; 17 18 import javax.servlet.ServletContext ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.eclipse.help.IIndex; 23 import org.eclipse.help.IIndexEntry; 24 import org.eclipse.help.ITopic; 25 import org.eclipse.help.internal.HelpPlugin; 26 27 30 public class IndexData extends ActivitiesData { 31 private IIndex index; 32 33 private String imagesDirectory; 35 36 private String plusMinusImage; 38 39 private String expandedCollapsed; 41 42 private boolean usePlusMinus; 44 45 private boolean expandAll; 47 48 private boolean isRTL; 50 51 private Writer out; 53 54 59 public IndexData(ServletContext context, HttpServletRequest request, 60 HttpServletResponse response) { 61 super(context, request, response); 62 63 imagesDirectory = preferences.getImagesDirectory(); 64 usePlusMinus = preferences.isIndexPlusMinus(); 65 expandAll = preferences.isIndexExpandAll(); 66 plusMinusImage = expandAll ? "/minus.gif" : "/plus.gif"; expandedCollapsed = expandAll ? "expanded" : "collapsed"; isRTL = UrlUtil.isRTL(request, response); 69 index = HelpPlugin.getIndexManager().getIndex(getLocale()); 70 } 71 72 81 public void generateIds(Writer out) throws IOException { 82 boolean first = true; 83 IIndexEntry[] entries = index.getEntries(); 84 for (int i=0;i<entries.length;++i) { 85 IIndexEntry entry = entries[i]; 86 if (entry != null && entry.getKeyword() != null && entry.getKeyword().length() > 0) { 87 if (first) { 88 first = false; 89 } else { 90 out.write(",\n"); } 92 out.write("\""); out.write(UrlUtil.JavaScriptEncode(entry.getKeyword())); 94 out.write("\""); } 96 } 97 } 98 99 105 public void generateIndex(Writer out) throws IOException { 106 this.out = out; 107 IIndexEntry[] entries = index.getEntries(); 108 for (int i=0;i<entries.length;++i) { 109 if (EnabledTopicUtils.isEnabled(entries[i])) { 110 generateEntry(entries[i], 0); 111 } 112 } 113 } 114 115 122 137 private void generateEntry(IIndexEntry entry, int level) throws IOException { 138 if (entry.getKeyword() != null && entry.getKeyword().length() > 0) { 139 ITopic[] topics = EnabledTopicUtils.getEnabled(entry.getTopics()); 140 IIndexEntry[] subentries = EnabledTopicUtils.getEnabled(entry.getSubentries()); 141 boolean multipleTopics = topics.length > 1; 142 boolean singleTopic = topics.length == 1; 143 144 out.write("<li>"); if (usePlusMinus && advancedUI) generatePlusImage(multipleTopics); 146 generateAnchor(singleTopic, entry, level); 147 if (multipleTopics || subentries.length > 0) { 148 if (!advancedUI) { 149 out.write("<ul>\n"); } 151 if (multipleTopics) generateTopicList(entry); 152 generateSubentries(entry, level + 1); 153 if (!advancedUI) { 154 out.write("</ul>\n"); } 156 } 157 out.write("</li>\n"); } 159 } 160 161 168 public void generateBasicIndex(Writer out) throws IOException { 169 this.out = out; 170 IIndexEntry[] entries = index.getEntries(); 171 for (int i=0;i<entries.length;++i) { 172 generateBasicEntry(entries[i], 0); 173 } 174 } 175 176 184 193 private void generateBasicEntry(IIndexEntry entry, int level) throws IOException { 194 ITopic[] topics = entry.getTopics(); 195 IIndexEntry[] subentries = entry.getSubentries(); 196 boolean multipleTopics = topics.length > 1; 197 boolean singleTopic = topics.length == 1; 198 199 out.write("<tr><td align=\""); out.write(isRTL ? "right" : "left"); out.write("\" nowrap>\n"); generateAnchor(singleTopic, entry, level); 203 out.write("</td></tr>\n"); if (multipleTopics || subentries.length > 0) { 205 out.write("<tr><td align=\""); out.write(isRTL ? "right" : "left"); out.write("\" nowrap><ul>\n"); if (multipleTopics) generateTopicList(entry); 209 generateSubentries(entry, level + 1); 210 out.write("</ul></td></tr>\n"); } 212 } 213 214 220 223 private void generatePlusImage(boolean multipleTopics) throws IOException { 224 out.write("<img SRC=\""); out.write(imagesDirectory); 226 out.write(plusMinusImage); 227 out.write("\" class=\""); if (multipleTopics) { 229 out.write(expandedCollapsed); 230 } else { 231 out.write("h"); } 233 out.write("\" alt=\""); if (multipleTopics) { 235 if (expandAll) { 236 out.write(ServletResources.getString("collapseTopicTitles", request)); } else { 238 out.write(ServletResources.getString("expandTopicTitles", request)); } 240 } 241 out.write("\">"); } 243 244 252 259 private void generateAnchor(boolean singleTopic, IIndexEntry entry, int level) throws IOException { 260 out.write("<a "); if (level == 0 && advancedUI) { 262 out.write("id=\""); out.write(entry.getKeyword()); 264 out.write("\" "); } 266 if (singleTopic) { 267 out.write("href=\""); out.write(UrlUtil.getHelpURL((entry.getTopics()[0]).getHref())); 269 out.write("\">"); } else { 271 if (advancedUI) { 272 out.write("class=\"nolink\" "); } 274 out.write("href=\"about:blank\">"); } 276 out.write(UrlUtil.htmlEncode(entry.getKeyword())); 277 out.write("</a>\n"); } 279 280 286 297 private void generateTopicList(IIndexEntry entry) throws IOException { 298 ITopic[] topics = entry.getTopics(); 299 300 if (advancedUI) { 301 out.write("\n<ul class=\""); out.write(expandedCollapsed); 303 out.write("\">\n"); } 305 for (int i = 0; i < topics.length; ++i) { 306 ITopic topic = (ITopic)topics[i]; 307 308 out.write("<li>"); if (usePlusMinus && advancedUI) { 310 out.write("<img class=\"h\" SRC=\""); out.write(imagesDirectory); 312 out.write(plusMinusImage); 313 out.write("\" alt=\"\">"); } 315 out.write("<a HREF=\""); out.write(UrlUtil.getHelpURL(topic.getHref())); 317 out.write("\"><img SRC=\""); out.write(imagesDirectory); 319 out.write("/topic.gif\" "); if (!advancedUI) { 321 out.write("border=0 "); } 323 out.write("alt=\"\">"); out.write(UrlUtil.htmlEncode(topic.getLabel())); 325 out.write("</a></li>\n"); } 327 if (advancedUI) { 328 out.write("</ul>\n"); } 330 } 331 332 339 348 private void generateSubentries(IIndexEntry entry, int level) throws IOException { 349 if (advancedUI) { 350 out.write("<ul class=\"expanded\">\n"); } 352 IIndexEntry[] subentries = entry.getSubentries(); 353 for (int i=0;i<subentries.length;++i) { 354 generateEntry(subentries[i], level); 355 } 356 if (advancedUI) { 357 out.write("</ul>\n"); } 359 } 360 } 361 | Popular Tags |