X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FViewArgumentUtils.java;h=c44a8a5c3363a485ee437975b32ac7631747f5df;hb=6a6726b1ee9c2e78971d26b50f15b867cc7c5a02;hp=1e7baee30eb7c60bdc215bcd59b8b34fa43df6b8;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ViewArgumentUtils.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ViewArgumentUtils.java index 1e7baee30..c44a8a5c3 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ViewArgumentUtils.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ViewArgumentUtils.java @@ -1,80 +1,80 @@ -/******************************************************************************* - * 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 parseViewArguments(IViewPart part) { - String secondaryId = part.getViewSite().getSecondaryId(); - Map result = ViewArgumentUtils.decodeArguments(secondaryId); - return result; - } - - public static Map decodeArguments(String secondaryId) { - Map result = new HashMap(); - 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 args) { - StringBuilder sb = new StringBuilder(); - boolean notFirst = false; - for (Map.Entry 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", "="); - } - -} +/******************************************************************************* + * 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 parseViewArguments(IViewPart part) { + String secondaryId = part.getViewSite().getSecondaryId(); + Map result = ViewArgumentUtils.decodeArguments(secondaryId); + return result; + } + + public static Map decodeArguments(String secondaryId) { + Map result = new HashMap(); + 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 args) { + StringBuilder sb = new StringBuilder(); + boolean notFirst = false; + for (Map.Entry 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", "="); + } + +}