Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-06-07 12:54:11 -0400
committerslewis2008-06-07 12:54:11 -0400
commit21ddb9eb83e961b6af7ee91604e1000b2d6d1aa7 (patch)
tree99b6759737ab08fb1591de5cc02c0a5fb0e2ca83 /providers/bundles/org.eclipse.ecf.provider.xmpp
parentf070aca2a49a59d71139982f530cbd941fcee6d2 (diff)
downloadorg.eclipse.ecf-21ddb9eb83e961b6af7ee91604e1000b2d6d1aa7.tar.gz
org.eclipse.ecf-21ddb9eb83e961b6af7ee91604e1000b2d6d1aa7.tar.xz
org.eclipse.ecf-21ddb9eb83e961b6af7ee91604e1000b2d6d1aa7.zip
Preparing for 232116
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.xmpp')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF1
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml8
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPFiletURLStreamHandlerService.java18
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileID.java84
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileNamespace.java35
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java15
6 files changed, 134 insertions, 27 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF
index 5fde9ee7c..60b433f8c 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF
@@ -32,5 +32,6 @@ Import-Package: org.eclipse.core.runtime.jobs,
org.eclipse.osgi.util;version="1.0.0",
org.osgi.framework;version="1.3.0",
org.osgi.service.log;version="1.3.0",
+ org.osgi.service.url,
org.osgi.util.tracker;version="1.3.2"
Bundle-ActivationPolicy: lazy
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml b/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml
index 3df5a080d..99fb1ef98 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml
@@ -86,5 +86,11 @@
<extension-point id="iqProviders" name="IQ Providers" schema="schema/iqProvider.exsd"/>
<extension-point id="extensionProviders" name="Extension Providers" schema="schema/extensionProvider.exsd"/>
<extension-point id="providerDirectories" name="Provider Directories" schema="schema/providerDirectories.exsd"/>
-
+ <extension
+ point="org.eclipse.ecf.filetransfer.urlStreamHandlerService">
+ <urlStreamHandlerService
+ protocol="xmppfile"
+ serviceClass="org.eclipse.ecf.internal.provider.xmpp.XMPPFiletURLStreamHandlerService">
+ </urlStreamHandlerService>
+ </extension>
</plugin>
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPFiletURLStreamHandlerService.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPFiletURLStreamHandlerService.java
new file mode 100644
index 000000000..3ae128684
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPFiletURLStreamHandlerService.java
@@ -0,0 +1,18 @@
+package org.eclipse.ecf.internal.provider.xmpp;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.osgi.service.url.AbstractURLStreamHandlerService;
+
+public class XMPPFiletURLStreamHandlerService extends AbstractURLStreamHandlerService {
+
+ public XMPPFiletURLStreamHandlerService() {
+ }
+
+ public URLConnection openConnection(URL u) throws IOException {
+ throw new IOException("Cannot open connection with xmppfile protocol"); //$NON-NLS-1$
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileID.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileID.java
index 2b6abcf78..aff356d62 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileID.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileID.java
@@ -11,14 +11,19 @@
package org.eclipse.ecf.provider.xmpp.identity;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.StringTokenizer;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.BaseID;
-import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.filetransfer.identity.IFileID;
-import org.eclipse.ecf.internal.provider.xmpp.Messages;
+import org.eclipse.osgi.util.NLS;
/**
* XMPPFileID for use with the XMPP outgoing file transfer.
@@ -26,15 +31,74 @@ import org.eclipse.ecf.internal.provider.xmpp.Messages;
public class XMPPFileID extends BaseID implements IFileID {
private static final long serialVersionUID = 9052434567658554404L;
+ public static final String FILENAME_KEY = "file"; //$NON-NLS-1$
+ public static final String XMPPIDNAMESPACE_KEY = "ns"; //$NON-NLS-1$
+ private static final String UTF_8 = "utf-8"; //$NON-NLS-1$
- XMPPID xmppid;
- String filename;
+ private final XMPPID xmppid;
+ private final String filename;
+ private final URL url;
- public XMPPFileID(XMPPID id, String fn) {
+ public XMPPFileID(XMPPID id, String fn) throws MalformedURLException {
Assert.isNotNull(id);
Assert.isNotNull(fn);
this.xmppid = id;
this.filename = fn;
+ this.url = createURL(xmppid, filename);
+ }
+
+ XMPPFileID(URL url) throws IDCreateException, MalformedURLException {
+ Assert.isNotNull(url);
+ this.url = url;
+ this.xmppid = (XMPPID) IDFactory.getDefault().createID(getPropertyFromURL(XMPPIDNAMESPACE_KEY, url), getIDStringFromFileURL(url));
+ this.filename = getPropertyFromURL(FILENAME_KEY, url);
+ }
+
+ private static String getIDStringFromFileURL(URL url) throws MalformedURLException {
+ final String result = url.getAuthority();
+ String path = url.getPath();
+ path = (path.startsWith("/") ? path : "/" + path); //$NON-NLS-1$ //$NON-NLS-2$
+ return result + path;
+ }
+
+ private static String getPropertyFromURL(String propKey, URL url) throws MalformedURLException {
+ final String query = url.getQuery();
+ if (query == null || query.equals("")) //$NON-NLS-1$
+ throw new MalformedURLException(NLS.bind("Cannot have empty query for URL {0}", url)); //$NON-NLS-1$
+ final StringTokenizer st = new StringTokenizer(query, "&"); //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ final String tok = st.nextToken();
+ if (tok.startsWith(propKey + "=")) { //$NON-NLS-1$
+ try {
+ return URLDecoder.decode(tok.substring(propKey.length() + "=".length()), UTF_8); //$NON-NLS-1$
+ } catch (final UnsupportedEncodingException e) {
+ // should not happen
+ throw new MalformedURLException(NLS.bind("Could not decode {0} in URL {1}", propKey, url)); //$NON-NLS-1$
+
+ }
+ }
+ }
+ throw new MalformedURLException(NLS.bind("Key {0} not found in URL {1}", propKey, url)); //$NON-NLS-1$
+ }
+
+ public static URL createURL(XMPPID xmppid2, String filename2) throws MalformedURLException {
+ final StringBuffer buf = new StringBuffer(XMPPFileNamespace.SCHEME);
+ buf.append("://"); //$NON-NLS-1$
+ buf.append(xmppid2.getFQName()).append(createQuery(filename2, xmppid2.getNamespace().getName()));
+ return new URL(buf.toString());
+ }
+
+ public static String createQuery(String filename, String xmppidScheme) throws MalformedURLException {
+ final StringBuffer sb = new StringBuffer("?"); //$NON-NLS-1$
+ try {
+ sb.append(FILENAME_KEY).append("=").append(URLEncoder.encode(filename, UTF_8)); //$NON-NLS-1$
+ sb.append("&"); //$NON-NLS-1$
+ sb.append(XMPPIDNAMESPACE_KEY).append("=").append(URLEncoder.encode(xmppidScheme, UTF_8)); //$NON-NLS-1$
+ return sb.toString();
+ } catch (final UnsupportedEncodingException e) {
+ // should never happen
+ throw new MalformedURLException("filename encoding exception"); //$NON-NLS-1$
+ }
}
public XMPPID getXMPPID() {
@@ -42,10 +106,10 @@ public class XMPPFileID extends BaseID implements IFileID {
}
/* (non-Javadoc)
- * @see org.eclipse.ecf.core.identity.BaseID#namespaceToExternalForm()
+ * @see org.eclipse.ecf.core.identity.BaseID#toExternalForm()
*/
- protected String namespaceToExternalForm() {
- return namespace.getScheme() + Namespace.SCHEME_SEPARATOR + xmppid.toExternalForm() + "*" + filename;
+ public String toExternalForm() {
+ return url.toExternalForm();
}
/* (non-Javadoc)
@@ -71,7 +135,7 @@ public class XMPPFileID extends BaseID implements IFileID {
* @see org.eclipse.ecf.core.identity.BaseID#namespaceGetName()
*/
protected String namespaceGetName() {
- return xmppid.getName() + "/" + filename; //$NON-NLS-1$
+ return toExternalForm();
}
/* (non-Javadoc)
@@ -92,7 +156,7 @@ public class XMPPFileID extends BaseID implements IFileID {
* @see org.eclipse.ecf.filetransfer.identity.IFileID#getURL()
*/
public URL getURL() throws MalformedURLException {
- throw new MalformedURLException(Messages.XMPPFileID_EXCEPTION_FILE_IDS_NOT_URLS);
+ return url;
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileNamespace.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileNamespace.java
index 45ac8f4f7..65aafc34d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileNamespace.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPFileNamespace.java
@@ -11,10 +11,11 @@
package org.eclipse.ecf.provider.xmpp.identity;
+import java.net.URL;
+
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.Namespace;
-import org.eclipse.ecf.internal.provider.xmpp.Messages;
import org.eclipse.osgi.util.NLS;
/**
@@ -28,16 +29,32 @@ public class XMPPFileNamespace extends Namespace {
public static final String NAME = "ecf.provider.filetransfer.xmpp"; //$NON-NLS-1$
+ private String getInitFromExternalForm(Object[] args) {
+ if (args == null || args.length < 1 || args[0] == null)
+ return null;
+ if (args[0] instanceof String) {
+ final String arg = (String) args[0];
+ if (arg.startsWith(getScheme() + Namespace.SCHEME_SEPARATOR)) {
+ final int index = arg.indexOf(Namespace.SCHEME_SEPARATOR);
+ if (index >= arg.length())
+ return null;
+ return arg.substring(index + 1);
+ }
+ }
+ return null;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[])
*/
public ID createInstance(Object[] parameters) throws IDCreateException {
- if (parameters == null || parameters.length < 2 || !(parameters[0] instanceof XMPPID || !(parameters[1] instanceof String)))
- throw new IDCreateException(Messages.XMPPFileNamespace_EXCEPTION_INVALID_FILEID_PARAMETERS);
try {
- final XMPPID target = (XMPPID) parameters[0];
- final String filename = (String) parameters[1];
- return new XMPPFileID(target, filename);
+ final String init = getInitFromExternalForm(parameters);
+ if (init != null)
+ return new XMPPFileID(new URL(init));
+ if (parameters[0] instanceof URL)
+ return new XMPPFileID((URL) parameters[0]);
+ return new XMPPFileID((XMPPID) parameters[0], (String) parameters[1]);
} catch (final Exception e) {
throw new IDCreateException(NLS.bind("{0} createInstance()", getName()), e); //$NON-NLS-1$
}
@@ -50,4 +67,10 @@ public class XMPPFileNamespace extends Namespace {
return SCHEME;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.identity.Namespace#getSupportedParameterTypes()
+ */
+ public Class[][] getSupportedParameterTypes() {
+ return new Class[][] { {String.class}, {URL.class}, {XMPPID.class, String.class}};
+ }
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
index c27a4ffc5..deb1e6917 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
@@ -97,15 +97,10 @@ public class XMPPID extends BaseID implements IChatID {
}
/* (non-Javadoc)
- * @see org.eclipse.ecf.core.identity.BaseID#toExternalForm()
+ * @see org.eclipse.ecf.core.identity.BaseID#namespaceToExternalForm()
*/
- public String toExternalForm() {
- final StringBuffer buf = new StringBuffer(namespace.getScheme());
- buf.append(Namespace.SCHEME_SEPARATOR);
- buf.append(USER_HOST_DELIMITER).append(hostname);
- buf.append((port == -1) ? "" : PORT_DELIMITER + "" + port);
- buf.append(resourcename);
- return buf.toString();
+ protected String namespaceToExternalForm() {
+ return uri.toASCIIString();
}
public String getUsername() {
@@ -125,11 +120,11 @@ public class XMPPID extends BaseID implements IChatID {
}
public String getUsernameAtHost() {
- return getUsername() + "@" + getHostname(); //$NON-NLS-1$
+ return getUsername() + USER_HOST_DELIMITER + getHostname();
}
public String getFQName() {
- return getUsernameAtHost() + getResourceName();
+ return getUsernameAtHost() + ((getPort() == -1) ? "" : ":" + getPort()) + getResourceName();
}
public String toString() {

Back to the top