1 12 package org.eclipse.help.internal.webapp.data; 13 import javax.servlet.*; 14 import javax.servlet.http.*; 15 16 import org.eclipse.help.*; 17 import org.eclipse.help.internal.*; 18 19 22 public class LinksData extends RequestData { 23 24 private String topicHref; 26 private String selectedTopicId = ""; 28 private IHelpResource[] links; 30 31 37 public LinksData(ServletContext context, HttpServletRequest request, 38 HttpServletResponse response) { 39 super(context, request, response); 40 this.topicHref = request.getParameter("topic"); if (topicHref != null && topicHref.length() == 0) 42 topicHref = null; 43 44 if (isLinksRequest()) 45 loadLinks(); 46 } 47 48 53 public boolean isLinksRequest() { 54 return (request.getParameter("contextId") != null); } 56 57 62 public int getLinksCount() { 63 return links.length; 64 } 65 66 public String getSelectedTopicId() { 67 return selectedTopicId; 68 } 69 70 public String getTopicHref(int i) { 71 return UrlUtil.getHelpURL(links[i].getHref()); 72 } 73 74 public String getTopicLabel(int i) { 75 return UrlUtil.htmlEncode(links[i].getLabel()); 76 } 77 78 public String getTopicTocLabel(int i) { 79 IToc toc = findTocForTopic(links[i].getHref()); 80 if (toc != null) 81 return UrlUtil.htmlEncode(toc.getLabel()); 82 return ""; } 84 85 88 private IToc findTocForTopic(String href) { 89 IToc[] tocs = HelpPlugin.getTocManager().getTocs(getLocale()); 90 for (int i = 0; i < tocs.length; i++) { 91 ITopic topic = tocs[i].getTopic(href); 92 if (topic != null) 93 return tocs[i]; 94 } 95 return null; 96 } 97 98 private void loadLinks() { 99 String contextId = request.getParameter("contextId"); if (contextId == null) { 101 links = new IHelpResource[0]; 102 return; 103 } 104 IContext context = HelpSystem.getContext(contextId); 105 if (context == null) { 106 links = new IHelpResource[0]; 107 return; 108 } 109 links = context.getRelatedTopics(); 110 if (links == null) { 111 links = new IHelpResource[0]; 112 return; 113 } 114 115 for (int i = 0; i < links.length; i++) { 116 if (links[i].getHref().equals(topicHref)) { 118 selectedTopicId = "a" + i; break; 120 } 121 } 122 } 123 124 } 125 | Popular Tags |