|
From: <pe...@us...> - 2003-10-25 11:30:02
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id
In directory sc8-pr-cvs1:/tmp/cvs-serv15459/src/java/org/neuclear/id
Modified Files:
NSTools.java
Log Message:
Replaced the dependency for the Apache Regex library with JDK1.4's Regex implementation.
Changed the valid format of NeuClear ID's to include neu://bob@hello/ formatted ids.
These ids are not identical to neu://hello/bob however in both cases neu://hello has to sign the Identity document.
Index: NSTools.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/NSTools.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** NSTools.java 21 Oct 2003 22:31:13 -0000 1.7
--- NSTools.java 22 Oct 2003 22:12:33 -0000 1.8
***************
*** 2,5 ****
--- 2,10 ----
* $Id$
* $Log$
+ * Revision 1.8 2003/10/22 22:12:33 pelle
+ * Replaced the dependency for the Apache Regex library with JDK1.4's Regex implementation.
+ * Changed the valid format of NeuClear ID's to include neu://bob@hello/ formatted ids.
+ * These ids are not identical to neu://hello/bob however in both cases neu://hello has to sign the Identity document.
+ *
* Revision 1.7 2003/10/21 22:31:13 pelle
* Renamed NeudistException to NeuClearException and moved it to org.neuclear.commons where it makes more sense.
***************
*** 113,128 ****
package org.neuclear.id;
- import org.apache.regexp.RE;
- import org.apache.regexp.RESyntaxException;
import org.dom4j.DocumentHelper;
import org.dom4j.Namespace;
import org.neuclear.id.resolver.NSResolver;
import org.neudist.crypto.CryptoTools;
- import org.neuclear.commons.NeuClearException;
import org.neudist.utils.Utility;
import java.util.Random;
public final class NSTools {
private NSTools() {
};
--- 118,140 ----
package org.neuclear.id;
import org.dom4j.DocumentHelper;
import org.dom4j.Namespace;
+ import org.neuclear.commons.NeuClearException;
import org.neuclear.id.resolver.NSResolver;
import org.neudist.crypto.CryptoTools;
import org.neudist.utils.Utility;
import java.util.Random;
+ import java.util.regex.Matcher;
+ import java.util.regex.Pattern;
public final class NSTools {
+ private static final String VALID_TOKEN = "[\\w.]+";
+ private static final String VALID_ID = "^(neu:\\/)?" +
+ "(\\/(" + VALID_TOKEN + "@" + VALID_TOKEN + ")?" +
+ "((\\/)|" + VALID_TOKEN + ")*)$";
+
+ private static final Pattern VALID = Pattern.compile(VALID_ID);
+
private NSTools() {
};
***************
*** 130,133 ****
--- 142,146 ----
/**
* Takes a valid NEU Name and Creates a URI
+ *
* @param name Valid NEU Name
* @return Valid URI
***************
*** 145,169 ****
* Name must follow the follwing rules:<br>
* Available Characters: <pre>a..zA..Z0..9_/.-</pre> <br>
! *
* Name starts with either URI prefix <tt>neu://</tt>
* or <tt>/</tt>
* @param name to test
* @return boolean
*/
! public static boolean isValidName(String name) throws NeuClearException {
! try {
! if (Utility.isEmpty(name))
! return false;
! RE re = new RE("^(neu:\\/)?((\\/)|(\\/[a-zA-Z0-9_\\-\\.]+)*)$");
! return (re.match(name));
! } catch (RESyntaxException e) {
! e.printStackTrace();
! Utility.rethrowException(e);
return false;
! }
}
/**
* Returns the URI of the parent Identity for a given NEU Name
* @param name a valid NEU Name
* @return Parent URI or null if name is the root
--- 158,178 ----
* Name must follow the follwing rules:<br>
* Available Characters: <pre>a..zA..Z0..9_/.-</pre> <br>
! * <p/>
* Name starts with either URI prefix <tt>neu://</tt>
* or <tt>/</tt>
+ *
* @param name to test
* @return boolean
*/
! public static boolean isValidName(String name) {
! if (Utility.isEmpty(name))
return false;
! Matcher matcher = VALID.matcher(name);
! return (matcher.matches());
}
/**
* Returns the URI of the parent Identity for a given NEU Name
+ *
* @param name a valid NEU Name
* @return Parent URI or null if name is the root
|