PublicIdpublic abstract class PublicId extends Object Static methods for dealing with public identifiers.
This class defines a set of static methods that can be called
to handle public identifiers. |
Constructors Summary |
---|
protected PublicId()
|
Methods Summary |
---|
public static java.lang.String | decodeURN(java.lang.String urn)Decode a "publicid" URN into a public identifier.
This method is declared static so that other classes
can use it directly.
String publicId = "";
if (urn.startsWith("urn:publicid:")) {
publicId = urn.substring(13);
} else {
return urn;
}
publicId = PublicId.stringReplace(publicId, "%2F", "/");
publicId = PublicId.stringReplace(publicId, ":", "//");
publicId = PublicId.stringReplace(publicId, "%3A", ":");
publicId = PublicId.stringReplace(publicId, ";", "::");
publicId = PublicId.stringReplace(publicId, "+", " ");
publicId = PublicId.stringReplace(publicId, "%2B", "+");
publicId = PublicId.stringReplace(publicId, "%23", "#");
publicId = PublicId.stringReplace(publicId, "%3F", "?");
publicId = PublicId.stringReplace(publicId, "%27", "'");
publicId = PublicId.stringReplace(publicId, "%3B", ";");
publicId = PublicId.stringReplace(publicId, "%25", "%");
return publicId;
| public static java.lang.String | encodeURN(java.lang.String publicId)Encode a public identifier as a "publicid" URN.
This method is declared static so that other classes
can use it directly.
String urn = PublicId.normalize(publicId);
urn = PublicId.stringReplace(urn, "%", "%25");
urn = PublicId.stringReplace(urn, ";", "%3B");
urn = PublicId.stringReplace(urn, "'", "%27");
urn = PublicId.stringReplace(urn, "?", "%3F");
urn = PublicId.stringReplace(urn, "#", "%23");
urn = PublicId.stringReplace(urn, "+", "%2B");
urn = PublicId.stringReplace(urn, " ", "+");
urn = PublicId.stringReplace(urn, "::", ";");
urn = PublicId.stringReplace(urn, ":", "%3A");
urn = PublicId.stringReplace(urn, "//", ":");
urn = PublicId.stringReplace(urn, "/", "%2F");
return "urn:publicid:" + urn;
| public static java.lang.String | normalize(java.lang.String publicId)Normalize a public identifier.
Public identifiers must be normalized according to the following
rules before comparisons between them can be made:
- Whitespace characters are normalized to spaces (e.g., line feeds,
tabs, etc. become spaces).
- Leading and trailing whitespace is removed.
- Multiple internal whitespaces are normalized to a single
space.
This method is declared static so that other classes
can use it directly.
String normal = publicId.replace('\t", ' ");
normal = normal.replace('\r", ' ");
normal = normal.replace('\n", ' ");
normal = normal.trim();
int pos;
while ((pos = normal.indexOf(" ")) >= 0) {
normal = normal.substring(0, pos) + normal.substring(pos+1);
}
return normal;
| private static java.lang.String | stringReplace(java.lang.String str, java.lang.String oldStr, java.lang.String newStr)Replace one string with another.
String result = "";
int pos = str.indexOf(oldStr);
// System.out.println(str + ": " + oldStr + " => " + newStr);
while (pos >= 0) {
// System.out.println(str + " (" + pos + ")");
result += str.substring(0, pos);
result += newStr;
str = str.substring(pos+1);
pos = str.indexOf(oldStr);
}
return result + str;
|
|