Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfbecker2011-02-23 22:02:41 +0000
committerfbecker2011-02-23 22:02:41 +0000
commit5edd86d1451512a637e0394d8a37d33333e76444 (patch)
treef09b8253c9e39de956913fe545d2b9b30e1c33c5 /org.eclipse.mylyn.tests.util
parentda574e0c37bb1df7c95a480897b4d0cf96f02638 (diff)
downloadorg.eclipse.mylyn.tasks-5edd86d1451512a637e0394d8a37d33333e76444.tar.gz
org.eclipse.mylyn.tasks-5edd86d1451512a637e0394d8a37d33333e76444.tar.xz
org.eclipse.mylyn.tasks-5edd86d1451512a637e0394d8a37d33333e76444.zip
NEW - bug 335278: enhance search result handler to handle additional attributes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335278
Diffstat (limited to 'org.eclipse.mylyn.tests.util')
-rw-r--r--org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UrlBuilder.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UrlBuilder.java b/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UrlBuilder.java
new file mode 100644
index 000000000..f0698abf1
--- /dev/null
+++ b/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UrlBuilder.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.tests.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+
+/**
+ * A builder class for constructing {@link TaskRepository task repository} URLs.
+ *
+ * @author David Green
+ * @since 3.5
+ */
+public class UrlBuilder {
+ private final StringBuilder buf = new StringBuilder(512);
+
+ private UrlBuilder() {
+ }
+
+ public static UrlBuilder build(TaskRepository repository) {
+ UrlBuilder builder = new UrlBuilder();
+ String url = repository.getRepositoryUrl();
+ if (url.endsWith("/")) {
+ url = url.substring(0, url.length() - 1);
+ }
+ return builder.append(url);
+ }
+
+ public UrlBuilder append(String urlSegment) {
+ buf.append(urlSegment);
+ return this;
+ }
+
+ public UrlBuilder parameter(String name, Object value) {
+ return parameter(name, value == null ? null : value.toString());
+ }
+
+ public UrlBuilder parameter(String name, String value) {
+ int indexOfQ = buf.indexOf("?");
+ if (indexOfQ == -1) {
+ buf.append("?");
+ } else {
+ buf.append("&");
+ }
+ buf.append(name);
+ buf.append('=');
+ if (value != null) {
+ buf.append(encode(value));
+ }
+ return this;
+ }
+
+ private String encode(String value) {
+ try {
+ return URLEncoder.encode(value, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return buf.toString();
+ }
+
+}

Back to the top