summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-07-28 13:09:53 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-07 12:18:00 (GMT)
commit0470264fd4f9e7e73d1b655dc680e5ca7c10513c (patch)
tree95e58af6ac3553123d2c404acee03938b4732647
parenteca0a80a7abb136094f252872499c59803999f85 (diff)
downloadstroke-0470264fd4f9e7e73d1b655dc680e5ca7c10513c.zip
stroke-0470264fd4f9e7e73d1b655dc680e5ca7c10513c.tar.bz2
Stringprep JIDs through icu4j
-rw-r--r--Makefile13
-rw-r--r--build.xml4
-rw-r--r--src/com/isode/stroke/jid/JID.java55
3 files changed, 55 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 85de348..6241ae2 100644
--- a/Makefile
+++ b/Makefile
@@ -10,19 +10,22 @@ distclean: clean
rm -rf third-party
.PHONY : dist/lib/stroke.jar
-dist/lib/stroke.jar: third-party/xpp/xpp.jar third-party/jzlib/jzlib.jar
+dist/lib/stroke.jar: third-party/xpp/xpp.jar third-party/jzlib/jzlib.jar third-party/icu4j.jar
ant -Dxpp-dir=third-party/xpp -Djzlib-dir=third-party/jzlib
-third-party/xpp/xpp.jar: third-party
+third-party/xpp/xpp.jar:
mkdir -p third-party/xpp
curl http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar -o third-party/xpp/xpp.jar
-third-party/jzlib/jzlib.jar: third-party
+third-party/jzlib/jzlib.jar:
+ mkdir -p third-party
curl http://www.jcraft.com/jzlib/jzlib-1.0.7.tar.gz -o third-party/jzlib-1.0.7.tar.gz
tar -xvzf third-party/jzlib-1.0.7.tar.gz -C third-party/
mv third-party/jzlib-1.0.7 third-party/jzlib
cp build-jzlib.xml third-party/jzlib/build.xml
ant -f third-party/jzlib/build.xml
-third-party:
- mkdir -p third-party \ No newline at end of file
+third-party/icu4j.jar:
+ mkdir -p third-party
+ curl http://download.icu-project.org/files/icu4j/4.8.1/icu4j-4_8_1.jar -o third-party/icu4j.jar
+
diff --git a/build.xml b/build.xml
index 709f20e..6e5cbde 100644
--- a/build.xml
+++ b/build.xml
@@ -16,12 +16,14 @@
<property name="main-class" value="com.isode.stroke.examples.gui.StrokeGUI"/>
<property name="compile.debug" value="true"/>
<property name="testsuiteclass" value="com.isode.stroke.unittest.StrokeTestSuite" />
- <property name="xpp-dir" value="../third-party/xpp"/>
+ <property name="xpp-dir" value="third-party/xpp"/>
<property name="jzlib-dir" value="third-party/jzlib"/>
+ <property name="icu4j-dir" value="third-party"/>
<path id="classpath">
<fileset dir="${xpp-dir}" includes="xpp.jar"/>
<fileset dir="${jzlib-dir}" includes="jzlib.jar"/>
+ <fileset dir="${icu4j-dir}" includes="icu4j.jar"/>
</path>
<target name="init">
<tstamp/>
diff --git a/src/com/isode/stroke/jid/JID.java b/src/com/isode/stroke/jid/JID.java
index a256944..a93bebc 100644
--- a/src/com/isode/stroke/jid/JID.java
+++ b/src/com/isode/stroke/jid/JID.java
@@ -8,6 +8,11 @@
*/
package com.isode.stroke.jid;
+import com.ibm.icu.text.StringPrep;
+import com.ibm.icu.text.StringPrepParseException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
/**
* JID helper.
*
@@ -82,16 +87,30 @@ public class JID {
bare = jid;
}
String[] nodeAndDomain = bare.split("@", 2);
+ String node;
+ String domain;
if (nodeAndDomain.length == 1) {
- node_ = "";
- domain_ = nodeAndDomain[0];
- resource_ = resource;
+ node = "";
+ domain = nodeAndDomain[0];
} else {
- node_ = nodeAndDomain[0];
- domain_ = nodeAndDomain[1];
- resource_ = resource;
+ node = nodeAndDomain[0];
+ domain = nodeAndDomain[1];
}
-
+ StringPrep nodePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);
+ StringPrep domainPrep = StringPrep.getInstance(StringPrep.RFC3920_NODEPREP);
+ StringPrep resourcePrep = StringPrep.getInstance(StringPrep.RFC3920_RESOURCEPREP);
+ try {
+ node = nodePrep.prepare(node, StringPrep.DEFAULT);
+ domain = domainPrep.prepare(domain, StringPrep.DEFAULT);
+ resource = resource != null ? resourcePrep.prepare(resource, StringPrep.DEFAULT) : null;
+ } catch (StringPrepParseException ex) {
+ node = "";
+ domain = "";
+ resource = "";
+ }
+ node_ = node;
+ domain_ = domain;
+ resource_ = resource;
}
/**
@@ -118,10 +137,24 @@ public class JID {
* @param resource JID resource part.
*/
public JID(final String node, final String domain, final String resource) {
- //FIXME: This doesn't nameprep!
- node_ = node;
- domain_ = domain;
- resource_ = resource;
+ StringPrep nodePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);
+ StringPrep domainPrep = StringPrep.getInstance(StringPrep.RFC3920_NODEPREP);
+ StringPrep resourcePrep = StringPrep.getInstance(StringPrep.RFC3920_RESOURCEPREP);
+ String preppedNode;
+ String preppedDomain;
+ String preppedResource;
+ try {
+ preppedNode = nodePrep.prepare(node, StringPrep.DEFAULT);
+ preppedDomain = domainPrep.prepare(domain, StringPrep.DEFAULT);
+ preppedResource = resource != null ? resourcePrep.prepare(resource, StringPrep.DEFAULT) : null;
+ } catch (StringPrepParseException ex) {
+ preppedNode = "";
+ preppedDomain = "";
+ preppedResource = "";
+ }
+ node_ = preppedNode;
+ domain_ = preppedDomain;
+ resource_ = preppedResource;
}