Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-04-01 21:22:33 +0000
committerChris Goldthorpe2010-04-01 21:22:33 +0000
commit5ae5529c9109d830b1e0bd2d5287e66f42afe3e7 (patch)
tree09fa83b7d8e8594cec9bc46f1ea0939305016c32
parentf919343dda7230ec1c1b08715a5cc4acc985afd0 (diff)
downloadeclipse.platform.ua-5ae5529c9109d830b1e0bd2d5287e66f42afe3e7.tar.gz
eclipse.platform.ua-5ae5529c9109d830b1e0bd2d5287e66f42afe3e7.tar.xz
eclipse.platform.ua-5ae5529c9109d830b1e0bd2d5287e66f42afe3e7.zip
Reduce encryption of scope cookie - [Webapp] Search scope cookie file reaches max size quickly, limits creation of new scopes
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java16
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java29
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java3
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java120
4 files changed, 153 insertions, 15 deletions
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java
index 032ba1528..7c797c774 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java
@@ -236,13 +236,13 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
private void saveContents() throws IOException {
StringBuffer data = new StringBuffer();
- data.append(URLCoder.encode(currentWorkingSet /* , "UTF8" */
+ data.append(URLCoder.compactEncode(currentWorkingSet /* , "UTF8" */
));
for (Iterator i = workingSets.iterator(); i.hasNext();) {
data.append('|');
WorkingSet ws = (WorkingSet) i.next();
- data.append(URLCoder.encode(ws.getName() /* , "UTF8" */
+ data.append(URLCoder.compactEncode(ws.getName() /* , "UTF8" */
));
AdaptableHelpResource[] resources = ws.getElements();
@@ -252,7 +252,7 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
IAdaptable parent = resources[j].getParent();
if (parent == getRoot()) {
// saving toc
- data.append(URLCoder.encode(resources[j].getHref()
+ data.append(URLCoder.compactEncode(resources[j].getHref()
/* , "UTF8" */
));
} else {
@@ -261,7 +261,7 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
AdaptableHelpResource[] siblings = (toc).getChildren();
for (int t = 0; t < siblings.length; t++) {
if (siblings[t] == resources[j]) {
- data.append(URLCoder.encode(toc.getHref()
+ data.append(URLCoder.compactEncode(toc.getHref()
/* , "UTF8" */
));
data.append('_');
@@ -280,12 +280,12 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
private void saveCriteria() throws IOException {
StringBuffer data = new StringBuffer();
- data.append(URLCoder.encode(currentWorkingSet));
+ data.append(URLCoder.compactEncode(currentWorkingSet));
//|scope1$platform#AIX,WINDOWS,$version#1.0,2.0,
for (Iterator i = workingSets.iterator(); i.hasNext();) {
data.append('|');
WorkingSet ws = (WorkingSet) i.next();
- data.append(URLCoder.encode(ws.getName()));
+ data.append(URLCoder.compactEncode(ws.getName()));
CriterionResource[] criteria = ws.getCriteria();
for (int j = 0; j < criteria.length; ++ j){
@@ -294,11 +294,11 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
List criterionValues = criterion.getCriterionValues();
if(null != criterionValues && !criterionValues.isEmpty()){
data.append('$');
- data.append(URLCoder.encode(criterionName));
+ data.append(URLCoder.compactEncode(criterionName));
data.append('#');
for (Iterator iter = criterionValues.iterator(); iter.hasNext();) {
String value = (String) iter.next();
- data.append(URLCoder.encode(value));
+ data.append(URLCoder.compactEncode(value));
data.append(',');
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java b/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java
index 100c7382d..35f9c8403 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -17,7 +17,15 @@ public class URLCoder {
public static String encode(String s) {
try {
- return urlEncode(s.getBytes("UTF8")); //$NON-NLS-1$
+ return urlEncode(s.getBytes("UTF8"), false); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException uee) {
+ return null;
+ }
+ }
+
+ public static String compactEncode(String s) {
+ try {
+ return urlEncode(s.getBytes("UTF8"), true); //$NON-NLS-1$
} catch (UnsupportedEncodingException uee) {
return null;
}
@@ -31,15 +39,24 @@ public class URLCoder {
}
}
- private static String urlEncode(byte[] data) {
+ private static String urlEncode(byte[] data, boolean encodeAlphanumeric) {
StringBuffer buf = new StringBuffer(data.length);
for (int i = 0; i < data.length; i++) {
- buf.append('%');
- buf.append(Character.forDigit((data[i] & 240) >>> 4, 16));
- buf.append(Character.forDigit(data[i] & 15, 16));
+ byte nextByte = data[i];
+ if (encodeAlphanumeric && isAlphaNumeric(nextByte)) {
+ buf.append((char)nextByte);
+ } else {
+ buf.append('%');
+ buf.append(Character.forDigit((nextByte & 240) >>> 4, 16));
+ buf.append(Character.forDigit(nextByte & 15, 16));
+ }
}
return buf.toString();
}
+
+ private static boolean isAlphaNumeric(byte b) {
+ return (b >= 0 && b <= 9) || (b >= 'a' && b < 'z') || ( b >= 'A' && b <= 'Z');
+ }
private static byte[] urlDecode(String encodedURL) {
int len = encodedURL.length();
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 ca3442a23..c140469d1 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 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
@@ -29,6 +29,7 @@ public class AllWebappTests extends TestSuite {
suite.addTestSuite(TopicPathTest.class);
suite.addTestSuite(FilterTest.class);
suite.addTestSuite(PluginsRootReplacement.class);
+ suite.addTestSuite(UrlCoderTest.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/UrlCoderTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java
new file mode 100644
index 000000000..4da540f1c
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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 junit.framework.TestCase;
+
+import org.eclipse.help.internal.util.URLCoder;
+
+public class UrlCoderTest extends TestCase {
+
+ private static final String SPECIAL_CHARACTERS = "!@#$%^&*()_+-={}[]:\";'<>,.?/'";
+ private static final String ALPHANUMERIC = "Bxz91r";
+ private static final String ALPHA = "acgrdft";
+ private static final String EMPTY_STRING = "";
+ private static final String ACCENTED = "seg\u00FAn cu\u00E1l oto\u00F1o";
+ private static final String CHINESE = "\u4ECA\u5929\u662F\u5929";
+
+ private void encodeDecode(String value) {
+ String encoded = URLCoder.encode(value);
+ assertEquals(value, URLCoder.decode(encoded));
+ }
+
+ private void compactEncodeDecode(String value) {
+ String encoded = URLCoder.compactEncode(value);
+ assertEquals(value, URLCoder.decode(encoded));
+ }
+
+ private boolean compactEncodingIsShorter(String value) {
+ String compactEncoded = URLCoder.compactEncode(value);
+ String encoded = URLCoder.encode(value);
+ return compactEncoded.length() < encoded.length();
+ }
+
+ public void testEncodeEmpty() {
+ encodeDecode(EMPTY_STRING);
+ }
+
+ public void testEncodeAlphabetic() {
+ encodeDecode(ALPHA);
+ }
+
+ public void testEncodeAlphaNumeric() {
+ encodeDecode(ALPHANUMERIC);
+ }
+
+ public void testEncodeSpecialCharacters() {
+ encodeDecode(SPECIAL_CHARACTERS);
+ }
+
+ public void testEncodeAccented() {
+ encodeDecode(ACCENTED);
+ }
+
+ public void testEncodeChinese() {
+ encodeDecode(CHINESE);
+ }
+
+ // Compact Encodings
+
+ public void testCompactEncodeEmpty() {
+ compactEncodeDecode(EMPTY_STRING);
+ }
+
+ public void testCompactEncodeAlphabetic() {
+ compactEncodeDecode(ALPHA);
+ }
+
+ public void testCompactEncodeAlphaNumeric() {
+ compactEncodeDecode(ALPHANUMERIC);
+ }
+
+ public void testCompactEncodeSpecialCharacters() {
+ compactEncodeDecode(SPECIAL_CHARACTERS);
+ }
+
+ public void testCompactEncodeAccented() {
+ compactEncodeDecode(ACCENTED);
+ }
+
+ public void testCompactEncodeChinese() {
+ compactEncodeDecode(CHINESE);
+ }
+
+ // Verify compaction
+
+
+ public void testCompactionEmpty() {
+ assertFalse(compactEncodingIsShorter(EMPTY_STRING));
+ }
+
+ public void testCompactionAlphabetic() {
+ assertTrue(compactEncodingIsShorter(ALPHA));
+ }
+
+ public void testCompactionAlphaNumeric() {
+ assertTrue(compactEncodingIsShorter(ALPHANUMERIC));
+ }
+
+ public void testCompactionSpecialCharacters() {
+ assertFalse(compactEncodingIsShorter(SPECIAL_CHARACTERS));
+ }
+
+ public void testCompactionAccented() {
+ assertTrue(compactEncodingIsShorter(ACCENTED));
+ }
+
+ public void testCompactionChinese() {
+ assertFalse(compactEncodingIsShorter(CHINESE));
+ }
+
+}

Back to the top