Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/IndexServlet.java')
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/IndexServlet.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/IndexServlet.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/IndexServlet.java
new file mode 100644
index 000000000..652a1c9dc
--- /dev/null
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/IndexServlet.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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
+ * 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.IOException;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.TransformerException;
+
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.dynamic.DocumentWriter;
+import org.eclipse.help.internal.index.Index;
+import org.eclipse.help.internal.index.IndexContribution;
+import org.eclipse.help.internal.webapp.data.UrlUtil;
+
+/*
+ * Sends all available keyword index data in XML form. The data is sent as one
+ * large index contribution that includes all merged contributions from the
+ * system.
+ *
+ * This is called on infocenters by client workbenches configured for remote
+ * help in order to gather all the index keywords and assemble them into a
+ * complete index.
+ */
+public class IndexServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+ private Map responseByLocale;
+ private DocumentWriter writer;
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ String locale = UrlUtil.getLocale(req, resp);
+ req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+ resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
+
+ if (responseByLocale == null) {
+ responseByLocale = new WeakHashMap();
+ }
+ String response = (String)responseByLocale.get(locale);
+ if (response == null) {
+ IndexContribution[] contributions = HelpPlugin.getIndexManager().getIndexContributions(locale);
+ try {
+ response = serialize(contributions, locale);
+ }
+ catch (TransformerException e) {
+ throw new ServletException(e);
+ }
+ responseByLocale.put(locale, response);
+ }
+ resp.getWriter().write(response);
+ }
+
+ public String serialize(IndexContribution[] contributions, String locale) throws TransformerException {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
+ buf.append("<indexContributions>\n"); //$NON-NLS-1$
+ if (writer == null) {
+ writer = new DocumentWriter();
+ }
+ for (int i=0;i<contributions.length;++i) {
+ IndexContribution contrib = contributions[i];
+ buf.append("<indexContribution\n"); //$NON-NLS-1$
+ buf.append(" id=\"" + contrib.getId() + '"'); //$NON-NLS-1$
+ buf.append(" locale=\"" + contrib.getLocale() + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ buf.append(writer.writeString((Index)contrib.getIndex(), false));
+ buf.append("</indexContribution>\n"); //$NON-NLS-1$
+ }
+ buf.append("</indexContributions>\n"); //$NON-NLS-1$
+ return buf.toString();
+ }
+}

Back to the top