Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkuppe2008-12-01 12:26:55 +0000
committermkuppe2008-12-01 12:26:55 +0000
commit7b38b348e09a54ea4a7850ffc8c464360efa10df (patch)
tree2b5396a9aa380c6a990a9fe0fe88c95b9dcbdb73
parent0e7ecb59680e4b90142671da349957c41d61f826 (diff)
downloadorg.eclipse.ecf-7b38b348e09a54ea4a7850ffc8c464360efa10df.tar.gz
org.eclipse.ecf-7b38b348e09a54ea4a7850ffc8c464360efa10df.tar.xz
org.eclipse.ecf-7b38b348e09a54ea4a7850ffc8c464360efa10df.zip
NEW - bug 255006: [Discovery][SLP] Fail to handle string attributes containing comma
https://bugs.eclipse.org/bugs/show_bug.cgi?id=255006
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jslp/src/org/eclipse/ecf/internal/provider/jslp/ServicePropertiesAdapter.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.jslp/src/org/eclipse/ecf/internal/provider/jslp/ServicePropertiesAdapter.java b/providers/bundles/org.eclipse.ecf.provider.jslp/src/org/eclipse/ecf/internal/provider/jslp/ServicePropertiesAdapter.java
new file mode 100644
index 000000000..c459accb7
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.jslp/src/org/eclipse/ecf/internal/provider/jslp/ServicePropertiesAdapter.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Versant Corp.
+ * 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:
+ * Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.internal.provider.jslp;
+
+import java.util.*;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.util.StringUtils;
+import org.eclipse.ecf.core.util.Trace;
+import org.eclipse.ecf.discovery.IServiceProperties;
+import org.eclipse.ecf.discovery.ServiceProperties;
+
+/**
+ * Adapts SLP's service properties to ECF's ServiceProperties and vice versa
+ * @see "http://www.ietf.org/rfc/rfc2608.txt page. 10ff"
+ */
+public class ServicePropertiesAdapter {
+
+ private static final String SLP_BYTE_PREFIX = "\\FF"; //$NON-NLS-1$
+ private IServiceProperties serviceProperties;
+
+ public ServicePropertiesAdapter(List aList) {
+ Assert.isNotNull(aList);
+ serviceProperties = new ServiceProperties();
+ for (Iterator itr = aList.iterator(); itr.hasNext();) {
+ String[] str = StringUtils.split((String) itr.next(), "="); //$NON-NLS-1$
+ if (str.length != 2) {
+ Trace.trace(Activator.PLUGIN_ID, "/debug/methods/tracing", this.getClass(), "ServicePropertiesAdapter(List)", "Skipped broken service attribute " + str); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ continue;
+ }
+ // remove the brackets "( )" from the string value which are added by jSLP for the LDAP style string representation
+ String key = str[0].substring(1);
+ String value = str[1].substring(0, str[1].length() - 1);
+ if (value.startsWith(SLP_BYTE_PREFIX)) {
+ String[] strs = StringUtils.split(value.substring(4), "\\"); //$NON-NLS-1$
+ byte[] b = new byte[strs.length];
+ for (int i = 0; i < strs.length; i++) {
+ b[i] = new Byte(strs[i]).byteValue();
+ }
+ serviceProperties.setPropertyBytes(key, b);
+ } else if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) { //$NON-NLS-1$ //$NON-NLS-2$
+ serviceProperties.setProperty(key, new Boolean(value));
+ } else if (isInteger(value)) {
+ serviceProperties.setProperty(key, new Integer(value));
+ } else {
+ serviceProperties.setProperty(key, value);
+ }
+ }
+ }
+
+ public ServicePropertiesAdapter(IServiceProperties aServiceProperties) {
+ Assert.isNotNull(aServiceProperties);
+ serviceProperties = aServiceProperties;
+ }
+
+ private boolean isInteger(String value) {
+ try {
+ Integer.parseInt(value);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ public IServiceProperties toServiceProperties() {
+ return serviceProperties;
+ }
+
+ public Dictionary toProperties() {
+ Dictionary dict = new Properties();
+ Enumeration propertyNames = serviceProperties.getPropertyNames();
+ while (propertyNames.hasMoreElements()) {
+ String key = (String) propertyNames.nextElement();
+ byte[] propertyBytes = serviceProperties.getPropertyBytes(key);
+ if (propertyBytes != null) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(SLP_BYTE_PREFIX);
+ for (int i = 0; i < propertyBytes.length; i++) {
+ buf.append("\\"); //$NON-NLS-1$
+ buf.append(propertyBytes[i]);
+ }
+ dict.put(key, buf.toString());
+ } else {
+ dict.put(key, serviceProperties.getProperty(key).toString());
+ }
+ }
+ return dict;
+ }
+} \ No newline at end of file

Back to the top