Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2007-03-01 21:46:40 +0000
committerCurtis D'Entremont2007-03-01 21:46:40 +0000
commit9077418527bb2eebdef1cae5e49b49c7bf0c11b3 (patch)
tree7eb54af4e9ea6ba9809fc95cd3b03eb164dfb810 /org.eclipse.help.webapp
parent883d67bd6bc502b1b8d898e4718df8ac48700b14 (diff)
downloadeclipse.platform.ua-9077418527bb2eebdef1cae5e49b49c7bf0c11b3.tar.gz
eclipse.platform.ua-9077418527bb2eebdef1cae5e49b49c7bf0c11b3.tar.xz
eclipse.platform.ua-9077418527bb2eebdef1cae5e49b49c7bf0c11b3.zip
166391 [Help] Add breadcrumbs support
Diffstat (limited to 'org.eclipse.help.webapp')
-rw-r--r--org.eclipse.help.webapp/advanced/breadcrumbs.css19
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/UrlUtil.java59
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java117
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java2
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/NavServlet.java14
5 files changed, 198 insertions, 13 deletions
diff --git a/org.eclipse.help.webapp/advanced/breadcrumbs.css b/org.eclipse.help.webapp/advanced/breadcrumbs.css
new file mode 100644
index 000000000..3c352b0cb
--- /dev/null
+++ b/org.eclipse.help.webapp/advanced/breadcrumbs.css
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+.help_breadcrumbs {
+ font: message-box;
+ margin-bottom: 10px;
+}
+
+body {
+ margin-top: 4px;
+}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/UrlUtil.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/UrlUtil.java
index 6bb5924d9..bd6152e88 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/UrlUtil.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/UrlUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,16 +9,28 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.help.internal.webapp.data;
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import java.util.regex.*;
-
-import javax.servlet.http.*;
-
-import org.eclipse.core.runtime.*;
-import org.eclipse.help.internal.base.*;
-import org.eclipse.help.internal.base.util.*;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.base.BaseHelpSystem;
+import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.base.util.TString;
public class UrlUtil {
// XML escaped characters mapping
@@ -123,6 +135,31 @@ public class UrlUtil {
url = "../topic" + url; //$NON-NLS-1$
return url;
}
+
+ /**
+ * Returns a path to the given topic in the form of child indexes. For
+ * example, if the path points to the 3rd subtopic under the 2nd topic of
+ * the 4th toc, it will return { 3, 1, 2 }.
+ *
+ * @param path the path portion of the url, e.g. "/help/topic/my.plugin/foo.html"
+ * @return path to the topic using zero-based indexes
+ */
+ public static int[] getTopicPath(String path) {
+ if (path.startsWith("/help/nav/")) { //$NON-NLS-1$
+ path = path.substring(10);
+ StringTokenizer tok = new StringTokenizer(path, "_"); //$NON-NLS-1$
+ int[] array = new int[tok.countTokens()];
+ for (int i=0;i<array.length;++i) {
+ array[i] = Integer.parseInt(tok.nextToken());
+ }
+ return array;
+ }
+ else {
+ // grab the part after /help/*topic/
+ String href = path.substring(path.indexOf('/', 6));
+ return HelpPlugin.getTocManager().getTopicPath(href);
+ }
+ }
public static boolean isBot(HttpServletRequest request) {
String agent = request.getHeader("User-Agent"); //$NON-NLS-1$
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java
new file mode 100644
index 000000000..5038c3f09
--- /dev/null
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.help.internal.webapp.servlet;
+
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.help.ITopic;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.webapp.HelpWebappPlugin;
+import org.eclipse.help.internal.webapp.data.UrlUtil;
+
+/**
+ * Injects breadcrumbs at the top of help documents, e.g.
+ * "Workbench User Guide > Concepts > Workbench".
+ */
+public class BreadcrumbsFilter implements IFilter {
+
+ private static final String HEAD_CONTENT =
+ "\n<link rel=\"stylesheet\" href=\"../content/PLUGINS_ROOT/" + HelpWebappPlugin.PLUGIN_ID + "/advanced/breadcrumbs.css\" charset=\"ISO-8859-1\" type=\"text/css\"></link>" //$NON-NLS-1$//$NON-NLS-2$
+ + "\n<script language=\"JavaScript\" src=\"../content/PLUGINS_ROOT/" + HelpPlugin.PLUGIN_ID + "/livehelp.js\"> </script>"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.internal.webapp.servlet.IFilter#filter(javax.servlet.http.HttpServletRequest, java.io.OutputStream)
+ */
+ public OutputStream filter(HttpServletRequest req, OutputStream out) {
+ String uri = req.getRequestURI();
+ if (uri == null || !uri.endsWith("html") && !uri.endsWith("htm") && !uri.startsWith("/help/nav/")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return out;
+ }
+ if (UrlUtil.isBot(req)) {
+ return out;
+ }
+ String pathInfo = req.getPathInfo();
+ if (pathInfo == null) {
+ return out;
+ }
+ int[] path = UrlUtil.getTopicPath(uri);
+ if (path != null && path.length > 1) {
+ boolean isNarrow = "/ntopic".equals(req.getServletPath()); //$NON-NLS-1$
+ String locale = UrlUtil.getLocale(req, null);
+ String bodyContent = getBodyContent(path, getBackpath(uri), isNarrow, locale);
+ try {
+ return new FilterHTMLHeadAndBodyOutputStream(out, HEAD_CONTENT.getBytes("ASCII"), bodyContent); //$NON-NLS-1$
+ }
+ catch (UnsupportedEncodingException e) {
+ }
+ }
+ return out;
+ }
+
+ private String getBackpath(String path) {
+ int num = new Path(path).segmentCount() - 2;
+ StringBuffer buf = new StringBuffer();
+ for (int i=0;i<num;++i) {
+ if (i > 0) {
+ buf.append('/');
+ }
+ buf.append(".."); //$NON-NLS-1$
+ }
+ return buf.toString();
+ }
+
+ private String getBodyContent(int[] path, String backPath, boolean isNarrow, String locale) {
+ StringBuffer buf = new StringBuffer();
+ StringBuffer pathBuf = new StringBuffer();
+ ITopic topic = HelpPlugin.getTocManager().getTocs(locale)[path[0]].getTopic(null);
+ pathBuf.append(path[0]);
+ buf.append("<div class=\"help_breadcrumbs\">"); //$NON-NLS-1$
+
+ for (int i=0;i<path.length-1;++i) {
+
+ // add the link
+ buf.append("<a href=\""); //$NON-NLS-1$
+ String href = topic.getHref();
+ if (href != null) {
+ href = backPath + (isNarrow ? "/ntopic" : "/topic") + href; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ if (isNarrow) {
+ href = "javascript:liveAction('org.eclipse.help.ui', 'org.eclipse.help.ui.internal.ShowInTocAction', '" + pathBuf.toString() + "')"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ href = backPath + "/nav/" + pathBuf.toString(); //$NON-NLS-1$
+ }
+ }
+ buf.append(href);
+ buf.append("\">"); //$NON-NLS-1$
+ buf.append(topic.getLabel());
+ buf.append("</a>"); //$NON-NLS-1$
+
+ // add separator
+ if (i < path.length - 2 || path.length == 2) {
+ // always add if there's only one link
+ buf.append(" > "); //$NON-NLS-1$
+ }
+
+ // move to the next topic in the path
+ topic = topic.getSubtopics()[path[i + 1]];
+ pathBuf.append('_');
+ pathBuf.append(path[i + 1]);
+ }
+ buf.append("</div>"); //$NON-NLS-1$
+ return buf.toString();
+ }
+}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java
index abc403212..29cc03f29 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java
@@ -45,7 +45,7 @@ public class EclipseConnector {
+ "<body><p>\n"; //$NON-NLS-1$
private static final String errorPageEnd = "</p></body></html>"; //$NON-NLS-1$
private static final IFilter filters[] = new IFilter[]{
- new HighlightFilter(), new FramesetFilter(), new InjectionFilter(), new DynamicXHTMLFilter() };
+ new HighlightFilter(), new FramesetFilter(), new InjectionFilter(), new DynamicXHTMLFilter(), new BreadcrumbsFilter() };
public EclipseConnector(ServletContext context) {
}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/NavServlet.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/NavServlet.java
index ff1cdbcec..0e76a0ac3 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/NavServlet.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/NavServlet.java
@@ -11,6 +11,7 @@
package org.eclipse.help.internal.webapp.servlet;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;
@@ -35,6 +36,9 @@ public class NavServlet extends HttpServlet {
private static final String XHTML_2 = "</title>\n</head>\n<body>\n"; //$NON-NLS-1$
private static final String XHTML_3 = "</body>\n</html>"; //$NON-NLS-1$
+ private static final IFilter filters[] = new IFilter[]{
+ new FramesetFilter(), new InjectionFilter(), new BreadcrumbsFilter() };
+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Locale locale = req.getLocale();
req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
@@ -42,7 +46,15 @@ public class NavServlet extends HttpServlet {
String path = req.getPathInfo().substring(1);
ITopic topic = getTopic(path, locale);
- writeContent(topic, path, locale, resp.getWriter());
+
+ OutputStream out = resp.getOutputStream();
+ for (int i = 0; i < filters.length; i++) {
+ out = filters[i].filter(req, out);
+ }
+
+ PrintWriter writer = new PrintWriter(out);
+ writeContent(topic, path, locale, writer);
+ writer.close();
}
private ITopic getTopic(String topicPath, Locale locale) {

Back to the top