1 11 package org.eclipse.help.internal.webapp.servlet; 12 13 import java.io.IOException ; 14 import java.io.OutputStream ; 15 import java.io.OutputStreamWriter ; 16 import java.io.PrintWriter ; 17 import java.util.Locale ; 18 import java.util.StringTokenizer ; 19 20 import javax.servlet.ServletException ; 21 import javax.servlet.http.HttpServlet ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.eclipse.help.ITopic; 26 import org.eclipse.help.UAContentFilter; 27 import org.eclipse.help.internal.HelpPlugin; 28 import org.eclipse.help.internal.base.HelpEvaluationContext; 29 import org.eclipse.help.internal.webapp.WebappResources; 30 import org.eclipse.help.internal.webapp.data.UrlUtil; 31 32 36 public class NavServlet extends HttpServlet { 37 38 private static final long serialVersionUID = 1L; 39 40 private static final String XHTML_1 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" HREF=\"../content/PLUGINS_ROOT/PRODUCT_PLUGIN/book.css\"/>\n<title>"; private static final String XHTML_2 = "</title>\n</head>\n<body>\n"; private static final String XHTML_3 = "</body>\n</html>"; 44 private static final IFilter filters[] = new IFilter[]{ 45 new FramesetFilter(), new InjectionFilter(), new BreadcrumbsFilter() }; 46 47 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException { 48 Locale locale = getLocale(req, resp); 49 50 req.setCharacterEncoding("UTF-8"); resp.setContentType("text/html; charset=UTF-8"); 53 String path = req.getPathInfo().substring(1); 54 ITopic topic = getTopic(path, locale); 55 56 OutputStream out = resp.getOutputStream(); 57 for (int i = 0; i < filters.length; i++) { 58 out = filters[i].filter(req, out); 59 } 60 61 PrintWriter writer = new PrintWriter (new OutputStreamWriter (out, "UTF-8")); writeContent(topic, path, locale, writer); 63 writer.close(); 64 } 65 66 private Locale getLocale (HttpServletRequest req, HttpServletResponse resp) { 67 Locale locale; 68 String nl = UrlUtil.getLocale(req, resp); 69 StringTokenizer locales = new StringTokenizer (nl, "_"); if (locales.countTokens() == 1) 72 locale = new Locale (locales.nextToken(), ""); else if (locales.countTokens() == 2) 74 locale = new Locale (locales.nextToken(), locales.nextToken()); 75 else if (locales.countTokens() == 3) 76 locale = new Locale (locales.nextToken(), locales.nextToken(), locales 77 .nextToken()); 78 else 79 locale = Locale.getDefault(); 80 return locale; 81 } 82 83 private ITopic getTopic(String topicPath, Locale locale) { 84 StringTokenizer tok = new StringTokenizer (topicPath, "_"); int index = Integer.parseInt(tok.nextToken()); 86 ITopic topic = HelpPlugin.getTocManager().getTocs(locale.toString())[index].getTopic(null); 87 while (tok.hasMoreTokens()) { 88 index = Integer.parseInt(tok.nextToken()); 89 topic = topic.getSubtopics()[index]; 90 } 91 return topic; 92 } 93 94 private void writeContent(ITopic topic, String path, Locale locale, PrintWriter writer) { 95 writer.write(XHTML_1); 96 writer.write(topic.getLabel()); 97 writer.write(XHTML_2); 98 writer.write("<h1 class=\"NavTitle\">" + topic.getLabel() + "</h1>\n"); writer.write("<h3 class=\"NavListTitle\">" + WebappResources.getString("TocHeading", locale) + "</h3>\n"); writer.write("<ul class=\"NavList\">\n"); ITopic[] subtopics = topic.getSubtopics(); 102 for (int i=0;i<subtopics.length;++i) { 103 if (!UAContentFilter.isFiltered(subtopics[i], HelpEvaluationContext.getContext())) { 104 writer.write("<li><a HREF=\""); String href = subtopics[i].getHref(); 106 if (href == null) { 107 href = path + '_' + i; 108 } 109 else { 110 href = XMLGenerator.xmlEscape(UrlUtil.getHelpURL(href)); 111 } 112 writer.write(href); 113 writer.write("\">" + subtopics[i].getLabel() + "</a></li>\n"); } 115 } 116 writer.write("</ul>\n"); writer.write(XHTML_3); 118 } 119 } 120 | Popular Tags |