1 11 package org.eclipse.help.internal.webapp.servlet; 12 13 import java.io.OutputStream ; 14 import java.io.UnsupportedEncodingException ; 15 16 import javax.servlet.http.HttpServletRequest ; 17 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.help.ITopic; 20 import org.eclipse.help.internal.HelpPlugin; 21 import org.eclipse.help.internal.webapp.HelpWebappPlugin; 22 import org.eclipse.help.internal.webapp.data.UrlUtil; 23 24 28 public class BreadcrumbsFilter implements IFilter { 29 30 private static final String HEAD_CONTENT = 31 "\n<link rel=\"stylesheet\" HREF=\"../content/PLUGINS_ROOT/" + HelpWebappPlugin.PLUGIN_ID + "/advanced/breadcrumbs.css\" charset=\"ISO-8859-1\" type=\"text/css\"></link>" + "\n<script language=\"JavaScript\" SRC=\"../content/PLUGINS_ROOT/" + HelpPlugin.PLUGIN_ID + "/livehelp.js\"> </script>"; 34 37 public OutputStream filter(HttpServletRequest req, OutputStream out) { 38 String uri = req.getRequestURI(); 39 if (uri == null || !uri.endsWith("html") && !uri.endsWith("htm") && !uri.startsWith("/help/nav/")) { return out; 41 } 42 if ("/rtopic".equals(req.getServletPath())) { return out; 44 } 45 if (UrlUtil.isBot(req)) { 46 return out; 47 } 48 String pathInfo = req.getPathInfo(); 49 if (pathInfo == null) { 50 return out; 51 } 52 int[] path = UrlUtil.getTopicPath(uri); 53 if (path != null && path.length > 1) { 54 boolean isNarrow = "/ntopic".equals(req.getServletPath()); String locale = UrlUtil.getLocale(req, null); 56 String bodyContent = getBodyContent(path, getBackpath(uri), isNarrow, locale); 57 try { 58 return new FilterHTMLHeadAndBodyOutputStream(out, HEAD_CONTENT.getBytes("ASCII"), bodyContent); } 60 catch (UnsupportedEncodingException e) { 61 } 62 } 63 return out; 64 } 65 66 private String getBackpath(String path) { 67 int num = new Path(path).segmentCount() - 2; 68 StringBuffer buf = new StringBuffer (); 69 for (int i=0;i<num;++i) { 70 if (i > 0) { 71 buf.append('/'); 72 } 73 buf.append(".."); } 75 return buf.toString(); 76 } 77 78 private String getBodyContent(int[] path, String backPath, boolean isNarrow, String locale) { 79 StringBuffer buf = new StringBuffer (); 80 StringBuffer pathBuf = new StringBuffer (); 81 ITopic topic = HelpPlugin.getTocManager().getTocs(locale)[path[0]].getTopic(null); 82 pathBuf.append(path[0]); 83 buf.append("<div class=\"help_breadcrumbs\">"); 85 for (int i=0;i<path.length-1;++i) { 86 87 buf.append("<a HREF=\""); String href = topic.getHref(); 90 if (href != null) { 91 href = backPath + (isNarrow ? "/ntopic" : "/topic") + href; } 93 else { 94 if (isNarrow) { 95 href = "javascript:liveAction('org.eclipse.help.ui', 'org.eclipse.help.ui.internal.ShowInTocAction', '" + pathBuf.toString() + "')"; } 97 else { 98 href = backPath + "/nav/" + pathBuf.toString(); } 100 } 101 buf.append(href); 102 buf.append("\">"); buf.append(topic.getLabel()); 104 buf.append("</a>"); 106 if (i < path.length - 2 || path.length == 2) { 108 buf.append(" > "); } 111 112 topic = topic.getSubtopics()[path[i + 1]]; 114 pathBuf.append('_'); 115 pathBuf.append(path[i + 1]); 116 } 117 buf.append("</div>"); return buf.toString(); 119 } 120 } 121 | Popular Tags |