Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-06-22 23:14:00 +0000
committerChris Goldthorpe2009-06-22 23:14:00 +0000
commitf23258e3dea07cf8d610797d45977d6c4bec5d23 (patch)
tree9b93428b0cd6431ea6f3037bf61671aea371e824
parent780cc0f6ed0a3a82384016e48d97fee13b57666e (diff)
downloadeclipse.platform.ua-f23258e3dea07cf8d610797d45977d6c4bec5d23.tar.gz
eclipse.platform.ua-f23258e3dea07cf8d610797d45977d6c4bec5d23.tar.xz
eclipse.platform.ua-f23258e3dea07cf8d610797d45977d6c4bec5d23.zip
Bug 279711 – [Help] PLUGINS_ROOT redirects slow infocenter
-rw-r--r--org.eclipse.help.webapp/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/CssUtil.java15
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java2
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java14
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java2
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InjectionFilter.java8
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootFilter.java34
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootResolvingStream.java90
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java84
10 files changed, 238 insertions, 14 deletions
diff --git a/org.eclipse.help.webapp/META-INF/MANIFEST.MF b/org.eclipse.help.webapp/META-INF/MANIFEST.MF
index a3441c642..b5c6985f3 100644
--- a/org.eclipse.help.webapp/META-INF/MANIFEST.MF
+++ b/org.eclipse.help.webapp/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %help_webapp_plugin_name
Bundle-SymbolicName: org.eclipse.help.webapp;singleton:=true
-Bundle-Version: 3.4.0.qualifier
+Bundle-Version: 3.4.100.qualifier
Bundle-Activator: org.eclipse.help.internal.webapp.HelpWebappPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/CssUtil.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/CssUtil.java
index a051ed99c..f9df4178c 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/CssUtil.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/CssUtil.java
@@ -17,6 +17,7 @@ import java.util.StringTokenizer;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.util.ProductPreferences;
/**
* Utility class for parsing the CSS preferences
@@ -24,7 +25,7 @@ import org.eclipse.help.internal.base.HelpBasePlugin;
public class CssUtil {
- private final static String cssLink1 = "<link rel=\"stylesheet\" href=\"../content/PLUGINS_ROOT"; //$NON-NLS-1$
+ private final static String cssLink1 = "<link rel=\"stylesheet\" href=\""; //$NON-NLS-1$
private static final String cssLink2 = "\" type=\"text/css\"></link>\n"; //$NON-NLS-1$
private static String replaceParameters(String input) {
@@ -61,15 +62,23 @@ public class CssUtil {
}
}
- public static String createCssIncludes(List cssFiles) {
+ public static String createCssIncludes(List cssFiles, String backPath) {
StringBuffer script = new StringBuffer();
for (Iterator iter = cssFiles.iterator(); iter.hasNext();) {
String cssPath = (String) iter.next();
script.append(cssLink1);
- script.append(cssPath);
+ script.append(fixCssPath(cssPath, backPath));
script.append(cssLink2);
}
return script.toString();
}
+
+ /*
+ * Substitute for PLUGINS_ROOT and PRODUCT_PLUGIN
+ */
+ private static String fixCssPath(String path, String prefix) {
+ String newPath = ProductPreferences.resolveSpecialIdentifiers(path);
+ return prefix + "content" + newPath; //$NON-NLS-1$
+ }
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java
index 534b6a5d1..2bd36a326 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/PrintData.java
@@ -306,6 +306,6 @@ public class PrintData extends RequestData {
private String getCssIncludes() {
List css = new ArrayList();
CssUtil.addCssFiles("topic_css", css); //$NON-NLS-1$
- return CssUtil.createCssIncludes(css);
+ return CssUtil.createCssIncludes(css, "../"); //$NON-NLS-1$
}
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java
index fd7e7d870..2d07c653c 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/BreadcrumbsFilter.java
@@ -30,9 +30,10 @@ import org.eclipse.help.webapp.IFilter;
*/
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 type=\"text/javascript\" src=\"../content/PLUGINS_ROOT/" + HelpPlugin.PLUGIN_ID + "/livehelp.js\"> </script>"; //$NON-NLS-1$ //$NON-NLS-2$
+ private static final String HEAD_CONTENT1 = "\n<link rel=\"stylesheet\" href=\""; //$NON-NLS-1$
+ private static final String HEAD_CONTENT2 = "/content/" + HelpWebappPlugin.PLUGIN_ID + "/advanced/breadcrumbs.css\" charset=\"ISO-8859-1\" type=\"text/css\"></link>" //$NON-NLS-1$ //$NON-NLS-2$
+ + "\n<script type=\"text/javascript\" src=\""; //$NON-NLS-1$
+ private static final String HEAD_CONTENT3 = "/content/" + 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)
@@ -75,9 +76,12 @@ public class BreadcrumbsFilter implements IFilter {
if (path != null && path.length > 1) {
try {
boolean isNarrow = "/ntopic".equals(req.getServletPath()); //$NON-NLS-1$
+ String backpath = getBackpath(pathInfo);
String bodyContent = getBodyContent(path,
- getBackpath(pathInfo), isNarrow, locale);
- return new FilterHTMLHeadAndBodyOutputStream(out, HEAD_CONTENT
+ backpath, isNarrow, locale);
+ String headContent = HEAD_CONTENT1 + backpath + HEAD_CONTENT2 + backpath +
+ HEAD_CONTENT3;
+ return new FilterHTMLHeadAndBodyOutputStream(out, headContent
.getBytes("ASCII"), bodyContent); //$NON-NLS-1$
}
catch (Exception e) {
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java
index 1c62f60db..d30697951 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java
@@ -50,7 +50,7 @@ public class EclipseConnector {
private static final String errorPageEnd = "</p></body></html>"; //$NON-NLS-1$
private static final IFilter allFilters[] = new IFilter[] {
new HighlightFilter(), new FramesetFilter(), new InjectionFilter(),
- new DynamicXHTMLFilter(), new BreadcrumbsFilter(),
+ new DynamicXHTMLFilter(), new BreadcrumbsFilter(), new PluginsRootFilter(),
new ShowInTocFilter(), new ExtraFilters() };
private static final IFilter errorPageFilters[] = new IFilter[] {
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InjectionFilter.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InjectionFilter.java
index 73b0cca07..bf39931f0 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InjectionFilter.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InjectionFilter.java
@@ -90,11 +90,12 @@ public class InjectionFilter implements IFilter {
String relativePath = FilterUtils.getRelativePathPrefix(req);
StringBuffer script = new StringBuffer();
StringBuffer disabledContent = new StringBuffer();
- script.append(CssUtil.createCssIncludes(cssIncludes));
+ script.append(CssUtil.createCssIncludes(cssIncludes, FilterUtils.getRelativePathPrefix(req)));
if (addDisabled) {
if (needsLiveHelp) {
script.append(disabledBook3);
- script.append("../content/PLUGINS_ROOT/org.eclipse.help/"); //$NON-NLS-1$
+ script.append(relativePath);
+ script.append("content/org.eclipse.help/"); //$NON-NLS-1$
script.append(disabledBook4);
}
appendDisabled(disabledContent, upLevels, addNarrow, relativePath);
@@ -115,7 +116,8 @@ public class InjectionFilter implements IFilter {
return;
buff.append("<div id=\"help-disabledTopic\">"); //$NON-NLS-1$
buff.append("<img src=\""); //$NON-NLS-1$
- buff.append("../content/PLUGINS_ROOT/org.eclipse.help.webapp/"); //$NON-NLS-1$
+ buff.append(relativePath);
+ buff.append("content/org.eclipse.help.webapp/"); //$NON-NLS-1$
buff.append("advanced/images/e_show_all.gif\" border=\"0\" align=\"bottom\">&nbsp;"); //$NON-NLS-1$
buff.append(message);
buff.append("<br><hr></div>"); //$NON-NLS-1$
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootFilter.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootFilter.java
new file mode 100644
index 000000000..1f397d5bd
--- /dev/null
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootFilter.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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 javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.help.webapp.IFilter;
+
+/**
+ * This class inserts a CSSs for narrow and disabled CSSs when called from the
+ * dynamic help view.
+ */
+public class PluginsRootFilter implements IFilter {
+
+ public OutputStream filter(HttpServletRequest req, OutputStream out) {
+ String pathPrefix = FilterUtils.getRelativePathPrefix(req);
+ if (pathPrefix.length() >= 3) {
+ return new PluginsRootResolvingStream(out, pathPrefix.substring(0, pathPrefix.length() - 3));
+ }
+ return out;
+ }
+
+}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootResolvingStream.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootResolvingStream.java
new file mode 100644
index 000000000..1b421954e
--- /dev/null
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/PluginsRootResolvingStream.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.io.OutputStream;
+
+public class PluginsRootResolvingStream extends OutputStream {
+
+ private OutputStream out;
+
+ private int state = INITIAL_STATE;
+ private static final int INITIAL_STATE = 0;
+ private static final int IN_TAG = 1;
+ private static final int IN_QUOTE = 3; // IN_QUOTE + n means n characters from PLUGIN_ROOT matched
+ private static final int IN_QUOTE_NOT_PLUGINS_ROOT = 2;
+ private static final String PLUGINS_ROOT = "PLUGINS_ROOT/"; //$NON-NLS-1$
+ private static final int IN_QUOTE_PLUGINS_ROOT = IN_QUOTE + 13; // 13 is PLUGINS_ROOT.length();
+
+ private String pathPrefix;
+
+ private void flushCachedCharacters(int charsMatched) throws IOException {
+ out.write(PLUGINS_ROOT.substring(0, charsMatched).getBytes());
+ }
+
+ public PluginsRootResolvingStream(OutputStream out, String prefix) {
+ this.out = out;
+ this.pathPrefix = prefix;
+ }
+
+ public void write(int b) throws IOException {
+ switch(state) {
+ case INITIAL_STATE:
+ if (b == '<') {
+ state = IN_TAG;
+ }
+ out.write(b);
+ break;
+ case IN_TAG:
+ if (b == '>') {
+ state = INITIAL_STATE;
+ } else if (b == '"') {
+ state = IN_QUOTE;
+ }
+ out.write(b);
+ break;
+ case IN_QUOTE_NOT_PLUGINS_ROOT:
+ if (b == '>') {
+ state = INITIAL_STATE;
+ } else if (b == '"') {
+ state = IN_TAG;
+ }
+ out.write(b);
+ break;
+ default:
+ // In a quote which may start with PLUGINS_ROOT
+ int charsMatched = state - IN_QUOTE;
+ if (b == PLUGINS_ROOT.charAt(charsMatched)) {
+ state++;
+ if (state == IN_QUOTE_PLUGINS_ROOT) {
+ out.write(pathPrefix.getBytes());
+ state = IN_QUOTE_NOT_PLUGINS_ROOT;
+ }
+ } else {
+ // We just discovered that this is not "PLUGINS_ROOT/
+ // flush out the characters
+ state = IN_QUOTE_NOT_PLUGINS_ROOT;
+ flushCachedCharacters(charsMatched);
+ out.write(b);
+ }
+ }
+ }
+
+ public void close() throws IOException {
+ if (state > IN_QUOTE && state < IN_QUOTE_PLUGINS_ROOT) {
+ flushCachedCharacters(state - IN_QUOTE);
+ }
+ out.close();
+ super.close();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java
index 17b06177d..ca3442a23 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java
@@ -28,6 +28,7 @@ public class AllWebappTests extends TestSuite {
suite.addTestSuite(BrowserIdentificationTest.class);
suite.addTestSuite(TopicPathTest.class);
suite.addTestSuite(FilterTest.class);
+ suite.addTestSuite(PluginsRootReplacement.class);
suite.addTestSuite(UrlUtilsTests.class);
suite.addTestSuite(LocaleTest.class);
suite.addTestSuite(RestrictedTopicParameter.class);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
new file mode 100644
index 000000000..81d455bd5
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.ua.tests.help.webapp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.eclipse.help.internal.webapp.servlet.PluginsRootResolvingStream;
+
+/**
+ * Test for replacing PLUGINS_ROOT with a relative path
+ */
+
+public class PluginsRootReplacement extends TestCase {
+
+ public void testEmpty() {
+ final String input = "";
+ checkFilter(input, input);
+ }
+
+ public void testNoMatch() {
+ final String input = "<HEAD><HEAD/>";
+ checkFilter(input, input);
+ }
+
+ public void testPartialMatch() {
+ final String input = "<A href = \"PLUGINS\">";
+ checkFilter(input, input);
+ }
+
+ public void testEndsUnmatched() {
+ final String input = "<A href = \"PLUGIN";
+ checkFilter(input, input);
+ }
+
+ public void testNotAtStart() {
+ final String input = "<A href = \"../PLUGINS_ROOT/plugin/a.html\">";
+ checkFilter(input, input);
+ }
+
+ public void testAtStart() {
+ final String input = "<A href = \"PLUGINS_ROOT/plugin/a.html\">";
+ final String expected = "<A href = \"../plugin/a.html\">";
+ checkFilter(input, expected);
+ }
+
+ public void testSecondArg() {
+ final String input = "<A alt=\"alt\" href = \"PLUGINS_ROOT/plugin/a.html\">";
+ final String expected = "<A alt=\"alt\" href = \"../plugin/a.html\">";
+ checkFilter(input, expected);
+ }
+
+
+ public void testMultipleMatches() {
+ final String input = "<A href = \"PLUGINS_ROOT/plugin/a.html\"><A href = \"PLUGINS_ROOT/plugin/b.html\">";
+ final String expected = "<A href = \"../plugin/a.html\"><A href = \"../plugin/b.html\">";
+ checkFilter(input, expected);
+ }
+
+ private void checkFilter(final String input, final String expected) {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ OutputStream filteredOutput = new PluginsRootResolvingStream(output, "../");
+ try {
+ filteredOutput.write(input.getBytes());
+ filteredOutput.close();
+ } catch (IOException e) {
+ fail("IO Exception");
+ }
+ assertEquals(expected, output.toString());
+ }
+
+}

Back to the top