-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-\r
-import org.eclipse.ui.IViewPart;\r
-import org.simantics.browsing.ui.common.views.IViewArguments;\r
-\r
-/**\r
- * Utilities for parsing what is specified in {@link IViewArguments}.\r
- */\r
-public class ViewArgumentUtils {\r
-\r
- private static final Pattern argumentPattern = Pattern.compile("([^:&=]*)=([^:&=]*)");\r
-\r
- public static Map<String, String> parseViewArguments(IViewPart part) {\r
- String secondaryId = part.getViewSite().getSecondaryId();\r
- Map<String, String> result = ViewArgumentUtils.decodeArguments(secondaryId);\r
- return result;\r
- } \r
-\r
- public static Map<String, String> decodeArguments(String secondaryId) {\r
- Map<String, String> result = new HashMap<String, String>();\r
- if (secondaryId == null)\r
- return result;\r
-\r
- String[] args = secondaryId.split("&");\r
- for (String arg : args) {\r
- Matcher m = argumentPattern.matcher(arg);\r
- if (m.matches()) {\r
- String key = m.group(1);\r
- String value = m.group(2);\r
-\r
- key = unescape(key);\r
- value = unescape(value);\r
-\r
- result.put(key, value);\r
- }\r
- }\r
- return result;\r
- }\r
-\r
- public static String encodeArguments(Map<String, String> args) {\r
- StringBuilder sb = new StringBuilder();\r
- boolean notFirst = false;\r
- for (Map.Entry<String, String> e : args.entrySet()) {\r
- if (notFirst)\r
- sb.append("&");\r
- notFirst = true;\r
- String key = e.getKey();\r
- String value = e.getValue();\r
- sb.append(escape(key));\r
- sb.append("=");\r
- sb.append(escape(value));\r
- }\r
- return sb.toString();\r
- }\r
-\r
- private static String escape(String s) {\r
- return s.replace("&", "%26").replace(":", "%3A").replace("=", "%3D");\r
- }\r
-\r
- private static String unescape(String s) {\r
- return s.replace("%26", "&").replace("%3A", ":").replace("%3D", "=");\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.swt;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ui.IViewPart;
+import org.simantics.browsing.ui.common.views.IViewArguments;
+
+/**
+ * Utilities for parsing what is specified in {@link IViewArguments}.
+ */
+public class ViewArgumentUtils {
+
+ private static final Pattern argumentPattern = Pattern.compile("([^:&=]*)=([^:&=]*)");
+
+ public static Map<String, String> parseViewArguments(IViewPart part) {
+ String secondaryId = part.getViewSite().getSecondaryId();
+ Map<String, String> result = ViewArgumentUtils.decodeArguments(secondaryId);
+ return result;
+ }
+
+ public static Map<String, String> decodeArguments(String secondaryId) {
+ Map<String, String> result = new HashMap<String, String>();
+ if (secondaryId == null)
+ return result;
+
+ String[] args = secondaryId.split("&");
+ for (String arg : args) {
+ Matcher m = argumentPattern.matcher(arg);
+ if (m.matches()) {
+ String key = m.group(1);
+ String value = m.group(2);
+
+ key = unescape(key);
+ value = unescape(value);
+
+ result.put(key, value);
+ }
+ }
+ return result;
+ }
+
+ public static String encodeArguments(Map<String, String> args) {
+ StringBuilder sb = new StringBuilder();
+ boolean notFirst = false;
+ for (Map.Entry<String, String> e : args.entrySet()) {
+ if (notFirst)
+ sb.append("&");
+ notFirst = true;
+ String key = e.getKey();
+ String value = e.getValue();
+ sb.append(escape(key));
+ sb.append("=");
+ sb.append(escape(value));
+ }
+ return sb.toString();
+ }
+
+ private static String escape(String s) {
+ return s.replace("&", "%26").replace(":", "%3A").replace("=", "%3D");
+ }
+
+ private static String unescape(String s) {
+ return s.replace("%26", "&").replace("%3A", ":").replace("%3D", "=");
+ }
+
+}